Emmabuntus, Ubuntu, Derivate, Linux, Open Source BackTrack, Linux, distributions, Ubuntu, derivate, securuty, forensic VirtualBox, Linux, Ubuntu, Raring Ringtail synaptic, Ubuntu, Linux, software packages jwplayer, multimedia, Linux, Ubuntu, flash Meshlab, graphic, software, Ubuntu, open source, Linux Synapse, Linux, Ubuntu, raring, Quantal Gimp, Ubuntu, Linux FreeMind, Linux, open source Linux, infographic, history

Introduction to the Gnome Canvas Widget


Introduction to the Canvas
The canvas widget is a powerful and extensible object-oriented display engine, useful in a wide variety of Gnome applications. The widget itself is simply a blank area; you can place GnomeCanvasItems on it. A GnomeCanvasItem is a GtkObject representing some element of the display, such as an image, a rectangle, an ellipse, or some text. You can refer to this architecture as structured graphics; the canvas lets you deal with graphics in terms of items, rather than an undifferentiated grid of pixels.

Since a GnomeCanvasItem is a GtkObject, you can create your own subclasses to supplement those that come with Gnome. This gives you quite a bit of exibility.

800 Image_Holiday

Using custom canvas items, the canvas can render almost anything. At the same time, you can use stock canvas items to save time and effort. The canvas puts you in control.

GnomeCanvas has two modes, representing a quality/speed tradeoff. In "GDK" mode, canvas items render directly to a GdkPixmap buffer using the GDK drawing primitives. The canvas copies the buffer to the screen once all items are rendered. In antialiased or "AA" mode, the canvas items write RGB pixels to a vector of bytes; after all the items have drawn on the RGB buffer, the canvas copies it to the screen. This RGB buffer mode is called "antialiased" mode because all the standard canvas items draw to the RGB buffer using the high-quality antialiased routines in libart_lgpl.

This results in smooth lines and very high display quality, with some cost in speed.

Basic Canvas Architecture
This section introduces the architecture of the canvas, including the arrangement of items into hierarchical groups, and the many coordinate systems involved in using the canvas.

GnomeCanvasGroup
Canvas items are arranged in a tree structure. You can group items together, to be moved as a unit; canvas architect Federico Mena Quintero likes to use a circuit diagram editor as an example. You might group together the shapes representing each logic gate, so you could manipulate the logic gate as a unit. You could also collect several logic gates into a single component; that is, groups can contain subgroups.

Within each group, the canvas maintains a stacking order; objects higher in the stacking order obscure objects lower in the stacking order.

To implement this, the canvas comes with a special kind of canvas item called GnomeCanvasGroup. As the name suggests, a canvas group groups a number canvas items together so you can manipulate the child items as a single item.

A GnomeCanvasGroup is invisible; to render itself, it simply recurses its children, rendering each of them in turn. When you create a new GnomeCanvas, a default group called the "root" is created for you. All canvas items are added somewhere below the root group. The canvas widget only deals with the root canvas item directly; all other canvas items are managed by their parent group.

An accessor function is provided to access the root canvas group, shown in Figure

L'immagine “http://img.mediastay.com/m/kingoloto/it/CONCORSO/728x90_kingolotto.gif” non può essere visualizzata poiché contiene degli errori.
#include
GnomeCanvasGroup* gnome_canvas_root(GnomeCanvas* canvas);
Root Group Accessor
Items must always be part of a group; there is no such thing as an "orphan" canvas item. When you create an item, you must specify its canvas group. It is also possible to reparent items after creation. However, items are permanently bound to the GnomeCanvas they were created on; it is not permitted to reparent an item to a group on a different canvas.

Coordinates Many of the features of the canvas are implemented via translations between different coordinate systems. Canvas items can be moved, rotated, or scaled via affine transformations, described in more detail below. (Short version: an affine transformation is a way to convert from one coordinate system to another.)

Here are the important coordinate systems which come up when using the canvas and writing custom canvas items:
• World coordinates are an absolute coordinate system; i.e., the same world coordinate refers to the same place on the canvas in all cases. World coordinates are conceptually infinite and are represented by a double. World coordinates are the real, toplevel, untransformed, canonical coordinate system. Consistent with the X Window System and GDK, Y coordinates increase as they move downward, so lower Y coordinates are toward the top of the canvas.
• Item coordinates are the coordinates used by a particular canvas item.

Item coordinates exist because each canvas item has an affine transformation associated with it. In the case of GnomeCanvasGroup, this transformation is applied to the group’s children. To convert from world coordinates to item coordinates for some particular item, you apply the transform for each canvas group in the item’s ancestry, starting with the root canvas group; then you apply the item’s own transform.

(Don’t worry, Gnome comes with a function to do this for you.) Like world coordinates, item coordinates are conceptually infinite.

• Canvas coordinates are pixel coordinates. While item and world coordinates are oating-point numbers, canvas pixel coordinates are integers. To use the canvas, you must specify a "scroll region," which is the rectangle in world coordinate space you want the user to be able to see. Canvas pixel coordinates are relative to this rectangle. Canvas pixel coordinates also take into account a scaling factor representing the number of pixels per world coordinate unit. To convert from world coordinates to canvas coordinates, the canvas subtracts the X and Y coordinates of the scroll region, multiplies by the scaling factor, and then rounds to an integer.

Thus, (0,0) in canvas coordinates will be the top left corner of the scroll region.

• Buffer coordinates are canvas coordinates modified by some offset. Item implementations use these during rendering. The canvas passes the item implementation a buffer (which is either a GdkDrawable or an RGB buffer, depending on the canvas mode). The canvas tells the item implementation which region of the screen the buffer represents—the buffer region is defined by an X offset, Y offset, width and height.

The X and Y offsets are in canvas coordinates, and are equivalent to (0,0) in buffer coordinates. To convert from canvas coordinates to buffer coordinates, simply subtract the offset. Buffer coordinates are only valid from (0,0) to
the maximum width and height of the buffer.

• Window coordinates are rarely used. The canvas eventually copies each temporary buffer to a GdkWindow (to be precise,it copies them to GTK_LAYOUT(canvas) >bin_window). Window coordinates are relative to this GdkWindow. In some rare cases you might want to draw to the window directly rather than using a canvas item, or you might want to respond to an event on the window (such as a drag- and-drop). Then you need to convert from window coordinates to one of the other coordinate systems.

728x90_donna_gif
When using preexisting canvas items, you will mostly be interested in world and item coordinates. When writing your own items, you will also need to use canvas and buffer coordinates.

There are two ways to convert between the various coordinate systems; one way is to obtain and use affines directly—this is described in the next section. The easy way is to use one of the convenience functions provided for the purpose.

Conversion between canvas and item coordinates requires you to convert to world coordinates first as an intermediate step. There is no function to convert to or from buffer coordinates, because this is a simple matter of subtracting the buffer offsets from the canvas coordinates (canvas to buffer), or adding the buffer offsets to the buffer coordinates (buffer to canvas).
#include
void gnome_canvas_w2c(GnomeCanvas* canvas, double wx, double wy, int* cx,
int* cy);
void gnome_canvas_w2c_d(GnomeCanvas* canvas, double wx, double wy, dou-
ble* cx, double* cy); void gnome_canvas_c2w(GnomeCanvas* canvas, int cx, int cy, double* wx, dou-
ble* wy);
void gnome_canvas_item_w2i(GnomeCanvasItem* item, double* x, double* y);
void gnome_canvas_item_i2w(GnomeCanvasItem* item, double* x, double* y);
void gnome_canvas_window_to_world(GnomeCanvas* canvas, double winx, dou-
ble winy, double* worldx, double* worldy);
void gnome_canvas_world_to_window(GnomeCanvas* canvas, double worldx, double worldy, double* winx, double* winy);

Coordinate Conversions Affine Transformations
An affine is a transformation matrix made up of six real numbers that can be applied to an ordered pair. Depending on the contents of the affine, the point it is applied to can be:
• translated—shifted by an arbitrary distance in either dimension;
• rotated some number of degrees;
• scaled by some factor.

Conceptually, an affine defines a relationship between points on a plane. For any point (A,B), the affine defines a single corresponding transformed point; the mapping is one-to-one, so given the transformed point you can determine the original point.

Affines have interesting properties that make them useful in computer graphics.
Most importantly, they can be composed, concatenated, or multiplied (the three terms are synonymous). You can compose any number of affines to create a single affine; applying the single affine has the same effect as applying each of the original affines in order. Note that the order of composition is important! Unlike multiplication, affine composition is not commutative (which is a reason to avoid the term "multiply" in this context).

