A PRIMER FOR PROGRAMMING PAD++ IN TCL/TK

Transformations

Pad++ maintains a distinction between the surface and the view. All graphical items sit at a distinct location on the surface with a given size. The view shows any given location on the surface at any magnification.

Initially the view onto the Pad++ surface looks at the origin (0, 0) with a magnification of 1.0. The view is always represented by a list of 3 numbers representing the (x, y) position and magnification, respectively. The view is specified by the point currently at the center of the window. It is possible to adjust the view onto the surface by using the moveto widget command. The getview command returns the current view.

Individual items may be moved or scaled, relative to the surface, using the widget commands slide and scale, respectively. Currently, rotation is not supported for either individual items, or the view.

Every item on the Pad++ surface has an anchor and an anchor point associated with it that controls the item's position and size. The anchor and the position of the anchor point can be accessed directly with the -anchor, and -place itemconfigure options. The -place consists of a list of three values where the first two values specify the position of the anchor point of the item, and the third value specifies its size. For example, an image with a -place of "25 30 2" and an -anchor of "center" will appear centered at the point (25, 30) with a magnification of 2. Changing its anchor to "w" will make the west side of the image appear at the point (25, 30).

Some items (such as text and images) get created with a -place of (0, 0, 1). Items with coordinates, however, (lines, rectangles, polygons, splines, and portals) are special in that these items get created with a -place that is determined by the coordinates. So, creating a rectangle from (0, 0) to (50, 50) with a center anchor gets a -place of "25 25 1".

Let's look at how the various transformations work. We'll start by creating two squares.

.pad create rectangle 0 0 100 100 -tags "rect1" -fill black
.pad create rectangle 0 0 100 100 -tags "rect2" -fill white

Notice that only the white rectangle is visible because both rectangles are drawn at the same place, and the one drawn last appears on top. We now slide the black rectangle to the left and shrink the white one.

.pad slide rect1 -100 0
.pad scale rect2 .5


These commands operate by modifying the item's configuration. We can see this by using the itemconfigure command to look at them.


.pad itemconfigure rect1 -place        => "-50 50 1"
.pad itemconfigure rect2 -place        => "50 50 .5"

If we zoom in a bit with the moveto command, both items will appear larger. This, however, is not the same as magnifying each item with the scale command. Changing the view affects the way all items are rendered (except sticky items, see below). Transforming items changes just the way those items are rendered.

.pad moveto 0 0 2


Note that the item configurations do not change when the view is changed:

.pad itemconfigure rect1 -place            => "-50 50 1"
.pad itemconfigure rect2 -place            => "50 50 .5"


We can retrieve the current view with the getview command:

.pad getview        => "0 0 2"

Pad++ Programmer's Guide - 10 JUN 1996

Generated with Harlequin WebMaker

Web Accessibility