<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://tcl.activestate.com/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Thu Feb 09 11:35:00 GMT 2012 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='97'>
<header><title>Moving Vertices of Canvas Items</title><author address="mailto:agnar.renolen@emap.no">Agnar Renolen</author><author address="mailto:donal.k.fellows@manchester.ac.uk">Donal K. Fellows</author><status type='project' state='final' tclversion="8.6" vote='after'>$Revision: 1.10 $</status><history></history><created day='7' month='jun' year='2002' /><keyword>Tk</keyword></header>
<abstract>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.</abstract>
<body><section title="Rationale">
<para>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 <emph style="bold">dchars</emph> and then insert the new one by <emph style="bold">insert</emph>, or for geometric items like lines and polygons using the <emph style="bold">coords</emph> command to obtain and reset the coordinates, after having modified the coordinate list by <emph style="bold">lreplace</emph>.</para>
<para>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.</para>
<para>The <emph style="bold">rchars</emph> canvas subcommand is proposed merely to conform with the <emph style="bold">dchars</emph> and <emph style="bold">insert</emph> commands, which both operate on lines, polygons and text items, hence <emph style="bold">rchars</emph> should do that as well.</para>
</section>
<section title="Specification">
<para>Two canvas widget subcommands are proposed: <emph style="bold">imove</emph> and <emph style="bold">rchars</emph>. The following subcommand is proposed to move a vertex of any canvas item:</para>
<quote><emph style="italic">canvas</emph> <emph style="bold">imove</emph> <emph style="italic">tagOrID index x y</emph></quote>
<para>This subcommand will move the <emph style="italic">index</emph>th coordinate of the items identified by <emph style="italic">tagOrID</emph> to the new position given by <emph style="italic">x</emph> and <emph style="italic">y</emph>. The <emph style="italic">index</emph> value will be processed according to normal canvas index rules (see the INDICES section of the <emph style="bold">canvas</emph> manual). The subcommand will only work for line and polygon items (or any third party items that set the TK_MOVABLE_POINTS flag).</para>
<para>The following command provides a similar functionality, but conforms to the model of the current <emph style="bold">insert</emph> and <emph style="bold">dchars</emph> subcommands.</para>
<quote><emph style="italic">canvas</emph> <emph style="bold">rchars</emph> <emph style="italic">tagOrID first last string</emph></quote>
<para>This command will:</para>
<describe><item.d name='for text items'><para>replace the characters in the range <emph style="italic">first</emph> and <emph style="italic">last</emph> (inclusive) with the characters in <emph style="italic">string</emph>.</para></item.d><item.d name='for line and polygon items'><para>replace the coordinates in the range <emph style="italic">first</emph> and <emph style="italic">last</emph> (inclusive) with the coordinate list specified in <emph style="italic">string</emph> (subject to the requirement that the coordinate list is an even number of floating point numbers).</para></item.d></describe>
<para>In both cases, <emph style="italic">first</emph> and <emph style="italic">last</emph> will be processed according to the rules in the INDICES section of the <emph style="bold">canvas</emph> manual page.</para>
<para>At the C level, the only change is the addition of a new flag, <emph style="bold">TK_MOVABLE_POINTS</emph>. If this flag is set in the <emph style="italic">alwaysRedraw</emph> field of the item type structure, it implies that the item supplies non-NULL <emph style="italic">dcharsProc</emph>, <emph style="italic">indexProc</emph> and <emph style="italic">insertProc</emph> 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.</para>
<subsection title="Notes">
<para>The <emph style="bold">imove</emph> subcommand is not strictly necessary as the <emph style="bold">rchars</emph> subcommand can be used to obtain the same result. However, I believe that a separate <emph style="bold">imove</emph> subcommand will be easier to understand for users than the <emph style="bold">rchars</emph> subcommand, though the latter is still necessary as it allows for more complex processing such as insertion or deletion of points.</para>
</subsection>
</section>
<section title="Reference Implementation">
<para>See Patch 2157629[<url ref="https://sourceforge.net/support/tracker.php?aid=2157629"/>].</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
</section>
</body></TIP>

