[Top] [Prev] [Next]

Limbo Draw Module

Draw Module
context - graphics environment

display - connection to draw device

font - character images for Unicode text

Image - pictures and drawing

point - coordinate position

pointer - state of a pointer device such as a mouse

rectangle - rectangular portion of the plane

screen - type to define the abstract data structures for the windows on a display


include "draw.m";
draw:=  load Draw Draw->PATH;


Inferno's Draw module provides basic graphics facilities, defining drawing contexts, images, character fonts, and rectangular geometric operations. See Limbo Prefab Module in Chapter 12 and Tk -graphics toolkit in Chapter 13 for higher level operations, such as windows and menu handling.


Images are defined on a rectangular region of an integer plane with a picture element, or pixel, at each grid point. Pixel values are integers with 1, 2, 4, or 8 bits per pixel, and all pixels in a given image have the same size, or depth. Some operations allow images with different depths to be combined, for example to do masking.

When an image is displayed, the value of each pixel determines the color of the display. For color displays, Inferno uses a fixed color map for each display depth (see rgbv - color map in Appendix A), and the application is responsible for mapping its desired colors to the values available. Facilities exist to convert from red, green, blue triplets to pixel values.


The graphics plane is defined on an integer grid, with each (x, y) coordinate identifying the upper left corner of the corresponding pixel. The plane's origin, (0, 0), resides at the upper left corner of the screen; x and y coordinates increase to the right and down. The abstract data type Point defines a coordinate position.


The type Rect defines a rectangular region of the plane. It comprises two Points, min and max, and specifies the region defined by pixels with coordinates greater than or equal to min and strictly less than max, in both x and y. This half-open property allows rectangles that share an edge to have equal coordinates on the edge.


The type Display represents a physical display, corresponding to a single connection to a draw device. Besides the image of the display itself, the Display type also stores references to off-screen images, fonts, and so on. The contents of such images are stored in the display device, not in the client of the display, which affects how they are allocated and used. See Image - pictures and drawing.


The Screen type is used to manage a set of windows on an image, typically but not necessarily that of a display. Screens and hence windows may be built recursively upon windows for subwindowing or even on off-screen images.


The Image type provides basic operations on groups of pixels. Through a few simple operations, especially the draw image combination operator (see Image - pictures and drawing), the Image type provides the building blocks for Display, Screen, and Font.


A Font defines which character image to draw for each character code value. Although all character drawing operations ultimately use the draw primitive on the underlying images, Fonts provide convenient and efficient management of display text. Inferno uses the 16-bit Unicode character encoding, so Fonts are managed hierarchically to control their size and to make common subsets such as ASCII or Greek efficient in practice. (See font - character images for Unicode text, UTF, Unicode, ASCII - character set and format in Appendix A, and font, subfont - external format for character fonts and subfonts in Appendix A)


A Context provides an interface to the system graphics and interactive devices. The system creates this context when it starts an application.


The Pointer type conveys information for pointing devices, such as mice or trackballs.

More about Images

An image occupies a rectangle, Image.r, of the graphics plane. A second rectangle, Image.clipr, defines a clipping region for the image. Typically, the clipping rectangle is the same as the basic image, but they may differ. For example, the clipping region may be made smaller and centered on the basic image to define a protected border.

The pixel depth of an Image is stored as a logarithm called Image.ldepth; pixels with 1, 2, 4, and 8 bits correspond to ldepth values 0, 1, 2, and 3.

An image may be marked for replication. When set, the boolean Image.repl causes the image to behave as if replicated across the entire integer plane, thus tiling the destination graphics area with copies of the source image. When replication is turned on, the clipping rectangle limits the extent of the replication and may even usefully be disjoint from Image.r. See Image - pictures and drawing for examples.

The Image member functions provide facilities for drawing text and geometric objects, manipulating windows, and so on.

Objects of type Display, Font, Screen, and Image must be allocated by the member functions. If such objects are created with a regular Limbo definition, they will not behave properly and may generate run-time errors.

There are no routines to free for graphics objects. Instead Limbo's garbage collection frees them automatically. In Limbo, references can be eliminated by assigning nil to reference variables, returning from functions whose local variables hold references, and so on.

Return Values

Most drawing operations operate asynchronously, so they have no error return. Functions that allocate objects return nil for failure. In such cases the system error string may be interrogated (such as by the %r print format) for more information.

See Also
ir - infrared remote control in Chapter 15

Limbo Prefab Module in Chapter 12

Tk -graphics toolkit in Chapter 13

font, subfont - external format for character fonts and subfonts in Appendix A

image - external format for images in Appendix A

[Top] [Prev] [Next]

Copyright © 1996,Lucent Technologies, Inc. All rights reserved.