annotate window/picture.cc @ 44:a85cdca1980a

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