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