![]() | ![]() | ![]() | DiaCanvas2 Reference Manual | ![]() |
---|
DiaCanvasItem — Base class for objects placed in a DiaCanvas.
#define DIA_CANVAS_ITEM (obj) struct DiaCanvasItem; enum DiaCanvasItemFlags; enum DiaCanvasItemUIStateFlags; DiaCanvasItem* dia_canvas_item_create (GType type, const gchar *first_arg_name, ...); void dia_canvas_item_set_parent (DiaCanvasItem *item, DiaCanvasItem *new_parent); void dia_canvas_item_request_update (DiaCanvasItem *item); void dia_canvas_item_update_now (DiaCanvasItem *item); void dia_canvas_item_update_child (DiaCanvasItem *item, DiaCanvasItem *child, gdouble affine[6]); void dia_canvas_item_affine_w2i (DiaCanvasItem *item, gdouble affine[6]); void dia_canvas_item_affine_i2w (DiaCanvasItem *item, gdouble affine[6]); void dia_canvas_item_affine_point_i2w (DiaCanvasItem *item, gdouble *x, gdouble *y); void dia_canvas_item_affine_point_w2i (DiaCanvasItem *item, gdouble *x, gdouble *y); void dia_canvas_item_select (DiaCanvasItem *item); void dia_canvas_item_unselect (DiaCanvasItem *item); gboolean dia_canvas_item_is_selected (DiaCanvasItem *item); void dia_canvas_item_focus (DiaCanvasItem *item); void dia_canvas_item_unfocus (DiaCanvasItem *item); gboolean dia_canvas_item_is_focused (DiaCanvasItem *item); void dia_canvas_item_grab (DiaCanvasItem *item); void dia_canvas_item_ungrab (DiaCanvasItem *item); gboolean dia_canvas_item_is_grabbed (DiaCanvasItem *item); void dia_canvas_item_visible (DiaCanvasItem *item); void dia_canvas_item_invisible (DiaCanvasItem *item); gboolean dia_canvas_item_is_visible (DiaCanvasItem *item); void dia_canvas_item_identity (DiaCanvasItem *item); void dia_canvas_item_scale (DiaCanvasItem *item, gdouble sx, gdouble sy); void dia_canvas_item_rotate (DiaCanvasItem *item, gdouble degrees); void dia_canvas_item_shear_x (DiaCanvasItem *item, gdouble dx, gdouble dy); void dia_canvas_item_shear_y (DiaCanvasItem *item, gdouble dx, gdouble dy); void dia_canvas_item_move (DiaCanvasItem *item, gdouble dx, gdouble dy); void dia_canvas_item_move_interactive (DiaCanvasItem *item, gdouble dx, gdouble dy); void dia_canvas_item_flip (DiaCanvasItem *item, gboolean horz, gboolean vert); void dia_canvas_item_expand_bounds (DiaCanvasItem *item, gdouble d); gboolean dia_canvas_item_get_shape_iter (DiaCanvasItem *item, DiaCanvasIter *iter); gboolean dia_canvas_item_shape_next (DiaCanvasItem *item, DiaCanvasIter *iter); DiaShape* dia_canvas_item_shape_value (DiaCanvasItem *item, DiaCanvasIter *iter); gboolean dia_canvas_item_connect (DiaCanvasItem *item, DiaHandle *handle); gboolean dia_canvas_item_disconnect (DiaCanvasItem *item, DiaHandle *handle); gboolean dia_canvas_item_disconnect_handles (DiaCanvasItem *item); void dia_canvas_item_bb_affine (DiaCanvasItem *item, gdouble affine[6], gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2); void dia_canvas_item_update_handles_i2w (DiaCanvasItem *item); void dia_canvas_item_update_handles_w2i (DiaCanvasItem *item); void dia_canvas_item_preserve_property (DiaCanvasItem *item, const gchar *property_name); void dia_canvas_item_set_child_of (DiaCanvasItem *item, DiaCanvasItem *new_parent); #define DIA_CANVAS_ITEM_VISIBLE (obj) #define DIA_CANVAS_ITEM_INTERACTIVE (obj) #define DIA_CANVAS_ITEM_COMPOSITE (obj) #define DIA_CANVAS_ITEM_NEED_UPDATE (obj) #define DIA_CANVAS_ITEM_UPDATE_ALL (obj)
GObject +----DiaCanvasItem
"affine"DiaCanvasItemAffine : Read / Write "connect" DiaHandle : Write "disconnect" DiaHandle : Write "handles"DiaCanvasItemHandles : Read "parent" DiaCanvasItem : Read / Write "visible"gboolean : Read / Write
"connect"gboolean user_function (DiaCanvasItem *diacanvasitem, DiaHandle *arg1,gpointer user_data); "disconnect"gboolean user_function (DiaCanvasItem *diacanvasitem, DiaHandle *arg1,gpointer user_data); "event"gboolean user_function (DiaCanvasItem *diacanvasitem,gpointer arg1,gpointer user_data); "has-state"gboolean user_function (DiaCanvasItem *diacanvasitem,gint arg1,gpointer user_data); "move" void user_function (DiaCanvasItem *diacanvasitem,gdouble arg1,gdouble arg2,gboolean arg3,gpointer user_data); "need-update" void user_function (DiaCanvasItem *diacanvasitem,gpointer user_data); "state-changed" void user_function (DiaCanvasItem *diacanvasitem,gint arg1,gpointer user_data); "z-order" void user_function (DiaCanvasItem *diacanvasitem,gint arg1,gpointer user_data);
DiaCanvasItem is the base class for all objects added to a DiaCanvas. For those of you who know the GnomeCanvasItem: it's quite similar. This class defines a list of handles on the object, a list of shapes and a transformation matrix. The handles are used to modify the item (e.g. resize or rotate). The shapes define what the object looks like.
To make custom behavior possible a few callback functions are defined
in the
void update (DiaCanvasItem *item, gdouble affine[6])
This function is used to update the object's internal state. It is called during idle time. A canvas item should try to do as much work as possible here and not in, for example, a tool.
gboolean get_shape_iter (DiaCanvasItem *item, DiaCanvasIter *iter) gboolean shape_next (DiaCanvasItem *item, DiaCanvasIter *iter) DiaShape* shape_value (DiaCanvasItem *item, DiaCanvasIter *iter)
Iterate shapes that belong to a DiaCanvasItem. The caller should first call dia_canvas_item_get_shape_iter() to set the iterator to point to the first shape and call dia_canvas_item_shape_value() to retrieve the shape the iterator points to. Call dia_canvas_item_shape_next() to set the iterator to point to the next shape. FALSE is returned if there are no more shapes.
gdouble point (DiaCanvasItem *item, gdouble x, gdouble y)
This function is used to determine the precise distance from point (x, y) to the closest point on the object. The distance to the object is returned.
void move (DiaCanvasItem *item, gdouble dx, gdouble dy)
Move the object. This function usually doesn't need to be overwritten. This function is used to move the object. Moving is assigned a special callback, since is it common practice for programs to allow movement of multiple objects at one.
void handle_motion (DiaCanvasItem *item, DiaHandle *handle, gdouble *wx, gdouble *wy, DiaEventMask mask)
If a handle is moved this function is called before doing the actual movement. Point (wx, wy) is the handles new position in world (canvas) relative coordinates. This function is allowed to change the values. For example, if a handle may only be moved horizontal you could set wy to zero. Mask is the button mask that is used during the move (for example DiaCanvasElement also uses this function to rotate the object).
void glue (DiaCanvasItem *item, DiaHandle *handle, gdouble *wx, gdouble *wy)
If a handle is near an object, that object is asked if it wants to connect the handle. Gluing is the first step: the item calculates the point where the handle should connect and the distance between the handles current position and the connection point is returned. Once the handle is released (the mouse button is released) the handle will request a connection to the item by calling dia_canvas_item_connect(), which will emit the connect() signal. Handle is the handle that wants to connect. (wx, wy) is the point where the cursor is currently (in world coordinates). The object should determine the position where the handle could connect and place it's coordinates in (wx, wy). Just like the point() callback, the distance from the point to the connection point (the new (wx, wy)) is returned.
#define DIA_CANVAS_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CANVAS_ITEM, DiaCanvasItem))
obj : |
struct DiaCanvasItem;
DiaCanvasItem is the base class for all objects that are displayed in a DiaCanvasView. DiaCanvasItems are held by a DiaCanvas. Since a DiaCanvas can have more than one view, every view holds some custom information in a DiaCanvasViewItem. If a DiaCanvasView is provided with a DiaHandleLayer, the canvas is able to view the handle and sent events to the handles.
typedef enum { DIA_VISIBLE = 1, DIA_INTERACTIVE = 1 << 1, DIA_COMPOSITE = 1 << 2, DIA_NEED_UPDATE = 1 << 3, DIA_UPDATE_ALL = 1 << 4 } DiaCanvasItemFlags;
Flags that can be set on a DiaCanvasItem.
DIA_VISIBLE | If true, the item is visible. (default=TRUE) |
DIA_INTERACTIVE | If true, the item has interactive capabilities (it can handle events). (Default=TRUE). |
DIA_COMPOSITE | The item is an aggregate of it's parent. This means that if the item is selected or gets the focus, the parent will act and draw as if it was selected itself. (Default=FALSE) |
DIA_NEED_UPDATE | The item's update method should be executed. This flag is set by dia_canvas_item_request_update(). It should not be set in the constructor. |
DIA_UPDATE_ALL | Tell that all child objects (if any) have been requesting an update. This flag is used to optimize update requests. |
typedef enum { DIA_UI_STATE_UNSELECTED, DIA_UI_STATE_SELECTED, DIA_UI_STATE_FOCUSED, DIA_UI_STATE_GRABBED, /* State UNCHANGED indicates that no changes have taken place. */ DIA_UI_STATE_UNCHANGED } DiaCanvasItemUIStateFlags;
DiaCanvasItem* dia_canvas_item_create (GType type, constgchar *first_arg_name, ...);
Create a new canvas item. You can assign addional properties to the item.
type : | Type of the new item, should be a DiaCanvasItem child. |
first_arg_name : | |
... : | |
Returns : | A newly created canvas item. |
void dia_canvas_item_set_parent (DiaCanvasItem *item, DiaCanvasItem *new_parent);
Set a (new) parent for the item.
item : | |
new_parent : | new parent or NULL in case of disconnect |
void dia_canvas_item_request_update (DiaCanvasItem *item);
Schedule an update for the item. If the item has children, they are scheduled for an update too.
item : | item that needs an update |
void dia_canvas_item_update_now (DiaCanvasItem *item);
Force an update of the item.
item : | Item to update |
void dia_canvas_item_update_child (DiaCanvasItem *item, DiaCanvasItem *child,gdouble affine[6]);
This function can be used in the item's update to trigger updates of a subitem (child).
item : | Canvas item |
child : | Canvas item, a child of item |
affine : | transformation matrix of item |
void dia_canvas_item_affine_w2i (DiaCanvasItem *item,gdouble affine[6]);
Return the affine transformation needed to convert world coordinates to item relative coordinates.
item : | |
affine : | OUT |
void dia_canvas_item_affine_i2w (DiaCanvasItem *item,gdouble affine[6]);
Calculate the affine transformation that is nessesary to convert a point from item coordinates to world coordinates.
item : | |
affine : | OUT |
void dia_canvas_item_affine_point_i2w (DiaCanvasItem *item,gdouble *x,gdouble *y);
Convert a point (x, y) from item to world coordinates.
item : | |
x : | |
y : |
void dia_canvas_item_affine_point_w2i (DiaCanvasItem *item,gdouble *x,gdouble *y);
Convert a point (x, y) from world coordinates to item relative coordinates.
item : | |
x : | |
y : |
void dia_canvas_item_select (DiaCanvasItem *item);
Select item. More than one item can be selected (usualy by holding the SHIFT or CONTROL button while selecting an item). The root item can not be selected.
item : |
void dia_canvas_item_unselect (DiaCanvasItem *item);
Unselect item.
item : |
gboolean dia_canvas_item_is_selected (DiaCanvasItem *item);
item : | |
Returns : |
void dia_canvas_item_focus (DiaCanvasItem *item);
item becomes the focused item. A focused item is also selected, but it has the privilege of being the last object that was selected.
item : |
void dia_canvas_item_unfocus (DiaCanvasItem *item);
Unfocus the focused object.
item : |
gboolean dia_canvas_item_is_focused (DiaCanvasItem *item);
item : | |
Returns : |
void dia_canvas_item_grab (DiaCanvasItem *item);
Make item the grabbed item. The grabbed item is also selected and also has the focus. A grabbed item will recieve all events send to the canvas, even if the event is not even near item.
item : |
void dia_canvas_item_ungrab (DiaCanvasItem *item);
Ungrab the item. Inverse of
item : |
gboolean dia_canvas_item_is_grabbed (DiaCanvasItem *item);
item : | |
Returns : |
void dia_canvas_item_visible (DiaCanvasItem *item);
Make item visible.
item : |
void dia_canvas_item_invisible (DiaCanvasItem *item);
Make item invisible.
item : |
gboolean dia_canvas_item_is_visible (DiaCanvasItem *item);
item : | |
Returns : |
void dia_canvas_item_identity (DiaCanvasItem *item);
Remove all transformations from item.
item : |
void dia_canvas_item_scale (DiaCanvasItem *item,gdouble sx,gdouble sy);
Scale the object. The objects center of its bounding box will not move.
item : | |
sx : | |
sy : |
void dia_canvas_item_rotate (DiaCanvasItem *item,gdouble degrees);
Rotate item around the center of its bounding box.
item : | |
degrees : |
void dia_canvas_item_shear_x (DiaCanvasItem *item,gdouble dx,gdouble dy);
Shear the object.
item : | |
dx : | |
dy : |
void dia_canvas_item_shear_y (DiaCanvasItem *item,gdouble dx,gdouble dy);
Like dia_canvas_item_shear_x(), but now for the y axis.
item : | |
dx : | |
dy : |
void dia_canvas_item_move (DiaCanvasItem *item,gdouble dx,gdouble dy);
Move item. Use dia_canvas_item_move_interactive() in event handlers.
item : | |
dx : | |
dy : |
void dia_canvas_item_move_interactive (DiaCanvasItem *item,gdouble dx,gdouble dy);
Move item. This function raises the DiaCanvas::move signal, which is caught by the active DiaCanvasView. The view will request all selected objects to move.
This function should be used in event handlers.
item : | |
dx : | |
dy : |
void dia_canvas_item_flip (DiaCanvasItem *item,gboolean horz,gboolean vert);
Flip item around its horizontal and/or vertical axis.
item : | |
horz : | |
vert : |
void dia_canvas_item_expand_bounds (DiaCanvasItem *item,gdouble d);
Expand the bounding box of item in all four directions. This is convenient if you have drawn a shape that comes out of the bounding box a little bit.
item : | |
d : | number to expand the bounding box with |
gboolean dia_canvas_item_get_shape_iter (DiaCanvasItem *item, DiaCanvasIter *iter);
item : | |
iter : | |
Returns : | The first shape to be drawn. |
gboolean dia_canvas_item_shape_next (DiaCanvasItem *item, DiaCanvasIter *iter);
item : | |
iter : | |
Returns : |
DiaShape* dia_canvas_item_shape_value (DiaCanvasItem *item, DiaCanvasIter *iter);
item : | |
iter : | |
Returns : | The value that corresponds with the values of the iterator. |
gboolean dia_canvas_item_connect (DiaCanvasItem *item, DiaHandle *handle);
Connect handle to item. Item should not be the owner of handle. If the "connect" signal returns FALSE, the object will not be connected.
During the connection process, a position for handle is calculated and
the handle is moved to that position (so it is not nessesary to do a
item : | |
handle : | |
Returns : | TRUE on success, FALSE otherwise. |
gboolean dia_canvas_item_disconnect (DiaCanvasItem *item, DiaHandle *handle);
Disconnect handle from item. handle->connected_to should be the same object as item.
item : | item the handle is connected too. |
handle : | handle to be disconnected from item. |
Returns : | TRUE on success, FALSE of failure. |
gboolean dia_canvas_item_disconnect_handles (DiaCanvasItem *item);
Disconnect all handles of item. Note that this function disconnects all handles that belong to item, while dia_canvas_item_disconnect() disconnects a handle that is connected to an item!
item : | |
Returns : | TRUE if no handles are connected, FALSE otherwise. |
void dia_canvas_item_bb_affine (DiaCanvasItem *item,gdouble affine[6],gdouble *x1,gdouble *y1,gdouble *x2,gdouble *y2);
Calculate the bounding box of item after a affine transformation.
item : | |
affine : | |
x1 : | OUT |
y1 : | OUT |
x2 : | OUT |
y2 : | OUT |
void dia_canvas_item_update_handles_i2w (DiaCanvasItem *item);
Sync the world coordinates and the item coordinates for all handles of item.
item : |
void dia_canvas_item_update_handles_w2i (DiaCanvasItem *item);
Sync all handles item coordinates to their world coordinates.
item : |
void dia_canvas_item_preserve_property (DiaCanvasItem *item, constgchar *property_name);
Shorthand for dia_canvas_preserve_property(). It adds a property to the canvas' undo stack.
item : | |
property_name : |
void dia_canvas_item_set_child_of (DiaCanvasItem *item, DiaCanvasItem *new_parent);
Set a (new) parent for the item. This implies setting the
The parent should implement the DiaCanvasGroupable interface. Applications should use dia_canvas_groupable_add() and dia_canvas_groupable_remove() to add and remove items in a group. This function should be used in the DiaCanvasGroupable::add and #::remove implementations to create the actual parent-child relationship.
NOTE: This function is not a substitute for the 'parent' property.
item : | |
new_parent : | new parent or NULL in case of disconnect |
#define DIA_CANVAS_ITEM_VISIBLE(obj) ((DIA_CANVAS_ITEM_FLAGS (obj) & DIA_VISIBLE) != 0)
The canvas item is visible. Canvas items that are not visible will not recieve events, nor will their child objects be visible.
obj : |
#define DIA_CANVAS_ITEM_INTERACTIVE(obj) ((DIA_CANVAS_ITEM_FLAGS (obj) & DIA_INTERACTIVE) != 0)
obj : |
#define DIA_CANVAS_ITEM_COMPOSITE(obj) ((DIA_CANVAS_ITEM_FLAGS (obj) & DIA_COMPOSITE) != 0)
obj : |
#define DIA_CANVAS_ITEM_NEED_UPDATE(obj) ((DIA_CANVAS_ITEM_FLAGS (obj) & DIA_NEED_UPDATE) != 0)
The canvas item needs updating. When calling dia_canvas_update_now() it
will update (by calling the
obj : |
"affine" ( |
|
"connect" (DiaHandle : Write) | Connect a handle to this item. This property should only be used by the undo mechanism. |
"disconnect" (DiaHandle : Write) | Disconnect a handle to this item. This property should only be used by the undo mechanism. |
"handles" ( | Get a list of handles applied to the canvas item. Note that this list is a copy of the list owned by the canvas item. You should free the list and unref the handles in it. |
"parent" (DiaCanvasItem : Read / Write) |
|
"visible" ( | Set the item visible or invisible. |
gboolean user_function (DiaCanvasItem *diacanvasitem, DiaHandle *arg1,gpointer user_data);
Connect a handle to the canvas item.
diacanvasitem : | the object which received the signal. |
arg1 : | |
user_data : | user data set when the signal handler was connected. |
Returns : |
gboolean user_function (DiaCanvasItem *diacanvasitem, DiaHandle *arg1,gpointer user_data);
This signal is emitted by the canvas item when a DiaHandle has been disconnected. If the emission is stopped, the handle is not disconnected.
diacanvasitem : | the object which received the signal. |
arg1 : | |
user_data : | user data set when the signal handler was connected. |
Returns : |
gboolean user_function (DiaCanvasItem *diacanvasitem,gpointer arg1,gpointer user_data);
The event signal is the controller between the DiaCanvasItem (model) and the DiaCanvasViewItem (view). It is used to handle (user-)events, such as mouse button and key presses.
item : | the object which received the signal. |
event : | The |
user_data : | user data set when the signal handler was connected. |
Returns : | TRUE if the event is successfully handled. FALSE if the event is not handled and should be handled by the item's parent. |
gboolean user_function (DiaCanvasItem *diacanvasitem,gint arg1,gpointer user_data);
diacanvasitem : | the object which received the signal. |
arg1 : | |
user_data : | user data set when the signal handler was connected. |
Returns : |
void user_function (DiaCanvasItem *diacanvasitem,gdouble arg1,gdouble arg2,gboolean arg3,gpointer user_data);
diacanvasitem : | the object which received the signal. |
dx : | relative movement |
dy : | relative movement |
interactive : | The movement is due to an action by the user |
user_data : | user data set when the signal handler was connected. |
void user_function (DiaCanvasItem *diacanvasitem,gpointer user_data);
Notify all views that the item needs to be updated.
diacanvasitem : | the object which received the signal. |
user_data : | user data set when the signal handler was connected. |
void user_function (DiaCanvasItem *diacanvasitem,gint arg1,gpointer user_data);
The state of the object has changed. This signal is used to notify the views that the item's state has been changed. The following properties can be changed: DIA_VISIBLE, DIA_SELECT, DIA_FOCUS, DIA_GRAB. The visibility will affect all views, whereas the select, focus and grab properties will only affect the active view (the one the user is working on). Those properties only have effect when set in the event() handler of the item, visibility can always be changed.
item : | the object which received the signal. |
new_state : | The new state for the (view)items. |
user_data : | user data set when the signal handler was connected. |
void user_function (DiaCanvasItem *diacanvasitem,gint arg1,gpointer user_data);
The item has been raised/lowered with respect to its siblings.
diacanvasitem : | the object which received the signal. |
position : | Number of places it has been changed. A possitive value indicates raising, negative values indicate lowering. |
user_data : | user data set when the signal handler was connected. |
<< DiaCanvasEditable | DiaCanvasGroup >> |