592 lines
28 KiB
HTML
592 lines
28 KiB
HTML
<head>
|
|
<title>graphics(3) - Plan 9 from User Space</title>
|
|
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
|
|
</head>
|
|
<body bgcolor=#ffffff>
|
|
<table border=0 cellpadding=0 cellspacing=0 width=100%>
|
|
<tr height=10><td>
|
|
<tr><td width=20><td>
|
|
<tr><td width=20><td><b>GRAPHICS(3)</b><td align=right><b>GRAPHICS(3)</b>
|
|
<tr><td width=20><td colspan=2>
|
|
<br>
|
|
<p><font size=+1><b>NAME </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
Display, Point, Rectangle, Cursor, initdraw, geninitdraw, drawerror,
|
|
initdisplay, closedisplay, getdefont, getwindow, gengetwindow,
|
|
flushimage, bufimage, lockdisplay, unlockdisplay, cursorswitch,
|
|
cursorset, openfont, buildfont, freefont, Pfmt, Rfmt, strtochan,
|
|
chantostr, chantodepth – interactive graphics
|
|
|
|
</table>
|
|
<p><font size=+1><b>SYNOPSIS </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>#include <u.h><br>
|
|
#include <libc.h><br>
|
|
#include <draw.h><br>
|
|
#include <cursor.h><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int initdraw(void (*errfun)(Display*, char*), char *font,<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
char *label)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
</table>
|
|
|
|
</table>
|
|
</font></tt>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
|
|
|
|
</table>
|
|
|
|
</table>
|
|
<tt><font size=+1>int geninitdraw(char *devdir, void(*errfun)(Display*, char*),<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>char *font, char *label, char *mousedir, char *windir,<br>
|
|
int ref)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
|
|
</table>
|
|
|
|
</table>
|
|
<tt><font size=+1>int newwindow(char *str)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void drawerror(Display *d, char *msg)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>Display*initdisplay(char *devdir, char *win, void(*errfun)(Display*,
|
|
char*))<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void closedisplay(Display *d)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>Font* getdefont(Display *d)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int flushimage(Display *d, int vis)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int bufimage(Display *d, int n)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int lockdisplay(Display *d)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int unlockdisplay(Display *d)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int getwindow(Display *d, int ref)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int gengetwindow(Display *d, char *winname,<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
Image **ip, Screen **sp, int ref)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
</table>
|
|
|
|
</table>
|
|
</font></tt>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
|
|
|
|
</table>
|
|
|
|
</table>
|
|
<tt><font size=+1>void cursorswitch(Cursor *curs)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void cursorset(Point p)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>Font* openfont(Display *d, char *name)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>Font* buildfont(Display *d, char *desc, char *name)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>void freefont(Font *f)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int Pfmt(Fmt*)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int Rfmt(Fmt*)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>ulong strtochan(char *s)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>char* chantostr(char *s, ulong chan)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>int chantodepth(ulong chan)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>extern Display *display<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>extern Image *screen<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>extern Screen *_screen<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
<tt><font size=+1>extern Font *font<br>
|
|
</font></tt>
|
|
</table>
|
|
<p><font size=+1><b>DESCRIPTION </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
A <tt><font size=+1>Display</font></tt> structure represents a connection to the graphics device,
|
|
<a href="../man3/draw.html"><i>draw</i>(3)</a>, holding all graphics resources associated with the connection,
|
|
including in particular raster image data in use by the client
|
|
program. The structure is defined (in part) as:<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>typedef<br>
|
|
struct Display<br>
|
|
{<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
...<br>
|
|
void (*error)(Display*, char*);<br>
|
|
...<br>
|
|
Image *black;<br>
|
|
Image *white;<br>
|
|
Image *opaque;<br>
|
|
Image *transparent;<br>
|
|
Image *image;<br>
|
|
Font *defaultfont;<br>
|
|
Subfont*defaultsubfont;<br>
|
|
...<br>
|
|
|
|
</table>
|
|
};<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
|
|
</table>
|
|
A <tt><font size=+1>Point</font></tt> is a location in an Image (see below and <a href="../man3/draw.html"><i>draw</i>(3)</a>), such
|
|
as the display, and is defined as:<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>typedef<br>
|
|
struct Point {<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
int x;<br>
|
|
int y;<br>
|
|
|
|
</table>
|
|
} Point;<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
|
|
</table>
|
|
The coordinate system has <i>x</i> increasing to the right and <i>y</i> increasing
|
|
down.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
A <tt><font size=+1>Rectangle</font></tt> is a rectangular area in an image.<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>typedef<br>
|
|
struct Rectangle {<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
Point min; /* upper left */<br>
|
|
Point max; /* lower right */<br>
|
|
|
|
</table>
|
|
} Rectangle;<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
|
|
</table>
|
|
By definition, <tt><font size=+1>min.x</font></tt>≤<tt><font size=+1>max.x</font></tt> and <tt><font size=+1>min.y</font></tt>≤<tt><font size=+1>max.y</font></tt>. By convention, the right
|
|
(maximum <i>x</i>) and bottom (maximum <i>y</i>) edges are excluded from the
|
|
represented rectangle, so abutting rectangles have no points in
|
|
common. Thus, <tt><font size=+1>max</font></tt> contains the coordinates of the first point
|
|
beyond the rectangle.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
The <tt><font size=+1>Image</font></tt> data structure is defined in <a href="../man3/draw.html"><i>draw</i>(3)</a>.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
A <tt><font size=+1>Font</font></tt> is a set of character images, indexed by runes (see <a href="../man7/utf.html"><i>utf</i>(7)</a>).
|
|
The images are organized into <tt><font size=+1>Subfonts</font></tt>, each containing the images
|
|
for a small, contiguous set of runes. The detailed format of these
|
|
data structures, which are described in detail in <a href="../man3/cachechars.html"><i>cachechars</i>(3)</a>,
|
|
is immaterial for most applications. <tt><font size=+1>Font</font></tt> and
|
|
<tt><font size=+1>Subfont</font></tt> structures contain two interrelated fields: <tt><font size=+1>ascent</font></tt>, the
|
|
distance from the top of the highest character (actually the top
|
|
of the image holding all the characters) to the baseline, and
|
|
<tt><font size=+1>height</font></tt>, the distance from the top of the highest character to
|
|
the bottom of the lowest character (and hence, the interline
|
|
spacing). See <a href="../man3/cachechars.html"><i>cachechars</i>(3)</a> for more details.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Buildfont</i> parses the font description in the buffer <tt><font size=+1>desc</font></tt>, returning
|
|
a <tt><font size=+1>Font*</font></tt> pointer that can be used by <tt><font size=+1>string</font></tt> (see <a href="../man3/draw.html"><i>draw</i>(3)</a>) to draw
|
|
characters from the font. <i>Openfont</i> does the same, but reads the
|
|
description from the named file. <i>Freefont</i> frees a font. The convention
|
|
for naming font files is:
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>/lib/font/bit/</font></tt><i>name</i><tt><font size=+1>/</font></tt><i>range</i><tt><font size=+1>.</font></tt><i>size</i><tt><font size=+1>.font
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
|
|
</table>
|
|
where <i>size</i> is approximately the height in pixels of the lower
|
|
case letters (without ascenders or descenders). <i>Range</i> gives some
|
|
indication of which characters will be available: for example
|
|
<tt><font size=+1>ascii</font></tt>, <tt><font size=+1>latin1</font></tt>, <tt><font size=+1>euro</font></tt>, or <tt><font size=+1>unicode</font></tt>. <tt><font size=+1>Euro</font></tt> includes most European languages,
|
|
punctuation marks, the International Phonetic
|
|
Alphabet, etc., but no Oriental languages. <tt><font size=+1>Unicode</font></tt> includes every
|
|
character for which appropriate-sized images exist on the system.
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
A <i>Cursor</i> is defined:<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>typedef struct<br>
|
|
Cursor {<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
Point offset;<br>
|
|
uchar clr[2*16];<br>
|
|
uchar set[2*16];<br>
|
|
|
|
</table>
|
|
} Cursor;<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
</font></tt>
|
|
|
|
</table>
|
|
The arrays are arranged in rows, two bytes per row, left to right
|
|
in big-endian order to give 16 rows of 16 bits each. A cursor
|
|
is displayed on the screen by adding <tt><font size=+1>offset</font></tt> to the current mouse
|
|
position, using <tt><font size=+1>clr</font></tt> as a mask to draw white at the pixels where
|
|
<tt><font size=+1>clr</font></tt> is one, and then drawing black at the pixels where <tt><font size=+1>set
|
|
</font></tt>is one.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
The routine <i>initdraw</i> connects to the display; it returns –1 if
|
|
it fails and sets the error string. <i>Initdraw</i> sets up the global
|
|
variables <tt><font size=+1>display</font></tt> (the <tt><font size=+1>Display</font></tt> structure representing the connection),
|
|
<tt><font size=+1>screen</font></tt> (an <tt><font size=+1>Image</font></tt> representing the display memory itself or, if
|
|
<a href="../man1/rio.html"><i>rio</i>(1)</a> is running, the client’s window), and <tt><font size=+1>font</font></tt> (the
|
|
default font for text). The arguments to <i>initdraw</i> include a <i>label</i>,
|
|
which is written to <tt><font size=+1>/dev/label</font></tt> if non-nil so that it can be used
|
|
to identify the window when hidden (see <a href="../man1/rio.html"><i>rio</i>(1)</a>). The font is created
|
|
by reading the named <i>font</i> file. If <tt><font size=+1>font</font></tt> is null, <i>initdraw</i> reads
|
|
the file named in the environment variable <tt><font size=+1>$font</font></tt>; if
|
|
<tt><font size=+1>$font</font></tt> is not set, it imports the default (usually minimal) font
|
|
from the operating system. The global <i>font</i> will be set to point
|
|
to the resulting <tt><font size=+1>Font</font></tt> structure. The <i>errfun</i> argument is a <i>graphics
|
|
error function</i> to call in the event of a fatal error in the library;
|
|
it must never return. Its arguments are the display pointer
|
|
and an error string. If <i>errfun</i> is nil, the library provides a
|
|
default, called <i>drawerror</i>. Another effect of <i>initdraw</i> is that
|
|
it installs <a href="../man3/print.html"><i>print</i>(3)</a> formats <i>Pfmt</i> and <i>Rfmt</i> as <tt><font size=+1>%P</font></tt> and <tt><font size=+1>%R</font></tt> for printing
|
|
<tt><font size=+1>Points</font></tt> and <tt><font size=+1>Rectangles</font></tt>.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
The <i>geninitdraw</i> function provides a less automated way to establish
|
|
a connection, for programs that wish to connect to multiple displays.
|
|
<i>Devdir</i> is the name of the directory containing the device files
|
|
for the display (if nil, default <tt><font size=+1>/dev</font></tt>); <i>errfun</i>, <i>font</i>, and <i>label</i>
|
|
are as in <i>initdraw</i>; <i>mousedir</i> and <i>windir</i> are the directories
|
|
holding the <tt><font size=+1>mouse</font></tt> and <tt><font size=+1>winname</font></tt> files; and <i>ref</i> specifies the refresh
|
|
function to be used to create the window, if running under <a href="../man1/rio.html"><i>rio</i>(1)</a>
|
|
(see <a href="../man3/window.html"><i>window</i>(3)</a>).
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Initdisplay</i> is part of <i>geninitdraw</i>; it sets up the display structures
|
|
but does not allocate any fonts or call <i>getwindow</i>. The arguments
|
|
are similar to those of <i>initdraw</i>; <i>win</i> names the directory, default
|
|
<tt><font size=+1>/dev</font></tt>, in which the files associated with the window reside. <i>Closedisplay</i>
|
|
disconnects the display and frees the associated
|
|
data structures. <i>Getdefont</i> builds a <tt><font size=+1>Font</font></tt> structure from in-core
|
|
data describing a default font. None of these routines is needed
|
|
by most programs, since <i>initdraw</i> calls them as needed.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
The data structures associated with the display must be protected
|
|
in a multi-process program, because they assume only one process
|
|
will be using them at a time. Multi-process programs should set
|
|
<tt><font size=+1>display−>locking</font></tt> to <tt><font size=+1>1</font></tt>, to notify the library to use a locking protocol
|
|
for its own accesses, and call <i>lockdisplay</i> and
|
|
<i>unlockdisplay</i> around any calls to the graphics library that will
|
|
cause messages to be sent to the display device. <i>Initdraw</i> and
|
|
<i>geninitdraw</i> initialize the display to the locked state.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Getwindow</i> returns a pointer to the window associated with the
|
|
application; it is called automatically by <i>initdraw</i> to establish
|
|
the <tt><font size=+1>screen</font></tt> pointer but must be called after each resizing of the
|
|
window to restore the library’s connection to the window. If <tt><font size=+1>rio</font></tt>
|
|
is not running, it returns <tt><font size=+1>display−>image</font></tt>; otherwise it
|
|
negotiates with <tt><font size=+1>rio</font></tt> by looking in <tt><font size=+1>/dev/winname</font></tt> to find the name
|
|
of the window and opening it using <tt><font size=+1>namedimage</font></tt> (see <a href="../man3/allocimage.html"><i>allocimage</i>(3)</a>).
|
|
The resulting window will be created using the refresh method
|
|
<i>ref</i> (see <a href="../man3/window.html"><i>window</i>(3)</a>); this should almost always be <tt><font size=+1>Refnone</font></tt> because
|
|
<tt><font size=+1>rio</font></tt> provides backing store for the window.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Getwindow</i> overwrites the global variables <tt><font size=+1>screen</font></tt>, a pointer to
|
|
the <tt><font size=+1>Image</font></tt> defining the window (or the overall display, if no window
|
|
system is running); and <tt><font size=+1>_screen</font></tt>, a pointer to the <tt><font size=+1>Screen</font></tt> representing
|
|
the root of the window’s hierarchy. (See <a href="../man3/window.html"><i>window</i>(3)</a>. The overloading
|
|
of the <tt><font size=+1>screen</font></tt> word is an unfortunate
|
|
historical accident.) <i>Getwindow</i> arranges that <tt><font size=+1>screen</font></tt> point to
|
|
the portion of the window inside the border; sophisticated clients
|
|
may use <tt><font size=+1>_screen</font></tt> to make further subwindows. <i>Gengetwindow</i>’s extra
|
|
arguments are the full path of the window’s <tt><font size=+1>winname</font></tt> file and pointers
|
|
to be overwritten with the values of the
|
|
‘global’ <tt><font size=+1>Image</font></tt> and <tt><font size=+1>Screen</font></tt> variables for the new window.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
The mouse cursor is always displayed. The initial cursor is an
|
|
arrow. <i>Cursorswitch</i> causes the argument cursor to be displayed
|
|
instead. A zero argument causes a switch back to the arrow cursor.
|
|
<i>Cursorset</i> moves the mouse cursor to position <i>p</i>, provided (if in
|
|
a window) that the requesting program is executing in the
|
|
current window and the mouse is within the window boundaries;
|
|
otherwise <i>cursorset</i> is a no-op.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
The graphics functions described in <a href="../man3/draw.html"><i>draw</i>(3)</a>, <a href="../man3/allocimage.html"><i>allocimage</i>(3)</a>, <a href="../man3/cachechars.html"><i>cachechars</i>(3)</a>,
|
|
and <a href="../man3/subfont.html"><i>subfont</i>(3)</a> are implemented by writing commands to files under
|
|
<tt><font size=+1>/dev/draw</font></tt> (see <a href="../man3/draw.html"><i>draw</i>(3)</a>); the writes are buffered, so the functions
|
|
may not take effect immediately. <i>Flushimage</i> flushes the buffer,
|
|
doing all pending graphics operations. If
|
|
<i>vis</i> is non-zero, any changes are also copied from the ‘soft screen’
|
|
(if any) in the driver to the visible frame buffer. The various
|
|
allocation routines in the library flush automatically, as does
|
|
the event package (see <a href="../man3/event.html"><i>event</i>(3)</a>); most programs do not need to
|
|
call <i>flushimage</i>. It returns –1 on error.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
<i>Bufimage</i> is used to allocate space for <i>n</i> bytes in the display
|
|
buffer. It is used by all the graphics routines to send messages
|
|
to the display.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
The functions <i>strtochan</i> and <i>chantostr</i> convert between the channel
|
|
descriptor strings used by <a href="../man7/image.html"><i>image</i>(7)</a> and the internal <tt><font size=+1>ulong</font></tt> representation
|
|
used by the graphics protocol (see <a href="../man3/draw.html"><i>draw</i>(3)</a>’s <tt><font size=+1>b</font></tt> message). <tt><font size=+1>Chantostr</font></tt>
|
|
writes at most nine bytes into the buffer pointed at by <i>s</i> and
|
|
returns <i>s</i> on success, 0 on failure.
|
|
<tt><font size=+1>Chantodepth</font></tt> returns the number of bits per pixel used by the format
|
|
specified by <i>chan</i>. Both <tt><font size=+1>chantodepth</font></tt> and <tt><font size=+1>strtochan</font></tt> return 0 when
|
|
presented with bad input.<br>
|
|
|
|
</table>
|
|
<p><font size=+1><b>EXAMPLES </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
To reconnect to the window after a resize event,<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>if(getwindow(display, Refnone) < 0)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
sysfatal("resize failed: %r");<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
</table>
|
|
</font></tt>
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
|
|
|
|
</table>
|
|
|
|
</table>
|
|
To create and set up a new <a href="../man1/rio.html"><i>rio</i>(1)</a> window,<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>Image *screen2;<br>
|
|
Screen *_screen2;<br>
|
|
srvwsys = getenv("wsys");<br>
|
|
if(srvwsys == nil)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
sysfatal("can't find $wsys: %r");<br>
|
|
|
|
</table>
|
|
rfork(RFNAMEG); /* keep mount of rio private */<br>
|
|
fd = open(srvwsys, ORDWR);<br>
|
|
if(fd < 0)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
sysfatal("can't open $wsys: %r");<br>
|
|
|
|
</table>
|
|
/* mount creates window; see</font></tt> <i>rio</i><tt><font size=+1>(4) */<br>
|
|
if(mount(fd, −1, "/tmp", MREPL, "new −dx 300−dy 200") < 0)<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
sysfatal("can't mount new window: %r");<br>
|
|
|
|
</table>
|
|
if(gengetwindow(display, "/tmp/winname",<br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
&screen2, &_screen2, Refnone) < 0)<br>
|
|
sysfatal("resize failed: %r");<br>
|
|
|
|
</table>
|
|
/* now open /tmp/cons, /tmp/mouse */<br>
|
|
...<br>
|
|
</font></tt>
|
|
</table>
|
|
|
|
</table>
|
|
<p><font size=+1><b>FILES </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>/usr/local/plan9/font/bit </font></tt> directory of fonts<br>
|
|
|
|
</table>
|
|
<p><font size=+1><b>SOURCE </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<tt><font size=+1>/usr/local/plan9/src/libdraw<br>
|
|
</font></tt>
|
|
</table>
|
|
<p><font size=+1><b>SEE ALSO </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
<a href="../man1/rio.html"><i>rio</i>(1)</a>, <a href="../man3/addpt.html"><i>addpt</i>(3)</a>, <a href="../man3/allocimage.html"><i>allocimage</i>(3)</a>, <a href="../man3/cachechars.html"><i>cachechars</i>(3)</a>, <a href="../man3/subfont.html"><i>subfont</i>(3)</a>, <a href="../man3/draw.html"><i>draw</i>(3)</a>,
|
|
<a href="../man3/event.html"><i>event</i>(3)</a>, <a href="../man3/frame.html"><i>frame</i>(3)</a>, <a href="../man3/print.html"><i>print</i>(3)</a>, <a href="../man3/window.html"><i>window</i>(3)</a>, <a href="../man3/draw.html"><i>draw</i>(3)</a>, <a href="../man7/image.html"><i>image</i>(7)</a>, <a href="../man7/font.html"><i>font</i>(7)</a><br>
|
|
|
|
</table>
|
|
<p><font size=+1><b>DIAGNOSTICS </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
An error function may call <a href="../man3/errstr.html"><i>errstr</i>(3)</a> for further diagnostics.<br>
|
|
|
|
</table>
|
|
<p><font size=+1><b>BUGS </b></font><br>
|
|
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>
|
|
|
|
The names <tt><font size=+1>clr</font></tt> and <tt><font size=+1>set</font></tt> in the <tt><font size=+1>Cursor</font></tt> structure are reminders of
|
|
an archaic color map and might be more appropriately called <tt><font size=+1>white</font></tt>
|
|
and <tt><font size=+1>black</font></tt>.
|
|
<table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
|
|
|
|
These manual pages contain many references to the now-fictitious
|
|
<tt><font size=+1>/dev/draw</font></tt>.<br>
|
|
|
|
</table>
|
|
|
|
<td width=20>
|
|
<tr height=20><td>
|
|
</table>
|
|
<!-- TRAILER -->
|
|
<table border=0 cellpadding=0 cellspacing=0 width=100%>
|
|
<tr height=15><td width=10><td><td width=10>
|
|
<tr><td><td>
|
|
<center>
|
|
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
|
|
</center>
|
|
</table>
|
|
<!-- TRAILER -->
|
|
</body></html>
|