[go: up one dir, main page]

Menu

[r102]: / trunk / aase.c  Maximize  Restore  History

Download this file

449 lines (317 with data), 9.1 kB

  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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
/* aase.c
*
* This file is part of the Allegro GUI Un-uglification Project.
* It emulates the look of the allegro-sprite-editor widget set.
*
* David A. Capello <dacap@users.sourceforge.net>
* http://ase.sourceforge.net
*/
#include <allegro.h>
#include "aase.h"
#include "agupitrn.h"
int aase_fg_color;
int aase_mg_color;
int aase_bg_color;
static void ase_rectedge(BITMAP *bmp, int x1, int y1, int x2, int y2, int fg, int bg);
static void ase_rectdotted(BITMAP *bmp, int x1, int y1, int x2, int y2, int fg, int bg);
static void ase_rectgouraud(BITMAP *bmp, int x1, int y1, int x2, int y2, int top, int bottom);
static void ase_rectbox(BITMAP *bmp, int x1, int y1, int x2, int y2, int flags);
void aase_init(void)
{
aase_fg_color = makecol(0, 0, 0);
aase_bg_color = makecol(255, 255, 255);
aase_mg_color = makecol(128, 128, 128);
}
void aase_shutdown(void)
{
}
static void ase_rectedge(BITMAP *bmp, int x1, int y1, int x2, int y2, int fg, int bg)
{
hline(bmp, x1, y1, x2 - 1, fg);
vline(bmp, x1, y1 + 1, y2 - 1, fg);
hline(bmp, x1, y2, x2, bg);
vline(bmp, x2, y1, y2 - 1, bg);
}
static void ase_rectdotted(BITMAP *bmp, int x1, int y1, int x2, int y2, int fg, int bg)
{
int x = ((x1+y1) & 1) ? 1 : 0;
int c;
/* two loops to avoid bank switches */
for (c=x1; c<=x2; c++)
putpixel(bmp, c, y1, (((c+y1) & 1) == x) ? fg : bg);
for (c=x1; c<=x2; c++)
putpixel(bmp, c, y2, (((c+y2) & 1) == x) ? fg : bg);
for (c=y1+1; c<y2; c++) {
putpixel(bmp, x1, c, (((c+x1) & 1) == x) ? fg : bg);
putpixel(bmp, x2, c, (((c+x2) & 1) == x) ? fg : bg);
}
}
static void ase_rectgouraud(BITMAP *bmp, int x1, int y1, int x2, int y2, int top, int bottom)
{
int gray, y;
for (y=y1; y<=y2; y++) {
gray = top + (bottom - top) * (y - y1) / (y2 - y1);
hline(bmp, x1, y, x2, makecol(gray, gray, gray));
}
}
static void ase_rectbox(BITMAP *bmp, int x1, int y1, int x2, int y2, int flags)
{
int bg, fg, top, bottom, aux;
if (flags & D_DISABLED) {
bg = makecol(192, 192, 192);
fg = makecol(128, 128, 128);
top = 255;
bottom = 128;
}
else {
bg = makecol(255, 255, 255);
fg = makecol(0, 0, 0);
top = 255;
bottom = (flags & D_GOTFOCUS)? 224: 194;
}
if (flags & D_SELECTED) {
aux = top;
top = bottom;
bottom = aux;
}
rect(bmp, x1, y1, x2, y2, fg);
ase_rectedge(bmp, x1+1, y1+1, x2-1, y2-1,
(flags & D_SELECTED)? makecol(128, 128, 128): makecol(255, 255, 255),
(flags & D_SELECTED)? makecol(255, 255, 255): makecol(128, 128, 128));
ase_rectgouraud(bmp, x1+2, y1+2, x2-2, y2-2, top, bottom);
if (flags & D_GOTFOCUS) {
if (flags & D_SELECTED)
ase_rectdotted(bmp, x1+3, y1+3, x2-2, y2-2, fg, bg);
else
ase_rectdotted(bmp, x1+2, y1+2, x2-3, y2-3, fg, bg);
}
}
int d_aase_box_proc(int msg, DIALOG *d, int c)
{
(void)c;
if (msg == MSG_DRAW)
ase_rectbox(gui_get_screen(), d->x, d->y, d->x+d->w-1, d->y+d->h-1, d->flags);
return D_O_K;
}
int d_aase_shadow_box_proc(int msg, DIALOG *d, int c)
{
return d_aase_box_proc(msg, d, c);
}
int d_aase_button_proc(int msg, DIALOG *d, int c)
{
if (msg == MSG_DRAW) {
ase_rectbox(gui_get_screen(), d->x, d->y, d->x+d->w-1, d->y+d->h-1, d->flags);
if (d->dp) {
gui_textout_ex(gui_get_screen(), (char *)d->dp,
((d->flags & D_SELECTED)? 1: 0) + d->x+d->w/2,
((d->flags & D_SELECTED)? 1: 0) + d->y+d->h/2-text_height(font)/2,
((d->flags & D_DISABLED)? makecol(128, 128, 128): makecol(0, 0, 0)), -1,
TRUE);
}
return D_O_K;
}
return d_button_proc(msg, d, c);
}
int d_aase_push_proc(int msg, DIALOG *d, int c)
{
int ret = D_O_K;
d->flags |= D_EXIT;
ret |= d_aase_button_proc(msg, d, c);
if (ret & D_CLOSE) {
ret &= ~D_CLOSE;
scare_mouse_area(d->x, d->y, d->x + d->w, d->y + d->h);
object_message(d, MSG_DRAW, 0);
unscare_mouse();
if (d->dp3)
ret |= ((int (*)(DIALOG *))d->dp3)(d);
}
return ret;
}
int d_aase_check_proc(int msg, DIALOG *d, int c)
{
if (msg == MSG_DRAW) {
int y = d->y+d->h/2;
int size = 12;
ase_rectbox(gui_get_screen(), d->x, y-size/2, d->x+size-1, y-size/2+size-1, d->flags);
gui_textout_ex(gui_get_screen(), (char *)d->dp,
d->x+size+4, y-text_height(font)/2,
((d->flags & D_DISABLED)? makecol(128, 128, 128): makecol(0, 0, 0)), -1,
FALSE);
return D_O_K;
}
return d_button_proc(msg, d, c);
}
int d_aase_radio_proc(int msg, DIALOG *d, int c)
{
if (msg == MSG_DRAW) {
int y = d->y+d->h/2;
int size = 12;
ase_rectbox(gui_get_screen(), d->x, y-size/2, d->x+size-1, y-size/2+size-1, d->flags);
gui_textout_ex(gui_get_screen(), (char *)d->dp,
d->x+size+4, y-text_height(font)/2,
((d->flags & D_DISABLED)? makecol(128, 128, 128): makecol(0, 0, 0)), -1,
FALSE);
return D_O_K;
}
return d_radio_proc(msg, d, c);
}
int d_aase_icon_proc(int msg, DIALOG *d, int c)
{
return d_icon_proc(msg, d, c);
}
int d_aase_edit_proc(int msg, DIALOG *d, int c)
{
int ret;
if (msg == MSG_START) {
/* this is mainly for `file_select', because the size that
it put to the `gui_edit_proc' is very small */
d->h = MAX(d->h, 3 + text_height(font) + 3);
}
else if (msg == MSG_DRAW) {
int f, l, p, w, x, fg, b, scroll;
char buf[16];
char *s;
agup_edit_adjust_position (d);
if (!(d->flags & D_INTERNAL))
d->w -= 6;
s = (char *)d->dp;
l = ustrlen(s);
if (d->d2 > l)
d->d2 = l;
/* calculate maximal number of displayable characters */
if (d->d2 == l) {
usetc(buf+usetc(buf, ' '), 0);
x = text_length(font, buf);
}
else
x = 0;
b = 0;
for (p=d->d2; p>=0; p--) {
usetc(buf+usetc(buf, ugetat(s, p)), 0);
x += text_length(font, buf);
b++;
if (x > d->w)
break;
}
if (x <= d->w) {
b = l;
scroll = FALSE;
}
else {
b--;
scroll = TRUE;
}
d->w += 6;
ase_rectedge(gui_get_screen(), d->x, d->y, d->x+d->w-1, d->y+d->h-1,
makecol(0, 0, 0),
makecol(255, 255, 255));
ase_rectedge(gui_get_screen(), d->x+1, d->y+1, d->x+d->w-2, d->y+d->h-2,
makecol(128, 128, 128),
makecol(192, 192, 192));
ase_rectgouraud(gui_get_screen(), d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,
(d->flags & D_DISABLED)? 128: 224, 255);
fg = (d->flags & D_DISABLED) ? aase_mg_color : d->fg;
x = 3;
if (scroll) {
p = d->d2-b+1;
b = d->d2;
}
else
p = 0;
for (; p<=b; p++) {
f = ugetat(s, p);
usetc(buf+usetc(buf, (f) ? f : ' '), 0);
w = text_length(font, buf);
if (x+w > d->w-2)
break;
f = ((p == d->d2) && (d->flags & D_GOTFOCUS));
textout_ex(gui_get_screen(), font, buf, d->x+x, d->y+d->h/2-text_height(font)/2,
(f) ? d->bg : fg, (f) ? fg : -1);
x += w;
}
if (d->flags & D_INTERNAL)
d->w -= 6;
agup_edit_restore_position (d);
return D_O_K;
}
d->w -= 6;
d->flags |= D_INTERNAL;
ret = d_agup_adjusted_edit_proc(msg, d, c);
d->flags &= ~D_INTERNAL;
d->w += 6;
return ret;
}
int d_aase_list_proc(int msg, DIALOG *d, int c)
{
return d_list_proc(msg, d, c);
}
int d_aase_text_list_proc(int msg, DIALOG *d, int c)
{
return d_text_list_proc(msg, d, c);
}
int d_aase_textbox_proc(int msg, DIALOG *d, int c)
{
return d_textbox_proc(msg, d, c);
}
int d_aase_slider_proc(int msg, DIALOG *d, int c)
{
return d_slider_proc(msg, d, c);
}
int d_aase_menu_proc(int msg, DIALOG *d, int c)
{
return d_menu_proc(msg, d, c);
}
int d_aase_window_proc(int msg, DIALOG *d, int c)
{
(void)c;
if (msg == MSG_DRAW) {
BITMAP *bmp = gui_get_screen();
ase_rectbox(bmp, d->x, d->y, d->x+d->w-1, d->y+d->h-1, d->flags);
if (d->dp) {
int cl = bmp->cl, ct = bmp->ct, cr = bmp->cr, cb = bmp->cb;
set_clip_rect(bmp, d->x, d->y, d->x+d->w-1, d->y+d->h-1);
textout_centre_ex(bmp, font, (char *)d->dp, d->x+d->w/2, d->y+4,
makecol(0, 0, 0), -1);
set_clip_rect(bmp, cl, ct, cr, cb);
}
}
return D_O_K;
}
int
d_aase_clear_proc (int msg, DIALOG *d, int c)
{
if (msg == MSG_DRAW)
{
clear_to_color (gui_get_screen(), aase_bg_color);
return D_O_K;
}
return d_clear_proc (msg, d, c);
}
static struct AGUP_THEME the_theme =
{
"ASE",
&aase_fg_color,
&aase_bg_color,
&aase_mg_color,
aase_init,
aase_shutdown,
d_aase_box_proc,
d_aase_shadow_box_proc,
d_aase_button_proc,
d_aase_push_proc,
d_aase_check_proc,
d_aase_radio_proc,
d_aase_icon_proc,
d_aase_edit_proc,
d_aase_list_proc,
d_aase_text_list_proc,
d_aase_textbox_proc,
d_aase_slider_proc,
d_aase_menu_proc,
d_aase_window_proc,
d_aase_clear_proc,
d_agup_common_text_proc,
d_agup_common_ctext_proc,
d_agup_common_rtext_proc
};
AL_CONST struct AGUP_THEME *aase_theme = &the_theme;