Next: Constructing hierarchy Up: The core graphics framework Previous: The core graphics framework

## Complex item classes

To add a new item type to the slate, the programmer subclasses the ComplexItem class. Once defined, items of the new type can be created and manipulated just like regular Tk canvas items. For example, one of the item types that we supply with the Slate is called Frame, because it mimics the appearance of the Tk frame widget. To create a new frame on a slate, we can execute code such as this:

      set frame [$slate create Frame 50 50 100 100 -color green -relief ridge]

which produces the item shown at the top left of figure 3. This item behaves like any other Tk canvas item - for example, we can change its coordinates:

      $slate coords $frame 70 70 140 120

We can move it:

      $slate move $frame 40 20

We can get a list of items overlapping a given region of the canvas, which will (in this case) include this item:

      set found [$slate find overlapping 100 100 200 200]

Figure 3 shows several other complex item types. At the top right is a Solid, which is a polygon with a pseudo-3D border like Frame; at the bottom left is a LabeledRectangle, which is a rectangle with a label and arbitrary graphics nested within it (in this case, two lines); at the bottom right is a SmartLine, which is a line that, given two end-points and the directions at those ends (n, s, e, or w), draws itself as one or more orthogonal segments. We emphasize that these items are a sample of those that we found useful for building graphical editors, and that it is quite simple to create new item types or to extend existing types by subclassing.

Figure 3: Some pre-defined complex items

Next: Constructing hierarchy Up: The core graphics framework Previous: The core graphics framework