1 /*
2  * ags.h  Alice Graphic System
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.h,v 1.25 2004/10/31 04:18:06 chikama Exp $ */
23 
24 #ifndef __AGS_H__
25 #define __AGS_H__
26 
27 #include "config.h"
28 
29 #include "portab.h"
30 #include "cg.h"
31 #include "graphics.h"
32 #include "font.h"
33 
34 
35 /* �ޥ�����������μ��� */
36 #define IDC_ARROW     1
37 #define IDC_CROSS     2
38 #define IDC_IBEAM     3
39 #define IDC_ICON      4
40 #define IDC_NO        5
41 #define IDC_SIZE      6
42 #define IDC_SIZEALL   7
43 #define IDC_SIZENESW  8
44 #define IDC_SIZENS    9
45 #define IDC_SIZENWSE 10
46 #define IDC_SIZEWE   11
47 #define IDC_UPARROW  12
48 #define IDC_WAIT     13
49 
50 /* RGB <-> alpha plane copy type */
51 typedef enum {
52 	FROM_16H,
53 	FROM_16L,
54 	FROM_24R,
55 	FROM_24G,
56 	FROM_24B,
57 	TO_16H,
58 	TO_16L,
59 	TO_24R,
60 	TO_24G,
61 	TO_24B
62 } ALPHA_DIB_COPY_TYPE;
63 
64 struct __surface {
65 	int no;      /* surface number, primary DIB is 0 */
66 
67 	int width;   /* width of surface  */
68 	int height;  /* height of surface */
69 	int depth;   /* depth of surface, 8/15/16/24/32 is available */
70 
71 	int bytes_per_line;   /* bytes per line  */
72 	int bytes_per_pixel;  /* bytes per pixel */
73 
74 	BYTE *pixel; /* pointer to pixel data */
75 	BYTE *alpha; /* pointer to alpha pixel data */
76 
77 	boolean has_alpha;
78 	boolean has_pixel;
79 
80 };
81 typedef struct __surface agsurface_t;
82 
83 #define GETOFFSET_PIXEL(suf, x, y) ((suf)->pixel + (y) * (suf)->bytes_per_line + (x) * (suf)->bytes_per_pixel)
84 #define GETOFFSET_ALPHA(suf, x, y) ((suf)->alpha + (y) * (suf)->width + (x))
85 
86 struct _agsevent {
87 	int type;
88 	int d1, d2, d3;
89 };
90 typedef struct _agsevent agsevent_t;
91 
92 
93 #define	AGSEVENT_MOUSE_MOTION 1
94 #define	AGSEVENT_BUTTON_PRESS 2
95 #define	AGSEVENT_BUTTON_RELEASE 3
96 #define AGSEVENT_KEY_PRESS 4
97 #define AGSEVENT_KEY_RELEASE 5
98 #define AGSEVENT_TIMER 6
99 
100 #define AGSEVENT_BUTTON_LEFT  1
101 #define AGSEVENT_BUTTON_MID   2
102 #define AGSEVENT_BUTTON_RIGHT 3
103 #define AGSEVENT_WHEEL_UP 4
104 #define AGSEVENT_WHEEL_DN 5
105 
106 
107 /*
108  * fader ��������
109  */
110 struct ags_faderinfo {
111 	int step_max;    /* ���� step �� */
112 	int effect_time; /* ���Τν����ˤ�������� */
113 
114 	boolean cancel;  /* ����� key ȴ�������Ĥ��뤫 */
115 	void (*callback)(int); /* callback �ؿ� */
116 };
117 typedef struct ags_faderinfo ags_faderinfo_t;
118 
119 
120 struct _ags {
121 	Pallet256 pal;              /* system pallet */
122 	boolean   pal_changed;      /* system pallet has changed */
123 
124 	MyDimension world_size;     /* size of off-screen */
125 
126 	MyRectangle view_area;      /* view region in off-screen */
127 
128 	int world_depth;            /* depth of off-screen (bits per pixel) */
129 
130 	int mouse_movesw;           /* mouse cursor move mode
131 				       0: ignore IZ
132 				       1: move to the geometory direcly
133 				       2: move to the geometory smoothly
134 				    */
135 
136 	boolean fullscree_is_on;    /* if full-screen mode then true */
137 
138 
139 	FONT *font;                 /* font device */
140 	agsurface_t *dib;           /* main surface */
141 	void (*eventcb)(agsevent_t *e); /* deliver event */
142 };
143 typedef struct _ags ags_t;
144 
145 
146 
147 /* ������ط� */
148 extern void ags_init();
149 extern void ags_remove();
150 
151 /* ������ɴط� */
152 extern void ags_setWorldSize(int width, int height, int depth);
153 extern void ags_setViewArea(int x, int y, int width, int height);
154 extern void ags_setWindowTitle(char *str);
155 extern void ags_getDIBInfo(DispInfo *info);
156 extern void ags_getWindowInfo(DispInfo *info);
157 extern void ags_getViewAreaInfo(DispInfo *info);
158 extern boolean ags_regionContains(MyRectangle *r, int x, int y);
159 extern void    ags_fullscreen(boolean on);
160 extern boolean ags_check_param(int *x, int *y, int *w, int *h);
161 extern boolean ags_check_param_xy(int *x, int *y);
162 extern void    ags_intersection(MyRectangle *r1, MyRectangle *r2, MyRectangle *rst);
163 extern agsurface_t *ags_getDIB();
164 extern void ags_sync();
165 
166 /* ���̹��� */
167 extern void ags_setExposeSwitch(boolean bool);
168 extern void ags_updateFull(void);
169 extern void ags_updateArea(int x, int y, int width, int height);
170 
171 /* �ѥ�åȴط� */
172 extern void ags_setPallets(Pallet256 *src_pal, int src, int dst, int cnt);
173 extern void ags_setPallet(int no, int red, int green, int blue);
174 extern void ags_setPalletToSystem(int src, int cnt);
175 
176 /* ����ط� */
177 extern void ags_drawRectangle(int x, int y, int w, int h, int col);
178 extern void ags_fillRectangle(int x, int y, int w, int h, int col);
179 extern void ags_fillRectangleNeg(int x, int y, int w, int h, int col);
180 extern void ags_drawLine(int x0, int y0, int x1, int y1, int col);
181 extern void ags_copyArea(int sx, int sy, int w, int h, int dx, int dy);
182 extern void ags_scaledCopyArea(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mirror_sw);
183 extern void ags_zoom(int x, int y, int w, int h);
184 extern void ags_copyAreaSP(int sx, int sy, int w, int h, int dx, int dy, int col);
185 extern void ags_copyArea_shadow_withrate(int sx, int sy, int w, int h, int dx, int dy, int lv);
186 
187 extern void ags_wrapColor(int x, int y, int w, int h, int p1, int p2);
188 extern void ags_getPixel(int x, int y, Pallet *cell);
189 extern void ags_changeColorArea(int x, int y, int w, int h, int dst, int src, int cnt);
190 
191 extern void* ags_saveRegion(int x, int y, int w, int h);
192 extern void ags_restoreRegion(void *region, int x, int y);
193 extern void ags_putRegion(void *region, int x, int y);
194 extern void ags_copyRegion(void *region, int sx, int sy, int w,int h,int dx,int dy);
195 extern void ags_delRegion(void *region);
196 
197 extern int  ags_drawString(int x, int y, char *src, int col);
198 extern void ags_drawCg8bit(cgdata *cg, int x, int y);
199 extern void ags_drawCg16bit(cgdata *cg, int x, int y);
200 
201 extern void ags_copyArea_shadow(int sx, int sy, int w, int h, int dx, int dy);
202 extern void ags_copyArea_transparent(int sx, int sy, int w, int h, int dx, int dy, int col);
203 extern void ags_copyArea_alphaLevel(int sx, int sy, int w, int h, int dx, int dy, int lv);
204 extern void ags_copyArea_alphaBlend(int sx, int sy, int w, int h, int dx, int dy, int lv);
205 extern void ags_copyArea_whiteLevel(int sx, int sy, int w, int h, int dx, int dy, int lv);
206 extern MyRectangle* ags_imageFlood(int x, int y, int c);
207 extern void ags_eCopyArea(int sx, int sy, int w, int h, int dx, int dy, int type, int opt, boolean flg, int spCol);
208 
209 /* alpha channel ��� */
210 extern void ags_copyFromAlpha(int sx, int sy, int w, int h, int dx, int dy, ALPHA_DIB_COPY_TYPE flg);
211 extern void ags_copyToAlpha(int sx, int sy, int w, int h, int dx, int dy, ALPHA_DIB_COPY_TYPE flg);
212 extern void ags_alpha_uppercut(int sx, int sy, int w, int h, int s, int d);
213 extern void ags_alpha_lowercut(int sx, int sy, int w, int h, int s, int d);
214 extern void ags_alpha_setLevel(int x, int y, int w, int h, int lv);
215 extern void ags_alpha_copyArea(int sx, int sy, int w, int h, int dx, int dy);
216 extern void ags_alpha_getPixel(int x, int y, int *pic);
217 extern void ags_alpha_setPixel(int x, int y, int w, int h, BYTE *b);
218 
219 /* fader */
220 extern void ags_fadeIn(int rate, boolean flg);
221 extern void ags_fadeOut(int rate, boolean flg);
222 extern void ags_whiteIn(int rate, boolean flg);
223 extern void ags_whiteOut(int rate, boolean flg);
224 extern void ags_fader_callback();
225 
226 /* �ե���ȴ�Ϣ */
227 extern void ags_setFont(int type, int size);
228 
229 /* ��������ط� */
230 extern void ags_setCursorType(int type);
231 extern void ags_loadCursor(int ,int);
232 extern void ags_setCursorLocation(int x, int y, boolean dibgeo);
233 extern void ags_setCursorMoveTime(int msec);
234 extern int  ags_getCursorMoveTime();
235 
236 /* misc */
237 extern void    ags_setAntialiasedStringMode(boolean mode);
238 extern boolean ags_getAntialiasedStringMode();
239 extern void    ags_fader(ags_faderinfo_t *);
240 extern void    ags_autorepeat(boolean bool);
241 
242 #define RGB_RMASK15 0x7c00
243 #define RGB_GMASK15 0x03e0
244 #define RGB_BMASK15 0x001f
245 #define RGB_RMASK16 0xf800
246 #define RGB_GMASK16 0x07e0
247 #define RGB_BMASK16 0x001f
248 #define RGB_RMASK24 0x00ff0000
249 #define RGB_GMASK24 0x0000ff00
250 #define RGB_BMASK24 0x000000ff
251 
252 #define BGR_RMASK15 0x001f
253 #define BGR_GMASK15 0x03e0
254 #define BGR_BMASK15 0x7c00
255 #define BGR_RMASK16 0x001f
256 #define BGR_GMASK16 0x07e0
257 #define BGR_BMASK16 0xf800
258 #define BGR_RMASK24 0x000000ff
259 #define BGR_GMASK24 0x0000ff00
260 #define BGR_BMASK24 0x00ff0000
261 
262 #define RGB_PIXR15(pic) (BYTE)(((pic) & RGB_RMASK15) >> 7)
263 #define RGB_PIXG15(pic) (BYTE)(((pic) & RGB_GMASK15) >> 2)
264 #define RGB_PIXB15(pic) (BYTE)(((pic) & RGB_BMASK15) << 3)
265 #define BGR_PIXR15(pic) (BYTE)(((pic) & BGR_RMASK15) << 3)
266 #define BGR_PIXG15(pic) (BYTE)(((pic) & BGR_GMASK15) >> 2)
267 #define BGR_PIXB15(pic) (BYTE)(((pic) & BGR_BMASK15) >> 7)
268 #define RGB_PIX15(r,g,b) (WORD)((((r) & 0xf8) << 7) | (((g) & 0xf8) << 2) | ((b       ) >> 3))
269 #define BGR_PIX15(r,g,b) (WORD)((((r)       ) >> 3) | (((g) & 0xf8) << 2) | ((b & 0xf8) << 7))
270 
271 #define RGB_PIXR16(pic) (BYTE)(((pic) & RGB_RMASK16) >> 8)
272 #define RGB_PIXG16(pic) (BYTE)(((pic) & RGB_GMASK16) >> 3)
273 #define RGB_PIXB16(pic) (BYTE)(((pic) & RGB_BMASK16) << 3)
274 #define BGR_PIXR16(pic) (BYTE)(((pic) & BGR_RMASK16) << 3)
275 #define BGR_PIXG16(pic) (BYTE)(((pic) & BGR_GMASK16) >> 3)
276 #define BGR_PIXB16(pic) (BYTE)(((pic) & BGR_BMASK16) >> 8)
277 #define RGB_PIX16(r,g,b) (WORD)((((r) & 0xf8) << 8) | (((g) & 0xfc) << 3) | ((b       ) >> 3))
278 #define BGR_PIX16(r,g,b) (WORD)((((r)       ) >> 3) | (((g) & 0xfc) << 3) | ((b & 0xf8) << 8))
279 
280 #define RGB_PIXR24(pic) (BYTE)(((pic) & RGB_RMASK24) >> 16)
281 #define RGB_PIXG24(pic) (BYTE)(((pic) & RGB_GMASK24) >>  8)
282 #define RGB_PIXB24(pic) (BYTE)(((pic) & RGB_BMASK24)      )
283 #define BGR_PIXR24(pic) (BYTE)(((pic) & BGR_RMASK24)      )
284 #define BGR_PIXG24(pic) (BYTE)(((pic) & BGR_GMASK24) >>  8)
285 #define BGR_PIXB24(pic) (BYTE)(((pic) & BGR_BMASK24) >> 16)
286 #define RGB_PIX24(r,g,b) (DWORD)((((r) << 16) | ((g) << 8) | (b)      ))
287 #define BGR_PIX24(r,g,b) (DWORD)((((r)      ) | ((g) << 8) | (b) << 16))
288 
289 #ifdef RGB_ORDER
290 #define PIXR15 RGB_PIXR15
291 #define PIXG15 RGB_PIXG15
292 #define PIXB15 RGB_PIXB15
293 #define PIXR16 RGB_PIXR16
294 #define PIXG16 RGB_PIXG16
295 #define PIXB16 RGB_PIXB16
296 #define PIXR24 RGB_PIXR24
297 #define PIXG24 RGB_PIXG24
298 #define PIXB24 RGB_PIXB24
299 #define PIX15  RGB_PIX15
300 #define PIX16  RGB_PIX16
301 #define PIX24  RGB_PIX24
302 #else
303 #define PIXR15 BGR_PIXR15
304 #define PIXG15 BGR_PIXG15
305 #define PIXB15 BGR_PIXB15
306 #define PIXR16 BGR_PIXR16
307 #define PIXG16 BGR_PIXG16
308 #define PIXB16 BGR_PIXB16
309 #define PIXR24 BGR_PIXR24
310 #define PIXG24 BGR_PIXG24
311 #define PIXB24 BGR_PIXB24
312 #define PIX15  BGR_PIX15
313 #define PIX16  BGR_PIX16
314 #define PIX24  BGR_PIX24
315 #endif
316 
317 #define ALPHABLEND15(f, b, a)  (PIX15((((PIXR15((f)) - PIXR15((b))) * (a)) >> 8) + PIXR15((b)),\
318                                       (((PIXG15((f)) - PIXG15((b))) * (a)) >> 8) + PIXG15((b)),\
319                                       (((PIXB15((f)) - PIXB15((b))) * (a)) >> 8) + PIXB15((b))))
320 
321 #define ALPHALEVEL15(p, lv) (PIX15(((PIXR15(p) * (lv)) >> 8),\
322                                    ((PIXG15(p) * (lv)) >> 8),\
323                                    ((PIXB15(p) * (lv)) >> 8)))
324 
325 #define WHITELEVEL15(p, lv) ALPHABLEND15(0x7fff, p, lv)
326 
327 #define ALPHABLEND16(f, b, a)  (PIX16((((PIXR16((f)) - PIXR16((b))) * (a)) >> 8)+ PIXR16((b)),\
328                                       (((PIXG16((f)) - PIXG16((b))) * (a)) >> 8)+ PIXG16((b)),\
329                                       (((PIXB16((f)) - PIXB16((b))) * (a)) >> 8)+ PIXB16((b))))
330 
331 #define ALPHALEVEL16(p, lv) PIX16(((PIXR16(p) * (lv)) >> 8),\
332                                   ((PIXG16(p) * (lv)) >> 8),\
333                                   ((PIXB16(p) * (lv)) >> 8))
334 
335 #define RGB_ALPHALEVEL16(p, lv) PIX16(((RGB_PIXR16(p) * (lv)) >> 8),\
336 				      ((RGB_PIXG16(p) * (lv)) >> 8),\
337 				      ((RGB_PIXB16(p) * (lv)) >> 8))
338 
339 #define WHITELEVEL16(p, lv) ALPHABLEND16(0xffff,p,lv)
340 
341 #define ALPHABLEND24(f, b, a)  (PIX24((((PIXR24((f)) - PIXR24((b))) * (a)) >> 8) + PIXR24((b)),\
342                                       (((PIXG24((f)) - PIXG24((b))) * (a)) >> 8) + PIXG24((b)),\
343                                       (((PIXB24((f)) - PIXB24((b))) * (a)) >> 8) + PIXB24((b))))
344 
345 #define ALPHALEVEL24(p, lv) (PIX24(((PIXR24(p) * (lv)) >> 8),\
346                                    ((PIXG24(p) * (lv)) >> 8),\
347                                    ((PIXB24(p) * (lv)) >> 8)))
348 
349 #define WHITELEVEL24(p, lv) ALPHABLEND24(0xffffffff, p, lv)
350 
351 #define SUTURADD15(pa, pb) PIX15(MIN(255,PIXR15(pa)+PIXR15(pb)), MIN(255, PIXG15(pa)+PIXG15(pb)), MIN(255, PIXB15(pa)+PIXB15(pb)));
352 #define SUTURADD16(pa, pb) PIX16(MIN(255,PIXR16(pa)+PIXR16(pb)), MIN(255, PIXG16(pa)+PIXG16(pb)), MIN(255, PIXB16(pa)+PIXB16(pb)));
353 //#define SUTURADD16(pa, pb) PIX16(MIN(255,(int)(PIXR16(pa))+(int)(PIXR16(pb))), MIN(255, (int)(PIXG16(pa))+(int)(PIXG16(pb))), MIN(255, (int)(PIXB16(pa))+(int)(PIXB16(pb))));
354 #define SUTURADD24(pa, pb) PIX24(MIN(255,PIXR24(pa)+PIXR24(pb)), MIN(255, PIXG24(pa)+PIXG24(pb)), MIN(255, PIXB24(pa)+PIXB24(pb)));
355 
356 
357 /* exter methods */
358 extern void ablend16_dpd(BYTE *, int, BYTE *, int, int, int, int, int);
359 extern void ablend16_ppd(BYTE *, BYTE *, BYTE *, int, int, int, int, int, int);
360 extern void ablend16_ppp(BYTE *, BYTE *, BYTE *, BYTE *, int, int, int, int, int, int, int);
361 
362 #endif /* !__AGS_H__ */
363