Inherits:
::tycho::Uninstantiable
-
Source File -
Contents:
public procs
- public commons
An "empty" item to which items can be added to create a complex item.
Clients can create a complex item directly (by calling the slate's
create
method) and add items into it by manipulating hierarchy tags.
often, however, the behavior of a complex item will need to be tailored,
and this is done by subclassing Picture (or one of its subclasses)
and adding procedures to override the default implementations
in this class.
Picture and its subclasses are not classes in the usual sense:
instead of instantiating these classes, the Slate creates a new item
ID that uniquely identifies it; instead of calling methods on an
object, the slate calls procedures in
those classes with the ID of the item as the first argument;
instead of instance variables, these classes manipulate common arrays
indexed by item ID. The Picture class and its subclasses have
mechanism to simulate inheritance and to give complex items options
just like regular Tk canvas items. This evilness is needed to avoid
creating large numbers of objects, which is just too inefficient
in Itcl. (I know this because I did it first...)
Because every "method" is just a procedure, each takes as its first
three arguments the item ID, the canvas on which the item is being
drawn, and the slate on which the item is being drawn. Arguments
following those three are arguments that would be passed to
methods if these classes implemented objects in the normal way.
Reading Picture documentation.
Public constructs
-
construct
id canvas slate tags x0 y0 x1 y1 args
- Create a new complex item. This procedure is used in place of
an object constructor. The default implementation just creates
the primary component (which must be present in all complex items)
as a rectangle at the given coordinates. From now on, this item
will be used to get and set the coordinates of the new item.
Components items can then be added to the new complex item with
the Slate's
create
method.
The arguments to every construct
procedure are the item ID,
the canvas, the slate, the tags to be given to each item added to the
complex item, two or more coordinate values, and
zero or more option-value pairs.
-
destruct
id canvas slate
- Delete a complex item. This procedure is used in place of
an object destructor. The default implementation does nothing.
This procedure does not need to delete component items, as
that is done automatically by the Slate.
-
coords
id canvas slate args
- Set or read a complex item's coordinates. With no arguments, return the
coordinates of the item as given by the primary component. With
arguments, set the coordinates of the item to those coordinates.
In the default implementation, the coordinates of the primary
components are set to the given coordinates and all other components
are scaled accordingly. If the coordinates are a rectangular region
(such as for items with a rectangle or oval as the primary component)
then the components are moved and scaled according to the size of the
original and new regions in the horizontal and vertical directions.
if the coordinates are not rectangular, then the bounding box of the
primary component is used to determine the moving and scale
figures.
Note that the scaling of all components is uniform -- subclasses will
want to override this behavior if non-uniform scaling is required.
(For example, the Frame class scales so that its border's remain
the same width.).
-
ghost
id canvas slate
- Create and return a "ghost" of the item. This is used when moving
and deforming the item. The default implementation creates a
grey item with the coordinates of the primary component.
-
primary
- The "primary" component that defines the item's coordinates.
Every Picture class must create exactly one primitive canvas item
and place its ID into this array indexed by the complex item ID.
The Slate uses this component to manipulate the coordinates of
complex items. Note: subclasses are not to create their own
copy of this variable.
-
methodtable
- The virtual "method" table. This is a common array indexed by
method name, with contents being the actual procedure to call
to implement the method. Every subclass of Picture must create
its own copy of this array, and fill it with methods names and
procedures. For example, the Picture class has an
entry named "coords" which contains "::tycho::Picture::coords".
This array implements "inheritance": if a method is not implements
in a given class, then the array contains the name of a procedure
in one of its superclasses. For example, the Frame class has an
entry called "ghost" with the value "::tycho::Picture::ghost": if
the Slate calls "ghost" in a Frame item, it will execute the
procedure defined in the Picture class.
-
optiondefault
- Default values of this item's options. Every class must create
its own copy of this array and initialize it with the default
values of the item's options.
-
shape
rectangle
- The "shape" of items of this type. Every Picture class must create
its own copy of this array and set it to a type that indicates
what shape the complex item is: point, line, polygon, rectangle,
or oval.
Index of classes
Author: H. John Reekie
Version: @(#)Picture.itcl 1.21 12/16/96
Copyright: (c) 1996 The Regents of the University of California.