canvas::edit::polyline(3tk) | Variations on a canvas | canvas::edit::polyline(3tk) |
canvas::edit::polyline - Editing a polyline on a canvas
package require Tcl 8.5
package require Tk 8.5
package require canvas::edit::points ?0.1?
package require canvas::edit::polyline ?0.2?
::canvas::edit polyline objectName canvas options...
objectName destroy
objectName enable
objectName disable
objectName active
objectName add x y
objectName clear
activeCmd editorObj id
createCmd canvas x y
dataCmd editorObj coordinates
This package provides a class whose instances handle editing a single poly-line (or -gon) on a canvas. Instances can be configured with regard to the visual appearance of the markers denoting the line's vertices, as well as if the line is to be closed or not, and further if a closed line has to be convex or not. Note that instances do not store the edited polyline themselves, but delegate this to a configurable object.
The polyline editor internally uses an instance of package canvas::edit::points, and inherits all the options and behaviours for it. The color options are additionally applied to the line element of this editor
Beyond that it provides 2 options to configure the editing mode, and one option to customize the line/polygon item used to render the line through the points.
The main editing mode is controlled by option -closed for line (i.e. open) versus polygon (i.e. closed). The default is line/open mode.
In polygon/closed mode the option -convex controls if the editor enforces convexity of the polygon, or not. The default is no enforcement of convexity.
The option -line-config enables basic customization of the line/polygon item. Note that it cannot overide the inherited color options.
The result of the command is the fully qualified name of the instance command.
The options accepted here, and their values, are explained in the section Options.
Instances of the polyline editors provide the following API:
Note that this operation does not destroy the items the editor managed on the attached canvas, nor the canvas itself.
The result of the method is an empty string.
The result of the method is an empty string.
The complementary method is disable. The interogatory method for the current state is active.
The result of the method is an empty string.
The complementary method is enable. The interogatory method for the current state is active.
The result of the method is a boolean value, true if the editor is active, and false otherwise, i.e. disabled.
The methods to change the state are enable and disable.
The result of the method is an empty string.
Note that this method goes through the whole set of callbacks invoked when the user interactively creates a vertex, i.e. -create-cmd, and, more importantly, -data-cmd.
One important difference however. The new vertex is always added at the end of the line, whereas interactive creation uses heuristics to splice it into the line at a suitable location.
This is the method through which to load the vertices of a pre-existing line into an editor instance.
The result of the method is an empty string.
Note that this method goes through the same callbacks invoked when the user interactively removes a vertex, i.e. -data-cmd.
The class command accepts the following options
If not specified it defaults to an empty command which does nothing.
The signature of this command prefix is
The id identifies the entered object.
An empty id indicates that the last entered object was left.
The value line indicates that the line was entered.
A numeric value N indicates that the N'th vertex of the line was entered, counting from 0.
The result of this method is ignored.
This option can only be set at construction time.
The default setup uses different events for adding and removing points, ButtonPress-1 and ButtonPress-2 respectively.
When using this option the same event is used for both operations. This is no problem because adding is bound as canvas-global event while removal is bound to the relevant canvas items.
This option can only be set at construction time.
If not specified it defaults to false
The default value is SkyBlue2.
This option can only be set at construction time.
If not specified it defaults to false
While this option can be set after construction, it is recommended to use this feature only as a means of inserting custom processing to be done at creation time which remembers and calls the previous value of the option.
If not specified it defaults to a command which will create a black-bordered blue circle of radius 3 centered on the location of the new point.
The signature of this command prefix is
The returned list of items is allowed to be empty, and such is taken as signal that the callback vetoed the creation of the vertex.
This option can only be set at construction time.
If not specified it defaults to an empty string and is ignored by the editor, i.e. not invoked.
The signature of this command prefix is
The editorObj identifies the instance invoking the callback, whereas coordinates is a list of vertex locations, with each location a pair of x- and y-coordinates.
The result of this method is ignored.
This option can only be set at construction time.
The default specification is ButtonPress-3.
The default value is red.
The default value is oval.
If not specified it defaults to the empty list.
The default value is 3.
This option can only be set at construction time.
If not specified it defaults to POLYLINE
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category canvas of the Tklib Trackers [http://core.tcl.tk/tklib/reportlist]. Please also report any ideas for enhancements you may have for either package and/or documentation.
canvas, editing, polyline
0.2 | tklib |