I am trying to add a mousemove eventlistener to the canvas generated by elm-graphics. I have absolutely no clue as to where I can add it. Do I use toHtml and then try to add the event handler to the Html msg.
Related
Is there a nice clean way to disable multiple touches on the canvas at all?
Thanks in advance.
Fabric.js uses Event.js for touch handling. I couldn't figure out which options could be passed into the canvas constructor, but you might try var canvas = new fabric.Canvas('c', {maxFingers:1}).
Another option might be to use event.preventDefault() inside the handlers for pinch and rotate, to cancel 2 finger gestures. Here are the number of 'pointers' and their actions defined for that library:
1 : click, dblclick, dbltap
1+ : tap, longpress, drag, swipe
2+ : pinch, rotate
If either of those aren't what you need, you will need to set up event listeners for touchstart, touchmove, etc. The MDN page describes how to listen for all touches, so just call preventDefault for each one after the first.
I have a fabricjs canvas and onto that i am adding image. when we click the image the image is in selected mode.
is there a way to know if the mouse if over the grapples(the square boxed around the image) but not the one used to rotate?
and if it is can i fire a javascript command from there?
the rotation square is called 'mtr' inside fabricjs.
You can hook a 'mousedown' or 'mouseover' event to the object in this way:
object.on('mouseover' myfunction.bind(object));
the function you pass will receive an object parameter that we will call opt, just for example.
function(opt) {
var mouseevent = opt.e;
if (this.__corner === 'mtr') {
callMyOtherFunction(mouseevent);
}
}
this will not stop the rotation handling during mousemove or firing modified on mouseup
this.__corner referes to the object (this) and the last findTargetCorner result. Is not documented and is not a public feature, is mostly used for internal fabric logic, but is there and you can use it.
You should propose on the fabric issue tracker to make it an official feature, removing the double dash in front and documenting it in the docs.
I'm using the Application Layout control and have set up a basicLeafNode within the bannerUtility links. I wanted to open another XPage (MeineAnmeldung.xsp) whenever that link 'Meine Anmeldungen' is clicked.
<bx:this.bannerUtilityLinks>
<xe:basicLeafNode
label="Meine Anmeldungen">
<xe:this.rendered><![CDATA[#{javascript:context.getUser().getRoles().contains('[CreateAnmeldung]')}]]></xe:this.rendered>
<xe:this.onClick><![CDATA[#{javascript:context.redirectToPage("MeineAnmeldungen.xsp")}]]></xe:this.onClick>
</xe:basicLeafNode>
but, as I have discovered, the onCLick event on the basicLeafNode is strictly CSJS, which I assume is the reason why I'm having issues.
Am I trying to do this at the wrong place? To be honest, I don't understand the difference between all these different bars at the top: Placebar, Search Bar, Title Bar, mastHeader. No idea which does what, and I'm trying to have a very simple UI without any clutter.
Or is there a way to redirect using CCJS? Perhaps by recalculating an URL, which I also am not sure about how to calculate.
Use a pageTreeNode instead. Here's an example:
<xe:this.bannerUtilityLinks>
<xe:pageTreeNode label="Meine Anmeldungen" page="/MeineAnmeldungen.xsp.xsp"></xe:pageTreeNode>
</xe:this.bannerUtilityLinks>
You can redirect via CSJS using location.href=.... CSJS is all the onClick event of the basicLeafNode can do.
The Application Layout control itself has an onItemClick event on the Events tab. That will allow you to trigger SSJS and use context.getSubmittedValue() to check the submitValue property (you'll need to add that) for the basicLeafNode.
See TitleBar tabs in ApplicationLayout control (extlib) generating invalid code
I want to add a new View to a Layout dynamically by layout.addView(view) method. The new View is not supposed to be visible, but I want it's Display List to be created so it doesn't have to redraw (call onDraw method) itself when I decide to show it (by animation, for example fade in).
I run this code:
customView = new CustomView(this.getContext());
customView .setAlpha(0.0f);
this.addView(customView ); // 'this' is RelativeLayout instance in this case
onDraw method gets called for customView and everything is fine. However, when I change anything in my layout (push a button, scroll, anything that invalidates layout), the onDraw method for my customView is called second time. After that, it isn't called any more if I don't invalidate my customView (correct behaviour).
I don't know why Android behaves this way. I want it to create customView, call onDraw, create a Display List for it, and not call onDraw any more until I invalidate my view. To sum up, onDraw is supposed to be called once.
And it has nothing to do with initial invisibility of customView, if alpha is set to 0.5f, behaviour is the same.
My question is, how to make Android call onDraw only once?
And if Android really has to call onDraw twice, then what should I do to enforce it to do it in some code right after this.addView(view); without setting up any timers because THAT would be totally ugly.
The behavior you are describing is ok and is a part of the android framework for view object -
Drawing
Drawing is handled by walking the tree and rendering each view that
intersects the invalid region. Because the tree is traversed in-order,
this means that parents will draw before (i.e., behind) their
children, with siblings drawn in the order they appear in the tree. If
you set a background drawable for a View, then the View will draw it
for you before calling back to its onDraw() method. Note that the
framework will not draw views that are not in the invalid region. To
force a view to draw, call invalidate()
(Taken from the official google android API docs).
Meaning your custom view is contained by the same view that contains the button\scrollbar etc. If you don't want it to be rendered everytime the onDraw method is called for the subtree your view resides in you can set the view's boolean flag to false - use setWillNotDraw() to do that. (you should place it on the activity's onCreate in order to render the view set this flag to false (which is also the default) and use invalidate() whenever you want to render the view).You can read the official google docs for further information.
I am implementing a custom surface view, which is called from other activity by setContentView(new SurfaceViewClass(Context)). This class is extending the surfaceView. In the Draw() method which I have added in the surface view, I am displaying an animation that gets triggered, say, every 200 milliseconds, which means that the surfaceview thread gets triggered every 200 msecs.
My requirement is I want to add a button at the bottom of the animation that can respond to events when user has pressed it. How it is possible to do this?
Thank you!
The idea is to have surfaceView(i.e. your graphics) inside a FrameLayout. See the xml layout in the following link.
In the following questions, i have posted the code for the same.
Android:Crash: Binary XML file line : Error inflating class (using SurfaceView)
Let us know if it works!