annotate window/picture.cc @ 66:d112357a0ec1

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