<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Tue May 21 06:03:26 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='164'>
<header><title>Add Rotate Subcommand to the Canvas Widget</title><author address="mailto:arjen.markus@wldelft.nl">Arjen Markus</author><author address="mailto:dzach@hol.gr">Dimitrios Zachariadis</author><author address="mailto:donal.k.fellows@manchester.ac.uk">Donal K. Fellows</author><status type='project' state='draft' tclversion="8.7" vote='prior'>$Revision: 1.5 $</status><history></history><created day='17' month='nov' year='2003' /><keyword>Tk canvas</keyword></header>
<abstract>This TIP proposes to add a <emph style="italic">rotate</emph> subcommand to the canvas widget to facilitate rotating items in very much the same way as is now possible with scaling and moving.</abstract>
<body><section title="Rationale">
<para>The canvas currently allows a programmer to scale and move items, but the third common affine transformation, rotation, is not supported. This can in itself be simulated by a script (simply get the coordinates of all items involved, transform them and set the new coordinates), but if you have several hundreds or even thousands of items this gets very slow.</para>
<para>Rotation is easy for polygons and lines: simply transform the coordinates. For circles and circular arcs new bounding boxes must be calculated and in addition for arcs the starting angle must be changed.</para>
<para>Implementing rotation should consider what to do with items that can not (easily) be rotated: text items, rectangles, non-circular ovals and arcs, widgets and images. Currently, text can not be drawn at an arbitrary angle, so I propose to only transform the coordinates at which the text is &quot;anchored&quot;. A similar strategy can be used for widgets and images.</para>
<para>For rectangles and general ovals and arcs there are two choices:</para>
<itemize><item.i><para>Transforming the item into a polygon would solve the definition problem (these items are defined by a bounding box and the orientation is implicitly assumed), but might break scripts that look for a particular type of item.</para></item.i><item.i><para>Therefore we will simply calculate a new bounding box and <emph style="italic">ignore changes in orientation</emph>.</para></item.i></itemize>
</section>
<section title="Proposal">
<para>Canvases will have a new subcommand, <emph style="bold">rotate</emph>, which will rotate the coordinates of chosen items by a specified angle about a specified point.</para>
<quote><emph style="italic">canvas</emph> <emph style="bold">rotate</emph> <emph style="italic">itemOrTag</emph> <emph style="italic">x</emph> <emph style="italic">y</emph> <emph style="italic">angle</emph></quote>
<para>Note that most of the arguments are very similar to the canvas&apos;s <emph style="bold">scale</emph> subcommand. <emph style="italic">Angle</emph> is measured in degrees, with positive values indicating anti-clockwise rotation.</para>
<subsection title="Canvas Item C API Alterations">
<para>[These are required for this TIP, but are not yet done.]</para>
</subsection>
</section>
<section title="Reference Implementation">
<para>A reference implementation does <emph style="italic">not</emph> yet exist.</para>
</section>
<section title="Future Work">
<para>Should we also consider the possibility of reflections in a line?</para>
<para>Should we also consider more general linear transformations (to be specified via a 2x2 matrix)? What about full affine transformations (i.e. with the translation components)?</para>
<para>If we implement these from the start, we need to do only a little more work.</para>
</section>
<section title="Comments">
<para>It might be useful to utilize the -anchor Tk option in all canvas items and add a new &quot;-anchoroffset $x,$y&quot; option, where $x $y be canvas distances relevant to the anchor position. Once defined, or with their default values, the -anchor and -anchoroffset values combined will provide the item&apos;s center, for placement and rotation purposes. Item sets, constituting symbols, can then be manipulated easily.</para>
<para>It could probably be beneficial to add an -angle option (and an accomplanying -angleunit one), to persist a rotation angle in the configuration database. The presence of an angle value other than zero would help negate rotation, thus re-instating the item to its initial orientation.</para>
</section>
<section title="Copyright">
<para>This document is placed in the public domain.</para>
</section>
</body></TIP>
