Standard Canvas Item Reference

This section describes each of the canvas items that come with Gnome, giving a table of arguments and describing any non-obvious arguments.

Rectangle and Ellipse Items

The GnomeCanvasRect and GnomeCanvasEllipse canvas items share exactly the same interface, via a GnomeCanvasRE base class. Their shape is given as a bounding box: a top left coordinate (x1, y1) and a bottom right coordinate (x2, y2). The rectangle item matches the shape of the bounding box; the ellipse is inscribed in the bounding box, touching the center of each side. Rectangles and ellipses can be filled or simply an outline. If they are only an outline, they are considered to be "hollow"; that is, the transparent area inside the shape is not part of the canvas item and events that occur in that area will not be relayed to the item.

GnomeCanvasRE does not behave gracefully if you give the coordinates in the wrong order. That is, x2 must be greater than x1, and y2 must be greater than y1; otherwise GnomeCanvasRE gets confused.

Table 1. 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
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.

Table 2. GnomeCanvasLine Arguments

Name Type Read/Write Description
points GnomeCanvasPoints* Both Points in the line
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
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.

Table 3. GnomeCanvasPolygon Arguments

Name Type Read/Write Description
points GnomeCanvasPoints* Both Points in the 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
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.

Table 4. 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)
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:

Affine transformation of GnomeCanvasText is not implemented very well. Because the X font model is inflexible and limited, there is no good way to rotate and otherwise transform rendered text. 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 GnomeCanvasText 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.

Table 5. 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
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.

Table 6. 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