The Tk canvas provides a simple but powerful set of structured graphics primitives, and is perhaps the easiest toolkit available for drawing simple 2D graphics. When we started to use the Tk canvas with a view towards implementing various graphical diagram editors, however, we realized that we needed a more powerful layer of abstraction.
To illustrate, figure 1 shows a mock-up visual program of the kind that we were interested in implementing. This is a sample of a language developed in . The rectangle marked ``let'' encloses an expression, and the value of the expression is indicated by the arrow connecting the two triangular ``terminals.'' The let-expression itself is connected to another function box. Items within the let-expression can be moved only within that frame, while moving the whole frame will move everything contained within it. This combination of hierarchy and complex user interaction necessitated a higher-level framework than the raw canvas.
Figure 1: A fragment of a visual program
We decided very early on that our implementation would be only in [incr Tcl], in order to guarantee portability. More recently, we used the namespace facility of Tcl 8.0 to port the code to Tcl 8.0, and it now runs in either Tcl and [incr Tcl]. Although the Tcl-only decision presented its own set of implementation challenges, we were able to achieve acceptable performance and the portability we desired. The Slate should, in fact, work with any canvas extension, since it uses only the standard canvas interface provided by Tcl/Tk.
After some experimentation, we ended up with a package that implements the following:
The key feature that makes the Slate useful is the ability to define new item types in Tcl. Items can be composed recursively, producing a straight-forward visual hierarchy, as is common in many graphics packages (see, for example, ). All of the canvas methods are rewritten to handle hierarchical items.
Every item has a shape, such as point, rectangle, polygon, or a custom-designed shape. Items can be queried for the coordinates of a feature, such as the north-east corner or the second vertex. Items can be requested to move one or more features, reshaping the item.
Event-handlers can be bound to any level of the visual hierarchy. In addition, we implemented a more abstract and more powerful user interaction framework, in which particular sequences of user interaction events are abstracted into objects called interactors.
We also added other useful methods, such as highlighting and selection. Unlike many research toolkits, we did not implement a constraint system, for reasons detailed in a later section.