comparison window/widget.h @ 52:15a18fbe6f21

* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author thib
date Sat, 18 Apr 2009 18:35:39 +0000
parents 5ae5533b3a9a
children 4416cfac86ae
comparison
equal deleted inserted replaced
51:cbb301016a4e 52:15a18fbe6f21
26 */ 26 */
27 27
28 #ifndef __WIDGET_H__ 28 #ifndef __WIDGET_H__
29 #define __WIDGET_H__ 29 #define __WIDGET_H__
30 30
31 #include<vector> 31 #include <vector>
32 #include"font/font.h" 32 #include "font/font.h"
33 #include"font/text.h" 33 #include "font/text.h"
34 #include"event.h" 34 #include "event.h"
35 #include"picture.h" 35 #include "picture.h"
36 36
37 #define TimeCursor WidTimeCursor 37 #define TimeCursor WidTimeCursor
38 #define MouseCursor WidMouseCursor 38 #define MouseCursor WidMouseCursor
39 #define Button WidButton 39 #define Button WidButton
40 #define Scale WidScale 40 #define Scale WidScale
49 #define AnmPtnAlpha WidAnmPtnAlpha 49 #define AnmPtnAlpha WidAnmPtnAlpha
50 50
51 // namespace Widget { 51 // namespace Widget {
52 52
53 struct TimeCursor : public Event::Time, PicWidget { 53 struct TimeCursor : public Event::Time, PicWidget {
54 int x,y,dx,dy, nptn; 54 int x, y, dx, dy, nptn;
55 int old_time, count, interval; 55 int old_time, count, interval;
56 TimeCursor(Event::Container& container, int _interval, PicContainer* parent, const char* fname, int sx, int sy, int sdx, int sdy, int nptn, const Rect& r); 56 TimeCursor(Event::Container& container, int _interval, PicContainer* parent, const char* fname, int sx, int sy, int sdx, int sdy, int nptn, const Rect& r);
57 void Elapsed(unsigned int current_time); 57 void Elapsed(unsigned int current_time);
58 }; 58 };
59 59
91 void activate(void) { Event::Video::activate();} 91 void activate(void) { Event::Video::activate();}
92 void deactivate(void) { Event::Video::deactivate();} 92 void deactivate(void) { Event::Video::deactivate();}
93 void SetRegion(const Rect& new_rect) { Event::Video::SetRegion(new_rect);} 93 void SetRegion(const Rect& new_rect) { Event::Video::SetRegion(new_rect);}
94 }; 94 };
95 struct Scale : Event::Video, PicWidget { 95 struct Scale : Event::Video, PicWidget {
96 private: 96 private:
97 Button* arrow_down, *arrow_up; 97 Button* arrow_down, *arrow_up;
98 Button* cursor; 98 Button* cursor;
99 PicContainer* panel; 99 PicContainer* panel;
100 Event::Container& container; 100 Event::Container& container;
101 PicContainer* parent; 101 PicContainer* parent;
102 Color cursor_color; 102 Color cursor_color;
103 103
104 int mouse_x, mouse_y; 104 int mouse_x, mouse_y;
105 enum {scale_max = 65536}; 105 enum {scale_max = 65536};
106 int min, max; 106 int min, max;
107 int value; 107 int value;
108 int value_add; 108 int value_add;
109 int value_dragstart; 109 int value_dragstart;
110 int cursor_width; 110 int cursor_width;
111 bool is_vertical; 111 bool is_vertical;
112 112
113 public: 113 public:
114 114 Scale(Event::Container& container, PicContainer* parent, const Rect& r_orig, const Color& cursor_color, bool _is_vertical);
115 Scale(Event::Container& container, PicContainer* parent, const Rect& r_orig, const Color& cursor_color, bool _is_vertical); 115 void InitCursor(int cursor_width_ratio); // 1024=max
116 void InitCursor(int cursor_width_ratio); // 1024=max 116 void SetRange(int min, int max);
117 void SetRange(int min, int max); 117 void SetValue(int value);
118 void SetValue(int value); 118 int GetValue(void) const;
119 int GetValue(void) const; 119 typedef void (*ChangeFunc)(void* pointer, Scale* from);
120 typedef void (*ChangeFunc)(void* pointer, Scale* from); 120 ChangeFunc change_func;
121 ChangeFunc change_func; 121 void* change_pointer;
122 void* change_pointer; 122
123 private: 123 private:
124 void Init(Rect r_orig); 124 void Init(Rect r_orig);
125 int CalcValue(void); 125 int CalcValue(void);
126 void SetScaleValue(int value); 126 void SetScaleValue(int value);
127 127
128 // callback 128 // callback
129 static void PressArrowDown(void* pointer, Button* from); 129 static void PressArrowDown(void* pointer, Button* from);
130 static void PressArrowUp(void* pointer, Button* from); 130 static void PressArrowUp(void* pointer, Button* from);
131 static void PressCursor(void* pointer, Button* from); 131 static void PressCursor(void* pointer, Button* from);
132 static void DragCursor(int x_from, int y_from,int x, int y, void* pointer, Button* from); 132 static void DragCursor(int x_from, int y_from,int x, int y, void* pointer, Button* from);
133 133
134 // 费镜¨Event::Video 134 // 费镜¨Event::Video
135 void Press(void); 135 void Press(void);
136 void Motion(int x, int y); 136 void Motion(int x, int y);
137 137
138 /* 费镜 : PicWidget */ 138 /* 费镜 : PicWidget */
139 void activate(void) { Event::Video::activate();} 139 void activate(void) { Event::Video::activate();}
140 void deactivate(void) { Event::Video::deactivate();} 140 void deactivate(void) { Event::Video::deactivate();}
141 void SetRegion(const Rect& new_rect) { Event::Video::SetRegion(new_rect);} 141 void SetRegion(const Rect& new_rect) { Event::Video::SetRegion(new_rect);}
142 }; 142 };
143 143
144 struct TextButton : public Button { 144 struct TextButton : public Button {
145 enum Attribute {CENTER=1, REVERSE=2, NOPADDING=4}; 145 enum Attribute {CENTER=1, REVERSE=2, NOPADDING=4};
146 PicRoot& root; 146 PicRoot& root;
157 }; 157 };
158 158
159 struct Text : public Event::Video, Event::Time, PicWidget { 159 struct Text : public Event::Video, Event::Time, PicWidget {
160 typedef TextGlyphStream::iterator iterator; 160 typedef TextGlyphStream::iterator iterator;
161 161
162 private: 162 private:
163 Event::Container& event; 163 Event::Container& event;
164 public: 164 public:
165 PicBase* pictext; 165 PicBase* pictext;
166 private: 166 private:
167 TimeCursor* cursor; 167 TimeCursor* cursor;
168 Surface* surface; 168 Surface* surface;
169 TextGlyphStream gstream; 169 TextGlyphStream gstream;
170 std::vector<int> bottom_pos; // 乖光さ(height)の芜纷猛 170 std::vector<int> bottom_pos; // 乖光さ(height)の芜纷猛
171 XKFont::HorizLayout layout; 171 XKFont::HorizLayout layout;
172 int fontsize; 172 int fontsize;
173 173
174 iterator cur_pos; 174 iterator cur_pos;
175 int line_number; 175 int line_number;
176 Rect srcrect; 176 Rect srcrect;
177 int press_count; 177 int press_count;
178 int scrolled_count; 178 int scrolled_count;
179 int scroll_height; 179 int scroll_height;
180 bool window_activated; 180 bool window_activated;
181 bool cursor_activated; 181 bool cursor_activated;
182 182
183 int speed; // chars / sec or -1 183 int speed; // chars / sec or -1
184 int wait_delay; // msec 184 int wait_delay; // msec
185 int old_time; 185 int old_time;
186 int wait_starttime; 186 int wait_starttime;
187 187
188 int CalcScrollHeight(void); 188 int CalcScrollHeight(void);
189 void DrawText(int& nChar); 189 void DrawText(int& nChar);
190 void Scrollup(int& nChar); 190 void Scrollup(int& nChar);
191 public: 191
192 Text(Event::Container& container, PicContainer* parent, const Rect& r, const Rect& text_r, int fontsize); 192 public:
193 ~Text(); 193 Text(Event::Container& container, PicContainer* parent, const Rect& r, const Rect& text_r, int fontsize);
194 194 ~Text();
195 TextStream stream; 195
196 enum {PREPARE, DRAW, WAIT, SCROLL, DRAW2, WAIT2} status; 196 TextStream stream;
197 197 enum {PREPARE, DRAW, WAIT, SCROLL, DRAW2, WAIT2} status;
198 void Clear(void); 198
199 void Start(void); 199 void Clear(void);
200 void Flush(void); 200 void Start(void);
201 201 void Flush(void);
202 void Elapsed(unsigned int current_time); 202
203 static bool Pressed(int x, int y, void* pointer); 203 void Elapsed(unsigned int current_time);
204 void activate(void); 204 static bool Pressed(int x, int y, void* pointer);
205 void deactivate(void); 205 void activate(void);
206 void SetSpeed(int new_speed); 206 void deactivate(void);
207 void SetWait(int new_wait); 207 void SetSpeed(int new_speed);
208 208 void SetWait(int new_wait);
209 void SetCursor(TimeCursor* cursor); 209
210 void SetCursor(TimeCursor* cursor);
210 }; 211 };
211 212
212 extern void SetFont(const char* fontname); 213 extern void SetFont(const char* fontname);
213 214
214 struct Label : PicWidget{ 215 struct Label : PicWidget{
215 private: 216 private:
216 Surface* surface; 217 Surface* surface;
217 bool is_center; 218 bool is_center;
218 PicRoot& root; 219 PicRoot& root;
219 int text_size; 220 int text_size;
220 public: 221 public:
221 Label(PicContainer* parent, const Rect& r_orig, bool is_center=true, const char* text=0, int textsize = 26); 222 Label(PicContainer* parent, const Rect& r_orig, bool is_center=true, const char* text=0, int textsize = 26);
222 ~Label(); 223 ~Label();
223 void SetText(const char* text); 224 void SetText(const char* text);
224 }; 225 };
225 226
226 class Dialog : public Event::Video, PicWidget { 227 class Dialog : public Event::Video, PicWidget {
227 Surface* surface_btn; 228 private:
228 Surface* surface_diag; 229 Surface* surface_btn;
229 public: 230 Surface* surface_diag;
230 enum { WAIT, OK, CANCEL} status; 231
231 Dialog(Event::Container& container, PicContainer* parent, const char* text, bool with_cancel); 232 public:
232 ~Dialog(); 233 enum { WAIT, OK, CANCEL} status;
233 static void press_ok(void* pointer, Button* btn); 234 Dialog(Event::Container& container, PicContainer* parent, const char* text, bool with_cancel);
234 static void press_cancel(void* pointer, Button* btn); 235 ~Dialog();
235 static void DrawBox(Surface* s, const Rect& r); 236 static void press_ok(void* pointer, Button* btn);
236 typedef void (*SetFunc)(void* pointer, Dialog* from); 237 static void press_cancel(void* pointer, Button* btn);
237 SetFunc set_func; 238 static void DrawBox(Surface* s, const Rect& r);
238 void* set_pointer; 239 typedef void (*SetFunc)(void* pointer, Dialog* from);
240 SetFunc set_func;
241 void* set_pointer;
239 }; 242 };
240 243
241 struct AnmTime : public Event::Time, PicAnm { 244 struct AnmTime : public Event::Time, PicAnm {
242 enum { PLAYING=1, FINISHED=3 } status; 245 enum { PLAYING=1, FINISHED=3 } status;
243 unsigned int start_time; 246 unsigned int start_time;
265 struct AnmMove : public AnmTime { 268 struct AnmMove : public AnmTime {
266 Rect from, to; 269 Rect from, to;
267 AnmMove(Event::Container& container, PicBase* _pic, const Rect& to, int total_time); 270 AnmMove(Event::Container& container, PicBase* _pic, const Rect& to, int total_time);
268 void Exec(int count); 271 void Exec(int count);
269 }; 272 };
273
270 #define ALPHA_MAX 255 274 #define ALPHA_MAX 255
271 struct AnmAlpha : public AnmTime { 275 struct AnmAlpha : public AnmTime {
272 int from, to; 276 int from, to;
273 unsigned char alpha; Rect alpha_r; 277 unsigned char alpha; Rect alpha_r;
274 AnmAlpha(Event::Container& container, PicBase* _pic, int alpha_from, int alpha_to, int total_time); 278 AnmAlpha(Event::Container& container, PicBase* _pic, int alpha_from, int alpha_to, int total_time);
275 AnmAlpha(Event::Container& container, std::vector<PicBase*> _pic, int alpha_from, int alpha_to, int total_time); 279 AnmAlpha(Event::Container& container, std::vector<PicBase*> _pic, int alpha_from, int alpha_to, int total_time);
276 void Start(void); 280 void Start(void);
277 void Exec(int count); 281 void Exec(int count);
278 void Finish(void); 282 void Finish(void);
279 }; 283 };
284
280 struct AnmAlphaMove : public AnmTime { 285 struct AnmAlphaMove : public AnmTime {
281 struct Ptn { 286 struct Ptn {
282 Rect pos; 287 Rect pos;
283 Rect surface_pos; 288 Rect surface_pos;
284 unsigned char alpha; 289 unsigned char alpha;
291 AnmAlphaMove(Event::Container& container, PicBase* _pic); 296 AnmAlphaMove(Event::Container& container, PicBase* _pic);
292 void SetPtn(void); 297 void SetPtn(void);
293 void Exec(int count); 298 void Exec(int count);
294 void Finish(void); 299 void Finish(void);
295 }; 300 };
301
296 struct AnmPtnSolid : public AnmTime { 302 struct AnmPtnSolid : public AnmTime {
297 AnmPtnSolid(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int total_time); 303 AnmPtnSolid(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int total_time);
298 ~AnmPtnSolid() { delete[] alpha; } 304 ~AnmPtnSolid() { delete[] alpha; }
299 const unsigned char* ptn; 305 const unsigned char* ptn;
300 int ptn_len; 306 int ptn_len;
303 309
304 void Start(void); 310 void Start(void);
305 void Exec(int count); 311 void Exec(int count);
306 void Finish(void); 312 void Finish(void);
307 }; 313 };
314
308 struct AnmPtnAlpha : public AnmTime { 315 struct AnmPtnAlpha : public AnmTime {
309 AnmPtnAlpha(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int alpha_bandwidth, int total_time); 316 AnmPtnAlpha(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int alpha_bandwidth, int total_time);
310 ~AnmPtnAlpha() { delete[] alpha; } 317 ~AnmPtnAlpha() { delete[] alpha; }
311 const unsigned char* ptn; 318 const unsigned char* ptn;
312 int ptn_len; 319 int ptn_len;