Subversion Repositories programming

Rev

Rev 291 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 291 Rev 292
Line 1... Line -...
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
static ggi_mode tm; //FIXME
-
 
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");
1
/*******************************************************************************
62
        exit (1);
-
 
63
    }
-
 
64
 
-
 
65
    ggiSetPalette (vis, 0, 5, palette);
-
 
66
}
-
 
67
 
-
 
68
void draw_flush ()
-
 
69
{
-
 
70
    ggiFlush (vis);
-
 
71
}
-
 
72
 
-
 
73
/* Close GGI when we're done drawing */
2
 * ggitest.c - a simple test of the draw library
74
void draw_close ()
-
 
75
{
-
 
76
    ggiClose (vis);
-
 
77
    ggiExit ();
-
 
78
}
-
 
79
 
-
 
80
void draw_clrscreen ()
-
 
81
{
-
 
82
    ggiSetGCForeground (vis, BLACK);
-
 
83
    ggiFillscreen (vis);
-
 
84
    draw_flush ();
-
 
85
}
-
 
86
 
-
 
87
void draw_putpixel (int x, int y, int color)
-
 
88
{
-
 
89
    ggiSetGCForeground (vis, color);
-
 
90
    ggiDrawPixel (vis, x, y);
-
 
91
    draw_flush ();
-
 
92
}
3
 *
93
 
-
 
94
void draw_box (int x, int y, int width, int height, int color)
4
 * Copyright (c) 2006, Ira W. Snyder (devel@irasnyder.com)
95
{
-
 
96
    ggiSetGCForeground (vis, color);
-
 
97
    ggiDrawBox (vis, x, y, width, height);
-
 
98
    draw_flush ();
-
 
99
}
-
 
100
 
-
 
101
void draw_line (int x1, int y1, int x2, int y2, int color)
5
 ******************************************************************************/
102
{
-
 
103
    ggiSetGCForeground (vis, color);
-
 
104
    ggiDrawLine (vis, x1, y1, x2, y2);
-
 
105
    draw_flush ();
-
 
106
}
-
 
107
 
-
 
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
 
6
 
113
    fprintf (stderr, "size.x: %d\n", tm.size.x);
-
 
114
    fprintf (stderr, "size.y: %d\n", tm.size.y);
7
#include <stdio.h>
115
 
-
 
116
    fprintf (stderr, "dpp:  %d\n", tm.dpp);
8
#include "draw.h"
117
}
-
 
118
 
9
 
119
int main ()
10
int main ()
120
{
11
{
121
    int i;
12
    int i;
122
 
13
 
123
    /* Initialize */
14
    /* Initialize */
124
    draw_init ();
15
    draw_init ();
125
 
16
 
126
    /* Use */
17
    /* Use */
127
    draw_clrscreen ();
18
    draw_clearscreen ();
128
    draw_putpixel (20, 20, RED);
19
    draw_putpixel (20, 20, RED);
129
    draw_box (50, 50, 100, 100, GREEN);
20
    draw_box (50, 50, 100, 100, GREEN);
130
    draw_line (30, 20, 300, 180, BLUE);
21
    draw_line (30, 20, 300, 180, BLUE);
131
    draw_box (100, 80, 100, 100, WHITE);
22
    draw_box (100, 80, 100, 100, WHITE);
132
 
23
 
133
    /* Sleep until the keyboard is pressed */
-
 
134
    ggiGetc (vis);
24
    sleep (5);
135
 
25
 
136
    draw_clrscreen ();
26
    draw_clearscreen ();
137
    draw_putpixel (40, 40, RED);
27
    draw_putpixel (40, 40, RED);
138
    draw_putpixel (20, 20, GREEN);
28
    draw_putpixel (20, 20, GREEN);
139
    draw_putpixel (30, 30, BLUE);
29
    draw_putpixel (30, 30, BLUE);
140
    
30
    
141
    ggiGetc (vis);
31
    sleep (5);
142
 
32
 
143
    /* Slow draw */
33
    /* Slow draw */
144
    draw_clrscreen ();
34
    draw_clearscreen ();
145
 
35
 
146
    for (i=0; i<800; i++)
36
    for (i=0; i<800; i++)
147
    {
37
    {
148
        draw_putpixel (i, i, RED);
38
        draw_putpixel (i, i, RED);
149
        usleep (10000);
39
        usleep (10000);
150
    }
40
    }
151
 
41
 
152
    ggiGetMode (vis, &tm);
-
 
153
 
-
 
154
    /* Quit */
42
    /* Quit */
155
    draw_close ();
43
    draw_close ();
156
 
44
 
157
    draw_printmode ();
-
 
158
 
-
 
159
    return (0);
45
    return (0);
160
}
46
}
-
 
47