0
|
1 #ifndef __PICTURE__
|
|
2 #define __PICTURE__
|
|
3
|
|
4 #include<vector>
|
|
5 #include<list>
|
|
6 #ifdef HAVE_CONFIG_H
|
|
7 # include "config.h"
|
|
8 #endif
|
|
9
|
|
10 class PicBase;
|
|
11 class PicContainer;
|
|
12 class PicRoot;
|
|
13
|
|
14 class Surface;
|
|
15
|
|
16 namespace Event {
|
|
17 class Video;
|
|
18 }
|
|
19
|
|
20 /* PicBase の内容をイベントと連動させるためのインターフェース */
|
|
21 class PicAnm {
|
|
22 public:
|
|
23 typedef std::vector<PicBase*>::iterator iterator;
|
|
24 std::vector<PicBase*> pic;
|
|
25 PicAnm(PicBase* pic);
|
|
26 PicAnm(std::vector<PicBase*> pic);
|
|
27 virtual ~PicAnm();
|
|
28 };
|
|
29
|
|
30 class PicBase {
|
|
31 friend class PicContainer;
|
|
32 friend class PicWidget;
|
|
33
|
|
34 typedef std::list<PicBase*> List;
|
|
35 typedef std::list<PicBase*>::iterator iterator;
|
|
36
|
|
37 PicContainer* parent;
|
|
38 class PicWidget* widget;
|
|
39 Rect rel_pos; // relative position to the parent
|
|
40 Rect rel_solid_area; // solid area(not alpha-blended) to the parent
|
|
41 Rect clip_area; // clip area on the parent
|
|
42 bool is_hidden;
|
|
43 bool is_hidden_now;
|
|
44 bool is_cached;
|
|
45 public:
|
|
46 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};
|
|
47 private:
|
|
48 int attribute;
|
|
49
|
|
50 PicRoot* root;
|
|
51 iterator z_pos;
|
|
52 int surface_x, surface_y, surface_w, surface_h;
|
|
53 Surface* surface_back;
|
|
54 Surface* surface_own;
|
|
55 const unsigned char* surface_alpha;
|
|
56 Rect surface_alpha_rect;
|
|
57 int distance_root;
|
|
58
|
|
59 void Blit(const Rect& rpos);
|
|
60 void Blit(void) {
|
|
61 is_cached = true;
|
|
62 Blit(Rect(0, 0, rel_pos.width(), rel_pos.height()));
|
|
63 }
|
|
64 /*
|
|
65 ** rpos : relative position to the widget
|
|
66 ** ppos : relative position to the parent
|
|
67 ** ppos = parent_pos(rpos)
|
|
68 ** rpos = child_pos(ppos, parent->this_widget)
|
|
69 ** cpos : relative position to a child widget
|
|
70 ** cpos = child_pos(rpos, a_child_widget)
|
|
71 ** apos : absolute position in the screen
|
|
72 ** apos = QueryAbsPos(rpos);
|
|
73 ** or
|
|
74 ** Rect ppos = rel_pos;
|
|
75 ** apos = parent->QueryAbsPos(ppos);
|
|
76 ** the latter form is used for 'rel_pos',
|
|
77 ** because rel_pos is defined as the relative position to the parent
|
|
78 */
|
|
79 Rect QueryAbsPos(Rect& ppos); // この picture 内の rel_pos を表示するのに実際に必要な絶対座標を得る
|
|
80
|
|
81 static Rect child_pos(Rect rpos, PicBase* child) { /* return 'cpos' */
|
|
82 rpos.intersect(child->rel_pos);
|
|
83 rpos.rmove( -(child->rel_pos.lx), -(child->rel_pos.ty));
|
|
84 return rpos;
|
|
85 }
|
|
86 Rect parent_pos(Rect rpos) { /* return 'ppos' */
|
|
87 rpos.rmove(rel_pos.lx, rel_pos.ty);
|
|
88 rpos.intersect(rel_pos);
|
|
89 return rpos;
|
|
90 }
|
|
91 void SetEventWidget(class PicWidget* widget);
|
|
92 public:
|
|
93 PicBase(const Rect& rel_pos, PicContainer* parent, int attr);
|
|
94 virtual ~PicBase();
|
|
95 void InitRoot(PicRoot* r) { root = r;} // only called from PicRoot::PicRoot
|
|
96
|
|
97 void ReBlit(const Rect& rpos);
|
|
98 void ReBlit(void) { ReBlit(Rect(0, 0, rel_pos.width(), rel_pos.height()));}
|
|
99 void ExecReBlit(const Rect& rpos);
|
|
100 void SimpleBlit(Surface* screen);
|
|
101
|
|
102 virtual void RMove(int add_x, int add_y);
|
|
103 void Move(int new_rx, int new_ry);
|
|
104 #define ZMOVE_TOP ((PicBase*)0xffff00ff) /* 最前面へ */
|
|
105 #define ZMOVE_BOTTOM ((PicBase*)0xffff0fff) /* 最背面へ */
|
|
106 void ZMove(PicBase* back); // back の前に移動(back と自分は同じ親を持つこと)
|
|
107
|
|
108 void SetSurface(Surface* new_surface, int x, int y, int attribute = 0);
|
|
109 void SetSurface(const char* new_surface, int x, int y);
|
|
110 void SetSurfacePos(int x, int y);
|
|
111 int SurfacePosX(void);
|
|
112 int SurfacePosY(void);
|
|
113 void SetSurfaceRect(const Rect& r);
|
|
114 void SetSurfaceAlpha(const unsigned char* alpha, const Rect& rect);
|
|
115 void SetSurfaceAlphaFile(const char* file);
|
|
116 void SetSurfaceColorKey(int r, int g, int b);
|
|
117 void SetSurfaceAttribute(int attribute);
|
|
118 void SetSurfaceFreeFlag(bool flag=true);
|
|
119 void SetClipArea(const Rect& r);
|
|
120
|
|
121 void hide(void);
|
|
122 void show_all(void);
|
|
123 void show(void);
|
|
124
|
|
125 int PosX(void) const { return rel_pos.lx;}
|
|
126 int PosY(void) const { return rel_pos.ty;}
|
|
127 int Width(void) const { return rel_pos.width();}
|
|
128 int Height(void) const { return rel_pos.height();}
|
|
129 int DistanceRoot(void) const { return distance_root; }
|
|
130 bool IsHidden(void) { return is_hidden_now;}
|
|
131 bool IsParent(PicBase* pic);
|
|
132
|
|
133 std::vector<PicAnm*> anm;
|
|
134 void ClearAnm(void);
|
|
135 };
|
|
136
|
|
137 class PicContainer : public PicBase {
|
|
138 friend class PicBase;
|
|
139
|
|
140 void BlitBack(iterator z, Rect rpos); // z より後ろの領域を描画
|
|
141 void BlitFront(iterator z, Rect rpos); // z を含め、zより前の領域を描画
|
|
142 void BlitChildren(Rect rpos);
|
|
143 void BlitSelf(Rect rpos);
|
|
144 void BlitSelf(void) {
|
|
145 is_cached = true;
|
|
146 BlitSelf(Rect(0, 0, rel_pos.width(), rel_pos.height()));
|
|
147 }
|
|
148 public:
|
|
149 List children;
|
|
150 private:
|
|
151
|
|
152 void set_showflag(void);
|
|
153 void set_nowhiddenflag(bool is_hide);
|
|
154 public:
|
|
155 PicContainer(const Rect& rel_pos, PicContainer* parent, int attr);
|
|
156 ~PicContainer();
|
|
157 PicBase* create_leaf(const Rect& rel_pos, int attr);
|
|
158 PicContainer* create_node(const Rect& rel_pos, int attr);
|
|
159 PicRoot& Root(void) { return *root;}
|
|
160 void RMove(int add_x, int add_y);
|
|
161 };
|
|
162
|
|
163 typedef enum { NO_MASK, ALPHA_MASK, COLOR_MASK} MaskType;
|
|
164 struct PicRoot {
|
|
165 class PicContainer* root;
|
|
166 private:
|
|
167 class FileToSurface* ftosurface;
|
|
168 struct UpdateItem {
|
|
169 PicBase* pic;
|
|
170 Rect rpos;
|
|
171 Rect apos;
|
|
172 static bool less(const UpdateItem&, const UpdateItem&);
|
|
173 UpdateItem(PicBase* p, const Rect& _rpos, const Rect& _apos) : pic(p), rpos(_rpos), apos(_apos) {}
|
|
174 };
|
|
175 std::vector<UpdateItem> update_rects;
|
|
176
|
|
177 friend class FileToSurface;
|
|
178 void DeleteSurfaceImpl(Surface* s) const;
|
|
179 public:
|
|
180 void Update(PicBase* pic, const Rect& rpos, const Rect& apos);
|
|
181 void DeleteUpdatePic(PicBase* pic);
|
|
182 void ExecUpdate(void);
|
|
183 void SetWindowCaption(const char* caption);
|
|
184
|
|
185 // Surface 操作
|
|
186 Surface* NewSurfaceFromRGBAData(int w, int h, char* data, MaskType with_mask) const; // data は malloc されたものであること(SDLの内部仕様)
|
|
187 Surface* NewSurface(int w, int h, MaskType with_mask) const;
|
|
188 Surface* NewSurface(const char* filename, MaskType with_mask = ALPHA_MASK);
|
|
189 Surface* RotZoomSurface(Surface* from, double zoom, double rotate_angle);
|
|
190 void DeleteSurface(Surface* s);
|
|
191 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;
|
|
192 void BlitSurface(Surface* src, const Rect& src_rpos, Surface* dest, const Rect& dest_rpos) const {
|
|
193 BlitSurface(src, src_rpos, 0, Rect(0,0), dest, dest_rpos, 0);
|
|
194 }
|
|
195 static bool with_mask(Surface* src);
|
|
196
|
|
197 Surface* surface;
|
|
198 Surface* hw_surface;
|
|
199 int width, height;
|
|
200 PicRoot(void);
|
|
201 ~PicRoot();
|
|
202 PicBase* create_leaf(const Rect& apos, int attr) {
|
|
203 return root->create_leaf(apos, attr);
|
|
204 }
|
|
205 PicContainer* create_node(const Rect& apos, int attr) {
|
|
206 return root->create_node(apos, attr);
|
|
207 }
|
|
208 };
|
|
209
|
|
210 class PicWidget {
|
|
211 PicBase* pic; /* 本来継承するべきだが、遅延初期化したいので instance */
|
|
212 public:
|
|
213 PicWidget(void);
|
|
214 virtual ~PicWidget();
|
|
215 void SetPic(PicBase* new_pic);
|
|
216 PicBase* Pic(void);
|
|
217 PicContainer* PicNode(void);
|
|
218 virtual void activate(void);
|
|
219 virtual void deactivate(void);
|
|
220 virtual void SetRegion(const Rect& apos);
|
|
221 void show(void);
|
|
222 void hide(void);
|
|
223 void show_all(void);
|
|
224 };
|
|
225
|
|
226 #endif /* PICTURE */
|