Etk
Main Page Object Hierarchy Data Structures Related Pages
Etk

Etk_Canvas


Detailed Description

The Etk_Canvas widget can contain any type of Evas_Object.

canvas.png
To add an object to a canvas, the object and the canvas should belong to the same evas. It means the canvas has to be realized when you create the objects. You can for example create the objects in a callback connected to the "realized" signal of the canvas widget.
 etk_signal_connect("realized", ETK_OBJECT(canvas), ETK_CALLBACK(canvas_realized_cb), NULL),

 void canvas_realized_cb(Etk_Widget *canvas, void *data)
 {
    Evas *evas;
    Evas_Object *obj;

    evas = etk_widget_toplevel_evas_get(canvas);
    obj = evas_object_rectangle_add(evas);
    etk_canvas_object_add(canvas, obj);
 }

Once an object is added to the canvas, you can use any evas_object_*() functions to control it.
You just have to keep in mind that calling evas_object_move() on an object belonging to the canvas will move the object relatively to the top-left corner of the window, and not to the top corner of the canvas itself.
So if you want to move your object to the position (200, 300) inside the canvas, you first have to get the position (cx, cy) of the canvas and then to move the object relatively to it:

 etk_widget_geometry_get(canvas, &cx, &cy, NULL, NULL);
 evas_object_move(object, cx + 200, cy + 300);

The function etk_canvas_object_move() does that for you.

When the canvas is moved, the objects belonging to it are automatically moved with it, but you might want to add a notification callback to the "geometry" property of the canvas widget, which will be called each time the geometry of the canvas is changed. That way, you can resize the objects when the size of the canvas is modified:

 etk_object_notification_callback_add(ETK_OBJECT(canvas), "geometry", canvas_geometry_changed_cb, NULL);

 void canvas_geometry_changed_cb(Etk_Object *canvas, const char *property_name, void *data)
 {
    int cx, cy, cw, ch;

     etk_widget_geometry_get(ETK_WIDGET(canvas), &cx, &cy, &cw, &ch);
    //Move and resize the evas objects here
 }

Object Hierarchy:
  • Etk_Object
    • Etk_Widget
      • Etk_Canvas


Data Structures

struct  Etk_Canvas
 [Widget] A widget that can contain any type of Evas_Object More...

Defines

#define ETK_CANVAS_TYPE   (etk_canvas_type_get())
#define ETK_CANVAS(obj)   (ETK_OBJECT_CAST((obj), ETK_CANVAS_TYPE, Etk_Canvas))
#define ETK_IS_CANVAS(obj)   (ETK_OBJECT_CHECK_TYPE((obj), ETK_CANVAS_TYPE))

Functions

Etk_Widget * etk_canvas_new (void)
 Creates a new canvas.
Etk_Bool etk_canvas_object_add (Etk_Canvas *canvas, Evas_Object *object)
 Adds an Evas object to the canvas. The object will be moved to the top left corner of the canvas and will be clipped against the canvas. You can then use any Evas function to control the object.
void etk_canvas_object_remove (Etk_Canvas *canvas, Evas_Object *object)
 Removes an Evas object from the canvas. The removed object will be automatically hidden.
void etk_canvas_object_move (Etk_Canvas *canvas, Evas_Object *object, int x, int y)
 Moves an Evas object to position ( x, y ), relatively to the canvas' top-left corner.
void etk_canvas_object_geometry_get (Etk_Canvas *canvas, Evas_Object *object, int *x, int *y, int *w, int *h)
 Gets the geometry of an Evas Object. The returned position will be relative to the canvas' top-left corner.


Define Documentation

#define ETK_CANVAS_TYPE   (etk_canvas_type_get())

Gets the type of a canvas

#define ETK_CANVAS ( obj   )     (ETK_OBJECT_CAST((obj), ETK_CANVAS_TYPE, Etk_Canvas))

Casts the object to an Etk_Canvas

#define ETK_IS_CANVAS ( obj   )     (ETK_OBJECT_CHECK_TYPE((obj), ETK_CANVAS_TYPE))

Checks if the object is an Etk_Canvas


Function Documentation

Etk_Widget * etk_canvas_new ( void   ) 

Creates a new canvas.

Returns:
Returns the new canvas widget

Etk_Bool etk_canvas_object_add ( Etk_Canvas *  canvas,
Evas_Object *  object 
)

Adds an Evas object to the canvas. The object will be moved to the top left corner of the canvas and will be clipped against the canvas. You can then use any Evas function to control the object.

Parameters:
canvas a canvas
object the object to add
Returns:
Returns ETK_TRUE on success, or ETK_FALSE on failure (probably because the canvas and the object do not belong to the same Evas)
Note:
The object will be automatically deleted when the canvas is destroyed
Warning:
The object position remains relative to the window, and not to the canvas itself (See the detailed description of Etk_Canvas, at the top of this page, for more information)

void etk_canvas_object_remove ( Etk_Canvas *  canvas,
Evas_Object *  object 
)

Removes an Evas object from the canvas. The removed object will be automatically hidden.

Parameters:
canvas a canvas
object the evas object to remove

void etk_canvas_object_move ( Etk_Canvas *  canvas,
Evas_Object *  object,
int  x,
int  y 
)

Moves an Evas object to position ( x, y ), relatively to the canvas' top-left corner.

Parameters:
canvas a canvas
object the object to move
x the x component of the position where to move the object, relative to the canvas' top-left corner
y the y component of the position where to move the object, relative to the canvas' top-left corner
Note:
You can still use evas_object_move() to move an object of the canvas, but the position passed to evas_object_move() is relative to the Evas, not to the canvas.

void etk_canvas_object_geometry_get ( Etk_Canvas *  canvas,
Evas_Object *  object,
int *  x,
int *  y,
int *  w,
int *  h 
)

Gets the geometry of an Evas Object. The returned position will be relative to the canvas' top-left corner.

Parameters:
canvas a canvas
object the object to get the geomtry of
x the location where to store the x component of the position of the object, relative to the canvas' top-left corner
y the location where to store the y component of the position of the object, relative to the canvas' top-left corner
w the location where to store the width of the object
h the location where to store the height of the object
Note:
You can still use evas_object_geometry_get(), but the position returned by evas_object_geometry_get() is relative to the Evas, not to the canvas.