1 /*
2 * ags.c system35�Υ���ե��å��֥�å�
3 *
4 * Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
5 * 1998- <masaki-c@is.aist-nara.ac.jp>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22 /* $Id: ags.c,v 1.34 2004/10/31 04:18:05 chikama Exp $ */
23
24 #include "config.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <glib.h>
31
32 #include "portab.h"
33 #include "xsystem35.h"
34 #include "ags.h"
35 #include "graphicsdevice.h"
36 #include "alpha_plane.h"
37 #include "counter.h"
38 #include "eucsjis.h"
39 #include "imput.h"
40 #include "flood.h"
41 #include "font.h"
42 #include "cursor.h"
43
44 #define check_param ags_check_param
45 #define check_param_xy ags_check_param_xy
46 #define intersection ags_intersection
47
48 static void initPal(Pallet256 *sys_pal);
49 static boolean intersects(MyRectangle *r1, MyRectangle *r2);
50
51 static Pallet256 pal_256;
52 static boolean need_update = TRUE;
53 static boolean fade_outed = FALSE;
54 static int cursor_move_time = 50; /* ���������ư�ˤ��������(ms) */
55
initPal(Pallet256 * pal)56 static void initPal(Pallet256 *pal) {
57 int i;
58 for (i = 0; i < 256; i++) {
59 pal->red[i] = 0; pal->green[i] = 0; pal->blue[i] = 0;
60 }
61 pal->red[0] = 0; pal->green[0] = 0; pal->blue[0] = 0;
62 pal->red[7] = 255; pal->green[7] = 255; pal->blue[7] = 255;
63 pal->red[15] = 255; pal->green[15] = 255; pal->blue[15] = 255;
64 pal->red[255] = 255; pal->green[255] = 255; pal->blue[255] = 255;
65 SetPallet(pal, 0, 256);
66 nact->sys_pal_changed = TRUE;
67 }
68
ags_regionContains(MyRectangle * r,int x,int y)69 boolean ags_regionContains(MyRectangle *r, int x, int y) {
70 return x >= r->x && x < r->x + r->width && y >= r->y && y < r->y + r->height;
71 }
72
intersects(MyRectangle * r1,MyRectangle * r2)73 static boolean intersects(MyRectangle *r1, MyRectangle *r2) {
74 return !((r2->x + r2->width <= r1->x) ||
75 (r2->y + r2->height <= r1->y) ||
76 (r2->x >= r1->x + r1->width) ||
77 (r2->y >= r1->y + r1->height));
78 }
79
ags_intersection(MyRectangle * r1,MyRectangle * r2,MyRectangle * rst)80 void ags_intersection(MyRectangle *r1, MyRectangle *r2, MyRectangle *rst) {
81 int x1 = max(r1->x, r2->x);
82 int x2 = min(r1->x + r1->width, r2->x + r2->width);
83 int y1 = max(r1->y, r2->y);
84 int y2 = min(r1->y + r1->height, r2->y + r2->height);
85 rst->x = x1;
86 rst->y = y1;
87 rst->width = x2 - x1;
88 rst->height = y2 - y1;
89 }
90
ags_check_param(int * x,int * y,int * w,int * h)91 boolean ags_check_param(int *x, int *y, int *w, int *h) {
92 if (*x >= nact->sys_world_size.width) {
93 WARNING("Illegal Param x = %d (max=%d)(@%03x:%05x)\n", *x, nact->sys_world_size.width, sl_getPage(), sl_getIndex());
94 return FALSE;
95 }
96 if (*y >= nact->sys_world_size.height) {
97 WARNING("Illegal Param y = %d (max=%d)\n", *y, nact->sys_world_size.height);
98 return FALSE;
99 }
100
101 if (*x < 0) { *w += *x; *x = 0; }
102 if (*y < 0) { *h += *y; *y = 0; }
103
104 if ((*x + *w) > nact->sys_world_size.width) { *w = nact->sys_world_size.width - *x;}
105 if ((*y + *h) > nact->sys_world_size.height) { *h = nact->sys_world_size.height - *y;}
106
107 if (*w <= 0) return FALSE;
108 if (*h <= 0) return FALSE;
109
110 return TRUE;
111 }
112
ags_check_param_xy(int * x,int * y)113 boolean ags_check_param_xy(int *x, int *y) {
114 if (*x >= nact->sys_world_size.width) {
115 WARNING("Illegal Param x = %d\n", *x);
116 return FALSE;
117 }
118 if (*y >= nact->sys_world_size.height) {
119 WARNING("Illegal Param y = %d\n", *y);
120 return FALSE;
121 }
122
123 if (*x < 0) { *x = 0; }
124 if (*y < 0) { *y = 0; }
125
126 return TRUE;
127 }
128
ags_init()129 void ags_init() {
130 nact->sys_mouse_movesw = 2; /* 0:IZ��̵��, 1: ľ�ܻ������, 2: ���ࡼ���˻������ */
131 nact->sys_pal = &pal_256;
132 nact->sys_world_size.width = SYS35_DEFAULT_WIDTH;
133 nact->sys_world_size.height = SYS35_DEFAULT_HEIGHT;
134 nact->sys_world_depth = SYS35_DEFAULT_DEPTH;
135 nact->sys_view_area.x = 0;
136 nact->sys_view_area.y = 0;
137 nact->sys_view_area.width = SYS35_DEFAULT_WIDTH;
138 nact->sys_view_area.height = SYS35_DEFAULT_HEIGHT;
139
140 GraphicsInitilize();
141
142 font_init(nact->fontdev);
143 SetFontDevice(nact->ags.font);
144
145 initPal(&pal_256);
146 cg_init();
147 }
148
ags_remove()149 void ags_remove() {
150 ags_autorepeat(TRUE);
151 GraphicsRemove();
152 }
153
ags_setWorldSize(int width,int height,int depth)154 void ags_setWorldSize(int width, int height, int depth) {
155 nact->sys_world_size.width = width;
156 nact->sys_world_size.height = height;
157 nact->sys_world_depth = depth;
158 SetWorldSize(width, height, depth);
159
160 nact->ags.dib = GetDIB();
161 nact->ags.dib->has_alpha = FALSE;
162 nact->ags.dib->has_pixel = TRUE;
163
164 /* DIB��8�ʾ�ξ��ϡ�alpha plane ���Ѱ� */
165 if (depth > 8) {
166 if (nact->ags.dib->alpha != NULL) {
167 g_free(nact->ags.dib->alpha);
168 }
169 nact->ags.dib->alpha = g_new0(BYTE, width * height);
170 nact->ags.dib->has_alpha = TRUE;
171 }
172
173 fade_outed = FALSE; /* thanx tajiri@wizard */
174
175 nact->sys_pal_changed = TRUE;
176 }
177
ags_setViewArea(int x,int y,int width,int height)178 void ags_setViewArea(int x, int y, int width, int height) {
179 nact->sys_view_area.x = x;
180 nact->sys_view_area.y = y;
181
182 nact->sys_view_area.width = width;
183 nact->sys_view_area.height = height;
184 SetWindowSize(x, y, width, height);
185 }
186
ags_setWindowTitle(char * src)187 void ags_setWindowTitle(char *src) {
188 #define TITLEHEAD "XSystem35 Version "VERSION":"
189 BYTE *dst, *d;
190
191 dst = sjis2lang(src);
192 if (NULL == (d = malloc(strlen(dst) + strlen(TITLEHEAD) + 1))) {
193 NOMEMERR();
194 }
195 strcpy(d, TITLEHEAD);
196 strcat(d, dst);
197 SetWindowTitle(d);
198 free(dst);
199 free(d);
200 }
201
ags_getDIBInfo(DispInfo * info)202 void ags_getDIBInfo(DispInfo *info) {
203 info->width = nact->sys_world_size.width;
204 info->height = nact->sys_world_size.height;
205 info->depth = nact->sys_world_depth;
206 }
207
ags_getViewAreaInfo(DispInfo * info)208 void ags_getViewAreaInfo(DispInfo *info) {
209 GetWindowInfo(info);
210 info->width = nact->sys_view_area.width;
211 info->height = nact->sys_view_area.height;
212 }
213
ags_getWindowInfo(DispInfo * info)214 void ags_getWindowInfo(DispInfo *info) {
215 GetWindowInfo(info);
216 }
217
ags_setExposeSwitch(boolean bool)218 void ags_setExposeSwitch(boolean bool) {
219 need_update = bool;
220 }
221
ags_updateArea(int x,int y,int w,int h)222 void ags_updateArea(int x, int y, int w, int h) {
223 MyRectangle r, update;
224 MyPoint p;
225
226 if (fade_outed) return;
227
228 if (need_update) {
229 r.x = x; r.y = y; r.width = w; r.height = h;
230 if (intersects(&nact->sys_view_area, &r)) {
231 intersection(&nact->sys_view_area, &r, &update);
232 p.x = update.x - nact->sys_view_area.x;
233 p.y = update.y - nact->sys_view_area.y;
234 UpdateArea(&update, &p);
235 }
236 }
237 }
238
ags_updateFull()239 void ags_updateFull() {
240 MyPoint p = {0, 0};
241 MyRectangle r;
242
243 if (fade_outed) return;
244
245 if (need_update) {
246 r.x = nact->sys_view_area.x;
247 r.y = nact->sys_view_area.y;
248 r.width = min(nact->sys_view_area.width, nact->sys_world_size.width);
249 r.height = min(nact->sys_view_area.height, nact->sys_world_size.height);
250 UpdateArea(&r, &p);
251 }
252 }
253
ags_setPallets(Pallet256 * src_pal,int src,int dst,int cnt)254 void ags_setPallets(Pallet256 *src_pal, int src, int dst, int cnt) {
255 int i;
256 for (i = 0; i < cnt; i++) {
257 nact->sys_pal->red [dst + i] = src_pal->red [src + i];
258 nact->sys_pal->green[dst + i] = src_pal->green[src + i];
259 nact->sys_pal->blue [dst + i] = src_pal->blue [src + i];
260 }
261 nact->sys_pal_changed = TRUE;
262 }
263
ags_setPallet(int no,int red,int green,int blue)264 void ags_setPallet(int no, int red, int green, int blue) {
265 nact->sys_pal->red[no] = red;
266 nact->sys_pal->green[no] = green;
267 nact->sys_pal->blue[no] = blue;
268 nact->sys_pal_changed = TRUE;
269 }
270
ags_setPalletToSystem(int src,int cnt)271 void ags_setPalletToSystem(int src, int cnt) {
272 if (!fade_outed)
273 SetPallet(nact->sys_pal, src, cnt);
274 }
275
ags_drawRectangle(int x,int y,int w,int h,int col)276 void ags_drawRectangle(int x, int y, int w, int h, int col) {
277 if (!check_param(&x, &y, &w, &h)) return;
278
279 DrawRectangle(x, y, w, h, col);
280 }
281
ags_fillRectangle(int x,int y,int w,int h,int col)282 void ags_fillRectangle(int x, int y, int w, int h, int col) {
283 if (!check_param(&x, &y, &w, &h)) return;
284
285 FillRectangle(x, y, w, h, col);
286 }
287
ags_drawLine(int x0,int y0,int x1,int y1,int col)288 void ags_drawLine(int x0, int y0, int x1, int y1, int col) {
289 if (!check_param_xy(&x0, &y0)) return;
290 if (!check_param_xy(&x1, &y1)) return;
291
292 DrawLine(x0, y0, x1, y1, col);
293 }
294
ags_copyArea(int sx,int sy,int w,int h,int dx,int dy)295 void ags_copyArea(int sx, int sy, int w, int h, int dx, int dy) {
296 if (!check_param(&sx, &sy, &w, &h)) return;
297 if (!check_param(&dx, &dy, &w, &h)) return;
298
299 CopyArea(sx, sy, w, h, dx, dy);
300 }
301
ags_scaledCopyArea(int sx,int sy,int sw,int sh,int dx,int dy,int dw,int dh,int mirror_sw)302 void ags_scaledCopyArea(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mirror_sw) {
303 if (!check_param(&sx, &sy, &sw, &sh)) return;
304 if (!check_param(&dx, &dy, &dw, &dh)) return;
305
306 DspDeviceSync(); /* Device��¸�� sync (ex. XSync()) */
307 ScaledCopyArea(sx, sy, sw, sh, dx, dy, dw, dh, mirror_sw);
308 }
309
ags_copyAreaSP(int sx,int sy,int w,int h,int dx,int dy,int col)310 void ags_copyAreaSP(int sx, int sy, int w, int h, int dx, int dy, int col) {
311 if (!check_param(&sx, &sy, &w, &h)) return;
312 if (!check_param(&dx, &dy, &w, &h)) return;
313
314 DspDeviceSync();
315 CopyAreaSP(sx, sy, w, h, dx, dy, col);
316 }
317
ags_wrapColor(int x,int y,int w,int h,int p1,int p2)318 void ags_wrapColor(int x, int y, int w, int h, int p1, int p2) {
319 if (nact->sys_world_depth == 8) return;
320
321 if (!check_param(&x, &y, &w, &h)) return;
322
323 DspDeviceSync();
324 WrapColor(x, y, w, h, p1, p2);
325 }
326
ags_getPixel(int x,int y,Pallet * cell)327 void ags_getPixel(int x, int y, Pallet *cell) {
328 if (!check_param_xy(&x, &y)) return;
329
330 DspDeviceSync();
331 GetPixel(x, y, cell);
332 }
333
ags_changeColorArea(int sx,int sy,int w,int h,int dst,int src,int cnt)334 void ags_changeColorArea(int sx, int sy, int w, int h, int dst, int src, int cnt) {
335 if (nact->sys_world_depth != 8) return;
336
337 if (!check_param(&sx, &sy, &w, &h)) return;
338
339 DspDeviceSync();
340 {
341 agsurface_t *dib = nact->ags.dib;
342 int x, y;
343 int src_last = src + cnt,dif = dst - src;
344 BYTE *yl;
345 BYTE *sdata = GETOFFSET_PIXEL(dib, sx, sy);
346
347 for (y = 0; y < h; y++) {
348 yl = sdata + y * dib->bytes_per_line;
349 for (x = 0; x < w; x++) {
350 if (*yl >= src && *yl < src_last) *yl += dif;
351 yl++;
352 }
353 }
354 }
355 }
356
ags_saveRegion(int x,int y,int w,int h)357 void* ags_saveRegion(int x, int y, int w, int h) {
358 if (!check_param(&x, &y, &w, &h)) return NULL;
359
360 DspDeviceSync();
361 return (void *)SaveRegion(x, y, w, h);
362 }
363
ags_restoreRegion(void * region,int x,int y)364 void ags_restoreRegion(void *region, int x, int y) {
365 if (region == NULL) return;
366
367 if (!check_param_xy(&x, &y)) return;
368
369 DspDeviceSync();
370 RestoreRegion(region, x, y);
371 }
372
ags_putRegion(void * region,int x,int y)373 void ags_putRegion(void *region, int x, int y) {
374 if (region == NULL) return;
375
376 if (!check_param_xy(&x, &y)) return;
377
378 DspDeviceSync();
379 PutRegion(region, x, y);
380 }
381
ags_copyRegion(void * region,int sx,int sy,int w,int h,int dx,int dy)382 void ags_copyRegion(void *region, int sx, int sy , int w, int h, int dx, int dy) {
383 if (region == NULL) return;
384
385 if (!check_param_xy(&dx, &dy)) return;
386 if (!check_param(&dx, &dy, &w, &h)) return;
387
388 DspDeviceSync();
389 CopyRegion(region, sx, sy, w, h, dx, dy);
390 }
391
ags_delRegion(void * region)392 void ags_delRegion(void *region) {
393 if (region == NULL) return;
394
395 DspDeviceSync();
396 DelRegion(region);
397 }
398
ags_drawString(int x,int y,char * src,int col)399 int ags_drawString(int x, int y, char *src, int col) {
400 int w;
401
402 if (!check_param_xy(&x, &y)) return 0;
403
404 DspDeviceSync();
405 w = DrawString(x, y, src, col);
406
407 return w;
408 }
409
ags_drawCg8bit(cgdata * cg,int x,int y)410 void ags_drawCg8bit(cgdata *cg, int x, int y) {
411 int sx, sy, w, h;
412
413 sx = x;
414 sy = y;
415 w = cg->width;
416 h = cg->height;
417
418 if (!check_param(&x, &y, &w, &h)) return;
419
420 cg->data_offset = abs(sy - y) * cg->width + abs(sx - x);
421 DspDeviceSync();
422 DrawImage8_fromData(cg, x, y, w, h);
423 }
424
ags_drawCg16bit(cgdata * cg,int x,int y)425 void ags_drawCg16bit(cgdata *cg, int x, int y) {
426 int sx, sy, w, h;
427
428 sx = x;
429 sy = y;
430 w = cg->width;
431 h = cg->height;
432
433 if (!check_param(&x, &y, &w, &h)) return;
434
435 cg->data_offset = abs(sy - y) * cg->width + abs(sx - x);
436 DspDeviceSync();
437 DrawImage16_fromData(cg, x, y, w, h);
438 }
439
ags_copyArea_shadow(int sx,int sy,int w,int h,int dx,int dy)440 void ags_copyArea_shadow(int sx, int sy, int w, int h, int dx, int dy) {
441 if (nact->sys_world_depth == 8) return;
442
443 if (!check_param(&sx, &sy, &w, &h)) return;
444 if (!check_param(&dx, &dy, &w, &h)) return;
445
446 DspDeviceSync();
447 CopyAreaSP16_shadow(sx, sy, w, h, dx, dy);
448 }
449
ags_copyArea_transparent(int sx,int sy,int w,int h,int dx,int dy,int col)450 void ags_copyArea_transparent(int sx, int sy, int w, int h, int dx, int dy, int col) {
451 if (nact->sys_world_depth == 8) return;
452
453 if (!check_param(&sx, &sy, &w, &h)) return;
454 if (!check_param(&dx, &dy, &w, &h)) return;
455
456 DspDeviceSync();
457 CopyAreaSP(sx, sy, w, h, dx, dy, col);
458 }
459
ags_copyArea_alphaLevel(int sx,int sy,int w,int h,int dx,int dy,int lv)460 void ags_copyArea_alphaLevel(int sx, int sy, int w, int h, int dx, int dy, int lv) {
461 if (nact->sys_world_depth == 8) return;
462
463 if (!check_param(&sx, &sy, &w, &h)) return;
464 if (!check_param(&dx, &dy, &w, &h)) return;
465
466 DspDeviceSync();
467 CopyAreaSP16_alphaLevel(sx, sy, w, h, dx, dy, lv);
468 }
469
ags_copyArea_alphaBlend(int sx,int sy,int w,int h,int dx,int dy,int lv)470 void ags_copyArea_alphaBlend(int sx, int sy, int w, int h, int dx, int dy, int lv) {
471 if (nact->sys_world_depth == 8) return;
472
473 if (!check_param(&sx, &sy, &w, &h)) return;
474 if (!check_param(&dx, &dy, &w, &h)) return;
475
476 DspDeviceSync();
477 CopyAreaSP16_alphaBlend(sx, sy, w, h, dx, dy, lv);
478 }
479
ags_copyArea_whiteLevel(int sx,int sy,int w,int h,int dx,int dy,int lv)480 void ags_copyArea_whiteLevel(int sx, int sy, int w, int h, int dx, int dy, int lv) {
481 if (nact->sys_world_depth == 8) return;
482
483 if (!check_param(&sx, &sy, &w, &h)) return;
484 if (!check_param(&dx, &dy, &w, &h)) return;
485
486 DspDeviceSync();
487 CopyAreaSP16_whiteLevel(sx, sy, w, h, dx, dy, lv);
488 }
489
490
491 /*******************************************************
492 *
493 * special thanks to tajiri@wizard.elec.waseda.ac.jp����
494 *
495 *******************************************************/
496 /* CP ���ޥ�ɤμ�����. Ʊ�����ǽ��褿�ΰ����ꤵ�줿
497 �����ɤ��Ѥ��롣
498 */
499 static int floodColor;
500 static int changeColor;
501 static agsurface_t *__img;
502 /*�������Τ��Ȥ˥��åץǡ��Ȥ����ΰ�
503 (updatePointTop �� updatePointEnd�ǰϤޤ줿Ĺ����)
504 */
505 static MyPoint updatePointTop, updatePointEnd;
506
pixcel(int x,int y)507 static int pixcel(int x, int y) {
508 int pixval;
509
510 if ((y >= 0) && (y <= __img->height) && (x >= 0) && (x <= __img->width)) {
511 BYTE *dst = (BYTE *)(__img->pixel + y * __img->bytes_per_line + x);
512 pixval = *dst;
513
514 if (pixval == floodColor){
515 /* if(pixval <= floodColor+2 && pixval >= floodColor-2){ */
516 *dst = changeColor;
517 if (x < updatePointTop.x) updatePointTop.x = x;
518 if (x > updatePointEnd.x) updatePointEnd.x = x;
519 if (y < updatePointTop.y) updatePointTop.y = y;
520 if (y > updatePointEnd.y) updatePointEnd.y = y;
521 return TRUE;
522 }
523 }
524 return FALSE;
525 }
526
ags_imageFlood(int x,int y,int c)527 MyRectangle* ags_imageFlood(int x, int y, int c) {
528 if (nact->sys_world_depth != 8) return NULL;
529
530 if (!check_param_xy(&x, &y)) return NULL;
531
532 DspDeviceSync();
533
534 {
535 agsurface_t *dib = nact->ags.dib;
536 BYTE *dst = GETOFFSET_PIXEL(dib, x, y);
537 static MyRectangle rec;
538 __img = dib;
539 updatePointTop.x = x;
540 updatePointTop.y = y;
541 updatePointEnd.x = x;
542 updatePointEnd.y = y;
543 /*ľ���Ϥ̤�ʤ������ꤷ�ʤ�����*/
544 if ((x <= 0 || (*(dst - 1) != *(dst))) && ((x >= dib->width) || (*(dst + 1) != *dst)))
545 return NULL;
546 if ((y <= 0 || (*(dst - dib->bytes_per_line) != *(dst)))
547 && ((y >= dib->height) || (*(dst + dib->bytes_per_line) != *dst)))
548 return NULL;
549 floodColor = *dst;
550
551 changeColor = c;
552 flood(x, y, pixcel);
553 rec.x = updatePointTop.x;
554 rec.y = updatePointTop.y;
555 rec.width = updatePointEnd.x - updatePointTop.x + 1;
556 rec.height = updatePointEnd.y - updatePointTop.y + 1;
557 return &rec;
558 }
559 }
560
ags_copyFromAlpha(int sx,int sy,int w,int h,int dx,int dy,ALPHA_DIB_COPY_TYPE flg)561 void ags_copyFromAlpha(int sx, int sy, int w, int h, int dx, int dy, ALPHA_DIB_COPY_TYPE flg) {
562 if (nact->sys_world_depth == 8) return;
563
564 if (!check_param(&sx, &sy, &w, &h)) return;
565 if (!check_param(&dx, &dy, &w, &h)) return;
566
567 DspDeviceSync();
568 Copy_from_alpha(sx, sy, w, h, dx, dy, flg);
569 }
570
ags_copyToAlpha(int sx,int sy,int w,int h,int dx,int dy,ALPHA_DIB_COPY_TYPE flg)571 void ags_copyToAlpha(int sx, int sy, int w, int h, int dx, int dy, ALPHA_DIB_COPY_TYPE flg) {
572 if (nact->sys_world_depth == 8) return;
573
574 if (!check_param(&sx, &sy, &w, &h)) return;
575 if (!check_param(&dx, &dy, &w, &h)) return;
576
577 DspDeviceSync();
578 Copy_to_alpha(sx, sy, w, h, dx, dy, flg);
579 }
580
ags_alpha_uppercut(int sx,int sy,int w,int h,int s,int d)581 void ags_alpha_uppercut(int sx, int sy, int w, int h, int s, int d) {
582 if (nact->sys_world_depth == 8) return;
583
584 if (!check_param(&sx, &sy, &w, &h)) return;
585
586 alpha_uppercut(nact->ags.dib, sx, sy, w, h, s, d);
587 }
588
ags_alpha_lowercut(int sx,int sy,int w,int h,int s,int d)589 void ags_alpha_lowercut(int sx, int sy, int w, int h, int s, int d) {
590 if (nact->sys_world_depth == 8) return;
591
592 if (!check_param(&sx, &sy, &w, &h)) return;
593
594 alpha_lowercut(nact->ags.dib, sx, sy, w, h, s, d);
595 }
596
ags_alpha_setLevel(int x,int y,int w,int h,int lv)597 void ags_alpha_setLevel(int x, int y, int w, int h, int lv) {
598 if (nact->sys_world_depth == 8) return;
599
600 if (!check_param(&x, &y, &w, &h)) return;
601
602 alpha_set_level(nact->ags.dib, x, y, w, h, lv);
603 }
604
ags_alpha_copyArea(int sx,int sy,int w,int h,int dx,int dy)605 void ags_alpha_copyArea(int sx, int sy, int w, int h, int dx, int dy) {
606 if (nact->sys_world_depth == 8) return;
607
608 if (!check_param(&sx, &sy, &w, &h)) return;
609 if (!check_param(&dx, &dy, &w, &h)) return;
610
611 alpha_copy_area(nact->ags.dib, sx, sy, w, h, dx, dy);
612 }
613
ags_alpha_getPixel(int x,int y,int * pic)614 void ags_alpha_getPixel(int x, int y, int *pic) {
615 if (nact->sys_world_depth == 8) return;
616
617 if (!check_param_xy(&x, &y)) {
618 *pic = 0;
619 } else {
620 alpha_get_pixel(nact->ags.dib, x, y, (BYTE *)pic);
621 }
622 }
623
ags_alpha_setPixel(int x,int y,int w,int h,BYTE * b)624 void ags_alpha_setPixel(int x, int y, int w, int h, BYTE *b) {
625 int savex, savey, savew, saveh, offset;
626
627 savex = x;
628 savey = y;
629 savew = w;
630 saveh = h;
631
632 if (!check_param(&x, &y, &w, &h)) return;
633
634 offset = abs(savey - y) * savew + abs(savex - x);
635
636 alpha_set_pixels(nact->ags.dib, x, y, w, h, b + offset, savew);
637 }
638
639 /*
640 * fade in/out �� wait ����
641 */
ags_fader(ags_faderinfo_t * i)642 void ags_fader(ags_faderinfo_t *i) {
643 int cnt_st, step, key = 0, canceled_key = 0;
644 cnt_st = get_high_counter(SYSTEMCOUNTER_MSEC);
645
646 i->callback(0);
647
648 if (i->effect_time == 0) goto out;
649
650 step = 1;
651 while(step < i->step_max) {
652 int lefttime, leftstep, mstime, cnt1, cnt2;
653
654 cnt1 = get_high_counter(SYSTEMCOUNTER_MSEC);
655 i->callback(step);
656 key = sys_getInputInfo();
657 /* �ºݤ� fade �ˤ����ä����� */
658 usleep(0); /* It's a magic !!! */
659 cnt2 = get_high_counter(SYSTEMCOUNTER_MSEC) - cnt1;
660
661 lefttime = i->effect_time - (cnt1 + cnt2 - cnt_st); /* fade �Ĥ���� */
662 leftstep = i->step_max - step; /* fade �Ĥꥹ�ƥå� */
663
664 if (lefttime <= 0) break; /* �����ڤ� */
665 if (leftstep <= 0) break;
666
667 mstime = lefttime / leftstep; /* 1step�˵��������� */
668 if (mstime > cnt2) {
669 /* wait ���;͵�������� */
670 key = sys_keywait(mstime - cnt2, i->cancel);
671 step++;
672 } else if (mstime > 0) {
673 /* wait ���;͵��̵����� */
674 step += ((cnt2+1) * leftstep / lefttime);
675 nact->callback();
676 } else {
677 break;
678 }
679 /* wait cancel ��ͭ���ξ�� */
680 if (i->cancel) {
681 if (key != 0) {
682 canceled_key = key;
683 break;
684 }
685 }
686 }
687 out:
688 /* fader last step */
689 i->callback(i->step_max);
690
691 /* store canceled key */
692 nact->waitcancel_key = canceled_key;
693 }
694
ags_fadeIn(int rate,boolean flag)695 void ags_fadeIn(int rate, boolean flag) {
696 ags_faderinfo_t i;
697
698 if (need_update) {
699 i.effect_time = (rate * 16 * 1000) / 60;
700 i.cancel = flag;
701 } else {
702 i.effect_time = 0;
703 }
704 fade_outed = FALSE;
705
706 nact->waitcancel_key = 0;
707
708 i.callback = FadeIn;
709 i.step_max = 255;
710 ags_fader(&i);
711 }
712
ags_fadeOut(int rate,boolean flag)713 void ags_fadeOut(int rate, boolean flag) {
714 ags_faderinfo_t i;
715
716 if (need_update && !fade_outed) {
717 i.effect_time = (rate * 16 * 1000) / 60;
718 i.cancel = flag;
719 } else {
720 i.effect_time = 0;
721 }
722 fade_outed = TRUE;
723
724 nact->waitcancel_key = 0;
725
726 i.callback = FadeOut;
727 i.step_max = 255;
728 ags_fader(&i);
729 }
730
ags_whiteIn(int rate,boolean flag)731 void ags_whiteIn(int rate, boolean flag) {
732 ags_faderinfo_t i;
733 if (need_update) {
734 i.effect_time = (rate * 16 * 1000) / 60;
735 i.cancel = flag;
736 } else {
737 i.effect_time = 0;
738 }
739 fade_outed = FALSE;
740
741 nact->waitcancel_key = 0;
742
743 i.callback = WhiteIn;
744 i.step_max = 255;
745 ags_fader(&i);
746 }
747
ags_whiteOut(int rate,boolean flag)748 void ags_whiteOut(int rate, boolean flag) {
749 ags_faderinfo_t i;
750 if (need_update && !fade_outed) {
751 i.effect_time = (rate * 16 * 1000) / 60;
752 i.cancel = flag;
753 } else {
754 i.effect_time = 0;
755 }
756 fade_outed = TRUE;
757
758 nact->waitcancel_key = 0;
759
760 i.callback = WhiteOut;
761 i.step_max = 255;
762 ags_fader(&i);
763 }
764
ags_setFont(int type,int size)765 void ags_setFont(int type, int size) {
766 nact->ags.font->sel_font(type, size);
767 }
768
ags_setCursorType(int type)769 void ags_setCursorType(int type) {
770 if (nact->noimagecursor && type >= 100) return;
771 SetCursorType(type);
772 }
773
ags_loadCursor(int p1,int p2)774 void ags_loadCursor(int p1,int p2) {
775 if (!nact->noimagecursor) {
776 cursor_load(p1, p2);
777 }
778 }
779
ags_setCursorLocation(int x,int y,boolean is_dibgeo)780 void ags_setCursorLocation(int x, int y, boolean is_dibgeo) {
781 int dx[8], dy[8];
782 int i, delx, dely;
783 MyPoint p;
784 if (!check_param_xy(&x, &y)) return;
785
786 /* DIB ��ɽ�Ϥ� Window ��ɽ�Ϥ� */
787 if (is_dibgeo) {
788 x -= nact->sys_view_area.x;
789 y -= nact->sys_view_area.y;
790 }
791
792 switch(nact->sys_mouse_movesw) {
793 case 0:
794 return;
795 case 1:
796 SetCursorLocation(x, y); break;
797 case 2:
798 sys_getMouseInfo(&p, is_dibgeo);
799 delx = x - p.x;
800 dely = y - p.y;
801
802 for (i = 1; i < 8; i++) {
803 dx[i-1] = ((delx*i*i*i) >> 9) - ((3*delx*i*i)>> 6) + ((3*delx*i) >> 3) + p.x;
804 dy[i-1] = ((dely*i*i*i) >> 9) - ((3*dely*i*i)>> 6) + ((3*dely*i) >> 3) + p.y;
805 }
806 dx[7] = x; dy[7] = y;
807
808 for (i = 0; i < 8; i++) {
809 SetCursorLocation(dx[i], dy[i]);
810 usleep(cursor_move_time * 1000 / 8);
811 }
812 break;
813 default:
814 return;
815 }
816 }
817
ags_setAntialiasedStringMode(boolean on)818 void ags_setAntialiasedStringMode(boolean on) {
819 if (!nact->noantialias) {
820 nact->ags.font->antialiase_on = on;
821 }
822 }
823
ags_getAntialiasedStringMode()824 boolean ags_getAntialiasedStringMode() {
825 return nact->ags.font->antialiase_on;
826 }
827
ags_fullscreen(boolean on)828 void ags_fullscreen(boolean on) {
829 nact->sys_fullscreen_on = on;
830 FullScreen(on);
831 }
832
ags_copyArea_shadow_withrate(int sx,int sy,int w,int h,int dx,int dy,int lv)833 void ags_copyArea_shadow_withrate(int sx, int sy, int w, int h, int dx, int dy, int lv) {
834 if (nact->sys_world_depth == 8) return;
835
836 if (lv == 0) return;
837
838 if (!check_param(&sx, &sy, &w, &h)) return;
839 if (!check_param(&dx, &dy, &w, &h)) return;
840
841 DspDeviceSync();
842 CopyAreaSP16_shadow_withRate(sx, sy, w, h, dx, dy, lv);
843 }
844
ags_setCursorMoveTime(int msec)845 void ags_setCursorMoveTime(int msec) {
846 cursor_move_time = msec;
847 }
848
ags_getCursorMoveTime()849 int ags_getCursorMoveTime() {
850 return cursor_move_time;
851 }
852
853 /*
854 * ������ΰ�������̤�Zoom
855 *
856 */
ags_zoom(int x,int y,int w,int h)857 void ags_zoom(int x, int y, int w, int h) {
858 if (!check_param(&x, &y, &w, &h)) return;
859
860 DspDeviceSync();
861 Zoom(x, y, w, h);
862 }
863
ags_getDIB()864 agsurface_t *ags_getDIB() {
865 return nact->ags.dib;
866 }
867
ags_sync()868 void ags_sync() {
869 DspDeviceSync();
870 }
871
ags_fillRectangleNeg(int x,int y,int w,int h,int col)872 void ags_fillRectangleNeg(int x, int y, int w, int h, int col) {
873 if (!check_param(&x, &y, &w, &h)) return;
874
875 DspDeviceSync();
876 image_fillRectangleNeg(nact->ags.dib, x, y, w, h, col);
877 }
878
ags_autorepeat(boolean bool)879 void ags_autorepeat(boolean bool) {
880 SetAutoRepeat(bool);
881 }
882