canvas

Name

canvas  -- A widget which displays graphic objects (in gnoclCanvas).

Synopsis

canvas [-option value...]

Screenshot

Options

-antialiased

type: boolean (default: 1)

Whether the canvas is antialiased. This cannot be changed after creation.

-background

type: COLOR

Background color of the canvas.

-centerScroll

type: boolean

Whether to center the scrolling region in the canvas window when it is smaller than the canvas' allocation.

-hasFocus

type: 1

This sets the focus to the widget. To unset the focus it must be set to another widet.

-height

type: integer

Height of the widget.

-name

type: string

Name of the widget, can be used to set options in an rc file.

-onButtonPress

type: string (default: "")

Tcl command which is executed if a mouse button is press inside the widget. Before evaluation the following percent strings are substituated: TABLE %% | % %w | widget name %t | type of event: one of buttonPress, button2Press or button3Press %x | x coordinate %y | y coordinate %b | button number %s | state of the buttons and modifiers (bitmask) TABLE

-onButtonRelease

type: string (default: "")

Tcl command which is executed if a mouse button is released inside the widget. Before evaluation the following percent strings are substituated: TABLE %% | % %w | widget name %t | type of event: always buttonRelease %x | x coordinate %y | y coordinate %b | button number %s | state of the buttons and modifiers (bitmask) TABLE

-onKeyPress

type: string (default: "")

Tcl command which is executed if a key is pressed while the widget is having the focus. Before evaluation the following percent strings are substituated: TABLE %% | % %w | widget name %k | key code as integer %K | key code as symbol %a | unicode unicode character, or the empty string if there is no corresponding character. %s | state of the buttons and modifiers (bitmask) TABLE

-onKeyRelease

type: string (default: "")

Tcl command which is executed if a key is released while the widget is having the focus. Before evaluation the following percent strings are substituated: TABLE %% | % %w | widget name %k | key code as integer %K | key code as symbol %a | unicode unicode character, or the empty string if there is no corresponding character. %s | state of the buttons and modifiers (bitmask) TABLE

-onMotion

type: string (default: "")

Tcl command which is executed if the mouse is moved inside the widget. Before evaluation the following percent strings are substituated: TABLE %% | % %w | widget name %x | x coordinate %y | y coordinate %s | state of the buttons and modifiers (bitmask) TABLE

-scrollRegion

type: list-of-four-floats

Region in which the canvas will then be able to scroll. The view of the canvas is adjusted as appropriate to display as much of the new region as possible.

-visible

type: boolean (default: 1)

Whether or not the item is visible.

-width

type: integer

Width of the widget.

Description

Canvas widgets implement structured graphics. A canvas displays any number of items, which may be rectangles, circles, lines, and text. Items may be manipulated (e.g. moved, scaled, rotated or re-colored) and commands may be associated with items with the bind command. For example, a particular command may be associated with the <button>-event so that the command is invoked whenever a button is pressed with the mouse cursor over an item. This means that items in a canvas can have behaviors defined by the Tcl scripts bound to them. Canvas items can be taged, so that all items with the same tag can be configured at once.

Commands

id delete

Deletes the widget and the associated tcl command.

id configure [-option value...]

Configures the widget. Option may have any of the values accepted on creation of the widget.

id create type [-option value...]

Create a new item of type type. Type can be one of "line", "rectangle", "ellipse", "bPath", "text", "richText", or "widget". Options are dependend on the type. Returns a numerical id with which this item can be identified. IDs are garanteed to be uniq during the lifetime of a canvas.

id affine tag-or-id list-of-coordinates

make affine transformation of id. Length of list-of-coordinates must be 6� The new coordinates are calculated by x_new = af[0] * x_old + af[2] * y_old + af[4]; y_new = af[1] * x_old + af[3] * y_old + af[5];

id findItemAt x y

Returns ID of item at the world coordinates x and y.

id getBounds tag-or-id

Returns the bounds (x1, y1, x2, y2) that enclose all items with tag-or-id in world coordinates.

id itemCommand tag-or-id cmd [-option value...]

Calls a subcommand for all items with tag-or-id. The subcommand and the options are dependend on the type of the items.

id itemConfigure tag-or-id [-option value...]

Configures all items with tag-or-id. The options are dependend on the type of the items.

id itemDelete tag-or-id

Deletes all items with tag-or-id.

id itemHide tag-or-id

Hides all items with tag-or-id.

id itemShow tag-or-id

Shows all items with tag-or-id.

id move tag-or-id list-of-coordinates

Moves tag-or-id. Length of list-of-coordinates must be 2 (delta x and delta y)�

id rotate tag-or-id list-of-coordinates

Rotates tag-or-id. Length of list-of-coordinates must be 3 (center point and angle)�

id scale tag-or-id list-of-coordinates

Scales tag-or-id. Length of list-of-coordinates must be 3 (center point and scale) or 4 (center point, x scale, and y scale).

id windowToWorld list-of-coordinates

Converts window coordinates to world coordinates.

id worldToWindow list-of-coordinates

Converts world coordinates to window coordinates.

Example


set canv [gnocl::canvas -background white]
set coords {10 100 30 60 50 20 110 20 150 60 190 100}
foreach {x y} $coords {
   $canv create ellipse -coords [list $x $y 3] -centerRadius 1 -fill darkgreen
}
$canv create bPath -coords [lrange $coords 2 9] -outline red -width 2
$canv create line -coords [lrange $coords 0 5] -fill blue
$canv create line -coords [lrange $coords 6 11] -fill blue
$canv create ellipse -coords {70 140 50} -centerRadius 1 -fill "" -outline mediumOrchid
$canv create rectangle -coords {110 105 180 180} -fill "" -outline green
$canv create text -coords {80 100} -text "Gnocl" -font "Utopia 14"
gnocl::window -title "Canvas" -child $canv

results in

See also

canvas line, canvas rectangle, canvas ellipse, canvas text, canvas richText, canvas widget, GnomeCanvas