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];
291 ira 14
static ggi_mode tm; //FIXME
290 ira 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
 
291 ira 68
void draw_flush ()
69
{
70
    ggiFlush (vis);
71
}
72
 
290 ira 73
/* Close GGI when we're done drawing */
74
void draw_close ()
75
{
76
    ggiClose (vis);
77
    ggiExit ();
78
}
79
 
80
void draw_clrscreen ()
81
{
82
    ggiSetGCForeground (vis, BLACK);
83
    ggiFillscreen (vis);
291 ira 84
    draw_flush ();
290 ira 85
}
86
 
87
void draw_putpixel (int x, int y, int color)
88
{
89
    ggiSetGCForeground (vis, color);
90
    ggiDrawPixel (vis, x, y);
291 ira 91
    draw_flush ();
290 ira 92
}
93
 
94
void draw_box (int x, int y, int width, int height, int color)
95
{
96
    ggiSetGCForeground (vis, color);
97
    ggiDrawBox (vis, x, y, width, height);
291 ira 98
    draw_flush ();
290 ira 99
}
100
 
101
void draw_line (int x1, int y1, int x2, int y2, int color)
102
{
103
    ggiSetGCForeground (vis, color);
104
    ggiDrawLine (vis, x1, y1, x2, y2);
291 ira 105
    draw_flush ();
290 ira 106
}
107
 
291 ira 108
void draw_printmode ()
109
{
110
    fprintf (stderr, "virt.x: %d\n", tm.virt.x);
111
    fprintf (stderr, "virt.y: %d\n", tm.virt.y);
112
 
113
    fprintf (stderr, "size.x: %d\n", tm.size.x);
114
    fprintf (stderr, "size.y: %d\n", tm.size.y);
115
 
116
    fprintf (stderr, "dpp:  %d\n", tm.dpp);
117
}
118
 
290 ira 119
int main ()
120
{
291 ira 121
    int i;
122
 
290 ira 123
    /* Initialize */
124
    draw_init ();
125
 
126
    /* Use */
127
    draw_clrscreen ();
128
    draw_putpixel (20, 20, RED);
129
    draw_box (50, 50, 100, 100, GREEN);
130
    draw_line (30, 20, 300, 180, BLUE);
131
    draw_box (100, 80, 100, 100, WHITE);
132
 
133
    /* Sleep until the keyboard is pressed */
134
    ggiGetc (vis);
135
 
136
    draw_clrscreen ();
137
    draw_putpixel (40, 40, RED);
138
    draw_putpixel (20, 20, GREEN);
139
    draw_putpixel (30, 30, BLUE);
140
 
141
    ggiGetc (vis);
142
 
291 ira 143
    /* Slow draw */
144
    draw_clrscreen ();
145
 
146
    for (i=0; i<800; i++)
147
    {
148
        draw_putpixel (i, i, RED);
149
        usleep (10000);
150
    }
151
 
152
    ggiGetMode (vis, &tm);
153
 
290 ira 154
    /* Quit */
155
    draw_close ();
156
 
291 ira 157
    draw_printmode ();
158
 
290 ira 159
    return (0);
160
}