Subversion Repositories programming

Rev

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

Rev 290 Rev 291
Line 9... Line 9...
9
#define WHITE 4
9
#define WHITE 4
10
 
10
 
11
 
11
 
12
static ggi_visual_t vis;
12
static ggi_visual_t vis;
13
static ggi_color palette[5];
13
static ggi_color palette[5];
14
 
-
 
-
 
14
static ggi_mode tm; //FIXME
15
 
15
 
16
/* Initialize the palette's colors */
16
/* Initialize the palette's colors */
17
void init_palette ()
17
void init_palette ()
18
{
18
{
19
    palette[0].r = 0;
19
    palette[0].r = 0;
Line 63... Line 63...
63
    }
63
    }
64
 
64
 
65
    ggiSetPalette (vis, 0, 5, palette);
65
    ggiSetPalette (vis, 0, 5, palette);
66
}
66
}
67
 
67
 
-
 
68
void draw_flush ()
-
 
69
{
-
 
70
    ggiFlush (vis);
-
 
71
}
-
 
72
 
68
/* Close GGI when we're done drawing */
73
/* Close GGI when we're done drawing */
69
void draw_close ()
74
void draw_close ()
70
{
75
{
71
    ggiClose (vis);
76
    ggiClose (vis);
72
    ggiExit ();
77
    ggiExit ();
Line 74... Line 79...
74
 
79
 
75
void draw_clrscreen ()
80
void draw_clrscreen ()
76
{
81
{
77
    ggiSetGCForeground (vis, BLACK);
82
    ggiSetGCForeground (vis, BLACK);
78
    ggiFillscreen (vis);
83
    ggiFillscreen (vis);
-
 
84
    draw_flush ();
79
}
85
}
80
 
86
 
81
void draw_putpixel (int x, int y, int color)
87
void draw_putpixel (int x, int y, int color)
82
{
88
{
83
    ggiSetGCForeground (vis, color);
89
    ggiSetGCForeground (vis, color);
84
    ggiDrawPixel (vis, x, y);
90
    ggiDrawPixel (vis, x, y);
85
}
-
 
86
 
-
 
87
void draw_flush ()
91
    draw_flush ();
88
{
-
 
89
    ggiFlush (vis);
-
 
90
}
92
}
91
 
93
 
92
void draw_box (int x, int y, int width, int height, int color)
94
void draw_box (int x, int y, int width, int height, int color)
93
{
95
{
94
    ggiSetGCForeground (vis, color);
96
    ggiSetGCForeground (vis, color);
95
    ggiDrawBox (vis, x, y, width, height);
97
    ggiDrawBox (vis, x, y, width, height);
-
 
98
    draw_flush ();
96
}
99
}
97
 
100
 
98
void draw_line (int x1, int y1, int x2, int y2, int color)
101
void draw_line (int x1, int y1, int x2, int y2, int color)
99
{
102
{
100
    ggiSetGCForeground (vis, color);
103
    ggiSetGCForeground (vis, color);
101
    ggiDrawLine (vis, x1, y1, x2, y2);
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
 
-
 
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);
102
}
117
}
103
 
118
 
104
int main ()
119
int main ()
105
{
120
{
-
 
121
    int i;
-
 
122
 
106
    /* Initialize */
123
    /* Initialize */
107
    draw_init ();
124
    draw_init ();
108
 
125
 
109
    /* Use */
126
    /* Use */
110
    draw_clrscreen ();
127
    draw_clrscreen ();
111
 
-
 
112
    draw_putpixel (20, 20, RED);
128
    draw_putpixel (20, 20, RED);
113
    draw_box (50, 50, 100, 100, GREEN);
129
    draw_box (50, 50, 100, 100, GREEN);
114
    draw_line (30, 20, 300, 180, BLUE);
130
    draw_line (30, 20, 300, 180, BLUE);
115
    draw_box (100, 80, 100, 100, WHITE);
131
    draw_box (100, 80, 100, 100, WHITE);
116
 
132
 
117
    draw_flush ();
-
 
118
 
-
 
119
    /* Sleep until the keyboard is pressed */
133
    /* Sleep until the keyboard is pressed */
120
    ggiGetc (vis);
134
    ggiGetc (vis);
121
 
135
 
122
    draw_clrscreen ();
136
    draw_clrscreen ();
123
 
-
 
124
    draw_putpixel (40, 40, RED);
137
    draw_putpixel (40, 40, RED);
125
    draw_putpixel (20, 20, GREEN);
138
    draw_putpixel (20, 20, GREEN);
126
    draw_putpixel (30, 30, BLUE);
139
    draw_putpixel (30, 30, BLUE);
127
    
140
    
128
    draw_flush ();
-
 
129
 
-
 
130
    ggiGetc (vis);
141
    ggiGetc (vis);
131
 
142
 
-
 
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
 
132
    /* Quit */
154
    /* Quit */
133
    draw_close ();
155
    draw_close ();
134
 
156
 
-
 
157
    draw_printmode ();
-
 
158
 
135
    return (0);
159
    return (0);
136
}
160
}