annotate window/picture.h @ 18:4d7486cb20a9

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