-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgr.c
240 lines (203 loc) · 3.44 KB
/
gr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include <Buzz_inc.h>
#include <externs.h>
#include <assert.h>
#ifdef DEAD_CODE
/** Unknown function
* \deprecated This function is probably depricated
*/
int
grInitMouse (void)
{
return gxSUCCESS;
}
#endif
#ifdef DEAD_CODE
/** Unknown function
* \deprecated This function is probably depricated
*/
void
grSetMousePos (int x, int y)
{
}
#endif
int
grGetMouseButtons (void)
{
int val;
val = av_mouse_pressed_latched || av_mouse_pressed_cur;
av_mouse_pressed_latched = 0;
return (val);
}
int
grGetMousePressedPos (int *xp, int *yp)
{
*xp = av_mouse_pressed_x / 2;
*yp = av_mouse_pressed_y / 2;
return (0);
}
int
grGetMouseCurPos (int *xp, int *yp)
{
*xp = av_mouse_cur_x / 2;
*yp = av_mouse_cur_y / 2;
return (0);
}
static int gr_fg_color; /**< current foreground color to use */
static int gr_bg_color; /**< current background color to use */
void
gr_set_color_map (unsigned char *map)
{
memcpy (pal, map, 256 * 3);
}
void
gr_sync (void)
{
av_sync ();
}
void
gr_maybe_sync (void)
{
if (screen_dirty)
av_sync ();
}
/** set foreground color
*
* \param color the color code to use
*
* \li 6 = red
* \li 1 = white
*/
void
grSetColor (int color)
{
gr_fg_color = color;
}
/** set background color
*
* \param color the color code to use
*/
void
grSetBkColor (int color)
{
gr_bg_color = color;
}
void
grClearArea (int x1, int y1, int x2, int y2)
{
int y, t;
SDL_Rect r;
assert(0 <= x1 && x1 < MAX_X);
assert(0 <= x2 && x2 < MAX_X);
assert(0 <= y1 && y1 < MAX_Y);
assert(0 <= y2 && y2 < MAX_Y);
if (x1 > x2) { t = x1; x1 = x2; x2 = t; }
if (y1 > y2) { t = y1; y1 = y2; y2 = t; }
for (y = y1; y <= y2; ++y) {
memset(&screen[y * MAX_X + x1], gr_bg_color, x2-x1+1);
}
r.x = x1;
r.y = y1;
r.h = y2-y1+1;
r.w = x2-x1+1;
av_need_update(&r);
}
static int gr_cur_x, gr_cur_y;
void
grMoveTo (int x, int y)
{
gr_cur_x = x;
gr_cur_y = y;
}
void
grPutPixel (int x, int y, int color)
{
screen[y * MAX_X + x] = color;
}
//#define abs(a) (((a) >= 0) ? (a) : (0))
#define swap(a,b) (t = a, a = b, b = t)
void
grLineTo (int x_arg, int y_arg)
{
int deltax, deltay;
int error;
int ystep;
int x, y;
int x0, y0, x1, y1;
int steep;
int t;
x0 = gr_cur_x;
y0 = gr_cur_y;
x1 = x_arg;
y1 = y_arg;
steep = abs(y1 - y0) > abs(x1 - x0);
if (steep) {
swap(x0, y0);
swap(x1, y1);
}
if (x0 > x1) {
swap(x0, x1);
swap(y0, y1);
}
deltax = x1 - x0;
deltay = abs (y1 - y0);
error = 0;
y = y0;
if (y0 < y1) {
ystep = 1;
} else {
ystep = -1;
}
for (x = x0; x <= x1; x++) {
if (steep) {
grPutPixel (y, x, gr_fg_color);
} else {
grPutPixel (x, y, gr_fg_color);
}
error = error + deltay;
if (2 * error >= deltax) {
y = y + ystep;
error = error - deltax;
}
}
gr_cur_x = x_arg;
gr_cur_y = y_arg;
}
void
grLineRel (int dx, int dy)
{
grLineTo (gr_cur_x + dx, gr_cur_y + dy);
}
void
grMoveRel (int dx, int dy)
{
grMoveTo (gr_cur_x + dx, gr_cur_y + dy);
}
void
grDrawRect (int x1, int y1, int x2, int y2, int mode)
{
SDL_Rect r;
int t;
assert (mode == grOUTLINE);
if (x1 > x2) { t = x1; x1 = x2; x2 = t;}
if (y1 > y2) { t = y1; y1 = y2; y2 = t;}
grMoveTo (x1, y1);
grLineTo (x2, y1);
grLineTo (x2, y2);
grLineTo (x1, y2);
grLineTo (x1, y1);
r.x = x1; r.y = y1;
r.w = x2-x1+1; r.h = y2-y1+1;
}
void
grDrawLine (int x1, int y1, int x2, int y2)
{
grMoveTo (x1, y1);
grLineTo (x2, y2);
}
int
grGetPixel (int x, int y)
{
assert(x >= 0 && x < MAX_X);
assert(y >= 0 && y < MAX_Y);
return screen[y * MAX_X + x];
}