Subversion Repositories programming

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
290 ira 1
#include <stdio.h>
2
#include <ggi/ggi.h>
3
 
4
 
5
#define BLACK 0
6
#define RED   1
7
#define GREEN 2
8
#define BLUE  3
9
#define WHITE 4
10
 
11
 
12
static ggi_visual_t vis;
13
static ggi_color palette[5];
14
 
15
 
16
/* Initialize the palette's colors */
17
void init_palette ()
18
{
19
    palette[0].r = 0;
20
    palette[0].g = 0;
21
    palette[0].b = 0;
22
 
23
    palette[1].r = 0xffff;
24
    palette[1].g = 0;
25
    palette[1].b = 0;
26
 
27
    palette[2].r = 0;
28
    palette[2].g = 0xffff;
29
    palette[2].b = 0;
30
 
31
    palette[3].r = 0;
32
    palette[3].g = 0;
33
    palette[3].b = 0xffff;
34
 
35
    palette[4].r = 0xffff;
36
    palette[4].g = 0xffff;
37
    palette[4].b = 0xffff;
38
}
39
 
40
/* Initialize GGI for drawing */
41
void draw_init ()
42
{
43
 
44
    init_palette ();
45
 
46
    if (ggiInit () != 0)
47
    {
48
        printf ("Error initialising GGI!\n");
49
        exit (1);
50
    }
51
 
52
    if ((vis = ggiOpen (NULL)) == NULL)
53
    {
54
        printf ("Error opening visual!\n");
55
        ggiExit ();
56
        exit (1);
57
    }
58
 
59
    if (ggiSetSimpleMode (vis, GGI_AUTO, GGI_AUTO, 0, GT_AUTO))
60
    {
61
        printf ("Set the GGI_DISPLAY variable to the palemu!\n");
62
        exit (1);
63
    }
64
 
65
    ggiSetPalette (vis, 0, 5, palette);
66
}
67
 
68
/* Close GGI when we're done drawing */
69
void draw_close ()
70
{
71
    ggiClose (vis);
72
    ggiExit ();
73
}
74
 
75
void draw_clrscreen ()
76
{
77
    ggiSetGCForeground (vis, BLACK);
78
    ggiFillscreen (vis);
79
}
80
 
81
void draw_putpixel (int x, int y, int color)
82
{
83
    ggiSetGCForeground (vis, color);
84
    ggiDrawPixel (vis, x, y);
85
}
86
 
87
void draw_flush ()
88
{
89
    ggiFlush (vis);
90
}
91
 
92
void draw_box (int x, int y, int width, int height, int color)
93
{
94
    ggiSetGCForeground (vis, color);
95
    ggiDrawBox (vis, x, y, width, height);
96
}
97
 
98
void draw_line (int x1, int y1, int x2, int y2, int color)
99
{
100
    ggiSetGCForeground (vis, color);
101
    ggiDrawLine (vis, x1, y1, x2, y2);
102
}
103
 
104
int main ()
105
{
106
    /* Initialize */
107
    draw_init ();
108
 
109
    /* Use */
110
    draw_clrscreen ();
111
 
112
    draw_putpixel (20, 20, RED);
113
    draw_box (50, 50, 100, 100, GREEN);
114
    draw_line (30, 20, 300, 180, BLUE);
115
    draw_box (100, 80, 100, 100, WHITE);
116
 
117
    draw_flush ();
118
 
119
    /* Sleep until the keyboard is pressed */
120
    ggiGetc (vis);
121
 
122
    draw_clrscreen ();
123
 
124
    draw_putpixel (40, 40, RED);
125
    draw_putpixel (20, 20, GREEN);
126
    draw_putpixel (30, 30, BLUE);
127
 
128
    draw_flush ();
129
 
130
    ggiGetc (vis);
131
 
132
    /* Quit */
133
    draw_close ();
134
 
135
    return (0);
136
}