L'immagine “http://hst.tradedoubler.com/file/77661/728X90.gif” non può essere visualizzata poiché contiene degli errori.
libart_lgpl contains a module for affine manipulation. It represents affines as an array of six doubles. Its affine functions are shown in
#include
void art_affine_point(ArtPoint* dst, const ArtPoint* src, const double affine[6]);
void art_affine_invert(double dst_affine[6], const double src_affine[6]);
void art_affine_multiply(double dst[6], const double src1[6], const dou-
ble src2[6]);
void art_affine_identity(double dst[6]);
void art_affine_scale(double dst[6], double sx, double sy);
void art_affine_rotate(double dst[6], double theta);
void art_affine_translate(double dst[6], double tx, double ty);
int art_affine_rectilinear(const double src[6]);

Affine Manipulation
art_affine_point() applies an affine to a point. The affine is applied to the second argument (src) and the result is copied into the first argument (dst). An ArtPoint is simply:
typedef struct _ArtPoint ArtPoint;
struct _ArtPoint {
double x, y;
};
Affines can be inverted. If an affine converts points in coordinate system A into points in coordinate system B, its inverse converts points in coordinate system B into points in coordinate system A. art_affine_invert() fills its first argument with the in-
verse of its second.
art_affine_multiply() composes two affines as described earlier in this section, placing the result in its first argument.
Four functions are provided to create affines with particular properties.
• art_affine_identity() creates the identity affine. Applying the identity affine to a point has no effect.
• art_affine_rotate() gives an affine that rotates points by theta degrees.
• art_affine_translate() gives an affine that translates points tx in the X dimension and ty in the Y dimension.
• art_affine_scale() gives an affine which scales the plane by the given factors
(a factor of 1.0 does no scaling, less than 1.0 shrinks, greater than 1.0 expands).
art_affine_rectilinear() returns TRUE if the affine rotates rectangles aligned to
the axes in such a way that they remain aligned to the axes. That is, it returns TRUE if the rotation is 0, 90, 180, or 270 degrees.
You can ask the canvas widget to compute affines which convert between its various coordinate systems. These functions are shown in Figure 12-4; each of them fills an array you pass in with the affine being requested.
#include
void gnome_canvas_item_i2w_affine(GnomeCanvasItem* item, double affine[6]);
void gnome_canvas_item_i2c_affine(GnomeCanvasItem* item, double affine[6]);
void gnome_canvas_w2c_affine(GnomeCanvas* canvas, double affine[6]);

Canvas Affines Using the Canvas
GnomeCanvas is easy to use; this is its virtue compared to GtkDrawingArea or some other low-level approach. This section describes how to create a canvas, and work with canvas items. It ends with a programming example.

Preparing the GnomeCanvas Widget
The first decision you have to make is whether to use the canvas in GDK mode or antialiased mode. When you create a canvas widget, you must specify the mode you want; there is no way to change it later. gnome_canvas_new() creates a GDK canvas.
gnome_canvas_new_aa() creates an antialiased canvas.
Sometimes it matters which visual and colormap the canvas will use. In particular:
• In GDK mode, if you want to use the GnomeCanvasImage item to display images, you must use Imlib’s visual and colormap. GnomeCanvasImage uses Imlib to render images.
• In antialiased mode, GDK’s RGB buffer rendering facilities (see the section called RGB Buffers in Chapter 10) are used to copy the RGB buffer to the screen. You must use the visual and colormap from the GDK RGB module.
To create a widget with a non-default visual and colormap, gtk_widget_push_visual() and gtk_widget_push_colormap() are used. Here is the code to create a GDK canvas that supports the image item:
GtkWidget* canvas;
gtk_widget_push_visual(gdk_imlib_get_visual());
gtk_widget_push_colormap(gdk_imlib_get_colormap());
canvas = gnome_canvas_new();
gtk_widget_pop_visual();
gtk_widget_pop_colormap();

222 CleanGreen-728x90-trans.jpg

To create an antialiased canvas, do this:
GtkWidget* canvas;
gtk_widget_push_visual(gdk_rgb_get_visual());
gtk_widget_push_colormap(gdk_rgb_get_cmap());
canvas = gnome_canvas_new_aa();
gtk_widget_pop_colormap();
gtk_widget_pop_visual();
#include
GtkWidget* gnome_canvas_new(void);
GtkWidget* gnome_canvas_new_aa(void);

Canvas Constructors Scroll Region
The canvas is practically infinite from a programmer ’s standpoint; however, in reality your application probably uses only a small area. When using the canvas you must specify which region is interesting to the user with gnome_canvas_set_scroll_region()
The scroll region is given in world coordinates. You can query the scroll region with gnome_canvas_get_scroll_region().
To add scroll bars to the canvas, simply create a GtkScrolledWindow and add the
canvas to it:
GtkWidget* sw;
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(sw), canvas);
If you want to implement scrolling via some mechanism other than the scroll bars, you can get and set the "scroll offsets." The scroll offsets are in canvas pixel coordinates; they specify the top left visible pixel. Remember that canvas pixel coordinates
are relative to the scroll region.
#include
void gnome_canvas_set_scroll_region(GnomeCanvas* canvas, double x1, double y1, double x2, double y2);
void gnome_canvas_get_scroll_region(GnomeCanvas* canvas, double* x1, double* y1, double* x2, double* y2);
void gnome_canvas_scroll_to(GnomeCanvas* canvas, gint cx, gint cy );
void gnome_canvas_get_scroll_offsets(GnomeCanvas* canvas, gint* cx, gint*
cy);

Canvas Scrolling Zooming
The canvas gives you zooming "for free"; it is included in the world-to-canvas and canvas-to-world coordinate system conversions. You can set the zoom factor with gnome_canvas_set_pixels_per_unit(). By default, there ratio of pixels to canvas units is 1.0, meaning no zoom. Specifying a value less than 1.0 means reduced size; greater than 1.0 means increased size.
In antialiased mode, you could achieve the same visual effect by applying a scaling affine transformation to the root canvas group. The pixels_per_unit member of the GnomeCanvas struct predates the canvas’s use of affines. Still, gnome_canvas_set_pixels_per_unit()
is a bit more convenient than the affine transform method, and it does work in GDK mode. (Because GDK mode uses Xlib primitives, it’s nontrivial to implement arbitrary affine transformations; a future version of Gnome may do so, however.)
#include
void gnome_canvas_set_pixels_per_unit(GnomeCanvas* canvas, double ppu);

Canvas Zooming Canvas Items
Most of the time you will be interested in canvas items rather than the canvas itself.
Canvas items are typically very easy to use, compared to widgets; none of the standard items have any unique signals, since they are not interactive. (Since GnomeCanvasItem is a subclass of GtkObject, however, you could certainly have an item with signals if you wanted to.) The GnomeCanvasItem base class has a single signal, "event", which is used to convey all types of event. The "event" signal has no default handler; canvas items do not respond to events unless you connect handlers of your own. Figure 12-8 lists all the useful functions for working with the

Scarica subito!
GnomeCanvasItem base class.
To create a canvas item, you use the generic gnome_canvas_item_new() (or gnome_canvas_item_newv()).
This function accepts the group to place the item in, the GtkType of the GnomeCanvasItem subclass to create, and finally a NULL-terminated list of arguments to set. The argument list is purely for convenience, so you don’t have to call gnome_canvas_item_set()
immediately. gnome_canvas_item_new() creates a new instance of the type with gtk_type_new(), adds the item to its GnomeCanvasGroup, and schedules it to be redrawn.
To destroy an item and remove it from the canvas, simply call gtk_object_destroy().
You can also use the standard reference counting mechanism with canvas items.
You can set an item’s affine using gnome_canvas_item_affine_absolute(), or compose a new affine with the item’s existing affine using gnome_canvas_item_affine_relative().
These functions can be used to translate, scale, or rotate a canvas item (however, scaling and rotation only work in antialiased mode).

Items in a group are normally stacked in the order you add them, with the most recently-added item "on top" and the oldest item on the bottom. You can manipulate the stacking order with gnome_canvas_item_raise() and gnome_canvas_item_lower().
These move an item up or down by the given number of positions. It is safe to pass in a too-large value for positions; the item will be moved as far as possible and no more. You can also request that an item is moved to one extreme or the other, using
gnome_canvas_item_raise_to_top() and gnome_canvas_item_lower_to_bottom.
Items can be shown and hidden; hidden items are not rendered by the canvas and do not receive events. All items are visible by default. The routines are gnome_canvas_item_show() and gnome_canvas_item_hide().
Reparenting a canvas item is straightforward; the only rule is that the new group must be on the same canvas as the old group.

gnome_canvas_item_grab_focus() is analagous to gtk_widget_grab_focus(); it sends all key events to the item with the grab. It also sends focus change events to the item (when the item gains or loses the focus).
Canvas items can grab and ungrab the mouse pointer just as a GdkWindow can; the arguments to gnome_canvas_item_grab() are exactly analagous to those of gdk_pointer_grab().
While a canvas item has the pointer grabbed, no other item receives events. Behind the scenes, GnomeCanvas uses gdk_pointer_grab() to implement gnome_canvas_item_grab(), so an item grabbing the mouse away from other items implies the canvas grabbing the mouse away from other widgets.

