How to create cocoa gesture event - xcode

I have a problem: how can I create gesture event by code, (rotate, magnify or swipe...), I don't want to use it to zoom or rotate a specific image or something like that, I want to create gesture event like scroll event create by CGEventRef cgEvent = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitLine, wheelCount, yScroll, xScroll);
CGEventPost(kCGHIDEventTap, cgEvent);
Thanks

Not all events have "shortcut" creation functions (like CGEventCreateScrollWheelEvent, CGEventCreateMouseEvent, and CGEventCreateKeyboardEvent), so you have to create an empty event and then set the fields manually using the CGEventSet* functions.
The gesture-related events only have public constants for the Cocoa API level. For example, while NSLeftMouseDragged == kCGEventLeftMouseDragged == NX_LMOUSEDRAGGED == 6, NSEventTypeMagnify == 30 doesn't have any equivalent kCGEventMagnify or NX_MAGNIFY.
Also, the way gesture events work is a bit tricky; if you don't send the proper sequence of mouse/trackpad events, gesture, gesture begin/end, and specific-gesture events, it won't work.
There's not much documentation on which fields each event type needs; the easiest way to find out is to first create an event tap that logs everything, then generate the events you want and see what gets logged. In fact, you probably want to also log an NSEvent global monitor (log both the NSEvent itself and its underlying cgEvent).

Related

Stopping clicks on object on one stage going through to the nextStage in EaselJS / CreateJS

I have two canvases and two stages in CreateJS / EaselJS. The first stage has autoClear set to false and I am doing dynamic drawing on it starting with a stagemousedown event. The second stage uses nextStage to send mouse events to the first stage. The second stage has interface such as a Bitmap that I want to press on to go to another page. When I click on the Bitmap, the stage beneath does the dynamic drawing. I want the click on the Bitmap not to go through to the first stage but stopImmediatePropagation does not work, nor does putting a clone of the Bitmap with mouseEnabled false on it underneath. I can just use mousedown on the Bitmap so the user does not notice as much, but was wondering if there is a way to disable mouse events from passing through the top stage if they are acting on an object with an event set to capture? Thanks in advance.
The stagemousedown and other stage events are decoupled from the EaselJS object event model. They are catch-all events, which basically represent mouse interaction with the . Because of this, catching and stopping these events won't interrupt the display list hierarchy.
Typically if you want to block other events in the same stage, you can create a canvas-size box (Shape, etc) that will block the interaction. When dealing with nextStage, this is especially true, since we are passing on events that are unhandled by objects in the EaselJS display list.
A better approach might be to toggle the nextStage on stagemousedown, so it is null during the click event. Not sure if this will work, but its a start.

gwt canvas- handling events altogether differently

