comparison window/widget.h @ 0:223b71206888

Initial import
author thib
date Fri, 01 Aug 2008 16:32:45 +0000
parents
children 5ae5533b3a9a
comparison
equal deleted inserted replaced
-1:000000000000 0:223b71206888
1 #ifndef __WIDGET_H__
2 #define __WIDGET_H__
3
4 #include<vector>
5 #include"font/font.h"
6 #include"font/text.h"
7 #include"event.h"
8 #include"picture.h"
9
10 #define TimeCursor WidTimeCursor
11 #define MouseCursor WidMouseCursor
12 #define Button WidButton
13 #define Scale WidScale
14 #define Label WidLabel
15 #define Dialog WidDialog
16 #define TextButton WidTextButton
17 #define Text WidText
18 #define AnmTime WidAnmTime
19 #define AnmMove WidAnmMove
20 #define AnmAlpha WidAnmAlpha
21 #define AnmPtnSolid WidAnmPtnSolid
22 #define AnmPtnAlpha WidAnmPtnAlpha
23
24 // namespace Widget {
25
26 struct TimeCursor : public Event::Time, PicWidget {
27 int x,y,dx,dy, nptn;
28 int old_time, count, interval;
29 TimeCursor(Event::Container& container, int _interval, PicContainer* parent, const char* fname, int sx, int sy, int sdx, int sdy, int nptn, const Rect& r);
30 void Elapsed(unsigned int current_time);
31 };
32
33 struct MouseCursor : public Event::Video, PicWidget {
34 int x, y;
35 Event::Container& container;
36 MouseCursor(Event::Container& container, PicContainer* parent, const char* s, int x, int y, int w, int h);
37 MouseCursor(Event::Container& container, PicContainer* parent, Surface* s, int x, int y, int w, int h);
38 ~MouseCursor();
39 static bool Motionfunc(int x, int y, void* pointer);
40 };
41
42 struct Button : public Event::Video, PicWidget {
43 int sx, sy, sdx, sdy, nptn;
44 bool is_in;
45 bool is_toggled;
46 bool is_toggle_switch;
47 Button(Event::Container& container, PicContainer* parent, const char* s, int sx, int sy, int sdx, int sdy, int nptn, const Rect& r, int _z);
48 Button(Event::Container& container, PicContainer* parent, Surface* s, int sx, int sy, int sdx, int sdy, int nptn, const Rect& r, int _z);
49 ~Button();
50 void Press(void);
51 void Release(void);
52 void Drag(int x_from, int y_from, int x_to, int y_to);
53 void In(void);
54 void Out(void);
55 void Toggle(bool new_toggle);
56 typedef void (*PressFunc)(void* pointer, Button* from);
57 typedef void (*DragFunc)(int x_from, int y_from, int x_to, int y_to, void* pointer, Button* from);
58 PressFunc press_func;
59 void* press_pointer;
60 DragFunc drag_func;
61 void* drag_pointer;
62
63 /* ·Ñ¾µ */
64 void activate(void) { Event::Video::activate();}
65 void deactivate(void) { Event::Video::deactivate();}
66 void SetRegion(const Rect& new_rect) { Event::Video::SetRegion(new_rect);}
67 };
68 struct Scale : Event::Video, PicWidget {
69 private:
70 Button* arrow_down, *arrow_up;
71 Button* cursor;
72 PicContainer* panel;
73 Event::Container& container;
74 PicContainer* parent;
75 Color cursor_color;
76
77 int mouse_x, mouse_y;
78 enum {scale_max = 65536};
79 int min, max;
80 int value;
81 int value_add;
82 int value_dragstart;
83 int cursor_width;
84 bool is_vertical;
85
86 public:
87
88 Scale(Event::Container& container, PicContainer* parent, const Rect& r_orig, const Color& cursor_color, bool _is_vertical);
89 void InitCursor(int cursor_width_ratio); // 1024=max
90 void SetRange(int min, int max);
91 void SetValue(int value);
92 int GetValue(void) const;
93 typedef void (*ChangeFunc)(void* pointer, Scale* from);
94 ChangeFunc change_func;
95 void* change_pointer;
96 private:
97 void Init(Rect r_orig);
98 int CalcValue(void);
99 void SetScaleValue(int value);
100
101 // callback
102 static void PressArrowDown(void* pointer, Button* from);
103 static void PressArrowUp(void* pointer, Button* from);
104 static void PressCursor(void* pointer, Button* from);
105 static void DragCursor(int x_from, int y_from,int x, int y, void* pointer, Button* from);
106
107 // ·Ñ¾µ¡§Event::Video
108 void Press(void);
109 void Motion(int x, int y);
110
111 /* ·Ñ¾µ : PicWidget */
112 void activate(void) { Event::Video::activate();}
113 void deactivate(void) { Event::Video::deactivate();}
114 void SetRegion(const Rect& new_rect) { Event::Video::SetRegion(new_rect);}
115 };
116
117 struct TextButton : public Button {
118 enum Attribute {CENTER=1, REVERSE=2, NOPADDING=4};
119 PicRoot& root;
120 Surface* surface;
121 Attribute attribute;
122 int text_size;
123 Color fore, pressed, back;
124 TextButton(Event::Container& container, PicContainer* parent, const char* s, int text_size, Attribute attr, const Rect& r, int _z, const Color& fore, const Color& pressed, const Color& back);
125 void SetText(const char* s, const Color& fore, const Color& pressed, const Color& back);
126 void SetText(const char* s) {
127 SetText(s, fore, pressed, back);
128 }
129 ~TextButton();
130 };
131
132 struct Text : public Event::Video, Event::Time, PicWidget {
133 typedef TextGlyphStream::iterator iterator;
134
135 private:
136 Event::Container& event;
137 public:
138 PicBase* pictext;
139 private:
140 TimeCursor* cursor;
141 Surface* surface;
142 TextGlyphStream gstream;
143 std::vector<int> bottom_pos; // ¹Ô¹â¤µ(height)¤ÎÎß·×ÃÍ
144 XKFont::HorizLayout layout;
145 int fontsize;
146
147 iterator cur_pos;
148 int line_number;
149 Rect srcrect;
150 int press_count;
151 int scrolled_count;
152 int scroll_height;
153 bool window_activated;
154 bool cursor_activated;
155
156 int speed; // chars / sec or -1
157 int wait_delay; // msec
158 int old_time;
159 int wait_starttime;
160
161 int CalcScrollHeight(void);
162 void DrawText(int& nChar);
163 void Scrollup(int& nChar);
164 public:
165 Text(Event::Container& container, PicContainer* parent, const Rect& r, const Rect& text_r, int fontsize);
166 ~Text();
167
168 TextStream stream;
169 enum {PREPARE, DRAW, WAIT, SCROLL, DRAW2, WAIT2} status;
170
171 void Clear(void);
172 void Start(void);
173 void Flush(void);
174
175 void Elapsed(unsigned int current_time);
176 static bool Pressed(int x, int y, void* pointer);
177 void activate(void);
178 void deactivate(void);
179 void SetSpeed(int new_speed);
180 void SetWait(int new_wait);
181
182 void SetCursor(TimeCursor* cursor);
183 };
184
185 extern void SetFont(const char* fontname);
186
187 struct Label : PicWidget{
188 private:
189 Surface* surface;
190 bool is_center;
191 PicRoot& root;
192 int text_size;
193 public:
194 Label(PicContainer* parent, const Rect& r_orig, bool is_center=true, const char* text=0, int textsize = 26);
195 ~Label();
196 void SetText(const char* text);
197 };
198
199 class Dialog : public Event::Video, PicWidget {
200 Surface* surface_btn;
201 Surface* surface_diag;
202 public:
203 enum { WAIT, OK, CANCEL} status;
204 Dialog(Event::Container& container, PicContainer* parent, const char* text, bool with_cancel);
205 ~Dialog();
206 static void press_ok(void* pointer, Button* btn);
207 static void press_cancel(void* pointer, Button* btn);
208 static void DrawBox(Surface* s, const Rect& r);
209 typedef void (*SetFunc)(void* pointer, Dialog* from);
210 SetFunc set_func;
211 void* set_pointer;
212 };
213
214 struct AnmTime : public Event::Time, PicAnm {
215 enum { PLAYING=1, FINISHED=3 } status;
216 unsigned int start_time;
217 unsigned int total_time;
218 int all_count;
219
220 AnmTime(Event::Container& container, PicBase* _pic, int total_time, int all_count = 0);
221 AnmTime(Event::Container& container, std::vector<PicBase*> _pic, int total_time, int all_count = 0);
222 virtual ~AnmTime() {}
223 void SetAllCount(int new_all_count) { all_count = new_all_count; }
224 void SetTotalTime(int new_total) { total_time = new_total; }
225 void Elapsed(unsigned int current_time);
226 void Play(void) {
227 start_time = 0;
228 status = PLAYING;
229 }
230
231 virtual void Start(void) {};
232 virtual void Exec(int count) = 0;
233 virtual void Finish(void) {};
234 void Abort(void);
235 bool IsEnd(void);
236 };
237
238 struct AnmMove : public AnmTime {
239 Rect from, to;
240 AnmMove(Event::Container& container, PicBase* _pic, const Rect& to, int total_time);
241 void Exec(int count);
242 };
243 #define ALPHA_MAX 255
244 struct AnmAlpha : public AnmTime {
245 int from, to;
246 unsigned char alpha; Rect alpha_r;
247 AnmAlpha(Event::Container& container, PicBase* _pic, int alpha_from, int alpha_to, int total_time);
248 AnmAlpha(Event::Container& container, std::vector<PicBase*> _pic, int alpha_from, int alpha_to, int total_time);
249 void Start(void);
250 void Exec(int count);
251 void Finish(void);
252 };
253 struct AnmAlphaMove : public AnmTime {
254 struct Ptn {
255 Rect pos;
256 Rect surface_pos;
257 unsigned char alpha;
258 unsigned int next_tick;
259 Ptn(const Rect& _r, const Rect& _surface_r, unsigned char _a, unsigned int _n) :
260 pos(_r), surface_pos(_surface_r), alpha(_a), next_tick(_n) {}
261 };
262 std::vector<Ptn> ptns;
263 int cur_count;
264 AnmAlphaMove(Event::Container& container, PicBase* _pic);
265 void SetPtn(void);
266 void Exec(int count);
267 void Finish(void);
268 };
269 struct AnmPtnSolid : public AnmTime {
270 AnmPtnSolid(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int total_time);
271 ~AnmPtnSolid() { delete[] alpha; }
272 const unsigned char* ptn;
273 int ptn_len;
274 unsigned char* alpha;
275 Rect alpha_r;
276
277 void Start(void);
278 void Exec(int count);
279 void Finish(void);
280 };
281 struct AnmPtnAlpha : public AnmTime {
282 AnmPtnAlpha(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int alpha_bandwidth, int total_time);
283 ~AnmPtnAlpha() { delete[] alpha; }
284 const unsigned char* ptn;
285 int ptn_len;
286 int band;
287 unsigned char* alpha;
288 Rect alpha_r;
289 void Start(void);
290 void Exec(int count);
291 void Finish(void);
292 };
293
294 // } /* end of namespace Widget */
295
296 #undef Text
297
298 #endif
299