Whole document tree
    

Whole document tree

Coordinates

8.3. Coordinates

The canvas uses a world coordinate system with coordinates specified as floating point numbers. World coordinates mean that units can represent whatever is most convenient to you: meters, pixels, parsecs, etc.

Coordinates are calculated from the origin of the canvas, which has coordinates (0.0, 0.0). Positive X coordinates go to the right of the origin, and positive Y coordinates go down, like in the rest of the X Window System.

Coordinates of items are calculated with respect to their parent group. When a group is moved, its children's logical coordinates do not change, although their physical position does. A group stores a single pair of coordinates which define its origin relative to its parent group. The canvas' root group starts with its origin in world position (0.0, 0.0).

For example, let us say you have a toplevel group at (5.0, 3.0). If you insert an item in it with coordinates (2.0, 1.0), the item will appear to be at coordinates (7.0, 4.0). Coordinates of items are always relative to their parent group.

You will normally only need use this floating point, world coordinate system. The canvas also has a different coordinate system which works in terms of pixel offsets. This coordinate system is used internally to control scrolling of the canvas. You won't need to know about it unless you want to do scrolling by hand (as opposed to letting scrollbars handle this for you), or when you create your own canvas item types. We will discuss this pixel coordinate system later.