Gwt HTML5 Canvas wrapper can responds to mouse and keyboard events, it binds to 5 - 6 types of different events, my question is, it is possible to define entirely new event system such as CanvasEvent (and related handler CanvasEventHandler extends to GwtEvent etc), bind this to canvas object and then handle all events differently using a handler interface methods will be something like onDraw(), onDrag(), onMove(), onSelect() etc.
I dont have good clarity of GWT event system but i want to know is this possible without individuality attaching separate event handlers to form a logic for handling my problem, can I access all possible event as one consolidated object and fire custom event based on conditions. What would be the best way to do it, there are threads with GWT custom events but they include senders, whereas in my case sender is already present (Canvas)
Thanks much
Certainly - remember that all of the GwtEvent objects are completely artificial and are based off of events fired from the native JavaScript. That JavaScript event object, (which comes in via onBrowserEvent) gets wrapped up as a ClickEvent or a KeyDownEvent based on the details of the original object, and then fired off via the internal HandlerManager instance. In the same way, you could listen for a MouseDownEvent, set some state, then if a MouseMoveEvent occurs, fire your own CanvasDrag event. You'd probably stop listening to those move events once a MouseUpEvent happens, then you would issue something like a CanvasDropEvent. If isntead the MouseUpEvent occurred right away with no move, you could trigger a CanvasSelectEvent (or you might have something else in mind for that select event).
Each of these new event types you declare then might contain specifics about whatever is going on. For example, while a MouseMoveEvent just has the element that the mouse is over and the x/y coords, you might be indicating what is being dragged around the page. That might be in the form of the shape that was last clicked, or even the data it represents.
Yes, the 'sender', or source, is already there, but it'll be easier to use if you expose some kind of a method to add handlers like addCanvasDragHandler, etc. This is not required - all users of your code could just use addHandler, but it does make it a little ambiguous about whether or not the widget supports the event in question. You would then call fireEvent on the canvas object to make all handlers of that event type listen.
Or, you could make a new class that contains an internal Canvas widget - possibly a Composite object or just something that implements IsWidget (Canvas has a private constructor, so you can't subclass it). This would enable you to add your own particular handlers, and keep your own HandlerManager/EventBus to track the events you are concerned with.

using drag events to switch rectangles in a grid in windows phone 7.5

I've run in a bit of a pickle with my puzzle game for windows phone.
I want to change between two adjutant rectangles, both on the same grid.
The tap event was easily implemented, but implementing drag seems to be a really big pain.
I'm also using a custom user control to get the rectangles on the grid, so i need to create custom delegates before attaching events to my rectangle matrix.
I am currently using the manipulation completed and manipulation started events to implement the drag gesture, but there are a couple of problems:
1) i have to tell the difference between tap and actual drag, both which are covered by the manipulation completed event. This is the way I do it right now:
if (e.TotalManipulation.Translation.X == 0 && e.TotalManipulation.Translation.Y == 0)
{
}
else
{do drag stuff here}
however, the do drag stuff here part does not seem to work, even if the transitions are different from 0; It always executes the tap event.
I am currently stacked in using manipulation events, because, as i said, I am using a custom control as an object prototype for my rectangle matrix, and i need custom delegates for that, and apparently, the GestureListener has no constructors for its event classes.
So, any suggestion on how to do this?
I figured the answer just after posting this question.
You can actually attach a gesture listener to a custom control and create custom delegates, by sending the drag gesture event parameter from the gesture listener drag event to the delegate you create and it works.

What's the difference between logical events and native events in GWT?

I notice that there are two methods by which an event handler can be hooked up to a GWT widget: addHandler and addDomHandler. The JavaDoc for addDomHandler says, "Adds a native event handler to the widget and sinks the corresponding native event. If you do not want to sink the native event, use the generic addHandler method instead."
I'd be very grateful if someone would enlighten me as to the difference between native events and logical events.
Native events are fired directly by the browser - events like clicks, mouseovers, keypresses, etc. To receive those events on a Widget, you have to specifically sink the events.
The generic events are, well, more generic. For example, I've created a SaveEvent and a DeleteEvent for my own use, that get fired when certain UI conditions are met. They are farther away from the browser and would never get fired directly by the browser. I think you should stick with the more generic events when you can. On the other hand, if you're creating a custom widget that you can't make out of other widgets - for example, if you want to build a slider that the user can click and drag - you'll need the DOM events.

Global Mouse Moved Events in Cocoa

Is there a way to register for global mouse moved events in Cocoa? I was able to register for the events using Carbon's InstallEventHandler(), but would prefer a Cocoa equivalent. I have looked for NSNotificationCenter events, but there doesn't seem to be any public event names (are there private ones?)
Alternatively, is there a way to use NSTrackingArea for views with a clearColor background?
The app is Snow Leopard only.
In SnowLeopard there is a new class method on NSEvent which does exactly what you want: + (id)addGlobalMonitorForEventsMatchingMask:(NSEventMask)mask handler:(void (^)(NSEvent*))block. You’ll want mask = NSMouseMovedMask.
A similar question was already asked on StackOverflow:
How to make a transparent NSView subclass handle mouse events?
To summarize, the tansparent view method didn't work. Quartz Event Taps seem to be the best answer.
Here are some hints on working with taps:
Create the tap with CGEventTapCreate.
a) For the location (first) parameter you'll probably want to use kCGSessionEventTap.
b) For the placement (second) parameter you'll probably want kCGHeadInsertEventTap.
c) For the event mask parameter, try (1 << kCGEventMouseMoved).
Create a run loop source with CFMachPortCreateRunLoopSource, passing the event tap as the second parameter.
Add the run loop source to your run loop. Assuming you want it added to the main run loop, do:
CFRunLoopAddSource(CFRunLoopGetMain(), sourceFromStep2, kCFRunLoopDefaultMode);
Enable the event tap with CGEventTapEnable
If you want to track the mouse no matter where it is, you want a CGEventTap. There is no Cocoa equivalent. If you just want to track it in your application then you should explain why you're finding yourself unable to do so a little more thoroughly.

Resources