1351 lines
19 KiB
HTML
1351 lines
19 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Graphics</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Graphics</H1>
|
|
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Graphics - Machine-independent graphics primitives.
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Graphics
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Graphics</B>
|
|
|
|
<BR> :
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
Machine-independent graphics primitives.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>exception Graphic_failure </I>
|
|
|
|
<B>of </B>
|
|
|
|
<B>string</B>
|
|
|
|
<P>
|
|
<P>
|
|
Raised by the functions below when they encounter an error.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Initializations</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val open_graph </I>
|
|
|
|
:
|
|
<B>string -> unit</B>
|
|
|
|
<P>
|
|
Show the graphics window or switch the screen to graphic mode.
|
|
The graphics window is cleared and the current point is set
|
|
to (0, 0). The string argument is used to pass optional
|
|
information on the desired graphics mode, the graphics window
|
|
size, and so on. Its interpretation is implementation-dependent.
|
|
If the empty string is given, a sensible default is selected.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val close_graph </I>
|
|
|
|
:
|
|
<B>unit -> unit</B>
|
|
|
|
<P>
|
|
Delete the graphics window or switch the screen back to text mode.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_window_title </I>
|
|
|
|
:
|
|
<B>string -> unit</B>
|
|
|
|
<P>
|
|
Set the title of the graphics window.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val resize_window </I>
|
|
|
|
:
|
|
<B>int -> int -> unit</B>
|
|
|
|
<P>
|
|
Resize and erase the graphics window.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val clear_graph </I>
|
|
|
|
:
|
|
<B>unit -> unit</B>
|
|
|
|
<P>
|
|
Erase the graphics window.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val size_x </I>
|
|
|
|
:
|
|
<B>unit -> int</B>
|
|
|
|
<P>
|
|
See
|
|
<B>Graphics.size_y</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val size_y </I>
|
|
|
|
:
|
|
<B>unit -> int</B>
|
|
|
|
<P>
|
|
Return the size of the graphics window. Coordinates of the screen
|
|
pixels range over
|
|
<B>0 .. size_x()-1</B>
|
|
|
|
and
|
|
<B>0 .. size_y()-1</B>
|
|
|
|
.
|
|
Drawings outside of this rectangle are clipped, without causing
|
|
an error. The origin (0,0) is at the lower left corner.
|
|
Some implementation (e.g. X Windows) represent coordinates by
|
|
16-bit integers, hence wrong clipping may occur with coordinates
|
|
below
|
|
<B>-32768</B>
|
|
|
|
or above
|
|
<B>32676</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Colors</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>type color </I>
|
|
|
|
=
|
|
<B>int</B>
|
|
|
|
<P>
|
|
<P>
|
|
A color is specified by its R, G, B components. Each component
|
|
is in the range
|
|
<B>0..255</B>
|
|
|
|
. The three components are packed in
|
|
an
|
|
<B>int</B>
|
|
|
|
:
|
|
<B>0xRRGGBB</B>
|
|
|
|
, where
|
|
<B>RR</B>
|
|
|
|
are the two hexadecimal digits for
|
|
the red component,
|
|
<B>GG</B>
|
|
|
|
for the green component,
|
|
<B>BB</B>
|
|
|
|
for the
|
|
blue component.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val rgb </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> color</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>rgb r g b</B>
|
|
|
|
returns the integer encoding the color with red
|
|
component
|
|
<B>r</B>
|
|
|
|
, green component
|
|
<B>g</B>
|
|
|
|
, and blue component
|
|
<B>b</B>
|
|
|
|
.
|
|
<B>r</B>
|
|
|
|
,
|
|
<B>g</B>
|
|
|
|
and
|
|
<B>b</B>
|
|
|
|
are in the range
|
|
<B>0..255</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_color </I>
|
|
|
|
:
|
|
<B>color -> unit</B>
|
|
|
|
<P>
|
|
Set the current drawing color.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val background </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
See
|
|
<B>Graphics.foreground</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val foreground </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
Default background and foreground colors (usually, either black
|
|
foreground on a white background or white foreground on a
|
|
black background).
|
|
<B>Graphics.clear_graph</B>
|
|
|
|
fills the screen with the
|
|
<B>background</B>
|
|
|
|
color.
|
|
The initial drawing color is
|
|
<B>foreground</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H3>Some predefined colors</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val black </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val white </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val red </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val green </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val blue </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val yellow </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val cyan </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val magenta </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H3>Point and line drawing</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val plot </I>
|
|
|
|
:
|
|
<B>int -> int -> unit</B>
|
|
|
|
<P>
|
|
Plot the given point with the current drawing color.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val plots </I>
|
|
|
|
:
|
|
<B>(int * int) array -> unit</B>
|
|
|
|
<P>
|
|
Plot the given points with the current drawing color.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val point_color </I>
|
|
|
|
:
|
|
<B>int -> int -> color</B>
|
|
|
|
<P>
|
|
Return the color of the given point in the backing store
|
|
(see "Double buffering" below).
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val moveto </I>
|
|
|
|
:
|
|
<B>int -> int -> unit</B>
|
|
|
|
<P>
|
|
Position the current point.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val rmoveto </I>
|
|
|
|
:
|
|
<B>int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>rmoveto dx dy</B>
|
|
|
|
translates the current point by the given vector.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val current_x </I>
|
|
|
|
:
|
|
<B>unit -> int</B>
|
|
|
|
<P>
|
|
Return the abscissa of the current point.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val current_y </I>
|
|
|
|
:
|
|
<B>unit -> int</B>
|
|
|
|
<P>
|
|
Return the ordinate of the current point.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val current_point </I>
|
|
|
|
:
|
|
<B>unit -> int * int</B>
|
|
|
|
<P>
|
|
Return the position of the current point.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val lineto </I>
|
|
|
|
:
|
|
<B>int -> int -> unit</B>
|
|
|
|
<P>
|
|
Draw a line with endpoints the current point and the given point,
|
|
and move the current point to the given point.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val rlineto </I>
|
|
|
|
:
|
|
<B>int -> int -> unit</B>
|
|
|
|
<P>
|
|
Draw a line with endpoints the current point and the
|
|
current point translated of the given vector,
|
|
and move the current point to this point.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val curveto </I>
|
|
|
|
:
|
|
<B>int * int -> int * int -> int * int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>curveto b c d</B>
|
|
|
|
draws a cubic Bezier curve starting from
|
|
the current point to point
|
|
<B>d</B>
|
|
|
|
, with control points
|
|
<B>b</B>
|
|
|
|
and
|
|
<B>c</B>
|
|
|
|
, and moves the current point to
|
|
<B>d</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val draw_rect </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>draw_rect x y w h</B>
|
|
|
|
draws the rectangle with lower left corner
|
|
at
|
|
<B>x,y</B>
|
|
|
|
, width
|
|
<B>w</B>
|
|
|
|
and height
|
|
<B>h</B>
|
|
|
|
.
|
|
The current point is unchanged.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>w</B>
|
|
|
|
or
|
|
<B>h</B>
|
|
|
|
is negative.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val draw_poly_line </I>
|
|
|
|
:
|
|
<B>(int * int) array -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>draw_poly_line points</B>
|
|
|
|
draws the line that joins the
|
|
points given by the array argument.
|
|
The array contains the coordinates of the vertices of the
|
|
polygonal line, which need not be closed.
|
|
The current point is unchanged.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val draw_poly </I>
|
|
|
|
:
|
|
<B>(int * int) array -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>draw_poly polygon</B>
|
|
|
|
draws the given polygon.
|
|
The array contains the coordinates of the vertices of the
|
|
polygon.
|
|
The current point is unchanged.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val draw_segments </I>
|
|
|
|
:
|
|
<B>(int * int * int * int) array -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>draw_segments segments</B>
|
|
|
|
draws the segments given in the array
|
|
argument. Each segment is specified as a quadruple
|
|
<B>(x0, y0, x1, y1)</B>
|
|
|
|
where
|
|
<B>(x0, y0)</B>
|
|
|
|
and
|
|
<B>(x1, y1)</B>
|
|
|
|
are
|
|
the coordinates of the end points of the segment.
|
|
The current point is unchanged.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val draw_arc </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> int -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>draw_arc x y rx ry a1 a2</B>
|
|
|
|
draws an elliptical arc with center
|
|
<B>x,y</B>
|
|
|
|
, horizontal radius
|
|
<B>rx</B>
|
|
|
|
, vertical radius
|
|
<B>ry</B>
|
|
|
|
, from angle
|
|
<B>a1</B>
|
|
|
|
to angle
|
|
<B>a2</B>
|
|
|
|
(in degrees). The current point is unchanged.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>rx</B>
|
|
|
|
or
|
|
<B>ry</B>
|
|
|
|
is negative.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val draw_ellipse </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>draw_ellipse x y rx ry</B>
|
|
|
|
draws an ellipse with center
|
|
<B>x,y</B>
|
|
|
|
, horizontal radius
|
|
<B>rx</B>
|
|
|
|
and vertical radius
|
|
<B>ry</B>
|
|
|
|
.
|
|
The current point is unchanged.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>rx</B>
|
|
|
|
or
|
|
<B>ry</B>
|
|
|
|
is negative.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val draw_circle </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>draw_circle x y r</B>
|
|
|
|
draws a circle with center
|
|
<B>x,y</B>
|
|
|
|
and
|
|
radius
|
|
<B>r</B>
|
|
|
|
. The current point is unchanged.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>r</B>
|
|
|
|
is negative.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_line_width </I>
|
|
|
|
:
|
|
<B>int -> unit</B>
|
|
|
|
<P>
|
|
Set the width of points and lines drawn with the functions above.
|
|
Under X Windows,
|
|
<B>set_line_width 0</B>
|
|
|
|
selects a width of 1 pixel
|
|
and a faster, but less precise drawing algorithm than the one
|
|
used when
|
|
<B>set_line_width 1</B>
|
|
|
|
is specified.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if the argument is negative.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Text drawing</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val draw_char </I>
|
|
|
|
:
|
|
<B>char -> unit</B>
|
|
|
|
<P>
|
|
See
|
|
<B>Graphics.draw_string</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val draw_string </I>
|
|
|
|
:
|
|
<B>string -> unit</B>
|
|
|
|
<P>
|
|
Draw a character or a character string with lower left corner
|
|
at current position. After drawing, the current position is set
|
|
to the lower right corner of the text drawn.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_font </I>
|
|
|
|
:
|
|
<B>string -> unit</B>
|
|
|
|
<P>
|
|
Set the font used for drawing text.
|
|
The interpretation of the argument to
|
|
<B>set_font</B>
|
|
|
|
is implementation-dependent.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set_text_size </I>
|
|
|
|
:
|
|
<B>int -> unit</B>
|
|
|
|
<P>
|
|
Set the character size used for drawing text.
|
|
The interpretation of the argument to
|
|
<B>set_text_size</B>
|
|
|
|
is implementation-dependent.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val text_size </I>
|
|
|
|
:
|
|
<B>string -> int * int</B>
|
|
|
|
<P>
|
|
Return the dimensions of the given text, if it were drawn with
|
|
the current font and size.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>Filling</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val fill_rect </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>fill_rect x y w h</B>
|
|
|
|
fills the rectangle with lower left corner
|
|
at
|
|
<B>x,y</B>
|
|
|
|
, width
|
|
<B>w</B>
|
|
|
|
and height
|
|
<B>h</B>
|
|
|
|
, with the current color.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>w</B>
|
|
|
|
or
|
|
<B>h</B>
|
|
|
|
is negative.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val fill_poly </I>
|
|
|
|
:
|
|
<B>(int * int) array -> unit</B>
|
|
|
|
<P>
|
|
Fill the given polygon with the current color. The array
|
|
contains the coordinates of the vertices of the polygon.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val fill_arc </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> int -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
Fill an elliptical pie slice with the current color. The
|
|
parameters are the same as for
|
|
<B>Graphics.draw_arc</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val fill_ellipse </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
Fill an ellipse with the current color. The
|
|
parameters are the same as for
|
|
<B>Graphics.draw_ellipse</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val fill_circle </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
Fill a circle with the current color. The
|
|
parameters are the same as for
|
|
<B>Graphics.draw_circle</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Images</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>type image </I>
|
|
|
|
<P>
|
|
<P>
|
|
The abstract type for images, in internal representation.
|
|
Externally, images are represented as matrices of colors.
|
|
Images are bound to the current graphics window and should not be reused
|
|
after closing this graphics window with
|
|
<B>Graphics.close_graph</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val transp </I>
|
|
|
|
:
|
|
<B>color</B>
|
|
|
|
<P>
|
|
In matrices of colors, this color represent a 'transparent'
|
|
point: when drawing the corresponding image, all pixels on the
|
|
screen corresponding to a transparent pixel in the image will
|
|
not be modified, while other points will be set to the color
|
|
of the corresponding point in the image. This allows superimposing
|
|
an image over an existing background.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val make_image </I>
|
|
|
|
:
|
|
<B>color array array -> image</B>
|
|
|
|
<P>
|
|
Convert the given color matrix to an image.
|
|
Each sub-array represents one horizontal line. All sub-arrays
|
|
must have the same length; otherwise, exception
|
|
<B>Graphic_failure</B>
|
|
|
|
is raised.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val dump_image </I>
|
|
|
|
:
|
|
<B>image -> color array array</B>
|
|
|
|
<P>
|
|
Convert an image to a color matrix.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val draw_image </I>
|
|
|
|
:
|
|
<B>image -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
Draw the given image with lower left corner at the given point.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get_image </I>
|
|
|
|
:
|
|
<B>int -> int -> int -> int -> image</B>
|
|
|
|
<P>
|
|
Capture the contents of a rectangle on the screen as an image.
|
|
The parameters are the same as for
|
|
<B>Graphics.fill_rect</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val create_image </I>
|
|
|
|
:
|
|
<B>int -> int -> image</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>create_image w h</B>
|
|
|
|
returns a new image
|
|
<B>w</B>
|
|
|
|
pixels wide and
|
|
<B>h</B>
|
|
|
|
pixels tall, to be used in conjunction with
|
|
<B>blit_image</B>
|
|
|
|
.
|
|
The initial image contents are random, except that no point
|
|
is transparent.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val blit_image </I>
|
|
|
|
:
|
|
<B>image -> int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>blit_image img x y</B>
|
|
|
|
copies screen pixels into the image
|
|
<B>img</B>
|
|
|
|
,
|
|
modifying
|
|
<B>img</B>
|
|
|
|
in-place. The pixels copied are those inside the
|
|
rectangle with lower left corner at
|
|
<B>x,y</B>
|
|
|
|
, and width and height
|
|
equal to those of the image. Pixels that were transparent in
|
|
<B>img</B>
|
|
|
|
are left unchanged.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H3>Mouse and keyboard events</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<I>type status </I>
|
|
|
|
= {
|
|
<BR> mouse_x :
|
|
<B>int</B>
|
|
|
|
; (* X coordinate of the mouse
|
|
<BR> *)
|
|
<BR> mouse_y :
|
|
<B>int</B>
|
|
|
|
; (* Y coordinate of the mouse
|
|
<BR> *)
|
|
<BR> button :
|
|
<B>bool</B>
|
|
|
|
; (* true if a mouse button is pressed
|
|
<BR> *)
|
|
<BR> keypressed :
|
|
<B>bool</B>
|
|
|
|
; (* true if a key has been pressed
|
|
<BR> *)
|
|
<BR> key :
|
|
<B>char</B>
|
|
|
|
; (* the character for the key pressed
|
|
<BR> *)
|
|
<BR> }
|
|
<P>
|
|
<P>
|
|
To report events.
|
|
<P>
|
|
<P>
|
|
<I>type event </I>
|
|
|
|
=
|
|
<BR> | Button_down (* A mouse button is pressed
|
|
<BR> *)
|
|
<BR> | Button_up (* A mouse button is released
|
|
<BR> *)
|
|
<BR> | Key_pressed (* A key is pressed
|
|
<BR> *)
|
|
<BR> | Mouse_motion (* The mouse is moved
|
|
<BR> *)
|
|
<BR> | Poll (* Don't wait; return immediately
|
|
<BR> *)
|
|
<BR>
|
|
<P>
|
|
To specify events to wait for.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val wait_next_event </I>
|
|
|
|
:
|
|
<B>event list -> status</B>
|
|
|
|
<P>
|
|
Wait until one of the events specified in the given event list
|
|
occurs, and return the status of the mouse and keyboard at
|
|
that time. If
|
|
<B>Poll</B>
|
|
|
|
is given in the event list, return immediately
|
|
with the current status. If the mouse cursor is outside of the
|
|
graphics window, the
|
|
<B>mouse_x</B>
|
|
|
|
and
|
|
<B>mouse_y</B>
|
|
|
|
fields of the event are
|
|
outside the range
|
|
<B>0..size_x()-1, 0..size_y()-1</B>
|
|
|
|
. Keypresses
|
|
are queued, and dequeued one by one when the
|
|
<B>Key_pressed</B>
|
|
|
|
event is specified and the
|
|
<B>Poll</B>
|
|
|
|
event is not specified.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val loop_at_exit </I>
|
|
|
|
:
|
|
<B>event list -> (status -> unit) -> unit</B>
|
|
|
|
<P>
|
|
Loop before exiting the program, the list given as argument is the
|
|
list of handlers and the events on which these handlers are called.
|
|
To exit cleanly the loop, the handler should raise Exit. Any other
|
|
exception will be propagated outside of the loop.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.01
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H3>Mouse and keyboard polling</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val mouse_pos </I>
|
|
|
|
:
|
|
<B>unit -> int * int</B>
|
|
|
|
<P>
|
|
Return the position of the mouse cursor, relative to the
|
|
graphics window. If the mouse cursor is outside of the graphics
|
|
window,
|
|
<B>mouse_pos()</B>
|
|
|
|
returns a point outside of the range
|
|
<B>0..size_x()-1, 0..size_y()-1</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val button_down </I>
|
|
|
|
:
|
|
<B>unit -> bool</B>
|
|
|
|
<P>
|
|
Return
|
|
<B>true</B>
|
|
|
|
if the mouse button is pressed,
|
|
<B>false</B>
|
|
|
|
otherwise.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val read_key </I>
|
|
|
|
:
|
|
<B>unit -> char</B>
|
|
|
|
<P>
|
|
Wait for a key to be pressed, and return the corresponding
|
|
character. Keypresses are queued.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val key_pressed </I>
|
|
|
|
:
|
|
<B>unit -> bool</B>
|
|
|
|
<P>
|
|
Return
|
|
<B>true</B>
|
|
|
|
if a keypress is available; that is, if
|
|
<B>read_key</B>
|
|
|
|
would not block.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAN"> </A>
|
|
<H3>Sound</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val sound </I>
|
|
|
|
:
|
|
<B>int -> int -> unit</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>sound freq dur</B>
|
|
|
|
plays a sound at frequency
|
|
<B>freq</B>
|
|
|
|
(in hertz)
|
|
for a duration
|
|
<B>dur</B>
|
|
|
|
(in milliseconds).
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<A NAME="lbAO"> </A>
|
|
<H3>Double buffering</H3>
|
|
|
|
<P>
|
|
<P>
|
|
|
|
<P>
|
|
<I>val auto_synchronize </I>
|
|
|
|
:
|
|
<B>bool -> unit</B>
|
|
|
|
<P>
|
|
By default, drawing takes place both on the window displayed
|
|
on screen, and in a memory area (the 'backing store').
|
|
The backing store image is used to re-paint the on-screen
|
|
window when necessary.
|
|
<P>
|
|
To avoid flicker during animations, it is possible to turn
|
|
off on-screen drawing, perform a number of drawing operations
|
|
in the backing store only, then refresh the on-screen window
|
|
explicitly.
|
|
<P>
|
|
<P>
|
|
<B>auto_synchronize false</B>
|
|
|
|
turns on-screen drawing off. All
|
|
subsequent drawing commands are performed on the backing store
|
|
only.
|
|
<P>
|
|
<P>
|
|
<B>auto_synchronize true</B>
|
|
|
|
refreshes the on-screen window from
|
|
the backing store (as per
|
|
<B>synchronize</B>
|
|
|
|
), then turns on-screen
|
|
drawing back on. All subsequent drawing commands are performed
|
|
both on screen and in the backing store.
|
|
<P>
|
|
The default drawing mode corresponds to
|
|
<B>auto_synchronize true</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val synchronize </I>
|
|
|
|
:
|
|
<B>unit -> unit</B>
|
|
|
|
<P>
|
|
Synchronize the backing store and the on-screen window, by
|
|
copying the contents of the backing store onto the graphics
|
|
window.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val display_mode </I>
|
|
|
|
:
|
|
<B>bool -> unit</B>
|
|
|
|
<P>
|
|
Set display mode on or off. When turned on, drawings are done
|
|
in the graphics window; when turned off, drawings do not affect
|
|
the graphics window. This occurs independently of
|
|
drawing into the backing store (see the function
|
|
<B>Graphics.remember_mode</B>
|
|
|
|
below). Default display mode is on.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val remember_mode </I>
|
|
|
|
:
|
|
<B>bool -> unit</B>
|
|
|
|
<P>
|
|
Set remember mode on or off. When turned on, drawings are done
|
|
in the backing store; when turned off, the backing store is
|
|
unaffected by drawings. This occurs independently of drawing
|
|
onto the graphics window (see the function
|
|
<B>Graphics.display_mode</B>
|
|
|
|
above).
|
|
Default remember mode is on.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">Module</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAE">Initializations</A><DD>
|
|
<DT id="5"><A HREF="#lbAF">Colors</A><DD>
|
|
<DT id="6"><A HREF="#lbAG">Some predefined colors</A><DD>
|
|
<DT id="7"><A HREF="#lbAH">Point and line drawing</A><DD>
|
|
<DT id="8"><A HREF="#lbAI">Text drawing</A><DD>
|
|
<DT id="9"><A HREF="#lbAJ">Filling</A><DD>
|
|
<DT id="10"><A HREF="#lbAK">Images</A><DD>
|
|
<DT id="11"><A HREF="#lbAL">Mouse and keyboard events</A><DD>
|
|
<DT id="12"><A HREF="#lbAM">Mouse and keyboard polling</A><DD>
|
|
<DT id="13"><A HREF="#lbAN">Sound</A><DD>
|
|
<DT id="14"><A HREF="#lbAO">Double buffering</A><DD>
|
|
</DL>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:45 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|