How to change image opacity with camanjs? - opacity

how to change image opacity with caman js
I tried with lates version also. Still issue is coming. If anything need to enable to achieve this ?
//throwing not defined with caman js. In this reference -
https://www.sitepoint.com/manipulating-images-web-pages-camanjs/
this.opacity(20);

Add these filter in camen.js
Filter.register("opacity", function (adjust) {
adjust = Math.floor(255 * (adjust / 100));
var imageData = this.imageData.data,
length = imageData.length;
// set every fourth value to 50
for (var i = 3; i < length; i += 4) {
imageData[i] = imageData[i] == 0 ? imageData[i] : adjust;
}
// after the manipulation, reset the data
this.imageData.data = imageData;
this.context.putImageData(this.imageData, 0, 0);
});
Now opacity filter will work.

Related

ChartJS - line graph, position tooltip

I have the following graph with 3 datasets. Everything works fine except for one small bug. I want to tooltip to be placed only on the first dataset, as it currently is placed on the average position of all datasets.
Here is a screenshot:
I know that ChartJS has the positioners function (the one below), but I can't figure out how to ignore the other 2 datasets so the tooltip is sticked only to the first line graph
Chart.Tooltip.positioners.top = function (elements, eventPosition) {
const tooltip = this;
return ;
};
You can also define a custom position function for tooltips. like this,
Chart.Tooltip.positioners.custom = function(elements, eventPosition) {
var x = eventPosition.x;
var y = eventPosition.y;
var minDistance = Number.POSITIVE_INFINITY;
var i, len, nearestElement;
var top_element = elements[0];
for (i = 0, len = elements.length; i < len; ++i) {
console.log(elements[i].tooltipPosition().y);
if (elements[i].tooltipPosition().y < top_element.tooltipPosition().y) {
top_element = elements[i];
}
}
var tp = top_element.tooltipPosition();
x = tp.x;
y = tp.y;
return {
x: x,
y: y
};
};
Once done, you can specify it in tooltips.options.
More information :
https://www.chartjs.org/docs/latest/configuration/tooltip.html#position-modes
Hope it helps!

Present Sheet in a center of parent window

I use function
NSViewController.PresentViewControllerAsSheet(NSViewController)
and everything works great, but I would like to have a chance change the position of this sheet (for ex. in the center of parent).
How to do that ?
Ok, I have found solution:
C# code, Xamarin.Mac
controller.PresentViewControllerAsModalWindow(_settingsController);
if (_settingsController.View.Window != null)
{
var x = (_window.Frame.Left) + (_window.Frame.Width / 2) - 400;
var y = (_window.Frame.Top) + (_window.Frame.Height / 2) - 300;
_settingsController.View.Window.SetFrame(new CoreGraphics.CGRect(x, y, 800, 600), true);
_settingsController.View.Window.TitleVisibility = NSWindowTitleVisibility.Hidden;
_settingsController.View.Window.TitlebarAppearsTransparent = true;
_settingsController.View.Window.StyleMask = NSWindowStyle.FullSizeContentView | NSWindowStyle.Borderless;
_settingsController.View.Window.IsMovable = false;
}

Sprite Grid Positioning issue cocosd-js 3.16

I am making a 2d(25x20) grid of sprites. But somehow sprites are getting re positioned by itself.enter image description here
makeLandBlocksMatrix : function () {
this.LAND_BLOCK_TAG = 1;
var blockCounter = 0;
var prices = MMMapData.getPrices();
this._blocks = MMUtility.createArray(MMConstants.totalNoRowsPerMap,MMConstants.totalNoColsPerMap);
for (var i = 0; i< MMConstants.totalNoRowsPerMap; i++){
for (var j = 0; j< MMConstants.totalNoColsPerMap; j++){
var block = new MMLandBlockSprite();
block.initWithData(res.BlockBlack,prices[blockCounter],this.LAND_BLOCK_TAG);
block.setPosition(cc.p(block.getContentSize().width*0.5 + i * block.getContentSize().width * 1.0, (this._size.height - block.getContentSize().height*0.5) - j * block.getContentSize().height * 1.0));
this.addChild(block);
block.setBg();
block._bg.setOpacity(0.0);
block.setPriceLabel();
block._priceLabel.setOpacity(0.0);
this._blocks[i][j] = block;
this.LAND_BLOCK_TAG++;
blockCounter++;
}
}
}
And same code is working fine with cocos2d-x(c++).
Thanks.
After lots of tweaks and googling, i just used lower version of cocos2d-html(version 3.7). And same code work as expected.There might be problem in rendering pipeline in latest cocos2d-html. And same issue persist in case we try to make Grid of UI component or Basic components(Sprite,Label) as components number increases positioning difference increases(i.e as show in reference image).

How target a movieClip in animate cc in this drag drop code

