Initial import from FreeBSD RELENG_4:
[games.git] / lib / libvgl / vgl.3
1 .\" Copyright (c) 1997 Søren Schmidt
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer,
9 .\"    in this position and unchanged.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. The name of the author may not be used to endorse or promote products
14 .\"    derived from this software without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 .\"
27 .\" $FreeBSD: src/lib/libvgl/vgl.3,v 1.12.2.8 2001/12/17 10:08:35 ru Exp $
28 .Dd November 7, 1999
29 .Dt VGL 3
30 .Os
31 .Sh NAME
32 .Nm VGLBitmapAllocateBits ,
33 .Nm VGLBitmapCopy ,
34 .Nm VGLBitmapCreate ,
35 .Nm VGLBitmapDestroy ,
36 .Nm VGLBitmapPutChar ,
37 .Nm VGLBitmapString ,
38 .Nm VGLBlankDisplay ,
39 .Nm VGLBox ,
40 .Nm VGLCheckSwitch ,
41 .Nm VGLClear ,
42 .Nm VGLEllipse ,
43 .Nm VGLEnd ,
44 .Nm VGLFilledBox ,
45 .Nm VGLFilledEllipse ,
46 .Nm VGLGetXY ,
47 .Nm VGLInit ,
48 .Nm VGLLine ,
49 .Nm VGLKeyboardInit ,
50 .Nm VGLKeyboardEnd ,
51 .Nm VGLKeyboardGetCh ,
52 .Nm VGLMouseInit ,
53 .Nm VGLMouseMode ,
54 .Nm VGLMouseSetImage ,
55 .Nm VGLMouseSetStdImage ,
56 .Nm VGLMouseStatus ,
57 .Nm VGLPanScreen ,
58 .Nm VGLSetBorder ,
59 .Nm VGLSetPalette ,
60 .Nm VGLSetPaletteIndex ,
61 .Nm VGLSetVScreenSize ,
62 .Nm VGLSetXY ,
63 .Nm VGLTextSetFontFile
64 .Nd Video Graphics Library functions
65 .Sh LIBRARY
66 .Lb libvgl
67 .Sh SYNOPSIS
68 .In machine/console.h
69 .In vgl.h
70 .Ft int
71 .Fn VGLInit "int mode"
72 .Ft void
73 .Fn VGLEnd "void"
74 .Ft void
75 .Fn VGLCheckSwitch "void"
76 .Ft int
77 .Fn VGLTextSetFontFile "char *filename"
78 .Ft int
79 .Fn VGLKeyboardInit "int code"
80 .Ft void
81 .Fn VGLKeyboardEnd "void"
82 .Ft int
83 .Fn VGLKeyboardGetCh "void"
84 .Ft int
85 .Fn VGLMouseInit "int mode"
86 .Ft void
87 .Fn VGLMouseMode "int mode"
88 .Ft int
89 .Fn VGLMouseStatus "int *x" "int *y" "char *buttons"
90 .Ft void
91 .Fn VGLMouseSetImage "VGLBitmap *AndMask" "VGLBitmap *OrMask"
92 .Ft void
93 .Fn VGLMouseSetStdImage "void"
94 .Ft byte
95 .Fn VGLGetXY "VGLBitmap *object" "int x" "int y"
96 .Ft void
97 .Fn VGLSetXY "VGLBitmap *object" "int x" "int y" "byte color"
98 .Ft void
99 .Fn VGLLine "VGLBitmap *object" "int x1" "int y1" "int x2" "int y2" "byte color"
100 .Ft void
101 .Fn VGLBox "VGLBitmap *object" "int x1" "int y1" "int x2" "int y2" "byte color"
102 .Ft void
103 .Fn VGLFilledBox "VGLBitmap *object" "int x1" "int y1" "int x2" "int y2" "byte color"
104 .Ft void
105 .Fn VGLEllipse "VGLBitmap *object" "int xc" "int yc" "int a" "int b" "byte color"
106 .Ft void
107 .Fn VGLFilledEllipse "VGLBitmap *object" "int xc" "int yc" "int a" "int b" "byte color"
108 .Ft VGLBitmap *
109 .Fn VGLBitmapCreate "int type" "int xsize" "int ysize" "byte *bits"
110 .Ft void
111 .Fn VGLBitmapDestroy "VGLBitmap *object"
112 .Ft int
113 .Fn VGLBitmapAllocateBits "VGLBitmap *object"
114 .Ft int
115 .Fn VGLBitmapCopy "VGLBitmap *src" "int srcx" "int srcy" "VGLBitmap *dst" "int dstx" "int dsty" "int width" "int hight"
116 .Ft void
117 .Fn VGLBitmapPutChar "VGLBitmap *Object" "int x" "int y" "byte ch" "byte fgcol" "byte bgcol" "int fill" "int dir"
118 .Ft void
119 .Fn VGLBitmapString "VGLBitmap *Object" "int x" "int y" "char *str" "byte fgcol" "byte bgcol" "int fill" "int dir"
120 .Ft void
121 .Fn VGLClear "VGLBitmap *object" "byte color"
122 .Ft void
123 .Fn VGLSetPalette "byte *red" "byte *green" "byte *blue"
124 .Ft void
125 .Fn VGLSetPaletteIndex "byte color" "byte red" "byte green" "byte blue"
126 .Ft void
127 .Fn VGLSetBorder "byte color"
128 .Ft int
129 .Fn VGLSetVScreenSize "VGLBitmap *object" "int vxsize" "int vysize"
130 .Ft int
131 .Fn VGLPanScreen "VGLBitmap *object" "int x" "int y"
132 .Ft void
133 .Fn VGLBlankDisplay "int blank"
134 .Sh DESCRIPTION
135 .Nm Libvgl
136 is a library that enables the programmer access to the graphics
137 modes supported by the console driver (syscons). The library takes care of
138 programming the actual video hardware, and provides a number of simple
139 functions to do various graphic operations.
140 There is also support for a
141 mouse via the standard mouse system in
142 .Fx ,
143 see
144 .Xr mouse 4 ,
145 including the ability to transparently have a mouse pointer superimposed on
146 the graphic image currently being worked on.
147 The library takes care of screen switching by storing the current image in
148 memory before switching to another virtual console, and restoring when the
149 user switches back.
150 This allows several graphic applications at once, but
151 on different virtual consoles.
152 .Pp
153 Below is a short description of the various functions:
154 .Pp
155 .Fn VGLInit
156 initialize the library and set up the graphic mode
157 .Va mode .
158 .Pp
159 .Fn VGLEnd
160 terminate graphic mode, and restore the screenmode that was active before
161 .Fn VGLInit
162 was called.
163 .Pp
164 .Fn VGLCheckSwitch
165 if the program goes into longer periods of processing without doing
166 any graphics output, calling this function occasionally will allow
167 the system to switch screens.
168 .Pp
169 .Fn VGLTextSetFontFile
170 instruct the char/string functions to use the font in file
171 .Pa filename
172 instead of the builtin font.
173 .Pp
174 .Fn VGLKeyboardInit
175 set up the keyboard in the
176 .Dq raw
177 I/O mode and
178 specify the key code to be used.
179 .Va code
180 must be
181 .Dv VGL_XLATEKEYS ,
182 .Dv VGL_CODEKEYS ,
183 or
184 .Dv VGL_RAWKEYS .
185 When
186 .Dv VGL_XLATEKEYS
187 is specified, the keyboard translate the raw keyboard scan code into
188 a character code.
189 If
190 .Dv VGL_RAWKEYS
191 is used, the raw keyboard scan code is read as is.
192 .Dv VGL_CODEKEYS
193 is the intermediate key code; each key is assigned a unique code whereas
194 more than one raw scan code may be generated when a key is pressed.
195 .Pp
196 .Fn VGLKeyboardEnd
197 when you have finished using the keyboard, call this function.
198 .Pp
199 .Fn VGLKeyboardGetCh
200 read one byte from the keyboard.  As the keyboard I/O is in the
201 .Dq raw
202 input mode, the function will not block even if there is no input data,
203 and returns 0.
204 .Pp
205 .Fn VGLMouseInit
206 initialize the mouse.
207 The optional on-screen mouse pointer is shown if the
208 argument is
209 .Dv VGL_MOUSESHOW .
210 .Pp
211 .Fn VGLMouseMode
212 either shows the mouse pointer if the argument is
213 .Dv VGL_MOUSESHOW ,
214 or hides the mouse pointer if the argument is
215 .Dv VGL_MOUSEHIDE .
216 .Pp
217 .Fn VGLMouseStatus
218 returns the current mouse pointer coordinates and button state in
219 .Va x , y ,
220 buttons.
221 The return value reflects if the mouse pointer
222 is currently shown on screen or not.
223 .Pp
224 .Fn VGLMouseSetImage
225 with this function it is possible to change the image of the mouse pointer
226 on screen.
227 .Pp
228 .Fn VGLMouseSetStdImage
229 this function restores the mouse pointer to the standard arrow.
230 .Pp
231 .Fn VGLGetXY
232 retrieves the color of the pixel located at
233 .Va x , y ,
234 coordinates of the
235 .Va object
236 argument, and returns it as a byte value.
237 .Pp
238 .Fn VGLSetXY
239 sets the color of the pixel located at
240 .Va x , y ,
241 coordinates of the
242 .Va object
243 argument to
244 .Va color
245 byte value.
246 .Pp
247 .Fn VGLLine
248 draw a line from
249 .Va x1 , y1
250 to
251 .Va x2 , y2
252 in color
253 .Va color .
254 .Pp
255 .Fn VGLBox
256 draw a box with upper left hand corner at
257 .Va x1 , y1
258 and lower right hand corner at
259 .Va x2 , y2
260 in color
261 .Va color .
262 .Pp
263 .Fn VGLFilledBox
264 draw a filled (solid) box with upper left hand corner at
265 .Va x1 , y1
266 and lower right hand corner at
267 .Va x2 , y2
268 in color
269 .Va color .
270 .Pp
271 .Fn VGLEllipse
272 draw an ellipse centered at
273 .Va xc , yc
274 make it
275 .Va a
276 pixels wide, and
277 .Va b
278 pixels high in color
279 .Va color .
280 .Pp
281 .Fn VGLFilledEllipse
282 draw a filled (solid) ellipse centered at
283 .Va xc , yc
284 make it
285 .Va a
286 pixels wide, and
287 .Va b
288 pixels high in color
289 .Va color .
290 .Pp
291 .Fn VGLBitmapCreate
292 create a bitmap object and initialize it with the specified
293 values and bit data.
294 .Va type
295 must be
296 .Dv MEMBUF
297 for the in-memory bitmap.
298 .Va bits
299 may be NULL so that bitmap data may be associated later.
300 .Pp
301 There also is a macro,
302 .Fn VGLBITMAP_INITIALIZER "type" "xsize" "ysize" "bits"
303 to initialize a statically declared bitmap object.
304 .Pp
305 .Fn VGLBitmapDestroy
306 free the bitmap data and the bitmap object.
307 .Pp
308 .Fn VGLBitmapAllocateBits
309 allocate a bit data buffer for the specified object.
310 .Pp
311 .Fn VGLBitmapCopy
312 copy a rectangle of pixels from bitmap
313 .Va src
314 upper left hand corner at
315 .Va srcx , srcy
316 to bitmap
317 .Va dst
318 at
319 .Va dstx , dsty
320 of the size
321 .Va width , height .
322 .Pp
323 .Fn VGLBitmapPutChar
324 write the character
325 .Va ch
326 at position
327 .Va x , y
328 in foreground color
329 .Va fgcol .
330 If
331 .Va fill
332 is != 0, use the color
333 .Va bgcol
334 as background otherwise the background is transparent.
335 The character is drawn in the direction specified by the argument
336 .Va dir .
337 .Pp
338 .Fn VGLBitmapString
339 write the string
340 .Va str
341 at position
342 .Va x , y
343 in foreground color
344 .Va fgcol .
345 If
346 .Va fill
347 is != 0, use the color
348 .Va bgcol
349 as background otherwise the background is transparent.
350 The string is drawn in the direction specified by the argument
351 .Va dir .
352 .Pp
353 .Fn VGLClear
354 clears the entire bitmap to color
355 .Va color .
356 .Pp
357 .Fn VGLSetPalette
358 this function sets the palette used, the arguments
359 .Va red , green , blue
360 should point to byte arrays of 256 positions each.
361 .Pp
362 .Fn VGLSetPaletteIndex
363 set the palette index
364 .Va color
365 to the specified RGB value.
366 .Pp
367 .Fn VGLSetBorder
368 set the border color to color
369 .Va color .
370 .Pp
371 .Fn VGLSetVScreenSize
372 change the virtual screen size of the display.  Note that this
373 function must be called when our vty is in the foreground.
374 And
375 .Va object
376 must be
377 .Va VGLDisplay .
378 Passing a in-memory bitmap to this function results in error.
379 .Pp
380 The desired virtual screen width may not be achievable because
381 of the video card hardware.  In such case the video driver (and
382 underlaying video BIOS) may choose the next largest values.
383 Always examine
384 .Va object->VXsize
385 and
386 .Va VYsize
387 after calling this function, in order to see how the virtual screen
388 is actually set up.
389 .Pp
390 In order to set up the largest possible virtual screen, you may
391 call this function with arbitrary large values.
392 .Pp
393 .Dl VGLSetVScreenSize(10000, 10000);
394 .Pp
395 .Fn VGLPanSreen
396 change the origin of the displayed screen in the virtual screen.
397 Note that this function must be called when our vty is in the
398 foreground.
399 .Va object
400 must be
401 .Va VGLDisplay .
402 Passing a in-memory bitmap to this function results in error.
403 .Pp
404 .Fn VGLBlankDisplay
405 blank the display if the argument
406 .Va blank
407 \*(Ne 0.
408 This can be done to shut off the screen during display updates that
409 the user should first see when it's done.
410 .Ss Program termination and signal processing
411 It is important to call
412 .Fn VGLEnd
413 before terminating the program.
414 Care must be taken if you install signal handlers and try to call
415 .Fn VGLEnd
416 and
417 .Xr exit 3
418 to end the program.
419 If a signal is caught while the program is inside
420 .Nm libvgl
421 functions,
422 .Fn VGLEnd
423 may not be able to properly restore the graphics hardware.
424 .Pp
425 The recommended way to handle signals and program termination is to
426 have a flag to indicate signal's delivery.
427 Your signal handlers set this flag but do not terminate
428 the program immediately.
429 The main part of the program checks the flag to see if it is
430 supposed to terminate, and calls
431 .Fn VGLEnd
432 and
433 .Xr exit 3
434 if the flag is set.
435 .Pp
436 Note that
437 .Fn VGLInit
438 installs its internal signal handlers for
439 .Dv SIGINT , SIGTERM , SIGSEGV ,
440 and
441 .Dv SIGBUS ,
442 and terminates the program at appropriate time,
443 after one of these signals is caught.
444 If you want to have your own signal handlers for these signals,
445 install handlers
446 .Em after
447 .Fn VGLInit .
448 .Pp
449 .Dv SIGUSR1
450 and
451 .Dv SIGUSR2
452 are internally used by
453 .Nm libvgl
454 to control screen switching and the mouse pointer,
455 and are not available to
456 .Nm libvgl
457 client programs.
458 .Sh AUTHORS
459 .An S\(/oren Schmidt Aq sos@FreeBSD.org
460 .Sh HISTORY
461 The
462 .Nm vgl
463 library appeared in
464 .Fx 3.0 .