Subversion Repositories programming

Rev

Rev 307 | Rev 317 | 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)
6
 ******************************************************************************/
7
 
8
#include <ggi/ggi.h>
9
#include <stdio.h>
10
#include "draw.h"
11
 
312 ira 12
#ifdef __cplusplus
13
extern "C"
14
{
15
#endif
16
 
292 ira 17
/* Initialize GGI for drawing */
18
void draw_init ()
19
{
20
    /* Initialize the palette */
296 ira 21
    palette[AQUA].r = 0x0000;
22
    palette[AQUA].g = 0xffff;
23
    palette[AQUA].b = 0xffff;
292 ira 24
 
296 ira 25
    palette[BLACK].r = 0x0000;
26
    palette[BLACK].g = 0x0000;
27
    palette[BLACK].b = 0x0000;
28
 
29
    palette[BLUE].r = 0x0000;
30
    palette[BLUE].g = 0x0000;
31
    palette[BLUE].b = 0xffff;
32
 
33
    palette[FUCHSIA].r = 0xffff;
34
    palette[FUCHSIA].g = 0x0000;
35
    palette[FUCHSIA].b = 0xffff;
36
 
37
    palette[GRAY].r = 0x8080;
38
    palette[GRAY].g = 0x8080;
39
    palette[GRAY].b = 0x8080;
40
 
41
    palette[GREEN].r = 0x0000;
42
    palette[GREEN].g = 0x8080;
43
    palette[GREEN].b = 0x0000;
44
 
45
    palette[LIME].r = 0x0000;
46
    palette[LIME].g = 0xffff;
47
    palette[LIME].b = 0x0000;
48
 
49
    palette[MAROON].r = 0x8080;
50
    palette[MAROON].g = 0x0000;
51
    palette[MAROON].b = 0x0000;
52
 
53
    palette[NAVY].r = 0x0000;
54
    palette[NAVY].g = 0x0000;
55
    palette[NAVY].b = 0x8080;
56
 
57
    palette[OLIVE].r = 0x8080;
58
    palette[OLIVE].g = 0x8080;
59
    palette[OLIVE].b = 0x0000;
60
 
61
    palette[PURPLE].r = 0x8080;
62
    palette[PURPLE].g = 0x0000;
63
    palette[PURPLE].b = 0x8080;
64
 
292 ira 65
    palette[RED].r = 0xffff;
296 ira 66
    palette[RED].g = 0x0000;
67
    palette[RED].b = 0x0000;
292 ira 68
 
296 ira 69
    palette[SILVER].r = 0xc0c0;
70
    palette[SILVER].g = 0xc0c0;
71
    palette[SILVER].b = 0xc0c0;
292 ira 72
 
296 ira 73
    palette[TEAL].r = 0x0000;
74
    palette[TEAL].g = 0x8080;
75
    palette[TEAL].b = 0x8080;
292 ira 76
 
77
    palette[WHITE].r = 0xffff;
78
    palette[WHITE].g = 0xffff;
79
    palette[WHITE].b = 0xffff;
80
 
296 ira 81
    palette[YELLOW].r = 0xffff;
82
    palette[YELLOW].g = 0xffff;
83
    palette[YELLOW].b = 0x0000;
84
 
292 ira 85
    /* Intialize GGI itself */
86
    if (ggiInit () != 0)
87
    {
88
        printf ("Error initialising GGI!\n");
89
        exit (1);
90
    }
91
 
92
    /* Try to open the screen */
307 ira 93
    /* if ((vis = ggiOpen (NULL)) == NULL) */
94
    if ((vis = ggiOpen ("display-fbdev:-noinput", NULL)) == NULL)
292 ira 95
    {
96
        printf ("Error opening visual!\n");
97
        ggiExit ();
98
        exit (1);
99
    }
100
 
101
    /* Try to set the screen mode */
102
    if (ggiSetSimpleMode (vis, GGI_AUTO, GGI_AUTO, 0, GT_AUTO))
103
    {
104
        printf ("Set the GGI_DISPLAY variable to the palemu!\n");
105
        exit (1);
106
    }
107
 
108
    /* load the palette to the screen */
296 ira 109
    ggiSetPalette (vis, 0, NUM_COLORS, palette);
110
 
111
    /* Set default foreground and background */
112
    ggiSetGCForeground (vis, BLACK);
113
    ggiSetGCBackground (vis, BLACK);
292 ira 114
}
115
 
116
/* Close GGI when we're done drawing */
117
void draw_close ()
118
{
119
    ggiClose (vis);
120
    ggiExit ();
121
}
122
 
123
void draw_clearscreen ()
124
{
125
    ggiSetGCForeground (vis, BLACK);
126
    ggiFillscreen (vis);
127
    ggiFlush (vis);
128
}
129
 
130
void draw_putpixel (int x, int y, int color)
131
{
132
    ggiSetGCForeground (vis, color);
133
    ggiDrawPixel (vis, x, y);
134
    ggiFlush (vis);
135
}
136
 
137
void draw_box (int x, int y, int width, int height, int color)
138
{
139
    ggiSetGCForeground (vis, color);
140
    ggiDrawBox (vis, x, y, width, height);
141
    ggiFlush (vis);
142
}
143
 
144
void draw_line (int x1, int y1, int x2, int y2, int color)
145
{
146
    ggiSetGCForeground (vis, color);
147
    ggiDrawLine (vis, x1, y1, x2, y2);
148
    ggiFlush (vis);
149
}
150
 
295 ira 151
void draw_putc (int x, int y, char c, int color)
152
{
153
    ggiSetGCForeground (vis, color);
154
    ggiPutc (vis, x, y, c);
155
    ggiFlush (vis);
156
}
157
 
158
void draw_puts (int x, int y, const char *str, int color)
159
{
160
    ggiSetGCForeground (vis, color);
161
    ggiPuts (vis, x, y, str);
162
    ggiFlush (vis);
163
}
164
 
312 ira 165
#ifdef __cplusplus
166
}
167
#endif
168