This file is indexed.

/usr/share/mozart/doc/wp/node35.html is in mozart-doc 1.4.0-8ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

1
2
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>6.3 Canvas Tags</TITLE><LINK href="ozdoc.css" rel="stylesheet" type="text/css"></HEAD><BODY><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node34.html#section.canvas.barchart">&lt;&lt; Prev</A></TD><TD><A href="node32.html">- Up -</A></TD><TD><A href="node36.html#section.canvas.animated">Next &gt;&gt;</A></TD></TR></TABLE><DIV id="section.canvas.tags"><H2><A name="section.canvas.tags">6.3 Canvas Tags</A></H2><P><A name="label295"></A> Each item in a canvas is identified by a unique integer. This integer can be returned by using the <CODE>tkReturnInt</CODE> method for creating items rather than the <CODE>tk</CODE> method. The returned integer can then be used to manipulate the corresponding item. However, returning values from the graphics engine involves latency. But there are some good news here, since it is not necessary to refer to items by numbers. </P><DIV class="apropos"><P class="margin">tags</P><P> Canvas widgets offer a more powerful and easier method to manipulate single items or even groups of items. Items can be referred to by <A name="label296"></A><EM>tags</EM>. A single item can be referred to by as many tags as you like to. Tags are provided as objects in Oz. Before an item can be added to a tag, a tag object must be created from the class <CODE>Tk<SPAN class="keyword">.</SPAN>canvasTag</CODE> and initialized with respect to a particular canvas. </P></DIV><P> To add an item to a tag, the option <CODE>tags</CODE> is used when creating the item. For instance, <A name="label298"></A> </P><DL class="anonymous"><DD class="code"><CODE>R={New&nbsp;Tk<SPAN class="keyword">.</SPAN>canvasTag&nbsp;tkInit(parent:C)}<BR>{C&nbsp;tk(create&nbsp;rectangle&nbsp;10&nbsp;10&nbsp;40&nbsp;40&nbsp;fill:red&nbsp;tags:R)}</CODE></DD></DL><P> creates a new rectangle item and adds it to the tag <CODE>R</CODE>. </P><P> A second oval item can be added to the tag <CODE>R</CODE> by </P><DL class="anonymous"><DD class="code"><CODE>{C&nbsp;tk(create&nbsp;oval&nbsp;20&nbsp;20&nbsp;40&nbsp;40&nbsp;tags:R)}</CODE></DD></DL><P> All items referred to by a tag can be manipulated simultaneously. The following moves all items 40 pixels to the right: </P><DL class="anonymous"><DD class="code"><CODE>{R&nbsp;tk(move&nbsp;40&nbsp;0)}</CODE></DD></DL><P> </P><P> <A href="node35.html#figure.canvas.tags">Figure&nbsp;6.3</A> shows a small program that creates items interactively. Pressing the mouse button over the canvas widget creates either a rectangle item or an oval item at the position of the mouse pointer. All rectangle items created are added to the tag <CODE>R</CODE>, and all oval items are added to the tag <CODE>O</CODE>. </P><P> </P><DIV id="figure.canvas.tags"><HR><P><A name="figure.canvas.tags"></A></P><P> </P><DIV align="center"><IMG alt="" src="tags.gif"></DIV><P> </P><DL class="anonymous"><DD class="code"><CODE>C={New&nbsp;Tk<SPAN class="keyword">.</SPAN>canvas&nbsp;&nbsp;&nbsp;&nbsp;tkInit(parent:W&nbsp;width:300&nbsp;height:200&nbsp;bg:white)}<BR>R={New&nbsp;Tk<SPAN class="keyword">.</SPAN>canvasTag&nbsp;tkInit(parent:C)}<BR>O={New&nbsp;Tk<SPAN class="keyword">.</SPAN>canvasTag&nbsp;tkInit(parent:C)}<BR>{C&nbsp;tkBind(event:&nbsp;&nbsp;<SPAN class="string">'&lt;1&gt;'</SPAN>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;args:&nbsp;&nbsp;&nbsp;[int(x)&nbsp;int(y)]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action:&nbsp;<SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">$</SPAN>&nbsp;X&nbsp;Y}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{C&nbsp;tk(create&nbsp;rectangle&nbsp;X<SPAN class="keyword">-</SPAN>10&nbsp;Y<SPAN class="keyword">-</SPAN>10&nbsp;X<SPAN class="keyword">+</SPAN>10&nbsp;Y<SPAN class="keyword">+</SPAN>10<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tags:R&nbsp;fill:steelblue)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>)}<BR>{C&nbsp;tkBind(event:&nbsp;&nbsp;<SPAN class="string">'&lt;2&gt;'</SPAN>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;args:&nbsp;&nbsp;&nbsp;[int(x)&nbsp;int(y)]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action:&nbsp;<SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">$</SPAN>&nbsp;X&nbsp;Y}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{C&nbsp;tk(create&nbsp;oval&nbsp;X<SPAN class="keyword">-</SPAN>10&nbsp;Y<SPAN class="keyword">-</SPAN>10&nbsp;X<SPAN class="keyword">+</SPAN>10&nbsp;Y<SPAN class="keyword">+</SPAN>10<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tags:O&nbsp;fill:orange)}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>)}<BR>{Tk<SPAN class="keyword">.</SPAN>send&nbsp;pack(C)}</CODE></DD></DL><P> </P><P class="caption"><STRONG>Figure&nbsp;6.3:</STRONG> A canvas for creating rectangles and ovals.</P><HR></DIV><P> </P><DIV class="apropos"><P class="margin">configuring items</P><P> <A name="label300"></A> Items can be configured with the command <CODE>itemconfigure</CODE>, which is similar to the command <CODE>configure</CODE> for widgets. The color of all rectangle and oval items in our previous example can be changed by: </P><DL class="anonymous"><DD class="code"><CODE>{R&nbsp;tk(itemconfigure&nbsp;fill:wheat)}<BR>{O&nbsp;tk(itemconfigure&nbsp;fill:blue)}</CODE></DD></DL><P> </P></DIV><P> Besides of the <CODE>move</CODE> command there are other commands for manipulating items. For instance, executing the following statement </P><DL class="anonymous"><DD class="code"><CODE>{O&nbsp;tk(delete)}</CODE></DD></DL><P> deletes all oval items attached to the tag <CODE>O</CODE>. Other commands allow to scale items, to change the coordinates of items and so on. More information on possible commands are available from <A href="../tcltk/TkCmd/canvas.htm"><KBD>canvas</KBD></A>. </P><H3><A name="label301">6.3.1 Event Bindings</A></H3><P> Similar to widgets, event bindings can be created for tags. Creating an event binding for a tag means to create the binding for all items referred to by the tag. The following example creates an event binding for all oval items. <A name="label302"></A> </P><DL class="anonymous"><DD class="code"><CODE>Colors={New&nbsp;<SPAN class="keyword">class</SPAN>&nbsp;<SPAN class="type">$</SPAN>&nbsp;<SPAN class="keyword">from</SPAN><SPAN class="type">&nbsp;BaseObject</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">attr</SPAN>&nbsp;cs:(Cs=red<SPAN class="keyword">|</SPAN>green<SPAN class="keyword">|</SPAN>blue<SPAN class="keyword">|</SPAN>yellow<SPAN class="keyword">|</SPAN>orange<SPAN class="keyword">|</SPAN>Cs&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">in</SPAN>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cs)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">meth</SPAN>&nbsp;<SPAN class="functionname">get</SPAN>(?C)&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Cr&nbsp;<SPAN class="keyword">in</SPAN>&nbsp;C<SPAN class="keyword">|</SPAN>Cr&nbsp;=&nbsp;(cs&nbsp;<SPAN class="keyword">:=</SPAN>&nbsp;Cr)&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>&nbsp;noop}<BR>{O&nbsp;tkBind(event:&nbsp;&nbsp;<SPAN class="string">'&lt;3&gt;'</SPAN>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action:&nbsp;<SPAN class="keyword">proc</SPAN><SPAN class="variablename">&nbsp;</SPAN>{<SPAN class="functionname">$</SPAN>}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{O&nbsp;tk(itemconfigure&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fill:{Colors&nbsp;get($)})}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<SPAN class="keyword">end</SPAN>)}</CODE></DD></DL><P> </P><P> Clicking with the right mouse button on an oval item, configures all items referred to by <CODE>O</CODE> to employ a different color. The <CODE>Colors</CODE> object serves as color generator. Each time the method <CODE>get</CODE> is invoked, it returns a color from the circular list of colors stored in the attribute <CODE>cs</CODE>. </P></DIV><TABLE align="center" border="0" cellpadding="6" cellspacing="6" class="nav"><TR bgcolor="#DDDDDD"><TD><A href="node34.html#section.canvas.barchart">&lt;&lt; Prev</A></TD><TD><A href="node32.html">- Up -</A></TD><TD><A href="node36.html#section.canvas.animated">Next &gt;&gt;</A></TD></TR></TABLE><HR><ADDRESS><A href="http://www.ps.uni-sb.de/~schulte/">Christian&nbsp;Schulte</A><BR><SPAN class="version">Version 1.4.0 (20110908185330)</SPAN></ADDRESS></BODY></HTML>