Back to index

LispMe graphics system

There's no special screen or window where graphic is output, it is just drawn onto the screen, where it remains until LispMe's UI is redrawn by a text output operation like write or the REP loop. To avoid this, call (own-gui #t), which disables most LispMe controls.

The graphic routines use screen coordinates in the range (0,0) to (160,160). (0,0) corresponds to the upper left corner of the screen.

Starting with version 3.5, many new graphic functions and color support was introduced in to PalmOS, which was enough reason to clean up LispMe's graphic functions, too.

The earlier global variables *font*, *pat* and *point are gone. They are replaced by the single global variable *gstate* containing the entire graphics state as a list. However, this shouldn't affect your old programs too much when you used the access functions defined in the memo ; Graphic utilities as recommended.

*gstate* format

*gstate* must be a list of 7 elements:
  1. The current point as a pair of integers both in the range 0 to 160
  2. The current font
  3. The drawing pattern
  4. The drawing mode
  5. The foreground color index (0-255)
  6. The background color index (0-255)
  7. The text color index (0-255)
The former restriction that a graphics state variable cannot be assigned has been omitted, you can set! *gstate* now as you like. You can save the current *gstate* in a variable, assign a new one locally, modify it and later restore the original one without restrictions.

Pen position

This is a pair whose car contains the current x coordinate and whose cdr contains the current y coordinate of the graphics cursor. These coordinates define the starting point of draw, rect, and text. draw and rect both update the pen position to the end point.

Fonts

Available fonts are
ValueFont name
0Standard font
1Bold font
2Large font
3Symbol font
4Symbol11 font
5Symbol7 font
6LED font (calculator font)
7Large Bold font (OS 3.0 or later only)
Any other value will effect in using font 0. Note that fonts 3-6 define only a few characters in unusual positions. You should use a tool like AsciiChart to see characters and their codes on your Pilot.

Color selection

The color selection has no effect with ROM versions prior to 3.5. LispMe simply uses the drawing pattern as always.

PalmOS 3.5 supports color depths upto 8 bits, resulting in 256 colors, which are indexes into a color palette containing RGB triples. All drawing functions use this color indexin the range 0-255, not the actual RGB value. The graphics state *gstate* contains separate entries for foreground, background and text color numbers.

text uses the text and the background color to render, all other drawing functions use foreground and background colors.

To determine the best-matching palette color from given RGB values, you should use the rgb->index function instead of hard-coding color indexes. The new color model works with 2- and 4-bit grayscale modes (and even black/white), too, see here for an example.

McColors is a nice little tool to show all available colors.

Drawing patterns

Drawing patterns (the former *pat* variable) were an unfortunate mixture of pattern and drawing modes in earlier LispMe versions. Now these are more clearly separated, but for backward compatibility still all values are supported.

ValueEffect prior to OS3.5Effect OS3.5 and later
#tdraw black on whiteUse foreground and background colors normally and pay attention to the drawing mode
#fdraw white on blackAlways use drawing mode dm-paint and swap foreground and background colors.
#ndraw inverted (XOR mode)Use foreground and background colors normally but always use drawing mode dm-invert .
a string of exactly 8 bytes specifying a 8×8 fill pattern draw black where pattern bits are set, white where notUse foreground and background colors normally and pay attention to the drawing mode. Where pattern bits are set, the foreground color is used, otherwise the background color is used.

You should only use pattern #t or string patterns with OS3.5 and specify the right drawing mode. Support for #f and #n in 3.5 is only for backwards compatibility.

Drawing modes

The drawing modes have no effect with ROM versions prior to 3.5. LispMe simply uses the drawing pattern as always.

ValueSymbol in the 3.5 SDKLispMe symbolDescription (from 3.5 SDK)
0winPaintdm-paintDestination replaced with source pixels (copy mode)
1winErasedm-eraseDestination cleared where source pixels are off (AND mode)
2winMaskdm-maskDestination cleared where source pixels are on (AND NOT mode)
3winInvertdm-invertDestination inverted where source pixels are on (XOR mode)
4winOverlaydm-overlayDestination set only where source pixels are on (OR mode)
5winPaintInversedm-paint-inverseDestination replaced with inverted source (copy NOT mode)
6winSwapdm-swapDestination foreground and background colors are swapped, leaving any other colors unchanged (color invert operation)

The following screenshots (source code) show the effects of draw modes 0-6 from left to right, please note that the dm-swap with a custom pattern crashes the Palm, so the right-most rectangle is drawn using a solid pattern.
Pre OS 3.5 Black/white 4 grays 16 grays 256 colors
Pre OS 3.5 Black/white 4 grays 16 grays 256 colors

The pattern in modes 2 and 5 looks strange, can this be a bug in ROM 3.5?

Associated language elements

*gstate* bitmap draw index->rgb move
rect rgb->index set-palette text