7.2 Canvas widget

local   C   Desc=canvas(handle:C width:200 height:200)in   {{QTk.build td(Desc)} show}   {C create(rect 10 10 190 190 fill:blue outline:red)}   {C create(text 100 100 text:"Canvas" fill:yellow)}end   

7.2.1 Description

Canvas widgets implement structured graphics. A canvas displays any number of items, which may be things like rectangles, circles, lines, and text. Items may be manipulated (e.g. moved or re-colored) and commands may be associated with items in much the same way that the bind command allows commands to be bound to widgets. This means that items in a canvas can have behaviors defined by the Oz commands bound to them.

Normally the origin of the canvas coordinate system is at the upper-left corner of the window containing the canvas. It is possible to adjust the origin of the canvas coordinate system relative to the origin of the window using the xview and yview widget commands; this is typically used for scrolling. Canvases do not support scaling or rotation of the canvas coordinate system relative to the window coordinate system. The coordinates can be specified either as floats or integers, but they are returned as floats only.

Individual items may be moved or scaled using widget commands described below, but they may not be rotated.

7.2.2 Parameter List

Specific Parameters

closeenoughconfineheightscrollregionwidthxscrollincrementyscrollincrement

Non Specific Parameters

backgroundborderwidthcursorfeaturegluehandlehighlightbackgroundhighlightcolorhighlightthicknessinsertbackgroundinsertborderwidthinsertofftimeinsertontimeinsertwidthlooklrscrollbaronCreationpadxpadyreliefscrollwidthselectbackgroundselectborderwidthselectforegroundtakefocustdscrollbartooltips

7.2.3 Method List

'raise'

'raise'(1:W): If the W argument is omitted then the command raises the widget so that it is above all of its siblings inthe stacking order (it will not be obscured by any siblings and will obscure any siblings that overlap it). IfW is specified then it must be a handle to another widget that is either a sibling of this widget or thedescendant of a sibling of this widget. In this case the 'raise' command will insert this widget into the stacking orderjust above W; this could end up either raisingor lowering the widget.

bind

bind(event:E action:A args:LA append:AP): Specifies an action LA to execute when the event E is triggered.

canvasx

