Previous: , Up: X Graphics   [Contents][Index]

17.9.3 Custom Operations on X Graphics Devices

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

(graphics-operation device 'set-foreground-color "blue")
operation on x-graphics-device: set-background-color color-name
operation on x-graphics-device: set-foreground-color color-name
operation on x-graphics-device: set-border-color color-name
operation on x-graphics-device: set-mouse-color color-name

These operations change the colors associated with a window. Color-name must be a string, which is the X server’s name for the desired color. set-border-color and set-mouse-color immediately change the border and mouse-cursor colors. 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. Color names include both mnemonic names, like "red", and intensity names specified in the "#rrggbb" notation.

operation on x-graphics-device: draw-arc x y radius-x radius-y angle-start angle-sweep fill?

Operation draw-arc draws or fills an arc. An arc is a segment of a circle, which may have been stretched along the x- or y- axis to form an ellipse.

The parameters x, y, radius-x and radius-y describe the circle and angle-start and angle-sweep choose which part of the circle is drawn. The arc is drawn on the graphics device with the center of the circle at the virtual coordinates given by x and y. radius-x and radius-y determine the size of the circle in virtual coordinate units.

The parameter angle-start determines where the arc starts. It is measured in degrees in an anti-clockwise direction, starting at 3 o’clock. angle-sweep determines how much of the circle is drawn. It too is measured anti-clockwise in degrees. A negative value means the measurement is in a clockwise direction.

Note that the angles are determined on a unit circle before it is stretched into an ellipse, so the actual angles that you will see on the computer screen depends on all of: radius-x and radius-y, the window size, and the virtual coordinates.

If fill? is #f then just the segment of the circle is drawn, otherwise the arc is filled in a pie-slice fashion.

This draws a quarter circle pie slice, standing on its point, with point at virtual coordinates (3,5):

(graphics-operation g 'draw-arc 3 5 .5 .5 45 90 #t)
operation on x-graphics-device: draw-circle x y radius
operation on x-graphics-device: fill-circle x y radius

These operations draw a circle (outline) or a filled circle (solid) at on the graphics device at the virtual coordinates given by x and y. These operations could be implemented trivially interms of the draw-arc operation.

operation on x-graphics-device: set-border-width width
operation on x-graphics-device: set-internal-border-width width

These operations change the external and internal border widths of a window. Width must be an exact non-negative integer, specified in pixels. The change takes place immediately. Note that changing the internal border width can cause displayed graphics to be garbled; we recommend calling graphics-clear on the window’s device after doing so.

operation on x-graphics-device: set-font font-name

Changes the font used when drawing text in a window. Font-name must be a string that is a font name known to the X server. This operation does not affect text drawn prior to its invocation.

operation on x-graphics-device: set-mouse-shape shape-number

Changes the shape of the mouse cursor. Shape-number is an exact non-negative integer that is used as an index into the mouse-shape font; when multiplied by 2 this number corresponds to an index in the file

operation on x-graphics-device: map-window
operation on x-graphics-device: withdraw-window

These operations control the mapping of windows. They correspond directly to Xlib’s XMapWindow and XWithdrawWindow.

operation on x-graphics-device: resize-window width height

Changes the size of a window. Width and height must be exact non-negative integers. The operation corresponds directly to Xlib’s XResizeWindow.

This operation resets the virtual coordinate system and the clip rectangle.

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

Changes the position of a window on the display. X and y must be exact integers. The operation corresponds directly to Xlib’s XMoveWindow. Note that the coordinates x and y do not take the external border into account, and therefore will not position the window as you might like. The only reliable way to position a window is to ask a window manager to do it for you.

operation on x-graphics-device: get-default resource property

This operation corresponds directly to Xlib’s XGetDefault. Resource and property must be strings. The operation returns the character string corresponding to the association of resource and property; if no such association exists, #f is returned.

operation on x-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.

operation on x-graphics-device: font-structure font-name

Returns a Scheme equivalent of the X font structure for the font named font-name. If the string font-name does not name a font known to the X server, or names a 16-bit font, #f is returned.

procedure: x-font-structure/name font-structure
procedure: x-font-structure/direction font-structure
procedure: x-font-structure/all-chars-exist font-structure
procedure: x-font-structure/default-char font-structure
procedure: x-font-structure/min-bounds font-structure
procedure: x-font-structure/max-bounds font-structure
procedure: x-font-structure/start-index font-structure
procedure: x-font-structure/character-bounds font-structure
procedure: x-font-structure/max-ascent font-structure
procedure: x-font-structure/max-descent font-structure

These procedures extract the components of the font description structure returned by the X graphics operation font-structure. A more complete description of these components appears in documentation of the XLoadQueryFont Xlib call. start-index is the index of the first character available in the font. The min-bounds and max-bounds components are structures of type x-character-bounds, and the character-bounds component is a vector of the same type.

procedure: x-character-bounds/lbearing character-bounds
procedure: x-character-bounds/rbearing character-bounds
procedure: x-character-bounds/width character-bounds
procedure: x-character-bounds/ascent character-bounds
procedure: x-character-bounds/descent character-bounds

These procedures extract components of objects of type x-character-bounds. A more complete description of them appears in documentation of the
XLoadQueryFont Xlib call.

Previous: , Up: X Graphics   [Contents][Index]