canvas::ed...adrilateral(n)
π
canvas::edit::quadrilateral β editing a quadrilateral on a canvas (the tklib manual, bestie edition)
okay so first things first: this page lives in the tklib manual set, and the whole thing is about canvas::edit::quadrilateral β yes that's a mouthful, we're gonna get through it together π«Ά
β¨ NAME β¨
canvas::edit::quadrilateral β editing a quadrilateral on a canvas. that's it, that's the vibe π
π SYNOPSIS π
package require Tcl 8.5
package require Tk 8.5
package require canvas::edit::points ?0.1?
package require canvas::edit::quadrilateral ?0.1?
::canvas::edit quadrilateral objectName canvas options...
objectName destroy
objectName enable
objectName disable
objectName active
objectName add x y
objectName clear
createCmd canvas x y
highlightCmd on canvas item
highlightCmd off canvas state
dataCmd editorObj coordinates
like, that's the whole menu. iconic honestly β¨
π¦ DESCRIPTION π¦
so this package hands you a class, and instances of that class handle the editing of a quadrilateral on a canvas π₯. you can configure the instances for how the vertex markers look β both the regular look and the highlighted look, because yes, aesthetics matter.
the important bit: instances do not store the edited quadrilateral themselves. nope. they delegate that whole job to a configurable object. main character energy: the editor just edits, someone else holds the data π
π CLASS API π
::canvas::edit quadrilateral objectName canvas options...
this is the class command, and it creates and configures a brand new instance of a quadrilateral editor named objectName. the instance gets connected to the canvas widget you named in canvas.
the result of the command is the fully qualified name of the instance command. slay β¨
the options accepted here, and their values, are explained down in [OPTIONS](#-options-), no skipping ahead π
π INSTANCE API π
instances of the quadrilateral editors provide the following API, bestie:
objectName destroy
this method destroys the quadrilateral editor and releases all its internal resources. bye girl π
note that this operation does not destroy the items the editor managed on the attached canvas, and it doesn't destroy the canvas itself either.
the result of the method is an empty string.
objectName enable
this method activates editing of the quadrilateral on the canvas. this is the default after instance creation. a call is ignored if the editor is already active.
the result of the method is an empty string.
the complementary method is disable. the interrogatory method for the current state is active.
objectName disable
this method disables editing of the quadrilateral on the canvas. a call is ignored if the editor is already disabled.
the result of the method is an empty string.
the complementary method is enable. the interrogatory method for the current state is active.
objectName active
this method queries the editor state.
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.
objectName add x y
this method programmatically adds a vertex at the specified location to the quadrilateral.
the result of the method is an empty string.
ngl this one's important: note that this method goes through the whole set of callbacks invoked when the user interactively creates a vertex β that means -create-cmd, and, more importantly, -data-cmd π
this is the method you use to load the vertices of a pre-existing quadrilateral into an editor instance.
note that at most 4 vertices can be specified, and at least 4 must be specified for the quadrilateral to be complete. quadrilateral rules, no cap.
objectName clear
this method programmatically unsets the quadrilateral in the editor. poof, gone π
the result of the method is an empty string.
note that this method goes through the same callback invoked when the user interactively removes a vertex, i.e. -data-cmd.
π OPTIONS π
the class command accepts the following options:
-convex booleanβ the value of this option is a boolean flag. when the flag is set, the editor will accept only convex quadrilaterals and reject all operations which would result in a violation of convexity. this option can only be set at construction time. if not specified it defaults tofalse, i.e. acceptance of any quadrilateral.-tag stringβ the value of this option is the name of the canvas tag with which to identify all items of all quadrilateral managed by the editor. this option can only be set at construction time. if not specified it defaults toQUADRILATERAL.-create-cmd command-prefixβ the value of this option is a command prefix the editor will invoke when it has to create a new vertex. this option can only be set at construction time. 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:
createCmd canvas x y
the result of the command prefix must be a list of the canvas items it created to represent the marker. note here that the visual representation of a "vertex" may consist of multiple canvas items in an arbitrary shape. multi-item markers, we love to see it π¦
-highlight-cmd command-prefixβ the value of this option is a command prefix the editor will invoke when it has to (un)highlight a vertex. this option can only be set at construction time. if not specified it defaults to a command which will re-color the item to highlight in red (and restores the color for unhighlighting). the two signatures of this command prefix are:
highlightCmd on canvas item
this method of the command prefix has to perform whatever is needed to highlight the vertex the item is a part of (remember the note above about quadrilateral allowed to be constructed from multiple canvas items). the result of the command can be anything and will be passed as is as argument state to the off method.
highlightCmd off canvas state
this method is invoked to unhighlight a vertex described by the state, which is the unchanged result of the on method of the command prefix. the result of this method is ignored.
note any interaction between dragging and highlighting of quadrilateral is handled within the editor, and that the callback bears no responsibility for doing such. the editor's got it, don't stress π
-data-cmd command-prefixβ the value of this option is a command prefix the editor will invoke when the quadrilateral was edited in some way. this is how the editor delegates the actual storage of quadrilateral information to an outside object. 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 signatures of this command prefix are:
dataCmd editorObj coordinates
this callback is invoked when the quadrilateral was changed either interactively, or programmatically. see instance method add for the latter. 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.
π BUGS, IDEAS, FEEDBACK π
this document, and the package it describes, will undoubtedly contain bugs and other problems. i meanβ¦ it's software, bestie π
please report such in the category canvas of the Tklib Trackers at http://core.tcl.cdk/tklib/reportlist β okay no wait, let me not fumble it, it's exactly this: http://core.tcl.tk/tklib/reportlist π«Ά
please also report any ideas for enhancements you may have for either package and/or documentation. they genuinely want your thoughts, periodt.
β KEYWORDS β
canvas, concave, convex, editing, non-convex, quadrilateral
and that's the whole page, bestie π this one's from the tklib source, version 0.1 β go forth and edit your quadrilaterals, you've got this πβ¨
π¦ where this page comes from
- alpine 3.24: tk-lib-doc 0.7-r0 Β· TCL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms