Subversion Repositories programming

Rev

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