annotate window/picture.cc @ 21:d1bb7b365816

Fixed dynamic strings in selections (Fuko Pranks for instance)
author thib
date Fri, 31 Oct 2008 14:30:37 +0000
parents 223b71206888
children 97b752b43502
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28 #include<stdio.h>
223b71206888 Initial import
thib
parents:
diff changeset
29 #include<vector>
223b71206888 Initial import
thib
parents:
diff changeset
30 #include<list>
223b71206888 Initial import
thib
parents:
diff changeset
31 #include<algorithm>
223b71206888 Initial import
thib
parents:
diff changeset
32
223b71206888 Initial import
thib
parents:
diff changeset
33 #include"rect.h"
223b71206888 Initial import
thib
parents:
diff changeset
34 #include"event.h"
223b71206888 Initial import
thib
parents:
diff changeset
35 #include"font/font.h"
223b71206888 Initial import
thib
parents:
diff changeset
36 #include"font/text.h"
223b71206888 Initial import
thib
parents:
diff changeset
37 #include"SDL_rotozoom.h"
223b71206888 Initial import
thib
parents:
diff changeset
38 #include"system/file.h"
223b71206888 Initial import
thib
parents:
diff changeset
39
223b71206888 Initial import
thib
parents:
diff changeset
40 #include"picture.h"
223b71206888 Initial import
thib
parents:
diff changeset
41
223b71206888 Initial import
thib
parents:
diff changeset
42 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
43
223b71206888 Initial import
thib
parents:
diff changeset
44 int print_blit=0;
223b71206888 Initial import
thib
parents:
diff changeset
45 inline void dprintf(const char* fmt, ...) {}
223b71206888 Initial import
thib
parents:
diff changeset
46 /* render.cc */
223b71206888 Initial import
thib
parents:
diff changeset
47 void DSurfaceBlitAlpha(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, const unsigned char* alpha, const Rect& alpharect);
223b71206888 Initial import
thib
parents:
diff changeset
48 void DSurfaceBlitSaturate(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect, unsigned char alpha);
223b71206888 Initial import
thib
parents:
diff changeset
49 void DSurfaceBlitMultiply(Surface* src_o, const Rect& srcrect, Surface* dst_o, const Rect& dstrect);
223b71206888 Initial import
thib
parents:
diff changeset
50 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a=0xff); // クリア
223b71206888 Initial import
thib
parents:
diff changeset
51 #if 0 /* DEBUG */
223b71206888 Initial import
thib
parents:
diff changeset
52 #include<sys/types.h>
223b71206888 Initial import
thib
parents:
diff changeset
53 #include<sys/time.h>
223b71206888 Initial import
thib
parents:
diff changeset
54 #define dprintf printf
223b71206888 Initial import
thib
parents:
diff changeset
55 static struct timeval tv;
223b71206888 Initial import
thib
parents:
diff changeset
56 void gettm(void) {
223b71206888 Initial import
thib
parents:
diff changeset
57 gettimeofday(&tv, 0);
223b71206888 Initial import
thib
parents:
diff changeset
58 }
223b71206888 Initial import
thib
parents:
diff changeset
59 int calctm(void) {
223b71206888 Initial import
thib
parents:
diff changeset
60 struct timeval tv2;
223b71206888 Initial import
thib
parents:
diff changeset
61 gettimeofday(&tv2, 0);
223b71206888 Initial import
thib
parents:
diff changeset
62 int n = (tv2.tv_sec-tv.tv_sec)*100000 + (tv2.tv_usec-tv.tv_usec)/10;
223b71206888 Initial import
thib
parents:
diff changeset
63 return n;
223b71206888 Initial import
thib
parents:
diff changeset
64 }
223b71206888 Initial import
thib
parents:
diff changeset
65 #endif
223b71206888 Initial import
thib
parents:
diff changeset
66
223b71206888 Initial import
thib
parents:
diff changeset
67 /******************************************
223b71206888 Initial import
thib
parents:
diff changeset
68 ** PicBase
223b71206888 Initial import
thib
parents:
diff changeset
69 */
223b71206888 Initial import
thib
parents:
diff changeset
70 PicBase::PicBase(const Rect& _rel_pos, PicContainer* _parent, int _attr) :
223b71206888 Initial import
thib
parents:
diff changeset
71 parent(_parent), rel_pos(_rel_pos), rel_solid_area(0,0,0,0), clip_area(0,0,0,0),
223b71206888 Initial import
thib
parents:
diff changeset
72 is_hidden(true), is_hidden_now(true), is_cached(false), attribute(_attr), surface_alpha_rect(0,0) {
223b71206888 Initial import
thib
parents:
diff changeset
73
223b71206888 Initial import
thib
parents:
diff changeset
74 if (parent) root = parent->root;
223b71206888 Initial import
thib
parents:
diff changeset
75 else root = 0;
223b71206888 Initial import
thib
parents:
diff changeset
76 surface_back = 0;
223b71206888 Initial import
thib
parents:
diff changeset
77 surface_own = 0;
223b71206888 Initial import
thib
parents:
diff changeset
78 surface_alpha = 0;
223b71206888 Initial import
thib
parents:
diff changeset
79 surface_x = 0; surface_y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
80 surface_w = -1; surface_h = -1;
223b71206888 Initial import
thib
parents:
diff changeset
81 widget = 0;
223b71206888 Initial import
thib
parents:
diff changeset
82 attribute |= NO_PICTURE;
223b71206888 Initial import
thib
parents:
diff changeset
83 if ( (attribute & CACHE_BACK) && root) {
223b71206888 Initial import
thib
parents:
diff changeset
84 surface_back = root->NewSurface(rel_pos.width(), rel_pos.height(), NO_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
85 }
223b71206888 Initial import
thib
parents:
diff changeset
86
223b71206888 Initial import
thib
parents:
diff changeset
87 if (parent) {
223b71206888 Initial import
thib
parents:
diff changeset
88 parent->children.push_back(this);
223b71206888 Initial import
thib
parents:
diff changeset
89 z_pos = parent->children.end(); z_pos--;
223b71206888 Initial import
thib
parents:
diff changeset
90 distance_root = parent->DistanceRoot() + 1;
223b71206888 Initial import
thib
parents:
diff changeset
91 } else {
223b71206888 Initial import
thib
parents:
diff changeset
92 distance_root = 1;
223b71206888 Initial import
thib
parents:
diff changeset
93 }
223b71206888 Initial import
thib
parents:
diff changeset
94 }
223b71206888 Initial import
thib
parents:
diff changeset
95 PicBase::~PicBase() {
223b71206888 Initial import
thib
parents:
diff changeset
96 ClearAnm();
223b71206888 Initial import
thib
parents:
diff changeset
97 if (widget) {
223b71206888 Initial import
thib
parents:
diff changeset
98 fprintf(stderr,"Warning: PicBase::~PicBase: surface is disallocated but widget is still alive.\n");
223b71206888 Initial import
thib
parents:
diff changeset
99 widget->deactivate();
223b71206888 Initial import
thib
parents:
diff changeset
100 }
223b71206888 Initial import
thib
parents:
diff changeset
101 if (surface_back) root->DeleteSurface(surface_back);
223b71206888 Initial import
thib
parents:
diff changeset
102 if (surface_own && (attribute & SURFACE_FREE)) root->DeleteSurface(surface_own);
223b71206888 Initial import
thib
parents:
diff changeset
103 if (surface_alpha && (attribute & ALPHA_FREE)) delete surface_alpha;
223b71206888 Initial import
thib
parents:
diff changeset
104 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
105 if (parent) { // 自分を親から削除
223b71206888 Initial import
thib
parents:
diff changeset
106 parent->children.remove(this);
223b71206888 Initial import
thib
parents:
diff changeset
107 // root の update 情報から自分を削除
223b71206888 Initial import
thib
parents:
diff changeset
108 parent->Root().DeleteUpdatePic(this);
223b71206888 Initial import
thib
parents:
diff changeset
109 // 自分の領域を書き直す
223b71206888 Initial import
thib
parents:
diff changeset
110 Rect old_ppos = rel_pos;
223b71206888 Initial import
thib
parents:
diff changeset
111 parent->QueryAbsPos(old_ppos);
223b71206888 Initial import
thib
parents:
diff changeset
112 parent->ReBlit(old_ppos);
223b71206888 Initial import
thib
parents:
diff changeset
113 }
223b71206888 Initial import
thib
parents:
diff changeset
114 }
223b71206888 Initial import
thib
parents:
diff changeset
115 void PicBase::Blit(const Rect& rpos_orig) {
223b71206888 Initial import
thib
parents:
diff changeset
116 // 実際に描画する領域を得る
223b71206888 Initial import
thib
parents:
diff changeset
117 Rect rpos = rpos_orig;
223b71206888 Initial import
thib
parents:
diff changeset
118 // 親widget上に設定されたclip area 内に描画を限定する
223b71206888 Initial import
thib
parents:
diff changeset
119 if (clip_area.width() != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
120 Rect clip = clip_area;
223b71206888 Initial import
thib
parents:
diff changeset
121 clip = child_pos(clip, this);
223b71206888 Initial import
thib
parents:
diff changeset
122 rpos.intersect(clip);
223b71206888 Initial import
thib
parents:
diff changeset
123 }
223b71206888 Initial import
thib
parents:
diff changeset
124 Rect apos = QueryAbsPos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
125 if (rpos.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
126 // 必要に応じて保存、描画
223b71206888 Initial import
thib
parents:
diff changeset
127 if (attribute & CACHE_BACK) root->BlitSurface(root->surface, apos, surface_back, rpos);
223b71206888 Initial import
thib
parents:
diff changeset
128 if (! (attribute & NO_PICTURE)) {
223b71206888 Initial import
thib
parents:
diff changeset
129 rpos.rmove(surface_x, surface_y);
223b71206888 Initial import
thib
parents:
diff changeset
130 if (surface_w >= 0 && surface_h >= 0) {
223b71206888 Initial import
thib
parents:
diff changeset
131 Rect clip(surface_x, surface_y, surface_x+surface_w, surface_y+surface_h);
223b71206888 Initial import
thib
parents:
diff changeset
132 rpos.intersect(clip);
223b71206888 Initial import
thib
parents:
diff changeset
133 }
223b71206888 Initial import
thib
parents:
diff changeset
134 //if (apos.ty < 200) fprintf(stderr,"Blit: %08x : (%d,%d,%d,%d) -> (%d,%d,%d,%d)\n",surface_own,rpos_orig.lx,rpos_orig.ty,rpos_orig.rx,rpos_orig.by,apos.lx,apos.ty,apos.rx,apos.by);
223b71206888 Initial import
thib
parents:
diff changeset
135 root->BlitSurface(surface_own, rpos, surface_alpha, surface_alpha_rect, root->surface, apos, attribute);
223b71206888 Initial import
thib
parents:
diff changeset
136 rpos.rmove(-surface_x, -surface_y);
223b71206888 Initial import
thib
parents:
diff changeset
137 } else if (parent == 0) { // 親がいないなら背景消去の責任をもつ
223b71206888 Initial import
thib
parents:
diff changeset
138 DSurfaceFill(root->surface, apos, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
139 }
223b71206888 Initial import
thib
parents:
diff changeset
140 PicContainer* cur = dynamic_cast<PicContainer*>(this);
223b71206888 Initial import
thib
parents:
diff changeset
141 if (cur && (!cur->children.empty())) {
223b71206888 Initial import
thib
parents:
diff changeset
142 cur->BlitChildren(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
143 }
223b71206888 Initial import
thib
parents:
diff changeset
144 }
223b71206888 Initial import
thib
parents:
diff changeset
145 void PicBase::SimpleBlit(Surface* screen) {
223b71206888 Initial import
thib
parents:
diff changeset
146 // 実際に描画する領域を得る
223b71206888 Initial import
thib
parents:
diff changeset
147 Rect rpos(0, 0, rel_pos.width(), rel_pos.height());
223b71206888 Initial import
thib
parents:
diff changeset
148 Rect apos = QueryAbsPos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
149 if (rpos.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
150 rpos.rmove(surface_x, surface_y);
223b71206888 Initial import
thib
parents:
diff changeset
151 if (surface_w >= 0 && surface_h >= 0) {
223b71206888 Initial import
thib
parents:
diff changeset
152 Rect clip(surface_x, surface_y, surface_x+surface_w, surface_y+surface_h);
223b71206888 Initial import
thib
parents:
diff changeset
153 rpos.intersect(clip);
223b71206888 Initial import
thib
parents:
diff changeset
154 }
223b71206888 Initial import
thib
parents:
diff changeset
155 //if (apos.ty < 200) fprintf(stderr,"S-Blit: %08x : (%d,%d,%d,%d) -> (%d,%d,%d,%d)\n",surface_own,rel_pos.lx,rel_pos.ty,rel_pos.rx,rel_pos.by,apos.lx,apos.ty,apos.rx,apos.by);
223b71206888 Initial import
thib
parents:
diff changeset
156 root->BlitSurface(surface_own, rpos, surface_alpha, surface_alpha_rect, screen, apos, attribute);
223b71206888 Initial import
thib
parents:
diff changeset
157 }
223b71206888 Initial import
thib
parents:
diff changeset
158
223b71206888 Initial import
thib
parents:
diff changeset
159 Rect PicBase::QueryAbsPos(Rect& rpos) {
223b71206888 Initial import
thib
parents:
diff changeset
160 rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height()));
223b71206888 Initial import
thib
parents:
diff changeset
161 if (parent == 0) { // root container
223b71206888 Initial import
thib
parents:
diff changeset
162 return rpos;
223b71206888 Initial import
thib
parents:
diff changeset
163 }
223b71206888 Initial import
thib
parents:
diff changeset
164 // 親の座標に変換後、Query する
223b71206888 Initial import
thib
parents:
diff changeset
165 Rect ppos = parent_pos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
166 Rect apos = parent->QueryAbsPos(ppos);
223b71206888 Initial import
thib
parents:
diff changeset
167 rpos = child_pos(ppos, this);
223b71206888 Initial import
thib
parents:
diff changeset
168 return apos;
223b71206888 Initial import
thib
parents:
diff changeset
169 };
223b71206888 Initial import
thib
parents:
diff changeset
170 void PicBase::ReBlit(const Rect& rpos_c) {
223b71206888 Initial import
thib
parents:
diff changeset
171 Rect rpos = rpos_c;
223b71206888 Initial import
thib
parents:
diff changeset
172 Rect apos = QueryAbsPos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
173
223b71206888 Initial import
thib
parents:
diff changeset
174 root->Update(this, rpos, apos);
223b71206888 Initial import
thib
parents:
diff changeset
175 }
223b71206888 Initial import
thib
parents:
diff changeset
176 void PicBase::ExecReBlit(const Rect& rpos_c) {
223b71206888 Initial import
thib
parents:
diff changeset
177 Rect rpos = rpos_c;
223b71206888 Initial import
thib
parents:
diff changeset
178 Rect abs_r = QueryAbsPos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
179 Rect ppos = parent_pos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
180 if(print_blit) fprintf(stderr,"back.");
223b71206888 Initial import
thib
parents:
diff changeset
181 if (parent) parent->BlitBack(z_pos, ppos);
223b71206888 Initial import
thib
parents:
diff changeset
182 if(print_blit) fprintf(stderr,"self.");
223b71206888 Initial import
thib
parents:
diff changeset
183 if (!is_hidden_now) Blit(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
184 if(print_blit) fprintf(stderr,"front.");
223b71206888 Initial import
thib
parents:
diff changeset
185 if (parent) parent->BlitFront(z_pos, ppos);
223b71206888 Initial import
thib
parents:
diff changeset
186 if(print_blit) fprintf(stderr,"end.");
223b71206888 Initial import
thib
parents:
diff changeset
187 }
223b71206888 Initial import
thib
parents:
diff changeset
188
223b71206888 Initial import
thib
parents:
diff changeset
189 void PicBase::ZMove(PicBase* move_to) {
223b71206888 Initial import
thib
parents:
diff changeset
190 if (parent == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
191 fprintf(stderr,"Warning: PicBase::ZMove is called by root.\n");
223b71206888 Initial import
thib
parents:
diff changeset
192 return;
223b71206888 Initial import
thib
parents:
diff changeset
193 }
223b71206888 Initial import
thib
parents:
diff changeset
194 if (move_to == ZMOVE_TOP) {
223b71206888 Initial import
thib
parents:
diff changeset
195 if (this == parent->children.back()) return;
223b71206888 Initial import
thib
parents:
diff changeset
196 } else if (move_to == ZMOVE_BOTTOM) {
223b71206888 Initial import
thib
parents:
diff changeset
197 if (this == parent->children.front()) return;
223b71206888 Initial import
thib
parents:
diff changeset
198 } else if (move_to == this) {
223b71206888 Initial import
thib
parents:
diff changeset
199 fprintf(stderr,"Error: PicBase::ZMove : move in front of itself!\n");
223b71206888 Initial import
thib
parents:
diff changeset
200 return;
223b71206888 Initial import
thib
parents:
diff changeset
201 } else if (move_to && move_to->parent != parent) {
223b71206888 Initial import
thib
parents:
diff changeset
202 fprintf(stderr,"Error: PicBase::ZMove was called with a no-brother picture\n");
223b71206888 Initial import
thib
parents:
diff changeset
203 return;
223b71206888 Initial import
thib
parents:
diff changeset
204 }
223b71206888 Initial import
thib
parents:
diff changeset
205 // move_to と zpos のうち、後ろの方の picture から書きなおす必要がある
223b71206888 Initial import
thib
parents:
diff changeset
206 iterator redraw_zpos = z_pos; redraw_zpos++;
223b71206888 Initial import
thib
parents:
diff changeset
207 if (move_to == ZMOVE_BOTTOM) { // 最背面へ
223b71206888 Initial import
thib
parents:
diff changeset
208 parent->children.erase(z_pos);
223b71206888 Initial import
thib
parents:
diff changeset
209 parent->children.push_front(this);
223b71206888 Initial import
thib
parents:
diff changeset
210 z_pos = parent->children.begin();
223b71206888 Initial import
thib
parents:
diff changeset
211 redraw_zpos = parent->children.begin();
223b71206888 Initial import
thib
parents:
diff changeset
212 } else if (move_to == ZMOVE_TOP) { // 最前面へ
223b71206888 Initial import
thib
parents:
diff changeset
213 redraw_zpos = z_pos; redraw_zpos++;
223b71206888 Initial import
thib
parents:
diff changeset
214 parent->children.erase(z_pos);
223b71206888 Initial import
thib
parents:
diff changeset
215 parent->children.push_back(this);
223b71206888 Initial import
thib
parents:
diff changeset
216 z_pos = parent->children.end(); z_pos--;
223b71206888 Initial import
thib
parents:
diff changeset
217 } else {
223b71206888 Initial import
thib
parents:
diff changeset
218 int dis_to = distance(move_to->parent->children.begin(), move_to->z_pos);
223b71206888 Initial import
thib
parents:
diff changeset
219 int dis_cur = distance(parent->children.begin(), z_pos);
223b71206888 Initial import
thib
parents:
diff changeset
220 if (dis_cur < dis_to) redraw_zpos = move_to->z_pos;
223b71206888 Initial import
thib
parents:
diff changeset
221 parent->children.erase(z_pos);
223b71206888 Initial import
thib
parents:
diff changeset
222 iterator insert_pos = move_to->z_pos; insert_pos++;
223b71206888 Initial import
thib
parents:
diff changeset
223 parent->children.insert(insert_pos, this);
223b71206888 Initial import
thib
parents:
diff changeset
224 z_pos = move_to->z_pos; z_pos++;
223b71206888 Initial import
thib
parents:
diff changeset
225 }
223b71206888 Initial import
thib
parents:
diff changeset
226 if (! is_hidden_now) {
223b71206888 Initial import
thib
parents:
diff changeset
227 is_cached = false;
223b71206888 Initial import
thib
parents:
diff changeset
228 ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
229 /* @@@ parent->Blit() と Blit() の違いが分からないので修正 06/12/02
223b71206888 Initial import
thib
parents:
diff changeset
230 Rect ppos = rel_pos;
223b71206888 Initial import
thib
parents:
diff changeset
231 parent->QueryAbsPos(ppos);
223b71206888 Initial import
thib
parents:
diff changeset
232 parent->ReBlit(ppos);
223b71206888 Initial import
thib
parents:
diff changeset
233 */
223b71206888 Initial import
thib
parents:
diff changeset
234 }
223b71206888 Initial import
thib
parents:
diff changeset
235 };
223b71206888 Initial import
thib
parents:
diff changeset
236 void PicBase::RMove(int add_x, int add_y) {
223b71206888 Initial import
thib
parents:
diff changeset
237 Rect old_ppos = rel_pos;
223b71206888 Initial import
thib
parents:
diff changeset
238 rel_pos.rmove(add_x, add_y);
223b71206888 Initial import
thib
parents:
diff changeset
239 parent->QueryAbsPos(old_ppos);
223b71206888 Initial import
thib
parents:
diff changeset
240 parent->ReBlit(old_ppos);
223b71206888 Initial import
thib
parents:
diff changeset
241 ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
242
223b71206888 Initial import
thib
parents:
diff changeset
243 if (widget) {
223b71206888 Initial import
thib
parents:
diff changeset
244 Rect new_ppos = rel_pos;
223b71206888 Initial import
thib
parents:
diff changeset
245 Rect new_apos = parent->QueryAbsPos(new_ppos);
223b71206888 Initial import
thib
parents:
diff changeset
246 widget->SetRegion(new_apos);
223b71206888 Initial import
thib
parents:
diff changeset
247 }
223b71206888 Initial import
thib
parents:
diff changeset
248 }
223b71206888 Initial import
thib
parents:
diff changeset
249 void PicBase::Move(int new_rx, int new_ry) {
223b71206888 Initial import
thib
parents:
diff changeset
250 RMove(new_rx-rel_pos.lx, new_ry-rel_pos.ty);
223b71206888 Initial import
thib
parents:
diff changeset
251 }
223b71206888 Initial import
thib
parents:
diff changeset
252 void PicBase::SetEventWidget(PicWidget* new_widget) {
223b71206888 Initial import
thib
parents:
diff changeset
253 widget = new_widget;
223b71206888 Initial import
thib
parents:
diff changeset
254 if (widget) {
223b71206888 Initial import
thib
parents:
diff changeset
255 Rect new_ppos = rel_pos;
223b71206888 Initial import
thib
parents:
diff changeset
256 Rect apos = parent->QueryAbsPos(new_ppos);
223b71206888 Initial import
thib
parents:
diff changeset
257 widget->SetRegion(apos);
223b71206888 Initial import
thib
parents:
diff changeset
258 }
223b71206888 Initial import
thib
parents:
diff changeset
259 }
223b71206888 Initial import
thib
parents:
diff changeset
260 void PicBase::show_all(void) {
223b71206888 Initial import
thib
parents:
diff changeset
261 PicContainer* cont = dynamic_cast<PicContainer*>(this);
223b71206888 Initial import
thib
parents:
diff changeset
262 if (cont && (!cont->children.empty())) cont->set_showflag();
223b71206888 Initial import
thib
parents:
diff changeset
263 show();
223b71206888 Initial import
thib
parents:
diff changeset
264 }
223b71206888 Initial import
thib
parents:
diff changeset
265 bool PicBase::IsParent(PicBase* to) {
223b71206888 Initial import
thib
parents:
diff changeset
266 if (parent == 0) return false;
223b71206888 Initial import
thib
parents:
diff changeset
267 if (parent == to) return true;
223b71206888 Initial import
thib
parents:
diff changeset
268 return parent->IsParent(to);
223b71206888 Initial import
thib
parents:
diff changeset
269 }
223b71206888 Initial import
thib
parents:
diff changeset
270 void PicBase::show(void) {
223b71206888 Initial import
thib
parents:
diff changeset
271 /* 自分の親がすべて shown か? */
223b71206888 Initial import
thib
parents:
diff changeset
272 PicContainer* cur;
223b71206888 Initial import
thib
parents:
diff changeset
273 for (cur = parent; cur != 0; cur = cur->parent)
223b71206888 Initial import
thib
parents:
diff changeset
274 if (cur->is_hidden) break;
223b71206888 Initial import
thib
parents:
diff changeset
275 if (cur) { // 親が隠れているので表示はしない
223b71206888 Initial import
thib
parents:
diff changeset
276 is_hidden = false;
223b71206888 Initial import
thib
parents:
diff changeset
277 is_hidden_now = true;
223b71206888 Initial import
thib
parents:
diff changeset
278 return;
223b71206888 Initial import
thib
parents:
diff changeset
279 }
223b71206888 Initial import
thib
parents:
diff changeset
280 if (is_hidden == false) return; // すでに表示されているのでなにもしない
223b71206888 Initial import
thib
parents:
diff changeset
281 if (widget) {
223b71206888 Initial import
thib
parents:
diff changeset
282 widget->activate();
223b71206888 Initial import
thib
parents:
diff changeset
283 }
223b71206888 Initial import
thib
parents:
diff changeset
284 is_hidden = false;
223b71206888 Initial import
thib
parents:
diff changeset
285 is_hidden_now = false;
223b71206888 Initial import
thib
parents:
diff changeset
286 is_cached = false;
223b71206888 Initial import
thib
parents:
diff changeset
287 cur = dynamic_cast<PicContainer*>(this);
223b71206888 Initial import
thib
parents:
diff changeset
288 if (cur && (!cur->children.empty())) cur->set_nowhiddenflag(false);
223b71206888 Initial import
thib
parents:
diff changeset
289 ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
290 }
223b71206888 Initial import
thib
parents:
diff changeset
291 void PicBase::hide(void) {
223b71206888 Initial import
thib
parents:
diff changeset
292 if (is_hidden) return;
223b71206888 Initial import
thib
parents:
diff changeset
293 if (widget) {
223b71206888 Initial import
thib
parents:
diff changeset
294 widget->deactivate();
223b71206888 Initial import
thib
parents:
diff changeset
295 }
223b71206888 Initial import
thib
parents:
diff changeset
296 is_hidden = true;
223b71206888 Initial import
thib
parents:
diff changeset
297 is_hidden_now = true;
223b71206888 Initial import
thib
parents:
diff changeset
298 is_cached = false;
223b71206888 Initial import
thib
parents:
diff changeset
299 PicContainer* cur = dynamic_cast<PicContainer*>(this);
223b71206888 Initial import
thib
parents:
diff changeset
300 if (cur && (!cur->children.empty())) cur->set_nowhiddenflag(true);
223b71206888 Initial import
thib
parents:
diff changeset
301 ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
302 }
223b71206888 Initial import
thib
parents:
diff changeset
303 void PicBase::SetSurfaceAlpha(const unsigned char* alpha, const Rect& alpha_r) {
223b71206888 Initial import
thib
parents:
diff changeset
304 if (attribute & ALPHA_FREE) {
223b71206888 Initial import
thib
parents:
diff changeset
305 if (surface_alpha) delete[] surface_alpha;
223b71206888 Initial import
thib
parents:
diff changeset
306 surface_alpha = 0;
223b71206888 Initial import
thib
parents:
diff changeset
307 }
223b71206888 Initial import
thib
parents:
diff changeset
308 surface_alpha = alpha;
223b71206888 Initial import
thib
parents:
diff changeset
309 surface_alpha_rect = alpha_r;
223b71206888 Initial import
thib
parents:
diff changeset
310 if (!is_hidden) ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
311 }
223b71206888 Initial import
thib
parents:
diff changeset
312 void PicBase::SetSurfaceColorKey(int r, int g, int b) {
223b71206888 Initial import
thib
parents:
diff changeset
313 surface_alpha = 0;
223b71206888 Initial import
thib
parents:
diff changeset
314 surface_alpha_rect = Rect(0,0);
223b71206888 Initial import
thib
parents:
diff changeset
315 attribute &= ~(BLIT_SATURATE | BLIT_MULTIPLY);
223b71206888 Initial import
thib
parents:
diff changeset
316 if (surface_own) {
223b71206888 Initial import
thib
parents:
diff changeset
317 int key = SDL_MapRGB( ((SDL_Surface*)surface_own)->format, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
318 key |= 0xff000000;
223b71206888 Initial import
thib
parents:
diff changeset
319 SDL_SetColorKey( (SDL_Surface*)surface_own, SDL_SRCCOLORKEY, key);
223b71206888 Initial import
thib
parents:
diff changeset
320 }
223b71206888 Initial import
thib
parents:
diff changeset
321 if (!is_hidden) ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
322 }
223b71206888 Initial import
thib
parents:
diff changeset
323 void PicBase::SetSurfaceAlphaFile(const char* file) {
223b71206888 Initial import
thib
parents:
diff changeset
324
223b71206888 Initial import
thib
parents:
diff changeset
325 /* ファイルを元に alpha 画像を作成する */
223b71206888 Initial import
thib
parents:
diff changeset
326 /* ファイル: パルフェの 'fil' ファイル */
223b71206888 Initial import
thib
parents:
diff changeset
327 ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, file,"fil");
223b71206888 Initial import
thib
parents:
diff changeset
328 if (info == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
329 char* new_alpha = info->CopyRead();
223b71206888 Initial import
thib
parents:
diff changeset
330 int alpha_size = info->Size();
223b71206888 Initial import
thib
parents:
diff changeset
331 delete info;
223b71206888 Initial import
thib
parents:
diff changeset
332 Rect sr(0,0); int w,h;
223b71206888 Initial import
thib
parents:
diff changeset
333 if (surface_own == 0 || new_alpha == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
334 err_ret:
223b71206888 Initial import
thib
parents:
diff changeset
335 if (new_alpha) delete[] new_alpha;
223b71206888 Initial import
thib
parents:
diff changeset
336 SetSurfaceAlpha(0,Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
337 return;
223b71206888 Initial import
thib
parents:
diff changeset
338 }
223b71206888 Initial import
thib
parents:
diff changeset
339 sr = Rect(*surface_own);
223b71206888 Initial import
thib
parents:
diff changeset
340 w = sr.width();
223b71206888 Initial import
thib
parents:
diff changeset
341 h = sr.height();
223b71206888 Initial import
thib
parents:
diff changeset
342 if (alpha_size < w*h) goto err_ret;
223b71206888 Initial import
thib
parents:
diff changeset
343 int i,j;
223b71206888 Initial import
thib
parents:
diff changeset
344 if ( ((SDL_Surface*)surface_own)->format->Amask == 0) { // mask を surface に繰り込む
223b71206888 Initial import
thib
parents:
diff changeset
345 Surface* dest = root->NewSurface(w,h, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
346 for (i=0; i<h; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
347 char* a = new_alpha + w*i;
223b71206888 Initial import
thib
parents:
diff changeset
348 char* s = (char*)((SDL_Surface*)surface_own)->pixels + ((SDL_Surface*)surface_own)->pitch*i;
223b71206888 Initial import
thib
parents:
diff changeset
349 char* d = (char*)((SDL_Surface*)dest)->pixels + ((SDL_Surface*)dest)->pitch*i;
223b71206888 Initial import
thib
parents:
diff changeset
350 int sbpp = ((SDL_Surface*)surface_own)->format->BytesPerPixel;
223b71206888 Initial import
thib
parents:
diff changeset
351 int dbpp = ((SDL_Surface*)dest)->format->BytesPerPixel;
223b71206888 Initial import
thib
parents:
diff changeset
352
223b71206888 Initial import
thib
parents:
diff changeset
353 for (j=0; j<w; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
354 int d = read_little_endian_int(s);
223b71206888 Initial import
thib
parents:
diff changeset
355 d &= 0xffffff;
223b71206888 Initial import
thib
parents:
diff changeset
356 if (d == 0) ;
223b71206888 Initial import
thib
parents:
diff changeset
357 else if (*a == 0) d |= 0xff000000;
223b71206888 Initial import
thib
parents:
diff changeset
358 else d |= (int(*a) << 24);
223b71206888 Initial import
thib
parents:
diff changeset
359 s += sbpp; d += dbpp; a++;
223b71206888 Initial import
thib
parents:
diff changeset
360 }
223b71206888 Initial import
thib
parents:
diff changeset
361 }
223b71206888 Initial import
thib
parents:
diff changeset
362 delete new_alpha;
223b71206888 Initial import
thib
parents:
diff changeset
363 root->DeleteSurface(surface_own);
223b71206888 Initial import
thib
parents:
diff changeset
364 surface_own = dest;
223b71206888 Initial import
thib
parents:
diff changeset
365 SetSurfaceAlpha(0, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
366 } else { // 外部にマスク作成
223b71206888 Initial import
thib
parents:
diff changeset
367 /* マスクのうち、0xff であるべき部分を画像から判別、変更する */
223b71206888 Initial import
thib
parents:
diff changeset
368 for (i=0; i<h; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
369 char* a = new_alpha + w*i;
223b71206888 Initial import
thib
parents:
diff changeset
370 char* s = (char*)((SDL_Surface*)surface_own)->pixels + ((SDL_Surface*)surface_own)->pitch*i;
223b71206888 Initial import
thib
parents:
diff changeset
371 int bpp = ((SDL_Surface*)surface_own)->format->BytesPerPixel;
223b71206888 Initial import
thib
parents:
diff changeset
372 for (j=0; j<w; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
373 if ( ((*(int*)s) & 0xffffff) == 0) *a = 0;
223b71206888 Initial import
thib
parents:
diff changeset
374 else if (*a == 0) *a = 0xff;
223b71206888 Initial import
thib
parents:
diff changeset
375 s += bpp; a++;
223b71206888 Initial import
thib
parents:
diff changeset
376 }
223b71206888 Initial import
thib
parents:
diff changeset
377 }
223b71206888 Initial import
thib
parents:
diff changeset
378 SetSurfaceAlpha( (unsigned char*)new_alpha, Rect(0,0,w,h));
223b71206888 Initial import
thib
parents:
diff changeset
379 attribute |= ALPHA_FREE;
223b71206888 Initial import
thib
parents:
diff changeset
380 }
223b71206888 Initial import
thib
parents:
diff changeset
381 }
223b71206888 Initial import
thib
parents:
diff changeset
382 void PicBase::SetSurface(const char* filename, int x, int y) {
223b71206888 Initial import
thib
parents:
diff changeset
383 Surface* s = root->NewSurface(filename);
223b71206888 Initial import
thib
parents:
diff changeset
384 SetSurface(s, x, y, SURFACE_FREE);
223b71206888 Initial import
thib
parents:
diff changeset
385 }
223b71206888 Initial import
thib
parents:
diff changeset
386 void PicBase::SetSurface(Surface* new_surface, int x, int y, int new_attr) {
223b71206888 Initial import
thib
parents:
diff changeset
387 if (surface_own && (attribute & SURFACE_FREE)) {
223b71206888 Initial import
thib
parents:
diff changeset
388 root->DeleteSurface(surface_own);
223b71206888 Initial import
thib
parents:
diff changeset
389 }
223b71206888 Initial import
thib
parents:
diff changeset
390 attribute &= ~(SURFACE_FREE | BLIT_SATURATE | BLIT_MULTIPLY | NO_PICTURE | SOLID);
223b71206888 Initial import
thib
parents:
diff changeset
391 attribute |= new_attr;
223b71206888 Initial import
thib
parents:
diff changeset
392 surface_own = new_surface;
223b71206888 Initial import
thib
parents:
diff changeset
393 surface_x = x;
223b71206888 Initial import
thib
parents:
diff changeset
394 surface_y = y;
223b71206888 Initial import
thib
parents:
diff changeset
395 surface_w = -1;
223b71206888 Initial import
thib
parents:
diff changeset
396 surface_h = -1;
223b71206888 Initial import
thib
parents:
diff changeset
397
223b71206888 Initial import
thib
parents:
diff changeset
398 if (attribute & FIT_SURFACE) {
223b71206888 Initial import
thib
parents:
diff changeset
399 // surface の大きさに自分の大きさを変更
223b71206888 Initial import
thib
parents:
diff changeset
400 parent->ReBlit(rel_pos);
223b71206888 Initial import
thib
parents:
diff changeset
401 if (surface_own == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
402 rel_pos = Rect(rel_pos.lx, rel_pos.ty);
223b71206888 Initial import
thib
parents:
diff changeset
403 } else {
223b71206888 Initial import
thib
parents:
diff changeset
404 Rect r(*surface_own);
223b71206888 Initial import
thib
parents:
diff changeset
405 int w = r.width(), h = r.height();
223b71206888 Initial import
thib
parents:
diff changeset
406 w -= x; h -= y;
223b71206888 Initial import
thib
parents:
diff changeset
407 rel_pos = Rect(rel_pos.lx, rel_pos.ty, rel_pos.lx+w, rel_pos.ty+h);
223b71206888 Initial import
thib
parents:
diff changeset
408 }
223b71206888 Initial import
thib
parents:
diff changeset
409 }
223b71206888 Initial import
thib
parents:
diff changeset
410
223b71206888 Initial import
thib
parents:
diff changeset
411 rel_solid_area = Rect(0,0,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
412 if (! surface_own) attribute |= NO_PICTURE;
223b71206888 Initial import
thib
parents:
diff changeset
413 else if (root->with_mask(surface_own) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
414 attribute |= SOLID;
223b71206888 Initial import
thib
parents:
diff changeset
415 rel_solid_area = rel_pos;
223b71206888 Initial import
thib
parents:
diff changeset
416 }
223b71206888 Initial import
thib
parents:
diff changeset
417 if (!is_hidden) ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
418 }
223b71206888 Initial import
thib
parents:
diff changeset
419 void PicBase::SetSurfacePos(int x, int y) {
223b71206888 Initial import
thib
parents:
diff changeset
420 if (surface_x == x && surface_y == y && surface_w == -1 && surface_h == -1) return;
223b71206888 Initial import
thib
parents:
diff changeset
421 surface_x = x; surface_y = y;
223b71206888 Initial import
thib
parents:
diff changeset
422 surface_w = -1; surface_h = -1;
223b71206888 Initial import
thib
parents:
diff changeset
423 if (!is_hidden_now) ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
424 }
223b71206888 Initial import
thib
parents:
diff changeset
425 int PicBase::SurfacePosX(void) {
223b71206888 Initial import
thib
parents:
diff changeset
426 return surface_x;
223b71206888 Initial import
thib
parents:
diff changeset
427 }
223b71206888 Initial import
thib
parents:
diff changeset
428 int PicBase::SurfacePosY(void) {
223b71206888 Initial import
thib
parents:
diff changeset
429 return surface_y;
223b71206888 Initial import
thib
parents:
diff changeset
430 }
223b71206888 Initial import
thib
parents:
diff changeset
431 void PicBase::SetSurfaceRect(const Rect& r) {
223b71206888 Initial import
thib
parents:
diff changeset
432 if (surface_x == r.lx && surface_y == r.ty && surface_w == r.width() && surface_h == r.height()) return;
223b71206888 Initial import
thib
parents:
diff changeset
433 surface_x = r.lx; surface_y = r.ty;
223b71206888 Initial import
thib
parents:
diff changeset
434 surface_w = r.width(); surface_h = r.height();
223b71206888 Initial import
thib
parents:
diff changeset
435 parent->ReBlit(rel_pos);
223b71206888 Initial import
thib
parents:
diff changeset
436 rel_pos = Rect(rel_pos.lx, rel_pos.ty, rel_pos.lx+surface_w, rel_pos.ty+surface_h);
223b71206888 Initial import
thib
parents:
diff changeset
437 if (widget) {
223b71206888 Initial import
thib
parents:
diff changeset
438 Rect new_ppos = rel_pos;
223b71206888 Initial import
thib
parents:
diff changeset
439 Rect apos = parent->QueryAbsPos(new_ppos);
223b71206888 Initial import
thib
parents:
diff changeset
440 widget->SetRegion(apos);
223b71206888 Initial import
thib
parents:
diff changeset
441 }
223b71206888 Initial import
thib
parents:
diff changeset
442 if (!is_hidden_now) ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
443 }
223b71206888 Initial import
thib
parents:
diff changeset
444 void PicBase::SetClipArea(const Rect& r) {
223b71206888 Initial import
thib
parents:
diff changeset
445 if (clip_area == r) return;
223b71206888 Initial import
thib
parents:
diff changeset
446 clip_area = r;
223b71206888 Initial import
thib
parents:
diff changeset
447 parent->ReBlit(rel_pos);
223b71206888 Initial import
thib
parents:
diff changeset
448 }
223b71206888 Initial import
thib
parents:
diff changeset
449
223b71206888 Initial import
thib
parents:
diff changeset
450 void PicBase::SetSurfaceAttribute(int new_attribute) {
223b71206888 Initial import
thib
parents:
diff changeset
451 attribute &= ~(BLIT_SATURATE | BLIT_MULTIPLY);
223b71206888 Initial import
thib
parents:
diff changeset
452 attribute |= new_attribute & (BLIT_SATURATE | BLIT_MULTIPLY);
223b71206888 Initial import
thib
parents:
diff changeset
453 if (new_attribute & (BLIT_SATURATE | BLIT_MULTIPLY)) {
223b71206888 Initial import
thib
parents:
diff changeset
454 rel_solid_area = Rect(0,0);
223b71206888 Initial import
thib
parents:
diff changeset
455 }
223b71206888 Initial import
thib
parents:
diff changeset
456 }
223b71206888 Initial import
thib
parents:
diff changeset
457 void PicBase::SetSurfaceFreeFlag(bool flag) {
223b71206888 Initial import
thib
parents:
diff changeset
458 if (flag) attribute |= SURFACE_FREE;
223b71206888 Initial import
thib
parents:
diff changeset
459 else attribute &= ~SURFACE_FREE;
223b71206888 Initial import
thib
parents:
diff changeset
460
223b71206888 Initial import
thib
parents:
diff changeset
461 }
223b71206888 Initial import
thib
parents:
diff changeset
462
223b71206888 Initial import
thib
parents:
diff changeset
463 /******************************************
223b71206888 Initial import
thib
parents:
diff changeset
464 ** PicContainer
223b71206888 Initial import
thib
parents:
diff changeset
465 */
223b71206888 Initial import
thib
parents:
diff changeset
466 PicContainer::PicContainer(const Rect& rel_pos, PicContainer* parent, int attr) :
223b71206888 Initial import
thib
parents:
diff changeset
467 PicBase(rel_pos, parent, attr) {
223b71206888 Initial import
thib
parents:
diff changeset
468 }
223b71206888 Initial import
thib
parents:
diff changeset
469 PicContainer::~PicContainer() {
223b71206888 Initial import
thib
parents:
diff changeset
470 iterator end = children.end();
223b71206888 Initial import
thib
parents:
diff changeset
471 for (iterator it = children.begin(); it != end; ) {
223b71206888 Initial import
thib
parents:
diff changeset
472 iterator it_next = it; it_next++;
223b71206888 Initial import
thib
parents:
diff changeset
473 if ((*it)->widget) delete (*it)->widget; // picture にwidget が付属しているなら、そちらをdelete
223b71206888 Initial import
thib
parents:
diff changeset
474 else delete (*it);
223b71206888 Initial import
thib
parents:
diff changeset
475 it = it_next;
223b71206888 Initial import
thib
parents:
diff changeset
476 }
223b71206888 Initial import
thib
parents:
diff changeset
477 }
223b71206888 Initial import
thib
parents:
diff changeset
478 void PicContainer::BlitBack(iterator z, Rect rpos) {
223b71206888 Initial import
thib
parents:
diff changeset
479 rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height()));
223b71206888 Initial import
thib
parents:
diff changeset
480 if (rpos.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
481 iterator end = children.end(), begin = children.begin(); iterator it = begin;
223b71206888 Initial import
thib
parents:
diff changeset
482
223b71206888 Initial import
thib
parents:
diff changeset
483 Rect ppos = parent_pos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
484 if (is_hidden_now) goto parent_redraw;
223b71206888 Initial import
thib
parents:
diff changeset
485 // cache されている領域を探す
223b71206888 Initial import
thib
parents:
diff changeset
486 // z自身がキャッシュしていれば、ここで終了
223b71206888 Initial import
thib
parents:
diff changeset
487 if ( ((*z)->attribute & CACHE_BACK) && ( (*z)->is_cached) && (*z)->rel_pos.is_inner(rpos)) {
223b71206888 Initial import
thib
parents:
diff changeset
488 Rect cpos = child_pos(rpos, *z);
223b71206888 Initial import
thib
parents:
diff changeset
489 Rect apos = (*z)->QueryAbsPos(cpos);
223b71206888 Initial import
thib
parents:
diff changeset
490 root->BlitSurface( (*z)->surface_back, cpos, root->surface, apos);
223b71206888 Initial import
thib
parents:
diff changeset
491 return;
223b71206888 Initial import
thib
parents:
diff changeset
492 }
223b71206888 Initial import
thib
parents:
diff changeset
493 // z より下の子がキャッシュ、あるいは SOLID 描画できないか?
223b71206888 Initial import
thib
parents:
diff changeset
494 for (it = z; it != begin;) { // 子がcontainerの場合のチェックは省略
223b71206888 Initial import
thib
parents:
diff changeset
495 it--;
223b71206888 Initial import
thib
parents:
diff changeset
496 if ( (*it)->is_hidden_now) continue;
223b71206888 Initial import
thib
parents:
diff changeset
497 if ( (*it)->rel_pos.is_crossed(rpos)) {
223b71206888 Initial import
thib
parents:
diff changeset
498 if ( ((*it)->attribute & CACHE_BACK) && ((*it)->is_cached) && (*it)->rel_pos.is_inner(rpos)) {
223b71206888 Initial import
thib
parents:
diff changeset
499 Rect cpos = child_pos(rpos, *it);
223b71206888 Initial import
thib
parents:
diff changeset
500 Rect apos = (*it)->QueryAbsPos(cpos);
223b71206888 Initial import
thib
parents:
diff changeset
501 root->BlitSurface( (*it)->surface_back, cpos, root->surface, apos);
223b71206888 Initial import
thib
parents:
diff changeset
502 goto children_redraw;
223b71206888 Initial import
thib
parents:
diff changeset
503 }
223b71206888 Initial import
thib
parents:
diff changeset
504 if ( (*it)->rel_solid_area.is_inner(rpos)) {
223b71206888 Initial import
thib
parents:
diff changeset
505 goto children_redraw;
223b71206888 Initial import
thib
parents:
diff changeset
506 }
223b71206888 Initial import
thib
parents:
diff changeset
507 }
223b71206888 Initial import
thib
parents:
diff changeset
508 }
223b71206888 Initial import
thib
parents:
diff changeset
509 // 自分自身がキャッシュ、あるいは SOLID 描画できないか?
223b71206888 Initial import
thib
parents:
diff changeset
510 if (rel_solid_area.is_inner(ppos)) {
223b71206888 Initial import
thib
parents:
diff changeset
511 goto self_redraw;
223b71206888 Initial import
thib
parents:
diff changeset
512 }
223b71206888 Initial import
thib
parents:
diff changeset
513 if ( (attribute & CACHE_BACK) && is_cached) {
223b71206888 Initial import
thib
parents:
diff changeset
514 Rect cpos = child_pos(rpos, *z);
223b71206888 Initial import
thib
parents:
diff changeset
515 Rect apos = (*z)->QueryAbsPos(cpos);
223b71206888 Initial import
thib
parents:
diff changeset
516 Rect draw_rpos = (*z)->parent_pos(cpos);
223b71206888 Initial import
thib
parents:
diff changeset
517 if(print_blit) fprintf(stderr,"cahce.");
223b71206888 Initial import
thib
parents:
diff changeset
518 root->BlitSurface(surface_back, draw_rpos, root->surface, apos);
223b71206888 Initial import
thib
parents:
diff changeset
519 goto self_redraw;
223b71206888 Initial import
thib
parents:
diff changeset
520 }
223b71206888 Initial import
thib
parents:
diff changeset
521 parent_redraw:
223b71206888 Initial import
thib
parents:
diff changeset
522 if (parent) {
223b71206888 Initial import
thib
parents:
diff changeset
523 Rect ppos = parent_pos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
524 if(print_blit) fprintf(stderr,"parent-back.");
223b71206888 Initial import
thib
parents:
diff changeset
525 parent->BlitBack(z_pos, ppos);
223b71206888 Initial import
thib
parents:
diff changeset
526 }
223b71206888 Initial import
thib
parents:
diff changeset
527 if (is_hidden_now) return;
223b71206888 Initial import
thib
parents:
diff changeset
528 self_redraw:
223b71206888 Initial import
thib
parents:
diff changeset
529 if(print_blit) fprintf(stderr,"back-self.");
223b71206888 Initial import
thib
parents:
diff changeset
530 BlitSelf(rpos); // 子は描画せず、自分だけ描画
223b71206888 Initial import
thib
parents:
diff changeset
531 children_redraw:
223b71206888 Initial import
thib
parents:
diff changeset
532 for (; it != z; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
533 if ( (*it)->is_hidden_now) continue;
223b71206888 Initial import
thib
parents:
diff changeset
534 if ( (*it)->rel_pos.is_crossed(rpos)) {
223b71206888 Initial import
thib
parents:
diff changeset
535 Rect cpos = child_pos(rpos, *it);
223b71206888 Initial import
thib
parents:
diff changeset
536 (*it)->Blit(cpos);
223b71206888 Initial import
thib
parents:
diff changeset
537 }
223b71206888 Initial import
thib
parents:
diff changeset
538 }
223b71206888 Initial import
thib
parents:
diff changeset
539 }
223b71206888 Initial import
thib
parents:
diff changeset
540 void PicContainer::BlitChildren(Rect rpos) {
223b71206888 Initial import
thib
parents:
diff changeset
541 if (print_blit) fprintf(stderr,"bc.");
223b71206888 Initial import
thib
parents:
diff changeset
542 iterator end = children.end();
223b71206888 Initial import
thib
parents:
diff changeset
543 for (iterator it = children.begin(); it != end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
544 if ( (*it)->is_hidden_now) if(print_blit) fprintf(stderr,"bch %08x;",*it);
223b71206888 Initial import
thib
parents:
diff changeset
545 if ( (*it)->is_hidden_now) continue;
223b71206888 Initial import
thib
parents:
diff changeset
546 if ( (*it)->rel_pos.is_crossed(rpos)) {
223b71206888 Initial import
thib
parents:
diff changeset
547 Rect cpos = child_pos(rpos, *it);
223b71206888 Initial import
thib
parents:
diff changeset
548 (*it)->Blit(cpos);
223b71206888 Initial import
thib
parents:
diff changeset
549 }
223b71206888 Initial import
thib
parents:
diff changeset
550 }
223b71206888 Initial import
thib
parents:
diff changeset
551 }
223b71206888 Initial import
thib
parents:
diff changeset
552 void PicContainer::BlitFront(iterator z, Rect rpos) {
223b71206888 Initial import
thib
parents:
diff changeset
553 rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height()));
223b71206888 Initial import
thib
parents:
diff changeset
554 if (rpos.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
555 iterator end = children.end(); iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
556 z++;
223b71206888 Initial import
thib
parents:
diff changeset
557 for (it = z; it != end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
558 if ( (*it)->is_hidden_now) continue;
223b71206888 Initial import
thib
parents:
diff changeset
559 if ( (*it)->rel_pos.is_crossed(rpos)) {
223b71206888 Initial import
thib
parents:
diff changeset
560 Rect cpos = child_pos(rpos, *it);
223b71206888 Initial import
thib
parents:
diff changeset
561 (*it)->Blit(cpos);
223b71206888 Initial import
thib
parents:
diff changeset
562 }
223b71206888 Initial import
thib
parents:
diff changeset
563 }
223b71206888 Initial import
thib
parents:
diff changeset
564 if (parent) {
223b71206888 Initial import
thib
parents:
diff changeset
565 Rect ppos = parent_pos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
566 parent->BlitFront(z_pos, ppos);
223b71206888 Initial import
thib
parents:
diff changeset
567 }
223b71206888 Initial import
thib
parents:
diff changeset
568 };
223b71206888 Initial import
thib
parents:
diff changeset
569 void PicContainer::BlitSelf(Rect rpos) {
223b71206888 Initial import
thib
parents:
diff changeset
570 // 実際に描画する領域を得る
223b71206888 Initial import
thib
parents:
diff changeset
571 rpos.intersect(Rect(0, 0, rel_pos.width(), rel_pos.height()));
223b71206888 Initial import
thib
parents:
diff changeset
572 if (rpos.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
573 Rect apos = QueryAbsPos(rpos);
223b71206888 Initial import
thib
parents:
diff changeset
574 // 必要に応じて保存、描画
223b71206888 Initial import
thib
parents:
diff changeset
575 if(print_blit) fprintf(stderr,"self-back.");
223b71206888 Initial import
thib
parents:
diff changeset
576 if (attribute & CACHE_BACK) root->BlitSurface(root->surface, apos, surface_back, rpos);
223b71206888 Initial import
thib
parents:
diff changeset
577 if (! (attribute & NO_PICTURE)) {
223b71206888 Initial import
thib
parents:
diff changeset
578 rpos.rmove(surface_x, surface_y);
223b71206888 Initial import
thib
parents:
diff changeset
579 if (surface_w >= 0 && surface_h >= 0) {
223b71206888 Initial import
thib
parents:
diff changeset
580 Rect clip(0, 0, surface_w, surface_h);
223b71206888 Initial import
thib
parents:
diff changeset
581 clip.rmove(rpos.lx, rpos.ty);
223b71206888 Initial import
thib
parents:
diff changeset
582 rpos.intersect(clip);
223b71206888 Initial import
thib
parents:
diff changeset
583 }
223b71206888 Initial import
thib
parents:
diff changeset
584 if(print_blit) fprintf(stderr,"self-blit.");
223b71206888 Initial import
thib
parents:
diff changeset
585 root->BlitSurface(surface_own, rpos, surface_alpha, surface_alpha_rect, root->surface, apos, attribute);
223b71206888 Initial import
thib
parents:
diff changeset
586 } else if (parent == 0) { // 親がいないなら背景消去の責任をもつ
223b71206888 Initial import
thib
parents:
diff changeset
587 DSurfaceFill(root->surface, apos, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
588 }
223b71206888 Initial import
thib
parents:
diff changeset
589 }
223b71206888 Initial import
thib
parents:
diff changeset
590
223b71206888 Initial import
thib
parents:
diff changeset
591 void PicContainer::set_showflag(void) {
223b71206888 Initial import
thib
parents:
diff changeset
592 iterator end = children.end();
223b71206888 Initial import
thib
parents:
diff changeset
593 for (iterator it = children.begin(); it != end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
594 (*it)->is_hidden = false;
223b71206888 Initial import
thib
parents:
diff changeset
595 PicContainer* next = dynamic_cast<PicContainer*>(*it);
223b71206888 Initial import
thib
parents:
diff changeset
596 if (next && (!next->children.empty())) next->set_showflag();
223b71206888 Initial import
thib
parents:
diff changeset
597 }
223b71206888 Initial import
thib
parents:
diff changeset
598 }
223b71206888 Initial import
thib
parents:
diff changeset
599 void PicContainer::set_nowhiddenflag(bool is_hide) {
223b71206888 Initial import
thib
parents:
diff changeset
600 iterator end = children.end();
223b71206888 Initial import
thib
parents:
diff changeset
601 for (iterator it = children.begin(); it != end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
602 if (is_hide) (*it)->is_hidden_now = true;
223b71206888 Initial import
thib
parents:
diff changeset
603 else (*it)->is_hidden_now = (*it)->is_hidden;
223b71206888 Initial import
thib
parents:
diff changeset
604 if ( (*it)->widget) {
223b71206888 Initial import
thib
parents:
diff changeset
605 if ((*it)->is_hidden_now) (*it)->widget->deactivate();
223b71206888 Initial import
thib
parents:
diff changeset
606 else (*it)->widget->activate();
223b71206888 Initial import
thib
parents:
diff changeset
607 }
223b71206888 Initial import
thib
parents:
diff changeset
608 PicContainer* next = dynamic_cast<PicContainer*>(*it);
223b71206888 Initial import
thib
parents:
diff changeset
609 if (next && (!next->children.empty())) next->set_nowhiddenflag(is_hide);
223b71206888 Initial import
thib
parents:
diff changeset
610 }
223b71206888 Initial import
thib
parents:
diff changeset
611 }
223b71206888 Initial import
thib
parents:
diff changeset
612 void PicContainer::RMove(int add_x, int add_y) { // event widget の移動があり得るので子についてもRMoveを呼び出す
223b71206888 Initial import
thib
parents:
diff changeset
613 PicBase::RMove(add_x, add_y);
223b71206888 Initial import
thib
parents:
diff changeset
614 iterator end = children.end();
223b71206888 Initial import
thib
parents:
diff changeset
615 for (iterator it = children.begin(); it != end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
616 (*it)->RMove(0,0);
223b71206888 Initial import
thib
parents:
diff changeset
617 }
223b71206888 Initial import
thib
parents:
diff changeset
618 }
223b71206888 Initial import
thib
parents:
diff changeset
619
223b71206888 Initial import
thib
parents:
diff changeset
620 PicBase* PicContainer::create_leaf(const Rect& rel_pos, int attr) {
223b71206888 Initial import
thib
parents:
diff changeset
621 return new PicBase(rel_pos, this, attr);
223b71206888 Initial import
thib
parents:
diff changeset
622 }
223b71206888 Initial import
thib
parents:
diff changeset
623 PicContainer* PicContainer::create_node(const Rect& rel_pos, int attr) {
223b71206888 Initial import
thib
parents:
diff changeset
624 return new PicContainer(rel_pos, this, attr);
223b71206888 Initial import
thib
parents:
diff changeset
625 }
223b71206888 Initial import
thib
parents:
diff changeset
626
223b71206888 Initial import
thib
parents:
diff changeset
627 /***************************************************************
223b71206888 Initial import
thib
parents:
diff changeset
628 **
223b71206888 Initial import
thib
parents:
diff changeset
629 ** PicWidget
223b71206888 Initial import
thib
parents:
diff changeset
630 */
223b71206888 Initial import
thib
parents:
diff changeset
631
223b71206888 Initial import
thib
parents:
diff changeset
632 PicWidget::PicWidget(void) {
223b71206888 Initial import
thib
parents:
diff changeset
633 pic = 0;
223b71206888 Initial import
thib
parents:
diff changeset
634 }
223b71206888 Initial import
thib
parents:
diff changeset
635 PicWidget::~PicWidget() {
223b71206888 Initial import
thib
parents:
diff changeset
636 if (pic) {
223b71206888 Initial import
thib
parents:
diff changeset
637 pic->SetEventWidget(0);
223b71206888 Initial import
thib
parents:
diff changeset
638 delete pic;
223b71206888 Initial import
thib
parents:
diff changeset
639 }
223b71206888 Initial import
thib
parents:
diff changeset
640 pic = 0;
223b71206888 Initial import
thib
parents:
diff changeset
641 }
223b71206888 Initial import
thib
parents:
diff changeset
642 void PicWidget::SetPic(PicBase* new_pic) {
223b71206888 Initial import
thib
parents:
diff changeset
643 if (pic) {
223b71206888 Initial import
thib
parents:
diff changeset
644 pic->SetEventWidget(0);
223b71206888 Initial import
thib
parents:
diff changeset
645 delete pic;
223b71206888 Initial import
thib
parents:
diff changeset
646 }
223b71206888 Initial import
thib
parents:
diff changeset
647 pic = new_pic;
223b71206888 Initial import
thib
parents:
diff changeset
648 if (pic) pic->SetEventWidget(this);
223b71206888 Initial import
thib
parents:
diff changeset
649 }
223b71206888 Initial import
thib
parents:
diff changeset
650 PicBase* PicWidget::Pic(void) {
223b71206888 Initial import
thib
parents:
diff changeset
651 if (pic == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
652 fprintf(stderr,"Error: PicWidget::Pic returns zero.\n");
223b71206888 Initial import
thib
parents:
diff changeset
653 }
223b71206888 Initial import
thib
parents:
diff changeset
654 return pic;
223b71206888 Initial import
thib
parents:
diff changeset
655 }
223b71206888 Initial import
thib
parents:
diff changeset
656 PicContainer* PicWidget::PicNode(void) {
223b71206888 Initial import
thib
parents:
diff changeset
657 PicContainer* node = dynamic_cast<PicContainer*>(pic);
223b71206888 Initial import
thib
parents:
diff changeset
658 if (node == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
659 fprintf(stderr,"Error: PicWidget::PicNode returns zero.\n");
223b71206888 Initial import
thib
parents:
diff changeset
660 }
223b71206888 Initial import
thib
parents:
diff changeset
661 return node;
223b71206888 Initial import
thib
parents:
diff changeset
662 }
223b71206888 Initial import
thib
parents:
diff changeset
663
223b71206888 Initial import
thib
parents:
diff changeset
664 /******************************************
223b71206888 Initial import
thib
parents:
diff changeset
665 ** FileToSurface
223b71206888 Initial import
thib
parents:
diff changeset
666 */
223b71206888 Initial import
thib
parents:
diff changeset
667
223b71206888 Initial import
thib
parents:
diff changeset
668 #include<list>
223b71206888 Initial import
thib
parents:
diff changeset
669 #include<map>
223b71206888 Initial import
thib
parents:
diff changeset
670 #include<string>
223b71206888 Initial import
thib
parents:
diff changeset
671 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
672 struct SurfaceIndex {
223b71206888 Initial import
thib
parents:
diff changeset
673 typedef list<SurfaceIndex*>::iterator qiterator;
223b71206888 Initial import
thib
parents:
diff changeset
674 string filename;
223b71206888 Initial import
thib
parents:
diff changeset
675 Surface* surface;
223b71206888 Initial import
thib
parents:
diff changeset
676 qiterator qpos;
223b71206888 Initial import
thib
parents:
diff changeset
677 int ref_count;
223b71206888 Initial import
thib
parents:
diff changeset
678 };
223b71206888 Initial import
thib
parents:
diff changeset
679
223b71206888 Initial import
thib
parents:
diff changeset
680 class FileToSurface {
223b71206888 Initial import
thib
parents:
diff changeset
681 typedef list<SurfaceIndex*>::iterator qiterator;
223b71206888 Initial import
thib
parents:
diff changeset
682
223b71206888 Initial import
thib
parents:
diff changeset
683 list<SurfaceIndex*> queue;
223b71206888 Initial import
thib
parents:
diff changeset
684 map<string, SurfaceIndex*> findex;
223b71206888 Initial import
thib
parents:
diff changeset
685 map<Surface*, SurfaceIndex*> mindex;
223b71206888 Initial import
thib
parents:
diff changeset
686 int count;
223b71206888 Initial import
thib
parents:
diff changeset
687 int count_max;
223b71206888 Initial import
thib
parents:
diff changeset
688 const PicRoot& root;
223b71206888 Initial import
thib
parents:
diff changeset
689 bool DeleteData(SurfaceIndex* data);
223b71206888 Initial import
thib
parents:
diff changeset
690 Surface* LoadSurface(string name, char*& mem);
223b71206888 Initial import
thib
parents:
diff changeset
691 public:
223b71206888 Initial import
thib
parents:
diff changeset
692 FileToSurface(const PicRoot& root);
223b71206888 Initial import
thib
parents:
diff changeset
693 ~FileToSurface(void);
223b71206888 Initial import
thib
parents:
diff changeset
694 Surface* Load(string name);
223b71206888 Initial import
thib
parents:
diff changeset
695 bool Free(Surface* s);
223b71206888 Initial import
thib
parents:
diff changeset
696 };
223b71206888 Initial import
thib
parents:
diff changeset
697
223b71206888 Initial import
thib
parents:
diff changeset
698 FileToSurface::FileToSurface(const PicRoot& _root) : root(_root) {
223b71206888 Initial import
thib
parents:
diff changeset
699 count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
700 count_max = 32; // キャッシュ量(決め打ち)
223b71206888 Initial import
thib
parents:
diff changeset
701 };
223b71206888 Initial import
thib
parents:
diff changeset
702 FileToSurface::~FileToSurface() {
223b71206888 Initial import
thib
parents:
diff changeset
703 qiterator it;
223b71206888 Initial import
thib
parents:
diff changeset
704 for (it=queue.begin(); it != queue.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
705 if ( (*it)->ref_count) {
223b71206888 Initial import
thib
parents:
diff changeset
706 fprintf(stderr, "Warning: FileToSurface: delete referenced surface named '%s'\n",(*it)->filename.c_str());
223b71206888 Initial import
thib
parents:
diff changeset
707 }
223b71206888 Initial import
thib
parents:
diff changeset
708 root.DeleteSurfaceImpl( (*it)->surface);
223b71206888 Initial import
thib
parents:
diff changeset
709 delete *it;
223b71206888 Initial import
thib
parents:
diff changeset
710 }
223b71206888 Initial import
thib
parents:
diff changeset
711 }
223b71206888 Initial import
thib
parents:
diff changeset
712 inline bool FileToSurface::DeleteData(SurfaceIndex* data) {
223b71206888 Initial import
thib
parents:
diff changeset
713 if ( data->ref_count) return false;
223b71206888 Initial import
thib
parents:
diff changeset
714 findex.erase(data->filename);
223b71206888 Initial import
thib
parents:
diff changeset
715 mindex.erase(data->surface);
223b71206888 Initial import
thib
parents:
diff changeset
716 queue.erase(data->qpos);
223b71206888 Initial import
thib
parents:
diff changeset
717 root.DeleteSurfaceImpl(data->surface);
223b71206888 Initial import
thib
parents:
diff changeset
718 delete data;
223b71206888 Initial import
thib
parents:
diff changeset
719 count--;
223b71206888 Initial import
thib
parents:
diff changeset
720 return true;
223b71206888 Initial import
thib
parents:
diff changeset
721 }
223b71206888 Initial import
thib
parents:
diff changeset
722 inline Surface* FileToSurface::LoadSurface(string name, char*& mem) {
223b71206888 Initial import
thib
parents:
diff changeset
723 ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, name.c_str(),"pdt");
223b71206888 Initial import
thib
parents:
diff changeset
724 if (info == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
725 GRPCONV* conv = GRPCONV::AssignConverter(info);
223b71206888 Initial import
thib
parents:
diff changeset
726 if (conv == 0) { delete info;return 0;}
223b71206888 Initial import
thib
parents:
diff changeset
727 mem = (char*)malloc(conv->Width() * conv->Height() * 4 + 1024);
223b71206888 Initial import
thib
parents:
diff changeset
728 Surface* s = 0;
223b71206888 Initial import
thib
parents:
diff changeset
729 if (conv->Read(mem)) {
223b71206888 Initial import
thib
parents:
diff changeset
730 MaskType is_mask = conv->IsMask() ? ALPHA_MASK : NO_MASK;
223b71206888 Initial import
thib
parents:
diff changeset
731 if (is_mask == ALPHA_MASK) { // alpha がすべて 0xff ならマスク無しとする
223b71206888 Initial import
thib
parents:
diff changeset
732 int len = conv->Width()*conv->Height();
223b71206888 Initial import
thib
parents:
diff changeset
733 unsigned int* d = (unsigned int*)mem;
223b71206888 Initial import
thib
parents:
diff changeset
734 int i; for (i=0; i<len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
735 if ( (*d&0xff000000) != 0xff000000) break;
223b71206888 Initial import
thib
parents:
diff changeset
736 d++;
223b71206888 Initial import
thib
parents:
diff changeset
737 }
223b71206888 Initial import
thib
parents:
diff changeset
738 if (i == len) {
223b71206888 Initial import
thib
parents:
diff changeset
739 is_mask = NO_MASK;
223b71206888 Initial import
thib
parents:
diff changeset
740 }
223b71206888 Initial import
thib
parents:
diff changeset
741 }
223b71206888 Initial import
thib
parents:
diff changeset
742 s = root.NewSurfaceFromRGBAData(conv->Width(), conv->Height(), mem, is_mask);
223b71206888 Initial import
thib
parents:
diff changeset
743 }
223b71206888 Initial import
thib
parents:
diff changeset
744 delete conv; delete info; // delete data;
223b71206888 Initial import
thib
parents:
diff changeset
745 return s;
223b71206888 Initial import
thib
parents:
diff changeset
746 }
223b71206888 Initial import
thib
parents:
diff changeset
747 Surface* FileToSurface::Load(string name) {
223b71206888 Initial import
thib
parents:
diff changeset
748 if (findex.find(name) != findex.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
749 findex[name]->ref_count++;
223b71206888 Initial import
thib
parents:
diff changeset
750 return findex[name]->surface;
223b71206888 Initial import
thib
parents:
diff changeset
751 }
223b71206888 Initial import
thib
parents:
diff changeset
752 char* mem;
223b71206888 Initial import
thib
parents:
diff changeset
753 Surface* surface = LoadSurface(name, mem);
223b71206888 Initial import
thib
parents:
diff changeset
754 if (surface == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
755
223b71206888 Initial import
thib
parents:
diff changeset
756 while (count >= count_max) { // count_max 以上のデータを可能なら削除する
223b71206888 Initial import
thib
parents:
diff changeset
757 qiterator it;
223b71206888 Initial import
thib
parents:
diff changeset
758 for (it=queue.begin(); it != queue.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
759 if (DeleteData(*it)) break;
223b71206888 Initial import
thib
parents:
diff changeset
760 }
223b71206888 Initial import
thib
parents:
diff changeset
761 if (it == queue.end()) break; // 全データが使用中なら終了
223b71206888 Initial import
thib
parents:
diff changeset
762 }
223b71206888 Initial import
thib
parents:
diff changeset
763 SurfaceIndex* new_index = new SurfaceIndex;
223b71206888 Initial import
thib
parents:
diff changeset
764 new_index->filename = name;
223b71206888 Initial import
thib
parents:
diff changeset
765 new_index->surface = surface;
223b71206888 Initial import
thib
parents:
diff changeset
766 findex[name] = new_index;
223b71206888 Initial import
thib
parents:
diff changeset
767 mindex[surface] = new_index;
223b71206888 Initial import
thib
parents:
diff changeset
768 queue.push_back(new_index);
223b71206888 Initial import
thib
parents:
diff changeset
769 new_index->qpos = queue.end(); new_index->qpos--;
223b71206888 Initial import
thib
parents:
diff changeset
770 new_index->ref_count = 1;
223b71206888 Initial import
thib
parents:
diff changeset
771 count++;
223b71206888 Initial import
thib
parents:
diff changeset
772 return surface;
223b71206888 Initial import
thib
parents:
diff changeset
773 }
223b71206888 Initial import
thib
parents:
diff changeset
774 bool FileToSurface::Free(Surface* s) {
223b71206888 Initial import
thib
parents:
diff changeset
775 if (mindex.find(s) == mindex.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
776 return false;
223b71206888 Initial import
thib
parents:
diff changeset
777 }
223b71206888 Initial import
thib
parents:
diff changeset
778 SurfaceIndex* index = mindex[s];
223b71206888 Initial import
thib
parents:
diff changeset
779 if (index->ref_count == 0) DeleteData(index);
223b71206888 Initial import
thib
parents:
diff changeset
780 else index->ref_count--;
223b71206888 Initial import
thib
parents:
diff changeset
781 return true;
223b71206888 Initial import
thib
parents:
diff changeset
782 }
223b71206888 Initial import
thib
parents:
diff changeset
783
223b71206888 Initial import
thib
parents:
diff changeset
784 /******************************************
223b71206888 Initial import
thib
parents:
diff changeset
785 ** PicRoot
223b71206888 Initial import
thib
parents:
diff changeset
786 */
223b71206888 Initial import
thib
parents:
diff changeset
787 #include<SDL.h>
223b71206888 Initial import
thib
parents:
diff changeset
788
223b71206888 Initial import
thib
parents:
diff changeset
789 #include"surface.h"
223b71206888 Initial import
thib
parents:
diff changeset
790
223b71206888 Initial import
thib
parents:
diff changeset
791 #define DefaultRmask 0xff0000
223b71206888 Initial import
thib
parents:
diff changeset
792 #define DefaultGmask 0xff00
223b71206888 Initial import
thib
parents:
diff changeset
793 #define DefaultBmask 0xff
223b71206888 Initial import
thib
parents:
diff changeset
794 #define DefaultAmask 0xff000000
223b71206888 Initial import
thib
parents:
diff changeset
795 #define DefaultBpp 32
223b71206888 Initial import
thib
parents:
diff changeset
796
223b71206888 Initial import
thib
parents:
diff changeset
797 PicRoot::PicRoot(void) {
223b71206888 Initial import
thib
parents:
diff changeset
798 hw_surface = (Surface*)SDL_GetVideoSurface();
223b71206888 Initial import
thib
parents:
diff changeset
799 SDL_PixelFormat* fmt_SDL = hw_surface->format;
223b71206888 Initial import
thib
parents:
diff changeset
800 if (fmt_SDL->BitsPerPixel == DefaultBpp && fmt_SDL->Rmask == DefaultRmask && fmt_SDL->Gmask == DefaultGmask && fmt_SDL->Bmask == DefaultBmask) {
223b71206888 Initial import
thib
parents:
diff changeset
801 surface = hw_surface;
223b71206888 Initial import
thib
parents:
diff changeset
802 } else {
223b71206888 Initial import
thib
parents:
diff changeset
803 surface = (Surface*)SDL_CreateRGBSurface(0, hw_surface->w, hw_surface->h, DefaultBpp, DefaultRmask, DefaultGmask, DefaultBmask, 0);
223b71206888 Initial import
thib
parents:
diff changeset
804 }
223b71206888 Initial import
thib
parents:
diff changeset
805
223b71206888 Initial import
thib
parents:
diff changeset
806 Rect rpos(0, 0, surface->w, surface->h);
223b71206888 Initial import
thib
parents:
diff changeset
807 root = new PicContainer(rpos, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
808 root->InitRoot(this);
223b71206888 Initial import
thib
parents:
diff changeset
809 root->show();
223b71206888 Initial import
thib
parents:
diff changeset
810 ftosurface = new FileToSurface(*this);
223b71206888 Initial import
thib
parents:
diff changeset
811 width = surface->w;
223b71206888 Initial import
thib
parents:
diff changeset
812 height = surface->h;
223b71206888 Initial import
thib
parents:
diff changeset
813 return;
223b71206888 Initial import
thib
parents:
diff changeset
814 }
223b71206888 Initial import
thib
parents:
diff changeset
815 PicRoot::~PicRoot() {
223b71206888 Initial import
thib
parents:
diff changeset
816 // if (surface) DeleteSurfaceImpl(surface); // SDL_GetVideoSurface() した surface は開放の必要がないらしい
223b71206888 Initial import
thib
parents:
diff changeset
817 surface = 0;
223b71206888 Initial import
thib
parents:
diff changeset
818 delete root;
223b71206888 Initial import
thib
parents:
diff changeset
819 delete ftosurface;
223b71206888 Initial import
thib
parents:
diff changeset
820 }
223b71206888 Initial import
thib
parents:
diff changeset
821 void PicRoot::Update(PicBase* pic, const Rect& rpos, const Rect& apos) {
223b71206888 Initial import
thib
parents:
diff changeset
822 update_rects.push_back(UpdateItem(pic, rpos, apos));
223b71206888 Initial import
thib
parents:
diff changeset
823 }
223b71206888 Initial import
thib
parents:
diff changeset
824 bool PicRoot::UpdateItem::less(const PicRoot::UpdateItem& a, const PicRoot::UpdateItem& b) {
223b71206888 Initial import
thib
parents:
diff changeset
825 return a.pic->DistanceRoot() < b.pic->DistanceRoot();
223b71206888 Initial import
thib
parents:
diff changeset
826 }
223b71206888 Initial import
thib
parents:
diff changeset
827 void PicRoot::DeleteUpdatePic(PicBase* pic) {
223b71206888 Initial import
thib
parents:
diff changeset
828 vector<UpdateItem>::iterator it = update_rects.begin();
223b71206888 Initial import
thib
parents:
diff changeset
829 while(it != update_rects.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
830 if (it->pic == pic) {
223b71206888 Initial import
thib
parents:
diff changeset
831 update_rects.erase(it);
223b71206888 Initial import
thib
parents:
diff changeset
832 it = update_rects.begin();
223b71206888 Initial import
thib
parents:
diff changeset
833 continue;
223b71206888 Initial import
thib
parents:
diff changeset
834 }
223b71206888 Initial import
thib
parents:
diff changeset
835 it++;
223b71206888 Initial import
thib
parents:
diff changeset
836 }
223b71206888 Initial import
thib
parents:
diff changeset
837 return;
223b71206888 Initial import
thib
parents:
diff changeset
838 }
223b71206888 Initial import
thib
parents:
diff changeset
839 void PicRoot::ExecUpdate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
840 /* 共通する領域を消去する */
223b71206888 Initial import
thib
parents:
diff changeset
841 sort(update_rects.begin(), update_rects.end(), UpdateItem::less);
223b71206888 Initial import
thib
parents:
diff changeset
842 vector<UpdateItem>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
843 vector<UpdateItem>::iterator end = update_rects.end();
223b71206888 Initial import
thib
parents:
diff changeset
844 if(print_blit){
223b71206888 Initial import
thib
parents:
diff changeset
845 fprintf(stderr,"ExecUpdate Start: \n\t");
223b71206888 Initial import
thib
parents:
diff changeset
846 for (it=update_rects.begin(); it != end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
847 fprintf(stderr,"(%d,%d,%d,%d), ",it->apos.lx,it->apos.ty,it->apos.rx,it->apos.by);
223b71206888 Initial import
thib
parents:
diff changeset
848 }
223b71206888 Initial import
thib
parents:
diff changeset
849 fprintf(stderr,"\n");
223b71206888 Initial import
thib
parents:
diff changeset
850 }
223b71206888 Initial import
thib
parents:
diff changeset
851 for (it=update_rects.begin(); it != end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
852 if (it->rpos.width() == 0) continue;
223b71206888 Initial import
thib
parents:
diff changeset
853
223b71206888 Initial import
thib
parents:
diff changeset
854 Rect apos = it->apos;
223b71206888 Initial import
thib
parents:
diff changeset
855 PicBase* pic = it->pic;
223b71206888 Initial import
thib
parents:
diff changeset
856
223b71206888 Initial import
thib
parents:
diff changeset
857 vector<UpdateItem>::iterator jt = it; jt++;
223b71206888 Initial import
thib
parents:
diff changeset
858 for (; jt != end; jt++) {
223b71206888 Initial import
thib
parents:
diff changeset
859 if (apos.is_inner(jt->apos)) {
223b71206888 Initial import
thib
parents:
diff changeset
860 if (jt->pic == pic || jt->pic->IsParent(pic)) { // 親が共通、かつ領域も共通
223b71206888 Initial import
thib
parents:
diff changeset
861 jt->rpos = Rect(0,0); // empty rect をセット
223b71206888 Initial import
thib
parents:
diff changeset
862 jt->apos = Rect(0,0);
223b71206888 Initial import
thib
parents:
diff changeset
863 }
223b71206888 Initial import
thib
parents:
diff changeset
864 } else if (jt->apos.is_inner(apos)) { // 相手に自分が包含される
223b71206888 Initial import
thib
parents:
diff changeset
865 if (jt->pic == pic || jt->pic->IsParent(pic)) { // 親が共通、かつ領域も共通
223b71206888 Initial import
thib
parents:
diff changeset
866 it->rpos = Rect(0,0);
223b71206888 Initial import
thib
parents:
diff changeset
867 it->apos = Rect(0,0);
223b71206888 Initial import
thib
parents:
diff changeset
868 break;
223b71206888 Initial import
thib
parents:
diff changeset
869 }
223b71206888 Initial import
thib
parents:
diff changeset
870 }
223b71206888 Initial import
thib
parents:
diff changeset
871 }
223b71206888 Initial import
thib
parents:
diff changeset
872 }
223b71206888 Initial import
thib
parents:
diff changeset
873 if(print_blit){
223b71206888 Initial import
thib
parents:
diff changeset
874 fprintf(stderr,"->\t");
223b71206888 Initial import
thib
parents:
diff changeset
875 for (it=update_rects.begin(); it != end; it++) {
223b71206888 Initial import
thib
parents:
diff changeset
876 fprintf(stderr,"(%d,%d,%d,%d), ",it->apos.lx,it->apos.ty,it->apos.rx,it->apos.by);
223b71206888 Initial import
thib
parents:
diff changeset
877 }
223b71206888 Initial import
thib
parents:
diff changeset
878 fprintf(stderr,"\n");
223b71206888 Initial import
thib
parents:
diff changeset
879 }
223b71206888 Initial import
thib
parents:
diff changeset
880
223b71206888 Initial import
thib
parents:
diff changeset
881 int num = update_rects.size();
223b71206888 Initial import
thib
parents:
diff changeset
882 SDL_Rect* r = new SDL_Rect[num];
223b71206888 Initial import
thib
parents:
diff changeset
883 Rect confine = Rect(0, 0, surface->w, surface->h);
223b71206888 Initial import
thib
parents:
diff changeset
884 int n = 0;
223b71206888 Initial import
thib
parents:
diff changeset
885 int i;
223b71206888 Initial import
thib
parents:
diff changeset
886 for (i=0; i<num; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
887 UpdateItem& item = update_rects[i];
223b71206888 Initial import
thib
parents:
diff changeset
888 Rect& ur = item.apos;
223b71206888 Initial import
thib
parents:
diff changeset
889 if (ur.width() == 0) continue;
223b71206888 Initial import
thib
parents:
diff changeset
890 if(print_blit)fprintf(stderr,"%08x: %d,%d,%d,%d",item.pic, item.apos.lx, item.apos.ty, item.apos.rx, item.apos.by);
223b71206888 Initial import
thib
parents:
diff changeset
891
223b71206888 Initial import
thib
parents:
diff changeset
892 item.pic->ExecReBlit(item.rpos);
223b71206888 Initial import
thib
parents:
diff changeset
893 if(print_blit)fprintf(stderr,"\n");
223b71206888 Initial import
thib
parents:
diff changeset
894 ur.intersect(confine);
223b71206888 Initial import
thib
parents:
diff changeset
895 r[n].x = ur.lx;
223b71206888 Initial import
thib
parents:
diff changeset
896 r[n].y = ur.ty;
223b71206888 Initial import
thib
parents:
diff changeset
897 r[n].w = ur.rx - ur.lx;
223b71206888 Initial import
thib
parents:
diff changeset
898 r[n].h = ur.by - ur.ty;
223b71206888 Initial import
thib
parents:
diff changeset
899 if (surface != hw_surface) SDL_BlitSurface(surface, &r[n], hw_surface, &r[n]);
223b71206888 Initial import
thib
parents:
diff changeset
900 n++;
223b71206888 Initial import
thib
parents:
diff changeset
901 }
223b71206888 Initial import
thib
parents:
diff changeset
902 if(print_blit)fprintf(stderr,"\n");
223b71206888 Initial import
thib
parents:
diff changeset
903 SDL_UpdateRects(hw_surface, n, r);
223b71206888 Initial import
thib
parents:
diff changeset
904 delete[] r; update_rects.clear();
223b71206888 Initial import
thib
parents:
diff changeset
905 }
223b71206888 Initial import
thib
parents:
diff changeset
906
223b71206888 Initial import
thib
parents:
diff changeset
907 Surface* PicRoot::NewSurface(int w, int h, MaskType with_mask) const {
223b71206888 Initial import
thib
parents:
diff changeset
908 Surface* s;
223b71206888 Initial import
thib
parents:
diff changeset
909 if (with_mask == ALPHA_MASK) {
223b71206888 Initial import
thib
parents:
diff changeset
910 s = (Surface*)SDL_CreateRGBSurface(SDL_SRCALPHA, w, h, DefaultBpp, DefaultRmask, DefaultGmask, DefaultBmask, DefaultAmask);
223b71206888 Initial import
thib
parents:
diff changeset
911 } else {
223b71206888 Initial import
thib
parents:
diff changeset
912 s = (Surface*)SDL_CreateRGBSurface(0, w, h, DefaultBpp, DefaultRmask, DefaultGmask, DefaultBmask, 0);
223b71206888 Initial import
thib
parents:
diff changeset
913 }
223b71206888 Initial import
thib
parents:
diff changeset
914 return s;
223b71206888 Initial import
thib
parents:
diff changeset
915 }
223b71206888 Initial import
thib
parents:
diff changeset
916
223b71206888 Initial import
thib
parents:
diff changeset
917 Surface* PicRoot::NewSurfaceFromRGBAData(int w, int h, char* data, MaskType with_mask) const {
223b71206888 Initial import
thib
parents:
diff changeset
918 int amask = (with_mask == ALPHA_MASK) ? DefaultAmask : 0;
223b71206888 Initial import
thib
parents:
diff changeset
919 Surface* s = (Surface*)SDL_CreateRGBSurfaceFrom(data, w, h, DefaultBpp, w*4, DefaultRmask, DefaultGmask, DefaultBmask, amask);
223b71206888 Initial import
thib
parents:
diff changeset
920 s->flags &= ~SDL_PREALLOC;
223b71206888 Initial import
thib
parents:
diff changeset
921 return s;
223b71206888 Initial import
thib
parents:
diff changeset
922 };
223b71206888 Initial import
thib
parents:
diff changeset
923 Surface* PicRoot::NewSurface(const char* f, MaskType with_mask) {
223b71206888 Initial import
thib
parents:
diff changeset
924 if (f == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
925 Surface* s = ftosurface->Load(f);
223b71206888 Initial import
thib
parents:
diff changeset
926 if (s == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
927 if (with_mask == COLOR_MASK) {
223b71206888 Initial import
thib
parents:
diff changeset
928 SDL_SetColorKey( (SDL_Surface*)s, SDL_SRCCOLORKEY, *(Uint32*)s->pixels);
223b71206888 Initial import
thib
parents:
diff changeset
929 }
223b71206888 Initial import
thib
parents:
diff changeset
930 /* xkanon の残骸 */
223b71206888 Initial import
thib
parents:
diff changeset
931 if (strcmp(f, "grdat") == 0)
223b71206888 Initial import
thib
parents:
diff changeset
932 SDL_SetColorKey(s, SDL_SRCCOLORKEY, 0x55aa66);
223b71206888 Initial import
thib
parents:
diff changeset
933 return s;
223b71206888 Initial import
thib
parents:
diff changeset
934 }
223b71206888 Initial import
thib
parents:
diff changeset
935 Surface* PicRoot::RotZoomSurface(Surface* from, double zoom, double rotate) {
223b71206888 Initial import
thib
parents:
diff changeset
936 Surface* ret = (Surface*)rotozoomSurface( (SDL_Surface*)from, rotate, zoom, SMOOTHING_OFF);
223b71206888 Initial import
thib
parents:
diff changeset
937 return ret;
223b71206888 Initial import
thib
parents:
diff changeset
938 }
223b71206888 Initial import
thib
parents:
diff changeset
939 void PicRoot::DeleteSurfaceImpl(Surface* s) const {
223b71206888 Initial import
thib
parents:
diff changeset
940 SDL_FreeSurface(s);
223b71206888 Initial import
thib
parents:
diff changeset
941 }
223b71206888 Initial import
thib
parents:
diff changeset
942 void PicRoot::DeleteSurface(Surface* s) {
223b71206888 Initial import
thib
parents:
diff changeset
943 if (!ftosurface->Free(s))
223b71206888 Initial import
thib
parents:
diff changeset
944 DeleteSurfaceImpl(s);
223b71206888 Initial import
thib
parents:
diff changeset
945 }
223b71206888 Initial import
thib
parents:
diff changeset
946 inline SDL_Rect SDLed(const Rect& rect) {
223b71206888 Initial import
thib
parents:
diff changeset
947 SDL_Rect r;
223b71206888 Initial import
thib
parents:
diff changeset
948 r.x = rect.lx;
223b71206888 Initial import
thib
parents:
diff changeset
949 r.y = rect.ty;
223b71206888 Initial import
thib
parents:
diff changeset
950 r.w = rect.rx-rect.lx;
223b71206888 Initial import
thib
parents:
diff changeset
951 r.h = rect.by-rect.ty;
223b71206888 Initial import
thib
parents:
diff changeset
952 return r;
223b71206888 Initial import
thib
parents:
diff changeset
953 }
223b71206888 Initial import
thib
parents:
diff changeset
954
223b71206888 Initial import
thib
parents:
diff changeset
955 #ifndef ALPHA_MAX
223b71206888 Initial import
thib
parents:
diff changeset
956 #define ALPHA_MAX 255
223b71206888 Initial import
thib
parents:
diff changeset
957 #endif
223b71206888 Initial import
thib
parents:
diff changeset
958 void PicRoot::BlitSurface(Surface* src, const Rect& src_r, const unsigned char* alpha, const Rect& alpha_r, Surface* dest, const Rect& dest_r, int attribute) const {
223b71206888 Initial import
thib
parents:
diff changeset
959 if (print_blit) fprintf(stderr," s %08x %d:%d:%d:%d;",src, dest_r.lx, dest_r.ty, dest_r.rx, dest_r.by);
223b71206888 Initial import
thib
parents:
diff changeset
960 SDL_Rect sr = SDLed(src_r); SDL_Rect dr = SDLed(dest_r);
223b71206888 Initial import
thib
parents:
diff changeset
961 special_blit:
223b71206888 Initial import
thib
parents:
diff changeset
962 if (attribute & PicBase::BLIT_MULTIPLY) {
223b71206888 Initial import
thib
parents:
diff changeset
963 if (print_blit) fprintf(stderr,"M");
223b71206888 Initial import
thib
parents:
diff changeset
964 DSurfaceBlitMultiply(src, src_r, dest, dest_r);
223b71206888 Initial import
thib
parents:
diff changeset
965 return;
223b71206888 Initial import
thib
parents:
diff changeset
966 } else if (attribute & PicBase::BLIT_SATURATE) {
223b71206888 Initial import
thib
parents:
diff changeset
967 if (src->format->Amask != 0) goto normal_blit;
223b71206888 Initial import
thib
parents:
diff changeset
968 if (print_blit) fprintf(stderr,"S");
223b71206888 Initial import
thib
parents:
diff changeset
969 unsigned char a = 255;
223b71206888 Initial import
thib
parents:
diff changeset
970 if (alpha && alpha_r.width() >= 1 && alpha_r.height() >= 1) a = *alpha;
223b71206888 Initial import
thib
parents:
diff changeset
971 DSurfaceBlitSaturate(src, src_r, dest, dest_r, a);
223b71206888 Initial import
thib
parents:
diff changeset
972 return;
223b71206888 Initial import
thib
parents:
diff changeset
973 }
223b71206888 Initial import
thib
parents:
diff changeset
974 normal_blit:
223b71206888 Initial import
thib
parents:
diff changeset
975 if (print_blit) fprintf(stderr,"N");
223b71206888 Initial import
thib
parents:
diff changeset
976 if (alpha == 0 || alpha_r.width() == 0) { // simple blit
223b71206888 Initial import
thib
parents:
diff changeset
977 if (print_blit) fprintf(stderr,"X");
223b71206888 Initial import
thib
parents:
diff changeset
978 SDL_BlitSurface(src, &sr, dest, &dr);
223b71206888 Initial import
thib
parents:
diff changeset
979 return;
223b71206888 Initial import
thib
parents:
diff changeset
980 }
223b71206888 Initial import
thib
parents:
diff changeset
981 if (alpha_r.width() == 1 && alpha_r.height() == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
982 if (*alpha == 255) {
223b71206888 Initial import
thib
parents:
diff changeset
983 if (print_blit) fprintf(stderr,"Y");
223b71206888 Initial import
thib
parents:
diff changeset
984 SDL_BlitSurface(src, &sr, dest, &dr);
223b71206888 Initial import
thib
parents:
diff changeset
985 return;
223b71206888 Initial import
thib
parents:
diff changeset
986 }
223b71206888 Initial import
thib
parents:
diff changeset
987 if (src->format->Amask == 0) { // use per-surface alpha
223b71206888 Initial import
thib
parents:
diff changeset
988 if (print_blit) fprintf(stderr,"Z");
223b71206888 Initial import
thib
parents:
diff changeset
989 SDL_SetAlpha(src, SDL_SRCALPHA, *alpha);
223b71206888 Initial import
thib
parents:
diff changeset
990 SDL_BlitSurface(src, &sr, dest, &dr);
223b71206888 Initial import
thib
parents:
diff changeset
991 SDL_SetAlpha(src, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
992 return;
223b71206888 Initial import
thib
parents:
diff changeset
993 }
223b71206888 Initial import
thib
parents:
diff changeset
994 }
223b71206888 Initial import
thib
parents:
diff changeset
995 // generic alpha blit
223b71206888 Initial import
thib
parents:
diff changeset
996 if (print_blit) fprintf(stderr,"W");
223b71206888 Initial import
thib
parents:
diff changeset
997 DSurfaceBlitAlpha(src, src_r, dest, dest_r, alpha, alpha_r);
223b71206888 Initial import
thib
parents:
diff changeset
998 return;
223b71206888 Initial import
thib
parents:
diff changeset
999 }
223b71206888 Initial import
thib
parents:
diff changeset
1000
223b71206888 Initial import
thib
parents:
diff changeset
1001 bool PicRoot::with_mask(Surface* s) {
223b71206888 Initial import
thib
parents:
diff changeset
1002 return s->format->Amask != 0;
223b71206888 Initial import
thib
parents:
diff changeset
1003 }
223b71206888 Initial import
thib
parents:
diff changeset
1004
223b71206888 Initial import
thib
parents:
diff changeset
1005 #if USE_X11
223b71206888 Initial import
thib
parents:
diff changeset
1006 #include<SDL_syswm.h>
223b71206888 Initial import
thib
parents:
diff changeset
1007 #include<X11/Xlib.h>
223b71206888 Initial import
thib
parents:
diff changeset
1008 #include<X11/Xutil.h>
223b71206888 Initial import
thib
parents:
diff changeset
1009 #endif /* USE_X11 */
223b71206888 Initial import
thib
parents:
diff changeset
1010 void PicRoot::SetWindowCaption(const char* caption) {
223b71206888 Initial import
thib
parents:
diff changeset
1011 #if USE_X11
223b71206888 Initial import
thib
parents:
diff changeset
1012 // SDL_WM_SetCaption(caption, 0);
223b71206888 Initial import
thib
parents:
diff changeset
1013 // SDLの関数では2バイト文字をサポートしてくれないので、同等の内容に修正
223b71206888 Initial import
thib
parents:
diff changeset
1014 SDL_SysWMinfo info;
223b71206888 Initial import
thib
parents:
diff changeset
1015 memset(&info,0,sizeof(info));
223b71206888 Initial import
thib
parents:
diff changeset
1016 SDL_VERSION(&(info.version));
223b71206888 Initial import
thib
parents:
diff changeset
1017 if (SDL_GetWMInfo(&info) == 1) {
223b71206888 Initial import
thib
parents:
diff changeset
1018 Display* display = info.info.x11.display;
223b71206888 Initial import
thib
parents:
diff changeset
1019 Window wm = info.info.x11.wmwindow;
223b71206888 Initial import
thib
parents:
diff changeset
1020 if (wm == 0) wm = info.info.x11.window;
223b71206888 Initial import
thib
parents:
diff changeset
1021 if (wm != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1022 XTextProperty titleprop;
223b71206888 Initial import
thib
parents:
diff changeset
1023 XmbTextListToTextProperty(display, (char**)&caption, 1, XCompoundTextStyle, &titleprop);
223b71206888 Initial import
thib
parents:
diff changeset
1024 XSetWMName(display, wm, &titleprop);
223b71206888 Initial import
thib
parents:
diff changeset
1025 XSetWMIconName(display, wm, &titleprop);
223b71206888 Initial import
thib
parents:
diff changeset
1026 XFree(titleprop.value);
223b71206888 Initial import
thib
parents:
diff changeset
1027 }
223b71206888 Initial import
thib
parents:
diff changeset
1028 XSync(display, False);
223b71206888 Initial import
thib
parents:
diff changeset
1029 }
223b71206888 Initial import
thib
parents:
diff changeset
1030 #endif /* USE_X11 */
223b71206888 Initial import
thib
parents:
diff changeset
1031 }
223b71206888 Initial import
thib
parents:
diff changeset
1032
223b71206888 Initial import
thib
parents:
diff changeset
1033 /************************************************************
223b71206888 Initial import
thib
parents:
diff changeset
1034 ** PicAnm
223b71206888 Initial import
thib
parents:
diff changeset
1035 */
223b71206888 Initial import
thib
parents:
diff changeset
1036
223b71206888 Initial import
thib
parents:
diff changeset
1037 void PicBase::ClearAnm(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1038 while(!anm.empty()) {
223b71206888 Initial import
thib
parents:
diff changeset
1039 delete anm.back();
223b71206888 Initial import
thib
parents:
diff changeset
1040 }
223b71206888 Initial import
thib
parents:
diff changeset
1041 }
223b71206888 Initial import
thib
parents:
diff changeset
1042 PicAnm::PicAnm(PicBase* _pic) {
223b71206888 Initial import
thib
parents:
diff changeset
1043 pic.push_back(_pic);
223b71206888 Initial import
thib
parents:
diff changeset
1044 pic[0]->anm.push_back(this);
223b71206888 Initial import
thib
parents:
diff changeset
1045 return;
223b71206888 Initial import
thib
parents:
diff changeset
1046
223b71206888 Initial import
thib
parents:
diff changeset
1047 }
223b71206888 Initial import
thib
parents:
diff changeset
1048 PicAnm::PicAnm(vector<PicBase*> _pic) : pic(_pic) {
223b71206888 Initial import
thib
parents:
diff changeset
1049 if (pic.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
1050 pic[0]->anm.push_back(this);
223b71206888 Initial import
thib
parents:
diff changeset
1051 return;
223b71206888 Initial import
thib
parents:
diff changeset
1052 }
223b71206888 Initial import
thib
parents:
diff changeset
1053 PicAnm::~PicAnm() {
223b71206888 Initial import
thib
parents:
diff changeset
1054 vector<PicAnm*>::iterator it = find(pic[0]->anm.begin(), pic[0]->anm.end(), this);
223b71206888 Initial import
thib
parents:
diff changeset
1055 if (it == pic[0]->anm.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
1056 fprintf(stderr,"Cannot found this in PicAnm::~PicAnm()");
223b71206888 Initial import
thib
parents:
diff changeset
1057 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1058 pic[0]->anm.erase(it);
223b71206888 Initial import
thib
parents:
diff changeset
1059 }
223b71206888 Initial import
thib
parents:
diff changeset
1060 }