Mercurial > otakunoraifu
annotate window/picture.h @ 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 |
rev | line source |
---|---|
31 | 1 /* |
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno | |
3 * All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * 3. The name of the author may not be used to endorse or promote products | |
14 * derived from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
0 | 28 #ifndef __PICTURE__ |
29 #define __PICTURE__ | |
30 | |
52 | 31 #include <vector> |
32 #include <list> | |
0 | 33 #ifdef HAVE_CONFIG_H |
34 # include "config.h" | |
35 #endif | |
36 | |
37 class PicBase; | |
38 class PicContainer; | |
39 class PicRoot; | |
40 | |
41 class Surface; | |
42 | |
43 namespace Event { | |
44 class Video; | |
45 } | |
46 | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
47 /* PicBase の内容をイベントと連動させるためのインターフェース */ |
0 | 48 class PicAnm { |
52 | 49 public: |
50 typedef std::vector<PicBase*>::iterator iterator; | |
51 std::vector<PicBase*> pic; | |
52 PicAnm(PicBase* pic); | |
53 PicAnm(std::vector<PicBase*> pic); | |
54 virtual ~PicAnm(); | |
0 | 55 }; |
56 | |
57 class PicBase { | |
52 | 58 private: |
59 friend class PicContainer; | |
60 friend class PicWidget; | |
0 | 61 |
52 | 62 typedef std::list<PicBase*> List; |
63 typedef std::list<PicBase*>::iterator iterator; | |
0 | 64 |
52 | 65 PicContainer* parent; |
66 class PicWidget* widget; | |
67 Rect rel_pos; // relative position to the parent | |
68 Rect rel_solid_area; // solid area(not alpha-blended) to the parent | |
69 Rect clip_area; // clip area on the parent | |
70 bool is_hidden; | |
71 bool is_hidden_now; | |
72 bool is_cached; | |
73 public: | |
60
e16e13d8cd68
Replaced SATURATE -> ADD, implemented objComposite, corrected minor things
Thibaut GIRKA <thib@sitedethib.com>
parents:
52
diff
changeset
|
74 enum { /*MOBILE=1,*/ CACHE_BACK=2, /* CACHE_SELF=4,*/ NO_PICTURE=8, SOLID = 16, SURFACE_FREE = 32, FIT_SURFACE = 64, BLIT_ADD = 128, BLIT_MULTIPLY = 256, ALPHA_FREE=512}; |
52 | 75 private: |
76 int attribute; | |
0 | 77 |
52 | 78 PicRoot* root; |
79 iterator z_pos; | |
80 int surface_x, surface_y, surface_w, surface_h; | |
81 Surface* surface_back; | |
82 Surface* surface_own; | |
83 const unsigned char* surface_alpha; | |
84 Rect surface_alpha_rect; | |
85 int distance_root; | |
0 | 86 |
52 | 87 void Blit(const Rect& rpos); |
88 void Blit(void) { | |
89 is_cached = true; | |
90 Blit(Rect(0, 0, rel_pos.width(), rel_pos.height())); | |
91 } | |
92 /* | |
93 ** rpos : relative position to the widget | |
94 ** ppos : relative position to the parent | |
95 ** ppos = parent_pos(rpos) | |
96 ** rpos = child_pos(ppos, parent->this_widget) | |
97 ** cpos : relative position to a child widget | |
98 ** cpos = child_pos(rpos, a_child_widget) | |
99 ** apos : absolute position in the screen | |
100 ** apos = QueryAbsPos(rpos); | |
101 ** or | |
102 ** Rect ppos = rel_pos; | |
103 ** apos = parent->QueryAbsPos(ppos); | |
104 ** the latter form is used for 'rel_pos', | |
105 ** because rel_pos is defined as the relative position to the parent | |
106 */ | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
107 Rect QueryAbsPos(Rect& ppos); // この picture 内の rel_pos を表示するのに実際に必要な絶対座標を得る |
0 | 108 |
52 | 109 static Rect child_pos(Rect rpos, PicBase* child) { /* return 'cpos' */ |
110 rpos.intersect(child->rel_pos); | |
111 rpos.rmove( -(child->rel_pos.lx), -(child->rel_pos.ty)); | |
112 return rpos; | |
113 } | |
114 Rect parent_pos(Rect rpos) { /* return 'ppos' */ | |
115 rpos.rmove(rel_pos.lx, rel_pos.ty); | |
116 rpos.intersect(rel_pos); | |
117 return rpos; | |
118 } | |
119 void SetEventWidget(class PicWidget* widget); | |
120 public: | |
121 PicBase(const Rect& rel_pos, PicContainer* parent, int attr); | |
122 virtual ~PicBase(); | |
123 void InitRoot(PicRoot* r) { root = r;} // only called from PicRoot::PicRoot | |
0 | 124 |
52 | 125 void ReBlit(const Rect& rpos); |
126 void ReBlit(void) { ReBlit(Rect(0, 0, rel_pos.width(), rel_pos.height()));} | |
127 void ExecReBlit(const Rect& rpos); | |
128 void SimpleBlit(Surface* screen); | |
0 | 129 |
52 | 130 virtual void RMove(int add_x, int add_y); |
131 void Move(int new_rx, int new_ry); | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
132 #define ZMOVE_TOP ((PicBase*)0xffff00ff) /* 最前面へ */ |
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
133 #define ZMOVE_BOTTOM ((PicBase*)0xffff0fff) /* 最背面へ */ |
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
134 void ZMove(PicBase* back); // back の前に移動(back と自分は同じ親を持つこと) |
0 | 135 |
52 | 136 void SetSurface(Surface* new_surface, int x, int y, int attribute = 0); |
137 void SetSurface(const char* new_surface, int x, int y); | |
138 void SetSurfacePos(int x, int y); | |
139 int SurfacePosX(void); | |
140 int SurfacePosY(void); | |
141 void SetSurfaceRect(const Rect& r); | |
142 void SetSurfaceAlpha(const unsigned char* alpha, const Rect& rect); | |
143 void SetSurfaceAlphaFile(const char* file); | |
144 void SetSurfaceColorKey(int r, int g, int b); | |
145 void SetSurfaceAttribute(int attribute); | |
146 void SetSurfaceFreeFlag(bool flag=true); | |
147 void SetClipArea(const Rect& r); | |
0 | 148 |
52 | 149 void hide(void); |
150 void show_all(void); | |
151 void show(void); | |
0 | 152 |
52 | 153 int PosX(void) const { return rel_pos.lx;} |
154 int PosY(void) const { return rel_pos.ty;} | |
155 int Width(void) const { return rel_pos.width();} | |
156 int Height(void) const { return rel_pos.height();} | |
157 int DistanceRoot(void) const { return distance_root; } | |
158 bool IsHidden(void) { return is_hidden_now;} | |
159 bool IsParent(PicBase* pic); | |
0 | 160 |
52 | 161 std::vector<PicAnm*> anm; |
162 void ClearAnm(void); | |
0 | 163 }; |
164 | |
165 class PicContainer : public PicBase { | |
52 | 166 private: |
167 friend class PicBase; | |
0 | 168 |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
169 void BlitBack(iterator z, Rect rpos); // z より後ろの領域を描画 |
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
170 void BlitFront(iterator z, Rect rpos); // z を含め、zより前の領域を描画 |
52 | 171 void BlitChildren(Rect rpos); |
172 void BlitSelf(Rect rpos); | |
173 void BlitSelf(void) { | |
174 is_cached = true; | |
175 BlitSelf(Rect(0, 0, rel_pos.width(), rel_pos.height())); | |
176 } | |
177 public: | |
178 List children; | |
179 private: | |
0 | 180 |
52 | 181 void set_showflag(void); |
182 void set_nowhiddenflag(bool is_hide); | |
183 public: | |
184 PicContainer(const Rect& rel_pos, PicContainer* parent, int attr); | |
185 ~PicContainer(); | |
186 PicBase* create_leaf(const Rect& rel_pos, int attr); | |
187 PicContainer* create_node(const Rect& rel_pos, int attr); | |
188 PicRoot& Root(void) { return *root;} | |
189 void RMove(int add_x, int add_y); | |
0 | 190 }; |
191 | |
192 typedef enum { NO_MASK, ALPHA_MASK, COLOR_MASK} MaskType; | |
193 struct PicRoot { | |
52 | 194 public: |
195 class PicContainer* root; | |
196 private: | |
197 class FileToSurface* ftosurface; | |
198 struct UpdateItem { | |
199 PicBase* pic; | |
200 Rect rpos; | |
201 Rect apos; | |
202 static bool less(const UpdateItem&, const UpdateItem&); | |
203 UpdateItem(PicBase* p, const Rect& _rpos, const Rect& _apos) : pic(p), rpos(_rpos), apos(_apos) {} | |
204 }; | |
205 std::vector<UpdateItem> update_rects; | |
0 | 206 |
52 | 207 friend class FileToSurface; |
208 void DeleteSurfaceImpl(Surface* s) const; | |
209 public: | |
210 void Update(PicBase* pic, const Rect& rpos, const Rect& apos); | |
211 void DeleteUpdatePic(PicBase* pic); | |
212 void ExecUpdate(void); | |
213 void SetWindowCaption(const char* caption); | |
0 | 214 |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
215 // Surface 操作 |
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
216 Surface* NewSurfaceFromRGBAData(int w, int h, char* data, MaskType with_mask) const; // data は malloc されたものであること(SDLの内部仕様) |
52 | 217 Surface* NewSurface(int w, int h, MaskType with_mask) const; |
218 Surface* NewSurface(const char* filename, MaskType with_mask = ALPHA_MASK); | |
219 Surface* RotZoomSurface(Surface* from, double zoom, double rotate_angle); | |
220 void DeleteSurface(Surface* s); | |
221 void BlitSurface(Surface* src, const Rect& src_rpos, const unsigned char* alpha, const Rect& alpha_r, Surface* dest, const Rect& dest_rpos, int attribute) const; | |
222 void BlitSurface(Surface* src, const Rect& src_rpos, Surface* dest, const Rect& dest_rpos) const { | |
223 BlitSurface(src, src_rpos, 0, Rect(0,0), dest, dest_rpos, 0); | |
224 } | |
225 static bool with_mask(Surface* src); | |
0 | 226 |
52 | 227 Surface* surface; |
228 Surface* hw_surface; | |
229 int width, height; | |
230 PicRoot(void); | |
231 ~PicRoot(); | |
232 PicBase* create_leaf(const Rect& apos, int attr) { | |
233 return root->create_leaf(apos, attr); | |
234 } | |
235 PicContainer* create_node(const Rect& apos, int attr) { | |
236 return root->create_node(apos, attr); | |
237 } | |
0 | 238 }; |
239 | |
240 class PicWidget { | |
52 | 241 private: |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
60
diff
changeset
|
242 PicBase* pic; /* 本来継承するべきだが、遅延初期化したいので instance */ |
52 | 243 public: |
244 PicWidget(void); | |
245 virtual ~PicWidget(); | |
246 void SetPic(PicBase* new_pic); | |
247 PicBase* Pic(void); | |
248 PicContainer* PicNode(void); | |
249 virtual void activate(void); | |
250 virtual void deactivate(void); | |
251 virtual void SetRegion(const Rect& apos); | |
252 void show(void); | |
253 void hide(void); | |
254 void show_all(void); | |
0 | 255 }; |
256 | |
257 #endif /* PICTURE */ |