1 /*
2 * sprite_draw.c: ���ץ饤�Ⱥ�����Ƽ�
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: sprite_draw.c,v 1.4 2004/10/31 04:18:02 chikama Exp $ */
23
24 #include "config.h"
25
26 #include <stdio.h>
27 #include <string.h>
28 #include <glib.h>
29
30 #include "portab.h"
31 #include "system.h"
32 #include "ags.h"
33 #include "graphics.h"
34 #include "sact.h"
35 #include "surface.h"
36 #include "ngraph.h"
37 #include "sprite.h"
38
39 static void fill_dmap(int dx ,int dy, int w, int h, WORD val);
40 static void fill_dmap_mask(surface_t *src, int sx, int sy, int dx ,int dy, int w, int h, WORD val);
41
42
43
44 // ����� depthmap ������
fill_dmap(int dx,int dy,int w,int h,WORD val)45 static void fill_dmap(int dx ,int dy, int w, int h, WORD val) {
46 BYTE *dp, *dp_;
47 int x, y;
48
49 dp = dp_ = (GETOFFSET_PIXEL(sact.dmap, dx, dy));
50
51 for (x = 0; x < w; x++) {
52 *((WORD *)dp + x) = val;
53 }
54 dp += sact.dmap->bytes_per_line;
55
56 for (y = 1; y < h; y++) {
57 memcpy(dp, dp_, w * 2);
58 dp += sact.dmap->bytes_per_line;
59 }
60 }
61
62 // alphamap�ˤ������äơ�alpha�ͤ�0����礭���Ȥ��������depth�Ȥ���
fill_dmap_mask(surface_t * src,int sx,int sy,int dx,int dy,int w,int h,WORD val)63 static void fill_dmap_mask(surface_t *src, int sx, int sy, int dx ,int dy, int w, int h, WORD val) {
64 BYTE *sp, *dp;
65 int x, y;
66
67 dp = GETOFFSET_PIXEL(sact.dmap, dx, dy);
68 sp = GETOFFSET_ALPHA(src, sx, sy);
69
70 for (y = 0; y < h; y++) {
71 BYTE *yls = (BYTE *)(sp + y * src->width);
72 WORD *yld = (WORD *)(dp + y * sact.dmap->bytes_per_line);
73 for (x = 0; x < w; x++) {
74 if (*yls > 0) *yld = val;
75 yls++; yld++;
76 }
77 }
78 }
79
80 /*
81 ����� sprite (�θ��ߤ�CG)�� surface0 �˽�
82 @param sp: ���褹�륹�ץ饤��
83 */
sp_draw(sprite_t * sp)84 int sp_draw(sprite_t *sp) {
85 if (sp == NULL) return NG;
86
87 return sp_draw2(sp, sp->curcg);
88 }
89
90 /*
91 ����� sprite�λ����CG�� surface0 �˽�
92 (���Υ����ե������Ϥ⤦����?)
93
94 @param sp: ���褹�륹�ץ饤��
95 @param cg: ���褹��CG
96 */
sp_draw2(sprite_t * sp,cginfo_t * cg)97 int sp_draw2(sprite_t *sp, cginfo_t *cg) {
98 surface_t update;
99 int sx, sy, w, h, dx, dy;
100
101 if (cg == NULL) return NG;
102 if (cg->sf == NULL) return NG;
103
104 // �����ΰ�γ���
105 update.width = sact.updaterect.width;
106 update.height = sact.updaterect.height;
107 sx = 0;
108 sy = 0;
109 dx = sp->cur.x - sact.updaterect.x;
110 dy = sp->cur.y - sact.updaterect.y;
111 w = cg->sf->width;
112 h = cg->sf->height;
113
114 if (!gr_clip(cg->sf, &sx, &sy, &w, &h, &update, &dx, &dy)) {
115 return NG;
116 }
117
118 dx += sact.updaterect.x;
119 dy += sact.updaterect.y;
120
121 if (cg->sf->has_alpha) {
122 // alpha map ��������
123 gre_BlendUseAMap(sf0, dx, dy,
124 sf0, dx, dy,
125 cg->sf, sx, sy, w, h,
126 cg->sf, sx, sy,
127 sp->blendrate);
128 } else {
129 if (sp->blendrate == 255) {
130 // alpha�ͻ��̵꤬�����
131 gr_copy(sf0, dx, dy, cg->sf, sx, sy, w, h);
132 } else if (sp->blendrate > 0) {
133 // alpha�ͻ��꤬������
134 gre_Blend(sf0, dx, dy,
135 sf0, dx, dy,
136 cg->sf, sx, sy, w, h,
137 sp->blendrate);
138 }
139 }
140
141 WARNING("do update no=%d, sx=%d, sy=%d, w=%d, h=%d, dx=%d, dy=%d\n", sp->no, sx, sy, w, h, dx, dy);
142
143 return OK;
144 }
145
146 /*
147 ���ץ饤�ȥ����Ԥ��Ѥ�depthmap ��
148 */
sp_draw_dmap(gpointer data,gpointer userdata)149 void sp_draw_dmap(gpointer data, gpointer userdata) {
150 sprite_t *sp = (sprite_t *)data;
151 cginfo_t *cg;
152 surface_t update;
153 int sx, sy, w, h, dx, dy;
154
155 // ��ɽ�����֤λ���̵��
156 if (!sp->show) return;
157
158 // �ɥ�å���Υ��ץ饤�Ȥ�̵��
159 if (sp == sact.draggedsp) return;
160
161 cg = sp->curcg;
162 if (cg == NULL) return;
163 if (cg->sf == NULL) return;
164
165 // depth map ��������
166 update.width = sf0->width;
167 update.height = sf0->height;
168 sx = 0;
169 sy = 0;
170 dx = sp->cur.x;
171 dy = sp->cur.y;
172 w = cg->sf->width;
173 h = cg->sf->height;
174
175 if (!gr_clip(cg->sf, &sx, &sy, &w, &h, &update, &dx, &dy)) {
176 return;
177 }
178
179 if (cg->sf->has_alpha) {
180 fill_dmap_mask(cg->sf, sx, sy, dx, dy, w, h, sp->no);
181 } else {
182 fill_dmap(dx, dy, w, h, sp->no);
183 }
184
185 return;
186 }
187