Subversion Repositories programming

Rev

Go to most recent revision | Details | 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 */
88
    if ((vis = ggiOpen (NULL)) == NULL)
89
    {
90
        printf ("Error opening visual!\n");
91
        ggiExit ();
92
        exit (1);
93
    }
94
 
95
    /* Try to set the screen mode */
96
    if (ggiSetSimpleMode (vis, GGI_AUTO, GGI_AUTO, 0, GT_AUTO))
97
    {
98
        printf ("Set the GGI_DISPLAY variable to the palemu!\n");
99
        exit (1);
100
    }
101
 
102
    /* load the palette to the screen */
296 ira 103
    ggiSetPalette (vis, 0, NUM_COLORS, palette);
104
 
105
    /* Set default foreground and background */
106
    ggiSetGCForeground (vis, BLACK);
107
    ggiSetGCBackground (vis, BLACK);
292 ira 108
}
109
 
110
/* Close GGI when we're done drawing */
111
void draw_close ()
112
{
113
    ggiClose (vis);
114
    ggiExit ();
115
}
116
 
117
void draw_clearscreen ()
118
{
119
    ggiSetGCForeground (vis, BLACK);
120
    ggiFillscreen (vis);
121
    ggiFlush (vis);
122
}
123
 
124
void draw_putpixel (int x, int y, int color)
125
{
126
    ggiSetGCForeground (vis, color);
127
    ggiDrawPixel (vis, x, y);
128
    ggiFlush (vis);
129
}
130
 
131
void draw_box (int x, int y, int width, int height, int color)
132
{
133
    ggiSetGCForeground (vis, color);
134
    ggiDrawBox (vis, x, y, width, height);
135
    ggiFlush (vis);
136
}
137
 
138
void draw_line (int x1, int y1, int x2, int y2, int color)
139
{
140
    ggiSetGCForeground (vis, color);
141
    ggiDrawLine (vis, x1, y1, x2, y2);
142
    ggiFlush (vis);
143
}
144
 
295 ira 145
void draw_putc (int x, int y, char c, int color)
146
{
147
    ggiSetGCForeground (vis, color);
148
    ggiPutc (vis, x, y, c);
149
    ggiFlush (vis);
150
}
151
 
152
void draw_puts (int x, int y, const char *str, int color)
153
{
154
    ggiSetGCForeground (vis, color);
155
    ggiPuts (vis, x, y, str);
156
    ggiFlush (vis);
157
}
158