| 292 |
ira |
1 |
/*******************************************************************************
|
|
|
2 |
* draw.c - implementation for libggi-based drawing on the GNU/Linux
|
|
|
3 |
* framebuffer device.
|
|
|
4 |
*
|
|
|
5 |
* Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)
|
| 317 |
ira |
6 |
*
|
|
|
7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
8 |
* of this software and associated documentation files (the "Software"), to
|
|
|
9 |
* deal in the Software without restriction, including without limitation the
|
|
|
10 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
11 |
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
12 |
* furnished to do so, subject to the following conditions:
|
|
|
13 |
*
|
|
|
14 |
* The above copyright notice and this permission notice shall be included in
|
|
|
15 |
* all copies or substantial portions of the Software.
|
|
|
16 |
*
|
|
|
17 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
18 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
19 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
20 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
21 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
23 |
* IN THE SOFTWARE.
|
|
|
24 |
*
|
| 292 |
ira |
25 |
******************************************************************************/
|
|
|
26 |
|
|
|
27 |
#include <ggi/ggi.h>
|
|
|
28 |
#include <stdio.h>
|
|
|
29 |
#include "draw.h"
|
|
|
30 |
|
| 312 |
ira |
31 |
#ifdef __cplusplus
|
|
|
32 |
extern "C"
|
|
|
33 |
{
|
|
|
34 |
#endif
|
|
|
35 |
|
| 292 |
ira |
36 |
/* Initialize GGI for drawing */
|
|
|
37 |
void draw_init ()
|
|
|
38 |
{
|
|
|
39 |
/* Initialize the palette */
|
| 296 |
ira |
40 |
palette[AQUA].r = 0x0000;
|
|
|
41 |
palette[AQUA].g = 0xffff;
|
|
|
42 |
palette[AQUA].b = 0xffff;
|
| 292 |
ira |
43 |
|
| 296 |
ira |
44 |
palette[BLACK].r = 0x0000;
|
|
|
45 |
palette[BLACK].g = 0x0000;
|
|
|
46 |
palette[BLACK].b = 0x0000;
|
|
|
47 |
|
|
|
48 |
palette[BLUE].r = 0x0000;
|
|
|
49 |
palette[BLUE].g = 0x0000;
|
|
|
50 |
palette[BLUE].b = 0xffff;
|
|
|
51 |
|
|
|
52 |
palette[FUCHSIA].r = 0xffff;
|
|
|
53 |
palette[FUCHSIA].g = 0x0000;
|
|
|
54 |
palette[FUCHSIA].b = 0xffff;
|
|
|
55 |
|
|
|
56 |
palette[GRAY].r = 0x8080;
|
|
|
57 |
palette[GRAY].g = 0x8080;
|
|
|
58 |
palette[GRAY].b = 0x8080;
|
|
|
59 |
|
|
|
60 |
palette[GREEN].r = 0x0000;
|
|
|
61 |
palette[GREEN].g = 0x8080;
|
|
|
62 |
palette[GREEN].b = 0x0000;
|
|
|
63 |
|
|
|
64 |
palette[LIME].r = 0x0000;
|
|
|
65 |
palette[LIME].g = 0xffff;
|
|
|
66 |
palette[LIME].b = 0x0000;
|
|
|
67 |
|
|
|
68 |
palette[MAROON].r = 0x8080;
|
|
|
69 |
palette[MAROON].g = 0x0000;
|
|
|
70 |
palette[MAROON].b = 0x0000;
|
|
|
71 |
|
|
|
72 |
palette[NAVY].r = 0x0000;
|
|
|
73 |
palette[NAVY].g = 0x0000;
|
|
|
74 |
palette[NAVY].b = 0x8080;
|
|
|
75 |
|
|
|
76 |
palette[OLIVE].r = 0x8080;
|
|
|
77 |
palette[OLIVE].g = 0x8080;
|
|
|
78 |
palette[OLIVE].b = 0x0000;
|
|
|
79 |
|
|
|
80 |
palette[PURPLE].r = 0x8080;
|
|
|
81 |
palette[PURPLE].g = 0x0000;
|
|
|
82 |
palette[PURPLE].b = 0x8080;
|
|
|
83 |
|
| 292 |
ira |
84 |
palette[RED].r = 0xffff;
|
| 296 |
ira |
85 |
palette[RED].g = 0x0000;
|
|
|
86 |
palette[RED].b = 0x0000;
|
| 292 |
ira |
87 |
|
| 296 |
ira |
88 |
palette[SILVER].r = 0xc0c0;
|
|
|
89 |
palette[SILVER].g = 0xc0c0;
|
|
|
90 |
palette[SILVER].b = 0xc0c0;
|
| 292 |
ira |
91 |
|
| 296 |
ira |
92 |
palette[TEAL].r = 0x0000;
|
|
|
93 |
palette[TEAL].g = 0x8080;
|
|
|
94 |
palette[TEAL].b = 0x8080;
|
| 292 |
ira |
95 |
|
|
|
96 |
palette[WHITE].r = 0xffff;
|
|
|
97 |
palette[WHITE].g = 0xffff;
|
|
|
98 |
palette[WHITE].b = 0xffff;
|
|
|
99 |
|
| 296 |
ira |
100 |
palette[YELLOW].r = 0xffff;
|
|
|
101 |
palette[YELLOW].g = 0xffff;
|
|
|
102 |
palette[YELLOW].b = 0x0000;
|
|
|
103 |
|
| 292 |
ira |
104 |
/* Intialize GGI itself */
|
|
|
105 |
if (ggiInit () != 0)
|
|
|
106 |
{
|
|
|
107 |
printf ("Error initialising GGI!\n");
|
|
|
108 |
exit (1);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/* Try to open the screen */
|
| 356 |
ira |
112 |
//if ((vis = ggiOpen (NULL)) == NULL)
|
|
|
113 |
//if ((vis = ggiOpen ("display-x:-noinput", NULL)) == NULL)
|
|
|
114 |
//if ((vis = ggiOpen ("display-auto:-noinput", NULL)) == NULL)
|
| 307 |
ira |
115 |
if ((vis = ggiOpen ("display-fbdev:-noinput", NULL)) == NULL)
|
| 292 |
ira |
116 |
{
|
|
|
117 |
printf ("Error opening visual!\n");
|
|
|
118 |
ggiExit ();
|
|
|
119 |
exit (1);
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
/* Try to set the screen mode */
|
|
|
123 |
if (ggiSetSimpleMode (vis, GGI_AUTO, GGI_AUTO, 0, GT_AUTO))
|
|
|
124 |
{
|
|
|
125 |
printf ("Set the GGI_DISPLAY variable to the palemu!\n");
|
|
|
126 |
exit (1);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
/* load the palette to the screen */
|
| 296 |
ira |
130 |
ggiSetPalette (vis, 0, NUM_COLORS, palette);
|
|
|
131 |
|
|
|
132 |
/* Set default foreground and background */
|
|
|
133 |
ggiSetGCForeground (vis, BLACK);
|
|
|
134 |
ggiSetGCBackground (vis, BLACK);
|
| 292 |
ira |
135 |
}
|
|
|
136 |
|
|
|
137 |
/* Close GGI when we're done drawing */
|
|
|
138 |
void draw_close ()
|
|
|
139 |
{
|
|
|
140 |
ggiClose (vis);
|
|
|
141 |
ggiExit ();
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
void draw_clearscreen ()
|
|
|
145 |
{
|
|
|
146 |
ggiSetGCForeground (vis, BLACK);
|
|
|
147 |
ggiFillscreen (vis);
|
|
|
148 |
ggiFlush (vis);
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
void draw_putpixel (int x, int y, int color)
|
|
|
152 |
{
|
|
|
153 |
ggiSetGCForeground (vis, color);
|
|
|
154 |
ggiDrawPixel (vis, x, y);
|
|
|
155 |
ggiFlush (vis);
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
void draw_box (int x, int y, int width, int height, int color)
|
|
|
159 |
{
|
|
|
160 |
ggiSetGCForeground (vis, color);
|
|
|
161 |
ggiDrawBox (vis, x, y, width, height);
|
|
|
162 |
ggiFlush (vis);
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
void draw_line (int x1, int y1, int x2, int y2, int color)
|
|
|
166 |
{
|
|
|
167 |
ggiSetGCForeground (vis, color);
|
|
|
168 |
ggiDrawLine (vis, x1, y1, x2, y2);
|
|
|
169 |
ggiFlush (vis);
|
|
|
170 |
}
|
|
|
171 |
|
| 295 |
ira |
172 |
void draw_putc (int x, int y, char c, int color)
|
|
|
173 |
{
|
|
|
174 |
ggiSetGCForeground (vis, color);
|
|
|
175 |
ggiPutc (vis, x, y, c);
|
|
|
176 |
ggiFlush (vis);
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
void draw_puts (int x, int y, const char *str, int color)
|
|
|
180 |
{
|
|
|
181 |
ggiSetGCForeground (vis, color);
|
|
|
182 |
ggiPuts (vis, x, y, str);
|
|
|
183 |
ggiFlush (vis);
|
|
|
184 |
}
|
|
|
185 |
|
| 312 |
ira |
186 |
#ifdef __cplusplus
|
|
|
187 |
}
|
|
|
188 |
#endif
|
|
|
189 |
|