chickadee » ezxdisp

ezxdisp

Description

A simple graphics library for X11.

Author

n-sibata and Morihiko Tamai, packaged for CHICKEN by felix winkelmann.

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/ezxdisp

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

Documentation

ezxdisp is a simple graphics library for 2D/3D graphical applications. (The official distribution can be found here).

Initialize/Finalize a window

ezx-init SIZE_X SIZE_Y WINDOW_NAMEprocedure

This procedure returns a EZX object all other procedures accept.

ezx-quit EZXprocedure

Update the graphics in the window

ezx-redraw EZXprocedure

Erase the graphics in the window/layer

ezx-wipe EZXprocedure
ezx-wipe-layer EZX LAYERprocedure

LAYER should be an exact integer between 0 and 8.

Get the pointer coordinates

ezx-sensebutton EZXprocedure

Returns the current pointer coordinates as three values: BUTTON, X and Y

ezx-pushbutton EZXprocedure

Block until an event is received. Returns three values: BUTTON, X and Y

The BUTTON result is 1, 2 or 3 for the first, second and third mouse button, respectively. The button number is additionally bitwise OR'd with 8 if the shift key is pressed and with 16 if the control key is pressed.

Draw 2D graphics

ezx-point-2d EZX X Y COLORprocedure
ezx-line-2d EZX X0 Y0 X1 Y1 COLOR WIDTHprocedure
ezx-lines-2d EZX POINTS COLOR WIDTHprocedure
ezx-poly-2d EZX POINTS COLORprocedure

The POINTS argument should be an SRFI-4 s32vector of the form [X1 Y1 ... Xn Yn] where X and Y are the coordinates of each point.

ezx-rect-2d EZX X0 Y0 X1 Y1 COLOR WIDTHprocedure
ezx-fillrect-2d EZX X0 Y0 X1 Y1 COLORprocedure
ezx-circle-2d EZX X0 Y0 R COLOR WIDTHprocedure
ezx-fillcircle-2d EZX X0 Y0 R COLORprocedure
ezx-str-2d EZX X0 Y0 STRING COLORprocedure

Draw 3D graphics

ezx-set-light-3d EZX EX EY EZprocedure
ezx-set-view-3d EZX EX EY EZ VX VY VZ Mprocedure
ezx-c3d-to-2d EZX SX SY SZprocedure

Returns two values, DX and DY.

ezx-line-3d EZX X0 Y0 Z0 X1 Y1 Z1 COLOR WIDTHprocedure
ezx-str-3d EZX X0 Y0 Z0 STRING COLORprocedure
ezx-poly-3d EZX POINTS HX HY HZ COLORprocedure
ezx-circle-3d EZX X0 Y0 Z0 R COLORprocedure

The POINTS argument should be a SRFI-4 f64vector containing the X, Y and Z coordinates of each point.

Event handling

ezx-next-event EZXprocedure

Removes the next event from the event queue and returns the event-specific information. If there is no event data in the event queue, this function blocks until the next event occurs. The procedure returns 5 values: the type of the event, the X- and Y-coordinates of the mouse pointer at the time of the event, the button- or keyboard-state mask and the button- or key-code of the event.

The following variables contain the event-types that may occur:

  • ezx:BUTTON-PRESS or ezx:BUTTON-RELEASE
  • ezx:KEY-PRESS or ezx:KEY-RELEASE
  • ezx:MOTION-NOTIFY
  • ezx:CLOSE

These button-codes are defined:

CodeButton
1left
2middle
3right
4wheel up
5wheel down

State mask values that may be returned:

MaskState
1shift key
2control key
4left button
8middle button
16right button

For keyboard events, some special keys will return a platform independent keycode:

Home#xff50
Left#xff51
Up#xff52
Right#xff53
Down#xff54

The result values will be undefined for events for which they are not used. This table summarizes what results are valid:

EventResults
ezx:CLOSE
ezx:BUTTON-PRESS ezx:BUTTON-RELEASEx, y, state, k/b
ezx:KEY-PRESS ezx:KEY-RELEASEx, y, state, k/b
ezx:MOTION-NOTIFYx, y, state

Miscellaneous functions

ezx-select-layer EZX LAYERprocedure

Focuses on the layer.

ezx-raise-window EZXprocedure

Raises the window.

ezx-window-name EZX STRINGprocedure

Sets a name of the window.

ezx-set-background EZX COLORprocedure

Sets the background color of the window.

Colors

make-ezx-color R G Bprocedure

This procedure returns a "color object", which is internally encoded as a f64vector. The red, green and blue components should be between 0 and 1.

Examples

(import ezxdisp)

(define ezx (ezx-init 100 100 "Hello, ezxdisp"))
(ezx-set-background ezx (make-ezx-color 1 1 1))
(ezx-fillcircle-2d ezx 50 50 25 (make-ezx-color 1 0 0))
(ezx-redraw ezx)

(let loop ()
  (let-values (((b _ _) (ezx-pushbutton ezx)))
    (loop)))

(ezx-quit ezx)

A more elaborate example is in the egg distribution in a file named 3d_clock.scm, which displays an animated 3D-clock.

Changelog

License

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2 of the
 License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Contents »