annotate window/picture.cc @ 59:36d92d21300f

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