Two functions are used to set canvas item properties: gnome_canvas_item_set()
and gnome_canvas_item_setv(). These are almost but not quite equivalent to gtk_object_set()
and gtk_object_setv()—they set object arguments in the same way, but they also mark the canvas item to be redrawn. So you should prefer them to the GtkObject variants. (This is something of a design bug, and future canvas versions will most
likely allow you to use gtk_object_set().)
gnome_canvas_item_request_update() marks the canvas item as "dirty" and queues it to be redrawn. Internally, the canvas uses a one-shot idle function to perform redraws; that is, it waits until no more GTK+ events are pending, then redraws itself a single time. It does this by installing an idle function with gtk_idle_add() and removing it after it runs once. Thus gnome_canvas_item_request_update() can be called many times without creating an efficiency problem—it pretty much does nothing at all if an update is already pending.
#include
GnomeCanvasItem* gnome_canvas_item_new(GnomeCanvasGroup* parent, GtkType type, const gchar* first_arg_name, ...);
GnomeCanvasItem* gnome_canvas_item_newv(GnomeCanvasGroup* parent, GtkType type, guint nargs, GtkArg* args);
void gnome_canvas_item_set(GnomeCanvasItem* item, const gchar* first_arg_name, ...);
void gnome_canvas_item_setv(GnomeCanvasItem* item, guint nargs, GtkArg* args);
void gnome_canvas_item_affine_relative(GnomeCanvasItem* item, const double affine[6]);
void gnome_canvas_item_affine_absolute(GnomeCanvasItem* item, const double
affine[6]);
void gnome_canvas_item_raise(GnomeCanvasItem* item, int positions);
void gnome_canvas_item_lower(GnomeCanvasItem* item, int positions);
void gnome_canvas_item_raise_to_top(GnomeCanvasItem* item);
void gnome_canvas_item_lower_to_bottom(GnomeCanvasItem* item);
void gnome_canvas_item_show(GnomeCanvasItem* item);
void gnome_canvas_item_hide(GnomeCanvasItem* item);
void gnome_canvas_item_reparent(GnomeCanvasItem* item, GnomeCanvasGroup*

Vola50_3

new_group);
void gnome_canvas_item_grab_focus(GnomeCanvasItem* item);
int gnome_canvas_item_grab(GnomeCanvasItem* item, unsigned int event_mask, GdkCursor* cursor, guint32 etime);
void gnome_canvas_item_ungrab(GnomeCanvasItem* item, guint32 etime);
void gnome_canvas_item_get_bounds(GnomeCanvasItem* item, double* x1, double* y1, double* x2, double* y2);
void gnome_canvas_item_request_update(GnomeCanvasItem* item);
Using GnomeCanvasItem Canvas Items and Events
The standard Gnome canvas items have only one signal, "event", which is emitted for all types of event. The canvas widget preprocesses all GDK events that it receives, and forwards some of them to canvas items. It also sythesizes certain events. Remember
that X sends events only to X windows (GdkWindows), and canvas items do not have an associated GdkWindow. Thus the canvas widget must act as intermediary. Here are some of the actions it takes:
• Coordinates are automatically converted to canvas world coordinates. For example, if a canvas item receives an event of type GDK_BUTTON_PRESS, the x and y fields of the event will be in world coordinates. (The raw event was received on the
canvas’s GdkWindow and thus had window coordinates.)
• Enter/leave events are synthesized for canvas items as the mouse pointer moves across the canvas.
• Events are propagated up the canvas item hierarchy, until some item’s "event" signal handler returns TRUE. This works just as it does with GtkWidget; events are first sent to the bottommost or leaf canvas item, and eventually make it up to the root item.
• Only user-generated events are sent to canvas items; many events you might expect to receive on a GdkWindow, such as expose and configure events, are not forwarded to canvas items.

The canvas does this work behind the scenes, so item events work intuitively and much like normal GDK events.
A canvas item event callback looks like this:
static gint
item_event_callback(GnomeCanvasItem* item,
GdkEvent* event,
gpointer data)
{
switch (event->type) {
case GDK_BUTTON_PRESS:
break;
case GDK_MOTION_NOTIFY:
break;
case GDK_BUTTON_RELEASE:
break;
default:
break;

AsteClick - iPod Shuffle 2Gb
}
/* Returning FALSE propagates the event to parent items;
* returning TRUE ends event propagation.
*/
return FALSE;
}
Of course, a real callback would probably examine the contents of the event and take some action in response to some of them.
A Canvas Example
This section gives a brief example program, demonstrating the user of the canvas.
It does not explain the particulars of the canvas items being created; see the section called Standard Canvas Item Reference for that. Figure 12-9 shows the example program in action. You can drag canvas items around the screen with the left mouse button;
clicking an item with the Shift key held down destroys it.
Simple GnomeCanvas program

Here is the code to create an antialiased canvas. Notice the call to gdk_rgb_init();
notice that the canvas’s scroll region is set; finally, notice that the GdkRGB colormap and visual are pushed when creating the canvas.
#include
static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data);
static void create_canvas_items(GtkWidget* canvas);
int
main(int argc, char* argv[])
{
GtkWidget* window;
GtkWidget* sw;
GtkWidget* canvas;
gnome_init("canvas-example", "0.0", argc, argv);
gdk_rgb_init();
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Canvas Example");
gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, TRUE);
gtk_signal_connect(GTK_OBJECT(window),
"delete_event",
GTK_SIGNAL_FUNC(delete_event_cb),
NULL);
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_widget_push_visual(gdk_rgb_get_visual());
gtk_widget_push_colormap(gdk_rgb_get_cmap());
canvas = gnome_canvas_new_aa();
gtk_widget_pop_colormap();
gtk_widget_pop_visual();
gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0, 0, 600, 450);
create_canvas_items(canvas);
gtk_container_add(GTK_CONTAINER(sw), canvas);
gtk_container_add(GTK_CONTAINER(window), sw);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
static gint
delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data)
{
gtk_main_quit();
return FALSE;
}
Once the canvas has been created, the program adds some items to it, and connects a simple callback to the item’s "event" signal. Here’s the code:
static gint
item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
static double x, y;
double new_x, new_y;
GdkCursor *fleur;

adserver 750x100
static int dragging;
double item_x, item_y;
item_x = event->button.x;
item_y = event->button.y;
gnome_canvas_item_w2i(item->parent, &item_x, &item_y);
switch (event->type)
{
case GDK_BUTTON_PRESS:
switch(event->button.button)
{
case 1:
if (event->button.state & GDK_SHIFT_MASK)
{
gtk_object_destroy(GTK_OBJECT(item));
}
else
{
x = item_x;
y = item_y;
fleur = gdk_cursor_new(GDK_FLEUR);
gnome_canvas_item_grab(item,
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
fleur,
event->button.time);
gdk_cursor_destroy(fleur);
dragging = TRUE;
}
break;
default:
break;
}
break;
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK))
{
new_x = item_x;
new_y = item_y;
gnome_canvas_item_move(item, new_x - x, new_y - y);
x = new_x;
y = new_y;
}
break;
case GDK_BUTTON_RELEASE:
gnome_canvas_item_ungrab(item, event->button.time);
dragging = FALSE;
break;
default:
break;
}
return FALSE;
}
static void

