Subversion Repositories programming

Rev

Rev 312 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 */
307 ira 112
    /* if ((vis = ggiOpen (NULL)) == NULL) */
113
    if ((vis = ggiOpen ("display-fbdev:-noinput", NULL)) == NULL)
292 ira 114
    {
115
        printf ("Error opening visual!\n");
116
        ggiExit ();
117
        exit (1);
118
    }
119
 
120
    /* Try to set the screen mode */
121
    if (ggiSetSimpleMode (vis, GGI_AUTO, GGI_AUTO, 0, GT_AUTO))
122
    {
123
        printf ("Set the GGI_DISPLAY variable to the palemu!\n");
124
        exit (1);
125
    }
126
 
127
    /* load the palette to the screen */
296 ira 128
    ggiSetPalette (vis, 0, NUM_COLORS, palette);
129
 
130
    /* Set default foreground and background */
131
    ggiSetGCForeground (vis, BLACK);
132
    ggiSetGCBackground (vis, BLACK);
292 ira 133
}
134
 
135
/* Close GGI when we're done drawing */
136
void draw_close ()
137
{
138
    ggiClose (vis);
139
    ggiExit ();
140
}
141
 
142
void draw_clearscreen ()
143
{
144
    ggiSetGCForeground (vis, BLACK);
145
    ggiFillscreen (vis);
146
    ggiFlush (vis);
147
}
148
 
149
void draw_putpixel (int x, int y, int color)
150
{
151
    ggiSetGCForeground (vis, color);
152
    ggiDrawPixel (vis, x, y);
153
    ggiFlush (vis);
154
}
155
 
156
void draw_box (int x, int y, int width, int height, int color)
157
{
158
    ggiSetGCForeground (vis, color);
159
    ggiDrawBox (vis, x, y, width, height);
160
    ggiFlush (vis);
161
}
162
 
163
void draw_line (int x1, int y1, int x2, int y2, int color)
164
{
165
    ggiSetGCForeground (vis, color);
166
    ggiDrawLine (vis, x1, y1, x2, y2);
167
    ggiFlush (vis);
168
}
169
 
295 ira 170
void draw_putc (int x, int y, char c, int color)
171
{
172
    ggiSetGCForeground (vis, color);
173
    ggiPutc (vis, x, y, c);
174
    ggiFlush (vis);
175
}
176
 
177
void draw_puts (int x, int y, const char *str, int color)
178
{
179
    ggiSetGCForeground (vis, color);
180
    ggiPuts (vis, x, y, str);
181
    ggiFlush (vis);
182
}
183
 
312 ira 184
#ifdef __cplusplus
185
}
186
#endif
187