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
|
|
31 #include<vector>
|
|
32 #include<list>
|
|
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
|
|
47 /* PicBase ¤ÎÆâÍƤò¥¤¥Ù¥ó¥È¤ÈϢư¤µ¤»¤ë¤¿¤á¤Î¥¤¥ó¥¿¡¼¥Õ¥§¡¼¥¹ */
|
|
48 class PicAnm {
|
|
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();
|
|
55 };
|
|
56
|
|
57 class PicBase {
|
|
58 friend class PicContainer;
|
|
59 friend class PicWidget;
|
|
60
|
|
61 typedef std::list<PicBase*> List;
|
|
62 typedef std::list<PicBase*>::iterator iterator;
|
|
63
|
|
64 PicContainer* parent;
|
|
65 class PicWidget* widget;
|
|
66 Rect rel_pos; // relative position to the parent
|
|
67 Rect rel_solid_area; // solid area(not alpha-blended) to the parent
|
|
68 Rect clip_area; // clip area on the parent
|
|
69 bool is_hidden;
|
|
70 bool is_hidden_now;
|
|
71 bool is_cached;
|
|
72 public:
|
|
73 enum { /*MOBILE=1,*/ CACHE_BACK=2, /* CACHE_SELF=4,*/ NO_PICTURE=8, SOLID = 16, SURFACE_FREE = 32, FIT_SURFACE = 64, BLIT_SATURATE = 128, BLIT_MULTIPLY = 256, ALPHA_FREE=512};
|
|
74 private:
|
|
75 int attribute;
|
|
76
|
|
77 PicRoot* root;
|
|
78 iterator z_pos;
|
|
79 int surface_x, surface_y, surface_w, surface_h;
|
|
80 Surface* surface_back;
|
|
81 Surface* surface_own;
|
|
82 const unsigned char* surface_alpha;
|
|
83 Rect surface_alpha_rect;
|
|
84 int distance_root;
|
|
85
|
|
86 void Blit(const Rect& rpos);
|
|
87 void Blit(void) {
|
|
88 is_cached = true;
|
|
89 Blit(Rect(0, 0, rel_pos.width(), rel_pos.height()));
|
|
90 }
|
|
91 /*
|
|
92 ** rpos : relative position to the widget
|
|
93 ** ppos : relative position to the parent
|
|
94 ** ppos = parent_pos(rpos)
|
|
95 ** rpos = child_pos(ppos, parent->this_widget)
|
|
96 ** cpos : relative position to a child widget
|
|
97 ** cpos = child_pos(rpos, a_child_widget)
|
|
98 ** apos : absolute position in the screen
|
|
99 ** apos = QueryAbsPos(rpos);
|
|
100 ** or
|
|
101 ** Rect ppos = rel_pos;
|
|
102 ** apos = parent->QueryAbsPos(ppos);
|
|
103 ** the latter form is used for 'rel_pos',
|
|
104 ** because rel_pos is defined as the relative position to the parent
|
|
105 */
|
|
106 Rect QueryAbsPos(Rect& ppos); // ¤³¤Î picture Æâ¤Î rel_pos ¤òɽ¼¨¤¹¤ë¤Î¤Ë¼ÂºÝ¤ËɬÍפÊÀäÂкÂɸ¤òÆÀ¤ë
|
|
107
|
|
108 static Rect child_pos(Rect rpos, PicBase* child) { /* return 'cpos' */
|
|
109 rpos.intersect(child->rel_pos);
|
|
110 rpos.rmove( -(child->rel_pos.lx), -(child->rel_pos.ty));
|
|
111 return rpos;
|
|
112 }
|
|
113 Rect parent_pos(Rect rpos) { /* return 'ppos' */
|
|
114 rpos.rmove(rel_pos.lx, rel_pos.ty);
|
|
115 rpos.intersect(rel_pos);
|
|
116 return rpos;
|
|
117 }
|
|
118 void SetEventWidget(class PicWidget* widget);
|
|
119 public:
|
|
120 PicBase(const Rect& rel_pos, PicContainer* parent, int attr);
|
|
121 virtual ~PicBase();
|
|
122 void InitRoot(PicRoot* r) { root = r;} // only called from PicRoot::PicRoot
|
|
123
|
|
124 void ReBlit(const Rect& rpos);
|
|
125 void ReBlit(void) { ReBlit(Rect(0, 0, rel_pos.width(), rel_pos.height()));}
|
|
126 void ExecReBlit(const Rect& rpos);
|
|
127 void SimpleBlit(Surface* screen);
|
|
128
|
|
129 virtual void RMove(int add_x, int add_y);
|
|
130 void Move(int new_rx, int new_ry);
|
|
131 #define ZMOVE_TOP ((PicBase*)0xffff00ff) /* ºÇÁ°ÌÌ¤Ø */
|
|
132 #define ZMOVE_BOTTOM ((PicBase*)0xffff0fff) /* ºÇÇØÌÌ¤Ø */
|
|
133 void ZMove(PicBase* back); // back ¤ÎÁ°¤Ë°ÜÆ°(back ¤È¼«Ê¬¤ÏƱ¤¸¿Æ¤ò»ý¤Ä¤³¤È)
|
|
134
|
|
135 void SetSurface(Surface* new_surface, int x, int y, int attribute = 0);
|
|
136 void SetSurface(const char* new_surface, int x, int y);
|
|
137 void SetSurfacePos(int x, int y);
|
|
138 int SurfacePosX(void);
|
|
139 int SurfacePosY(void);
|
|
140 void SetSurfaceRect(const Rect& r);
|
|
141 void SetSurfaceAlpha(const unsigned char* alpha, const Rect& rect);
|
|
142 void SetSurfaceAlphaFile(const char* file);
|
|
143 void SetSurfaceColorKey(int r, int g, int b);
|
|
144 void SetSurfaceAttribute(int attribute);
|
|
145 void SetSurfaceFreeFlag(bool flag=true);
|
|
146 void SetClipArea(const Rect& r);
|
|
147
|
|
148 void hide(void);
|
|
149 void show_all(void);
|
|
150 void show(void);
|
|
151
|
|
152 int PosX(void) const { return rel_pos.lx;}
|
|
153 int PosY(void) const { return rel_pos.ty;}
|
|
154 int Width(void) const { return rel_pos.width();}
|
|
155 int Height(void) const { return rel_pos.height();}
|
|
156 int DistanceRoot(void) const { return distance_root; }
|
|
157 bool IsHidden(void) { return is_hidden_now;}
|
|
158 bool IsParent(PicBase* pic);
|
|
159
|
|
160 std::vector<PicAnm*> anm;
|
|
161 void ClearAnm(void);
|
|
162 };
|
|
163
|
|
164 class PicContainer : public PicBase {
|
|
165 friend class PicBase;
|
|
166
|
|
167 void BlitBack(iterator z, Rect rpos); // z ¤è¤ê¸å¤í¤ÎÎΰè¤òÉÁ²è
|
|
168 void BlitFront(iterator z, Rect rpos); // z ¤ò´Þ¤á¡¢z¤è¤êÁ°¤ÎÎΰè¤òÉÁ²è
|
|
169 void BlitChildren(Rect rpos);
|
|
170 void BlitSelf(Rect rpos);
|
|
171 void BlitSelf(void) {
|
|
172 is_cached = true;
|
|
173 BlitSelf(Rect(0, 0, rel_pos.width(), rel_pos.height()));
|
|
174 }
|
|
175 public:
|
|
176 List children;
|
|
177 private:
|
|
178
|
|
179 void set_showflag(void);
|
|
180 void set_nowhiddenflag(bool is_hide);
|
|
181 public:
|
|
182 PicContainer(const Rect& rel_pos, PicContainer* parent, int attr);
|
|
183 ~PicContainer();
|
|
184 PicBase* create_leaf(const Rect& rel_pos, int attr);
|
|
185 PicContainer* create_node(const Rect& rel_pos, int attr);
|
|
186 PicRoot& Root(void) { return *root;}
|
|
187 void RMove(int add_x, int add_y);
|
|
188 };
|
|
189
|
|
190 typedef enum { NO_MASK, ALPHA_MASK, COLOR_MASK} MaskType;
|
|
191 struct PicRoot {
|
|
192 class PicContainer* root;
|
|
193 private:
|
|
194 class FileToSurface* ftosurface;
|
|
195 struct UpdateItem {
|
|
196 PicBase* pic;
|
|
197 Rect rpos;
|
|
198 Rect apos;
|
|
199 static bool less(const UpdateItem&, const UpdateItem&);
|
|
200 UpdateItem(PicBase* p, const Rect& _rpos, const Rect& _apos) : pic(p), rpos(_rpos), apos(_apos) {}
|
|
201 };
|
|
202 std::vector<UpdateItem> update_rects;
|
|
203
|
|
204 friend class FileToSurface;
|
|
205 void DeleteSurfaceImpl(Surface* s) const;
|
|
206 public:
|
|
207 void Update(PicBase* pic, const Rect& rpos, const Rect& apos);
|
|
208 void DeleteUpdatePic(PicBase* pic);
|
|
209 void ExecUpdate(void);
|
|
210 void SetWindowCaption(const char* caption);
|
|
211
|
|
212 // Surface Áàºî
|
|
213 Surface* NewSurfaceFromRGBAData(int w, int h, char* data, MaskType with_mask) const; // data ¤Ï malloc ¤µ¤ì¤¿¤â¤Î¤Ç¤¢¤ë¤³¤È(SDL¤ÎÆâÉô»ÅÍÍ)
|
|
214 Surface* NewSurface(int w, int h, MaskType with_mask) const;
|
|
215 Surface* NewSurface(const char* filename, MaskType with_mask = ALPHA_MASK);
|
|
216 Surface* RotZoomSurface(Surface* from, double zoom, double rotate_angle);
|
|
217 void DeleteSurface(Surface* s);
|
|
218 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;
|
|
219 void BlitSurface(Surface* src, const Rect& src_rpos, Surface* dest, const Rect& dest_rpos) const {
|
|
220 BlitSurface(src, src_rpos, 0, Rect(0,0), dest, dest_rpos, 0);
|
|
221 }
|
|
222 static bool with_mask(Surface* src);
|
|
223
|
|
224 Surface* surface;
|
|
225 Surface* hw_surface;
|
|
226 int width, height;
|
|
227 PicRoot(void);
|
|
228 ~PicRoot();
|
|
229 PicBase* create_leaf(const Rect& apos, int attr) {
|
|
230 return root->create_leaf(apos, attr);
|
|
231 }
|
|
232 PicContainer* create_node(const Rect& apos, int attr) {
|
|
233 return root->create_node(apos, attr);
|
|
234 }
|
|
235 };
|
|
236
|
|
237 class PicWidget {
|
|
238 PicBase* pic; /* ËÜÍè·Ñ¾µ¤¹¤ë¤Ù¤¤À¤¬¡¢ÃÙ±ä½é´ü²½¤·¤¿¤¤¤Î¤Ç instance */
|
|
239 public:
|
|
240 PicWidget(void);
|
|
241 virtual ~PicWidget();
|
|
242 void SetPic(PicBase* new_pic);
|
|
243 PicBase* Pic(void);
|
|
244 PicContainer* PicNode(void);
|
|
245 virtual void activate(void);
|
|
246 virtual void deactivate(void);
|
|
247 virtual void SetRegion(const Rect& apos);
|
|
248 void show(void);
|
|
249 void hide(void);
|
|
250 void show_all(void);
|
|
251 };
|
|
252
|
|
253 #endif /* PICTURE */
|