Mercurial > otakunoraifu
annotate window/widget.h @ 67:419761c8d9b9
Add configure option to build scn2kdump.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 23 Feb 2011 01:48:51 +0100 |
parents | 4416cfac86ae |
children |
rev | line source |
---|---|
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 | |
52 | 31 #include <vector> |
32 #include "font/font.h" | |
33 #include "font/text.h" | |
34 #include "event.h" | |
35 #include "picture.h" | |
0 | 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 { | |
52 | 54 int x, y, dx, dy, nptn; |
0 | 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 | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
90 /* 継承 */ |
0 | 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 { | |
52 | 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; | |
0 | 103 |
52 | 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; | |
0 | 112 |
52 | 113 public: |
114 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 SetRange(int min, int max); | |
117 void SetValue(int value); | |
118 int GetValue(void) const; | |
119 typedef void (*ChangeFunc)(void* pointer, Scale* from); | |
120 ChangeFunc change_func; | |
121 void* change_pointer; | |
122 | |
123 private: | |
124 void Init(Rect r_orig); | |
125 int CalcValue(void); | |
126 void SetScaleValue(int value); | |
0 | 127 |
52 | 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); | |
0 | 133 |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
134 // 継承:Event::Video |
52 | 135 void Press(void); |
136 void Motion(int x, int y); | |
0 | 137 |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
138 /* 継承 : PicWidget */ |
52 | 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);} | |
0 | 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 | |
52 | 162 private: |
163 Event::Container& event; | |
164 public: | |
165 PicBase* pictext; | |
166 private: | |
167 TimeCursor* cursor; | |
168 Surface* surface; | |
169 TextGlyphStream gstream; | |
65
4416cfac86ae
Convert EUC-JP files to UTF8
Thibaut Girka <thib@sitedethib.com>
parents:
52
diff
changeset
|
170 std::vector<int> bottom_pos; // 行高さ(height)の累計値 |
52 | 171 XKFont::HorizLayout layout; |
172 int fontsize; | |
0 | 173 |
52 | 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; | |
0 | 182 |
52 | 183 int speed; // chars / sec or -1 |
184 int wait_delay; // msec | |
185 int old_time; | |
186 int wait_starttime; | |
0 | 187 |
52 | 188 int CalcScrollHeight(void); |
189 void DrawText(int& nChar); | |
190 void Scrollup(int& nChar); | |
191 | |
192 public: | |
193 Text(Event::Container& container, PicContainer* parent, const Rect& r, const Rect& text_r, int fontsize); | |
194 ~Text(); | |
0 | 195 |
52 | 196 TextStream stream; |
197 enum {PREPARE, DRAW, WAIT, SCROLL, DRAW2, WAIT2} status; | |
0 | 198 |
52 | 199 void Clear(void); |
200 void Start(void); | |
201 void Flush(void); | |
0 | 202 |
52 | 203 void Elapsed(unsigned int current_time); |
204 static bool Pressed(int x, int y, void* pointer); | |
205 void activate(void); | |
206 void deactivate(void); | |
207 void SetSpeed(int new_speed); | |
208 void SetWait(int new_wait); | |
0 | 209 |
52 | 210 void SetCursor(TimeCursor* cursor); |
0 | 211 }; |
212 | |
213 extern void SetFont(const char* fontname); | |
214 | |
215 struct Label : PicWidget{ | |
52 | 216 private: |
217 Surface* surface; | |
218 bool is_center; | |
219 PicRoot& root; | |
220 int text_size; | |
221 public: | |
222 Label(PicContainer* parent, const Rect& r_orig, bool is_center=true, const char* text=0, int textsize = 26); | |
223 ~Label(); | |
224 void SetText(const char* text); | |
0 | 225 }; |
226 | |
227 class Dialog : public Event::Video, PicWidget { | |
52 | 228 private: |
229 Surface* surface_btn; | |
230 Surface* surface_diag; | |
231 | |
232 public: | |
233 enum { WAIT, OK, CANCEL} status; | |
234 Dialog(Event::Container& container, PicContainer* parent, const char* text, bool with_cancel); | |
235 ~Dialog(); | |
236 static void press_ok(void* pointer, Button* btn); | |
237 static void press_cancel(void* pointer, Button* btn); | |
238 static void DrawBox(Surface* s, const Rect& r); | |
239 typedef void (*SetFunc)(void* pointer, Dialog* from); | |
240 SetFunc set_func; | |
241 void* set_pointer; | |
0 | 242 }; |
243 | |
244 struct AnmTime : public Event::Time, PicAnm { | |
245 enum { PLAYING=1, FINISHED=3 } status; | |
246 unsigned int start_time; | |
247 unsigned int total_time; | |
248 int all_count; | |
249 | |
250 AnmTime(Event::Container& container, PicBase* _pic, int total_time, int all_count = 0); | |
251 AnmTime(Event::Container& container, std::vector<PicBase*> _pic, int total_time, int all_count = 0); | |
252 virtual ~AnmTime() {} | |
253 void SetAllCount(int new_all_count) { all_count = new_all_count; } | |
254 void SetTotalTime(int new_total) { total_time = new_total; } | |
255 void Elapsed(unsigned int current_time); | |
256 void Play(void) { | |
257 start_time = 0; | |
258 status = PLAYING; | |
259 } | |
260 | |
261 virtual void Start(void) {}; | |
262 virtual void Exec(int count) = 0; | |
263 virtual void Finish(void) {}; | |
264 void Abort(void); | |
265 bool IsEnd(void); | |
266 }; | |
267 | |
268 struct AnmMove : public AnmTime { | |
269 Rect from, to; | |
270 AnmMove(Event::Container& container, PicBase* _pic, const Rect& to, int total_time); | |
271 void Exec(int count); | |
272 }; | |
52 | 273 |
0 | 274 #define ALPHA_MAX 255 |
275 struct AnmAlpha : public AnmTime { | |
276 int from, to; | |
277 unsigned char alpha; Rect alpha_r; | |
278 AnmAlpha(Event::Container& container, 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); | |
280 void Start(void); | |
281 void Exec(int count); | |
282 void Finish(void); | |
283 }; | |
52 | 284 |
0 | 285 struct AnmAlphaMove : public AnmTime { |
286 struct Ptn { | |
287 Rect pos; | |
288 Rect surface_pos; | |
289 unsigned char alpha; | |
290 unsigned int next_tick; | |
291 Ptn(const Rect& _r, const Rect& _surface_r, unsigned char _a, unsigned int _n) : | |
292 pos(_r), surface_pos(_surface_r), alpha(_a), next_tick(_n) {} | |
293 }; | |
294 std::vector<Ptn> ptns; | |
295 int cur_count; | |
296 AnmAlphaMove(Event::Container& container, PicBase* _pic); | |
297 void SetPtn(void); | |
298 void Exec(int count); | |
299 void Finish(void); | |
300 }; | |
52 | 301 |
0 | 302 struct AnmPtnSolid : public AnmTime { |
303 AnmPtnSolid(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int total_time); | |
304 ~AnmPtnSolid() { delete[] alpha; } | |
305 const unsigned char* ptn; | |
306 int ptn_len; | |
307 unsigned char* alpha; | |
308 Rect alpha_r; | |
309 | |
310 void Start(void); | |
311 void Exec(int count); | |
312 void Finish(void); | |
313 }; | |
52 | 314 |
0 | 315 struct AnmPtnAlpha : public AnmTime { |
316 AnmPtnAlpha(Event::Container& container, PicBase* _pic, const unsigned char* ptn, const Rect& alpha_r, int alpha_bandwidth, int total_time); | |
317 ~AnmPtnAlpha() { delete[] alpha; } | |
318 const unsigned char* ptn; | |
319 int ptn_len; | |
320 int band; | |
321 unsigned char* alpha; | |
322 Rect alpha_r; | |
323 void Start(void); | |
324 void Exec(int count); | |
325 void Finish(void); | |
326 }; | |
327 | |
328 // } /* end of namespace Widget */ | |
329 | |
330 #undef Text | |
331 | |
332 #endif | |
333 |