Author: Agnar Renolen <[email protected]> Author: Donal K. Fellows <[email protected]> State: Final Type: Project Tcl-Version: 8.6 Vote: Done Created: 07-Jun-2002 Post-History: Keywords: Tk Tk-Ticket: 2157629
This TIP proposes a canvas subcommand (or possibly two) that allows for replacing characters in text objects and to move individual vertices of line and polygon items.
Interactive graphics programs often allow users to modify shapes of objects by selecting and dragging the vertices. Moving one vertex of a canvas item in the current version of Tk, (at least as far as I can find out from the documentation), can only be done by first removing the coordinate by dchars and then insert the new one by insert, or for geometric items like lines and polygons using the coords command to obtain and reset the coordinates, after having modified the coordinate list by lreplace.
The most important issue here, I think, is performance. I believe that the current way of moving a vertex can be slow in some scenarios.
The rchars canvas subcommand is proposed merely to conform with the dchars and insert commands, which both operate on lines, polygons and text items, hence rchars should do that as well.
Two canvas widget subcommands are proposed: imove and rchars. The following subcommand is proposed to move a vertex of any canvas item:
canvas imove tagOrID index x y
This subcommand will move the index_th coordinate of the items identified by _tagOrID to the new position given by x and y. The index value will be processed according to normal canvas index rules (see the INDICES section of the canvas manual). The subcommand will only work for line and polygon items (or any third party items that set the TK_MOVABLE_POINTS flag).
The following command provides a similar functionality, but conforms to the model of the current insert and dchars subcommands.
canvas rchars tagOrID first last string
This command will:
for text items: replace the characters in the range first and last (inclusive) with the characters in string.
for line and polygon items: replace the coordinates in the range first and last (inclusive) with the coordinate list specified in string (subject to the requirement that the coordinate list is an even number of floating point numbers).
In both cases, first and last will be processed according to the rules in the INDICES section of the canvas manual page.
At the C level, the only change is the addition of a new flag, TK_MOVABLE_POINTS. If this flag is set in the alwaysRedraw field of the item type structure, it implies that the item supplies non-NULL dcharsProc, indexProc and insertProc fields, and gives them semantics equivalent to the line and polygon items (i.e. that the methods will work with the coordinate list). Note that text items, despite having all the required methods, do not set the flag because those methods work with character indices.
The imove subcommand is not strictly necessary as the rchars subcommand can be used to obtain the same result. However, I believe that a separate imove subcommand will be easier to understand for users than the rchars subcommand, though the latter is still necessary as it allows for more complex processing such as insertion or deletion of points.
See Patch 2157629https://sourceforge.net/support/tracker.php?aid=2157629 .
This document has been placed in the public domain.