canvasx(1:I 2:V: or canvasx(1:I 2:I 3:V): Returns the canvas x-coordinate corresponding to a window coordinate. The first parameter specifies the window coordinate. This method binds the last parameter to the corresponding canvas coordinate. If a supplementary second parameter is given, then the canvas coordinate is rounded to the nearest multiple of that parameter.

canvasy

canvasy(1:I 2:V: or canvasy(1:I 2:I 3:V): Returns the canvas y-coordinate corresponding to a window coordinate. The first parameter specifies the window coordinate. This method binds the last parameter to the corresponding canvas coordinate. If a supplementary second parameter is given, then the canvas coordinate is rounded to the nearest multiple of that parameter.

create

create(1:A ...): Creates a new item in the canvas of type A. The exact format of the arguments after type depends on type, but usually they consist of the coordinates for one or more points, followed by specifications for zero or more item options. If a handle parameter is specified, it is bound to an Oz object controlling the canvas item. See the subsections on individual item types below for more on the syntax of this command.

focus

focus(1:R): Set the keyboard focus for the canvas widget to the item given by R. If R refers to several items, then the focus is set to the first such item in the display list that supports the insertion cursor. If R doesn't refer to any items, or if none of them support the insertion cursor, then the focus isn't changed. If R is an empty string, then the focus item is reset so that no item has the focus.

get

get(parameter1:Variable1 ... parameterX:VariableX): Obtains the value of one or more parameters. parameterX must be a valid parameter for the widget. VariableX must be free variables that will receive the current value of the parameters.

getFocus

getFocus(force:B): if B is false (or by default): if the application currently has the input focus on the widget's display, this command resets the input focus for the widget's display to the widget. If the application doesn't currently have the input focus on the widget's display, the widget will be remembered as the focus for its top-level; the next time the focus arrives at the top-level, it will be redirected it to the widget. If B is true: sets the focus of the widget's display to the widget, even if the application doesn't currently have the input focus for the display. This command should be used sparingly, if at all. In normal usage, an application should not claim the focus for itself; instead, it should wait for the window manager to give it the focus. B must be a boolean.

getGrabStatus

getGrabStatus(1:V): Binds V to the atom none if there is no grab on the widget, to the atom local if there is a local grab and to global if there is a global grab. V must be a free variable.

lower

lower(1:W): If the W argument is omitted then the command lowers the widget so that it is below all of its siblings inthe stacking order (it will be obscured by any siblings and will not obscure any siblings that overlap it). IfW is specified then it must be a handle to another widget that is either a sibling of this widget or thedescendant of a sibling of this widget. In this case the lower command will insert this widget into the stacking orderjust below W; this could end up either raisingor lowering the widget.

newTag

newTag(1:V): Binds V to a canvas tag (see Section 7.2.5 for details).

postscript

postscript(param1:value1 ... paramX:valueX: Generate a Postscript representation for part or all of the canvas. The Postscript is created in Encapsulated Postscript form using version 3.0 of the Document Structuring Conventions. Note: by default Postscript is only generated for information that appears in the canvas's window on the screen. If the canvas is freshly created it may still have its initial size of 1x1 pixel so nothing will appear in the Postscript. To get around this problem either invoke the update command to wait for the canvas window to reach its final size, or else use the width and height options to specify the area of the canvas to print. The option-value argument pairs provide additional information to control the generation of Postscript. The following options are supported:

releaseGrab

releaseGrab: Releases the grab on the widget if there is one, otherwise does nothing.

scan

scan(...): This command is used to implement scanning on canvases. It has two forms, depending on option:

select

select(...): Manipulates the selection in one of several ways, depending on option. The command may take any of the forms described below. In all of the descriptions below, Tag must refer to an item that supports indexing and selection; if it refers to multiple items then the first of these that supports indexing and the selection is used.

set

set(parameter1:value1 ... parameterX:valueX): Changes the value of one or more parameters. parameterX must be a valid parameter for the widget. valueX must be a valid value for the parameter.

setGrab

setGrab(global:B): Sets a grab on the widget. If B is true then the grab is global, otherwise it is local (B false by default). If a grab was already in effect for this application then it is automatically released. If there is already a grab on the widget and it has the same global/local form as the requested grab, then the command does nothing. Local grab affects only the grabbing application: events willbe reported to other applications as if the grab had never occurred. A global grablocks out all applications on the screen, so that only the given subtree of the grabbing application will besensitive to pointer events (mouse button presses, mouse button releases, pointer motions, window entries, andwindow exits). During global grabs the window manager will not receive pointer events either. Warning: whe a grab is set, it is define for the whole Oz process so that it will prevent the user to do input to other windows as well. Moreover a grab is still effective even if the window that contains the grabbed widgets is hidden. B must be a boolean.

winfo

winfo(parameter1:value1 ... parameterX:valueX): This commands works like the get method, but for window-related information. For more details, see Section 8.9.

7.2.4 Detailed Parameters List

closeenough

closeenough:F: Specifies a floating-point value indicating how close the mouse cursor must be to an item before it is considered to be ``inside'' the item. Defaults to 1.0. F must be a float value.

confine

confine:B: Specifies a boolean value that indicates whether or not it should be allowable to set the canvas's view outside the region defined by the scrollregion argument. Defaults to true, which means that the view will be constrained within the scroll region. B must be a boolean.

height

height:P: Specifies a desired window height that the canvas widget should request from its geometry manager. P must be a valid screen distance (see Section 8.6).

background

background:C: or bg:C: Specifies the normal background color to use when displaying the widget. C must be a valid color (see Section 8.2).

borderwidth

borderwidth:P: Specifies a non-negative value indicating the width of the 3-D border to draw around the outside of the widget (if such a border is being drawn; the relief option typically determines this). The value may also be used when drawing 3-D effects in the interior of the widget. P must be a valid screen distance (see Section 8.6).

cursor

cursor:A: Specifies the mouse cursor to be used for the widget. A must be a valid cursor (see Section 8.7)

feature

feature:A: Specifies a feature name for the container object to reference the object controlling this widget. For more details, see Section 4.2. A must be an atom.

glue

glue:A: Specifies how a widget must fit in its own available place. A must be an atom that is any combination of n, s, w and e. If a direction is specified, the corresponding border is glued to its neighbor or border of the frame if there is no neighbor. If a direction is not specified, the corresponding border if such that the widget takes just the width or height it needs to draw itself. If none of opposite directions is specified, the widget is centered. For more details, see Section 4.1.

handle

handle:V: Specifies a variable to reference the object controlling this widget. This variable is bound when the window is built. For more details, see Section 4.2. V must be a free variable.

highlightbackground

highlightbackground:C: Specifies the color to display in the traversal highlight region when the widget does not have the input focus. C must be a valid color (see Section 8.2)

highlightcolor

highlightcolor:C: Specifies the color to use for the traversal highlight rectangle that is drawn around the widget when it has the input focus. C must be a valid color (see Section 8.2)

highlightthickness

highlightthickness:P: Specifies a non-negative value indicating the width of the highlight rectangle to draw around the outside of the widget when it has the input focus. If the value is zero, no focus highlight is drawn around the widget. P must be a valid screen distance (see Section 8.6).

insertbackground

insertbackground:C: Specifies the color to use as background in the area covered by the insertion cursor. This color will normally override either the normal background for the widget (or the selection background if the insertion cursor happens to fall in the selection). C must be a valid color (see Section 8.2).

insertborderwidth

insertborderwidth:P: Specifies a non-negative value indicating the width of the 3-D border to draw around the insertion cursor. P must be a valid screen distance (see Section 8.6).

insertofftime

insertofftime:I: Specifies a non-negative integer value indicating the number of milliseconds the insertion cursor should remain "off" in each blink cycle. If this option is zero then the cursor doesn't blink: it is on all the time. I must be a positive integer value.

insertontime

insertontime:I: Specifies a non-negative integer value indicating the number of milliseconds the insertion cursor should remain "on" in each blink cycle. I must be a positive integer value.

insertwidth

insertwidth:P: Specifies a value indicating the total width of the insertion cursor. If a border has been specified for the insertion cursor (using the insertborderwidth option), the border will be drawn inside the width specified by the insertwidth option. P must be a valid screen distance (see Section 8.6).

look

look:L: Specifies a look to use for the widget. A look specifies default values for the parameters of widgets. This parameter can be specified at creation time only. Moreover changing a look will not change the appearance of widgets that are already displayed with that look. See Section 5.1 for more details.

lrscrollbar

lrscrollbar:B: Determines whether the widget has got a horizontal bar below. This option can be specified at creation time only. B must be a boolean.

onCreation

onCreation:P: When a widget is created, for example by QTk.build, this parameter specifies an action to execute right after the widget has been created, but before returning from the build instruction. It is usefull if one needs the handle of the widget to initialize it in ways not permitted by its description record (for example binding the Enter or Leave mouse events).

padx

padx:P: Specifies how much horizontal external padding to leave on each side of the widget. This space is added outside the widget border. P must be a valid screen distance (see Section 8.6)

pady

pady:P: Specifies how much vertical external padding to leave on each side of the widget. This space is added outside the widget border. P must be a valid screen distance (see Section 8.6)

relief

relief:A: Specifies the 3-D effect desired for the widget. Must be one of these atoms: raised, sunken, flat, ridge, solid or groove. The value indicates how the interior of the widget should appear relative to its exterior; for example, raised means the interior of the widget should appear to protrude from the screen, relative to the exterior of the widget.

scrollwidth

scrollwidth:P: Specifies the width of the vertical and horizontal scrollbars. P must be a valid screen distance (see Section 8.6)

selectbackground

selectbackground:C: Specifies the background color to use when displaying selected items. C must be a valid color (see Section 8.2).

selectborderwidth

selectborderwidth:P: pecifies a non-negative value indicating the width of the 3-D border to draw around selected items. P must be a valid screen distance (see Section 8.6).

selectforeground

selectforeground:C: Specifies the foreground color to use when displaying selected items. C must be a valid color (see Section 8.2).

takefocus

takefocus:B: Determines whether the window accepts the focus during keyboard traversal (e.g., Tab and Shift-Tab). Before setting the focus to a window, the traversal mechanims consult the value of the takeFocus option. A value of false means that the widget should be skipped entirely during keyboard traversal. true means that the widget should receive the input focus as long as it is viewable (it and all of its ancestors are mapped). B must be a boolean.

tdscrollbar

tdscrollbar:B: Determines whether the widget has got a vertical bar at the right. This option can be specified at creation time only. B must be a boolean.

tooltips

tooltips:VS: Specifies a tooltip for the widget. A tooltip is a small message that appears when the mouse cursor if left still over the widget for a while. If VS is set to nil, no tooltip will appear at all. VS must be a virtual string.

scrollregion

scrollregion:Q: Specifies four coordinates describing the left, top, right, and bottom coordinates of a rectangular region. This region is used for scrolling purposes and is considered to be the boundary of the information in the canvas. Q must be a record of the form q(X1 Y1 X2 Y2). X1, Y1, X2 and Y2 must be valid screen distances (see Section 8.6).

width

width:P: Specifies a desired window width that the canvas widget should request from its geometry manager. P must be a valid screen distance (see Section 8.6).

xscrollincrement

xscrollincrement:P: Specifies an increment for horizontal scrolling. If the value of this option is greater than zero, the horizontal view in the window will be constrained so that the canvas x coordinate at the left edge of the window is always an even multiple of xscrollincrement; furthermore, the units for scrolling (e.g., the change in view when the left and right arrows of a scrollbar are selected) will also be xscrollincrement. If the value of this option is less than or equal to zero, then horizontal scrolling is unconstrained. P must be a valid screen distance (see Section 8.6).

yscrollincrement

yscrollincrement:P: Specifies an increment for vertical scrolling. If the value of this option is greater than zero, the vertical view in the window will be constrained so that the canvas y coordinate at the top edge of the window is always an even multiple of yscrollincrement; furthermore, the units for scrolling (e.g., the change in view when the top and bottom arrows of a scrollbar are selected) will also be yscrollincrement. If the value of this option is less than or equal to zero, then vertical scrolling is unconstrained. P must be a valid screen distance (see Section 8.6).

7.2.5 Canvas item handles and canvas tags

When creating an item, it is possible to ask for a handle to further manipulate this item. Another way of manipulating items is to by means of canvas tags. Zero, one or more canvas items can be assigned to a single tag. A tag is an Oz object that manipulates all items that are assigned to it. Tags are obtained by the newTag($) method and are assigned to items by their tag parameter. Canvas tags and canvas items objects support the same methods. The handle to a canvas item can be seen as a private tag for this item only. As such, the documentation below will only refer to tags, implicitely implying handle to canvas items also.

Note: when manipulating text items, particular positions of the charaters are specified by one of the following form:

Methods supported by canvas tags and canvas items handles:

7.2.6 Graphical items

The sections below describe the various types of items supported by canvas widgets. Each item type is characterized by two things: first, the form of the create method used to create instances of the type; and second, a set of configuration options for items of that type.

ARC ITEMS

Items of type arc appear on the display as arc-shaped regions. An arc is a section of an oval delimited by two angles (specified by the start and extent options) and displayed in one of several ways (specified by the style option). Arcs are created with widget commands of the following form:

create(arc X1 Y1 X2 Y2 param1:value1 ... paramX:valueX)

The arguments X1, Y1, X2, and Y2 give the coordinates of two diagonally opposite corners of a rectangular region enclosing the oval that defines the arc. After the coordinates there may be any number of option-value pairs, each of which sets one of the configuration options for the item. These same option-value pairs may be used in itemconfigure widget commands to change the item's configuration. The following options are supported for arcs:

BITMAP ITEMS

Items of type bitmap appear on the display as images with two colors, foreground and background. Bitmaps are created with widget commands of the following form:

create(bitmap X Y param1:value1 ... paramX:valueX)

The arguments X and Y specify the coordinates of a point used to position the bitmap on the display (see the anchor option below for more information on how bitmaps are displayed). After the coordinates there may be any number of parameters, each of which sets one of the configuration options for the item. The following options are supported for bitmaps:

IMAGE ITEMS

Items of type image are used to display images on a canvas. Images are created with widget commands of the following form:

create(image X Y param1:value1 ... paramX:valueX)

The arguments X and Y specify the coordinates of a point used to position the image on the display (see the anchor option below for more information). After the coordinates there may be any number of parameters, each of which sets one of the configuration options for the item. The following options are supported for images:

LINE ITEMS

Items of type line appear on the display as one or more connected line segments or curves. Lines are created with widget commands of the following form:

create(line X1 Y1 ... Xn Yn param1:value1 ... paramX:valueX)

The arguments X1 through Yn give the coordinates for a series of two or more points that describe a series of connected line segments. After the coordinates there may be any number of parameters, each of which sets one of the configuration options for the item. The following options are supported for lines:

OVAL ITEMS

Items of type oval appear as circular or oval regions on the display. Each oval may have an outline, a fill, or both. Ovals are created with widget commands of the following form:

create(oval X1 Y1 X2 Y2 param1:value1 ... paramX:valueX)

The arguments X1, Y1, X2, and Y2 give the coordinates of two diagonally opposite corners of a rectangular region enclosing the oval. The oval will include the top and left edges of the rectangle not the lower or right edges. If the region is square then the resulting oval is circular; otherwise it is elongated in shape. After the coordinates there may be any number of parameters, each of which sets one of the configuration options for the item. The following parameters are supported for ovals:

POLYGON ITEMS

Items of type polygon appear as polygonal or curved filled regions on the display. Polygons are created with widget commands of the following form:

create(polygon X1 Y1 ... Xn Yn param1:value1 ... paramX:valueX)

The arguments X1 through Yn specify the coordinates for three or more points that define a closed polygon. The first and last points may be the same; whether they are or not, the polygon if drawed as a closed polygon. After the coordinates there may be any number of parameters, each of which sets one of the configuration options for the item. The following parameters are supported for polygons:

Polygon items are different from other items such as rectangles, ovals and arcs in that interior points are considered to be ``inside'' a polygon even if it is not filled. For most other item types, an interior point is considered to be inside the item only if the item is filled or if it has neither a fill nor an outline. If you would like an unfilled polygon whose interior points are not considered to be inside the polygon, use a line item instead.

RECTANGLE ITEMS

Items of type rectangle appear as rectangular regions on the display. Each rectangle may have an outline, a fill, or both. Rectangles are created with widget commands of the following form:

create(rectangle X1 Y1 X2 Y2 param1:value1 ... paramX:valueX)

The arguments X1, Y1, X2, and Y2 give the coordinates of two diagonally opposite corners of the rectangle (the rectangle will include its upper and left edges but not its lower or right edges). After the coordinates there may be any number of parameters for the item. The following parameters are supported for rectangles:

TEXT ITEMS

A text item displays a string of characters on the screen in one or more lines. Text items support indexing and selection, along with the following tag methods: dchars, focus, icursor, index, insert, select. Text items are created with widget commands of the following form:

create(text X Y param1:value1 ... paramX:valueX)

The arguments X and Y specify the coordinates of a point used to position the text on the display (see the options below for more information on how text is displayed). After the coordinates there may be any number of paremeters. The following parameters are supported for text items:

WINDOW ITEMS

Items of type window cause a particular window to be displayed at a given position on the canvas. Window items are created with widget commands of the following form:

create(window X Y window:Desc param1:value1 ... paramX:valueX)

The arguments X and Y specify the coordinates of a point used to position the window on the display. The Desc parameter is a usual description of a window (like td(...)) that is to display. After these parameters there may be any number of parameters. The following options are supported for window items:

Note: due to restrictions in the ways that windows are managed, it is not possible to draw other graphical items (such as lines and images) on top of window items. A window item always obscures any graphics that overlap it, regardless of their order in the display list.


Donatien Grolaux
Version 1.3.0 (20040413)