annotate window/widget.cc @ 7:fa8511a21d05

Fixes somes memory leaks
author thib
date Tue, 05 Aug 2008 10:06:04 +0000
parents 223b71206888
children 8da1d92ac8f8
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;
223b71206888 Initial import
thib
parents:
diff changeset
40 static char* wdefault_font_orig = "times.ttf;msgothic.ttc";
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) {
223b71206888 Initial import
thib
parents:
diff changeset
66 if (size_to_layout.find(text_size) == size_to_layout.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
67 size_to_layout[text_size] = new XKFont::HorizLayout(wdefault_font.c_str(), text_size);
223b71206888 Initial import
thib
parents:
diff changeset
68 }
223b71206888 Initial import
thib
parents:
diff changeset
69 return size_to_layout[text_size];
223b71206888 Initial import
thib
parents:
diff changeset
70 }
223b71206888 Initial import
thib
parents:
diff changeset
71
223b71206888 Initial import
thib
parents:
diff changeset
72 void PicWidget::activate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
73 }
223b71206888 Initial import
thib
parents:
diff changeset
74 void PicWidget::deactivate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
75 }
223b71206888 Initial import
thib
parents:
diff changeset
76 void PicWidget::SetRegion(const Rect& apos) {
223b71206888 Initial import
thib
parents:
diff changeset
77 }
223b71206888 Initial import
thib
parents:
diff changeset
78 void PicWidget::show(void) {
223b71206888 Initial import
thib
parents:
diff changeset
79 Pic()->show();
223b71206888 Initial import
thib
parents:
diff changeset
80 }
223b71206888 Initial import
thib
parents:
diff changeset
81 void PicWidget::hide(void) {
223b71206888 Initial import
thib
parents:
diff changeset
82 Pic()->hide();
223b71206888 Initial import
thib
parents:
diff changeset
83 }
223b71206888 Initial import
thib
parents:
diff changeset
84 void PicWidget::show_all(void) {
223b71206888 Initial import
thib
parents:
diff changeset
85 Pic()->show_all();
223b71206888 Initial import
thib
parents:
diff changeset
86 }
223b71206888 Initial import
thib
parents:
diff changeset
87
223b71206888 Initial import
thib
parents:
diff changeset
88 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
89 Time(container) {
223b71206888 Initial import
thib
parents:
diff changeset
90 interval = _interval;
223b71206888 Initial import
thib
parents:
diff changeset
91 if (interval < 0) interval = 100;
223b71206888 Initial import
thib
parents:
diff changeset
92 nptn = _nptn;
223b71206888 Initial import
thib
parents:
diff changeset
93 if (nptn < 0) nptn = 1;
223b71206888 Initial import
thib
parents:
diff changeset
94 count = 0; old_time = 0;
223b71206888 Initial import
thib
parents:
diff changeset
95
223b71206888 Initial import
thib
parents:
diff changeset
96 x = _sx; y = _sy; dx = _sdx; dy = _sdy;
223b71206888 Initial import
thib
parents:
diff changeset
97 SetPic(parent->create_leaf(r, PicBase::CACHE_BACK));
223b71206888 Initial import
thib
parents:
diff changeset
98 Pic()->SetSurface(s, _sx, _sy);
223b71206888 Initial import
thib
parents:
diff changeset
99 };
223b71206888 Initial import
thib
parents:
diff changeset
100 void TimeCursor::Elapsed(unsigned int current_time) {
223b71206888 Initial import
thib
parents:
diff changeset
101 int move = (current_time-old_time)/interval;
223b71206888 Initial import
thib
parents:
diff changeset
102 if (move) {
223b71206888 Initial import
thib
parents:
diff changeset
103 old_time += move*interval;
223b71206888 Initial import
thib
parents:
diff changeset
104 count += move;
223b71206888 Initial import
thib
parents:
diff changeset
105 count %= nptn;
223b71206888 Initial import
thib
parents:
diff changeset
106 Pic()->SetSurfacePos(x + count*dx, y + count*dy);
223b71206888 Initial import
thib
parents:
diff changeset
107 }
223b71206888 Initial import
thib
parents:
diff changeset
108 if (current_time > old_time+interval) SetWakeup(current_time);
223b71206888 Initial import
thib
parents:
diff changeset
109 else SetWakeup(old_time+interval);
223b71206888 Initial import
thib
parents:
diff changeset
110 }
223b71206888 Initial import
thib
parents:
diff changeset
111
223b71206888 Initial import
thib
parents:
diff changeset
112 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
113 Event::Video(_container), container(_container) {
223b71206888 Initial import
thib
parents:
diff changeset
114 int sx, sy;
223b71206888 Initial import
thib
parents:
diff changeset
115 _container.MousePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
116 SetPic(parent->create_leaf(Rect(sx, sy, sx+w, sy+h), 0));
223b71206888 Initial import
thib
parents:
diff changeset
117 Pic()->SetSurface(s, x, y);
223b71206888 Initial import
thib
parents:
diff changeset
118 x = 0; y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
119 container.RegisterGlobalMotionFunc(&Motionfunc, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
120 }
223b71206888 Initial import
thib
parents:
diff changeset
121 MouseCursor::MouseCursor(Event::Container& _container, PicContainer* parent, Surface* s, int x, int y, int w, int h) :
223b71206888 Initial import
thib
parents:
diff changeset
122 Event::Video(_container), container(_container) {
223b71206888 Initial import
thib
parents:
diff changeset
123 int sx, sy;
223b71206888 Initial import
thib
parents:
diff changeset
124 _container.MousePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
125 SetPic(parent->create_leaf(Rect(sx, sy, sx+w, sy+h), 0));
223b71206888 Initial import
thib
parents:
diff changeset
126 Pic()->SetSurface(s, x, y);
223b71206888 Initial import
thib
parents:
diff changeset
127 x = 0; y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
128 container.RegisterGlobalMotionFunc(&Motionfunc, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
129 }
223b71206888 Initial import
thib
parents:
diff changeset
130
223b71206888 Initial import
thib
parents:
diff changeset
131 MouseCursor::~MouseCursor() {
223b71206888 Initial import
thib
parents:
diff changeset
132 container.DeleteGlobalMotionFunc(&Motionfunc, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
133 }
223b71206888 Initial import
thib
parents:
diff changeset
134
223b71206888 Initial import
thib
parents:
diff changeset
135 bool MouseCursor::Motionfunc(int x, int y, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
136 MouseCursor* _this = (MouseCursor*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
137 // 左上がカーソルポイントの場合
223b71206888 Initial import
thib
parents:
diff changeset
138 // _this->Pic()->Move(x,y);
223b71206888 Initial import
thib
parents:
diff changeset
139 // 左下がカーソルポイントの場合
223b71206888 Initial import
thib
parents:
diff changeset
140 _this->Pic()->Move(x,y-_this->Pic()->Height());
223b71206888 Initial import
thib
parents:
diff changeset
141 return true;
223b71206888 Initial import
thib
parents:
diff changeset
142 }
223b71206888 Initial import
thib
parents:
diff changeset
143
223b71206888 Initial import
thib
parents:
diff changeset
144 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
145 SetPic(parent->create_leaf(r, 0));
223b71206888 Initial import
thib
parents:
diff changeset
146 Pic()->SetSurface(s, _sx, _sy);
223b71206888 Initial import
thib
parents:
diff changeset
147 show();
223b71206888 Initial import
thib
parents:
diff changeset
148 is_in = false;
223b71206888 Initial import
thib
parents:
diff changeset
149 is_toggled = false;
223b71206888 Initial import
thib
parents:
diff changeset
150 press_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
151 press_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
152 drag_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
153 drag_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
154 is_toggle_switch = false;
223b71206888 Initial import
thib
parents:
diff changeset
155 }
223b71206888 Initial import
thib
parents:
diff changeset
156 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
157 SetPic(parent->create_leaf(r, 0));
223b71206888 Initial import
thib
parents:
diff changeset
158 Pic()->SetSurface(s, _sx, _sy);
223b71206888 Initial import
thib
parents:
diff changeset
159 show();
223b71206888 Initial import
thib
parents:
diff changeset
160 is_in = false;
223b71206888 Initial import
thib
parents:
diff changeset
161 is_toggled = false;
223b71206888 Initial import
thib
parents:
diff changeset
162 press_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
163 press_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
164 drag_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
165 drag_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
166 is_toggle_switch = false;
223b71206888 Initial import
thib
parents:
diff changeset
167 }
223b71206888 Initial import
thib
parents:
diff changeset
168 Button::~Button() {
223b71206888 Initial import
thib
parents:
diff changeset
169 }
223b71206888 Initial import
thib
parents:
diff changeset
170 void Button::In(void) {
223b71206888 Initial import
thib
parents:
diff changeset
171 is_in = true;
223b71206888 Initial import
thib
parents:
diff changeset
172 if (nptn > 1)
223b71206888 Initial import
thib
parents:
diff changeset
173 if (! is_toggled)
223b71206888 Initial import
thib
parents:
diff changeset
174 Pic()->SetSurfacePos(sx+sdx, sy+sdy);
223b71206888 Initial import
thib
parents:
diff changeset
175 }
223b71206888 Initial import
thib
parents:
diff changeset
176 void Button::Out(void) {
223b71206888 Initial import
thib
parents:
diff changeset
177 is_in = false;
223b71206888 Initial import
thib
parents:
diff changeset
178 if (!is_toggled)
223b71206888 Initial import
thib
parents:
diff changeset
179 Pic()->SetSurfacePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
180 }
223b71206888 Initial import
thib
parents:
diff changeset
181 void Button::Toggle(bool new_toggle) {
223b71206888 Initial import
thib
parents:
diff changeset
182 if (is_toggled == new_toggle) {
223b71206888 Initial import
thib
parents:
diff changeset
183 return;
223b71206888 Initial import
thib
parents:
diff changeset
184 }
223b71206888 Initial import
thib
parents:
diff changeset
185 is_toggled = new_toggle;
223b71206888 Initial import
thib
parents:
diff changeset
186 // if (is_in) return; // is_in に関わらずウィジットの表示を変更することにする
223b71206888 Initial import
thib
parents:
diff changeset
187 if (is_toggled) {
223b71206888 Initial import
thib
parents:
diff changeset
188 if (nptn > 2)
223b71206888 Initial import
thib
parents:
diff changeset
189 Pic()->SetSurfacePos(sx+sdx*2, sy+sdy*2);
223b71206888 Initial import
thib
parents:
diff changeset
190 else if (nptn > 1)
223b71206888 Initial import
thib
parents:
diff changeset
191 Pic()->SetSurfacePos(sx+sdx, sy+sdy);
223b71206888 Initial import
thib
parents:
diff changeset
192 else
223b71206888 Initial import
thib
parents:
diff changeset
193 Pic()->SetSurfacePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
194 } else {
223b71206888 Initial import
thib
parents:
diff changeset
195 Pic()->SetSurfacePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
196 }
223b71206888 Initial import
thib
parents:
diff changeset
197 }
223b71206888 Initial import
thib
parents:
diff changeset
198 void Button::Press(void) {
223b71206888 Initial import
thib
parents:
diff changeset
199 is_in = true;
223b71206888 Initial import
thib
parents:
diff changeset
200 if (is_toggled) ;
223b71206888 Initial import
thib
parents:
diff changeset
201 else if (nptn > 2)
223b71206888 Initial import
thib
parents:
diff changeset
202 Pic()->SetSurfacePos(sx+sdx*2, sy+sdy*2);
223b71206888 Initial import
thib
parents:
diff changeset
203 else if (nptn > 1)
223b71206888 Initial import
thib
parents:
diff changeset
204 Pic()->SetSurfacePos(sx+sdx, sy+sdy);
223b71206888 Initial import
thib
parents:
diff changeset
205 if (press_func) press_func(press_pointer, this);
223b71206888 Initial import
thib
parents:
diff changeset
206 if (is_toggle_switch) Toggle(!is_toggled);
223b71206888 Initial import
thib
parents:
diff changeset
207 }
223b71206888 Initial import
thib
parents:
diff changeset
208 void Button::Release(void) {
223b71206888 Initial import
thib
parents:
diff changeset
209 if (is_toggled) ;
223b71206888 Initial import
thib
parents:
diff changeset
210 else if (nptn > 1 && is_in)
223b71206888 Initial import
thib
parents:
diff changeset
211 Pic()->SetSurfacePos(sx+sdx, sy+sdy);
223b71206888 Initial import
thib
parents:
diff changeset
212 else if (nptn > 1)
223b71206888 Initial import
thib
parents:
diff changeset
213 Pic()->SetSurfacePos(sx, sy);
223b71206888 Initial import
thib
parents:
diff changeset
214 }
223b71206888 Initial import
thib
parents:
diff changeset
215 void Button::Drag(int x_from, int y_from, int x_to, int y_to) {
223b71206888 Initial import
thib
parents:
diff changeset
216 if (drag_func) drag_func(x_from,y_from,x_to, y_to,drag_pointer, this);
223b71206888 Initial import
thib
parents:
diff changeset
217 }
223b71206888 Initial import
thib
parents:
diff changeset
218
223b71206888 Initial import
thib
parents:
diff changeset
219 Scale::Scale(Event::Container& _container, PicContainer* _parent, const Rect& r_orig, const Color& _color, bool _is_vertical) :
223b71206888 Initial import
thib
parents:
diff changeset
220 Event::Video(_container,Rect(0,0), 1),
223b71206888 Initial import
thib
parents:
diff changeset
221 container(_container), parent(_parent), cursor_color(_color),
223b71206888 Initial import
thib
parents:
diff changeset
222 mouse_x(0), mouse_y(0), max(0), min(0),
223b71206888 Initial import
thib
parents:
diff changeset
223 value(0), value_add(0), value_dragstart(0), is_vertical(_is_vertical),
223b71206888 Initial import
thib
parents:
diff changeset
224 change_func(0), change_pointer(0) {
223b71206888 Initial import
thib
parents:
diff changeset
225
223b71206888 Initial import
thib
parents:
diff changeset
226 arrow_down = 0;
223b71206888 Initial import
thib
parents:
diff changeset
227 arrow_up = 0;
223b71206888 Initial import
thib
parents:
diff changeset
228 cursor = 0;
223b71206888 Initial import
thib
parents:
diff changeset
229 panel = 0;
223b71206888 Initial import
thib
parents:
diff changeset
230
223b71206888 Initial import
thib
parents:
diff changeset
231 Init(r_orig);
223b71206888 Initial import
thib
parents:
diff changeset
232 }
223b71206888 Initial import
thib
parents:
diff changeset
233
223b71206888 Initial import
thib
parents:
diff changeset
234 extern char* create_button(int number, int& width, int& height, int r, int g, int b);
223b71206888 Initial import
thib
parents:
diff changeset
235 extern char* create_box(int& width, int& height, int r, int g, int b);
223b71206888 Initial import
thib
parents:
diff changeset
236 void Scale::Init(Rect r_orig) {
223b71206888 Initial import
thib
parents:
diff changeset
237 int r=cursor_color.r, g=cursor_color.g, b=cursor_color.b;
223b71206888 Initial import
thib
parents:
diff changeset
238 // 矢印
223b71206888 Initial import
thib
parents:
diff changeset
239 int arrow_width = -1;
223b71206888 Initial import
thib
parents:
diff changeset
240 cursor_width = -1;
223b71206888 Initial import
thib
parents:
diff changeset
241 char* button1;
223b71206888 Initial import
thib
parents:
diff changeset
242 char* button2;
223b71206888 Initial import
thib
parents:
diff changeset
243 if (is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
244 // 矢印に必要な領域確保
223b71206888 Initial import
thib
parents:
diff changeset
245 int arrow_height = r_orig.width();
223b71206888 Initial import
thib
parents:
diff changeset
246 button1 = create_button(2, arrow_height, arrow_width, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
247 button2 = create_button(3, arrow_height, arrow_width, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
248 if (r_orig.height() < arrow_width*4) {
223b71206888 Initial import
thib
parents:
diff changeset
249 if (r_orig.height() < 8) r_orig.by = r_orig.ty + 8; // 小さすぎる場合は強制変更
223b71206888 Initial import
thib
parents:
diff changeset
250 free( (void*)button1);
223b71206888 Initial import
thib
parents:
diff changeset
251 free( (void*)button2);
223b71206888 Initial import
thib
parents:
diff changeset
252 arrow_width = r_orig.height()/4;
223b71206888 Initial import
thib
parents:
diff changeset
253 // 再割り当て
223b71206888 Initial import
thib
parents:
diff changeset
254 button1 = create_button(2, arrow_height, arrow_width, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
255 button2 = create_button(3, arrow_height, arrow_width, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
256 }
223b71206888 Initial import
thib
parents:
diff changeset
257 // 矢印ボタンの作成
223b71206888 Initial import
thib
parents:
diff changeset
258 Surface* a1s = parent->Root().NewSurfaceFromRGBAData(arrow_height, arrow_width*3, button1, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
259 int x = r_orig.lx; int y = r_orig.ty;
223b71206888 Initial import
thib
parents:
diff changeset
260 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
261 arrow_up->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
262 Surface* a2s = parent->Root().NewSurfaceFromRGBAData(arrow_height, arrow_width*3, button2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
263 x = r_orig.rx - arrow_height; y = r_orig.by - arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
264 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
265 arrow_down->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
266 // picture作成(ボタンの動く領域)
223b71206888 Initial import
thib
parents:
diff changeset
267 Rect r = r_orig;
223b71206888 Initial import
thib
parents:
diff changeset
268 r.ty += arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
269 r.by -= arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
270 panel = parent->create_node(r, 0);
223b71206888 Initial import
thib
parents:
diff changeset
271 SetPic(panel);
223b71206888 Initial import
thib
parents:
diff changeset
272 // ボタンの中心線を描画、設定
223b71206888 Initial import
thib
parents:
diff changeset
273 Surface* s = parent->Root().NewSurface(r.width()/2, r.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
274 DSurfaceFill(s, Rect(0,0,r.width()/2,r.height()), 0, 0, 0, 0xff);
223b71206888 Initial import
thib
parents:
diff changeset
275 Pic()->SetSurface(s, -r.width()/4, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
276 Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
277 } else {
223b71206888 Initial import
thib
parents:
diff changeset
278 // 矢印に必要な領域確保
223b71206888 Initial import
thib
parents:
diff changeset
279 int arrow_height = r_orig.height();
223b71206888 Initial import
thib
parents:
diff changeset
280 button1 = create_button(0, arrow_width, arrow_height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
281 button2 = create_button(1, arrow_width, arrow_height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
282 if (r_orig.width() < arrow_width*4) {
223b71206888 Initial import
thib
parents:
diff changeset
283 if (r_orig.width() < 8) r_orig.rx = r_orig.lx + 8; // 小さすぎる場合は強制変更
223b71206888 Initial import
thib
parents:
diff changeset
284 free( (void*)button1);
223b71206888 Initial import
thib
parents:
diff changeset
285 free( (void*)button2);
223b71206888 Initial import
thib
parents:
diff changeset
286 arrow_width = r_orig.width()/4;
223b71206888 Initial import
thib
parents:
diff changeset
287 // 再割り当て
223b71206888 Initial import
thib
parents:
diff changeset
288 button1 = create_button(2, arrow_width, arrow_height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
289 button2 = create_button(3, arrow_width, arrow_height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
290 }
223b71206888 Initial import
thib
parents:
diff changeset
291 // 矢印ボタンの作成
223b71206888 Initial import
thib
parents:
diff changeset
292 Surface* a1s = parent->Root().NewSurfaceFromRGBAData(arrow_width, arrow_height*3, button1, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
293 int x = r_orig.lx; int y = r_orig.ty;
223b71206888 Initial import
thib
parents:
diff changeset
294 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
295 arrow_up->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
296 Surface* a2s = parent->Root().NewSurfaceFromRGBAData(arrow_width, arrow_height*3, button2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
297 x = r_orig.rx - arrow_width; y = r_orig.by - arrow_height;
223b71206888 Initial import
thib
parents:
diff changeset
298 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
299 arrow_down->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
300 // picture作成(ボタンの動く領域)
223b71206888 Initial import
thib
parents:
diff changeset
301 Rect r = r_orig;
223b71206888 Initial import
thib
parents:
diff changeset
302 r.lx += arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
303 r.rx -= arrow_width;
223b71206888 Initial import
thib
parents:
diff changeset
304 panel = parent->create_node(r, 0);
223b71206888 Initial import
thib
parents:
diff changeset
305 SetPic(panel);
223b71206888 Initial import
thib
parents:
diff changeset
306 // ボタンの中心線を描画、設定
223b71206888 Initial import
thib
parents:
diff changeset
307 Surface* s = parent->Root().NewSurface(r.width(), r.height()/2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
308 DSurfaceFill(s, Rect(0,0,r.width(),r.height()/2), 0, 0, 0, 0xff);
223b71206888 Initial import
thib
parents:
diff changeset
309 Pic()->SetSurface(s, 0, -r.height()/4, 0);
223b71206888 Initial import
thib
parents:
diff changeset
310 Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
311 }
223b71206888 Initial import
thib
parents:
diff changeset
312 arrow_up->press_func = &Scale::PressArrowUp;
223b71206888 Initial import
thib
parents:
diff changeset
313 arrow_up->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
314 arrow_down->press_func = &Scale::PressArrowDown;
223b71206888 Initial import
thib
parents:
diff changeset
315 arrow_down->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
316 arrow_up->show();
223b71206888 Initial import
thib
parents:
diff changeset
317 arrow_down->show();
223b71206888 Initial import
thib
parents:
diff changeset
318 panel->show();
223b71206888 Initial import
thib
parents:
diff changeset
319 InitCursor(0);
223b71206888 Initial import
thib
parents:
diff changeset
320 }
223b71206888 Initial import
thib
parents:
diff changeset
321
223b71206888 Initial import
thib
parents:
diff changeset
322 void Scale::InitCursor(int width_ratio) {
223b71206888 Initial import
thib
parents:
diff changeset
323 int r=cursor_color.r, g=cursor_color.g, b=cursor_color.b;
223b71206888 Initial import
thib
parents:
diff changeset
324 if (cursor) delete cursor;
223b71206888 Initial import
thib
parents:
diff changeset
325 cursor = 0;
223b71206888 Initial import
thib
parents:
diff changeset
326 Rect region(0,0);
223b71206888 Initial import
thib
parents:
diff changeset
327 if (width_ratio < 0) width_ratio = 0;
223b71206888 Initial import
thib
parents:
diff changeset
328 else if (width_ratio > 1024) width_ratio = 1024;
223b71206888 Initial import
thib
parents:
diff changeset
329 if (is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
330 if (width_ratio == 0) cursor_width = Pic()->Width() * 3 / 2; // 幅の1.5倍
223b71206888 Initial import
thib
parents:
diff changeset
331 else cursor_width = Pic()->Height()*width_ratio/1024;
223b71206888 Initial import
thib
parents:
diff changeset
332 if (cursor_width <= 0) return; // カーソルなし(いいのか?)
223b71206888 Initial import
thib
parents:
diff changeset
333 region = Rect(0, 0, Pic()->Width(), cursor_width);
223b71206888 Initial import
thib
parents:
diff changeset
334 } else { // horizontal
223b71206888 Initial import
thib
parents:
diff changeset
335 if (width_ratio == 0) cursor_width = Pic()->Height() * 3 / 2; // 高さの1.5倍
223b71206888 Initial import
thib
parents:
diff changeset
336 else cursor_width = Pic()->Width()*width_ratio/1024;
223b71206888 Initial import
thib
parents:
diff changeset
337 if (cursor_width <= 0) return; // カーソルなし(いいのか?)
223b71206888 Initial import
thib
parents:
diff changeset
338 region = Rect(0, 0, cursor_width, Pic()->Height());
223b71206888 Initial import
thib
parents:
diff changeset
339 }
223b71206888 Initial import
thib
parents:
diff changeset
340
223b71206888 Initial import
thib
parents:
diff changeset
341 int height = region.height();
223b71206888 Initial import
thib
parents:
diff changeset
342 int width = region.width();
223b71206888 Initial import
thib
parents:
diff changeset
343 char* box = create_box(width, height, r, g, b);
223b71206888 Initial import
thib
parents:
diff changeset
344 Surface* boxs = parent->Root().NewSurfaceFromRGBAData(width, height*3, box, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
345 cursor = new Button(container, panel, boxs, 0, 0, 0, height, 3, region, 2);
223b71206888 Initial import
thib
parents:
diff changeset
346 cursor->Pic()->SetSurfaceFreeFlag();
223b71206888 Initial import
thib
parents:
diff changeset
347
223b71206888 Initial import
thib
parents:
diff changeset
348 cursor->press_func = &Scale::PressCursor;
223b71206888 Initial import
thib
parents:
diff changeset
349 cursor->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
350 cursor->drag_func = &Scale::DragCursor;
223b71206888 Initial import
thib
parents:
diff changeset
351 cursor->drag_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
352 cursor->show();
223b71206888 Initial import
thib
parents:
diff changeset
353
223b71206888 Initial import
thib
parents:
diff changeset
354 // 矢印等をクリックしたときの移動量計算
223b71206888 Initial import
thib
parents:
diff changeset
355 int bar_width;
223b71206888 Initial import
thib
parents:
diff changeset
356 if (is_vertical) bar_width = Pic()->Height();
223b71206888 Initial import
thib
parents:
diff changeset
357 else bar_width = Pic()->Width();
223b71206888 Initial import
thib
parents:
diff changeset
358 if (bar_width <= 0) value_add = max-min;
223b71206888 Initial import
thib
parents:
diff changeset
359 else if (cursor_width == 0) value_add = 2;
223b71206888 Initial import
thib
parents:
diff changeset
360 else value_add = scale_max*cursor_width/bar_width;
223b71206888 Initial import
thib
parents:
diff changeset
361
223b71206888 Initial import
thib
parents:
diff changeset
362 return;
223b71206888 Initial import
thib
parents:
diff changeset
363 }
223b71206888 Initial import
thib
parents:
diff changeset
364
223b71206888 Initial import
thib
parents:
diff changeset
365 void Scale::PressArrowDown(void* pointer, Button* from) {
223b71206888 Initial import
thib
parents:
diff changeset
366 Scale* self = (Scale*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
367 self->SetScaleValue(self->value + self->value_add);
223b71206888 Initial import
thib
parents:
diff changeset
368 }
223b71206888 Initial import
thib
parents:
diff changeset
369 void Scale::PressArrowUp(void* pointer, Button* from){
223b71206888 Initial import
thib
parents:
diff changeset
370 Scale* self = (Scale*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
371 self->SetScaleValue(self->value - self->value_add);
223b71206888 Initial import
thib
parents:
diff changeset
372 }
223b71206888 Initial import
thib
parents:
diff changeset
373 void Scale::PressCursor(void* pointer, Button* from){
223b71206888 Initial import
thib
parents:
diff changeset
374 Scale* self = (Scale*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
375 self->value_dragstart = self->value;
223b71206888 Initial import
thib
parents:
diff changeset
376 }
223b71206888 Initial import
thib
parents:
diff changeset
377 void Scale::DragCursor(int x_from, int y_from,int x, int y, void* pointer, Button* from){
223b71206888 Initial import
thib
parents:
diff changeset
378 Scale* self = (Scale*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
379 int dx, w;
223b71206888 Initial import
thib
parents:
diff changeset
380 if (self->is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
381 dx = y-y_from;
223b71206888 Initial import
thib
parents:
diff changeset
382 w = self->Event::Video::Region().height();
223b71206888 Initial import
thib
parents:
diff changeset
383 } else {
223b71206888 Initial import
thib
parents:
diff changeset
384 dx = x-x_from;
223b71206888 Initial import
thib
parents:
diff changeset
385 w = self->Event::Video::Region().width();
223b71206888 Initial import
thib
parents:
diff changeset
386 }
223b71206888 Initial import
thib
parents:
diff changeset
387 if (w == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
388 self->SetScaleValue(self->value_dragstart + dx*scale_max/w);
223b71206888 Initial import
thib
parents:
diff changeset
389 }
223b71206888 Initial import
thib
parents:
diff changeset
390 int Scale::CalcValue(void) {
223b71206888 Initial import
thib
parents:
diff changeset
391 Rect own_region = Event::Video::Region();
223b71206888 Initial import
thib
parents:
diff changeset
392 int x, w;
223b71206888 Initial import
thib
parents:
diff changeset
393 if (is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
394 w = own_region.height();
223b71206888 Initial import
thib
parents:
diff changeset
395 x = mouse_y - own_region.ty;
223b71206888 Initial import
thib
parents:
diff changeset
396 } else {
223b71206888 Initial import
thib
parents:
diff changeset
397 w = own_region.width();
223b71206888 Initial import
thib
parents:
diff changeset
398 x = mouse_x - own_region.lx;
223b71206888 Initial import
thib
parents:
diff changeset
399 }
223b71206888 Initial import
thib
parents:
diff changeset
400 if (w == 0) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
401 if (x < 0) x = 0;
223b71206888 Initial import
thib
parents:
diff changeset
402 else if (x > w) x = w;
223b71206888 Initial import
thib
parents:
diff changeset
403 return x*scale_max/w;
223b71206888 Initial import
thib
parents:
diff changeset
404 }
223b71206888 Initial import
thib
parents:
diff changeset
405 void Scale::Press(void){
223b71206888 Initial import
thib
parents:
diff changeset
406 int v = CalcValue();
223b71206888 Initial import
thib
parents:
diff changeset
407 if (v < value) SetScaleValue(value-value_add);
223b71206888 Initial import
thib
parents:
diff changeset
408 else SetScaleValue(value+value_add);
223b71206888 Initial import
thib
parents:
diff changeset
409 return;
223b71206888 Initial import
thib
parents:
diff changeset
410 }
223b71206888 Initial import
thib
parents:
diff changeset
411 void Scale::Motion(int x, int y){
223b71206888 Initial import
thib
parents:
diff changeset
412 mouse_x = x;
223b71206888 Initial import
thib
parents:
diff changeset
413 mouse_y = y;
223b71206888 Initial import
thib
parents:
diff changeset
414 }
223b71206888 Initial import
thib
parents:
diff changeset
415
223b71206888 Initial import
thib
parents:
diff changeset
416 void Scale::SetRange(int new_min, int new_max) {
223b71206888 Initial import
thib
parents:
diff changeset
417 min = new_min;
223b71206888 Initial import
thib
parents:
diff changeset
418 max = new_max;
223b71206888 Initial import
thib
parents:
diff changeset
419 SetValue(value);
223b71206888 Initial import
thib
parents:
diff changeset
420 return;
223b71206888 Initial import
thib
parents:
diff changeset
421 }
223b71206888 Initial import
thib
parents:
diff changeset
422 void Scale::SetValue(int new_value) {
223b71206888 Initial import
thib
parents:
diff changeset
423 if (min == max) {
223b71206888 Initial import
thib
parents:
diff changeset
424 value = min;
223b71206888 Initial import
thib
parents:
diff changeset
425 SetScaleValue(0);
223b71206888 Initial import
thib
parents:
diff changeset
426 return;
223b71206888 Initial import
thib
parents:
diff changeset
427 }
223b71206888 Initial import
thib
parents:
diff changeset
428 int scale_value = (new_value-min) * scale_max / (max-min);
223b71206888 Initial import
thib
parents:
diff changeset
429 SetScaleValue(scale_value);
223b71206888 Initial import
thib
parents:
diff changeset
430 }
223b71206888 Initial import
thib
parents:
diff changeset
431 int Scale::GetValue(void) const{
223b71206888 Initial import
thib
parents:
diff changeset
432 return min + value * (max-min) / scale_max;
223b71206888 Initial import
thib
parents:
diff changeset
433 }
223b71206888 Initial import
thib
parents:
diff changeset
434 void Scale::SetScaleValue(int new_value) {
223b71206888 Initial import
thib
parents:
diff changeset
435 if (new_value < 0) value = 0;
223b71206888 Initial import
thib
parents:
diff changeset
436 else if (new_value > scale_max) value = scale_max;
223b71206888 Initial import
thib
parents:
diff changeset
437 else value = new_value;
223b71206888 Initial import
thib
parents:
diff changeset
438 if (is_vertical) {
223b71206888 Initial import
thib
parents:
diff changeset
439 int h = Pic()->Height();
223b71206888 Initial import
thib
parents:
diff changeset
440 int y = (h-cursor_width) * value / scale_max;
223b71206888 Initial import
thib
parents:
diff changeset
441 if (y < 0) y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
442 cursor->Pic()->Move(0, y);
223b71206888 Initial import
thib
parents:
diff changeset
443 } else { // horizontal
223b71206888 Initial import
thib
parents:
diff changeset
444 int w = Pic()->Width();
223b71206888 Initial import
thib
parents:
diff changeset
445 int x = (w-cursor_width) * value / scale_max;
223b71206888 Initial import
thib
parents:
diff changeset
446 if (x < 0) x = 0;
223b71206888 Initial import
thib
parents:
diff changeset
447 cursor->Pic()->Move(x, 0);
223b71206888 Initial import
thib
parents:
diff changeset
448 }
223b71206888 Initial import
thib
parents:
diff changeset
449 if (change_func) {
223b71206888 Initial import
thib
parents:
diff changeset
450 (*change_func)(change_pointer, this);
223b71206888 Initial import
thib
parents:
diff changeset
451 }
223b71206888 Initial import
thib
parents:
diff changeset
452 return;
223b71206888 Initial import
thib
parents:
diff changeset
453 }
223b71206888 Initial import
thib
parents:
diff changeset
454
223b71206888 Initial import
thib
parents:
diff changeset
455 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
456 Button(container, parent, (Surface*)0, 0, 0, 0, 0, 0, r_orig, _z),
223b71206888 Initial import
thib
parents:
diff changeset
457 root(parent->Root()), surface(0), attribute(attr), text_size(_text_size),
223b71206888 Initial import
thib
parents:
diff changeset
458 fore(_fore), pressed(_pressed), back(_back)
223b71206888 Initial import
thib
parents:
diff changeset
459 {
223b71206888 Initial import
thib
parents:
diff changeset
460 bool rect_changed = false;
223b71206888 Initial import
thib
parents:
diff changeset
461 // まず、テキスト領域の広さを得る
223b71206888 Initial import
thib
parents:
diff changeset
462 Rect r(r_orig);
223b71206888 Initial import
thib
parents:
diff changeset
463
223b71206888 Initial import
thib
parents:
diff changeset
464 if (text == 0) text = "";
223b71206888 Initial import
thib
parents:
diff changeset
465 int width = r.width(); int height = r.height();
223b71206888 Initial import
thib
parents:
diff changeset
466 if (width == 0) width = parent->Width() - r.lx;
223b71206888 Initial import
thib
parents:
diff changeset
467
223b71206888 Initial import
thib
parents:
diff changeset
468 TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, width);
223b71206888 Initial import
thib
parents:
diff changeset
469
223b71206888 Initial import
thib
parents:
diff changeset
470 if (r.width() == 0) { // 文字に合わせてウィジット作成
223b71206888 Initial import
thib
parents:
diff changeset
471 rect_changed = true;
223b71206888 Initial import
thib
parents:
diff changeset
472 width = gs.width() + text_size;
223b71206888 Initial import
thib
parents:
diff changeset
473 r.rx = r.lx + gs.width();
223b71206888 Initial import
thib
parents:
diff changeset
474 attribute = Attribute(attribute | CENTER);
223b71206888 Initial import
thib
parents:
diff changeset
475 }
223b71206888 Initial import
thib
parents:
diff changeset
476 if (r.height() == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
477 rect_changed = true;
223b71206888 Initial import
thib
parents:
diff changeset
478 if (attribute & NOPADDING) r.by = r.ty + gs.height();
223b71206888 Initial import
thib
parents:
diff changeset
479 else r.by = r.ty + gs.height() + text_size/2;
223b71206888 Initial import
thib
parents:
diff changeset
480 }
223b71206888 Initial import
thib
parents:
diff changeset
481
223b71206888 Initial import
thib
parents:
diff changeset
482 if (rect_changed) {
223b71206888 Initial import
thib
parents:
diff changeset
483 // 大きさ変更
223b71206888 Initial import
thib
parents:
diff changeset
484 Pic()->SetSurfaceRect(r);
223b71206888 Initial import
thib
parents:
diff changeset
485 }
223b71206888 Initial import
thib
parents:
diff changeset
486
223b71206888 Initial import
thib
parents:
diff changeset
487 sx = 0; sy = 0; sdx = 0; sdy = r.height(); nptn = 3;
223b71206888 Initial import
thib
parents:
diff changeset
488 int x = 0, y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
489 if (attribute & CENTER)
223b71206888 Initial import
thib
parents:
diff changeset
490 x = (Pic()->Width() - gs.width()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
491 y = (Pic()->Height() - gs.height()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
492
223b71206888 Initial import
thib
parents:
diff changeset
493 if (back.a == 0) { // 背景なし、もしくはボタン押の状態のみ背景あり
223b71206888 Initial import
thib
parents:
diff changeset
494 surface = root.NewSurface(r.width(), r.height()*2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
495 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
496 if (attribute & REVERSE) {
223b71206888 Initial import
thib
parents:
diff changeset
497 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
498 }
223b71206888 Initial import
thib
parents:
diff changeset
499 gs.SetColor(fore.r, fore.g, fore.b);
223b71206888 Initial import
thib
parents:
diff changeset
500 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
501 gs.SetColor(pressed.r, pressed.g, pressed.b);
223b71206888 Initial import
thib
parents:
diff changeset
502 if (attribute & REVERSE) {
223b71206888 Initial import
thib
parents:
diff changeset
503 gs.SetReverse(true);
223b71206888 Initial import
thib
parents:
diff changeset
504 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
505 gs.SetReverse(false);
223b71206888 Initial import
thib
parents:
diff changeset
506 } else {
223b71206888 Initial import
thib
parents:
diff changeset
507 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
508 }
223b71206888 Initial import
thib
parents:
diff changeset
509 nptn = 2;
223b71206888 Initial import
thib
parents:
diff changeset
510 } else { // ボタン型の背景あり
223b71206888 Initial import
thib
parents:
diff changeset
511 /* ラベル用の Surface を作る */
223b71206888 Initial import
thib
parents:
diff changeset
512 width = r.width(); height = r.height();
223b71206888 Initial import
thib
parents:
diff changeset
513 char* box = create_box(width, height, back.r, back.g, back.b);
223b71206888 Initial import
thib
parents:
diff changeset
514 surface = root.NewSurfaceFromRGBAData(r.width(), r.height()*3, box, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
515
223b71206888 Initial import
thib
parents:
diff changeset
516 Surface* text_surface = root.NewSurface(r.width(), r.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
517 DSurfaceFill(text_surface, Rect(*text_surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
518
223b71206888 Initial import
thib
parents:
diff changeset
519 gs.SetColor(fore.r, fore.g, fore.b);
223b71206888 Initial import
thib
parents:
diff changeset
520 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), text_surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
521 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
522 gs.SetColor(pressed.r, pressed.g, pressed.b);
223b71206888 Initial import
thib
parents:
diff changeset
523 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), text_surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
524 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,height));
223b71206888 Initial import
thib
parents:
diff changeset
525 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,height*2));
223b71206888 Initial import
thib
parents:
diff changeset
526 root.DeleteSurface(text_surface);
223b71206888 Initial import
thib
parents:
diff changeset
527 }
223b71206888 Initial import
thib
parents:
diff changeset
528
223b71206888 Initial import
thib
parents:
diff changeset
529 Pic()->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
530 show();
223b71206888 Initial import
thib
parents:
diff changeset
531 }
223b71206888 Initial import
thib
parents:
diff changeset
532 void TextButton::SetText(const char* text, const Color& _fore, const Color& _pressed, const Color& _back)
223b71206888 Initial import
thib
parents:
diff changeset
533 {
223b71206888 Initial import
thib
parents:
diff changeset
534 int width = Pic()->Width(); int height = Pic()->Height();
223b71206888 Initial import
thib
parents:
diff changeset
535 // まず、テキスト領域の広さを得る
223b71206888 Initial import
thib
parents:
diff changeset
536 if (text == 0) text = "";
223b71206888 Initial import
thib
parents:
diff changeset
537
223b71206888 Initial import
thib
parents:
diff changeset
538 TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, width);
223b71206888 Initial import
thib
parents:
diff changeset
539
223b71206888 Initial import
thib
parents:
diff changeset
540 int x = 0, y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
541 if (attribute & CENTER) {
223b71206888 Initial import
thib
parents:
diff changeset
542 x = (width - gs.width()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
543 y = (height - gs.height()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
544 }
223b71206888 Initial import
thib
parents:
diff changeset
545 int surf_x = Pic()->SurfacePosX();
223b71206888 Initial import
thib
parents:
diff changeset
546 int surf_y = Pic()->SurfacePosY();
223b71206888 Initial import
thib
parents:
diff changeset
547 Pic()->SetSurface( (Surface*)0,0,0);
223b71206888 Initial import
thib
parents:
diff changeset
548 root.DeleteSurface(surface);
223b71206888 Initial import
thib
parents:
diff changeset
549 surface = 0;
223b71206888 Initial import
thib
parents:
diff changeset
550
223b71206888 Initial import
thib
parents:
diff changeset
551 if (back.a == 0) { // 背景なし
223b71206888 Initial import
thib
parents:
diff changeset
552 surface = root.NewSurface(width, height*2, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
553 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
554 if (attribute & REVERSE) {
223b71206888 Initial import
thib
parents:
diff changeset
555 DSurfaceFill(surface, Rect(0,height,width,height*2), pressed.r, pressed.g, pressed.b, 0xff);
223b71206888 Initial import
thib
parents:
diff changeset
556 }
223b71206888 Initial import
thib
parents:
diff changeset
557 gs.SetColor(_fore.r, _fore.g, _fore.b);
223b71206888 Initial import
thib
parents:
diff changeset
558 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
559 gs.SetColor(_pressed.r, _pressed.g, _pressed.b);
223b71206888 Initial import
thib
parents:
diff changeset
560 gs.SetReverse(true);
223b71206888 Initial import
thib
parents:
diff changeset
561 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), surface, Rect(x,y+height));
223b71206888 Initial import
thib
parents:
diff changeset
562 gs.SetReverse(false);
223b71206888 Initial import
thib
parents:
diff changeset
563 nptn = 2;
223b71206888 Initial import
thib
parents:
diff changeset
564 } else {
223b71206888 Initial import
thib
parents:
diff changeset
565 /* ラベル用の Surface を作る */
223b71206888 Initial import
thib
parents:
diff changeset
566 char* box = create_box(width, height, _back.r, _back.g, _back.b);
223b71206888 Initial import
thib
parents:
diff changeset
567 surface = root.NewSurfaceFromRGBAData(width, height*3, box, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
568
223b71206888 Initial import
thib
parents:
diff changeset
569 Surface* text_surface = root.NewSurface(width, height, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
570 DSurfaceFill(text_surface, Rect(*text_surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
571
223b71206888 Initial import
thib
parents:
diff changeset
572 gs.SetColor(_fore.r, _fore.g, _fore.b);
223b71206888 Initial import
thib
parents:
diff changeset
573 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), text_surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
574 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
575 gs.SetColor(_pressed.r, _pressed.g, _pressed.b);
223b71206888 Initial import
thib
parents:
diff changeset
576 DSurfaceRenderText(gs.begin(), gs.end(), Rect(0,0,gs.width(),gs.height()), text_surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
577 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,height));
223b71206888 Initial import
thib
parents:
diff changeset
578 root.BlitSurface(text_surface, Rect(0,0,width,height), surface, Rect(0,height*2));
223b71206888 Initial import
thib
parents:
diff changeset
579 root.DeleteSurface(text_surface);
223b71206888 Initial import
thib
parents:
diff changeset
580 }
223b71206888 Initial import
thib
parents:
diff changeset
581
223b71206888 Initial import
thib
parents:
diff changeset
582 Pic()->SetSurface(surface, surf_x, surf_y);
223b71206888 Initial import
thib
parents:
diff changeset
583 show();
223b71206888 Initial import
thib
parents:
diff changeset
584 }
223b71206888 Initial import
thib
parents:
diff changeset
585
223b71206888 Initial import
thib
parents:
diff changeset
586 TextButton::~TextButton() {
223b71206888 Initial import
thib
parents:
diff changeset
587 if (surface) root.DeleteSurface(surface);
223b71206888 Initial import
thib
parents:
diff changeset
588 surface = 0;
223b71206888 Initial import
thib
parents:
diff changeset
589 return;
223b71206888 Initial import
thib
parents:
diff changeset
590 }
223b71206888 Initial import
thib
parents:
diff changeset
591
223b71206888 Initial import
thib
parents:
diff changeset
592 Text::Text(Event::Container& container, PicContainer* parent, const Rect& r, const Rect& text_r, int _fontsize) :
223b71206888 Initial import
thib
parents:
diff changeset
593 Event::Video(container),
223b71206888 Initial import
thib
parents:
diff changeset
594 Event::Time(container),
223b71206888 Initial import
thib
parents:
diff changeset
595 event(container),
223b71206888 Initial import
thib
parents:
diff changeset
596 srcrect(0,0,0,0),
223b71206888 Initial import
thib
parents:
diff changeset
597 layout(wdefault_font.c_str(), _fontsize), fontsize(_fontsize) {
223b71206888 Initial import
thib
parents:
diff changeset
598
223b71206888 Initial import
thib
parents:
diff changeset
599 SetPic(parent->create_node(r, 0));
223b71206888 Initial import
thib
parents:
diff changeset
600 surface = parent->Root().NewSurface(text_r.width(), text_r.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
601 pictext = PicNode()->create_leaf(text_r, PicBase::CACHE_BACK);
223b71206888 Initial import
thib
parents:
diff changeset
602 pictext->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
603 pictext->show();
223b71206888 Initial import
thib
parents:
diff changeset
604 cursor = 0;
223b71206888 Initial import
thib
parents:
diff changeset
605 cursor_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
606 window_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
607
223b71206888 Initial import
thib
parents:
diff changeset
608 event.RegisterGlobalPressFunc(&Pressed, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
609
223b71206888 Initial import
thib
parents:
diff changeset
610 speed = 10;
223b71206888 Initial import
thib
parents:
diff changeset
611 wait_delay = -1;
223b71206888 Initial import
thib
parents:
diff changeset
612 status = PREPARE;
223b71206888 Initial import
thib
parents:
diff changeset
613 old_time = wait_starttime = 0;
223b71206888 Initial import
thib
parents:
diff changeset
614 }
223b71206888 Initial import
thib
parents:
diff changeset
615
223b71206888 Initial import
thib
parents:
diff changeset
616 Text::~Text() {
223b71206888 Initial import
thib
parents:
diff changeset
617 event.DeleteGlobalPressFunc(&Pressed, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
618 PicNode()->Root().DeleteSurface(surface);
223b71206888 Initial import
thib
parents:
diff changeset
619 }
223b71206888 Initial import
thib
parents:
diff changeset
620
223b71206888 Initial import
thib
parents:
diff changeset
621 void Text::SetSpeed(int new_speed) {
223b71206888 Initial import
thib
parents:
diff changeset
622 speed = new_speed;
223b71206888 Initial import
thib
parents:
diff changeset
623 }
223b71206888 Initial import
thib
parents:
diff changeset
624 void Text::SetWait(int new_wait) {
223b71206888 Initial import
thib
parents:
diff changeset
625 if (new_wait < 0) new_wait = 100000000;
223b71206888 Initial import
thib
parents:
diff changeset
626 wait_delay = new_wait;
223b71206888 Initial import
thib
parents:
diff changeset
627 }
223b71206888 Initial import
thib
parents:
diff changeset
628
223b71206888 Initial import
thib
parents:
diff changeset
629 int Text::CalcScrollHeight(void) {
223b71206888 Initial import
thib
parents:
diff changeset
630 int i;
223b71206888 Initial import
thib
parents:
diff changeset
631 int len = bottom_pos.size();
223b71206888 Initial import
thib
parents:
diff changeset
632 int y0 = bottom_pos[line_number];
223b71206888 Initial import
thib
parents:
diff changeset
633 int height = Rect(*surface).height();
223b71206888 Initial import
thib
parents:
diff changeset
634 for (i=line_number; i<len; i++)
223b71206888 Initial import
thib
parents:
diff changeset
635 if (bottom_pos[i] - y0 > height) break;
223b71206888 Initial import
thib
parents:
diff changeset
636 if (i == line_number) i = line_number + 1;
223b71206888 Initial import
thib
parents:
diff changeset
637 return i - line_number - 1;
223b71206888 Initial import
thib
parents:
diff changeset
638 }
223b71206888 Initial import
thib
parents:
diff changeset
639 void Text::Elapsed(unsigned int current_time) {
223b71206888 Initial import
thib
parents:
diff changeset
640 SetWakeup(current_time + 50);
223b71206888 Initial import
thib
parents:
diff changeset
641 if (status == PREPARE) {
223b71206888 Initial import
thib
parents:
diff changeset
642 old_time = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
643 return;
223b71206888 Initial import
thib
parents:
diff changeset
644 }
223b71206888 Initial import
thib
parents:
diff changeset
645 int nChar = speed * (current_time - old_time) / 1000;
223b71206888 Initial import
thib
parents:
diff changeset
646 if (speed == -1 || press_count) nChar = -1;
223b71206888 Initial import
thib
parents:
diff changeset
647 if (nChar == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
648 if (speed == -1) old_time = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
649 else old_time += nChar * 1000 / speed;
223b71206888 Initial import
thib
parents:
diff changeset
650
223b71206888 Initial import
thib
parents:
diff changeset
651 switch(status) {
223b71206888 Initial import
thib
parents:
diff changeset
652 case WAIT: goto label_wait;
223b71206888 Initial import
thib
parents:
diff changeset
653 case SCROLL: goto label_scroll;
223b71206888 Initial import
thib
parents:
diff changeset
654 case DRAW2: goto label_draw2;
223b71206888 Initial import
thib
parents:
diff changeset
655 case WAIT2: goto label_wait2;
223b71206888 Initial import
thib
parents:
diff changeset
656 }
223b71206888 Initial import
thib
parents:
diff changeset
657
223b71206888 Initial import
thib
parents:
diff changeset
658 status = DRAW;
223b71206888 Initial import
thib
parents:
diff changeset
659 if (press_count) {
223b71206888 Initial import
thib
parents:
diff changeset
660 nChar = -1;
223b71206888 Initial import
thib
parents:
diff changeset
661 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
662 }
223b71206888 Initial import
thib
parents:
diff changeset
663 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
664 if (nChar == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
665 status = WAIT;
223b71206888 Initial import
thib
parents:
diff changeset
666 cursor_activated = true;
223b71206888 Initial import
thib
parents:
diff changeset
667 if (cursor_activated && window_activated && cursor) cursor->show();
223b71206888 Initial import
thib
parents:
diff changeset
668 wait_starttime = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
669 label_wait:
223b71206888 Initial import
thib
parents:
diff changeset
670 if (current_time < wait_starttime + wait_delay && press_count == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
671 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
672 nChar = 0;
223b71206888 Initial import
thib
parents:
diff changeset
673 cursor_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
674 if (cursor) cursor->hide();
223b71206888 Initial import
thib
parents:
diff changeset
675 while(cur_pos != gstream.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
676 // スクロールしては次行描画、を繰り返す
223b71206888 Initial import
thib
parents:
diff changeset
677 for (scroll_height = CalcScrollHeight(); scroll_height > 0; scroll_height--) {
223b71206888 Initial import
thib
parents:
diff changeset
678 status = SCROLL;
223b71206888 Initial import
thib
parents:
diff changeset
679 label_scroll:
223b71206888 Initial import
thib
parents:
diff changeset
680 if (press_count) break;
223b71206888 Initial import
thib
parents:
diff changeset
681 Scrollup(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
682 if (nChar == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
683 status = DRAW2;
223b71206888 Initial import
thib
parents:
diff changeset
684 label_draw2:
223b71206888 Initial import
thib
parents:
diff changeset
685 if (press_count) break;
223b71206888 Initial import
thib
parents:
diff changeset
686 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
687 if (nChar == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
688 }
223b71206888 Initial import
thib
parents:
diff changeset
689 if (nChar != 0 && scroll_height) {
223b71206888 Initial import
thib
parents:
diff changeset
690 nChar = 100000;
223b71206888 Initial import
thib
parents:
diff changeset
691 if (status == SCROLL) Scrollup(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
692 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
693 scroll_height--;
223b71206888 Initial import
thib
parents:
diff changeset
694 for (; scroll_height > 0; scroll_height--) {
223b71206888 Initial import
thib
parents:
diff changeset
695 Scrollup(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
696 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
697 }
223b71206888 Initial import
thib
parents:
diff changeset
698 }
223b71206888 Initial import
thib
parents:
diff changeset
699 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
700 status = WAIT2;
223b71206888 Initial import
thib
parents:
diff changeset
701 cursor_activated = true;
223b71206888 Initial import
thib
parents:
diff changeset
702 if (cursor_activated && window_activated && cursor) cursor->show();
223b71206888 Initial import
thib
parents:
diff changeset
703 wait_starttime = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
704 label_wait2:
223b71206888 Initial import
thib
parents:
diff changeset
705 if (current_time < wait_starttime + wait_delay && press_count == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
706 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
707 nChar = 0;
223b71206888 Initial import
thib
parents:
diff changeset
708 cursor_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
709 if (cursor) cursor->hide();
223b71206888 Initial import
thib
parents:
diff changeset
710 }
223b71206888 Initial import
thib
parents:
diff changeset
711 status = PREPARE;
223b71206888 Initial import
thib
parents:
diff changeset
712 return;
223b71206888 Initial import
thib
parents:
diff changeset
713 }
223b71206888 Initial import
thib
parents:
diff changeset
714
223b71206888 Initial import
thib
parents:
diff changeset
715 bool Text::Pressed(int x, int y, void* pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
716 Text* wid = (Text*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
717 if (wid->Pic()->IsHidden()) return true;
223b71206888 Initial import
thib
parents:
diff changeset
718 wid->press_count++;
223b71206888 Initial import
thib
parents:
diff changeset
719 return true;
223b71206888 Initial import
thib
parents:
diff changeset
720 }
223b71206888 Initial import
thib
parents:
diff changeset
721
223b71206888 Initial import
thib
parents:
diff changeset
722 void Text::Clear(void) {
223b71206888 Initial import
thib
parents:
diff changeset
723 stream.container.clear();
223b71206888 Initial import
thib
parents:
diff changeset
724 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
725 pictext->ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
726 status = PREPARE;
223b71206888 Initial import
thib
parents:
diff changeset
727 }
223b71206888 Initial import
thib
parents:
diff changeset
728
223b71206888 Initial import
thib
parents:
diff changeset
729 void Text::Flush(void) {
223b71206888 Initial import
thib
parents:
diff changeset
730 int nChar = -1;
223b71206888 Initial import
thib
parents:
diff changeset
731 DrawText(nChar);
223b71206888 Initial import
thib
parents:
diff changeset
732 }
223b71206888 Initial import
thib
parents:
diff changeset
733
223b71206888 Initial import
thib
parents:
diff changeset
734 void Text::Start(void) {
223b71206888 Initial import
thib
parents:
diff changeset
735 gstream.clear();
223b71206888 Initial import
thib
parents:
diff changeset
736 bottom_pos.clear();
223b71206888 Initial import
thib
parents:
diff changeset
737 layout.Layout(stream, gstream, bottom_pos, pictext->Width()-fontsize/2);
223b71206888 Initial import
thib
parents:
diff changeset
738
223b71206888 Initial import
thib
parents:
diff changeset
739 // height の積算値として bottom_pos を計算
223b71206888 Initial import
thib
parents:
diff changeset
740 std::vector<int>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
741 int pos = 0;
223b71206888 Initial import
thib
parents:
diff changeset
742 for (it = bottom_pos.begin(); it != bottom_pos.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
743 pos += *it;
223b71206888 Initial import
thib
parents:
diff changeset
744 *it = pos;
223b71206888 Initial import
thib
parents:
diff changeset
745 }
223b71206888 Initial import
thib
parents:
diff changeset
746
223b71206888 Initial import
thib
parents:
diff changeset
747 cur_pos = gstream.begin();
223b71206888 Initial import
thib
parents:
diff changeset
748 line_number = 0;
223b71206888 Initial import
thib
parents:
diff changeset
749 scrolled_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
750 srcrect = Rect(0, 0, pictext->Width(), pictext->Height());
223b71206888 Initial import
thib
parents:
diff changeset
751 press_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
752
223b71206888 Initial import
thib
parents:
diff changeset
753 status = DRAW;
223b71206888 Initial import
thib
parents:
diff changeset
754 cursor_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
755 if (cursor) cursor->hide();
223b71206888 Initial import
thib
parents:
diff changeset
756 }
223b71206888 Initial import
thib
parents:
diff changeset
757
223b71206888 Initial import
thib
parents:
diff changeset
758 void Text::DrawText(int& nChar) {
223b71206888 Initial import
thib
parents:
diff changeset
759 // 描画範囲を得る
223b71206888 Initial import
thib
parents:
diff changeset
760 iterator end = gstream.end();
223b71206888 Initial import
thib
parents:
diff changeset
761 iterator it = cur_pos;
223b71206888 Initial import
thib
parents:
diff changeset
762 while(nChar && it != end) { // nChar < 0 なら出来るだけの文字を描画
223b71206888 Initial import
thib
parents:
diff changeset
763 if (! (it->flag & TextGlyph::Group)) nChar--;
223b71206888 Initial import
thib
parents:
diff changeset
764 if (it->flag & TextGlyph::LineEnd) {
223b71206888 Initial import
thib
parents:
diff changeset
765 if (bottom_pos[line_number+1] > srcrect.by) { //改行すると画面から出てしまう
223b71206888 Initial import
thib
parents:
diff changeset
766 it++;
223b71206888 Initial import
thib
parents:
diff changeset
767 if (nChar == 0) nChar = 1;
223b71206888 Initial import
thib
parents:
diff changeset
768 break;
223b71206888 Initial import
thib
parents:
diff changeset
769 }
223b71206888 Initial import
thib
parents:
diff changeset
770 line_number++;
223b71206888 Initial import
thib
parents:
diff changeset
771 }
223b71206888 Initial import
thib
parents:
diff changeset
772 it++;
223b71206888 Initial import
thib
parents:
diff changeset
773 }
223b71206888 Initial import
thib
parents:
diff changeset
774 // 描画する
223b71206888 Initial import
thib
parents:
diff changeset
775 Rect r = DSurfaceRenderText(cur_pos, it, srcrect, surface, Rect(0,0,0,0));
223b71206888 Initial import
thib
parents:
diff changeset
776 pictext->ReBlit(r);
223b71206888 Initial import
thib
parents:
diff changeset
777 cur_pos = it;
223b71206888 Initial import
thib
parents:
diff changeset
778 return;
223b71206888 Initial import
thib
parents:
diff changeset
779 }
223b71206888 Initial import
thib
parents:
diff changeset
780
223b71206888 Initial import
thib
parents:
diff changeset
781 void Text::Scrollup(int& nChar) {
223b71206888 Initial import
thib
parents:
diff changeset
782 if (nChar < 0) { // 一画面分スクロールする
223b71206888 Initial import
thib
parents:
diff changeset
783 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
784 pictext->ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
785 srcrect = Rect(*surface);
223b71206888 Initial import
thib
parents:
diff changeset
786 srcrect.rmove(0, bottom_pos[line_number]);
223b71206888 Initial import
thib
parents:
diff changeset
787 line_number++;
223b71206888 Initial import
thib
parents:
diff changeset
788 scrolled_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
789 return;
223b71206888 Initial import
thib
parents:
diff changeset
790 }
223b71206888 Initial import
thib
parents:
diff changeset
791 // スクロール幅を求める
223b71206888 Initial import
thib
parents:
diff changeset
792 const int max_scroll_count = 8;
223b71206888 Initial import
thib
parents:
diff changeset
793 int dy = bottom_pos[line_number+1] - bottom_pos[line_number];
223b71206888 Initial import
thib
parents:
diff changeset
794 int cur_dy;
223b71206888 Initial import
thib
parents:
diff changeset
795 if (scrolled_count+nChar >= max_scroll_count) {
223b71206888 Initial import
thib
parents:
diff changeset
796 cur_dy = dy - (scrolled_count*dy/max_scroll_count);
223b71206888 Initial import
thib
parents:
diff changeset
797 nChar -= max_scroll_count-scrolled_count;
223b71206888 Initial import
thib
parents:
diff changeset
798 nChar++;
223b71206888 Initial import
thib
parents:
diff changeset
799 scrolled_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
800 line_number++;
223b71206888 Initial import
thib
parents:
diff changeset
801 srcrect.rmove(0, dy);
223b71206888 Initial import
thib
parents:
diff changeset
802 } else {
223b71206888 Initial import
thib
parents:
diff changeset
803 cur_dy = (scrolled_count+nChar)*dy/max_scroll_count;
223b71206888 Initial import
thib
parents:
diff changeset
804 cur_dy -=(scrolled_count*dy/max_scroll_count);
223b71206888 Initial import
thib
parents:
diff changeset
805 scrolled_count += nChar;
223b71206888 Initial import
thib
parents:
diff changeset
806 nChar = 0;
223b71206888 Initial import
thib
parents:
diff changeset
807 }
223b71206888 Initial import
thib
parents:
diff changeset
808 Rect r(*surface);
223b71206888 Initial import
thib
parents:
diff changeset
809 DSurfaceMove(surface, r, surface, Rect(0, -cur_dy, 0, 0));
223b71206888 Initial import
thib
parents:
diff changeset
810 r.ty = r.by-cur_dy;
223b71206888 Initial import
thib
parents:
diff changeset
811 DSurfaceFill(surface, r, 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
812 pictext->ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
813 return;
223b71206888 Initial import
thib
parents:
diff changeset
814 }
223b71206888 Initial import
thib
parents:
diff changeset
815
223b71206888 Initial import
thib
parents:
diff changeset
816 void Text::activate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
817 event.RegisterGlobalPressFunc(&Pressed, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
818 Event::Video::activate();
223b71206888 Initial import
thib
parents:
diff changeset
819 window_activated = true;
223b71206888 Initial import
thib
parents:
diff changeset
820 if (cursor_activated && window_activated && cursor) cursor->show();
223b71206888 Initial import
thib
parents:
diff changeset
821 }
223b71206888 Initial import
thib
parents:
diff changeset
822 void Text::deactivate(void) {
223b71206888 Initial import
thib
parents:
diff changeset
823 event.DeleteGlobalPressFunc(&Pressed, (void*)this);
223b71206888 Initial import
thib
parents:
diff changeset
824 Event::Video::deactivate();
223b71206888 Initial import
thib
parents:
diff changeset
825 window_activated = false;
223b71206888 Initial import
thib
parents:
diff changeset
826 if (cursor) cursor->hide();
223b71206888 Initial import
thib
parents:
diff changeset
827 }
223b71206888 Initial import
thib
parents:
diff changeset
828 void Text::SetCursor(TimeCursor* c) {
223b71206888 Initial import
thib
parents:
diff changeset
829 cursor = c;
223b71206888 Initial import
thib
parents:
diff changeset
830 if (c) {
223b71206888 Initial import
thib
parents:
diff changeset
831 if (cursor_activated && window_activated) c->show();
223b71206888 Initial import
thib
parents:
diff changeset
832 else c->hide();
223b71206888 Initial import
thib
parents:
diff changeset
833 }
223b71206888 Initial import
thib
parents:
diff changeset
834 }
223b71206888 Initial import
thib
parents:
diff changeset
835
223b71206888 Initial import
thib
parents:
diff changeset
836 Label::Label(PicContainer* parent, const Rect& r_orig, bool _is_center, const char* text, int _text_size) :
223b71206888 Initial import
thib
parents:
diff changeset
837 is_center(_is_center),
223b71206888 Initial import
thib
parents:
diff changeset
838 root(parent->Root()),
223b71206888 Initial import
thib
parents:
diff changeset
839 text_size(_text_size) {
223b71206888 Initial import
thib
parents:
diff changeset
840 Rect r(r_orig);
223b71206888 Initial import
thib
parents:
diff changeset
841
223b71206888 Initial import
thib
parents:
diff changeset
842 if (text == 0) text = "";
223b71206888 Initial import
thib
parents:
diff changeset
843 int width = r.width(); int height = r.height();
223b71206888 Initial import
thib
parents:
diff changeset
844 if (width == 0) width = parent->Width() - r.lx;
223b71206888 Initial import
thib
parents:
diff changeset
845
223b71206888 Initial import
thib
parents:
diff changeset
846 TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, width);
223b71206888 Initial import
thib
parents:
diff changeset
847
223b71206888 Initial import
thib
parents:
diff changeset
848 if (r.width() == 0) { // 文字に合わせてウィジット作成
223b71206888 Initial import
thib
parents:
diff changeset
849 width = gs.width();
223b71206888 Initial import
thib
parents:
diff changeset
850 r.rx = r.lx + gs.width();
223b71206888 Initial import
thib
parents:
diff changeset
851 }
223b71206888 Initial import
thib
parents:
diff changeset
852 if (r.height() == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
853 r.by = r.ty + gs.height();
223b71206888 Initial import
thib
parents:
diff changeset
854 }
223b71206888 Initial import
thib
parents:
diff changeset
855
223b71206888 Initial import
thib
parents:
diff changeset
856 SetPic(parent->create_leaf(r, 0));
223b71206888 Initial import
thib
parents:
diff changeset
857
223b71206888 Initial import
thib
parents:
diff changeset
858 /* ラベル用の Surface を作る */
223b71206888 Initial import
thib
parents:
diff changeset
859 surface = parent->Root().NewSurface(r.width(), r.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
860
223b71206888 Initial import
thib
parents:
diff changeset
861 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
862 int x = 0, y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
863 if (is_center) {
223b71206888 Initial import
thib
parents:
diff changeset
864 x = (Pic()->Width() - gs.width()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
865 y = (Pic()->Height() - gs.height()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
866 }
223b71206888 Initial import
thib
parents:
diff changeset
867
223b71206888 Initial import
thib
parents:
diff changeset
868 DSurfaceRenderText(gs.begin(), gs.end(), Rect(*surface), surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
869
223b71206888 Initial import
thib
parents:
diff changeset
870 Pic()->SetSurface(surface, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
871 show();
223b71206888 Initial import
thib
parents:
diff changeset
872 }
223b71206888 Initial import
thib
parents:
diff changeset
873 Label::~Label() {
223b71206888 Initial import
thib
parents:
diff changeset
874 root.DeleteSurface(surface);
223b71206888 Initial import
thib
parents:
diff changeset
875 }
223b71206888 Initial import
thib
parents:
diff changeset
876 void Label::SetText(const char* text) {
223b71206888 Initial import
thib
parents:
diff changeset
877 if (text == 0) text = "";
223b71206888 Initial import
thib
parents:
diff changeset
878 TextGlyphStream gs = DefaultLayout(text_size)->Layout(text, Pic()->Width());
223b71206888 Initial import
thib
parents:
diff changeset
879 DSurfaceFill(surface, Rect(*surface), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
880 int x = 0, y = 0;
223b71206888 Initial import
thib
parents:
diff changeset
881 if (is_center) {
223b71206888 Initial import
thib
parents:
diff changeset
882 x = (Pic()->Width() - gs.width()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
883 y = (Pic()->Height() - gs.height()) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
884 }
223b71206888 Initial import
thib
parents:
diff changeset
885
223b71206888 Initial import
thib
parents:
diff changeset
886 DSurfaceRenderText(gs.begin(), gs.end(), Rect(*surface), surface, Rect(x,y));
223b71206888 Initial import
thib
parents:
diff changeset
887 Pic()->ReBlit();
223b71206888 Initial import
thib
parents:
diff changeset
888 }
223b71206888 Initial import
thib
parents:
diff changeset
889
223b71206888 Initial import
thib
parents:
diff changeset
890 Dialog::Dialog(Event::Container& container, PicContainer* parent, const char* text, bool with_cancel) :
223b71206888 Initial import
thib
parents:
diff changeset
891 Event::Video(container) {
223b71206888 Initial import
thib
parents:
diff changeset
892
223b71206888 Initial import
thib
parents:
diff changeset
893 int x,y;
223b71206888 Initial import
thib
parents:
diff changeset
894 status = WAIT;
223b71206888 Initial import
thib
parents:
diff changeset
895 set_func = 0;
223b71206888 Initial import
thib
parents:
diff changeset
896 set_pointer = 0;
223b71206888 Initial import
thib
parents:
diff changeset
897
223b71206888 Initial import
thib
parents:
diff changeset
898 XKFont::HorizLayout& layout = *DefaultLayout(26);
223b71206888 Initial import
thib
parents:
diff changeset
899 int dialog_width = parent->Width() / 2;
223b71206888 Initial import
thib
parents:
diff changeset
900 TextGlyphStream s_ok = layout.Layout("OK", dialog_width);
223b71206888 Initial import
thib
parents:
diff changeset
901 TextGlyphStream s_cancel = layout.Layout("取消", dialog_width);
223b71206888 Initial import
thib
parents:
diff changeset
902 TextGlyphStream s_text = layout.Layout(text, dialog_width);
223b71206888 Initial import
thib
parents:
diff changeset
903
223b71206888 Initial import
thib
parents:
diff changeset
904 Rect r_text(0, 0, s_text.width(), s_text.height());
223b71206888 Initial import
thib
parents:
diff changeset
905 Rect r_ok(0, 0, s_ok.width(), s_ok.height());
223b71206888 Initial import
thib
parents:
diff changeset
906 Rect r_cancel(0, 0, s_cancel.width(), s_cancel.height());
223b71206888 Initial import
thib
parents:
diff changeset
907
223b71206888 Initial import
thib
parents:
diff changeset
908 /* ダイアログボックスの Surface を作る */
223b71206888 Initial import
thib
parents:
diff changeset
909 int dwidth = r_text.width() + (r_text.width()/10)*2 + 6;
223b71206888 Initial import
thib
parents:
diff changeset
910 int dheight = r_text.height() + r_ok.height() + r_cancel.height()*3 + 4;
223b71206888 Initial import
thib
parents:
diff changeset
911 surface_diag = parent->Root().NewSurface(dwidth, dheight, NO_MASK); // alpha なし
223b71206888 Initial import
thib
parents:
diff changeset
912 DSurfaceFill(surface_diag, Rect(*surface_diag), 0xf0, 0xd0, 0xa0);
223b71206888 Initial import
thib
parents:
diff changeset
913 DrawBox(surface_diag, Rect(0,0,dwidth,dheight));
223b71206888 Initial import
thib
parents:
diff changeset
914
223b71206888 Initial import
thib
parents:
diff changeset
915 Surface* surface_text = parent->Root().NewSurface(r_text.width(), r_text.height(), ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
916 s_text.SetColor(0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
917 DSurfaceRenderText(s_text.begin(), s_text.end(), r_text, surface_text, Rect(0, 0, 0, 0));
223b71206888 Initial import
thib
parents:
diff changeset
918 x = r_text.width()/10 + 3;
223b71206888 Initial import
thib
parents:
diff changeset
919 y = r_cancel.height()+2;
223b71206888 Initial import
thib
parents:
diff changeset
920 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
921 parent->Root().DeleteSurface(surface_text);
223b71206888 Initial import
thib
parents:
diff changeset
922
223b71206888 Initial import
thib
parents:
diff changeset
923 /* panel をつくる */
223b71206888 Initial import
thib
parents:
diff changeset
924 x = (parent->Width()-dwidth)/2;
223b71206888 Initial import
thib
parents:
diff changeset
925 y = (parent->Height()-dheight)/2;
223b71206888 Initial import
thib
parents:
diff changeset
926 SetPic(parent->create_node(Rect(x, y, x+dwidth, y+dheight), 0));
223b71206888 Initial import
thib
parents:
diff changeset
927
223b71206888 Initial import
thib
parents:
diff changeset
928 /* ボタンを作成する */
223b71206888 Initial import
thib
parents:
diff changeset
929 /* f8d8c8 背景(明)*/
223b71206888 Initial import
thib
parents:
diff changeset
930 /* f0d0a0 背景*/
223b71206888 Initial import
thib
parents:
diff changeset
931 /* b08040 枠(明)*/
223b71206888 Initial import
thib
parents:
diff changeset
932 /* 805010 枠*/
223b71206888 Initial import
thib
parents:
diff changeset
933 /* 382018 黒*/
223b71206888 Initial import
thib
parents:
diff changeset
934 /* 9890f8 青*/
223b71206888 Initial import
thib
parents:
diff changeset
935 /* dc6448 赤*/
223b71206888 Initial import
thib
parents:
diff changeset
936 /* 各ボタンは左右にボタン幅の 1/4, 上下にボタン幅の 1/4 のマージンを持つ */
223b71206888 Initial import
thib
parents:
diff changeset
937 Rect r_btn(r_ok); r_btn.join(r_cancel);
223b71206888 Initial import
thib
parents:
diff changeset
938 int btn_width = r_btn.width() * 3 / 2;
223b71206888 Initial import
thib
parents:
diff changeset
939 int btn_height = r_btn.height() * 3 / 2;
223b71206888 Initial import
thib
parents:
diff changeset
940 surface_btn = parent->Root().NewSurface(btn_width, btn_height*4, ALPHA_MASK);
223b71206888 Initial import
thib
parents:
diff changeset
941 DSurfaceFill(surface_btn, Rect(*surface_btn), 0, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
942 s_ok.SetColor(0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
943 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
944 s_ok.SetColor(0x98, 0x90, 0xf8);
223b71206888 Initial import
thib
parents:
diff changeset
945 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
946 s_cancel.SetColor(0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
947 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
948 s_cancel.SetColor(0xdc, 0x64, 0x48);
223b71206888 Initial import
thib
parents:
diff changeset
949 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
950
223b71206888 Initial import
thib
parents:
diff changeset
951 x = (dwidth - btn_width*2) / 3;;
223b71206888 Initial import
thib
parents:
diff changeset
952 y = r_cancel.height()*3/2 + r_text.height() + 2;
223b71206888 Initial import
thib
parents:
diff changeset
953 if (!with_cancel) x = (dwidth - btn_width) / 2;
223b71206888 Initial import
thib
parents:
diff changeset
954 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
955 DrawBox(surface_diag, Rect(x-3,y-2,x+btn_width+3,y+btn_height+2));
223b71206888 Initial import
thib
parents:
diff changeset
956 b_ok->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
957 b_ok->press_func = &press_ok;
223b71206888 Initial import
thib
parents:
diff changeset
958 if (with_cancel) {
223b71206888 Initial import
thib
parents:
diff changeset
959 x += x + btn_width;
223b71206888 Initial import
thib
parents:
diff changeset
960 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
961 DrawBox(surface_diag, Rect(x-3,y-2,x+btn_width+3,y+btn_height+2));
223b71206888 Initial import
thib
parents:
diff changeset
962 b_cancel->press_pointer = (void*)this;
223b71206888 Initial import
thib
parents:
diff changeset
963 b_cancel->press_func = &press_cancel;
223b71206888 Initial import
thib
parents:
diff changeset
964 }
223b71206888 Initial import
thib
parents:
diff changeset
965
223b71206888 Initial import
thib
parents:
diff changeset
966 Pic()->SetSurface(surface_diag, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
967 Pic()->ZMove(ZMOVE_TOP);
223b71206888 Initial import
thib
parents:
diff changeset
968
223b71206888 Initial import
thib
parents:
diff changeset
969 show_all();
223b71206888 Initial import
thib
parents:
diff changeset
970 }
223b71206888 Initial import
thib
parents:
diff changeset
971 Dialog::~Dialog() {
223b71206888 Initial import
thib
parents:
diff changeset
972 PicRoot& root = PicNode()->Root();
223b71206888 Initial import
thib
parents:
diff changeset
973 SetPic(0);
223b71206888 Initial import
thib
parents:
diff changeset
974 root.DeleteSurface(surface_btn);
223b71206888 Initial import
thib
parents:
diff changeset
975 root.DeleteSurface(surface_diag);
223b71206888 Initial import
thib
parents:
diff changeset
976 return;
223b71206888 Initial import
thib
parents:
diff changeset
977 }
223b71206888 Initial import
thib
parents:
diff changeset
978
223b71206888 Initial import
thib
parents:
diff changeset
979 void Dialog::press_ok(void* pointer, Button* btn) {
223b71206888 Initial import
thib
parents:
diff changeset
980 if (pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
981 Dialog* wid = (Dialog*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
982 wid->status = OK;
223b71206888 Initial import
thib
parents:
diff changeset
983 if (wid->set_func) {
223b71206888 Initial import
thib
parents:
diff changeset
984 (*wid->set_func)(wid->set_pointer, wid);
223b71206888 Initial import
thib
parents:
diff changeset
985 }
223b71206888 Initial import
thib
parents:
diff changeset
986 }
223b71206888 Initial import
thib
parents:
diff changeset
987 }
223b71206888 Initial import
thib
parents:
diff changeset
988 void Dialog::press_cancel(void* pointer, Button* btn) {
223b71206888 Initial import
thib
parents:
diff changeset
989 if (pointer) {
223b71206888 Initial import
thib
parents:
diff changeset
990 Dialog* wid = (Dialog*)pointer;
223b71206888 Initial import
thib
parents:
diff changeset
991 wid->status = CANCEL;
223b71206888 Initial import
thib
parents:
diff changeset
992 if (wid->set_func) {
223b71206888 Initial import
thib
parents:
diff changeset
993 (*wid->set_func)(wid->set_pointer, wid);
223b71206888 Initial import
thib
parents:
diff changeset
994 }
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 void Dialog::DrawBox(Surface* s, const Rect& r) {
223b71206888 Initial import
thib
parents:
diff changeset
999 DSurfaceFill(s, Rect(r.lx, r.ty, r.rx, r.ty+1), 0x80, 0x50, 0x10);
223b71206888 Initial import
thib
parents:
diff changeset
1000 DSurfaceFill(s, Rect(r.lx, r.ty+1, r.rx, r.ty+2), 0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
1001 DSurfaceFill(s, Rect(r.lx, r.by-2, r.rx, r.by-1), 0x80, 0x50, 0x10);
223b71206888 Initial import
thib
parents:
diff changeset
1002 DSurfaceFill(s, Rect(r.lx, r.by-1, r.rx, r.by), 0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
1003
223b71206888 Initial import
thib
parents:
diff changeset
1004 DSurfaceFill(s, Rect(r.lx, r.ty, r.lx+1, r.by), 0xb0, 0x80, 0x40);
223b71206888 Initial import
thib
parents:
diff changeset
1005 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
1006 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
1007 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
1008 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
1009 DSurfaceFill(s, Rect(r.rx-1, r.ty, r.rx, r.by), 0x38, 0x20, 0x18);
223b71206888 Initial import
thib
parents:
diff changeset
1010 }
223b71206888 Initial import
thib
parents:
diff changeset
1011
223b71206888 Initial import
thib
parents:
diff changeset
1012 AnmTime::AnmTime(Event::Container& container, PicBase* _pic, int _total_time, int _all_count) :
223b71206888 Initial import
thib
parents:
diff changeset
1013 Event::Time(container),
223b71206888 Initial import
thib
parents:
diff changeset
1014 PicAnm(_pic), start_time(0), total_time(_total_time), all_count(_all_count) {
223b71206888 Initial import
thib
parents:
diff changeset
1015 status = FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1016 if (total_time == 0) total_time = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1017 }
223b71206888 Initial import
thib
parents:
diff changeset
1018 AnmTime::AnmTime(Event::Container& container, std::vector<PicBase*> _pic, int _total_time, int _all_count) :
223b71206888 Initial import
thib
parents:
diff changeset
1019 Event::Time(container),
223b71206888 Initial import
thib
parents:
diff changeset
1020 PicAnm(_pic), start_time(0), total_time(_total_time), all_count(_all_count) {
223b71206888 Initial import
thib
parents:
diff changeset
1021 status = FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1022 if (total_time == 0) total_time = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1023 }
223b71206888 Initial import
thib
parents:
diff changeset
1024 void AnmTime::Elapsed(unsigned int current_time) {
223b71206888 Initial import
thib
parents:
diff changeset
1025 if (total_time == 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
1026 if (status == FINISHED || current_time == 0) {SetWakeup(current_time+1); return;}
223b71206888 Initial import
thib
parents:
diff changeset
1027 if (start_time == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1028 start_time = current_time;
223b71206888 Initial import
thib
parents:
diff changeset
1029 Start();
223b71206888 Initial import
thib
parents:
diff changeset
1030 }
223b71206888 Initial import
thib
parents:
diff changeset
1031 unsigned int time_elapsed = current_time - start_time;
223b71206888 Initial import
thib
parents:
diff changeset
1032 if (time_elapsed < total_time) {
223b71206888 Initial import
thib
parents:
diff changeset
1033 int count = time_elapsed * all_count / total_time;
223b71206888 Initial import
thib
parents:
diff changeset
1034 Exec(count);
223b71206888 Initial import
thib
parents:
diff changeset
1035 int next_time = start_time + (count+1) * total_time / all_count;
223b71206888 Initial import
thib
parents:
diff changeset
1036 SetWakeup(next_time);
223b71206888 Initial import
thib
parents:
diff changeset
1037 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1038 Exec(all_count);
223b71206888 Initial import
thib
parents:
diff changeset
1039 Finish();
223b71206888 Initial import
thib
parents:
diff changeset
1040 status = FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1041 }
223b71206888 Initial import
thib
parents:
diff changeset
1042 return;
223b71206888 Initial import
thib
parents:
diff changeset
1043 }
223b71206888 Initial import
thib
parents:
diff changeset
1044 void AnmTime::Abort(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1045 if (status == FINISHED) return;
223b71206888 Initial import
thib
parents:
diff changeset
1046 if (start_time == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1047 Start();
223b71206888 Initial import
thib
parents:
diff changeset
1048 Exec(all_count);
223b71206888 Initial import
thib
parents:
diff changeset
1049 }
223b71206888 Initial import
thib
parents:
diff changeset
1050 if (total_time) {
223b71206888 Initial import
thib
parents:
diff changeset
1051 Finish();
223b71206888 Initial import
thib
parents:
diff changeset
1052 }
223b71206888 Initial import
thib
parents:
diff changeset
1053 status = FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1054 }
223b71206888 Initial import
thib
parents:
diff changeset
1055 bool AnmTime::IsEnd(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1056 return status == FINISHED;
223b71206888 Initial import
thib
parents:
diff changeset
1057 }
223b71206888 Initial import
thib
parents:
diff changeset
1058 AnmMove::AnmMove(Event::Container& container, PicBase* _pic, const Rect& _to, int total_time) :
223b71206888 Initial import
thib
parents:
diff changeset
1059 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1060 from(0,0), to(_to) {
223b71206888 Initial import
thib
parents:
diff changeset
1061 from.lx = _pic->PosX();
223b71206888 Initial import
thib
parents:
diff changeset
1062 from.ty = _pic->PosY();
223b71206888 Initial import
thib
parents:
diff changeset
1063 from.rx = from.lx + _pic->Width();
223b71206888 Initial import
thib
parents:
diff changeset
1064 from.by = from.ty + _pic->Height();
223b71206888 Initial import
thib
parents:
diff changeset
1065
223b71206888 Initial import
thib
parents:
diff changeset
1066 int dx = to.lx - from.lx;
223b71206888 Initial import
thib
parents:
diff changeset
1067 int dy = to.ty - from.ty;
223b71206888 Initial import
thib
parents:
diff changeset
1068 if (dx < 0) dx = -dx;
223b71206888 Initial import
thib
parents:
diff changeset
1069 if (dy < 0) dy = -dy;
223b71206888 Initial import
thib
parents:
diff changeset
1070 if (dx < dy) dx = dy;
223b71206888 Initial import
thib
parents:
diff changeset
1071 if (dx == 0) dx = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1072 SetAllCount(dx);
223b71206888 Initial import
thib
parents:
diff changeset
1073 }
223b71206888 Initial import
thib
parents:
diff changeset
1074 void AnmMove::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1075 Rect r(from);
223b71206888 Initial import
thib
parents:
diff changeset
1076 int dx = to.lx - from.lx;
223b71206888 Initial import
thib
parents:
diff changeset
1077 int dy = to.ty - from.ty;
223b71206888 Initial import
thib
parents:
diff changeset
1078 r.rmove(dx*count/all_count, dy*count/all_count);
223b71206888 Initial import
thib
parents:
diff changeset
1079 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1080 for (it=pic.begin(); it!=pic.end(); it++) (*it)->Move(r.lx, r.ty);
223b71206888 Initial import
thib
parents:
diff changeset
1081 }
223b71206888 Initial import
thib
parents:
diff changeset
1082 AnmAlpha::AnmAlpha(Event::Container& container, PicBase* _pic, int alpha_from, int alpha_to, int total_time) :
223b71206888 Initial import
thib
parents:
diff changeset
1083 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1084 from(alpha_from), to(alpha_to), alpha_r(0,0,1,1) {
223b71206888 Initial import
thib
parents:
diff changeset
1085 if (from < 0) from = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1086 if (from >= ALPHA_MAX) from = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1087 if (to < 0) to = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1088 if (to >= ALPHA_MAX) to = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1089 int c = from - to;
223b71206888 Initial import
thib
parents:
diff changeset
1090 if (c < 0) c = -c;
223b71206888 Initial import
thib
parents:
diff changeset
1091 if (c == 0) c = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1092 SetAllCount(c);
223b71206888 Initial import
thib
parents:
diff changeset
1093 }
223b71206888 Initial import
thib
parents:
diff changeset
1094 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
1095 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1096 from(alpha_from), to(alpha_to), alpha_r(0,0,1,1) {
223b71206888 Initial import
thib
parents:
diff changeset
1097 if (from < 0) from = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1098 if (from >= ALPHA_MAX) from = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1099 if (to < 0) to = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1100 if (to >= ALPHA_MAX) to = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1101 int c = from - to;
223b71206888 Initial import
thib
parents:
diff changeset
1102 if (c < 0) c = -c;
223b71206888 Initial import
thib
parents:
diff changeset
1103 if (c == 0) c = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1104 SetAllCount(c);
223b71206888 Initial import
thib
parents:
diff changeset
1105 }
223b71206888 Initial import
thib
parents:
diff changeset
1106 void AnmAlpha::Start(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1107 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1108 for (it=pic.begin(); it!=pic.end(); it++) (*it)->show();
223b71206888 Initial import
thib
parents:
diff changeset
1109 }
223b71206888 Initial import
thib
parents:
diff changeset
1110 void AnmAlpha::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1111 alpha = (from * (all_count-count) + (to-from) * count) / all_count;
223b71206888 Initial import
thib
parents:
diff changeset
1112 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1113 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(&alpha, alpha_r);
223b71206888 Initial import
thib
parents:
diff changeset
1114 }
223b71206888 Initial import
thib
parents:
diff changeset
1115 void AnmAlpha::Finish(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1116 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1117 for (it=pic.begin(); it!=pic.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1118 if (to == 0) (*it)->hide();
223b71206888 Initial import
thib
parents:
diff changeset
1119 else if (to != ALPHA_MAX) fprintf(stderr,"Warning in AnmAlpha::Finish: alpha value suddenly changed.\n");
223b71206888 Initial import
thib
parents:
diff changeset
1120 (*it)->SetSurfaceAlpha(0,Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
1121 }
223b71206888 Initial import
thib
parents:
diff changeset
1122 }
223b71206888 Initial import
thib
parents:
diff changeset
1123 AnmAlphaMove::AnmAlphaMove(Event::Container& container, PicBase* _pic) :
223b71206888 Initial import
thib
parents:
diff changeset
1124 AnmTime(container, _pic, 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1125 }
223b71206888 Initial import
thib
parents:
diff changeset
1126 void AnmAlphaMove::SetPtn(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1127 int total = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1128 std::vector<Ptn>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1129 for (it=ptns.begin(); it!=ptns.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1130 if (total < it->next_tick) total = it->next_tick;
223b71206888 Initial import
thib
parents:
diff changeset
1131 }
223b71206888 Initial import
thib
parents:
diff changeset
1132 SetAllCount(total);
223b71206888 Initial import
thib
parents:
diff changeset
1133 SetTotalTime(total);
223b71206888 Initial import
thib
parents:
diff changeset
1134 cur_count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1135 }
223b71206888 Initial import
thib
parents:
diff changeset
1136 void AnmAlphaMove::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1137 if (ptns.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
1138 if (cur_count != 0 && ptns[cur_count].next_tick > count) return;
223b71206888 Initial import
thib
parents:
diff changeset
1139 if (cur_count >= ptns.size()) return;
223b71206888 Initial import
thib
parents:
diff changeset
1140 // 次のパターンを探す
223b71206888 Initial import
thib
parents:
diff changeset
1141 // count <= it->next_tick なる条件を満たす最後の it を探す
223b71206888 Initial import
thib
parents:
diff changeset
1142 std::vector<Ptn>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1143 for (it=ptns.begin()+cur_count; it != ptns.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
1144 if (count <= it->next_tick) break;
223b71206888 Initial import
thib
parents:
diff changeset
1145 }
223b71206888 Initial import
thib
parents:
diff changeset
1146 if (it == ptns.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
1147 fprintf(stderr,"end\n");
223b71206888 Initial import
thib
parents:
diff changeset
1148 it = ptns.end() - 1;
223b71206888 Initial import
thib
parents:
diff changeset
1149 }
223b71206888 Initial import
thib
parents:
diff changeset
1150 cur_count = it - ptns.begin();
223b71206888 Initial import
thib
parents:
diff changeset
1151
223b71206888 Initial import
thib
parents:
diff changeset
1152 iterator p;
223b71206888 Initial import
thib
parents:
diff changeset
1153 for (p=pic.begin(); p!=pic.end(); p++) {
223b71206888 Initial import
thib
parents:
diff changeset
1154 // move
223b71206888 Initial import
thib
parents:
diff changeset
1155 (*p)->Move(it->pos.lx, it->pos.ty);
223b71206888 Initial import
thib
parents:
diff changeset
1156 (*p)->SetSurfacePos(it->surface_pos.lx, it->surface_pos.ty);
223b71206888 Initial import
thib
parents:
diff changeset
1157 // alpha set
223b71206888 Initial import
thib
parents:
diff changeset
1158 if (it->alpha == 0) (*p)->hide();
223b71206888 Initial import
thib
parents:
diff changeset
1159 else if (it->alpha == ALPHA_MAX) { (*p)->show(); (*p)->SetSurfaceAlpha(0, Rect(0,0)); }
223b71206888 Initial import
thib
parents:
diff changeset
1160 else { (*p)->show(); (*p)->SetSurfaceAlpha( &(it->alpha), Rect(0,0,1,1)); }
223b71206888 Initial import
thib
parents:
diff changeset
1161 }
223b71206888 Initial import
thib
parents:
diff changeset
1162 }
223b71206888 Initial import
thib
parents:
diff changeset
1163 void AnmAlphaMove::Finish(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1164 if (ptns.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
1165 if (cur_count >= ptns.size() - 1) return;
223b71206888 Initial import
thib
parents:
diff changeset
1166 cur_count = ptns.size() - 1;
223b71206888 Initial import
thib
parents:
diff changeset
1167 Exec(ptns[cur_count].next_tick); // 最後の pattern の状態にする
223b71206888 Initial import
thib
parents:
diff changeset
1168 }
223b71206888 Initial import
thib
parents:
diff changeset
1169
223b71206888 Initial import
thib
parents:
diff changeset
1170 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
1171 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1172 ptn(_ptn), alpha_r(_alpha_r)
223b71206888 Initial import
thib
parents:
diff changeset
1173 {
223b71206888 Initial import
thib
parents:
diff changeset
1174 ptn_len = alpha_r.width() * alpha_r.height();
223b71206888 Initial import
thib
parents:
diff changeset
1175 alpha = new unsigned char[ptn_len];
223b71206888 Initial import
thib
parents:
diff changeset
1176 int max_a = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1177 for (int i=0; i<ptn_len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1178 if (ptn[i] > max_a) max_a = ptn[i];
223b71206888 Initial import
thib
parents:
diff changeset
1179 }
223b71206888 Initial import
thib
parents:
diff changeset
1180 if (max_a == 0) max_a = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1181 SetAllCount(max_a);
223b71206888 Initial import
thib
parents:
diff changeset
1182 }
223b71206888 Initial import
thib
parents:
diff changeset
1183
223b71206888 Initial import
thib
parents:
diff changeset
1184 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
1185 AnmTime(container, _pic, total_time),
223b71206888 Initial import
thib
parents:
diff changeset
1186 ptn(_ptn), band(_band_width), alpha_r(_alpha_r)
223b71206888 Initial import
thib
parents:
diff changeset
1187 {
223b71206888 Initial import
thib
parents:
diff changeset
1188 ptn_len = alpha_r.width() * alpha_r.height();
223b71206888 Initial import
thib
parents:
diff changeset
1189 alpha = new unsigned char[ptn_len];
223b71206888 Initial import
thib
parents:
diff changeset
1190 if (band <= 0) band = 1;
223b71206888 Initial import
thib
parents:
diff changeset
1191 SetAllCount(ALPHA_MAX+band);
223b71206888 Initial import
thib
parents:
diff changeset
1192 }
223b71206888 Initial import
thib
parents:
diff changeset
1193
223b71206888 Initial import
thib
parents:
diff changeset
1194 void AnmPtnSolid::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1195 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1196 for (i=0; i<ptn_len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1197 if (ptn[i] <= count) alpha[i] = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1198 else alpha[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1199 }
223b71206888 Initial import
thib
parents:
diff changeset
1200 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1201 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(alpha, alpha_r);
223b71206888 Initial import
thib
parents:
diff changeset
1202 }
223b71206888 Initial import
thib
parents:
diff changeset
1203 void AnmPtnAlpha::Exec(int count) {
223b71206888 Initial import
thib
parents:
diff changeset
1204 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1205 int ptn_zero = count;
223b71206888 Initial import
thib
parents:
diff changeset
1206 int ptn_max = count - band;
223b71206888 Initial import
thib
parents:
diff changeset
1207 for (i=0; i<ptn_len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1208 if (ptn[i] >= ptn_zero) alpha[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1209 else if (ptn[i] < ptn_max) alpha[i] = ALPHA_MAX;
223b71206888 Initial import
thib
parents:
diff changeset
1210 else alpha[i] = (ptn_zero-ptn[i])*ALPHA_MAX/band;
223b71206888 Initial import
thib
parents:
diff changeset
1211 }
223b71206888 Initial import
thib
parents:
diff changeset
1212 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1213 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(alpha, alpha_r);
223b71206888 Initial import
thib
parents:
diff changeset
1214 }
223b71206888 Initial import
thib
parents:
diff changeset
1215
223b71206888 Initial import
thib
parents:
diff changeset
1216 void AnmPtnSolid::Start(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1217 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1218 for (it=pic.begin(); it!=pic.end(); it++) (*it)->show();
223b71206888 Initial import
thib
parents:
diff changeset
1219 }
223b71206888 Initial import
thib
parents:
diff changeset
1220 void AnmPtnSolid::Finish(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1221 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1222 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(0, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
1223 }
223b71206888 Initial import
thib
parents:
diff changeset
1224 void AnmPtnAlpha::Start(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1225 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1226 for (it=pic.begin(); it!=pic.end(); it++) (*it)->show();
223b71206888 Initial import
thib
parents:
diff changeset
1227 }
223b71206888 Initial import
thib
parents:
diff changeset
1228 void AnmPtnAlpha::Finish(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1229 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
1230 for (it=pic.begin(); it!=pic.end(); it++) (*it)->SetSurfaceAlpha(0, Rect(0,0));
223b71206888 Initial import
thib
parents:
diff changeset
1231 }
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 Widget の種類
223b71206888 Initial import
thib
parents:
diff changeset
1236 Mouse: マウス位置に連動する。Surface と origin が必須
223b71206888 Initial import
thib
parents:
diff changeset
1237 Panel : なにも存在しないところに張りつけていく
223b71206888 Initial import
thib
parents:
diff changeset
1238 背景張りつけも可能
223b71206888 Initial import
thib
parents:
diff changeset
1239 ButtonPanel : 無効化可能。Group の Button がカーソルに入ったら、全Button / Label が「カーソル下」状態になる
223b71206888 Initial import
thib
parents:
diff changeset
1240 同一変数を扱うボタンは原則、同一ButtonPanel の下に入ること(同期する。高速化可能)
223b71206888 Initial import
thib
parents:
diff changeset
1241 そうでない場合、ボタンの GlobalVariable フラグを立てる必要がある
223b71206888 Initial import
thib
parents:
diff changeset
1242 背景種類:Window
223b71206888 Initial import
thib
parents:
diff changeset
1243 内部の透明度と枠形を別々に指定可能。枠形は全枠、部分枠どちらの形でも可能
223b71206888 Initial import
thib
parents:
diff changeset
1244 (部分枠なら、内部的には上枠、下枠、左右枠と別 Surface で管理する)
223b71206888 Initial import
thib
parents:
diff changeset
1245 DragButton
223b71206888 Initial import
thib
parents:
diff changeset
1246 Panel 全体をドラッグし、場所変更できるボタン。
223b71206888 Initial import
thib
parents:
diff changeset
1247 Button: 無効化>通常>カーソル下>ボタン押下 のpicture / animation
223b71206888 Initial import
thib
parents:
diff changeset
1248 Toggle Button にできる(Group化すればRadioButtonにもできる)
223b71206888 Initial import
thib
parents:
diff changeset
1249 Label : 無効化>通常>カーソル下 のanimation
223b71206888 Initial import
thib
parents:
diff changeset
1250 animation は
223b71206888 Initial import
thib
parents:
diff changeset
1251 ・上への変化
223b71206888 Initial import
thib
parents:
diff changeset
1252 ・下への変化
223b71206888 Initial import
thib
parents:
diff changeset
1253 ・常時変形
223b71206888 Initial import
thib
parents:
diff changeset
1254 の3つの形式をもつ。
223b71206888 Initial import
thib
parents:
diff changeset
1255 形式は
223b71206888 Initial import
thib
parents:
diff changeset
1256 ・x / y increment による(全領域と x,y の大きさを指定すると左上から右上、左下、という方へ勝手に領域を変更していく)
223b71206888 Initial import
thib
parents:
diff changeset
1257 ・色変化(明度変化)。色テーブルを指定する。Surface は alpha のみとする
223b71206888 Initial import
thib
parents:
diff changeset
1258 どちらも、一つのラベルに使う時間の長さを指定する
223b71206888 Initial import
thib
parents:
diff changeset
1259 ・callback による。指定した一定時間以上が立つとCallBack が呼び出され、新たなSurface , origin を指定する。
223b71206888 Initial import
thib
parents:
diff changeset
1260
223b71206888 Initial import
thib
parents:
diff changeset
1261 ・Surface は
223b71206888 Initial import
thib
parents:
diff changeset
1262 普通の画像
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 Cursor
223b71206888 Initial import
thib
parents:
diff changeset
1267 リターンカーソル。Label の一種。
223b71206888 Initial import
thib
parents:
diff changeset
1268 Number
223b71206888 Initial import
thib
parents:
diff changeset
1269 数字を表示する。フォントの大きさ、もしくは画像数値列
223b71206888 Initial import
thib
parents:
diff changeset
1270 Text
223b71206888 Initial import
thib
parents:
diff changeset
1271 テキストを表示する
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 ProgressBar など
223b71206888 Initial import
thib
parents:
diff changeset
1276 バーの長さ、あるいは位置で変数の大きさを示す。
223b71206888 Initial import
thib
parents:
diff changeset
1277 Tick, Max を指定、変数の変化には適当に対応できるようにする
223b71206888 Initial import
thib
parents:
diff changeset
1278 バーの方向として縦/横。Surface は繰り返しで使う(速度上、32pixel くらいあったほうがいいかも?)
223b71206888 Initial import
thib
parents:
diff changeset
1279 バーの代わりにボタンも使える。Surface 指定のメソッドが違うだけ。
223b71206888 Initial import
thib
parents:
diff changeset
1280 オプション:バーのどこかをクリックされたとき、そこに移動するかそこに向かって移動するか
223b71206888 Initial import
thib
parents:
diff changeset
1281 オプション?:矢印ボタン(いらないか)
223b71206888 Initial import
thib
parents:
diff changeset
1282 ScrollBar
223b71206888 Initial import
thib
parents:
diff changeset
1283 横/縦。Panel と連動する(専用, ProgressBar の一種として実装)
223b71206888 Initial import
thib
parents:
diff changeset
1284 (Panel 側で「見えない部分はdelete, 見える部分は自動で作成」機能をつける?:バックログ)
223b71206888 Initial import
thib
parents:
diff changeset
1285
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 // }