aboutsummaryrefslogtreecommitdiff
path: root/man/man3/graphics.html
blob: 92f08c001ef53303f28e84ee65ee6bfba59d2bcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
<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 &ndash; 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 &lt;u.h&gt;<br>
    #include &lt;libc.h&gt;<br>
    #include &lt;draw.h&gt;<br>
    #include &lt;cursor.h&gt;<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;&nbsp;newwindow(char *str)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>void &nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;&nbsp;lockdisplay(Display *d)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;unlockdisplay(Display *d)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;cursorswitch(Cursor *curs)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>void &nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;freefont(Font *f)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;Pfmt(Fmt*)<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>int &nbsp;&nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;&nbsp;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 &nbsp;&nbsp;&nbsp;&nbsp;*screen<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>extern Screen &nbsp;&nbsp;&nbsp;&nbsp;*_screen<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    </font></tt>
    <tt><font size=+1>extern Font &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*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 &nbsp;&nbsp;&nbsp;&nbsp;(*error)(Display*, char*);<br>
            ...<br>
            Image &nbsp;&nbsp;&nbsp;*black;<br>
            Image &nbsp;&nbsp;&nbsp;*white;<br>
            Image &nbsp;&nbsp;&nbsp;*opaque;<br>
            Image &nbsp;&nbsp;&nbsp;*transparent;<br>
            Image &nbsp;&nbsp;&nbsp;*image;<br>
            Font &nbsp;&nbsp;&nbsp;&nbsp;*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; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* upper left */<br>
            Point max; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* 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>&le;<tt><font size=+1>max.x</font></tt> and <tt><font size=+1>min.y</font></tt>&le;<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 &ndash;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&#8217;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&#8722;&gt;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&#8217;s connection to the window. If <tt><font size=+1>rio</font></tt>
    is not running, it returns <tt><font size=+1>display&#8722;&gt;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&#8217;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>&#8217;s extra
    arguments are the full path of the window&#8217;s <tt><font size=+1>winname</font></tt> file and pointers
    to be overwritten with the values of the
    &#8216;global&#8217; <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 &#8216;soft screen&#8217;
    (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 &ndash;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>&#8217;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) &lt; 0)<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            sysfatal(&quot;resize failed: %r&quot;);<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(&quot;wsys&quot;);<br>
        if(srvwsys == nil)<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            sysfatal(&quot;can't find $wsys: %r&quot;);<br>
            
        </table>
        rfork(RFNAMEG); /* keep mount of rio private */<br>
        fd = open(srvwsys, ORDWR);<br>
        if(fd &lt; 0)<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            sysfatal(&quot;can't open $wsys: %r&quot;);<br>
            
        </table>
        /* mount creates window; see</font></tt> <i>rio</i><tt><font size=+1>(4) */<br>
        if(mount(fd, &#8722;1, &quot;/tmp&quot;, MREPL, &quot;new &#8722;dx 300&#8722;dy 200&quot;) &lt; 0)<br>
        
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            sysfatal(&quot;can't mount new window: %r&quot;);<br>
            
        </table>
        if(gengetwindow(display, &quot;/tmp/winname&quot;,<br>
         
        <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

            &amp;screen2, &amp;_screen2, Refnone) &lt; 0)<br>
            sysfatal(&quot;resize failed: %r&quot;);<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>&nbsp;&nbsp;&nbsp;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>