setup_item(GnomeCanvasItem *item)
{
gtk_signal_connect(GTK_OBJECT(item), "event",
(GtkSignalFunc) item_event,
NULL);
}
static void
create_canvas_items(GtkWidget* canvas)
{
GnomeCanvasPoints* points;
GnomeCanvasGroup* group;
GnomeCanvasItem* item;
double affine[6];
group = gnome_canvas_root(GNOME_CANVAS(canvas));
/* A polygon */
points = gnome_canvas_points_new(14);
points->coords[0] = 270.0;
points->coords[1] = 330.0;
points->coords[2] = 270.0;
points->coords[3] = 430.0;
points->coords[4] = 390.0;
points->coords[5] = 430.0;
points->coords[6] = 390.0;
points->coords[7] = 330.0;
points->coords[8] = 310.0;
points->coords[9] = 330.0;
points->coords[10] = 310.0;
points->coords[11] = 390.0;
points->coords[12] = 350.0;
points->coords[13] = 390.0;
points->coords[14] = 350.0;
points->coords[15] = 370.0;
points->coords[16] = 330.0;
points->coords[17] = 370.0;
points->coords[18] = 330.0;
points->coords[19] = 350.0;
points->coords[20] = 370.0;
points->coords[21] = 350.0;
points->coords[22] = 370.0;
points->coords[23] = 410.0;
points->coords[24] = 290.0;
points->coords[25] = 410.0;
points->coords[26] = 290.0;
points->coords[27] = 330.0;

Chris Brown – With You
item = gnome_canvas_item_new(group,
gnome_canvas_polygon_get_type (),
"points", points,
"fill_color", "tan",
"outline_color", "black",
"width_units", 3.0,
NULL);
setup_item(item);
gnome_canvas_points_unref(points);
/* Translate the polygon */
art_affine_translate(affine, -150.0, -300.0);
gnome_canvas_item_affine_relative(item, affine);
/* A translucent rectangle */
setup_item (gnome_canvas_item_new (group,
gnome_canvas_rect_get_type(),
"x1", 90.0,
"y1", 40.0,
"x2", 180.0,
"y2", 100.0,
"fill_color_rgba", 0x3cb37180,
"outline_color", "black",
"width_units", 4.0,
NULL));
/* A translucent ellipse */
setup_item (gnome_canvas_item_new (group,
gnome_canvas_ellipse_get_type(),
"x1", 210.0,
"y1", 80.0,
"x2", 280.0,
"y2", 140.0,
"fill_color_rgba", 0x5f9ea080,
"outline_color", "black",
"width_pixels", 0,
NULL));
/* Create ellipses arranged in a line; they’re manipulated as a
single item. */
group =
GNOME_CANVAS_GROUP (gnome_canvas_item_new (group,
gnome_canvas_group_get_type(),
"x", 0.0,
"y", 0.0,
NULL));
setup_item(GNOME_CANVAS_ITEM(group));
{
double xpos = 20.0;
while (xpos <>

vodafoneshop.de
That is, x2 must be greater than x1, and y2 must be greater than y1; otherwise GnomeCanvasRE gets confused. GnomeCanvasRE Arguments Name Type Read/Write Description x1 double Both Leftmost coordinate y1 double Both Topmost coordinate x2 double Both Rightmost coordinate y2 double Both Bottommost coordinate fill_color gchar* Write-only Fill color; string for gdk_color_parse(), or NULL for transparent fill_color_gdk GdkColor* Both Fill color; specified as already-allocated GdkColor fill_color_rgba guint32 Both Fill color; specified as 32-bit value packing red, green, blue, and alpha into bytes 1, 2, 3, and 4; alpha of 255 is opaque, 0 is invisible outline_color gchar* Write-only Outline color; string for gdk_color_parse, or NULL for transparent Name Type Read/Write Description outline_color_gdk GdkColor* Both Outline color; specified as already-allocated GdkColor outline_color_rgba guint32 Both Outline color; specified as 32-bit value packing red, green, blue, and alpha into bytes 1, 2, 3, and 4; alpha of 255 is opaque, 0 is invisible fill_stipple GdkBitmap* Both Stipple to use when drawing fill; GDK mode only outline_stipple GdkBitmap* Both Stipple to use when drawing outline; GDK mode only width_pixels guint Write-only Width of the outline, in pixels (independent of zoom) width_units double Write-only Width of the outline, in canvas units; pixel width changes with zoom factor (pixels per unit) Line Item GnomeCanvasLine represents one or more line segments joined at their endpoints. You can use it to represent an unfilled polygon as well. GnomeCanvasPolygon is used for filled polygons. A line is specified using a GnomeCanvasPoints structure, which looks like this: typedef struct { int num_points; double *coords; int ref_count; } GnomeCanvasPoints; The coords field contains an array of points, alternating X and Y coordinates.

You fill the coords array directly, after creating a GnomeCanvasPoints with gnome_canvas_points_new(); the structure should be destroyed with gnome_canvas_points_unref(). Lines can have arrowheads on either end; the arrowhead shape is specified via three parameters, arbitrarily named A, B, and C. Parameter A (specified with the arrow_shape_a argument) specifies the distance from the base of the arrowhead to the tip. B specifies the distance from the tip of the arrowhead to one of the trailing points; C specifies the distance of a trailing point from the outer edge of the line. GnomeCanvasLine Arguments Name Type Read/Write Description points GnomeCanvas Both Points in the line Points* fill_color gchar* Write-only Fill color; string for gdk_color_parse() fill_color_gdk GdkColor* Both Fill color; specified as already-allocated GdkColor fill_color_rgba guint32 Both Fill color; specified as 32-bit value packing red, green, blue, and alpha into bytes 1, 2, 3, and 4; alpha of 255 is opaque, 0 is invisible fill_stipple GdkBitmap* Both Stipple to use when drawing line; GDK mode only width_pixels guint Write-only Width of the line, in pixels (independent of zoom) width_units double Write-only Width of the line, in canvas units; pixel width changes with zoom factor (pixels per unit) cap_style GdkCapStyle Both Cap style (GDK mode only) join_style GdkJoinStyle Both Join style (GDK mode only) line_style GdkLineStyle Both Line style (GDK mode only) first_arrowhead gboolean Both Whether to put an arrowhead at the start of the line last_arrowhead gboolean Both Whether to put an arrowhead at the end of the line smooth gboolean Both Whether to smooth the line using parabolic splines spline_steps guint Both Number of steps to use when rendering curves arrow_shape_a double Both Length of arrowhead Name Type Read/Write Description arrow_shape_b double Both Length of arrowhead edges (tip to trailing points) arrow_shape_c double Both Width of arrowhead Polygon Item GnomeCanvasPolygon represents a filled polygon; it can be filled or only an outline. Unlike GnomeCanvasRE, an unfilled GnomeCanvasPolygon is not "hollow"; the transparent portion in the center is part of the canvas item. GnomeCanvasLine is used for "hollow" polygons. GnomeCanvasPolygon Arguments Name Type Read/Write Description points GnomeCanvas Both Points in the Points* polygon fill_color gchar* Write-only Fill color; string for gdk_color_parse(), or NULL for transparent fill_color_gdk GdkColor* Both Fill color; specified as already-allocated GdkColor fill_color_rgba guint32 Both Fill color; specified as 32-bit value packing red, green, blue, and alpha into bytes 1, 2, 3, and 4; alpha of 255 is opaque, 0 is invisible outline_color gchar* Write-only Outline color; string for gdk_color_parse, or NULL for transparent outline_color_gdk GdkColor* Both Outline color; specified as already-allocated GdkColor Name Type Read/Write Description outline_color_rgba guint32 Both Outline color; specified as 32-bit value packing red, green, blue, and alpha into bytes 1, 2, 3, and 4; alpha of 255 is opaque, 0 is invisible fill_stipple GdkBitmap* Both Stipple to use when drawing fill; GDK mode only outline_stipple GdkBitmap* Both Stipple to use when drawing outline; GDK mode only width_pixels guint Write-only Width of the outline, in pixels (independent of zoom) width_units double Write-only Width of the outline, in canvas units; pixel width changes with zoom factor (pixels per unit) Image Item GnomeCanvasImage places an image on the canvas; you pass it a GdkImlibImage, loaded using one of the Imlib routines. If the image has transparent areas, they will be properly handled (they won’t be considered part of the item, and will not receive events). To use GnomeCanvasImage with a GDK canvas, you must push the Imlib visual and colormap before creating the canvas; see the section called Preparing the GnomeCanvas Widget. GnomeCanvasImage Arguments Name Type Read/Write Description image GdkImlibImage* Both GdkImlibImage to display x double Both X coordinate of the anchor point y double Both Y coordinate of the anchor point anchor GtkAnchorType Both Location of anchor point width double Both Width in canvas units (image will be scaled) Name Type Read/Write Description height double Both Height in canvas units (image will be scaled) Text Item GnomeCanvasText displays a text string. You can specify the coordinates of the string as an ordered pair; these coordinates will represent the location of the text’s anchor. For example, if the "anchor" argument is set to GTK_ANCHOR_NORTH, the text item’s coordinates will represent the location of the top-center of the item. That is, the text will be centered around the X position and begin just below the Y position. Possible anchor values are: • GTK_ANCHOR_CENTER • GTK_ANCHOR_NORTH • GTK_ANCHOR_NORTH_WEST • GTK_ANCHOR_NORTH_EAST • GTK_ANCHOR_SOUTH • GTK_ANCHOR_SOUTH_WEST • GTK_ANCHOR_SOUTH_EAST • GTK_ANCHOR_WEST • GTK_ANCHOR_EAST Affine transformation of GnomeCanvasText is not implemented very well. Because the X font model is in exible and limited, there is no good way to rotate and otherwise transform rendered text.

Contro Corrente gif728x90
In antialiased mode the canvas item implements this in the only way it can: it draws the entire font to a GdkPixmap, then copies the pixmap to a GdkImage, then reads individual pixels out of the image into a client side bitmap, then copies the characters to be displayed from the entire-font bitmap into a temporary buffer, then uses libart_lgpl to apply any affine transformations to this buffer, then copies the transformed buffer to the canvas RGB buffer. Finally the canvas copies the RGB buffer to the screen. Needless to say this is slower than molasses: an entire bitmap goes over the network more than once. Moreover, scaling and rotating fonts as bitmaps leads to a low quality image. If you try to use Gnome CanvasText with antialiased mode, you will probably notice this; if your canvas is slow to update, suspect the text item. There are plans to fix the text item, using a new font abstraction called GnomeFont. However, Gnome 1.0 lacks this feature. There is not a good solution to the problem; if your application allows it, you can get dramatic speed increases by creating your own text item that caches the entire-font bitmaps.

However, if you don’t reuse the same fonts often, caching will be useless. Another possibility is to abandon X fonts and use Type 1 fonts with a rasterization library like t1lib, but this limits the fonts available to you and adds a library dependency. You could also use True Type fonts with the FreeType library, or use the Display PostScript extension to X (XDPS). Unfortunately, your best bet is probably to wait for the GnomeFont feature in a future version of the Gnome libraries. GnomeCanvasText Arguments Name Type Read/Write Description text gchar* Both String to display x double Both X coordinate of the anchor point y double Both Y coordinate of the anchor point anchor GtkAnchorType Both Location of anchor point font gchar* Write-only Font name for gdk_font_load() fontset gchar* Write-only Fontset name for gdk_fontset_load() font_gdk GdkFont* Both Font for rendering the text justification GtkJustification Both Justification (multiline text only) fill_color gchar* Write-only Fill color; string for gdk_color_parse(), or NULL for transparent fill_color_gdk GdkColor* Both Fill color; specified as already-allocated GdkColor fill_color_rgba guint32 Both Fill color; specified as 32-bit value packing red, green, blue, and alpha into bytes 1, 2, 3, and 4; alpha of 255 is opaque, 0 is invisible fill_stipple GdkBitmap* Both Stipple to use when drawing text; GDK mode only clip_width double Both Width of clip rectangle in canvas units clip_height double Both Height of clip rectangle in canvas units clip gboolean Both Enables or disables clipping x_offset double Both Horizontal offset to add to X position y_offset double Both Vertical offset to add to Y position text_width double Read-only Width of rendered text Name Type Read/Write Description text_height double Read-only Height of rendered text Widget Item The GnomeCanvasWidget item places a widget on the canvas.

The canvas item emulates a container widget, passing a size allocation to the widget it holds. You can specify an anchor point for the widget item, just as you can for GnomeCanvasText. GnGnomeCanvas This chapter describes the GnomeCanvas widget, and the standard canvas items that come with Gnome. The following chapter discusses in more detail how to write a custom canvas item. Introduction to the Canvas The canvas widget is a powerful and extensible object-oriented display engine, useful in a wide variety of Gnome applications. The widget itself is simply a blank area; you can place GnomeCanvasItems on it.

A GnomeCanvasItem is a GtkObject representing some element of the display, such as an image, a rectangle, an ellipse, or some text. You can refer to this architecture as structured graphics; the canvas lets you deal with graphics in terms of items, rather than an undifferentiated grid of pixels. Since a GnomeCanvasItem is a GtkObject, you can create your own subclasses to supplement those that come with Gnome. This gives you quite a bit of exibility. Using custom canvas items, the canvas can render almost anything. At the same time, you can use stock canvas items to save time and effort. The canvas puts you in control. GnomeCanvas has two modes, representing a quality/speed tradeoff.

In "GDK" mode, canvas items render directly to a GdkPixmap buffer using the GDK drawing primitives. The canvas copies the buffer to the screen once all items are rendered. In antialiased or "AA" mode, the canvas items write RGB pixels to a vector of bytes; after all the items have drawn on the RGB buffer, the canvas copies it to the screen. This RGB buffer mode is called "antialiased" mode because all the standard canvas items draw to the RGB buffer using the high-quality antialiased routines in libart_lgpl. This results in smooth lines and very high display quality, with some cost in speed. Basic Canvas Architecture This section introduces the architecture of the canvas, including the arrangement of items into hierarchical groups, and the many coordinate systems involved in using the canvas.

no one deals like we do!

GnomeCanvasGroup Canvas items are arranged in a tree structure. You can group items together, to be moved as a unit; canvas architect Federico Mena Quintero likes to use a circuit diagram editor as an example. You might group together the shapes representing each logic gate, so you could manipulate the logic gate as a unit. You could also collect several logic gates into a single component; that is, groups can contain subgroups. Within each group, the canvas maintains a stacking order; objects higher in the stacking order obscure objects lower in the stacking order.

To implement this, the canvas comes with a special kind of canvas item called GnomeCanvasGroup. As the name suggests, a canvas group groups a number canvas items together so you can manipulate the child items as a single item. A GnomeCanvasGroup is invisible; to render itself, it simply recurses its children, rendering each of them in turn. When you create a new GnomeCanvas, a default group called the "root" is created for you. All canvas items are added somewhere below the root group.

The canvas widget only deals with the root canvas item directly; all other canvas items are managed by their parent group. An accessor function is provided to access the root canvas group, shown in Figure #include
GnomeCanvasGroup* gnome_canvas_root(GnomeCanvas* canvas);
Root Group Accessor
Items must always be part of a group; there is no such thing as an "orphan" canvas item. When you create an item, you must specify its canvas group. It is also possible to reparent items after creation. However, items are permanently bound to the GnomeCanvas they were created on; it is not permitted to reparent an item to a group on a different canvas.

Coordinates
Many of the features of the canvas are implemented via translations between different coordinate systems. Canvas items can be moved, rotated, or scaled via affine transformations, described in more detail below. (Short version: an affine transformation is a way to convert from one coordinate system to another.) Here are the important coordinate systems which come up when using the canvas and writing custom canvas items:
• World coordinates are an absolute coordinate system; i.e., the same world coordinate refers to the same place on the canvas in all cases. World coordinates are conceptually infinite and are represented by a double. World coordinates are the real, toplevel, untransformed, canonical coordinate system. Consistent with the X Window System and GDK, Y coordinates increase as they move downward, so lower Y coordinates are toward the top of the canvas.
• Item coordinates are the coordinates used by a particular canvas item. Item coordinates exist because each canvas item has an affine transformation associated with it. In the case of GnomeCanvasGroup, this transformation is applied to the group’s children. To convert from world coordinates to item coordinates for some particular item, you apply the transform for each canvas group in the item’s ancestry, starting with the root canvas group; then you apply the item’s own transform.

(Don’t worry, Gnome comes with a function to do this for you.) Like world coordinates, item coordinates are conceptually infinite.
• Canvas coordinates are pixel coordinates. While item and world coordinates are oating-point numbers, canvas pixel coordinates are integers. To use the canvas, you must specify a "scroll region," which is the rectangle in world coordinate space you want the user to be able to see.

Canvas pixel coordinates are relative to this rectangle. Canvas pixel coordinates also take into account a scaling factor representing the number of pixels per world coordinate unit. To convert from world coordinates to canvas coordinates, the canvas subtracts the X and Y coordinates of the scroll region, multiplies by the scaling factor, and then rounds to an integer.
Thus, (0,0) in canvas coordinates will be the top left corner of the scroll region.
• Buffer coordinates are canvas coordinates modified by some offset. Item implementations use these during rendering. The canvas passes the item implementation a buffer (which is either a GdkDrawable or an RGB buffer, depending on the canvas mode). The canvas tells the item implementation which region of the screen the buffer represents—the buffer region is defined by an X offset, Y offset, width and height. The X and Y offsets are in canvas coordinates, and are equivalent to (0,0) in buffer coordinates. To convert from canvas coordinates to buffer coordinates, simply subtract the offset. Buffer coordinates are only valid from (0,0) to
the maximum width and height of the buffer.


• Window coordinates are rarely used. The canvas eventually copies each temporary buffer to a GdkWindow (to be precise,it copies them to GTK_LAYOUT(canvas) >bin_window). Window coordinates are relative to this GdkWindow. In some rare cases you might want to draw to the window directly rather than using a canvas item, or you might want to respond to an event on the window (such as a drag- and-drop). Then you need to convert from window coordinates to one of the other coordinate systems.

When using preexisting canvas items, you will mostly be interested in world and item coordinates. When writing your own items, you will also need to use canvas and buffer coordinates.
There are two ways to convert between the various coordinate systems; one way is to obtain and use affines directly—this is described in the next section. The easy way is to use one of the convenience functions provided for the purpose.

Conversion between canvas and item coordinates requires you to convert to world coordinates first as an intermediate step. There is no function to convert to or from buffer coordinates, because this is a simple matter of subtracting the buffer offsets from the canvas coordinates (canvas to buffer), or adding the buffer offsets to the buffer coordinates (buffer to canvas).
#include
void gnome_canvas_w2c(GnomeCanvas* canvas, double wx, double wy, int* cx,
int* cy);
void gnome_canvas_w2c_d(GnomeCanvas* canvas, double wx, double wy, dou-
ble* cx, double* cy); void gnome_canvas_c2w(GnomeCanvas* canvas, int cx, int cy, double* wx, dou-
ble* wy);
void gnome_canvas_item_w2i(GnomeCanvasItem* item, double* x, double* y);
void gnome_canvas_item_i2w(GnomeCanvasItem* item, double* x, double* y);
void gnome_canvas_window_to_world(GnomeCanvas* canvas, double winx, dou-
ble winy, double* worldx, double* worldy);
void gnome_canvas_world_to_window(GnomeCanvas* canvas, double worldx, double worldy, double* winx, double* winy);

Coordinate Conversions Affine Transformations
An affine is a transformation matrix made up of six real numbers that can be applied to an ordered pair. Depending on the contents of the affine, the point it is applied to can be:
• translated—shifted by an arbitrary distance in either dimension;
• rotated some number of degrees;
• scaled by some factor.

Conceptually, an affine defines a relationship between points on a plane. For any point (A,B), the affine defines a single corresponding transformed point; the mapping is one-to-one, so given the transformed point you can determine the original point.
Affines have interesting properties that make them useful in computer graphics.
Most importantly, they can be composed, concatenated, or multiplied (the three terms are synonymous). You can compose any number of affines to create a single affine; applying the single affine has the same effect as applying each of the original affines in order. Note that the order of composition is important! Unlike multiplication, affine composition is not commutative (which is a reason to avoid the term "multiply" in this context).
libart_lgpl contains a module for affine manipulation. It represents affines as an array of six doubles. Its affine functions are shown in
#include
void art_affine_point(ArtPoint* dst, const ArtPoint* src, const double affine[6]);
void art_affine_invert(double dst_affine[6], const double src_affine[6]);
void art_affine_multiply(double dst[6], const double src1[6], const dou-
ble src2[6]);
void art_affine_identity(double dst[6]);
void art_affine_scale(double dst[6], double sx, double sy);
void art_affine_rotate(double dst[6], double theta);
void art_affine_translate(double dst[6], double tx, double ty);
int art_affine_rectilinear(const double src[6]);
L'immagine “http://www.aliprestito.net/banner/728x90_ali_r2aereo.gif” non può essere visualizzata poiché contiene degli errori.
Affine Manipulation
art_affine_point() applies an affine to a point. The affine is applied to the second argument (src) and the result is copied into the first argument (dst). An ArtPoint is simply:
typedef struct _ArtPoint ArtPoint;
struct _ArtPoint {
double x, y;
};
Affines can be inverted. If an affine converts points in coordinate system A into points in coordinate system B, its inverse converts points in coordinate system B into points in coordinate system A. art_affine_invert() fills its first argument with the in-
verse of its second.
art_affine_multiply() composes two affines as described earlier in this section, placing the result in its first argument.
Four functions are provided to create affines with particular properties.
• art_affine_identity() creates the identity affine. Applying the identity affine to a point has no effect.
• art_affine_rotate() gives an affine that rotates points by theta degrees.
• art_affine_translate() gives an affine that translates points tx in the X dimension and ty in the Y dimension.
• art_affine_scale() gives an affine which scales the plane by the given factors
(a factor of 1.0 does no scaling, less than 1.0 shrinks, greater than 1.0 expands).
art_affine_rectilinear() returns TRUE if the affine rotates rectangles aligned to
the axes in such a way that they remain aligned to the axes. That is, it returns TRUE if the rotation is 0, 90, 180, or 270 degrees.
You can ask the canvas widget to compute affines which convert between its various coordinate systems. These functions are shown in Figure 12-4; each of them fills an array you pass in with the affine being requested.
#include
void gnome_canvas_item_i2w_affine(GnomeCanvasItem* item, double affine[6]);
void gnome_canvas_item_i2c_affine(GnomeCanvasItem* item, double affine[6]);
void gnome_canvas_w2c_affine(GnomeCanvas* canvas, double affine[6]);

Canvas Affines Using the Canvas
GnomeCanvas is easy to use; this is its virtue compared to GtkDrawingArea or some other low-level approach. This section describes how to create a canvas, and work with canvas items. It ends with a programming example.

Preparing the GnomeCanvas Widget
The first decision you have to make is whether to use the canvas in GDK mode or antialiased mode. When you create a canvas widget, you must specify the mode you want; there is no way to change it later. gnome_canvas_new() creates a GDK canvas.
gnome_canvas_new_aa() creates an antialiased canvas.
Sometimes it matters which visual and colormap the canvas will use. In particular:
• In GDK mode, if you want to use the GnomeCanvasImage item to display images, you must use Imlib’s visual and colormap. GnomeCanvasImage uses Imlib to render images.
• In antialiased mode, GDK’s RGB buffer rendering facilities (see the section called RGB Buffers in Chapter 10) are used to copy the RGB buffer to the screen. You must use the visual and colormap from the GDK RGB module.
To create a widget with a non-default visual and colormap, gtk_widget_push_visual() and gtk_widget_push_colormap() are used. Here is the code to create a GDK canvas that supports the image item:
GtkWidget* canvas;
gtk_widget_push_visual(gdk_imlib_get_visual());
gtk_widget_push_colormap(gdk_imlib_get_colormap());
canvas = gnome_canvas_new();
gtk_widget_pop_visual();
gtk_widget_pop_colormap();

To create an antialiased canvas, do this:
GtkWidget* canvas;
gtk_widget_push_visual(gdk_rgb_get_visual());
gtk_widget_push_colormap(gdk_rgb_get_cmap());
canvas = gnome_canvas_new_aa();
gtk_widget_pop_colormap();
gtk_widget_pop_visual();
#include
GtkWidget* gnome_canvas_new(void);
GtkWidget* gnome_canvas_new_aa(void);
L'immagine “http://www.lineacredito.net/banner/468x60_animato.gif” non può essere visualizzata poiché contiene degli errori.
Canvas Constructors Scroll Region
The canvas is practically infinite from a programmer ’s standpoint; however, in reality your application probably uses only a small area. When using the canvas you must specify which region is interesting to the user with gnome_canvas_set_scroll_region()
The scroll region is given in world coordinates. You can query the scroll region with gnome_canvas_get_scroll_region().
To add scroll bars to the canvas, simply create a GtkScrolledWindow and add the
canvas to it:
GtkWidget* sw;
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(sw), canvas);
If you want to implement scrolling via some mechanism other than the scroll bars, you can get and set the "scroll offsets." The scroll offsets are in canvas pixel coordinates; they specify the top left visible pixel. Remember that canvas pixel coordinates
are relative to the scroll region.
#include
void gnome_canvas_set_scroll_region(GnomeCanvas* canvas, double x1, double y1, double x2, double y2);
void gnome_canvas_get_scroll_region(GnomeCanvas* canvas, double* x1, double* y1, double* x2, double* y2);
void gnome_canvas_scroll_to(GnomeCanvas* canvas, gint cx, gint cy );
void gnome_canvas_get_scroll_offsets(GnomeCanvas* canvas, gint* cx, gint*
cy);

Canvas Scrolling Zooming
The canvas gives you zooming "for free"; it is included in the world-to-canvas and canvas-to-world coordinate system conversions. You can set the zoom factor with gnome_canvas_set_pixels_per_unit(). By default, there ratio of pixels to canvas units is 1.0, meaning no zoom. Specifying a value less than 1.0 means reduced size; greater than 1.0 means increased size.

In antialiased mode, you could achieve the same visual effect by applying a scaling affine transformation to the root canvas group. The pixels_per_unit member of the GnomeCanvas struct predates the canvas’s use of affines. Still, gnome_canvas_set_pixels_per_unit()
is a bit more convenient than the affine transform method, and it does work in GDK mode. (Because GDK mode uses Xlib primitives, it’s nontrivial to implement arbitrary affine transformations; a future version of Gnome may do so, however.)
#include
void gnome_canvas_set_pixels_per_unit(GnomeCanvas* canvas, double ppu);
Canvas Zooming Canvas Items
Most of the time you will be interested in canvas items rather than the canvas itself.
Canvas items are typically very easy to use, compared to widgets; none of the standard items have any unique signals, since they are not interactive. (Since GnomeCanvasItem is a subclass of GtkObject, however, you could certainly have an item with signals if you wanted to.) The GnomeCanvasItem base class has a single signal, "event", which is used to convey all types of event. The "event" signal has no default handler; canvas items do not respond to events unless you connect handlers of your own. Figure 12-8 lists all the useful functions for working with the

GnomeCanvasItem base class.
To create a canvas item, you use the generic gnome_canvas_item_new() (or gnome_canvas_item_newv()).
This function accepts the group to place the item in, the GtkType of the GnomeCanvasItem subclass to create, and finally a NULL-terminated list of arguments to set. The argument list is purely for convenience, so you don’t have to call gnome_canvas_item_set()
immediately. gnome_canvas_item_new() creates a new instance of the type with gtk_type_new(), adds the item to its GnomeCanvasGroup, and schedules it to be redrawn.
To destroy an item and remove it from the canvas, simply call gtk_object_destroy().
You can also use the standard reference counting mechanism with canvas items.
You can set an item’s affine using gnome_canvas_item_affine_absolute(), or compose a new affine with the item’s existing affine using gnome_canvas_item_affine_relative().
These functions can be used to translate, scale, or rotate a canvas item (however, scaling and rotation only work in antialiased mode).
Items in a group are normally stacked in the order you add them, with the most recently-added item "on top" and the oldest item on the bottom. You can manipulate the stacking order with gnome_canvas_item_raise() and gnome_canvas_item_lower().
L'immagine “http://www.motoreshopping.it/giocodigitale/728x90.jpg” non può essere visualizzata poiché contiene degli errori.
These move an item up or down by the given number of positions. It is safe to pass in a too-large value for positions; the item will be moved as far as possible and no more. You can also request that an item is moved to one extreme or the other, using
gnome_canvas_item_raise_to_top() and gnome_canvas_item_lower_to_bottom.
Items can be shown and hidden; hidden items are not rendered by the canvas and do not receive events. All items are visible by default. The routines are gnome_canvas_item_show() and gnome_canvas_item_hide().
Reparenting a canvas item is straightforward; the only rule is that the new group must be on the same canvas as the old group.
gnome_canvas_item_grab_focus() is analagous to gtk_widget_grab_focus(); it sends all key events to the item with the grab. It also sends focus change events to the item (when the item gains or loses the focus).
Canvas items can grab and ungrab the mouse pointer just as a GdkWindow can; the arguments to gnome_canvas_item_grab() are exactly analagous to those of gdk_pointer_grab().
While a canvas item has the pointer grabbed, no other item receives events.

Behind the scenes, GnomeCanvas uses gdk_pointer_grab() to implement gnome_canvas_item_grab(), so an item grabbing the mouse away from other items implies the canvas grabbing the mouse away from other widgets.

The visual properties of canvas items are manipulated almost entirely via object arguments. If you skipped Chapter 9, go back and read the section on object arguments now. Two functions are used to set canvas item properties: gnome_canvas_item_set()
and gnome_canvas_item_setv(). These are almost but not quite equivalent to gtk_object_set()
and gtk_object_setv()—they set object arguments in the same way, but they also mark the canvas item to be redrawn. So you should prefer them to the GtkObject variants. (This is something of a design bug, and future canvas versions will most
likely allow you to use gtk_object_set().)
gnome_canvas_item_request_update() marks the canvas item as "dirty" and queues it to be redrawn. Internally, the canvas uses a one-shot idle function to perform redraws; that is, it waits until no more GTK+ events are pending, then redraws itself a single time. It does this by installing an idle function with gtk_idle_add() and removing it after it runs once. Thus gnome_canvas_item_request_update() can be called many times without creating an efficiency problem—it pretty much does nothing at all if an update is already pending.
#include
GnomeCanvasItem* gnome_canvas_item_new(GnomeCanvasGroup* parent, GtkType type, const gchar* first_arg_name, ...);
GnomeCanvasItem* gnome_canvas_item_newv(GnomeCanvasGroup* parent, GtkType type, guint nargs, GtkArg* args);
void gnome_canvas_item_set(GnomeCanvasItem* item, const gchar* first_arg_name, ...);
void gnome_canvas_item_setv(GnomeCanvasItem* item, guint nargs, GtkArg* args);
void gnome_canvas_item_affine_relative(GnomeCanvasItem* item, const double affine[6]);
void gnome_canvas_item_affine_absolute(GnomeCanvasItem* item, const double
affine[6]);
void gnome_canvas_item_raise(GnomeCanvasItem* item, int positions);
void gnome_canvas_item_lower(GnomeCanvasItem* item, int positions);
void gnome_canvas_item_raise_to_top(GnomeCanvasItem* item);
void gnome_canvas_item_lower_to_bottom(GnomeCanvasItem* item);
void gnome_canvas_item_show(GnomeCanvasItem* item);
void gnome_canvas_item_hide(GnomeCanvasItem* item);
void gnome_canvas_item_reparent(GnomeCanvasItem* item, GnomeCanvasGroup*

new_group);
void gnome_canvas_item_grab_focus(GnomeCanvasItem* item);
int gnome_canvas_item_grab(GnomeCanvasItem* item, unsigned int event_mask, GdkCursor* cursor, guint32 etime);
void gnome_canvas_item_ungrab(GnomeCanvasItem* item, guint32 etime);
void gnome_canvas_item_get_bounds(GnomeCanvasItem* item, double* x1, double* y1, double* x2, double* y2);
void gnome_canvas_item_request_update(GnomeCanvasItem* item);
Using GnomeCanvasItem Canvas Items and Events

The standard Gnome canvas items have only one signal, "event", which is emitted for all types of event. The canvas widget preprocesses all GDK events that it receives, and forwards some of them to canvas items. It also sythesizes certain events. Remember
that X sends events only to X windows (GdkWindows), and canvas items do not have an associated GdkWindow. Thus the canvas widget must act as intermediary. Here are some of the actions it takes:
• Coordinates are automatically converted to canvas world coordinates. For example, if a canvas item receives an event of type GDK_BUTTON_PRESS, the x and y fields of the event will be in world coordinates. (The raw event was received on the
canvas’s GdkWindow and thus had window coordinates.)
• Enter/leave events are synthesized for canvas items as the mouse pointer moves across the canvas.
• Events are propagated up the canvas item hierarchy, until some item’s "event" signal handler returns TRUE. This works just as it does with GtkWidget; events are first sent to the bottommost or leaf canvas item, and eventually make it up to the root item.
• Only user-generated events are sent to canvas items; many events you might expect to receive on a GdkWindow, such as expose and configure events, are not forwarded to canvas items.
L'immagine “http://www.galassiacellulare.it.s3.amazonaws.com/b_ivip/728x90_ivip.gif” non può essere visualizzata poiché contiene degli errori.
The canvas does this work behind the scenes, so item events work intuitively and much like normal GDK events.
A canvas item event callback looks like this:
static gint
item_event_callback(GnomeCanvasItem* item,
GdkEvent* event,
gpointer data)
{
switch (event->type) {
case GDK_BUTTON_PRESS:
break;
case GDK_MOTION_NOTIFY:
break;
case GDK_BUTTON_RELEASE:
break;
default:
break;

}
/* Returning FALSE propagates the event to parent items;
* returning TRUE ends event propagation.
*/
return FALSE;
}
Of course, a real callback would probably examine the contents of the event and take some action in response to some of them.
A Canvas Example
This section gives a brief example program, demonstrating the user of the canvas.
It does not explain the particulars of the canvas items being created; see the section called Standard Canvas Item Reference for that. Figure 12-9 shows the example program in action. You can drag canvas items around the screen with the left mouse button;
clicking an item with the Shift key held down destroys it.

Simple GnomeCanvas program
Here is the code to create an antialiased canvas. Notice the call to gdk_rgb_init();
notice that the canvas’s scroll region is set; finally, notice that the GdkRGB colormap and visual are pushed when creating the canvas.
#include
static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data);
static void create_canvas_items(GtkWidget* canvas);
int
main(int argc, char* argv[])
{
GtkWidget* window;
GtkWidget* sw;
GtkWidget* canvas;
gnome_init("canvas-example", "0.0", argc, argv);
gdk_rgb_init();
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Canvas Example");
gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, TRUE);
gtk_signal_connect(GTK_OBJECT(window),
"delete_event",
GTK_SIGNAL_FUNC(delete_event_cb),
NULL);
sw = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_widget_push_visual(gdk_rgb_get_visual());
gtk_widget_push_colormap(gdk_rgb_get_cmap());
canvas = gnome_canvas_new_aa();
gtk_widget_pop_colormap();
gtk_widget_pop_visual();
gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas), 0, 0, 600, 450);
create_canvas_items(canvas);
gtk_container_add(GTK_CONTAINER(sw), canvas);
gtk_container_add(GTK_CONTAINER(window), sw);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
static gint
delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data)
{
gtk_main_quit();
return FALSE;
}
Once the canvas has been created, the program adds some items to it, and connects a simple callback to the item’s "event" signal. Here’s the code:
static gint
item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
static double x, y;
double new_x, new_y;
GdkCursor *fleur;
L'immagine “http://www.galassiacellulare.it.s3.amazonaws.com/b_indMus/728x90musica.gif” non può essere visualizzata poiché contiene degli errori.
static int dragging;
double item_x, item_y;
item_x = event->button.x;
item_y = event->button.y;
gnome_canvas_item_w2i(item->parent, &item_x, &item_y);
switch (event->type)
{
case GDK_BUTTON_PRESS:
switch(event->button.button)
{
case 1:
if (event->button.state & GDK_SHIFT_MASK)
{
gtk_object_destroy(GTK_OBJECT(item));
}
else
{
x = item_x;
y = item_y;
fleur = gdk_cursor_new(GDK_FLEUR);
gnome_canvas_item_grab(item,
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
fleur,
event->button.time);
gdk_cursor_destroy(fleur);
dragging = TRUE;
}
break;
default:
break;
}
break;
case GDK_MOTION_NOTIFY:
if (dragging && (event->motion.state & GDK_BUTTON1_MASK))
{
new_x = item_x;
new_y = item_y;
gnome_canvas_item_move(item, new_x - x, new_y - y);
x = new_x;
y = new_y;
}
break;
case GDK_BUTTON_RELEASE:
gnome_canvas_item_ungrab(item, event->button.time);
dragging = FALSE;
break;
default:
break;
}
return FALSE;
}
static void

