Tizen Native API
|
In this example we illustrate how to interact with canvas' (and its objects') events, including the key input ones. We also demonstrate precise point collision on objects and canvas "obscured regions", here.
The example application consists of a window with a white background and an image -- the Enlightenment logo. The application begins with this image switching back and forth into two sizes: the exact canvas' size and one quarter of it (when it's placed on the top left quadrant). Thus, we'll have an animation going on, with image states set to change each 2 elapsed seconds.
There's a global variable to aid accessing our desired context variables from anywhere in the code:
What interests us there are the canvas
pointer, our image handle -- img
-- and the background one, bg
.
The first interesting thing on the example is the registration of a callback on each canvas resizing event, where we put our canvas' size and the background rectangle's one in synchrony, so that we don't get bogus content on rendering with canvas resizes:
Than, after grabbing our canvas pointer from the Ecore Evas helper infrastructure, we registrate an event callbacks on it:
- to resize the example's window (thus resizing the canvas' viewport)
- let the animation run
When one resizes the canvas, there's at least one operation it has to do which will require new calculation for rendering: the resizing of the background rectangle, in a callback we already shown you.
The creation of our background rectangle is so that we give it a name, via evas_object_name_set() and we give it the canvas focus:
Still exemplifying events and callbacks, we register a callback on the canvas event of an object being focused:
In that call, event_info
is going to be the focused object's handle, in this case our background rectangle. We print its name, so you can check it's the same. We check that pointer is the same reported by Evas' API with regard to the newest focused object. Finally, we check whether that object is really flagged as focused, now using an Evas object API function.
The animation we talked about comes from a timer we register just before we start the example's main loop. As we said, the resizing of the image will also force the canvas to repaint itself, thus flushing the rendering pipeline whenever the timer ticks:
ev->key
string (remember the event information struct for key down events is the Evas_Event_Key_Down one). There's one more trick for grabbing input events on this example -- evas_object_key_grab(). The 'c' command will, when firstly used, unfocus the background rectangle. Unfocused objects on an Evas canvas will never receive key events. We grab, then, the keys we're interested at to the object forcefully: What follows is the complete code for this example.