annotate window/widget.cc @ 51:cbb301016a4e

* oops... finishing what was started and not said with the other patch: fixing memory leaks
author thib
date Fri, 17 Apr 2009 18:40:39 +0000
parents 5f548e5957a8
children 15a18fbe6f21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 /*
223b71206888 Initial import
thib
parents:
diff changeset
2 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
223b71206888 Initial import
thib
parents:
diff changeset
3 * All rights reserved.
223b71206888 Initial import
thib
parents:
diff changeset
4 *
223b71206888 Initial import
thib
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
223b71206888 Initial import
thib
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
223b71206888 Initial import
thib
parents:
diff changeset
7 * are met:
223b71206888 Initial import
thib
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
223b71206888 Initial import
thib
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
223b71206888 Initial import
thib
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
223b71206888 Initial import
thib
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
223b71206888 Initial import
thib
parents:
diff changeset
13 * 3. The name of the author may not be used to endorse or promote products
223b71206888 Initial import
thib
parents:
diff changeset
14 * derived from this software without specific prior written permission.
223b71206888 Initial import
thib
parents:
diff changeset
15 *
223b71206888 Initial import
thib
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
223b71206888 Initial import
thib
parents:
diff changeset
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223b71206888 Initial import
thib
parents:
diff changeset
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223b71206888 Initial import
thib
parents:
diff changeset
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
223b71206888 Initial import
thib
parents:
diff changeset
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
223b71206888 Initial import
thib
parents:
diff changeset
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
223b71206888 Initial import
thib
parents:
diff changeset
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
223b71206888 Initial import
thib
parents:
diff changeset
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
223b71206888 Initial import
thib
parents:
diff changeset
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
223b71206888 Initial import
thib
parents:
diff changeset
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
223b71206888 Initial import
thib
parents:
diff changeset
26 */
223b71206888 Initial import
thib
parents:
diff changeset
27
223b71206888 Initial import
thib
parents:
diff changeset
28 #include"widget.h"
223b71206888 Initial import
thib
parents:
diff changeset
29 #include<algorithm>
223b71206888 Initial import
thib
parents:
diff changeset
30 #include<map>
223b71206888 Initial import
thib
parents:
diff changeset
31 #include<string>
223b71206888 Initial import
thib
parents:
diff changeset
32
223b71206888 Initial import
thib
parents:
diff changeset
33 Rect DSurfaceRenderText(TextGlyphStream::iterator start, TextGlyphStream::iterator end, const Rect& srcrect,
223b71206888 Initial import
thib
parents:
diff changeset
34 Surface* dst, const Rect& dstrect);
223b71206888 Initial import
thib
parents:
diff changeset
35 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a = 0xff);
223b71206888 Initial import
thib
parents:
diff changeset
36 void DSurfaceMove(Surface* src, const Rect& srcrect, Surface* dst_o, const Rect& dstrect);
223b71206888 Initial import
thib
parents:
diff changeset
37
223b71206888 Initial import
thib
parents:
diff changeset
38 //static char* wdefault_font_orig = "msgothic.ttc;times.ttf;";
223b71206888 Initial import
thib
parents:
diff changeset
39 static std::map<int, XKFont::HorizLayout*> size_to_layout;
47
5f548e5957a8 * get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents: 14
diff changeset
40 static const char* wdefault_font_orig = "times.ttf;msgothic.ttc";
0
223b71206888 Initial import
thib
parents:
diff changeset
41 static std::string wdefault_font = wdefault_font_orig;
223b71206888 Initial import
thib
parents:
diff changeset
42
223b71206888 Initial import
thib
parents:
diff changeset
43 void SetFont(const char* font) {
223b71206888 Initial import
thib
parents:
diff changeset
44 if (font == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
45 std::map<int,XKFont::HorizLayout*>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
46 for (it=size_to_layout.begin(); it != size_to_layout.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
47 delete it->second;
223b71206888 Initial import
thib
parents:
diff changeset
48 }
223b71206888 Initial import
thib
parents:
diff changeset
49 size_to_layout.clear();
223b71206888 Initial import
thib
parents:
diff changeset
50 wdefault_font = font;
223b71206888 Initial import
thib
parents:
diff changeset
51 }
223b71206888 Initial import
thib
parents:
diff changeset
52 // namespace Widget {
223b71206888 Initial import
thib
parents:
diff changeset
53 #define TimeCursor WidTimeCursor
223b71206888 Initial import
thib
parents:
diff changeset
54 #define MouseCursor WidMouseCursor
223b71206888 Initial import
thib
parents:
diff changeset
55 #define Button WidButton
223b71206888 Initial import
thib
parents:
diff changeset
56 #define Scale WidScale
223b71206888 Initial import
thib
parents:
diff changeset
57 #define TextButton WidTextButton
223b71206888 Initial import
thib
parents:
diff changeset
58 #define Text WidText
223b71206888 Initial import
thib
parents:
diff changeset
59 #define AnmTime WidAnmTime
223b71206888 Initial import
thib
parents:
diff changeset
60 #define AnmMove WidAnmMove
223b71206888 Initial import
thib
parents:
diff changeset
61 #define AnmAlpha WidAnmAlpha
223b71206888 Initial import
thib
parents:
diff changeset
62 #define AnmPtnSolid WidAnmPtnSolid
223b71206888 Initial import
thib
parents:
diff changeset
63 #define AnmPtnAlpha WidAnmPtnAlpha
223b71206888 Initial import
thib
parents:
diff changeset
64
223b71206888 Initial import
thib
parents:
diff changeset
65 XKFont::HorizLayout* DefaultLayout(int text_size) {
14
8da1d92ac8f8 Don't create fonts faces for size <= 0, and update objects when their font size is set
thib
parents: 0
diff changeset
66 if(text_size <= 0) abort();//FIXME: Find why the hell text_size can be <= 0
0
223b71206888 Initial import
thib
parents:
diff changeset
67 if (size_to_layout.find(text_size) == size_to_layout.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
68 size_to_layout[text_size] = new XKFont::HorizLayout(wdefault_font.c_str(), text_size);
223b71206888 Initial import
thib
parents:
diff changeset
69 }
223b71206888 Initial import
thib
parents:
diff changeset
70 return size_to_layout[text_size];
223b71206888 Initial import
thib
parents:
diff changeset
71 }
223b71206888 Initial import
thib
parents:
diff changeset
72
223b71206888 Initial import
thib
parents:
diff changeset
73 void PicWidget::activate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
74 }
223b71206888 Initial import
thib
parents:
diff changeset
75 void PicWidget::deactivate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
76 }
223b71206888 Initial import
thib
parents:
diff changeset
77 void PicWidget::SetRegion(const Rect& apos) {
223b71206888 Initial import
thib
parents:
diff changeset
78 }
223b71206888 Initial import
thib
parents:
diff changeset
79 void PicWidget::show(void) {
223b71206888 Initial import
thib
parents:
diff changeset
80 Pic()->show();
223b71206888 Initial import
thib
parents:
diff changeset
81 }
223b71206888 Initial import
thib
parents:
diff changeset
82 void PicWidget::hide(void) {
223b71206888 Initial import
thib
parents:
diff changeset
83 Pic()->hide();
223b71206888 Initial import
thib
parents:
diff changeset
84 }
223b71206888 Initial import
thib
parents:
diff changeset
85 void PicWidget::show_all(void) {
223b71206888 Initial import
thib
parents:
diff changeset
86 Pic()->show_all();
223b71206888 Initial import
thib
parents:
diff changeset
87 }
223b71206888 Initial import
thib
parents:
diff changeset
88
223b71206888 Initial import
thib
parents:
diff changeset
89 TimeCursor::TimeCursor(Event::Container& container, int _interval, PicContainer* parent, const char* s, int _sx, int _sy, int _sdx, int _sdy, int _nptn, const Rect& r) :
223b71206888 Initial import
thib
parents:
diff changeset
90 Time(container) {
223b71206888 Initial import
thib
parents:
diff changeset
91 interval = _interval;
223b71206888 Initial import
thib
parents:
diff changeset
92 if (interval < 0) interval = 100;
223b71206888 Initial import
thib
parents:
diff changeset
93 nptn = _nptn;
223b71206888 Initial import
thib
parents:
diff changeset
94 if (nptn < 0) nptn = 1;
223b71206888 Initial import
thib
parents:
diff changeset
95 count = 0; old_time = 0;
223b71206888 Initial import
thib
parents:
diff changeset
96
223b71206888 Initial import
thib
parents:
diff changeset
97 x = _sx; y = _sy; dx = _sdx; dy = _sdy;
223b71206888 Initial import
thib
parents:
diff changeset
98 SetPic(parent->create_leaf(r, PicBase::CACHE_BACK));
223b71206888 Initial import
thib
parents:
diff changeset
99 Pic()->SetSurface(s, _sx, _sy);
223b71206888 Initial import
thib
parents:
diff changeset
100 };
223b71206888 Initial import
thib
parents:
diff changeset
101 void TimeCursor::Elapsed(unsigned int current_time) {
223b71206888 Initial import
thib
parents:
diff changeset
102 int move = (current_time-old_time)/interval;
223b71206888 Initial import
thib
parents:
diff changeset
103 if (move) {
223b71206888 Initial import
thib
parents:
diff changeset
104 old_time += move*interval;
223b71206888 Initial import
thib
parents:
diff changeset
105 count += move;
223b71206888 Initial import
thib
parents:
diff changeset
106 count %= nptn;
223b71206888 Initial import
thib
parents:
diff changeset
107 Pic()->SetSurfacePos(x + count*dx, y + count*dy);
223b71206888 Initial import
thib
parents:
diff changeset
108 }
223b71206888 Initial import
thib
parents:
diff changeset
109 if (current_time > old_time+interval) SetWakeup(current_time);
223b71206888 Initial import
thib
parents:
diff changeset
110 else SetWakeup(old_time+interval);
223b71206888 Initial import
thib
parents:
diff changeset
111 }
223b71206888 Initial import
thib
parents:
diff changeset
112
223b71206888 Initial import
thib
parents:
diff changeset
113 MouseCursor::MouseCursor(Event::Container& _container, PicContainer* parent, const char* s, int x, int y, int w, int h) :
223b71206888 Initial import
thib
parents:
diff changeset
114 Event::Video(_container), container(_container) {
223b71206888 Initial import
thib
parents:
diff changeset
115 int sx, sy;
223b71206888 Initial import
thib
parents:
diff changeset
116 _container.MousePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
117 SetPic(parent->create_leaf(Rect(sx, sy, sx+w, sy+h), 0));
223b71206888 Initial import
thib
parents:
diff changeset
118 Pic()->SetSurface(s, x, y);
223b71206888 Initial import
thib
parents:
diff changeset
119 x = 0; y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
120 container.RegisterGlobalMotionFunc(&Motionfunc, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
121 }
223b71206888 Initial import
thib
parents:
diff changeset
122 MouseCursor::MouseCursor(Event::Container& _container, PicContainer* parent, Surface* s, int x, int y, int w, int h) :
223b71206888 Initial import
thib
parents:
diff changeset
123 Event::Video(_container), container(_container) {
223b71206888 Initial import
thib
parents:
diff changeset
124 int sx, sy;
223b71206888 Initial import
thib
parents:
diff changeset
125 _container.MousePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
126 SetPic(parent->create_leaf(Rect(sx, sy, sx+w, sy+h), 0));
223b71206888 Initial import
thib
parents:
diff changeset
127 Pic()->SetSurface(s, x, y);
223b71206888 Initial import
thib
parents:
diff changeset
128 x = 0; y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
129 container.RegisterGlobalMotionFunc(&Motionfunc, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
130 }
223b71206888 Initial import
thib
parents:
diff changeset
131
223b71206888 Initial import
thib
parents:
diff changeset
132 MouseCursor::~MouseCursor() {
223b71206888 Initial import
thib
parents:
diff changeset
133 container.DeleteGlobalMotionFunc(&Motionfunc, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
134 }
223b71206888 Initial import
thib
parents:
diff changeset
135
223b71206888 Initial import
thib
parents:
diff changeset
136 bool MouseCursor::Motionfunc(int x, int y, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
137 MouseCursor* _this = (MouseCursor*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
138 // º¸¾å¤¬¥«¡¼¥½¥ë¥Ý¥¤¥ó¥È¤Î¾ì¹ç
223b71206888 Initial import
thib
parents:
diff changeset
139 // _this->Pic()->Move(x,y);
223b71206888 Initial import
thib
parents:
diff changeset
140 // º¸²¼¤¬¥«¡¼¥½¥ë¥Ý¥¤¥ó¥È¤Î¾ì¹ç
223b71206888 Initial import
thib
parents:
diff changeset
141 _this->Pic()->Move(x,y-_this->Pic()->Height());
223b71206888 Initial import
thib
parents:
diff changeset
142 return true;
223b71206888 Initial import
thib
parents:
diff changeset
143 }
223b71206888 Initial import
thib
parents:
diff changeset
144
223b71206888 Initial import
thib
parents:
diff changeset
145 Button::Button(Event::Container& container, PicContainer* parent, const char* s, int _sx, int _sy, int _sdx, int _sdy, int _nptn, const Rect& r, int _z) : sx(_sx), sy(_sy), sdx(_sdx), sdy(_sdy), nptn(_nptn) ,Event::Video(container,r, _z) {
223b71206888 Initial import
thib
parents:
diff changeset
146 SetPic(parent->create_leaf(r, 0));
223b71206888 Initial import
thib
parents:
diff changeset
147 Pic()->SetSurface(s, _sx, _sy);
223b71206888 Initial import
thib
parents:
diff changeset
148 show();
223b71206888 Initial import
thib
parents:
diff changeset
149 is_in = false;
223b71206888 Initial import
thib
parents:
diff changeset
150 is_toggled = false;
223b71206888 Initial import
thib
parents:
diff changeset
151 press_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
152 press_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
153 drag_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
154 drag_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
155 is_toggle_switch = false;
223b71206888 Initial import
thib
parents:
diff changeset
156 }
223b71206888 Initial import
thib
parents:
diff changeset
157 Button::Button(Event::Container& container, PicContainer* parent, Surface* s, int _sx, int _sy, int _sdx, int _sdy, int _nptn, const Rect& r, int _z) : sx(_sx), sy(_sy), sdx(_sdx), sdy(_sdy), nptn(_nptn) ,Event::Video(container,r, _z) {
223b71206888 Initial import
thib
parents:
diff changeset
158 SetPic(parent->create_leaf(r, 0));
223b71206888 Initial import
thib
parents:
diff changeset
159 Pic()->SetSurface(s, _sx, _sy);
223b71206888 Initial import
thib
parents:
diff changeset
160 show();
223b71206888 Initial import
thib
parents:
diff changeset
161 is_in = false;
223b71206888 Initial import
thib
parents:
diff changeset
162 is_toggled = false;
223b71206888 Initial import
thib
parents:
diff changeset
163 press_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
164 press_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
165 drag_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
166 drag_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
167 is_toggle_switch = false;
223b71206888 Initial import
thib
parents:
diff changeset
168 }
223b71206888 Initial import
thib
parents:
diff changeset
169 Button::~Button() {
223b71206888 Initial import
thib
parents:
diff changeset
170 }
223b71206888 Initial import
thib
parents:
diff changeset
171 void Button::In(void) {
223b71206888 Initial import
thib
parents:
diff changeset
172 is_in = true;
223b71206888 Initial import
thib
parents:
diff changeset
173 if (nptn > 1)
223b71206888 Initial import
thib
parents:
diff changeset
174 if (! is_toggled)
223b71206888 Initial import
thib
parents:
diff changeset
175 Pic()->SetSurfacePos(sx+sdx, sy+sdy);
223b71206888 Initial import
thib
parents:
diff changeset
176 }
223b71206888 Initial import
thib
parents:
diff changeset
177 void Button::Out(void) {
223b71206888 Initial import
thib
parents:
diff changeset
178 is_in = false;
223b71206888 Initial import
thib
parents:
diff changeset
179 if (!is_toggled)
223b71206888 Initial import
thib
parents:
diff changeset
180 Pic()->SetSurfacePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
181 }
223b71206888 Initial import
thib
parents:
diff changeset
182 void Button::Toggle(bool new_toggle) {
223b71206888 Initial import
thib
parents:
diff changeset
183 if (is_toggled == new_toggle) {
223b71206888 Initial import
thib
parents:
diff changeset
184 return;
223b71206888 Initial import
thib
parents:
diff changeset
185 }
223b71206888 Initial import
thib
parents:
diff changeset
186 is_toggled = new_toggle;
223b71206888 Initial import
thib
parents:
diff changeset
187 // if (is_in) return; // is_in ¤Ë´Ø¤ï¤é¤º¥¦¥£¥¸¥Ã¥È¤Îɽ¼¨¤òÊѹ¹¤¹¤ë¤³¤È¤Ë¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
188 if (is_toggled) {
223b71206888 Initial import
thib
parents:
diff changeset
189 if (nptn > 2)
223b71206888 Initial import
thib
parents:
diff changeset
190 Pic()->SetSurfacePos(sx+sdx*2, sy+sdy*2);
223b71206888 Initial import
thib
parents:
diff changeset
191 else if (nptn > 1)
223b71206888 Initial import
thib
parents:
diff changeset
192 Pic()->SetSurfacePos(sx+sdx, sy+sdy);
223b71206888 Initial import
thib
parents:
diff changeset
193 else
223b71206888 Initial import
thib
parents:
diff changeset
194 Pic()->SetSurfacePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
195 } else {
223b71206888 Initial import
thib
parents:
diff changeset
196 Pic()->SetSurfacePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
197 }
223b71206888 Initial import
thib
parents:
diff changeset
198 }
223b71206888 Initial import
thib
parents:
diff changeset
199 void Button::Press(void) {
223b71206888 Initial import
thib
parents:
diff changeset
200 is_in = true;
223b71206888 Initial import
thib
parents:
diff changeset
201 if (is_toggled) ;
223b71206888 Initial import
thib
parents:
diff changeset
202 else if (nptn > 2)
223b71206888 Initial import
thib
parents:
diff changeset
203 Pic()->SetSurfacePos(sx+sdx*2, sy+sdy*2);
223b71206888 Initial import
thib
parents:
diff changeset
204 else if (nptn > 1)
223b71206888 Initial import
thib
parents:
diff changeset
205 Pic()->SetSurfacePos(sx+sdx, sy+sdy);
223b71206888 Initial import
thib
parents:
diff changeset
206 if (press_func) press_func(press_pointer, this);
223b71206888 Initial import
thib
parents:
diff changeset
207 if (is_toggle_switch) Toggle(!is_toggled);
223b71206888 Initial import
thib
parents:
diff changeset
208 }
223b71206888 Initial import
thib
parents:
diff changeset
209 void Button::Release(void) {
223b71206888 Initial import
thib
parents:
diff changeset
210 if (is_toggled) ;
223b71206888 Initial import
thib
parents:
diff changeset
211 else if (nptn > 1 && is_in)
223b71206888 Initial import
thib
parents:
diff changeset
212 Pic()->SetSurfacePos(sx+sdx, sy+sdy);
223b71206888 Initial import
thib
parents:
diff changeset
213 else if (nptn > 1)
223b71206888 Initial import
thib
parents:
diff changeset
214 Pic()->SetSurfacePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
215 }
223b71206888 Initial import
thib
parents:
diff changeset
216 void Button::Drag(int x_from, int y_from, int x_to, int y_to) {
223b71206888 Initial import
thib
parents:
diff changeset
217 if (drag_func) drag_func(x_from,y_from,x_to, y_to,drag_pointer, this);
223b71206888 Initial import
thib
parents:
diff changeset
218 }
223b71206888 Initial import
thib
parents:
diff changeset
219
223b71206888 Initial import
thib
parents:
diff changeset
220 Scale::Scale(Event::Container& _container, PicContainer* _parent, const Rect& r_orig, const Color& _color, bool _is_vertical) :
223b71206888 Initial import
thib
parents:
diff changeset
221 Event::Video(_container,Rect(0,0), 1),
223b71206888 Initial import
thib
parents:
diff changeset
222 container(_container), parent(_parent), cursor_color(_color),
223b71206888 Initial import
thib
parents:
diff changeset
223 mouse_x(0), mouse_y(0), max(0), min(0),
223b71206888 Initial import
thib
parents:
diff changeset
224 value(0), value_add(0), value_dragstart(0), is_vertical(_is_vertical),
223b71206888 Initial import
thib
parents:
diff changeset
225 change_func(0), change_pointer(0) {
223b71206888 Initial import
thib
parents:
diff changeset
226
223b71206888 Initial import
thib
parents:
diff changeset
227 arrow_down = 0;
223b71206888 Initial import
thib
parents:
diff changeset
228 arrow_up = 0;
223b71206888 Initial import
thib
parents:
diff changeset
229 cursor = 0;
223b71206888 Initial import
thib
parents:
diff changeset
230 panel = 0;
223b71206888 Initial import
thib
parents:
diff changeset
231
223b71206888 Initial import
thib
parents:
diff changeset
232 Init(r_orig);
223b71206888 Initial import
thib
parents:
diff changeset
233 }
223b71206888 Initial import
thib
parents:
diff changeset
234
223b71206888 Initial import
thib
parents:
diff changeset
235 extern char* create_button(int number, int& width, int& height, int r, int g, int b);
223b71206888 Initial import
thib
parents:
diff changeset
236 extern char* create_box(int& width, int& height, int r, int g, int b);
223b71206888 Initial import
thib
parents:
diff changeset
237 void Scale::Init(Rect r_orig) {
223b71206888 Initial import
thib
parents:
diff changeset
238 int r=cursor_color.r, g=cursor_color.g, b=cursor_color.b;
223b71206888 Initial import
thib
parents:
diff changeset
239 // Ìð°õ
223b71206888 Initial import
thib
parents:
diff changeset
240 int arrow_width = -1;
223b71206888 Initial import
thib
parents:
diff changeset
241 cursor_width = -1;
223b71206888 Initial import
thib
parents:
diff changeset
242 char* button1;
223b71206888 Initial import
thib
parents:
diff changeset
243 char* button2;
223b71206888 Initial import
thib
parents:
diff changeset
244 if (is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
245 // Ìð°õ¤ËɬÍפÊÎΰè³ÎÊÝ
223b71206888 Initial import
thib
parents:
diff changeset
246 int arrow_height = r_orig.width();
223b71206888 Initial import
thib
parents:
diff changeset
247 button1 = create_button(2, arrow_height, arrow_width, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
248 button2 = create_button(3, arrow_height, arrow_width, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
249 if (r_orig.height() < arrow_width*4) {
223b71206888 Initial import
thib
parents:
diff changeset
250 if (r_orig.height() < 8) r_orig.by = r_orig.ty + 8; // ¾®¤µ¤¹¤®¤ë¾ì¹ç¤Ï¶¯À©Êѹ¹
223b71206888 Initial import
thib
parents:
diff changeset
251 free( (void*)button1);
223b71206888 Initial import
thib
parents:
diff changeset
252 free( (void*)button2);
223b71206888 Initial import
thib
parents:
diff changeset
253 arrow_width = r_orig.height()/4;
223b71206888 Initial import
thib
parents:
diff changeset
254 // ºÆ³ä¤êÅö¤Æ
223b71206888 Initial import
thib
parents:
diff changeset
255 button1 = create_button(2, arrow_height, arrow_width, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
256 button2 = create_button(3, arrow_height, arrow_width, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
257 }
223b71206888 Initial import
thib
parents:
diff changeset
258 // Ìð°õ¥Ü¥¿¥ó¤ÎºîÀ®
223b71206888 Initial import
thib
parents:
diff changeset
259 Surface* a1s = parent->Root().NewSurfaceFromRGBAData(arrow_height, arrow_width*3, button1, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
260 int x = r_orig.lx; int y = r_orig.ty;
223b71206888 Initial import
thib
parents:
diff changeset
261 arrow_up = new Button(container, parent, a1s, 0, 0, 0, arrow_width, 3, Rect(x,y,x+arrow_height,y+arrow_width),1);
223b71206888 Initial import
thib
parents:
diff changeset
262 arrow_up->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
263 Surface* a2s = parent->Root().NewSurfaceFromRGBAData(arrow_height, arrow_width*3, button2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
264 x = r_orig.rx - arrow_height; y = r_orig.by - arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
265 arrow_down = new Button(container, parent, a2s, 0, 0, 0, arrow_width, 3, Rect(x,y,x+arrow_height,y+arrow_width),1);
223b71206888 Initial import
thib
parents:
diff changeset
266 arrow_down->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
267 // pictureºîÀ®¡Ê¥Ü¥¿¥ó¤ÎÆ°¤¯Îΰè¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
268 Rect r = r_orig;
223b71206888 Initial import
thib
parents:
diff changeset
269 r.ty += arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
270 r.by -= arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
271 panel = parent->create_node(r, 0);
223b71206888 Initial import
thib
parents:
diff changeset
272 SetPic(panel);
223b71206888 Initial import
thib
parents:
diff changeset
273 // ¥Ü¥¿¥ó¤ÎÃæ¿´Àþ¤òÉÁ²è¡¢ÀßÄê
223b71206888 Initial import
thib
parents:
diff changeset
274 Surface* s = parent->Root().NewSurface(r.width()/2, r.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
275 DSurfaceFill(s, Rect(0,0,r.width()/2,r.height()), 0, 0, 0, 0xff);
223b71206888 Initial import
thib
parents:
diff changeset
276 Pic()->SetSurface(s, -r.width()/4, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
277 Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
278 } else {
223b71206888 Initial import
thib
parents:
diff changeset
279 // Ìð°õ¤ËɬÍפÊÎΰè³ÎÊÝ
223b71206888 Initial import
thib
parents:
diff changeset
280 int arrow_height = r_orig.height();
223b71206888 Initial import
thib
parents:
diff changeset
281 button1 = create_button(0, arrow_width, arrow_height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
282 button2 = create_button(1, arrow_width, arrow_height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
283 if (r_orig.width() < arrow_width*4) {
223b71206888 Initial import
thib
parents:
diff changeset
284 if (r_orig.width() < 8) r_orig.rx = r_orig.lx + 8; // ¾®¤µ¤¹¤®¤ë¾ì¹ç¤Ï¶¯À©Êѹ¹
223b71206888 Initial import
thib
parents:
diff changeset
285 free( (void*)button1);
223b71206888 Initial import
thib
parents:
diff changeset
286 free( (void*)button2);
223b71206888 Initial import
thib
parents:
diff changeset
287 arrow_width = r_orig.width()/4;
223b71206888 Initial import
thib
parents:
diff changeset
288 // ºÆ³ä¤êÅö¤Æ
223b71206888 Initial import
thib
parents:
diff changeset
289 button1 = create_button(2, arrow_width, arrow_height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
290 button2 = create_button(3, arrow_width, arrow_height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
291 }
223b71206888 Initial import
thib
parents:
diff changeset
292 // Ìð°õ¥Ü¥¿¥ó¤ÎºîÀ®
223b71206888 Initial import
thib
parents:
diff changeset
293 Surface* a1s = parent->Root().NewSurfaceFromRGBAData(arrow_width, arrow_height*3, button1, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
294 int x = r_orig.lx; int y = r_orig.ty;
223b71206888 Initial import
thib
parents:
diff changeset
295 arrow_up = new Button(container, parent, a1s, 0, 0, 0, arrow_height, 3, Rect(x,y,x+arrow_width,y+arrow_height),1);
223b71206888 Initial import
thib
parents:
diff changeset
296 arrow_up->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
297 Surface* a2s = parent->Root().NewSurfaceFromRGBAData(arrow_width, arrow_height*3, button2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
298 x = r_orig.rx - arrow_width; y = r_orig.by - arrow_height;
223b71206888 Initial import
thib
parents:
diff changeset
299 arrow_down = new Button(container, parent, a2s, 0, 0, 0, arrow_height, 3, Rect(x,y,x+arrow_width,y+arrow_height),1);
223b71206888 Initial import
thib
parents:
diff changeset
300 arrow_down->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
301 // pictureºîÀ®¡Ê¥Ü¥¿¥ó¤ÎÆ°¤¯Îΰè¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
302 Rect r = r_orig;
223b71206888 Initial import
thib
parents:
diff changeset
303 r.lx += arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
304 r.rx -= arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
305 panel = parent->create_node(r, 0);
223b71206888 Initial import
thib
parents:
diff changeset
306 SetPic(panel);
223b71206888 Initial import
thib
parents:
diff changeset
307 // ¥Ü¥¿¥ó¤ÎÃæ¿´Àþ¤òÉÁ²è¡¢ÀßÄê
223b71206888 Initial import
thib
parents:
diff changeset
308 Surface* s = parent->Root().NewSurface(r.width(), r.height()/2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
309 DSurfaceFill(s, Rect(0,0,r.width(),r.height()/2), 0, 0, 0, 0xff);
223b71206888 Initial import
thib
parents:
diff changeset
310 Pic()->SetSurface(s, 0, -r.height()/4, 0);
223b71206888 Initial import
thib
parents:
diff changeset
311 Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
312 }
223b71206888 Initial import
thib
parents:
diff changeset
313 arrow_up->press_func = &Scale::PressArrowUp;
223b71206888 Initial import
thib
parents:
diff changeset
314 arrow_up->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
315 arrow_down->press_func = &Scale::PressArrowDown;
223b71206888 Initial import
thib
parents:
diff changeset
316 arrow_down->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
317 arrow_up->show();
223b71206888 Initial import
thib
parents:
diff changeset
318 arrow_down->show();
223b71206888 Initial import
thib
parents:
diff changeset
319 panel->show();
223b71206888 Initial import
thib
parents:
diff changeset
320 InitCursor(0);
223b71206888 Initial import
thib
parents:
diff changeset
321 }
223b71206888 Initial import
thib
parents:
diff changeset
322
223b71206888 Initial import
thib
parents:
diff changeset
323 void Scale::InitCursor(int width_ratio) {
223b71206888 Initial import
thib
parents:
diff changeset
324 int r=cursor_color.r, g=cursor_color.g, b=cursor_color.b;
223b71206888 Initial import
thib
parents:
diff changeset
325 if (cursor) delete cursor;
223b71206888 Initial import
thib
parents:
diff changeset
326 cursor = 0;
223b71206888 Initial import
thib
parents:
diff changeset
327 Rect region(0,0);
223b71206888 Initial import
thib
parents:
diff changeset
328 if (width_ratio < 0) width_ratio = 0;
223b71206888 Initial import
thib
parents:
diff changeset
329 else if (width_ratio > 1024) width_ratio = 1024;
223b71206888 Initial import
thib
parents:
diff changeset
330 if (is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
331 if (width_ratio == 0) cursor_width = Pic()->Width() * 3 / 2; // Éý¤Î1.5ÇÜ
223b71206888 Initial import
thib
parents:
diff changeset
332 else cursor_width = Pic()->Height()*width_ratio/1024;
223b71206888 Initial import
thib
parents:
diff changeset
333 if (cursor_width <= 0) return; // ¥«¡¼¥½¥ë¤Ê¤·¡Ê¤¤¤¤¤Î¤«¡©¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
334 region = Rect(0, 0, Pic()->Width(), cursor_width);
223b71206888 Initial import
thib
parents:
diff changeset
335 } else { // horizontal
223b71206888 Initial import
thib
parents:
diff changeset
336 if (width_ratio == 0) cursor_width = Pic()->Height() * 3 / 2; // ¹â¤µ¤Î1.5ÇÜ
223b71206888 Initial import
thib
parents:
diff changeset
337 else cursor_width = Pic()->Width()*width_ratio/1024;
223b71206888 Initial import
thib
parents:
diff changeset
338 if (cursor_width <= 0) return; // ¥«¡¼¥½¥ë¤Ê¤·¡Ê¤¤¤¤¤Î¤«¡©¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
339 region = Rect(0, 0, cursor_width, Pic()->Height());
223b71206888 Initial import
thib
parents:
diff changeset
340 }
223b71206888 Initial import
thib
parents:
diff changeset
341
223b71206888 Initial import
thib
parents:
diff changeset
342 int height = region.height();
223b71206888 Initial import
thib
parents:
diff changeset
343 int width = region.width();
223b71206888 Initial import
thib
parents:
diff changeset
344 char* box = create_box(width, height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
345 Surface* boxs = parent->Root().NewSurfaceFromRGBAData(width, height*3, box, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
346 cursor = new Button(container, panel, boxs, 0, 0, 0, height, 3, region, 2);
223b71206888 Initial import
thib
parents:
diff changeset
347 cursor->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
348
223b71206888 Initial import
thib
parents:
diff changeset
349 cursor->press_func = &Scale::PressCursor;
223b71206888 Initial import
thib
parents:
diff changeset
350 cursor->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
351 cursor->drag_func = &Scale::DragCursor;
223b71206888 Initial import
thib
parents:
diff changeset
352 cursor->drag_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
353 cursor->show();
223b71206888 Initial import
thib
parents:
diff changeset
354
223b71206888 Initial import
thib
parents:
diff changeset
355 // Ìð°õÅù¤ò¥¯¥ê¥Ã¥¯¤·¤¿¤È¤­¤Î°ÜÆ°ÎÌ·×»»
223b71206888 Initial import
thib
parents:
diff changeset
356 int bar_width;
223b71206888 Initial import
thib
parents:
diff changeset
357 if (is_vertical) bar_width = Pic()->Height();
223b71206888 Initial import
thib
parents:
diff changeset
358 else bar_width = Pic()->Width();
223b71206888 Initial import
thib
parents:
diff changeset
359 if (bar_width <= 0) value_add = max-min;
223b71206888 Initial import
thib
parents:
diff changeset
360 else if (cursor_width == 0) value_add = 2;
223b71206888 Initial import
thib
parents:
diff changeset
361 else value_add = scale_max*cursor_width/bar_width;
223b71206888 Initial import
thib
parents:
diff changeset
362
223b71206888 Initial import
thib
parents:
diff changeset
363 return;
223b71206888 Initial import
thib
parents:
diff changeset
364 }
223b71206888 Initial import
thib
parents:
diff changeset
365
223b71206888 Initial import
thib
parents:
diff changeset
366 void Scale::PressArrowDown(void* pointer, Button* from) {
223b71206888 Initial import
thib
parents:
diff changeset
367 Scale* self = (Scale*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
368 self->SetScaleValue(self->value + self->value_add);
223b71206888 Initial import
thib
parents:
diff changeset
369 }
223b71206888 Initial import
thib
parents:
diff changeset
370 void Scale::PressArrowUp(void* pointer, Button* from){
223b71206888 Initial import
thib
parents:
diff changeset
371 Scale* self = (Scale*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
372 self->SetScaleValue(self->value - self->value_add);
223b71206888 Initial import
thib
parents:
diff changeset
373 }
223b71206888 Initial import
thib
parents:
diff changeset
374 void Scale::PressCursor(void* pointer, Button* from){
223b71206888 Initial import
thib
parents:
diff changeset
375 Scale* self = (Scale*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
376 self->value_dragstart = self->value;
223b71206888 Initial import
thib
parents:
diff changeset
377 }
223b71206888 Initial import
thib
parents:
diff changeset
378 void Scale::DragCursor(int x_from, int y_from,int x, int y, void* pointer, Button* from){
223b71206888 Initial import
thib
parents:
diff changeset
379 Scale* self = (Scale*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
380 int dx, w;
223b71206888 Initial import
thib
parents:
diff changeset
381 if (self->is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
382 dx = y-y_from;
223b71206888 Initial import
thib
parents:
diff changeset
383 w = self->Event::Video::Region().height();
223b71206888 Initial import
thib
parents:
diff changeset
384 } else {
223b71206888 Initial import
thib
parents:
diff changeset
385 dx = x-x_from;
223b71206888 Initial import
thib
parents:
diff changeset
386 w = self->Event::Video::Region().width();
223b71206888 Initial import
thib
parents:
diff changeset
387 }
223b71206888 Initial import
thib
parents:
diff changeset
388 if (w == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
389 self->SetScaleValue(self->value_dragstart + dx*scale_max/w);
223b71206888 Initial import
thib
parents:
diff changeset
390 }
223b71206888 Initial import
thib
parents:
diff changeset
391 int Scale::CalcValue(void) {
223b71206888 Initial import
thib
parents:
diff changeset
392 Rect own_region = Event::Video::Region();
223b71206888 Initial import
thib
parents:
diff changeset
393 int x, w;
223b71206888 Initial import
thib
parents:
diff changeset
394 if (is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
395 w = own_region.height();
223b71206888 Initial import
thib
parents:
diff changeset
396 x = mouse_y - own_region.ty;
223b71206888 Initial import
thib
parents:
diff changeset
397 } else {
223b71206888 Initial import
thib
parents:
diff changeset
398 w = own_region.width();
223b71206888 Initial import
thib
parents:
diff changeset
399 x = mouse_x - own_region.lx;
223b71206888 Initial import
thib
parents:
diff changeset
400 }
223b71206888 Initial import
thib
parents:
diff changeset
401 if (w == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
402 if (x < 0) x = 0;
223b71206888 Initial import
thib
parents:
diff changeset
403 else if (x > w) x = w;
223b71206888 Initial import
thib
parents:
diff changeset
404 return x*scale_max/w;
223b71206888 Initial import
thib
parents:
diff changeset
405 }
223b71206888 Initial import
thib
parents:
diff changeset
406 void Scale::Press(void){
223b71206888 Initial import
thib
parents:
diff changeset
407 int v = CalcValue();
223b71206888 Initial import
thib
parents:
diff changeset
408 if (v < value) SetScaleValue(value-value_add);
223b71206888 Initial import
thib
parents:
diff changeset
409 else SetScaleValue(value+value_add);
223b71206888 Initial import
thib
parents:
diff changeset
410 return;
223b71206888 Initial import
thib
parents:
diff changeset
411 }
223b71206888 Initial import
thib
parents:
diff changeset
412 void Scale::Motion(int x, int y){
223b71206888 Initial import
thib
parents:
diff changeset
413 mouse_x = x;
223b71206888 Initial import
thib
parents:
diff changeset
414 mouse_y = y;
223b71206888 Initial import
thib
parents:
diff changeset
415 }
223b71206888 Initial import
thib
parents:
diff changeset
416
223b71206888 Initial import
thib
parents:
diff changeset
417 void Scale::SetRange(int new_min, int new_max) {
223b71206888 Initial import
thib
parents:
diff changeset
418 min = new_min;
223b71206888 Initial import
thib
parents:
diff changeset
419 max = new_max;
223b71206888 Initial import
thib
parents:
diff changeset
420 SetValue(value);
223b71206888 Initial import
thib
parents:
diff changeset
421 return;
223b71206888 Initial import
thib
parents:
diff changeset
422 }
223b71206888 Initial import
thib
parents:
diff changeset
423 void Scale::SetValue(int new_value) {
223b71206888 Initial import
thib
parents:
diff changeset
424 if (min == max) {
223b71206888 Initial import
thib
parents:
diff changeset
425 value = min;
223b71206888 Initial import
thib
parents:
diff changeset
426 SetScaleValue(0);
223b71206888 Initial import
thib
parents:
diff changeset
427 return;
223b71206888 Initial import
thib
parents:
diff changeset
428 }
223b71206888 Initial import
thib
parents:
diff changeset
429 int scale_value = (new_value-min) * scale_max / (max-min);
223b71206888 Initial import
thib
parents:
diff changeset
430 SetScaleValue(scale_value);
223b71206888 Initial import
thib
parents:
diff changeset
431 }
223b71206888 Initial import
thib
parents:
diff changeset
432 int Scale::GetValue(void) const{
223b71206888 Initial import
thib
parents:
diff changeset
433 return min + value * (max-min) / scale_max;
223b71206888 Initial import
thib
parents:
diff changeset
434 }
223b71206888 Initial import
thib
parents:
diff changeset
435 void Scale::SetScaleValue(int new_value) {
223b71206888 Initial import
thib
parents:
diff changeset
436 if (new_value < 0) value = 0;
223b71206888 Initial import
thib
parents:
diff changeset
437 else if (new_value > scale_max) value = scale_max;
223b71206888 Initial import
thib
parents:
diff changeset
438 else value = new_value;
223b71206888 Initial import
thib
parents:
diff changeset
439 if (is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
440 int h = Pic()->Height();
223b71206888 Initial import
thib
parents:
diff changeset
441 int y = (h-cursor_width) * value / scale_max;
223b71206888 Initial import
thib
parents:
diff changeset
442 if (y < 0) y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
443 cursor->Pic()->Move(0, y);
223b71206888 Initial import
thib
parents:
diff changeset
444 } else { // horizontal
223b71206888 Initial import
thib
parents:
diff changeset
445 int w = Pic()->Width();
223b71206888 Initial import
thib
parents:
diff changeset
446 int x = (w-cursor_width) * value / scale_max;
223b71206888 Initial import
thib
parents:
diff changeset
447 if (x < 0) x = 0;
223b71206888 Initial import
thib
parents:
diff changeset
448 cursor->Pic()->Move(x, 0);
223b71206888 Initial import
thib
parents:
diff changeset
449 }
223b71206888 Initial import
thib
parents:
diff changeset
450 if (change_func) {
223b71206888 Initial import
thib
parents:
diff changeset
451 (*change_func)(change_pointer, this);
223b71206888 Initial import
thib
parents:
diff changeset
452 }
223b71206888 Initial import
thib
parents:
diff changeset
453 return;
223b71206888 Initial import
thib
parents:
diff changeset
454 }
223b71206888 Initial import
thib
parents:
diff changeset
455
223b71206888 Initial import
thib
parents:
diff changeset
456 TextButton::TextButton(Event::Container& container, PicContainer* parent, const char* text, int _text_size, Attribute attr, const Rect& r_orig, int _z, const Color& _fore, const Color& _pressed, const Color& _back) :
223b71206888 Initial import
thib
parents:
diff changeset
457 Button(container, parent, (Surface*)0, 0, 0, 0, 0, 0, r_orig, _z),
223b71206888 Initial import
thib
parents:
diff changeset
458 root(parent->Root()), surface(0), attribute(attr), text_size(_text_size),
223b71206888 Initial import
thib
parents:
diff changeset
459 fore(_fore), pressed(_pressed), back(_back)
223b71206888 Initial import
thib
parents:
diff changeset
460 {
223b71206888 Initial import
thib
parents:
diff changeset
461 bool rect_changed = false;
223b71206888 Initial import
thib
parents:
diff changeset
462 // ¤Þ¤º¡¢¥Æ¥­¥¹¥ÈÎΰè¤Î¹­¤µ¤òÆÀ¤ë
223b71206888 Initial import
thib
parents:
diff changeset
463 Rect r(r_orig);
223b71206888 Initial import
thib
parents:
diff changeset
464
223b71206888 Initial import
thib
parents:
diff changeset
465 if (text == 0) text = "";
223b71206888 Initial import
thib
parents:
diff changeset
466 int width = r.width(); int height = r.height();
223b71206888 Initial import
thib
parents:
diff changeset
467 if (width == 0) width = parent->Width() - r.lx;
223b71206888 Initial import
thib
parents:
diff changeset
468
223b71206888 Initial import
thib
parents:
diff changeset
469 TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, width);
223b71206888 Initial import
thib
parents:
diff changeset
470
223b71206888 Initial import
thib
parents:
diff changeset
471 if (r.width() == 0) { // ʸ»ú¤Ë¹ç¤ï¤»¤Æ¥¦¥£¥¸¥Ã¥ÈºîÀ®
223b71206888 Initial import
thib
parents:
diff changeset
472 rect_changed = true;
223b71206888 Initial import
thib
parents:
diff changeset
473 width = gs.width() + text_size;
223b71206888 Initial import
thib
parents:
diff changeset
474 r.rx = r.lx + gs.width();
223b71206888 Initial import
thib
parents:
diff changeset
475 attribute = Attribute(attribute | CENTER);
223b71206888 Initial import
thib
parents:
diff changeset
476 }
223b71206888 Initial import
thib
parents:
diff changeset
477 if (r.height() == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
478 rect_changed = true;
223b71206888 Initial import
thib
parents:
diff changeset
479 if (attribute & NOPADDING) r.by = r.ty + gs.height();
223b71206888 Initial import
thib
parents:
diff changeset
480 else r.by = r.ty + gs.height() + text_size/2;
223b71206888 Initial import
thib
parents:
diff changeset
481 }
223b71206888 Initial import
thib
parents:
diff changeset
482
223b71206888 Initial import
thib
parents:
diff changeset
483 if (rect_changed) {
223b71206888 Initial import
thib
parents:
diff changeset
484 // Â礭¤µÊѹ¹
223b71206888 Initial import
thib
parents:
diff changeset
485 Pic()->SetSurfaceRect(r);
223b71206888 Initial import
thib
parents:
diff changeset
486 }
223b71206888 Initial import
thib
parents:
diff changeset
487
223b71206888 Initial import
thib
parents:
diff changeset
488 sx = 0; sy = 0; sdx = 0; sdy = r.height(); nptn = 3;
223b71206888 Initial import
thib
parents:
diff changeset
489 int x = 0, y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
490 if (attribute & CENTER)
223b71206888 Initial import
thib
parents:
diff changeset
491 x = (Pic()->Width() - gs.width()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
492 y = (Pic()->Height() - gs.height()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
493
223b71206888 Initial import
thib
parents:
diff changeset
494 if (back.a == 0) { // Çطʤʤ·¡¢¤â¤·¤¯¤Ï¥Ü¥¿¥ó²¡¤Î¾õÂ֤ΤßÇطʤ¢¤ê
223b71206888 Initial import
thib
parents:
diff changeset
495 surface = root.NewSurface(r.width(), r.height()*2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
496 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
497 if (attribute & REVERSE) {
223b71206888 Initial import
thib
parents:
diff changeset
498 DSurfaceFill(surface, Rect(0,r.height(),r.width(),r.height()*2), pressed.r, pressed.g, pressed.b, 0xff);
223b71206888 Initial import
thib
parents:
diff changeset
499 }
223b71206888 Initial import
thib
parents:
diff changeset
500 gs.SetColor(fore.r, fore.g, fore.b);
223b71206888 Initial import
thib
parents:
diff changeset
501 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
502 gs.SetColor(pressed.r, pressed.g, pressed.b);
223b71206888 Initial import
thib
parents:
diff changeset
503 if (attribute & REVERSE) {
223b71206888 Initial import
thib
parents:
diff changeset
504 gs.SetReverse(true);
223b71206888 Initial import
thib
parents:
diff changeset
505 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), surface, Rect(x,y+r.height()));
223b71206888 Initial import
thib
parents:
diff changeset
506 gs.SetReverse(false);
223b71206888 Initial import
thib
parents:
diff changeset
507 } else {
223b71206888 Initial import
thib
parents:
diff changeset
508 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), surface, Rect(x,y+r.height()));
223b71206888 Initial import
thib
parents:
diff changeset
509 }
223b71206888 Initial import
thib
parents:
diff changeset
510 nptn = 2;
223b71206888 Initial import
thib
parents:
diff changeset
511 } else { // ¥Ü¥¿¥ó·¿¤ÎÇطʤ¢¤ê
223b71206888 Initial import
thib
parents:
diff changeset
512 /* ¥é¥Ù¥ëÍѤΠSurface ¤òºî¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
513 width = r.width(); height = r.height();
223b71206888 Initial import
thib
parents:
diff changeset
514 char* box = create_box(width, height, back.r, back.g, back.b);
223b71206888 Initial import
thib
parents:
diff changeset
515 surface = root.NewSurfaceFromRGBAData(r.width(), r.height()*3, box, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
516
223b71206888 Initial import
thib
parents:
diff changeset
517 Surface* text_surface = root.NewSurface(r.width(), r.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
518 DSurfaceFill(text_surface, Rect(*text_surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
519
223b71206888 Initial import
thib
parents:
diff changeset
520 gs.SetColor(fore.r, fore.g, fore.b);
223b71206888 Initial import
thib
parents:
diff changeset
521 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), text_surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
522 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
523 gs.SetColor(pressed.r, pressed.g, pressed.b);
223b71206888 Initial import
thib
parents:
diff changeset
524 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), text_surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
525 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,height));
223b71206888 Initial import
thib
parents:
diff changeset
526 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,height*2));
223b71206888 Initial import
thib
parents:
diff changeset
527 root.DeleteSurface(text_surface);
223b71206888 Initial import
thib
parents:
diff changeset
528 }
223b71206888 Initial import
thib
parents:
diff changeset
529
223b71206888 Initial import
thib
parents:
diff changeset
530 Pic()->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
531 show();
223b71206888 Initial import
thib
parents:
diff changeset
532 }
223b71206888 Initial import
thib
parents:
diff changeset
533 void TextButton::SetText(const char* text, const Color& _fore, const Color& _pressed, const Color& _back)
223b71206888 Initial import
thib
parents:
diff changeset
534 {
223b71206888 Initial import
thib
parents:
diff changeset
535 int width = Pic()->Width(); int height = Pic()->Height();
223b71206888 Initial import
thib
parents:
diff changeset
536 // ¤Þ¤º¡¢¥Æ¥­¥¹¥ÈÎΰè¤Î¹­¤µ¤òÆÀ¤ë
223b71206888 Initial import
thib
parents:
diff changeset
537 if (text == 0) text = "";
223b71206888 Initial import
thib
parents:
diff changeset
538
223b71206888 Initial import
thib
parents:
diff changeset
539 TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, width);
223b71206888 Initial import
thib
parents:
diff changeset
540
223b71206888 Initial import
thib
parents:
diff changeset
541 int x = 0, y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
542 if (attribute & CENTER) {
223b71206888 Initial import
thib
parents:
diff changeset
543 x = (width - gs.width()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
544 y = (height - gs.height()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
545 }
223b71206888 Initial import
thib
parents:
diff changeset
546 int surf_x = Pic()->SurfacePosX();
223b71206888 Initial import
thib
parents:
diff changeset
547 int surf_y = Pic()->SurfacePosY();
223b71206888 Initial import
thib
parents:
diff changeset
548 Pic()->SetSurface( (Surface*)0,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
549 root.DeleteSurface(surface);
223b71206888 Initial import
thib
parents:
diff changeset
550 surface = 0;
223b71206888 Initial import
thib
parents:
diff changeset
551
223b71206888 Initial import
thib
parents:
diff changeset
552 if (back.a == 0) { // Çطʤʤ·
223b71206888 Initial import
thib
parents:
diff changeset
553 surface = root.NewSurface(width, height*2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
554 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
555 if (attribute & REVERSE) {
223b71206888 Initial import
thib
parents:
diff changeset
556 DSurfaceFill(surface, Rect(0,height,width,height*2), pressed.r, pressed.g, pressed.b, 0xff);
223b71206888 Initial import
thib
parents:
diff changeset
557 }
223b71206888 Initial import
thib
parents:
diff changeset
558 gs.SetColor(_fore.r, _fore.g, _fore.b);
223b71206888 Initial import
thib
parents:
diff changeset
559 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
560 gs.SetColor(_pressed.r, _pressed.g, _pressed.b);
223b71206888 Initial import
thib
parents:
diff changeset
561 gs.SetReverse(true);
223b71206888 Initial import
thib
parents:
diff changeset
562 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), surface, Rect(x,y+height));
223b71206888 Initial import
thib
parents:
diff changeset
563 gs.SetReverse(false);
223b71206888 Initial import
thib
parents:
diff changeset
564 nptn = 2;
223b71206888 Initial import
thib
parents:
diff changeset
565 } else {
223b71206888 Initial import
thib
parents:
diff changeset
566 /* ¥é¥Ù¥ëÍѤΠSurface ¤òºî¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
567 char* box = create_box(width, height, _back.r, _back.g, _back.b);
223b71206888 Initial import
thib
parents:
diff changeset
568 surface = root.NewSurfaceFromRGBAData(width, height*3, box, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
569
223b71206888 Initial import
thib
parents:
diff changeset
570 Surface* text_surface = root.NewSurface(width, height, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
571 DSurfaceFill(text_surface, Rect(*text_surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
572
223b71206888 Initial import
thib
parents:
diff changeset
573 gs.SetColor(_fore.r, _fore.g, _fore.b);
223b71206888 Initial import
thib
parents:
diff changeset
574 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), text_surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
575 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
576 gs.SetColor(_pressed.r, _pressed.g, _pressed.b);
223b71206888 Initial import
thib
parents:
diff changeset
577 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), text_surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
578 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,height));
223b71206888 Initial import
thib
parents:
diff changeset
579 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,height*2));
223b71206888 Initial import
thib
parents:
diff changeset
580 root.DeleteSurface(text_surface);
223b71206888 Initial import
thib
parents:
diff changeset
581 }
223b71206888 Initial import
thib
parents:
diff changeset
582
223b71206888 Initial import
thib
parents:
diff changeset
583 Pic()->SetSurface(surface, surf_x, surf_y);
223b71206888 Initial import
thib
parents:
diff changeset
584 show();
223b71206888 Initial import
thib
parents:
diff changeset
585 }
223b71206888 Initial import
thib
parents:
diff changeset
586
223b71206888 Initial import
thib
parents:
diff changeset
587 TextButton::~TextButton() {
223b71206888 Initial import
thib
parents:
diff changeset
588 if (surface) root.DeleteSurface(surface);
223b71206888 Initial import
thib
parents:
diff changeset
589 surface = 0;
223b71206888 Initial import
thib
parents:
diff changeset
590 return;
223b71206888 Initial import
thib
parents:
diff changeset
591 }
223b71206888 Initial import
thib
parents:
diff changeset
592
223b71206888 Initial import
thib
parents:
diff changeset
593 Text::Text(Event::Container& container, PicContainer* parent, const Rect& r, const Rect& text_r, int _fontsize) :
223b71206888 Initial import
thib
parents:
diff changeset
594 Event::Video(container),
223b71206888 Initial import
thib
parents:
diff changeset
595 Event::Time(container),
223b71206888 Initial import
thib
parents:
diff changeset
596 event(container),
223b71206888 Initial import
thib
parents:
diff changeset
597 srcrect(0,0,0,0),
223b71206888 Initial import
thib
parents:
diff changeset
598 layout(wdefault_font.c_str(), _fontsize), fontsize(_fontsize) {
223b71206888 Initial import
thib
parents:
diff changeset
599
223b71206888 Initial import
thib
parents:
diff changeset
600 SetPic(parent->create_node(r, 0));
223b71206888 Initial import
thib
parents:
diff changeset
601 surface = parent->Root().NewSurface(text_r.width(), text_r.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
602 pictext = PicNode()->create_leaf(text_r, PicBase::CACHE_BACK);
223b71206888 Initial import
thib
parents:
diff changeset
603 pictext->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
604 pictext->show();
223b71206888 Initial import
thib
parents:
diff changeset
605 cursor = 0;
223b71206888 Initial import
thib
parents:
diff changeset
606 cursor_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
607 window_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
608
223b71206888 Initial import
thib
parents:
diff changeset
609 event.RegisterGlobalPressFunc(&Pressed, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
610
223b71206888 Initial import
thib
parents:
diff changeset
611 speed = 10;
223b71206888 Initial import
thib
parents:
diff changeset
612 wait_delay = -1;
223b71206888 Initial import
thib
parents:
diff changeset
613 status = PREPARE;
223b71206888 Initial import
thib
parents:
diff changeset
614 old_time = wait_starttime = 0;
223b71206888 Initial import
thib
parents:
diff changeset
615 }
223b71206888 Initial import
thib
parents:
diff changeset
616
223b71206888 Initial import
thib
parents:
diff changeset
617 Text::~Text() {
223b71206888 Initial import
thib
parents:
diff changeset
618 event.DeleteGlobalPressFunc(&Pressed, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
619 PicNode()->Root().DeleteSurface(surface);
223b71206888 Initial import
thib
parents:
diff changeset
620 }
223b71206888 Initial import
thib
parents:
diff changeset
621
223b71206888 Initial import
thib
parents:
diff changeset
622 void Text::SetSpeed(int new_speed) {
223b71206888 Initial import
thib
parents:
diff changeset
623 speed = new_speed;
223b71206888 Initial import
thib
parents:
diff changeset
624 }
223b71206888 Initial import
thib
parents:
diff changeset
625 void Text::SetWait(int new_wait) {
223b71206888 Initial import
thib
parents:
diff changeset
626 if (new_wait < 0) new_wait = 100000000;
223b71206888 Initial import
thib
parents:
diff changeset
627 wait_delay = new_wait;
223b71206888 Initial import
thib
parents:
diff changeset
628 }
223b71206888 Initial import
thib
parents:
diff changeset
629
223b71206888 Initial import
thib
parents:
diff changeset
630 int Text::CalcScrollHeight(void) {
223b71206888 Initial import
thib
parents:
diff changeset
631 int i;
223b71206888 Initial import
thib
parents:
diff changeset
632 int len = bottom_pos.size();
223b71206888 Initial import
thib
parents:
diff changeset
633 int y0 = bottom_pos[line_number];
223b71206888 Initial import
thib
parents:
diff changeset
634 int height = Rect(*surface).height();
223b71206888 Initial import
thib
parents:
diff changeset
635 for (i=line_number; i<len; i++)
223b71206888 Initial import
thib
parents:
diff changeset
636 if (bottom_pos[i] - y0 > height) break;
223b71206888 Initial import
thib
parents:
diff changeset
637 if (i == line_number) i = line_number + 1;
223b71206888 Initial import
thib
parents:
diff changeset
638 return i - line_number - 1;
223b71206888 Initial import
thib
parents:
diff changeset
639 }
223b71206888 Initial import
thib
parents:
diff changeset
640 void Text::Elapsed(unsigned int current_time) {
223b71206888 Initial import
thib
parents:
diff changeset
641 SetWakeup(current_time + 50);
223b71206888 Initial import
thib
parents:
diff changeset
642 if (status == PREPARE) {
223b71206888 Initial import
thib
parents:
diff changeset
643 old_time = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
644 return;
223b71206888 Initial import
thib
parents:
diff changeset
645 }
223b71206888 Initial import
thib
parents:
diff changeset
646 int nChar = speed * (current_time - old_time) / 1000;
223b71206888 Initial import
thib
parents:
diff changeset
647 if (speed == -1 || press_count) nChar = -1;
223b71206888 Initial import
thib
parents:
diff changeset
648 if (nChar == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
649 if (speed == -1) old_time = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
650 else old_time += nChar * 1000 / speed;
223b71206888 Initial import
thib
parents:
diff changeset
651
223b71206888 Initial import
thib
parents:
diff changeset
652 switch(status) {
223b71206888 Initial import
thib
parents:
diff changeset
653 case WAIT: goto label_wait;
223b71206888 Initial import
thib
parents:
diff changeset
654 case SCROLL: goto label_scroll;
223b71206888 Initial import
thib
parents:
diff changeset
655 case DRAW2: goto label_draw2;
223b71206888 Initial import
thib
parents:
diff changeset
656 case WAIT2: goto label_wait2;
223b71206888 Initial import
thib
parents:
diff changeset
657 }
223b71206888 Initial import
thib
parents:
diff changeset
658
223b71206888 Initial import
thib
parents:
diff changeset
659 status = DRAW;
223b71206888 Initial import
thib
parents:
diff changeset
660 if (press_count) {
223b71206888 Initial import
thib
parents:
diff changeset
661 nChar = -1;
223b71206888 Initial import
thib
parents:
diff changeset
662 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
663 }
223b71206888 Initial import
thib
parents:
diff changeset
664 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
665 if (nChar == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
666 status = WAIT;
223b71206888 Initial import
thib
parents:
diff changeset
667 cursor_activated = true;
223b71206888 Initial import
thib
parents:
diff changeset
668 if (cursor_activated && window_activated && cursor) cursor->show();
223b71206888 Initial import
thib
parents:
diff changeset
669 wait_starttime = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
670 label_wait:
223b71206888 Initial import
thib
parents:
diff changeset
671 if (current_time < wait_starttime + wait_delay && press_count == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
672 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
673 nChar = 0;
223b71206888 Initial import
thib
parents:
diff changeset
674 cursor_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
675 if (cursor) cursor->hide();
223b71206888 Initial import
thib
parents:
diff changeset
676 while(cur_pos != gstream.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
677 // ¥¹¥¯¥í¡¼¥ë¤·¤Æ¤Ï¼¡¹ÔÉÁ²è¡¢¤ò·«¤êÊÖ¤¹
223b71206888 Initial import
thib
parents:
diff changeset
678 for (scroll_height = CalcScrollHeight(); scroll_height > 0; scroll_height--) {
223b71206888 Initial import
thib
parents:
diff changeset
679 status = SCROLL;
223b71206888 Initial import
thib
parents:
diff changeset
680 label_scroll:
223b71206888 Initial import
thib
parents:
diff changeset
681 if (press_count) break;
223b71206888 Initial import
thib
parents:
diff changeset
682 Scrollup(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
683 if (nChar == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
684 status = DRAW2;
223b71206888 Initial import
thib
parents:
diff changeset
685 label_draw2:
223b71206888 Initial import
thib
parents:
diff changeset
686 if (press_count) break;
223b71206888 Initial import
thib
parents:
diff changeset
687 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
688 if (nChar == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
689 }
223b71206888 Initial import
thib
parents:
diff changeset
690 if (nChar != 0 && scroll_height) {
223b71206888 Initial import
thib
parents:
diff changeset
691 nChar = 100000;
223b71206888 Initial import
thib
parents:
diff changeset
692 if (status == SCROLL) Scrollup(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
693 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
694 scroll_height--;
223b71206888 Initial import
thib
parents:
diff changeset
695 for (; scroll_height > 0; scroll_height--) {
223b71206888 Initial import
thib
parents:
diff changeset
696 Scrollup(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
697 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
698 }
223b71206888 Initial import
thib
parents:
diff changeset
699 }
223b71206888 Initial import
thib
parents:
diff changeset
700 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
701 status = WAIT2;
223b71206888 Initial import
thib
parents:
diff changeset
702 cursor_activated = true;
223b71206888 Initial import
thib
parents:
diff changeset
703 if (cursor_activated && window_activated && cursor) cursor->show();
223b71206888 Initial import
thib
parents:
diff changeset
704 wait_starttime = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
705 label_wait2:
223b71206888 Initial import
thib
parents:
diff changeset
706 if (current_time < wait_starttime + wait_delay && press_count == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
707 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
708 nChar = 0;
223b71206888 Initial import
thib
parents:
diff changeset
709 cursor_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
710 if (cursor) cursor->hide();
223b71206888 Initial import
thib
parents:
diff changeset
711 }
223b71206888 Initial import
thib
parents:
diff changeset
712 status = PREPARE;
223b71206888 Initial import
thib
parents:
diff changeset
713 return;
223b71206888 Initial import
thib
parents:
diff changeset
714 }
223b71206888 Initial import
thib
parents:
diff changeset
715
223b71206888 Initial import
thib
parents:
diff changeset
716 bool Text::Pressed(int x, int y, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
717 Text* wid = (Text*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
718 if (wid->Pic()->IsHidden()) return true;
223b71206888 Initial import
thib
parents:
diff changeset
719 wid->press_count++;
223b71206888 Initial import
thib
parents:
diff changeset
720 return true;
223b71206888 Initial import
thib
parents:
diff changeset
721 }
223b71206888 Initial import
thib
parents:
diff changeset
722
223b71206888 Initial import
thib
parents:
diff changeset
723 void Text::Clear(void) {
223b71206888 Initial import
thib
parents:
diff changeset
724 stream.container.clear();
223b71206888 Initial import
thib
parents:
diff changeset
725 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
726 pictext->ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
727 status = PREPARE;
223b71206888 Initial import
thib
parents:
diff changeset
728 }
223b71206888 Initial import
thib
parents:
diff changeset
729
223b71206888 Initial import
thib
parents:
diff changeset
730 void Text::Flush(void) {
223b71206888 Initial import
thib
parents:
diff changeset
731 int nChar = -1;
223b71206888 Initial import
thib
parents:
diff changeset
732 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
733 }
223b71206888 Initial import
thib
parents:
diff changeset
734
223b71206888 Initial import
thib
parents:
diff changeset
735 void Text::Start(void) {
223b71206888 Initial import
thib
parents:
diff changeset
736 gstream.clear();
223b71206888 Initial import
thib
parents:
diff changeset
737 bottom_pos.clear();
223b71206888 Initial import
thib
parents:
diff changeset
738 layout.Layout(stream, gstream, bottom_pos, pictext->Width()-fontsize/2);
223b71206888 Initial import
thib
parents:
diff changeset
739
223b71206888 Initial import
thib
parents:
diff changeset
740 // height ¤ÎÀÑ»»ÃͤȤ·¤Æ bottom_pos ¤ò·×»»
223b71206888 Initial import
thib
parents:
diff changeset
741 std::vector<int>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
742 int pos = 0;
223b71206888 Initial import
thib
parents:
diff changeset
743 for (it = bottom_pos.begin(); it != bottom_pos.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
744 pos += *it;
223b71206888 Initial import
thib
parents:
diff changeset
745 *it = pos;
223b71206888 Initial import
thib
parents:
diff changeset
746 }
223b71206888 Initial import
thib
parents:
diff changeset
747
223b71206888 Initial import
thib
parents:
diff changeset
748 cur_pos = gstream.begin();
223b71206888 Initial import
thib
parents:
diff changeset
749 line_number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
750 scrolled_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
751 srcrect = Rect(0, 0, pictext->Width(), pictext->Height());
223b71206888 Initial import
thib
parents:
diff changeset
752 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
753
223b71206888 Initial import
thib
parents:
diff changeset
754 status = DRAW;
223b71206888 Initial import
thib
parents:
diff changeset
755 cursor_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
756 if (cursor) cursor->hide();
223b71206888 Initial import
thib
parents:
diff changeset
757 }
223b71206888 Initial import
thib
parents:
diff changeset
758
223b71206888 Initial import
thib
parents:
diff changeset
759 void Text::DrawText(int& nChar) {
223b71206888 Initial import
thib
parents:
diff changeset
760 // ÉÁ²èÈϰϤòÆÀ¤ë
223b71206888 Initial import
thib
parents:
diff changeset
761 iterator end = gstream.end();
223b71206888 Initial import
thib
parents:
diff changeset
762 iterator it = cur_pos;
223b71206888 Initial import
thib
parents:
diff changeset
763 while(nChar && it != end) { // nChar < 0 ¤Ê¤é½ÐÍè¤ë¤À¤±¤Îʸ»ú¤òÉÁ²è
223b71206888 Initial import
thib
parents:
diff changeset
764 if (! (it->flag & TextGlyph::Group)) nChar--;
223b71206888 Initial import
thib
parents:
diff changeset
765 if (it->flag & TextGlyph::LineEnd) {
223b71206888 Initial import
thib
parents:
diff changeset
766 if (bottom_pos[line_number+1] > srcrect.by) { //²þ¹Ô¤¹¤ë¤È²èÌ̤«¤é½Ð¤Æ¤·¤Þ¤¦
223b71206888 Initial import
thib
parents:
diff changeset
767 it++;
223b71206888 Initial import
thib
parents:
diff changeset
768 if (nChar == 0) nChar = 1;
223b71206888 Initial import
thib
parents:
diff changeset
769 break;
223b71206888 Initial import
thib
parents:
diff changeset
770 }
223b71206888 Initial import
thib
parents:
diff changeset
771 line_number++;
223b71206888 Initial import
thib
parents:
diff changeset
772 }
223b71206888 Initial import
thib
parents:
diff changeset
773 it++;
223b71206888 Initial import
thib
parents:
diff changeset
774 }
223b71206888 Initial import
thib
parents:
diff changeset
775 // ÉÁ²è¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
776 Rect r = DSurfaceRenderText(cur_pos, it, srcrect, surface, Rect(0,0,0,0));
223b71206888 Initial import
thib
parents:
diff changeset
777 pictext->ReBlit(r);
223b71206888 Initial import
thib
parents:
diff changeset
778 cur_pos = it;
223b71206888 Initial import
thib
parents:
diff changeset
779 return;
223b71206888 Initial import
thib
parents:
diff changeset
780 }
223b71206888 Initial import
thib
parents:
diff changeset
781
223b71206888 Initial import
thib
parents:
diff changeset
782 void Text::Scrollup(int& nChar) {
223b71206888 Initial import
thib
parents:
diff changeset
783 if (nChar < 0) { // °ì²èÌÌʬ¥¹¥¯¥í¡¼¥ë¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
784 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
785 pictext->ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
786 srcrect = Rect(*surface);
223b71206888 Initial import
thib
parents:
diff changeset
787 srcrect.rmove(0, bottom_pos[line_number]);
223b71206888 Initial import
thib
parents:
diff changeset
788 line_number++;
223b71206888 Initial import
thib
parents:
diff changeset
789 scrolled_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
790 return;
223b71206888 Initial import
thib
parents:
diff changeset
791 }
223b71206888 Initial import
thib
parents:
diff changeset
792 // ¥¹¥¯¥í¡¼¥ëÉý¤òµá¤á¤ë
223b71206888 Initial import
thib
parents:
diff changeset
793 const int max_scroll_count = 8;
223b71206888 Initial import
thib
parents:
diff changeset
794 int dy = bottom_pos[line_number+1] - bottom_pos[line_number];
223b71206888 Initial import
thib
parents:
diff changeset
795 int cur_dy;
223b71206888 Initial import
thib
parents:
diff changeset
796 if (scrolled_count+nChar >= max_scroll_count) {
223b71206888 Initial import
thib
parents:
diff changeset
797 cur_dy = dy - (scrolled_count*dy/max_scroll_count);
223b71206888 Initial import
thib
parents:
diff changeset
798 nChar -= max_scroll_count-scrolled_count;
223b71206888 Initial import
thib
parents:
diff changeset
799 nChar++;
223b71206888 Initial import
thib
parents:
diff changeset
800 scrolled_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
801 line_number++;
223b71206888 Initial import
thib
parents:
diff changeset
802 srcrect.rmove(0, dy);
223b71206888 Initial import
thib
parents:
diff changeset
803 } else {
223b71206888 Initial import
thib
parents:
diff changeset
804 cur_dy = (scrolled_count+nChar)*dy/max_scroll_count;
223b71206888 Initial import
thib
parents:
diff changeset
805 cur_dy -=(scrolled_count*dy/max_scroll_count);
223b71206888 Initial import
thib
parents:
diff changeset
806 scrolled_count += nChar;
223b71206888 Initial import
thib
parents:
diff changeset
807 nChar = 0;
223b71206888 Initial import
thib
parents:
diff changeset
808 }
223b71206888 Initial import
thib
parents:
diff changeset
809 Rect r(*surface);
223b71206888 Initial import
thib
parents:
diff changeset
810 DSurfaceMove(surface, r, surface, Rect(0, -cur_dy, 0, 0));
223b71206888 Initial import
thib
parents:
diff changeset
811 r.ty = r.by-cur_dy;
223b71206888 Initial import
thib
parents:
diff changeset
812 DSurfaceFill(surface, r, 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
813 pictext->ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
814 return;
223b71206888 Initial import
thib
parents:
diff changeset
815 }
223b71206888 Initial import
thib
parents:
diff changeset
816
223b71206888 Initial import
thib
parents:
diff changeset
817 void Text::activate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
818 event.RegisterGlobalPressFunc(&Pressed, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
819 Event::Video::activate();
223b71206888 Initial import
thib
parents:
diff changeset
820 window_activated = true;
223b71206888 Initial import
thib
parents:
diff changeset
821 if (cursor_activated && window_activated && cursor) cursor->show();
223b71206888 Initial import
thib
parents:
diff changeset
822 }
223b71206888 Initial import
thib
parents:
diff changeset
823 void Text::deactivate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
824 event.DeleteGlobalPressFunc(&Pressed, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
825 Event::Video::deactivate();
223b71206888 Initial import
thib
parents:
diff changeset
826 window_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
827 if (cursor) cursor->hide();
223b71206888 Initial import
thib
parents:
diff changeset
828 }
223b71206888 Initial import
thib
parents:
diff changeset
829 void Text::SetCursor(TimeCursor* c) {
223b71206888 Initial import
thib
parents:
diff changeset
830 cursor = c;
223b71206888 Initial import
thib
parents:
diff changeset
831 if (c) {
223b71206888 Initial import
thib
parents:
diff changeset
832 if (cursor_activated && window_activated) c->show();
223b71206888 Initial import
thib
parents:
diff changeset
833 else c->hide();
223b71206888 Initial import
thib
parents:
diff changeset
834 }
223b71206888 Initial import
thib
parents:
diff changeset
835 }
223b71206888 Initial import
thib
parents:
diff changeset
836
223b71206888 Initial import
thib
parents:
diff changeset
837 Label::Label(PicContainer* parent, const Rect& r_orig, bool _is_center, const char* text, int _text_size) :
223b71206888 Initial import
thib
parents:
diff changeset
838 is_center(_is_center),
223b71206888 Initial import
thib
parents:
diff changeset
839 root(parent->Root()),
223b71206888 Initial import
thib
parents:
diff changeset
840 text_size(_text_size) {
223b71206888 Initial import
thib
parents:
diff changeset
841 Rect r(r_orig);
223b71206888 Initial import
thib
parents:
diff changeset
842
223b71206888 Initial import
thib
parents:
diff changeset
843 if (text == 0) text = "";
223b71206888 Initial import
thib
parents:
diff changeset
844 int width = r.width(); int height = r.height();
223b71206888 Initial import
thib
parents:
diff changeset
845 if (width == 0) width = parent->Width() - r.lx;
223b71206888 Initial import
thib
parents:
diff changeset
846
223b71206888 Initial import
thib
parents:
diff changeset
847 TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, width);
223b71206888 Initial import
thib
parents:
diff changeset
848
223b71206888 Initial import
thib
parents:
diff changeset
849 if (r.width() == 0) { // ʸ»ú¤Ë¹ç¤ï¤»¤Æ¥¦¥£¥¸¥Ã¥ÈºîÀ®
223b71206888 Initial import
thib
parents:
diff changeset
850 width = gs.width();
223b71206888 Initial import
thib
parents:
diff changeset
851 r.rx = r.lx + gs.width();
223b71206888 Initial import
thib
parents:
diff changeset
852 }
223b71206888 Initial import
thib
parents:
diff changeset
853 if (r.height() == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
854 r.by = r.ty + gs.height();
223b71206888 Initial import
thib
parents:
diff changeset
855 }
223b71206888 Initial import
thib
parents:
diff changeset
856
223b71206888 Initial import
thib
parents:
diff changeset
857 SetPic(parent->create_leaf(r, 0));
223b71206888 Initial import
thib
parents:
diff changeset
858
223b71206888 Initial import
thib
parents:
diff changeset
859 /* ¥é¥Ù¥ëÍѤΠSurface ¤òºî¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
860 surface = parent->Root().NewSurface(r.width(), r.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
861
223b71206888 Initial import
thib
parents:
diff changeset
862 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
863 int x = 0, y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
864 if (is_center) {
223b71206888 Initial import
thib
parents:
diff changeset
865 x = (Pic()->Width() - gs.width()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
866 y = (Pic()->Height() - gs.height()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
867 }
223b71206888 Initial import
thib
parents:
diff changeset
868
223b71206888 Initial import
thib
parents:
diff changeset
869 DSurfaceRenderText(gs.begin(), gs.end(), Rect(*surface), surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
870
223b71206888 Initial import
thib
parents:
diff changeset
871 Pic()->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
872 show();
223b71206888 Initial import
thib
parents:
diff changeset
873 }
223b71206888 Initial import
thib
parents:
diff changeset
874 Label::~Label() {
223b71206888 Initial import
thib
parents:
diff changeset
875 root.DeleteSurface(surface);
223b71206888 Initial import
thib
parents:
diff changeset
876 }
223b71206888 Initial import
thib
parents:
diff changeset
877 void Label::SetText(const char* text) {
223b71206888 Initial import
thib
parents:
diff changeset
878 if (text == 0) text = "";
223b71206888 Initial import
thib
parents:
diff changeset
879 TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, Pic()->Width());
223b71206888 Initial import
thib
parents:
diff changeset
880 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
881 int x = 0, y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
882 if (is_center) {
223b71206888 Initial import
thib
parents:
diff changeset
883 x = (Pic()->Width() - gs.width()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
884 y = (Pic()->Height() - gs.height()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
885 }
223b71206888 Initial import
thib
parents:
diff changeset
886
223b71206888 Initial import
thib
parents:
diff changeset
887 DSurfaceRenderText(gs.begin(), gs.end(), Rect(*surface), surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
888 Pic()->ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
889 }
223b71206888 Initial import
thib
parents:
diff changeset
890
223b71206888 Initial import
thib
parents:
diff changeset
891 Dialog::Dialog(Event::Container& container, PicContainer* parent, const char* text, bool with_cancel) :
223b71206888 Initial import
thib
parents:
diff changeset
892 Event::Video(container) {
223b71206888 Initial import
thib
parents:
diff changeset
893
223b71206888 Initial import
thib
parents:
diff changeset
894 int x,y;
223b71206888 Initial import
thib
parents:
diff changeset
895 status = WAIT;
223b71206888 Initial import
thib
parents:
diff changeset
896 set_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
897 set_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
898
223b71206888 Initial import
thib
parents:
diff changeset
899 XKFont::HorizLayout& layout = *DefaultLayout(26);
223b71206888 Initial import
thib
parents:
diff changeset
900 int dialog_width = parent->Width() / 2;
223b71206888 Initial import
thib
parents:
diff changeset
901 TextGlyphStream s_ok = layout.Layout("£Ï£Ë", dialog_width);
223b71206888 Initial import
thib
parents:
diff changeset
902 TextGlyphStream s_cancel = layout.Layout("¼è¾Ã", dialog_width);
223b71206888 Initial import
thib
parents:
diff changeset
903 TextGlyphStream s_text = layout.Layout(text, dialog_width);
223b71206888 Initial import
thib
parents:
diff changeset
904
223b71206888 Initial import
thib
parents:
diff changeset
905 Rect r_text(0, 0, s_text.width(), s_text.height());
223b71206888 Initial import
thib
parents:
diff changeset
906 Rect r_ok(0, 0, s_ok.width(), s_ok.height());
223b71206888 Initial import
thib
parents:
diff changeset
907 Rect r_cancel(0, 0, s_cancel.width(), s_cancel.height());
223b71206888 Initial import
thib
parents:
diff changeset
908
223b71206888 Initial import
thib
parents:
diff changeset
909 /* ¥À¥¤¥¢¥í¥°¥Ü¥Ã¥¯¥¹¤Î Surface ¤òºî¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
910 int dwidth = r_text.width() + (r_text.width()/10)*2 + 6;
223b71206888 Initial import
thib
parents:
diff changeset
911 int dheight = r_text.height() + r_ok.height() + r_cancel.height()*3 + 4;
223b71206888 Initial import
thib
parents:
diff changeset
912 surface_diag = parent->Root().NewSurface(dwidth, dheight, NO_MASK); // alpha ¤Ê¤·
223b71206888 Initial import
thib
parents:
diff changeset
913 DSurfaceFill(surface_diag, Rect(*surface_diag), 0xf0, 0xd0, 0xa0);
223b71206888 Initial import
thib
parents:
diff changeset
914 DrawBox(surface_diag, Rect(0,0,dwidth,dheight));
223b71206888 Initial import
thib
parents:
diff changeset
915
223b71206888 Initial import
thib
parents:
diff changeset
916 Surface* surface_text = parent->Root().NewSurface(r_text.width(), r_text.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
917 s_text.SetColor(0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
918 DSurfaceRenderText(s_text.begin(), s_text.end(), r_text, surface_text, Rect(0, 0, 0, 0));
223b71206888 Initial import
thib
parents:
diff changeset
919 x = r_text.width()/10 + 3;
223b71206888 Initial import
thib
parents:
diff changeset
920 y = r_cancel.height()+2;
223b71206888 Initial import
thib
parents:
diff changeset
921 parent->Root().BlitSurface(surface_text, r_text, surface_diag, Rect(x, y, x+r_text.width(), y+r_text.height()));
223b71206888 Initial import
thib
parents:
diff changeset
922 parent->Root().DeleteSurface(surface_text);
223b71206888 Initial import
thib
parents:
diff changeset
923
223b71206888 Initial import
thib
parents:
diff changeset
924 /* panel ¤ò¤Ä¤¯¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
925 x = (parent->Width()-dwidth)/2;
223b71206888 Initial import
thib
parents:
diff changeset
926 y = (parent->Height()-dheight)/2;
223b71206888 Initial import
thib
parents:
diff changeset
927 SetPic(parent->create_node(Rect(x, y, x+dwidth, y+dheight), 0));
223b71206888 Initial import
thib
parents:
diff changeset
928
223b71206888 Initial import
thib
parents:
diff changeset
929 /* ¥Ü¥¿¥ó¤òºîÀ®¤¹¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
930 /* f8d8c8 ÇØ·Ê(ÌÀ)*/
223b71206888 Initial import
thib
parents:
diff changeset
931 /* f0d0a0 ÇØ·Ê*/
223b71206888 Initial import
thib
parents:
diff changeset
932 /* b08040 ÏÈ¡ÊÌÀ)*/
223b71206888 Initial import
thib
parents:
diff changeset
933 /* 805010 ÏÈ*/
223b71206888 Initial import
thib
parents:
diff changeset
934 /* 382018 ¹õ*/
223b71206888 Initial import
thib
parents:
diff changeset
935 /* 9890f8 ÀÄ*/
223b71206888 Initial import
thib
parents:
diff changeset
936 /* dc6448 ÀÖ*/
223b71206888 Initial import
thib
parents:
diff changeset
937 /* ³Æ¥Ü¥¿¥ó¤Ïº¸±¦¤Ë¥Ü¥¿¥óÉý¤Î 1/4, ¾å²¼¤Ë¥Ü¥¿¥óÉý¤Î 1/4 ¤Î¥Þ¡¼¥¸¥ó¤ò»ý¤Ä */
223b71206888 Initial import
thib
parents:
diff changeset
938 Rect r_btn(r_ok); r_btn.join(r_cancel);
223b71206888 Initial import
thib
parents:
diff changeset
939 int btn_width = r_btn.width() * 3 / 2;
223b71206888 Initial import
thib
parents:
diff changeset
940 int btn_height = r_btn.height() * 3 / 2;
223b71206888 Initial import
thib
parents:
diff changeset
941 surface_btn = parent->Root().NewSurface(btn_width, btn_height*4, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
942 DSurfaceFill(surface_btn, Rect(*surface_btn), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
943 s_ok.SetColor(0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
944 DSurfaceRenderText(s_ok.begin(), s_ok.end(), r_ok, surface_btn, Rect( (btn_width-r_ok.width())/2,(btn_height-r_ok.height())/2));
223b71206888 Initial import
thib
parents:
diff changeset
945 s_ok.SetColor(0x98, 0x90, 0xf8);
223b71206888 Initial import
thib
parents:
diff changeset
946 DSurfaceRenderText(s_ok.begin(), s_ok.end(), r_ok, surface_btn, Rect( (btn_width-r_ok.width())/2,(btn_height-r_ok.height())/2 + btn_height));
223b71206888 Initial import
thib
parents:
diff changeset
947 s_cancel.SetColor(0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
948 DSurfaceRenderText(s_cancel.begin(), s_cancel.end(), r_cancel, surface_btn, Rect( (btn_width-r_cancel.width())/2,(btn_height-r_cancel.height())/2 + btn_height*2));
223b71206888 Initial import
thib
parents:
diff changeset
949 s_cancel.SetColor(0xdc, 0x64, 0x48);
223b71206888 Initial import
thib
parents:
diff changeset
950 DSurfaceRenderText(s_cancel.begin(), s_cancel.end(), r_cancel, surface_btn, Rect( (btn_width-r_cancel.width())/2,(btn_height-r_cancel.height())/2 + btn_height*3));
223b71206888 Initial import
thib
parents:
diff changeset
951
223b71206888 Initial import
thib
parents:
diff changeset
952 x = (dwidth - btn_width*2) / 3;;
223b71206888 Initial import
thib
parents:
diff changeset
953 y = r_cancel.height()*3/2 + r_text.height() + 2;
223b71206888 Initial import
thib
parents:
diff changeset
954 if (!with_cancel) x = (dwidth - btn_width) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
955 Button* b_ok = new Button(container, PicNode(), surface_btn, 0, 0, 0, btn_height, 2, Rect(x, y, x+btn_width, y+btn_height), 1);
223b71206888 Initial import
thib
parents:
diff changeset
956 DrawBox(surface_diag, Rect(x-3,y-2,x+btn_width+3,y+btn_height+2));
223b71206888 Initial import
thib
parents:
diff changeset
957 b_ok->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
958 b_ok->press_func = &press_ok;
223b71206888 Initial import
thib
parents:
diff changeset
959 if (with_cancel) {
223b71206888 Initial import
thib
parents:
diff changeset
960 x += x + btn_width;
223b71206888 Initial import
thib
parents:
diff changeset
961 Button* b_cancel = new Button(container, PicNode(), surface_btn, 0, btn_height*2, 0, btn_height, 2, Rect(x, y, x+btn_width, y+btn_height), 1);
223b71206888 Initial import
thib
parents:
diff changeset
962 DrawBox(surface_diag, Rect(x-3,y-2,x+btn_width+3,y+btn_height+2));
223b71206888 Initial import
thib
parents:
diff changeset
963 b_cancel->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
964 b_cancel->press_func = &press_cancel;
223b71206888 Initial import
thib
parents:
diff changeset
965 }
223b71206888 Initial import
thib
parents:
diff changeset
966
223b71206888 Initial import
thib
parents:
diff changeset
967 Pic()->SetSurface(surface_diag, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
968 Pic()->ZMove(ZMOVE_TOP);
223b71206888 Initial import
thib
parents:
diff changeset
969
223b71206888 Initial import
thib
parents:
diff changeset
970 show_all();
223b71206888 Initial import
thib
parents:
diff changeset
971 }
223b71206888 Initial import
thib
parents:
diff changeset
972 Dialog::~Dialog() {
223b71206888 Initial import
thib
parents:
diff changeset
973 PicRoot& root = PicNode()->Root();
223b71206888 Initial import
thib
parents:
diff changeset
974 SetPic(0);
223b71206888 Initial import
thib
parents:
diff changeset
975 root.DeleteSurface(surface_btn);
223b71206888 Initial import
thib
parents:
diff changeset
976 root.DeleteSurface(surface_diag);
223b71206888 Initial import
thib
parents:
diff changeset
977 return;
223b71206888 Initial import
thib
parents:
diff changeset
978 }
223b71206888 Initial import
thib
parents:
diff changeset
979
223b71206888 Initial import
thib
parents:
diff changeset
980 void Dialog::press_ok(void* pointer, Button* btn) {
223b71206888 Initial import
thib
parents:
diff changeset
981 if (pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
982 Dialog* wid = (Dialog*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
983 wid->status = OK;
223b71206888 Initial import
thib
parents:
diff changeset
984 if (wid->set_func) {
223b71206888 Initial import
thib
parents:
diff changeset
985 (*wid->set_func)(wid->set_pointer, wid);
223b71206888 Initial import
thib
parents:
diff changeset
986 }
223b71206888 Initial import
thib
parents:
diff changeset
987 }
223b71206888 Initial import
thib
parents:
diff changeset
988 }
223b71206888 Initial import
thib
parents:
diff changeset
989 void Dialog::press_cancel(void* pointer, Button* btn) {
223b71206888 Initial import
thib
parents:
diff changeset
990 if (pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
991 Dialog* wid = (Dialog*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
992 wid->status = CANCEL;
223b71206888 Initial import
thib
parents:
diff changeset
993 if (wid->set_func) {
223b71206888 Initial import
thib
parents:
diff changeset
994 (*wid->set_func)(wid->set_pointer, wid);
223b71206888 Initial import
thib
parents:
diff changeset
995 }
223b71206888 Initial import
thib
parents:
diff changeset
996 }
223b71206888 Initial import
thib
parents:
diff changeset
997 }
223b71206888 Initial import
thib
parents:
diff changeset
998
223b71206888 Initial import
thib
parents:
diff changeset
999 void Dialog::DrawBox(Surface* s, const Rect& r) {
223b71206888 Initial import
thib
parents:
diff changeset
1000 DSurfaceFill(s, Rect(r.lx, r.ty, r.rx, r.ty+1), 0x80, 0x50, 0x10);
223b71206888 Initial import
thib
parents:
diff changeset
1001 DSurfaceFill(s, Rect(r.lx, r.ty+1, r.rx, r.ty+2), 0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
1002 DSurfaceFill(s, Rect(r.lx, r.by-2, r.rx, r.by-1), 0x80, 0x50, 0x10);
223b71206888 Initial import
thib
parents:
diff changeset
1003 DSurfaceFill(s, Rect(r.lx, r.by-1, r.rx, r.by), 0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
1004
223b71206888 Initial import
thib
parents:
diff changeset
1005 DSurfaceFill(s, Rect(r.lx, r.ty, r.lx+1, r.by), 0xb0, 0x80, 0x40);
223b71206888 Initial import
thib
parents:
diff changeset
1006 DSurfaceFill(s, Rect(r.lx+1, r.ty+1, r.lx+2, r.by-1), 0x80, 0x50, 0x10);
223b71206888 Initial import
thib
parents:
diff changeset
1007 DSurfaceFill(s, Rect(r.lx+1, r.ty+2, r.lx+2, r.by-2), 0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
1008 DSurfaceFill(s, Rect(r.rx-3, r.ty+2, r.rx-2, r.by-2), 0xb0, 0x80, 0x40);
223b71206888 Initial import
thib
parents:
diff changeset
1009 DSurfaceFill(s, Rect(r.rx-2, r.ty+1, r.rx-1, r.by-1), 0x80, 0x50, 0x10);
223b71206888 Initial import
thib
parents:
diff changeset
1010 DSurfaceFill(s, Rect(r.rx-1, r.ty, r.rx, r.by), 0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
1011 }
223b71206888 Initial import
thib
parents:
diff changeset
1012
223b71206888 Initial import
thib
parents:
diff changeset
1013 AnmTime::AnmTime(Event::Container& container, PicBase* _pic, int _total_time, int _all_count) :
223b71206888 Initial import
thib
parents:
diff changeset
1014 Event::Time(container),
223b71206888 Initial import
thib
parents:
diff changeset
1015 PicAnm(_pic), start_time(0), total_time(_total_time), all_count(_all_count) {
223b71206888 Initial import
thib
parents:
diff changeset
1016 status = FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1017 if (total_time == 0) total_time = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1018 }
223b71206888 Initial import
thib
parents:
diff changeset
1019 AnmTime::AnmTime(Event::Container& container, std::vector<PicBase*> _pic, int _total_time, int _all_count) :
223b71206888 Initial import
thib
parents:
diff changeset
1020 Event::Time(container),
223b71206888 Initial import
thib
parents:
diff changeset
1021 PicAnm(_pic), start_time(0), total_time(_total_time), all_count(_all_count) {
223b71206888 Initial import
thib
parents:
diff changeset
1022 status = FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1023 if (total_time == 0) total_time = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1024 }
223b71206888 Initial import
thib
parents:
diff changeset
1025 void AnmTime::Elapsed(unsigned int current_time) {
223b71206888 Initial import
thib
parents:
diff changeset
1026 if (total_time == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
1027 if (status == FINISHED || current_time == 0) {SetWakeup(current_time+1); return;}
223b71206888 Initial import
thib
parents:
diff changeset
1028 if (start_time == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1029 start_time = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
1030 Start();
223b71206888 Initial import
thib
parents:
diff changeset
1031 }
223b71206888 Initial import
thib
parents:
diff changeset
1032 unsigned int time_elapsed = current_time - start_time;
223b71206888 Initial import
thib
parents:
diff changeset
1033 if (time_elapsed < total_time) {
223b71206888 Initial import
thib
parents:
diff changeset
1034 int count = time_elapsed * all_count / total_time;
223b71206888 Initial import
thib
parents:
diff changeset
1035 Exec(count);
223b71206888 Initial import
thib
parents:
diff changeset
1036 int next_time = start_time + (count+1) * total_time / all_count;
223b71206888 Initial import
thib
parents:
diff changeset
1037 SetWakeup(next_time);
223b71206888 Initial import
thib
parents:
diff changeset
1038 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1039 Exec(all_count);
223b71206888 Initial import
thib
parents:
diff changeset
1040 Finish();
223b71206888 Initial import
thib
parents:
diff changeset
1041 status = FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1042 }
223b71206888 Initial import
thib
parents:
diff changeset
1043 return;
223b71206888 Initial import
thib
parents:
diff changeset
1044 }
223b71206888 Initial import
thib
parents:
diff changeset
1045 void AnmTime::Abort(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1046 if (status == FINISHED) return;
223b71206888 Initial import
thib
parents:
diff changeset
1047 if (start_time == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1048 Start();
223b71206888 Initial import
thib
parents:
diff changeset
1049 Exec(all_count);
223b71206888 Initial import
thib
parents:
diff changeset
1050 }
223b71206888 Initial import
thib
parents:
diff changeset
1051 if (total_time) {
223b71206888 Initial import
thib
parents:
diff changeset
1052 Finish();
223b71206888 Initial import
thib
parents:
diff changeset
1053 }
223b71206888 Initial import
thib
parents:
diff changeset
1054 status = FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1055 }
223b71206888 Initial import
thib
parents:
diff changeset
1056 bool AnmTime::IsEnd(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1057 return status == FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1058 }
223b71206888 Initial import
thib
parents:
diff changeset
1059 AnmMove::AnmMove(Event::Container& container, PicBase* _pic, const Rect& _to, int total_time) :
223b71206888 Initial import
thib
parents:
diff changeset
1060 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1061 from(0,0), to(_to) {
223b71206888 Initial import
thib
parents:
diff changeset
1062 from.lx = _pic->PosX();
223b71206888 Initial import
thib
parents:
diff changeset
1063 from.ty = _pic->PosY();
223b71206888 Initial import
thib
parents:
diff changeset
1064 from.rx = from.lx + _pic->Width();
223b71206888 Initial import
thib
parents:
diff changeset
1065 from.by = from.ty + _pic->Height();
223b71206888 Initial import
thib
parents:
diff changeset
1066
223b71206888 Initial import
thib
parents:
diff changeset
1067 int dx = to.lx - from.lx;
223b71206888 Initial import
thib
parents:
diff changeset
1068 int dy = to.ty - from.ty;
223b71206888 Initial import
thib
parents:
diff changeset
1069 if (dx < 0) dx = -dx;
223b71206888 Initial import
thib
parents:
diff changeset
1070 if (dy < 0) dy = -dy;
223b71206888 Initial import
thib
parents:
diff changeset
1071 if (dx < dy) dx = dy;
223b71206888 Initial import
thib
parents:
diff changeset
1072 if (dx == 0) dx = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1073 SetAllCount(dx);
223b71206888 Initial import
thib
parents:
diff changeset
1074 }
223b71206888 Initial import
thib
parents:
diff changeset
1075 void AnmMove::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1076 Rect r(from);
223b71206888 Initial import
thib
parents:
diff changeset
1077 int dx = to.lx - from.lx;
223b71206888 Initial import
thib
parents:
diff changeset
1078 int dy = to.ty - from.ty;
223b71206888 Initial import
thib
parents:
diff changeset
1079 r.rmove(dx*count/all_count, dy*count/all_count);
223b71206888 Initial import
thib
parents:
diff changeset
1080 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1081 for (it=pic.begin(); it!=pic.end(); it++) (*it)->Move(r.lx, r.ty);
223b71206888 Initial import
thib
parents:
diff changeset
1082 }
223b71206888 Initial import
thib
parents:
diff changeset
1083 AnmAlpha::AnmAlpha(Event::Container& container, PicBase* _pic, int alpha_from, int alpha_to, int total_time) :
223b71206888 Initial import
thib
parents:
diff changeset
1084 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1085 from(alpha_from), to(alpha_to), alpha_r(0,0,1,1) {
223b71206888 Initial import
thib
parents:
diff changeset
1086 if (from < 0) from = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1087 if (from >= ALPHA_MAX) from = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1088 if (to < 0) to = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1089 if (to >= ALPHA_MAX) to = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1090 int c = from - to;
223b71206888 Initial import
thib
parents:
diff changeset
1091 if (c < 0) c = -c;
223b71206888 Initial import
thib
parents:
diff changeset
1092 if (c == 0) c = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1093 SetAllCount(c);
223b71206888 Initial import
thib
parents:
diff changeset
1094 }
223b71206888 Initial import
thib
parents:
diff changeset
1095 AnmAlpha::AnmAlpha(Event::Container& container, std::vector<PicBase*> _pic, int alpha_from, int alpha_to, int total_time) :
223b71206888 Initial import
thib
parents:
diff changeset
1096 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1097 from(alpha_from), to(alpha_to), alpha_r(0,0,1,1) {
223b71206888 Initial import
thib
parents:
diff changeset
1098 if (from < 0) from = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1099 if (from >= ALPHA_MAX) from = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1100 if (to < 0) to = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1101 if (to >= ALPHA_MAX) to = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1102 int c = from - to;
223b71206888 Initial import
thib
parents:
diff changeset
1103 if (c < 0) c = -c;
223b71206888 Initial import
thib
parents:
diff changeset
1104 if (c == 0) c = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1105 SetAllCount(c);
223b71206888 Initial import
thib
parents:
diff changeset
1106 }
223b71206888 Initial import
thib
parents:
diff changeset
1107 void AnmAlpha::Start(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1108 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1109 for (it=pic.begin(); it!=pic.end(); it++) (*it)->show();
223b71206888 Initial import
thib
parents:
diff changeset
1110 }
223b71206888 Initial import
thib
parents:
diff changeset
1111 void AnmAlpha::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1112 alpha = (from * (all_count-count) + (to-from) * count) / all_count;
223b71206888 Initial import
thib
parents:
diff changeset
1113 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1114 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(&alpha, alpha_r);
223b71206888 Initial import
thib
parents:
diff changeset
1115 }
223b71206888 Initial import
thib
parents:
diff changeset
1116 void AnmAlpha::Finish(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1117 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1118 for (it=pic.begin(); it!=pic.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1119 if (to == 0) (*it)->hide();
223b71206888 Initial import
thib
parents:
diff changeset
1120 else if (to != ALPHA_MAX) fprintf(stderr,"Warning in AnmAlpha::Finish: alpha value suddenly changed.\n");
223b71206888 Initial import
thib
parents:
diff changeset
1121 (*it)->SetSurfaceAlpha(0,Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
1122 }
223b71206888 Initial import
thib
parents:
diff changeset
1123 }
223b71206888 Initial import
thib
parents:
diff changeset
1124 AnmAlphaMove::AnmAlphaMove(Event::Container& container, PicBase* _pic) :
223b71206888 Initial import
thib
parents:
diff changeset
1125 AnmTime(container, _pic, 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1126 }
223b71206888 Initial import
thib
parents:
diff changeset
1127 void AnmAlphaMove::SetPtn(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1128 int total = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1129 std::vector<Ptn>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1130 for (it=ptns.begin(); it!=ptns.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1131 if (total < it->next_tick) total = it->next_tick;
223b71206888 Initial import
thib
parents:
diff changeset
1132 }
223b71206888 Initial import
thib
parents:
diff changeset
1133 SetAllCount(total);
223b71206888 Initial import
thib
parents:
diff changeset
1134 SetTotalTime(total);
223b71206888 Initial import
thib
parents:
diff changeset
1135 cur_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1136 }
223b71206888 Initial import
thib
parents:
diff changeset
1137 void AnmAlphaMove::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1138 if (ptns.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
1139 if (cur_count != 0 && ptns[cur_count].next_tick > count) return;
223b71206888 Initial import
thib
parents:
diff changeset
1140 if (cur_count >= ptns.size()) return;
223b71206888 Initial import
thib
parents:
diff changeset
1141 // ¼¡¤Î¥Ñ¥¿¡¼¥ó¤òõ¤¹
223b71206888 Initial import
thib
parents:
diff changeset
1142 // count <= it->next_tick ¤Ê¤ë¾ò·ï¤òËþ¤¿¤¹ºÇ¸å¤Î it ¤òõ¤¹
223b71206888 Initial import
thib
parents:
diff changeset
1143 std::vector<Ptn>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1144 for (it=ptns.begin()+cur_count; it != ptns.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1145 if (count <= it->next_tick) break;
223b71206888 Initial import
thib
parents:
diff changeset
1146 }
223b71206888 Initial import
thib
parents:
diff changeset
1147 if (it == ptns.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
1148 fprintf(stderr,"end\n");
223b71206888 Initial import
thib
parents:
diff changeset
1149 it = ptns.end() - 1;
223b71206888 Initial import
thib
parents:
diff changeset
1150 }
223b71206888 Initial import
thib
parents:
diff changeset
1151 cur_count = it - ptns.begin();
223b71206888 Initial import
thib
parents:
diff changeset
1152
223b71206888 Initial import
thib
parents:
diff changeset
1153 iterator p;
223b71206888 Initial import
thib
parents:
diff changeset
1154 for (p=pic.begin(); p!=pic.end(); p++) {
223b71206888 Initial import
thib
parents:
diff changeset
1155 // move
223b71206888 Initial import
thib
parents:
diff changeset
1156 (*p)->Move(it->pos.lx, it->pos.ty);
223b71206888 Initial import
thib
parents:
diff changeset
1157 (*p)->SetSurfacePos(it->surface_pos.lx, it->surface_pos.ty);
223b71206888 Initial import
thib
parents:
diff changeset
1158 // alpha set
223b71206888 Initial import
thib
parents:
diff changeset
1159 if (it->alpha == 0) (*p)->hide();
223b71206888 Initial import
thib
parents:
diff changeset
1160 else if (it->alpha == ALPHA_MAX) { (*p)->show(); (*p)->SetSurfaceAlpha(0, Rect(0,0)); }
223b71206888 Initial import
thib
parents:
diff changeset
1161 else { (*p)->show(); (*p)->SetSurfaceAlpha( &(it->alpha), Rect(0,0,1,1)); }
223b71206888 Initial import
thib
parents:
diff changeset
1162 }
223b71206888 Initial import
thib
parents:
diff changeset
1163 }
223b71206888 Initial import
thib
parents:
diff changeset
1164 void AnmAlphaMove::Finish(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1165 if (ptns.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
1166 if (cur_count >= ptns.size() - 1) return;
223b71206888 Initial import
thib
parents:
diff changeset
1167 cur_count = ptns.size() - 1;
223b71206888 Initial import
thib
parents:
diff changeset
1168 Exec(ptns[cur_count].next_tick); // ºÇ¸å¤Î pattern ¤Î¾õÂ֤ˤ¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1169 }
223b71206888 Initial import
thib
parents:
diff changeset
1170
223b71206888 Initial import
thib
parents:
diff changeset
1171 AnmPtnSolid::AnmPtnSolid(Event::Container& container, PicBase* _pic, const unsigned char* _ptn, const Rect& _alpha_r, int total_time) :
223b71206888 Initial import
thib
parents:
diff changeset
1172 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1173 ptn(_ptn), alpha_r(_alpha_r)
223b71206888 Initial import
thib
parents:
diff changeset
1174 {
223b71206888 Initial import
thib
parents:
diff changeset
1175 ptn_len = alpha_r.width() * alpha_r.height();
223b71206888 Initial import
thib
parents:
diff changeset
1176 alpha = new unsigned char[ptn_len];
223b71206888 Initial import
thib
parents:
diff changeset
1177 int max_a = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1178 for (int i=0; i<ptn_len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1179 if (ptn[i] > max_a) max_a = ptn[i];
223b71206888 Initial import
thib
parents:
diff changeset
1180 }
223b71206888 Initial import
thib
parents:
diff changeset
1181 if (max_a == 0) max_a = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1182 SetAllCount(max_a);
223b71206888 Initial import
thib
parents:
diff changeset
1183 }
223b71206888 Initial import
thib
parents:
diff changeset
1184
223b71206888 Initial import
thib
parents:
diff changeset
1185 AnmPtnAlpha::AnmPtnAlpha(Event::Container& container, PicBase* _pic, const unsigned char* _ptn, const Rect& _alpha_r, int _band_width, int total_time) :
223b71206888 Initial import
thib
parents:
diff changeset
1186 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1187 ptn(_ptn), band(_band_width), alpha_r(_alpha_r)
223b71206888 Initial import
thib
parents:
diff changeset
1188 {
223b71206888 Initial import
thib
parents:
diff changeset
1189 ptn_len = alpha_r.width() * alpha_r.height();
223b71206888 Initial import
thib
parents:
diff changeset
1190 alpha = new unsigned char[ptn_len];
223b71206888 Initial import
thib
parents:
diff changeset
1191 if (band <= 0) band = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1192 SetAllCount(ALPHA_MAX+band);
223b71206888 Initial import
thib
parents:
diff changeset
1193 }
223b71206888 Initial import
thib
parents:
diff changeset
1194
223b71206888 Initial import
thib
parents:
diff changeset
1195 void AnmPtnSolid::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1196 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1197 for (i=0; i<ptn_len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1198 if (ptn[i] <= count) alpha[i] = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1199 else alpha[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1200 }
223b71206888 Initial import
thib
parents:
diff changeset
1201 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1202 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(alpha, alpha_r);
223b71206888 Initial import
thib
parents:
diff changeset
1203 }
223b71206888 Initial import
thib
parents:
diff changeset
1204 void AnmPtnAlpha::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1205 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1206 int ptn_zero = count;
223b71206888 Initial import
thib
parents:
diff changeset
1207 int ptn_max = count - band;
223b71206888 Initial import
thib
parents:
diff changeset
1208 for (i=0; i<ptn_len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1209 if (ptn[i] >= ptn_zero) alpha[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1210 else if (ptn[i] < ptn_max) alpha[i] = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1211 else alpha[i] = (ptn_zero-ptn[i])*ALPHA_MAX/band;
223b71206888 Initial import
thib
parents:
diff changeset
1212 }
223b71206888 Initial import
thib
parents:
diff changeset
1213 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1214 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(alpha, alpha_r);
223b71206888 Initial import
thib
parents:
diff changeset
1215 }
223b71206888 Initial import
thib
parents:
diff changeset
1216
223b71206888 Initial import
thib
parents:
diff changeset
1217 void AnmPtnSolid::Start(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1218 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1219 for (it=pic.begin(); it!=pic.end(); it++) (*it)->show();
223b71206888 Initial import
thib
parents:
diff changeset
1220 }
223b71206888 Initial import
thib
parents:
diff changeset
1221 void AnmPtnSolid::Finish(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1222 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1223 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(0, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
1224 }
223b71206888 Initial import
thib
parents:
diff changeset
1225 void AnmPtnAlpha::Start(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1226 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1227 for (it=pic.begin(); it!=pic.end(); it++) (*it)->show();
223b71206888 Initial import
thib
parents:
diff changeset
1228 }
223b71206888 Initial import
thib
parents:
diff changeset
1229 void AnmPtnAlpha::Finish(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1230 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1231 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(0, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
1232 }
223b71206888 Initial import
thib
parents:
diff changeset
1233
223b71206888 Initial import
thib
parents:
diff changeset
1234 /*
223b71206888 Initial import
thib
parents:
diff changeset
1235
223b71206888 Initial import
thib
parents:
diff changeset
1236 Widget ¤Î¼ïÎà
223b71206888 Initial import
thib
parents:
diff changeset
1237 Mouse: ¥Þ¥¦¥¹°ÌÃÖ¤ËϢư¤¹¤ë¡£Surface ¤È origin ¤¬É¬¿Ü
223b71206888 Initial import
thib
parents:
diff changeset
1238 Panel : ¤Ê¤Ë¤â¸ºß¤·¤Ê¤¤¤È¤³¤í¤ËÄ¥¤ê¤Ä¤±¤Æ¤¤¤¯
223b71206888 Initial import
thib
parents:
diff changeset
1239 ÇØ·ÊÄ¥¤ê¤Ä¤±¤â²Äǽ
223b71206888 Initial import
thib
parents:
diff changeset
1240 ButtonPanel : ̵¸ú²½²Äǽ¡£Group ¤Î Button ¤¬¥«¡¼¥½¥ë¤ËÆþ¤Ã¤¿¤é¡¢Á´Button / Label ¤¬¡Ö¥«¡¼¥½¥ë²¼¡×¾õÂ֤ˤʤë
223b71206888 Initial import
thib
parents:
diff changeset
1241 Ʊ°ìÊÑ¿ô¤ò°·¤¦¥Ü¥¿¥ó¤Ï¸¶Â§¡¢Æ±°ìButtonPanel ¤Î²¼¤ËÆþ¤ë¤³¤È¡ÊƱ´ü¤¹¤ë¡£¹â®²½²Äǽ¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
1242 ¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¡¢¥Ü¥¿¥ó¤Î GlobalVariable ¥Õ¥é¥°¤òΩ¤Æ¤ëɬÍפ¬¤¢¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1243 ÇطʼïÎࡧWindow
223b71206888 Initial import
thib
parents:
diff changeset
1244 ÆâÉô¤ÎÆ©ÌÀÅÙ¤ÈÏÈ·Á¤òÊÌ¡¹¤Ë»ØÄê²Äǽ¡£ÏÈ·Á¤ÏÁ´ÏÈ¡¢ÉôʬÏȤɤÁ¤é¤Î·Á¤Ç¤â²Äǽ
223b71206888 Initial import
thib
parents:
diff changeset
1245 ¡ÊÉôʬÏȤʤ顢ÆâÉôŪ¤Ë¤Ï¾åÏÈ¡¢²¼ÏÈ¡¢º¸±¦ÏȤÈÊÌ Surface ¤Ç´ÉÍý¤¹¤ë¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
1246 DragButton
223b71206888 Initial import
thib
parents:
diff changeset
1247 Panel Á´ÂΤò¥É¥é¥Ã¥°¤·¡¢¾ì½êÊѹ¹¤Ç¤­¤ë¥Ü¥¿¥ó¡£
223b71206888 Initial import
thib
parents:
diff changeset
1248 Button: ̵¸ú²½¡äÄ̾ï¡ä¥«¡¼¥½¥ë²¼¡ä¥Ü¥¿¥ó²¡²¼ ¤Îpicture / animation
223b71206888 Initial import
thib
parents:
diff changeset
1249 Toggle Button ¤Ë¤Ç¤­¤ë(Group²½¤¹¤ì¤ÐRadioButton¤Ë¤â¤Ç¤­¤ë)
223b71206888 Initial import
thib
parents:
diff changeset
1250 Label : ̵¸ú²½¡äÄ̾ï¡ä¥«¡¼¥½¥ë²¼¡¡¤Îanimation
223b71206888 Initial import
thib
parents:
diff changeset
1251 animation ¤Ï
223b71206888 Initial import
thib
parents:
diff changeset
1252 ¡¦¾å¤Ø¤ÎÊѲ½
223b71206888 Initial import
thib
parents:
diff changeset
1253 ¡¦²¼¤Ø¤ÎÊѲ½
223b71206888 Initial import
thib
parents:
diff changeset
1254 ¡¦¾ï»þÊÑ·Á
223b71206888 Initial import
thib
parents:
diff changeset
1255 ¤Î£³¤Ä¤Î·Á¼°¤ò¤â¤Ä¡£
223b71206888 Initial import
thib
parents:
diff changeset
1256 ·Á¼°¤Ï
223b71206888 Initial import
thib
parents:
diff changeset
1257 ¡¦x / y increment ¤Ë¤è¤ë¡ÊÁ´Îΰè¤È x,y ¤ÎÂ礭¤µ¤ò»ØÄꤹ¤ë¤Èº¸¾å¤«¤é±¦¾å¡¢º¸²¼¡¢¤È¤¤¤¦Êý¤Ø¾¡¼ê¤ËÎΰè¤òÊѹ¹¤·¤Æ¤¤¤¯¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
1258 ¡¦¿§ÊѲ½¡ÊÌÀÅÙÊѲ½¡Ë¡£¿§¥Æ¡¼¥Ö¥ë¤ò»ØÄꤹ¤ë¡£Surface ¤Ï alpha ¤Î¤ß¤È¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1259 ¤É¤Á¤é¤â¡¢°ì¤Ä¤Î¥é¥Ù¥ë¤Ë»È¤¦»þ´Ö¤ÎŤµ¤ò»ØÄꤹ¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1260 ¡¦callback ¤Ë¤è¤ë¡£»ØÄꤷ¤¿°ìÄê»þ´Ö°Ê¾å¤¬Î©¤Ä¤ÈCallBack ¤¬¸Æ¤Ó½Ð¤µ¤ì¡¢¿·¤¿¤ÊSurface , origin ¤ò»ØÄꤹ¤ë¡£
223b71206888 Initial import
thib
parents:
diff changeset
1261
223b71206888 Initial import
thib
parents:
diff changeset
1262 ¡¦Surface ¤Ï
223b71206888 Initial import
thib
parents:
diff changeset
1263 ÉáÄ̤βèÁü
223b71206888 Initial import
thib
parents:
diff changeset
1264 ʸ»úÎó¡ÊŬÅö¤Ë²¾ÁÛ²½¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
1265 ²èÁü¿ôÃÍÎó
223b71206888 Initial import
thib
parents:
diff changeset
1266 ¤Î¤¤¤º¤ì¤«
223b71206888 Initial import
thib
parents:
diff changeset
1267 Cursor
223b71206888 Initial import
thib
parents:
diff changeset
1268 ¥ê¥¿¡¼¥ó¥«¡¼¥½¥ë¡£Label ¤Î°ì¼ï¡£
223b71206888 Initial import
thib
parents:
diff changeset
1269 Number
223b71206888 Initial import
thib
parents:
diff changeset
1270 ¿ô»ú¤òɽ¼¨¤¹¤ë¡£¥Õ¥©¥ó¥È¤ÎÂ礭¤µ¡¢¤â¤·¤¯¤Ï²èÁü¿ôÃÍÎó
223b71206888 Initial import
thib
parents:
diff changeset
1271 Text
223b71206888 Initial import
thib
parents:
diff changeset
1272 ¥Æ¥­¥¹¥È¤òɽ¼¨¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1273 ¥Ñ¥Í¥ë¤ÎÂ礭¤µ¤À¤±»ØÄꤹ¤ë¤ÈŬÅö¤Ë¤ä¤Ã¤Æ¤¯¤ì¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1274 ¥«¡¼¥½¥ë¤Î°ÌÃÖ¡Êʸ»ú¤Î¼¡/ºÇ½ª¡Ë¤ò»ØÄꤹ¤ë¤³¤È
223b71206888 Initial import
thib
parents:
diff changeset
1275 µ¡Ç½¡§Ê¸»úÁ÷¤ê®ÅÙÀßÄê¡¢ÆɤßÈô¤Ð¤·ÀßÄê¡Ê¾ï¤ËºÇ¹â®¤Ç²¡¤·¤Ã¤Ñ¤Ê¤·¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
1276 ProgressBar ¤Ê¤É
223b71206888 Initial import
thib
parents:
diff changeset
1277 ¥Ð¡¼¤ÎŤµ¡¢¤¢¤ë¤¤¤Ï°ÌÃÖ¤ÇÊÑ¿ô¤ÎÂ礭¤µ¤ò¼¨¤¹¡£
223b71206888 Initial import
thib
parents:
diff changeset
1278 Tick, Max ¤ò»ØÄê¡¢ÊÑ¿ô¤ÎÊѲ½¤Ë¤ÏŬÅö¤ËÂбþ¤Ç¤­¤ë¤è¤¦¤Ë¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1279 ¥Ð¡¼¤ÎÊý¸þ¤È¤·¤Æ½Ä/²£¡£Surface ¤Ï·«¤êÊÖ¤·¤Ç»È¤¦¡Ê®Åپ塢32pixel ¤¯¤é¤¤¤¢¤Ã¤¿¤Û¤¦¤¬¤¤¤¤¤«¤â¡©¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
1280 ¥Ð¡¼¤ÎÂå¤ï¤ê¤Ë¥Ü¥¿¥ó¤â»È¤¨¤ë¡£Surface »ØÄê¤Î¥á¥½¥Ã¥É¤¬°ã¤¦¤À¤±¡£
223b71206888 Initial import
thib
parents:
diff changeset
1281 ¥ª¥×¥·¥ç¥ó¡§¥Ð¡¼¤Î¤É¤³¤«¤ò¥¯¥ê¥Ã¥¯¤µ¤ì¤¿¤È¤­¡¢¤½¤³¤Ë°ÜÆ°¤¹¤ë¤«¤½¤³¤Ë¸þ¤«¤Ã¤Æ°ÜÆ°¤¹¤ë¤«
223b71206888 Initial import
thib
parents:
diff changeset
1282 ¥ª¥×¥·¥ç¥ó¡©¡§Ìð°õ¥Ü¥¿¥ó¡Ê¤¤¤é¤Ê¤¤¤«¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
1283 ScrollBar
223b71206888 Initial import
thib
parents:
diff changeset
1284 ²£/½Ä¡£Panel ¤ÈϢư¤¹¤ë(ÀìÍÑ, ProgressBar ¤Î°ì¼ï¤È¤·¤Æ¼ÂÁõ)
223b71206888 Initial import
thib
parents:
diff changeset
1285 (Panel ¦¤Ç¡Ö¸«¤¨¤Ê¤¤Éôʬ¤Ïdelete, ¸«¤¨¤ëÉôʬ¤Ï¼«Æ°¤ÇºîÀ®¡×µ¡Ç½¤ò¤Ä¤±¤ë¡©¡§¥Ð¥Ã¥¯¥í¥°¡Ë
223b71206888 Initial import
thib
parents:
diff changeset
1286
223b71206888 Initial import
thib
parents:
diff changeset
1287
223b71206888 Initial import
thib
parents:
diff changeset
1288
223b71206888 Initial import
thib
parents:
diff changeset
1289 ¥á¥Ë¥å¡¼¤Î½Ð¤·Êý
223b71206888 Initial import
thib
parents:
diff changeset
1290 ±¦¥¯¥ê¥Ã¥¯
223b71206888 Initial import
thib
parents:
diff changeset
1291 ¥Ü¥¿¥ó¤ò²¡¤¹
223b71206888 Initial import
thib
parents:
diff changeset
1292 ¾å¤ÎÊý¡¢±¦¤ÎÊý¤Ê¤ÉÎΰè¤Ë¹Ô¤¯¤È¥Ì¤Ã¤È½Ð¤Æ¤¯¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1293 ¥á¥Ë¥å¡¼¥â¡¼¥ÉÆâ
223b71206888 Initial import
thib
parents:
diff changeset
1294 ¥Ü¥¿¥ó¤ò²¡¤·¤Æ½ªÎ»
223b71206888 Initial import
thib
parents:
diff changeset
1295 ¥Þ¥Ã¥×¤òºî¤Ã¤Æ¤ª¤­¡¢³Æ¥á¥Ë¥å¡¼¤Ë̾Á°¤ò³ä¤ê¿¶¤ë¤ÈÆ󼡸µ¤Ë¹­¤¬¤Ã¤¿¥á¥Ë¥å¡¼¤Ë¤Ê¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1296 ̾Á°¤ò³ä¤ê¿¶¤ë¤È¾å¤Ë̾Á°¥ê¥¹¥È¤¬¤Ç¤Æ¤¯¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1297 ̾Á°¤ò³ä¤ê¿¶¤ë¤È²£¤Ë̾Á°¥ê¥¹¥È¤¬½Ð¤Æ¤¯¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1298
223b71206888 Initial import
thib
parents:
diff changeset
1299 */
223b71206888 Initial import
thib
parents:
diff changeset
1300 // }