canvas.html
来自「perl教程」· HTML 代码 · 共 1,385 行 · 第 1/5 页
HTML
1,385 行
item or a tag that selects zero or more items.</p>
<p><em>tagOrId</em> may contain a logical expressions of
tags by using operators: '&&', '||', '^' '!', and parenthezised
subexpressions. For example:</p>
<p>$c->find('withtag', '(a&&!b)|(!a&&b)');</p>
<p>or equivalently:</p>
<p>$c->find('withtag', 'a^b');</p>
<p>will find only those items with either "a" or "b" tags, but not both.</p>
<p>Some methods only operate on a single item at a
time; if <em>tagOrId</em> is specified in a way that
names multiple items, then the normal behavior is for
the methods is to use the first (lowest) of these items in
the display list that is suitable for the method.
Exceptions are noted in the method descriptions
below.</p>
<p>
</p>
<hr />
<h1><a name="coordinates">COORDINATES</a></h1>
<p>All coordinates related to canvases are stored as floating-point
numbers.
Coordinates and distances are specified in screen units,
which are floating-point numbers optionally followed
by one of several letters.
If no letter is supplied then the distance is in pixels.
If the letter is <strong>m</strong> then the distance is in millimeters on
the screen; if it is <strong>c</strong> then the distance is in centimeters;
<strong>i</strong> means inches, and <strong>p</strong> means printers points (1/72 inch).
Larger y-coordinates refer to points lower on the screen; larger
x-coordinates refer to points farther to the right.</p>
<p>
</p>
<hr />
<h1><a name="transformations">TRANSFORMATIONS</a></h1>
<p>Normally the origin of the canvas coordinate system is at the
upper-left corner of the window containing the canvas.
It is possible to adjust the origin of the canvas
coordinate system relative to the origin of the window using the
<strong>xview</strong> and <strong>yview</strong> methods; this is typically used
for scrolling.
Canvases do not support scaling or rotation of the canvas coordinate
system relative to the window coordinate system.</p>
<p>Individual items may be moved or scaled using methods
described below, but they may not be rotated.</p>
<p>
</p>
<hr />
<h1><a name="indices">INDICES</a></h1>
<p>Text items support the notion of an <em>index</em> for identifying
particular positions within the item.</p>
<p>Indices are used for methods such as inserting text, deleting
a range of characters, and setting the insertion cursor position.
An index may be specified in any of a number of ways, and
different types of items may support different forms for
specifying indices.</p>
<p>In a similar fashion, line and polygon items support <em>index</em> for
identifying, inserting and deleting subsets of their coordinates.
Indices are used for commands such as inserting or deleting
a range of characters or coordinates, and setting the insertion
cursor position. An index may be specified in any of a number
of ways, and different types of items may support different forms
for specifying indices.</p>
<p>Text items support the following forms for an index; if you
define new types of text-like items, it would be advisable to
support as many of these forms as practical.
Note that it is possible to refer to the character just after
the last one in the text item; this is necessary for such
tasks as inserting new text at the end of the item.
Lines and Polygons don't support the insertion cursor
and the selection. Their indices are supposed to be even
always, because coordinates always appear in pairs.</p>
<dl>
<dt><strong><a name="item_number"><em>number</em></a></strong>
<dd>
<p>A decimal number giving the position of the desired character
within the text item.
0 refers to the first character, 1 to the next character, and
so on. If indexes are odd for lines and polygons, they will be
automatically decremented by one.
A number less than 0 is treated as if it were zero, and a
number greater than the length of the text item is treated
as if it were equal to the length of the text item. For
polygons, numbers less than 0 or greater then the length
of the coordinate list will be adjusted by adding or substracting
the length until the result is between zero and the length,
inclusive.</p>
</dd>
</li>
<dt><strong><a name="item_end"><strong>end</strong></a></strong>
<dd>
<p>Refers to the character or coordinate just after the last one
in the item (same as the number of characters or coordinates
in the item).</p>
</dd>
</li>
<dt><strong><a name="item_insert"><strong>insert</strong></a></strong>
<dd>
<p>Refers to the character just before which the insertion cursor
is drawn in this item. Not valid for lines and polygons.</p>
</dd>
</li>
<dt><strong><a name="item_sel_2efirst"><strong>sel.first</strong></a></strong>
<dd>
<p>Refers to the first selected character in the item.
If the selection isn't in this item then this form is illegal.</p>
</dd>
</li>
<dt><strong><a name="item_sel_2elast"><strong>sel.last</strong></a></strong>
<dd>
<p>Refers to the last selected character in the item.
If the selection isn't in this item then this form is illegal.</p>
</dd>
</li>
<dt><strong><a name="item__5bx_2cy_5d"><strong>[</strong><em>x,y</em><strong>]</strong></a></strong>
<dd>
<p>Refers to the character or coordinate at the point given by <em>x</em> and
<em>y</em>, where <em>x</em> and <em>y</em> are specified in the coordinate
system of the canvas.
If <em>x</em> and <em>y</em> lie outside the coordinates covered by the
text item, then they refer to the first or last character in the
line that is closest to the given point.
The Tcl string form "@x,y" is also allowed.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="dash_patterns">DASH PATTERNS</a></h1>
<p>Many items support the notion of an dash pattern for outlines.</p>
<p>The first possible syntax is a list of integers. Each element
represents the number of pixels of a line segment. Only the odd
segments are drawn using the "outline" color. The other segments
are drawn transparant.</p>
<p>The second possible syntax is a character list containing only
5 possible characters <strong>[.,-_ ]</strong>. The space can be used
to enlarge the space between other line elements, and can not
occur as the first position in the string. Some examples:</p>
<pre>
-dash . = -dash [2,4]
-dash - = -dash [6,4]
-dash -. = -dash [6,4,2,4]
-dash -.. = -dash [6,4,2,4,2,4]
-dash '. ' = -dash [2,8]
-dash ',' = -dash [4,4]</pre>
<p>The main difference of this syntax with the previous is that it
it shape-conserving. This means that all values in the dash
list will be multiplied by the line width before display. This
assures that "." will always be displayed as a dot and "-"
always as a dash regardless of the line width.</p>
<p>On systems where only a limited set of dash patterns, the dash
pattern will be displayed as the most close dash pattern that
is available. For example, on Windows only the first 4 of the
above examples are available. The last 2 examples will be
displayed identically as the first one.</p>
<p>
</p>
<hr />
<h1><a name="widget_methods">WIDGET METHODS</a></h1>
<p>The <strong>Canvas</strong> method creates a widget object.
This object supports the <strong>configure</strong> and <strong>cget</strong> methods
described in <a href="../../lib/Tk/options.html">the Tk::options manpage</a> which can be used to enquire and
modify the options described above.
The widget also inherits all the methods provided by the generic
<a href="../../lib/Tk/Widget.html">Tk::Widget</a> class.</p>
<p>The following additional methods are available for canvas widgets:</p>
<dl>
<dt><strong><a name="item_addtag"><em>$canvas</em>-><strong>addtag</strong>(<em>tag, searchSpec, </em>?<em>arg, arg, ...</em>?)</a></strong>
<dd>
<p>For each item that meets the constraints specified by
<em>searchSpec</em> and the <em>arg</em>s, add
<em>tag</em> to the list of tags associated with the item if it
isn't already present on that list.
It is possible that no items will satisfy the constraints
given by <em>searchSpec</em> and <em>arg</em>s, in which case the
method has no effect.
This command returns an empty string as result.
<em>SearchSpec</em> and <em>arg</em>'s may take any of the following
forms:</p>
</dd>
<dl>
<dt><strong><a name="item_above_tagorid"><strong>above </strong><em>tagOrId</em></a></strong>
<dd>
<p>Selects the item just after (above) the one given by <em>tagOrId</em>
in the display list.
If <em>tagOrId</em> denotes more than one item, then the last (topmost)
of these items in the display list is used.</p>
</dd>
</li>
<dt><strong><a name="item_all"><strong>all</strong></a></strong>
<dd>
<p>Selects all the items in the canvas.</p>
</dd>
</li>
<dt><strong><a name="item_below_tagorid"><strong>below </strong><em>tagOrId</em></a></strong>
<dd>
<p>Selects the item just before (below) the one given by <em>tagOrId</em>
in the display list.
If <em>tagOrId</em> denotes more than one item, then the first (lowest)
of these items in the display list is used.</p>
</dd>
</li>
<dt><strong><a name="item_closest_x_y__3fhalo_3f__3fstart_3f"><strong>closest </strong><em>x y </em>?<em>halo</em>? ?<em>start</em>?</a></strong>
<dd>
<p>Selects the item closest to the point given by <em>x</em> and <em>y</em>.
If more than one item is at the same closest distance (e.g. two
items overlap the point), then the top-most of these items (the
last one in the display list) is used.
If <em>halo</em> is specified, then it must be a non-negative
value.
Any item closer than <em>halo</em> to the point is considered to
overlap it.
The <em>start</em> argument may be used to step circularly through
all the closest items.
If <em>start</em> is specified, it names an item using a tag or id
(if by tag, it selects the first item in the display list with
the given tag).
Instead of selecting the topmost closest item, this form will
select the topmost closest item that is below <em>start</em> in
the display list; if no such item exists, then the selection
behaves as if the <em>start</em> argument had not been specified.</p>
</dd>
</li>
<dt><strong><a name="item_enclosed_x1_y1_x2_y2"><strong>enclosed</strong> <em>x1</em> <em>y1</em> <em>x2</em> <em>y2</em></a></strong>
<dd>
<p>Selects all the items completely enclosed within the rectangular
region given by <em>x1</em>, <em>y1</em>, <em>x2</em>, and <em>y2</em>.
<em>X1</em> must be no greater then <em>x2</em> and <em>y1</em> must be
no greater than <em>y2</em>.</p>
</dd>
</li>
<dt><strong><a name="item_overlapping_x1_y1_x2_y2"><strong>overlapping</strong> <em>x1</em> <em>y1</em> <em>x2</em> <em>y2</em></a></strong>
<dd>
<p>Selects all the items that overlap or are enclosed within the
rectangular region given by <em>x1</em>, <em>y1</em>, <em>x2</em>,
and <em>y2</em>.
<em>X1</em> must be no greater then <em>x2</em> and <em>y1</em> must be
no greater than <em>y2</em>.</p>
</dd>
</li>
<dt><strong><a name="item_withtag_tagorid"><strong>withtag </strong><em>tagOrId</em></a></strong>
<dd>
<p>Selects all the items given by <em>tagOrId</em>.</p>
</dd>
</li>
</dl>
<dt><strong><a name="item_bbox"><em>$canvas</em>-><strong>bbox</strong>(<em>tagOrId, </em>?<em>tagOrId, tagOrId, ...</em>?)</a></strong>
<dd>
<p>Returns a list with four elements giving an approximate bounding box
for all the items named by the <em>tagOrId</em> arguments.
The list has the form ``<em>x1 y1 x2 y2</em>'' such that the drawn
areas of all the named elements are within the region bounded by
<em>x1</em> on the left, <em>x2</em> on the right, <em>y1</em> on the top,
and <em>y2</em> on the bottom.
The return value may overestimate the actual bounding box by
a few pixels.
If no items match any of the <em>tagOrId</em> arguments or if the
matching items have empty bounding boxes (i.e. they have nothing
to display)
then an empty string is returned.</p>
</dd>
</li>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?