2 * Copyright (c) 1999 Greg Haerr <greg@censoft.com>
4 * Screen Driver using BOGL Library
6 * This driver now requires only the following BOGL entry points:
7 * bogl_init, bogl_done,
8 * bogl_pixel, bogl_readpixel,
9 * bogl_vline, bogl_hline
11 * All graphics drawing primitives are based on top of these functions.
13 * This file also contains the generalized low-level font/text
14 * drawing routines, which will be split out into another file.
15 * Both fixed and proportional fonts are supported, with fixed
16 * pitch structure allowing much smaller font files.
19 #include "../device.h"
20 #include "bogl/bogl.h"
22 /* specific bogl driver entry points*/
23 static int BOGL_open(SCREENDEVICE *psd);
24 static void BOGL_close(void);
25 static void BOGL_getscreeninfo(PSCREENINFO psi);
26 static void BOGL_setpalette(int first,int count,RGBENTRY *pal);
27 static void BOGL_drawpixel(COORD x, COORD y, PIXELVAL c);
28 static PIXELVAL BOGL_readpixel(COORD x, COORD y);
29 static void BOGL_drawhline(COORD x1, COORD x2, COORD y, PIXELVAL c);
30 static void BOGL_drawvline(COORD x, COORD y1, COORD y2, PIXELVAL c);
31 static void BOGL_fillrect(COORD x1, COORD y1, COORD x2, COORD y2, PIXELVAL c);
33 /* generalized text/font routines*/
34 static BOOL gen_getfontinfo(FONTID fontid,PFONTINFO pfontinfo);
35 static void gen_gettextsize(const UCHAR *str,int cc,COORD *retwd,
36 COORD *retht,FONTID fontid);
37 static void gen_gettextbits(UCHAR ch,IMAGEBITS *retmap,COORD *retwd,
38 COORD *retht,FONTID fontid);
39 /*static void gen_drawtext(COORD x, COORD y, const UCHAR *s, int n,
40 PIXELVAL fg, FONTID fontid);
41 static void gen_drawbitmap(COORD x, COORD y, COORD width, COORD height,
42 IMAGEBITS *table, PIXELVAL fgcolor);*/
44 SCREENDEVICE scrdev = {
57 640, 480, 256, PF_PALETTE
60 /* compiled in fonts*/
61 #define NUMBER_FONTS 3
62 extern FONT font_rom8x16, font_rom8x8;
63 extern FONT font_winFreeSansSerif11x13;
64 extern FONT font_winFreeSystem14x16;
65 extern FONT font_winSystem14x16;
66 extern FONT font_winMSSansSerif11x13;
67 extern FONT font_winTerminal8x12;
68 extern FONT font_helvB10, font_helvB12, font_helvR10;
70 /* first font is default font*/
71 PFONT fonts[NUMBER_FONTS] = {
73 &font_winSystem14x16, /* FONT_SYSTEM_VAR*/
74 &font_winMSSansSerif11x13, /* FONT_GUI_VAR*/
75 &font_winTerminal8x12 /* FONT_OEM_FIXED*/
77 &font_winFreeSystem14x16, /* FONT_SYSTEM_VAR*/
78 &font_winFreeSansSerif11x13, /* FONT_GUI_VAR*/
79 &font_rom8x16 /* FONT_OEM_FIXED*/
84 BOGL_open(SCREENDEVICE *psd)
88 psd->xres = bogl_xres;
89 psd->yres = bogl_yres;
90 psd->ncolors = bogl_ncols;
94 psd->pixtype = PF_TRUECOLOR24;
95 else if(bogl_ncols == 256 && bogl_truecolor)
96 psd->pixtype = PF_TRUECOLOR332;
98 psd->pixtype = PF_PALETTE;
109 BOGL_getscreeninfo(PSCREENINFO psi)
111 psi->rows = scrdev.yres;
112 psi->cols = scrdev.xres;
113 psi->ncolors = scrdev.ncolors;
114 psi->pixtype = scrdev.pixtype;
117 psi->fonts = NUMBER_FONTS;
119 if(scrdev.yres > 480) {
121 psi->xdpcm = 33; /* assumes screen width of 24 cm*/
122 psi->ydpcm = 33; /* assumes screen height of 18 cm*/
123 } else if(scrdev.yres > 350) {
125 psi->xdpcm = 27; /* assumes screen width of 24 cm*/
126 psi->ydpcm = 27; /* assumes screen height of 18 cm*/
129 psi->xdpcm = 27; /* assumes screen width of 24 cm*/
130 psi->ydpcm = 19; /* assumes screen height of 18 cm*/
135 * Set count palette entries starting from first
138 BOGL_setpalette(int first,int count,RGBENTRY *pal)
140 bogl_set_palette(first, count, (void*)pal);
144 BOGL_drawpixel(COORD x, COORD y, PIXELVAL c)
150 BOGL_readpixel(COORD x, COORD y)
152 return bogl_readpixel(x, y);
156 BOGL_drawhline(COORD x1, COORD x2, COORD y, PIXELVAL c)
159 * bogl uses type 2 line drawing, the last point is not drawn
161 bogl_hline(x1, x2+1, y, c);
164 * Uncomment the following if driver doesn't support hline
166 bogl_pixel(x1++, y, c);
171 BOGL_drawvline(COORD x, COORD y1, COORD y2, PIXELVAL c)
174 * bogl uses type 2 line drawing, the last point is not drawn
176 bogl_vline(x, y1, y2+1, c);
179 * Uncomment the following if driver doesn't support vline
181 bogl_pixel(x, y1++, c);
186 BOGL_fillrect(COORD x1, COORD y1, COORD x2, COORD y2, PIXELVAL c)
189 * Call bogl hline (type 2) to save size
191 ++x2; /* fix bogl last point not drawn*/
193 bogl_hline(x1, x2, y1++, c);
195 * Uncomment the following if driver doesn't support fillrect
197 BOGL_drawhline(x1, x2, y1++, c);
203 * Generalized low level text draw routine, called only
204 * if no clipping is required
207 gen_drawtext(COORD x,COORD y,const UCHAR *s,int n,PIXELVAL fg,FONTID fontid)
209 COORD width; /* width of character */
210 COORD height; /* height of character */
212 IMAGEBITS bitmap[MAX_CHAR_HEIGHT];/* bitmap for character */
214 if(fontid >= NUMBER_FONTS)
218 /* x, y is bottom left corner*/
221 gen_gettextbits(*s++, bitmap, &width, &height, pf);
222 gen_drawbitmap(x, y, width, height, bitmap, fg);
228 * Generalized low level bitmap output routine, called
229 * only if no clipping is required. Only the set bits
230 * in the bitmap are drawn, in the foreground color.
233 gen_drawbitmap(COORD x, COORD y, COORD width, COORD height, IMAGEBITS *table,
238 IMAGEBITS bitvalue; /* bitmap word value */
239 int bitcount; /* number of bits left in bitmap word */
242 maxx = x + width - 1;
246 bitcount = IMAGE_BITSPERIMAGE;
249 if (IMAGE_TESTBIT(bitvalue))
250 BOGL_drawpixel(x, y, fgcolor);
251 bitvalue = IMAGE_SHIFTBIT(bitvalue);
264 * Generalized low level get font info routine. This
265 * routine works with fixed and proportional fonts.
268 gen_getfontinfo(FONTID fontid,PFONTINFO pfontinfo)
273 if(fontid >= NUMBER_FONTS)
277 pfontinfo->font = fontid;
278 pfontinfo->height = pf->height;
279 pfontinfo->maxwidth = pf->maxwidth;
280 pfontinfo->baseline = 0;
281 pfontinfo->fixed = pf->width == NULL? TRUE: FALSE;
282 for(i=0; i<256; ++i) {
283 if(pf->width == NULL)
284 pfontinfo->widths[i] = pf->maxwidth;
286 if(i<pf->firstchar || i >= pf->firstchar+pf->size)
287 pfontinfo->widths[i] = 0;
288 else pfontinfo->widths[i] = pf->width[i-pf->firstchar];
295 * Generalized low level routine to calc bounding box for text output.
296 * Handles both fixed and proportional fonts.
299 gen_gettextsize(const UCHAR *str,int cc,COORD *retwd,COORD *retht,
306 if(fontid >= NUMBER_FONTS) {
313 if(pf->width == NULL)
314 width = cc * pf->maxwidth;
318 if( (c = *str++) >= pf->firstchar &&
319 c < pf->firstchar+pf->size)
320 width += pf->width[c - pf->firstchar];
330 * Generalized low level routine to get the bitmap associated
331 * with a character. Handles fixed and proportional fonts.
334 gen_gettextbits(UCHAR ch,IMAGEBITS *retmap,COORD *retwd, COORD *retht,
341 if(fontid < NUMBER_FONTS)
344 if(!pf || ch < pf->firstchar || ch >= pf->firstchar+pf->size) {
351 /* get font bitmap depending on fixed pitch or not*/
352 bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch));
353 for(n=0; n<pf->height; ++n)
356 /* return width depending on fixed pitch or not*/
357 *retwd = pf->width? pf->width[ch]: pf->maxwidth;
362 static unsigned char palette[16+16][3] = {
363 /* Linux 16 color palette*/
370 { 0xaa,0x55,0x00 }, /* adjust to brown*/
371 //{ 0xaa,0xaa,0x00 },
382 /* 16 entry std palette*/
389 {0xbf, 0x60, 0x00}, /* adjust to brown*/
390 //{0xbf, 0xbf, 0x00},