is there a way to modify this code for animate cc to make object in the stage and interact with it ?
it is a bit of pain to make drag and drop in createjs for animate cc
there is nothing in the web that describe how to do it for animate cc or flash cc even the documentation has nothing to tell about drag and drop in the canvas
//Stage
var stage = new createjs.Stage("demoCanvas");
//VARIABLES
//Drag Object Size
dragRadius = 40;
//Destination Size
destHeight = 100;
destWidth = 100;
//Circle Creation
var label = new createjs.Text("DRAG ME", "14px Lato", "#fff");
label.textAlign="center";
label.y -= 7;
var circle = new createjs.Shape();
circle.graphics.setStrokeStyle(2).beginStroke("black")
.beginFill("red").drawCircle(0,0, dragRadius);
//Drag Object Creation
//Placed inside a container to hold both label and shape
var dragger = new createjs.Container();
dragger.x = dragger.y = 100;
dragger.addChild(circle, label);
dragger.setBounds(100, 100, dragRadius*2, dragRadius*2);
//DragRadius * 2 because 2*r = width of the bounding box
var label2 = new createjs.Text("HERE", "bold 14px Lato", "#000");
label2.textAlign = "center";
label2.x += 50;
label2.y += 40;
var box = new createjs.Shape();
box.graphics.setStrokeStyle(2).beginStroke("black").rect(0, 0, destHeight, destWidth);
var destination = new createjs.Container();
destination.x = 350;
destination.y = 50;
destination.setBounds(350, 50, destHeight, destWidth);
destination.addChild(label2, box);
//DRAG FUNCTIONALITY =====================
dragger.on("pressmove", function(evt){
evt.currentTarget.x = evt.stageX;
evt.currentTarget.y = evt.stageY;
stage.update(); //much smoother because it refreshes the screen every pixel movement instead of the FPS set on the Ticker
if(intersect(evt.currentTarget, destination)){
evt.currentTarget.alpha=0.2;
box.graphics.clear();
box.graphics.setStrokeStyle(3)
.beginStroke("#0066A4")
.rect(0, 0, destHeight, destWidth);
}else{
evt.currentTarget.alpha=1;
box.graphics.clear(); box.graphics.setStrokeStyle(2).beginStroke("black").rect(0, 0, destHeight, destWidth);
}
});
//Mouse UP and SNAP====================
dragger.on("pressup", function(evt) {
if(intersect(evt.currentTarget, destination)){
dragger.x = destination.x + destWidth/2;
dragger.y = destination.y + destHeight/2;
dragger.alpha = 1;
box.graphics.clear();
box.graphics.setStrokeStyle(2).beginStroke("black").rect(0, 0, destHeight, destWidth);
stage.update(evt);
}
});
//Tests if two objects are intersecting
//Sees if obj1 passes through the first and last line of its
//bounding box in the x and y sectors
//Utilizes globalToLocal to get the x and y of obj1 in relation
//to obj2
//PRE: Must have bounds set for each object
//Post: Returns true or false
function intersect(obj1, obj2){
var objBounds1 = obj1.getBounds().clone();
var objBounds2 = obj2.getBounds().clone();
var pt = obj1.globalToLocal(objBounds2.x, objBounds2.y);
var h1 = -(objBounds1.height / 2 + objBounds2.height);
var h2 = objBounds2.width / 2;
var w1 = -(objBounds1.width / 2 + objBounds2.width);
var w2 = objBounds2.width / 2;
if(pt.x > w2 || pt.x < w1) return false;
if(pt.y > h2 || pt.y < h1) return false;
return true;
}
//Adds the object into stage
stage.addChild(destination, dragger);
stage.mouseMoveOutside = true;
stage.update();
thanks
I am not exactly sure what you are asking. The demo you showed works fine (looks like it came from this codepen), and it is not clear what you are trying to add. This demo was made directly in code, not with Animate CC - which is really good for building assets, animations, and display list structure, but you should write application code around what gets exported.
There are plenty of documentation and examples online for Drag and Drop, in the EaselJS GitHub, and EaselJS docs:
DragAndDrop demo in GitHub
Live demo on EaselJS demos page
Documentation on pressMove
Tutorial on Mouse Events which includes Drag and Drop
I recommend narrowing down what you are trying to do, show what code or approaches you have tried so far, and posting specific questions here.
Lastly, here is the first part of an ongoing series for working with Animate CC: http://blog.gskinner.com/archives/2015/04/introduction-to-the-flash-cc-html5-canvas-document.html
Cheers.

Background color for TabControl?

I'm working on a browser that's running on Geckofx, and well I can't find a way to change the color of the TabControl
I don't want to change the tab page, I want to change the container.
Here's what I mean:
This is what i'm trying to do:
And this is where i'm at:
I'm already using this for the tabs
private void tabControl_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
{
TabPage CurrentTab = tabControl.TabPages[e.Index];
Rectangle ItemRect = tabControl.GetTabRect(e.Index);
SolidBrush FillBrush = new SolidBrush(Color.Red);
SolidBrush FBG = new SolidBrush(Color.Black);
SolidBrush TextBrush = new SolidBrush(Color.Green);
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
if (System.Convert.ToBoolean(e.State & DrawItemState.Selected))
{
FillBrush.Color = Color.Black;
TextBrush.Color = Color.Green;
ItemRect.Inflate(0, 0);
}
if (tabControl.Alignment == TabAlignment.Left || tabControl.Alignment == TabAlignment.Right)
{
float RotateAngle = 90;
if (tabControl.Alignment == TabAlignment.Left)
RotateAngle = 270;
PointF cp = new PointF(ItemRect.Left + (ItemRect.Width / 3), ItemRect.Top + (ItemRect.Height / 5));
e.Graphics.TranslateTransform(cp.X, cp.Y);
e.Graphics.RotateTransform(RotateAngle);
ItemRect = new Rectangle(-(ItemRect.Height / 3), -(ItemRect.Width / 3), ItemRect.Height, ItemRect.Width);
}
e.Graphics.FillRectangle(FillBrush, ItemRect);
e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, (RectangleF)ItemRect, sf);
e.Graphics.ResetTransform();
FillBrush.Dispose();
TextBrush.Dispose();
}
}
I just have no idea how to change the color of the TabControl
I've looked over online everywhere and the examples either made 0 sense whatsoever or did not work.
I know it's possible from the example i've seen
Can anyone help?
TabControl have the propertie BackColor, from Control. Maybe if nothing work, try to set the DefaultBackColor to the color you need for your TabControl?
Look at this : http://msdn.microsoft.com/en-us/library/system.windows.forms.control.defaultbackcolor.aspx