Previous: Win32 Graphics Type, Up: Win32 Graphics


17.10.2 Custom Operations for Win32 Graphics

Custom operations are invoked using the procedure graphics-operation. For example,

     (graphics-operation device 'set-foreground-color "blue")
— operation on win32-graphics-device: set-background-color color-name
— operation on win32-graphics-device: set-foreground-color color-name

These operations change the colors associated with a window. Color-name must be of one of the valid color specification forms listed below. set-background-color and set-foreground-color change the colors to be used when drawing, but have no effect on anything drawn prior to their invocation. Because changing the background color affects the entire window, we recommend calling graphics-clear on the window's device afterwards.

The foreground color affects the drawing of text, points, lines, ellipses and filled polygons.

Colors are specified in one of three ways:

An integer
This is the Win32 internal RGB value.
By name
A limited number of names are understood by the system. Names are strings, e.g. "red", "blue", "black". More names can be registered with the define-color operation.
RGB (Red-Green-Blue) triples
A triple is either a vector or list of three integers in the range 0–255 inclusive which specify the intensity of the red, green and blue components of the color. Thus #(0 0 0) is black, (0 0 128) is dark blue and #(255 255 255) is white.

If the color is not available in the graphics device then the nearest available color is used instead.

— operation on win32-graphics-device: define-color name spec

Define the string name to be the color specified by spec. Spec may be any acceptable color specification. Note that the color names defined this way are available to any Win32 graphics device, and the names do not have to be defined for each device.

Color names defined by this interface may also be used when setting the colors of the Scheme console window, or the colors of Edwin editor windows.

— operation on win32-graphics-device: find-color name

Looks up a color previously defined by define-color. This returns the color in its most efficient form for operations set-foreground-color or set-background-color.

— operation on win32-graphics-device: draw-ellipse left top right bottom

Draw an ellipse. Left, top, right and bottom indicate the coordinates of the bounding rectangle of the ellipse. Circles are merely ellipses with equal width and height. Note that the bounding rectangle has horizontal and vertical sides. Ellipses with rotated axes cannot be drawn. The rectangle applies to the center of the line used to draw the ellipse; if the line width has been set to greater than 1 then the ellipse will spill outside the bounding rectange by half of the line width.

— operation on win32-graphics-device: fill-polygon points

Draws a filled polygon using the current foreground color. Points is a vector of real numbers. The numbers are in the order x1 y1 x2 y2 ... xn yn. For example,

          (graphics-operation device 'fill-polygon #(0 0 0 1 1 0))
     

draws a solid triangular region between the points (0, 0), (0, 1) and (1, 0).

— operation on win32-graphics-device: load-bitmap pathname

The graphics device contents and size are initialized from the windows bitmap file specified by pathname. If no file type is supplied then a ".BMP" extension is added. If a clip rectangle is in effect when this procedure is called, it is necessary to redefine the clip rectangle afterwards.

— operation on win32-graphics-device: save-bitmap pathname

The graphics device contents are saved as a bitmap to the file specified by pathname. If no file type is supplied then a ".BMP" extension is added. The saved bitmap may be incorporated into documents or printed.

— operation on win32-graphics-device: move-window x y

The graphics device window is moved to the screen position specified by x and y.

— operation on win32-graphics-device: resize-window width height

The graphics device window is resized to the specified width and height in device coordinates (pixels). If a clip rectangle is in effect when this procedure is called, it is necessary to redefine the clip rectangle afterwards.

— operation on win32-graphics-device: set-line-width width

This operation sets the line width for future drawing of lines, points and ellipses. It does not affect existing lines and has no effect on filled polygons. The line width is specified in device units. The default and initial value of this parameter is 1 pixel.

— operation on win32-graphics-device: set-window-name name

This sets the window title to the string name. The window is given the name "Scheme Graphics" at creation.

— operation on win32-graphics-device: set-font handle

Sets the font for drawing text. Currently not well supported. If you can get a Win32 font handle it can be used here.

— operation on win32-graphics-device: copy-area source-x-left source-y-top width height destination-x-left destination-y-top

This operation copies the contents of the rectangle specified by source-x-left, source-y-top, width, and height to the rectangle of the same dimensions at destination-x-left and destination-y-top.