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