setup_item(GnomeCanvasItem *item)
{
gtk_signal_connect(GTK_OBJECT(item), "event",
(GtkSignalFunc) item_event,
NULL);
}
static void
create_canvas_items(GtkWidget* canvas)
{
GnomeCanvasPoints* points;
GnomeCanvasGroup* group;
GnomeCanvasItem* item;
double affine[6];
group = gnome_canvas_root(GNOME_CANVAS(canvas));
/* A polygon */
points = gnome_canvas_points_new(14);
points->coords[0] = 270.0;
points->coords[1] = 330.0;
points->coords[2] = 270.0;
points->coords[3] = 430.0;
points->coords[4] = 390.0;
points->coords[5] = 430.0;
points->coords[6] = 390.0;
points->coords[7] = 330.0;
points->coords[8] = 310.0;
points->coords[9] = 330.0;
points->coords[10] = 310.0;
points->coords[11] = 390.0;
points->coords[12] = 350.0;
points->coords[13] = 390.0;
points->coords[14] = 350.0;
points->coords[15] = 370.0;
points->coords[16] = 330.0;
points->coords[17] = 370.0;
points->coords[18] = 330.0;
points->coords[19] = 350.0;
points->coords[20] = 370.0;
points->coords[21] = 350.0;
points->coords[22] = 370.0;
points->coords[23] = 410.0;
points->coords[24] = 290.0;
points->coords[25] = 410.0;
points->coords[26] = 290.0;
points->coords[27] = 330.0;
L'immagine “http://www.galassiacellulare.it.s3.amazonaws.com/b_indFilm/728x90film.gif” non può essere visualizzata poiché contiene degli errori.
item = gnome_canvas_item_new(group,
gnome_canvas_polygon_get_type (),
"points", points,
"fill_color", "tan",
"outline_color", "black",
"width_units", 3.0,
NULL);
setup_item(item);
gnome_canvas_points_unref(points);
/* Translate the polygon */
art_affine_translate(affine, -150.0, -300.0);
gnome_canvas_item_affine_relative(item, affine);
/* A translucent rectangle */
setup_item (gnome_canvas_item_new (group,
gnome_canvas_rect_get_type(),
"x1", 90.0,
"y1", 40.0,
"x2", 180.0,
"y2", 100.0,
"fill_color_rgba", 0x3cb37180,
"outline_color", "black",
"width_units", 4.0,
NULL));
/* A translucent ellipse */
setup_item (gnome_canvas_item_new (group,
gnome_canvas_ellipse_get_type(),
"x1", 210.0,
"y1", 80.0,
"x2", 280.0,
"y2", 140.0,
"fill_color_rgba", 0x5f9ea080,
"outline_color", "black",
"width_pixels", 0,
NULL));
/* Create ellipses arranged in a line; they’re manipulated as a
single item. */
group =
GNOME_CANVAS_GROUP (gnome_canvas_item_new (group,
gnome_canvas_group_get_type(),
"x", 0.0,
"y", 0.0,
NULL));
setup_item(GNOME_CANVAS_ITEM(group));
{
double xpos = 20.0;
while (xpos <>
L'immagine “http://www.motoreshopping.it/prometeo/728x90.gif” non può essere visualizzata poiché contiene degli errori.
In antialiased mode the canvas item implements this in the only way it can: it draws the entire font to a GdkPixmap, then copies the pixmap to a GdkImage, then reads individual pixels out of the image into a client side bitmap, then copies the characters to be displayed from the entire-font bitmap into a temporary buffer, then uses libart_lgpl to apply any affine transformations to this buffer, then copies the transformed buffer to the canvas RGB buffer. Finally the canvas copies the RGB buffer to the screen. Needless to say this is slower than molasses: an entire bitmap goes over the network more than once.

Moreover, scaling and rotating fonts as bitmaps leads to a low quality image. If you try to use Gnome CanvasText with antialiased mode, you will probably notice this; if your canvas is slow to update, suspect the text item. There are plans to fix the text item, using a new font abstraction called GnomeFont. However, Gnome 1.0 lacks this feature. There is not a good solution to the problem; if your application allows it, you can get dramatic speed increases by creating your own text item that caches the entire-font bitmaps. However, if you don’t reuse the same fonts often, caching will be useless. Another possibility is to abandon X fonts and use Type 1 fonts with a rasterization library like t1lib, but this limits the fonts available to you and adds a library dependency. You could also use True Type fonts with the FreeType library, or use the Display PostScript extension to X (XDPS). Unfortunately, your best bet is probably to wait for the GnomeFont feature in a future version of the Gnome libraries. GnomeCanvasText Arguments Name Type Read/Write Description text gchar* Both String to display x double Both X coordinate of the anchor point y double Both Y coordinate of the anchor point anchor GtkAnchorType Both Location of anchor point font gchar* Write-only Font name for gdk_font_load() fontset gchar* Write-only Fontset name for gdk_fontset_load() font_gdk GdkFont* Both Font for rendering the text justification GtkJustification Both Justification (multiline text only) fill_color gchar* Write-only Fill color; string for gdk_color_parse(), or NULL for transparent fill_color_gdk GdkColor* Both Fill color; specified as already-allocated GdkColor fill_color_rgba guint32 Both Fill color; specified as 32-bit value packing red, green, blue, and alpha into bytes 1, 2, 3, and 4; alpha of 255 is opaque, 0 is invisible fill_stipple GdkBitmap* Both Stipple to use when drawing text; GDK mode only clip_width double Both Width of clip rectangle in canvas units clip_height double Both Height of clip rectangle in canvas units clip gboolean Both Enables or disables clipping x_offset double Both Horizontal offset to add to X position y_offset double Both Vertical offset to add to Y position text_width double Read-only Width of rendered text Name Type Read/Write Description text_height double Read-only Height of rendered text Widget Item The GnomeCanvasWidget item places a widget on the canvas. The canvas item emulates a container widget, passing a size allocation to the widget it holds. You can specify an anchor point for the widget item, just as you can for GnomeCanvasText. GnomeCanvasWidget Arguments Name Type Read/Write Description widget GtkWidget* Both Widget to display x double Both X coordinate of the anchor point y double Both Y coordinate of the anchor point anchor GtkAnchorType Both Location of anchor point width double Both Width of widget height double Both Height of widget size_pixels gboolean Both Specifies how to interpret the width and height argument; if TRUE, they are in pixels; if FALSE, they are in canvas units omeCanvasWidget Arguments Name Type Read/Write Description widget GtkWidget* Both Widget to display x double Both X coordinate of the anchor point y double Both Y coordinate of the anchor point anchor GtkAnchorType Both Location of anchor point width double Both Width of widget height double Both Height of widget size_pixels gboolean Both Specifies how to interpret the width and height argument; if TRUE, they are in pixels; if FALSE, they are in canvas units.

L'immagine “http://img.etoiledirect.com/it/sky8_728x90.gif” non può essere visualizzata poiché contiene degli errori.

Latest Post



Linux Links

    160x600     step



Do you consider this article interesting? Share it on your network of Twitter contacts, on your Facebook wall or simply press "+1" to suggest this result in searches in Google, Linkedin, Instagram or Pinterest. Spreading content that you find relevant helps this blog to grow. Thank you!
Share on Google Plus

About Hugo

Ubuntu is a Linux distribution that offers an operating system predominantly focused on desktop computers but also provides support for servers. Based on Debian GNU / Linux, Ubuntu focuses on ease of use, freedom in usage restriction, regular releases (every 6 months) and ease of installation.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment