1 | package Crossfire::Client::Widget; |
1 | package CFClient::Widget; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
5 | use Scalar::Util; |
5 | use Scalar::Util; |
6 | |
6 | |
7 | use SDL::OpenGL; |
7 | use SDL::OpenGL; |
8 | use SDL::OpenGL::Constants; |
8 | use SDL::OpenGL::Constants; |
9 | |
9 | |
10 | our $FOCUS; # the widget with current focus |
10 | use CFClient; |
|
|
11 | |
|
|
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
|
|
13 | |
|
|
14 | our $TOPLEVEL; |
|
|
15 | our $BUTTON_STATE; |
11 | |
16 | |
12 | # class methods for events |
17 | # class methods for events |
13 | sub feed_sdl_key_down_event { $FOCUS->key_down ($_[0]) if $FOCUS } |
18 | sub feed_sdl_key_down_event { |
14 | sub feed_sdl_key_up_event { $FOCUS->key_up ($_[0]) if $FOCUS } |
19 | $FOCUS->key_down ($_[0]) if $FOCUS; |
|
|
20 | } |
|
|
21 | |
|
|
22 | sub feed_sdl_key_up_event { |
|
|
23 | $FOCUS->key_up ($_[0]) if $FOCUS; |
|
|
24 | } |
|
|
25 | |
15 | sub feed_sdl_button_down_event { } |
26 | sub feed_sdl_button_down_event { |
|
|
27 | my ($ev) = @_; |
|
|
28 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
29 | |
|
|
30 | if (!$BUTTON_STATE) { |
|
|
31 | my $widget = $TOPLEVEL->find_widget ($x, $y); |
|
|
32 | |
|
|
33 | $GRAB = $widget; |
|
|
34 | $GRAB->update if $GRAB; |
|
|
35 | } |
|
|
36 | |
|
|
37 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
|
|
38 | |
|
|
39 | $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; |
|
|
40 | } |
|
|
41 | |
16 | sub feed_sdl_button_up_event { } |
42 | sub feed_sdl_button_up_event { |
|
|
43 | my ($ev) = @_; |
|
|
44 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
45 | |
|
|
46 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
|
|
47 | |
|
|
48 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
|
|
49 | |
|
|
50 | $GRAB->button_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; |
|
|
51 | |
|
|
52 | if (!$BUTTON_STATE) { |
|
|
53 | my $grab = $GRAB; undef $GRAB; |
|
|
54 | $grab->update if $grab; |
|
|
55 | $GRAB->update if $GRAB; |
|
|
56 | } |
|
|
57 | } |
|
|
58 | |
|
|
59 | sub feed_sdl_motion_event { |
|
|
60 | my ($ev) = @_; |
|
|
61 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
62 | |
|
|
63 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
|
|
64 | |
|
|
65 | if ($widget != $HOVER) { |
|
|
66 | my $hover = $HOVER; $HOVER = $widget; |
|
|
67 | |
|
|
68 | $hover->update if $hover; |
|
|
69 | $HOVER->update if $HOVER; |
|
|
70 | } |
|
|
71 | |
|
|
72 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
|
|
73 | } |
17 | |
74 | |
18 | sub new { |
75 | sub new { |
19 | my $class = shift; |
76 | my $class = shift; |
20 | |
77 | |
21 | bless { @_ }, $class |
78 | bless { @_ }, $class |
… | |
… | |
42 | |
99 | |
43 | $self->{w} = $w; |
100 | $self->{w} = $w; |
44 | $self->{h} = $h; |
101 | $self->{h} = $h; |
45 | } |
102 | } |
46 | |
103 | |
|
|
104 | # translate global koordinates to local coordinate system |
|
|
105 | sub translate { |
|
|
106 | my ($self, $x, $y) = @_; |
|
|
107 | |
|
|
108 | $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); |
|
|
109 | } |
|
|
110 | |
47 | sub focus_in { |
111 | sub focus_in { |
48 | my ($widget) = @_; |
112 | my ($self) = @_; |
49 | $FOCUS = $widget; |
113 | |
|
|
114 | my $focus = $FOCUS; $FOCUS = $self; |
|
|
115 | $focus->update if $focus; |
|
|
116 | $FOCUS->update; |
50 | } |
117 | } |
51 | |
118 | |
52 | sub focus_out { |
119 | sub focus_out { |
53 | my ($widget) = @_; |
120 | my ($self) = @_; |
54 | } |
|
|
55 | |
121 | |
56 | sub key_down { |
122 | return unless $FOCUS == $self; |
57 | my ($widget, $sdlev) = @_; |
|
|
58 | } |
|
|
59 | |
123 | |
60 | sub key_up { |
124 | my $focus = $FOCUS; undef $FOCUS; |
61 | my ($widget, $sdlev) = @_; |
125 | $focus->update if $focus; #? |
62 | } |
126 | } |
63 | |
127 | |
|
|
128 | sub mouse_motion { } |
|
|
129 | sub button_up { } |
64 | sub button_down { |
130 | sub button_down { } |
65 | my ($widget, $sdlev) = @_; |
131 | sub key_down { } |
66 | } |
132 | sub key_up { } |
67 | |
133 | |
68 | sub button_up { |
|
|
69 | my ($widget, $sdlev) = @_; |
|
|
70 | } |
|
|
71 | |
|
|
72 | sub w { $_[0]->{w} = $_[1] if $_[1]; $_[0]->{w} } |
134 | sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } |
73 | sub h { $_[0]->{h} = $_[1] if $_[1]; $_[0]->{h} } |
135 | sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } |
74 | sub x { $_[0]->{x} = $_[1] if $_[1]; $_[0]->{x} } |
136 | sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } |
75 | sub y { $_[0]->{y} = $_[1] if $_[1]; $_[0]->{y} } |
137 | sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } |
76 | sub z { $_[0]->{z} = $_[1] if $_[1]; $_[0]->{z} } |
138 | sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } |
77 | |
139 | |
78 | sub draw { |
140 | sub draw { |
79 | my ($self) = @_; |
141 | my ($self) = @_; |
80 | |
142 | |
81 | glPushMatrix; |
143 | glPushMatrix; |
82 | glTranslate $self->{x}, $self->{y}, 0; |
144 | glTranslate $self->{x}, $self->{y}, 0; |
83 | $self->_draw; |
145 | $self->_draw; |
|
|
146 | if ($self == $HOVER) { |
|
|
147 | glColor 1, 1, 1, 0.4; |
|
|
148 | glEnable GL_BLEND; |
|
|
149 | glBegin GL_QUADS; |
|
|
150 | glVertex 0 , 0; |
|
|
151 | glVertex $self->{w}, 0; |
|
|
152 | glVertex $self->{w}, $self->{h}; |
|
|
153 | glVertex 0 , $self->{h}; |
|
|
154 | glEnd; |
|
|
155 | glDisable GL_BLEND; |
|
|
156 | } |
84 | glPopMatrix; |
157 | glPopMatrix; |
85 | } |
158 | } |
86 | |
159 | |
87 | sub _draw { |
160 | sub _draw { |
88 | my ($self) = @_; |
161 | my ($self) = @_; |
… | |
… | |
137 | #$self->deactivate; |
210 | #$self->deactivate; |
138 | } |
211 | } |
139 | |
212 | |
140 | ############################################################################# |
213 | ############################################################################# |
141 | |
214 | |
142 | package Crossfire::Client::Widget::Container; |
215 | package CFClient::Widget::Container; |
143 | |
216 | |
144 | our @ISA = Crossfire::Client::Widget::; |
217 | our @ISA = CFClient::Widget::; |
145 | |
218 | |
146 | sub new { |
219 | sub new { |
147 | my ($class, @widgets) = @_; |
220 | my ($class, %arg) = @_; |
|
|
221 | |
|
|
222 | my $children = delete $arg{children} || []; |
148 | |
223 | |
149 | my $self = $class->SUPER::new (children => []); |
224 | my $self = $class->SUPER::new (children => []); |
150 | $self->add ($_) for @widgets; |
225 | $self->add ($_) for @$children; |
151 | |
226 | |
152 | $self |
227 | $self |
153 | } |
228 | } |
154 | |
229 | |
155 | sub add { |
230 | sub add { |
… | |
… | |
160 | |
235 | |
161 | @{$self->{children}} = |
236 | @{$self->{children}} = |
162 | sort { $a->{z} <=> $b->{z} } |
237 | sort { $a->{z} <=> $b->{z} } |
163 | @{$self->{children}}, $chld; |
238 | @{$self->{children}}, $chld; |
164 | |
239 | |
165 | $self->size_allocate ($self->{w}, $self->{h}); |
240 | $self->size_allocate ($self->{w}, $self->{h}) |
|
|
241 | if $self->{w}; #TODO: check for "realised state" |
166 | } |
242 | } |
167 | |
243 | |
168 | sub remove { |
244 | sub remove { |
169 | my ($self, $widget) = @_; |
245 | my ($self, $widget) = @_; |
170 | |
246 | |
… | |
… | |
174 | } |
250 | } |
175 | |
251 | |
176 | sub find_widget { |
252 | sub find_widget { |
177 | my ($self, $x, $y) = @_; |
253 | my ($self, $x, $y) = @_; |
178 | |
254 | |
|
|
255 | $x -= $self->{x}; |
|
|
256 | $y -= $self->{y}; |
|
|
257 | |
179 | my $res; |
258 | my $res; |
180 | |
259 | |
181 | for (@{ $self->{children} }) { |
260 | for (reverse @{ $self->{children} }) { |
182 | $res = $_->find_widget ($x, $y) |
261 | $res = $_->find_widget ($x, $y) |
183 | and return $res; |
262 | and return $res; |
184 | } |
263 | } |
185 | |
264 | |
186 | () |
265 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
187 | } |
|
|
188 | |
|
|
189 | sub size_request { |
|
|
190 | my ($self) = @_; |
|
|
191 | |
|
|
192 | my ($hs, $ws) = (0, 0); |
|
|
193 | for (@{$self->{children} || []}) { |
|
|
194 | my ($w, $h) = $_->size_request; |
|
|
195 | $hs += $h; |
|
|
196 | if ($ws < $w) { $ws = $w } |
|
|
197 | } |
|
|
198 | |
|
|
199 | return ($ws, $hs); |
|
|
200 | } |
266 | } |
201 | |
267 | |
202 | sub _draw { |
268 | sub _draw { |
203 | my ($self) = @_; |
269 | my ($self) = @_; |
204 | |
270 | |
205 | $_->draw for @{$self->{children}}; |
271 | $_->draw for @{$self->{children}}; |
206 | } |
272 | } |
207 | |
273 | |
208 | ############################################################################# |
274 | ############################################################################# |
209 | |
275 | |
210 | package Crossfire::Client::Widget::Bin; |
276 | package CFClient::Widget::Bin; |
211 | |
277 | |
212 | our @ISA = Crossfire::Client::Widget::Container::; |
278 | our @ISA = CFClient::Widget::Container::; |
213 | |
279 | |
214 | sub child { $_[0]->{children}[0] } |
280 | sub child { $_[0]->{children}[0] } |
215 | |
281 | |
216 | sub size_request { |
282 | sub size_request { |
217 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
283 | $_[0]{children}[0]->size_request if $_[0]{children}[0]; |
218 | } |
284 | } |
219 | |
285 | |
220 | sub size_allocate { |
286 | sub size_allocate { |
221 | my ($self, $w, $h) = @_; |
287 | my ($self, $w, $h) = @_; |
|
|
288 | |
222 | $self->SUPER::size_allocate ($w, $h); |
289 | $self->SUPER::size_allocate ($w, $h); |
223 | $self->{children}[0]->size_allocate ($w, $h) |
290 | $self->{children}[0]->size_allocate ($w, $h) |
224 | if $self->{children}[0] |
291 | if $self->{children}[0] |
225 | } |
292 | } |
226 | |
293 | |
227 | ############################################################################# |
294 | ############################################################################# |
228 | |
295 | |
229 | package Crossfire::Client::Widget::Toplevel; |
296 | package CFClient::Widget::Window; |
230 | |
297 | |
231 | our @ISA = Crossfire::Client::Widget::Container::; |
298 | our @ISA = CFClient::Widget::Bin::; |
|
|
299 | |
|
|
300 | use SDL::OpenGL; |
|
|
301 | |
|
|
302 | sub new { |
|
|
303 | my ($class, %arg) = @_; |
|
|
304 | |
|
|
305 | my $self = $class->SUPER::new (%arg); |
|
|
306 | } |
232 | |
307 | |
233 | sub update { |
308 | sub update { |
234 | my ($self) = @_; |
309 | my ($self) = @_; |
235 | |
310 | |
236 | ::refresh (); |
311 | # we want to do this delayed... |
237 | } |
|
|
238 | |
|
|
239 | ############################################################################# |
|
|
240 | |
|
|
241 | package Crossfire::Client::Widget::Window; |
|
|
242 | |
|
|
243 | our @ISA = Crossfire::Client::Widget::Bin::; |
|
|
244 | |
|
|
245 | use SDL::OpenGL; |
|
|
246 | |
|
|
247 | sub add { |
|
|
248 | my ($self, $chld) = @_; |
|
|
249 | warn "ADD $chld\n"; |
|
|
250 | $self->SUPER::add ($chld); |
|
|
251 | $chld->set_parent ($self); |
|
|
252 | } |
|
|
253 | |
|
|
254 | sub remove { |
|
|
255 | my ($self) = @_; |
|
|
256 | # TODO FIXME: removing a child from a window will crash, see render_chld |
|
|
257 | # $self->update; |
|
|
258 | } |
|
|
259 | |
|
|
260 | sub update { |
|
|
261 | my ($self) = @_; |
|
|
262 | $self->render_chld; |
312 | $self->render_chld; |
|
|
313 | $self->SUPER::update; |
263 | } |
314 | } |
264 | |
315 | |
265 | sub render_chld { |
316 | sub render_chld { |
266 | my ($self) = @_; |
317 | my ($self) = @_; |
267 | my $chld = $self->get; |
|
|
268 | my ($w, $h) = $self->size_request; |
|
|
269 | |
318 | |
270 | require Carp; |
|
|
271 | Carp::cluck "RENDERCHI $w $h"; |
|
|
272 | warn "RENDERCHI $w $h\n"; |
|
|
273 | $self->{texture} = |
319 | $self->{texture} = |
274 | Crossfire::Client::Texture->new_from_opengl ( |
320 | CFClient::Texture->new_from_opengl ( |
275 | $w, $h, sub { $chld->draw } |
321 | $self->{w}, $self->{h}, sub { $self->child->draw } |
276 | ); |
322 | ); |
277 | $self->{texture}->upload; |
|
|
278 | } |
|
|
279 | |
|
|
280 | sub size_request { |
|
|
281 | my ($self) = @_; |
|
|
282 | ($self->w, $self->h) |
|
|
283 | } |
323 | } |
284 | |
324 | |
285 | sub size_allocate { |
325 | sub size_allocate { |
286 | my ($self, $w, $h) = @_; |
326 | my ($self, $w, $h) = @_; |
287 | |
327 | |
288 | $self->w ($w); |
328 | $self->{w} = $w; |
289 | $self->h ($h); |
329 | $self->{h} = $h; |
|
|
330 | |
290 | $self->get->size_allocate ($w, $h); |
331 | $self->child->size_allocate ($w, $h); |
291 | |
332 | |
292 | $self->update; #TODO: Move this to the size_request event propably? |
333 | $self->render_chld; |
293 | } |
334 | } |
294 | |
335 | |
295 | sub _draw { |
336 | sub _draw { |
296 | my ($self) = @_; |
337 | my ($self) = @_; |
297 | |
338 | |
… | |
… | |
301 | or return; |
342 | or return; |
302 | |
343 | |
303 | glEnable GL_BLEND; |
344 | glEnable GL_BLEND; |
304 | glEnable GL_TEXTURE_2D; |
345 | glEnable GL_TEXTURE_2D; |
305 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
346 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
306 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
307 | |
347 | |
308 | glBegin GL_QUADS; |
348 | $tex->draw_quad (0, 0, $w, $h); |
309 | glTexCoord 0, 0; glVertex 0, 0; |
|
|
310 | glTexCoord 0, 1; glVertex 0, $h; |
|
|
311 | glTexCoord 1, 1; glVertex $w, $h; |
|
|
312 | glTexCoord 1, 0; glVertex $w, 0; |
|
|
313 | glEnd; |
|
|
314 | |
349 | |
315 | glDisable GL_BLEND; |
350 | glDisable GL_BLEND; |
316 | glDisable GL_TEXTURE_2D; |
351 | glDisable GL_TEXTURE_2D; |
317 | } |
352 | } |
318 | |
353 | |
319 | ############################################################################# |
354 | ############################################################################# |
320 | |
355 | |
321 | package Crossfire::Client::Widget::Frame; |
356 | package CFClient::Widget::Frame; |
322 | |
357 | |
323 | our @ISA = Crossfire::Client::Widget::Bin::; |
358 | our @ISA = CFClient::Widget::Bin::; |
324 | |
359 | |
325 | use SDL::OpenGL; |
360 | use SDL::OpenGL; |
326 | |
361 | |
327 | sub size_request { |
362 | sub size_request { |
328 | my ($self) = @_; |
363 | my ($self) = @_; |
… | |
… | |
334 | map { $_ + 4 } $chld->size_request; |
369 | map { $_ + 4 } $chld->size_request; |
335 | } |
370 | } |
336 | |
371 | |
337 | sub size_allocate { |
372 | sub size_allocate { |
338 | my ($self, $w, $h) = @_; |
373 | my ($self, $w, $h) = @_; |
339 | |
374 | |
340 | $self->w ($w); |
375 | $self->{w} = $w; |
341 | $self->h ($h); |
376 | $self->{h} = $h; |
342 | |
377 | |
343 | $self->child->size_allocate ($w - 4, $h - 4); |
378 | $self->child->size_allocate ($w - 4, $h - 4); |
344 | $self->child->move (2, 2); |
379 | $self->child->move (2, 2); |
345 | } |
380 | } |
346 | |
381 | |
… | |
… | |
351 | |
386 | |
352 | my ($w, $h) = $chld->size_request; |
387 | my ($w, $h) = $chld->size_request; |
353 | |
388 | |
354 | glBegin GL_QUADS; |
389 | glBegin GL_QUADS; |
355 | glColor 0, 0, 0; |
390 | glColor 0, 0, 0; |
356 | glTexCoord 0, 0; glVertex 0 , 0; |
391 | glVertex 0 , 0; |
357 | glTexCoord 0, 1; glVertex 0 , $h + 4; |
392 | glVertex 0 , $h + 4; |
358 | glTexCoord 1, 1; glVertex $w + 4 , $h + 4; |
393 | glVertex $w + 4 , $h + 4; |
359 | glTexCoord 1, 0; glVertex $w + 4 , 0; |
394 | glVertex $w + 4 , 0; |
360 | glEnd; |
395 | glEnd; |
361 | |
396 | |
362 | $chld->draw; |
397 | $chld->draw; |
363 | } |
398 | } |
364 | |
399 | |
365 | ############################################################################# |
400 | ############################################################################# |
366 | |
401 | |
367 | package Crossfire::Client::Widget::FancyFrame; |
402 | package CFClient::Widget::FancyFrame; |
368 | |
403 | |
369 | our @ISA = Crossfire::Client::Widget::Frame::; |
404 | our @ISA = CFClient::Widget::Bin::; |
370 | |
405 | |
371 | use SDL::OpenGL; |
406 | use SDL::OpenGL; |
372 | |
407 | |
373 | sub new { |
408 | my @tex = |
374 | my ($self, $theme) = @_; |
|
|
375 | $self = $self->SUPER::new; |
|
|
376 | |
|
|
377 | $self->{txts} = [ |
|
|
378 | map { new_from_file Crossfire::Client::Texture Crossfire::Client::find_rcfile $_ } |
409 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
379 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png) |
410 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
380 | ]; |
|
|
381 | $self |
|
|
382 | } |
|
|
383 | |
411 | |
384 | sub size_request { |
412 | sub size_request { |
385 | my ($self) = @_; |
413 | my ($self) = @_; |
386 | |
414 | |
387 | my ($w, $h) = $self->SUPER::size_request; |
415 | my ($w, $h) = $self->SUPER::size_request; |
388 | |
416 | |
389 | $h += $self->{txts}->[1]->{height}; |
417 | $h += $tex[1]->{height}; |
390 | $h += $self->{txts}->[4]->{height}; |
418 | $h += $tex[4]->{height}; |
391 | $w += $self->{txts}->[2]->{width}; |
419 | $w += $tex[2]->{width}; |
392 | $w += $self->{txts}->[3]->{width}; |
420 | $w += $tex[3]->{width}; |
393 | |
421 | |
394 | ($w, $h) |
422 | ($w, $h) |
395 | } |
423 | } |
396 | |
424 | |
397 | sub size_allocate { |
425 | sub size_allocate { |
398 | my ($self, $w, $h) = @_; |
426 | my ($self, $w, $h) = @_; |
399 | |
427 | |
400 | $self->SUPER::size_allocate ($w, $h); |
428 | $self->SUPER::size_allocate ($w, $h); |
401 | |
429 | |
402 | $h -= $self->{txts}->[1]->{height}; |
430 | $h -= $tex[1]->{height}; |
403 | $h -= $self->{txts}->[4]->{height}; |
431 | $h -= $tex[4]->{height}; |
404 | $w -= $self->{txts}->[2]->{width}; |
432 | $w -= $tex[2]->{width}; |
405 | $w -= $self->{txts}->[3]->{width}; |
433 | $w -= $tex[3]->{width}; |
406 | |
434 | |
407 | $h = $h < 0 ? 0 : $h; |
435 | $h = $h < 0 ? 0 : $h; |
408 | $w = $w < 0 ? 0 : $w; |
436 | $w = $w < 0 ? 0 : $w; |
409 | warn "CHILD:$w $h\n"; |
437 | |
410 | $self->child->size_allocate ($w, $h); |
438 | $self->child->size_allocate ($w, $h); |
411 | $self->child->move ($self->{txts}->[3]->{width}, $self->{txts}->[1]->{height}); |
439 | $self->child->move ($tex[3]->{width}, $tex[1]->{height}); |
412 | } |
440 | } |
413 | |
441 | |
414 | sub _draw { |
442 | sub _draw { |
415 | my ($self) = @_; |
443 | my ($self) = @_; |
416 | |
444 | |
417 | my ($w, $h) = ($self->w, $self->h); |
445 | my ($w, $h) = ($self->{w}, $self->{h}); |
418 | my ($cw, $ch) = ($self->child->w, $self->child->h); |
446 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
419 | |
447 | |
420 | glEnable GL_BLEND; |
448 | glEnable GL_BLEND; |
421 | glEnable GL_TEXTURE_2D; |
449 | glEnable GL_TEXTURE_2D; |
422 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
450 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
423 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
451 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
424 | |
452 | |
425 | my $top = $self->{txts}->[1]; |
453 | my $top = $tex[1]; |
426 | glBindTexture GL_TEXTURE_2D, $top->{name}; |
454 | $top->draw_quad (0, 0, $w, $top->{height}); |
427 | |
455 | |
428 | glBegin GL_QUADS; |
|
|
429 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
430 | glTexCoord 0, 1; glVertex 0 , $top->{height}; |
|
|
431 | glTexCoord 1, 1; glVertex $w , $top->{height}; |
|
|
432 | glTexCoord 1, 0; glVertex $w , 0; |
|
|
433 | glEnd; |
|
|
434 | |
|
|
435 | my $left = $self->{txts}->[3]; |
456 | my $left = $tex[3]; |
436 | glBindTexture GL_TEXTURE_2D, $left->{name}; |
457 | $left->draw_quad (0, $top->{height}, $left->{width}, $ch); |
437 | |
458 | |
438 | glBegin GL_QUADS; |
|
|
439 | glTexCoord 0, 0; glVertex 0 , $top->{height}; |
|
|
440 | glTexCoord 0, 1; glVertex 0 , $top->{height} + $ch; |
|
|
441 | glTexCoord 1, 1; glVertex $left->{width}, $top->{height} + $ch; |
|
|
442 | glTexCoord 1, 0; glVertex $left->{width}, $top->{height}; |
|
|
443 | glEnd; |
|
|
444 | |
|
|
445 | my $right = $self->{txts}->[2]; |
459 | my $right = $tex[2]; |
446 | glBindTexture GL_TEXTURE_2D, $right->{name}; |
460 | $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch); |
447 | |
461 | |
448 | glBegin GL_QUADS; |
|
|
449 | glTexCoord 0, 0; glVertex $w - $right->{width}, $top->{height}; |
|
|
450 | glTexCoord 0, 1; glVertex $w - $right->{width}, $top->{height} + $ch; |
|
|
451 | glTexCoord 1, 1; glVertex $w , $top->{height} + $ch; |
|
|
452 | glTexCoord 1, 0; glVertex $w , $top->{height}; |
|
|
453 | glEnd; |
|
|
454 | |
|
|
455 | my $bottom = $self->{txts}->[4]; |
462 | my $bottom = $tex[4]; |
456 | glBindTexture GL_TEXTURE_2D, $bottom->{name}; |
463 | $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height}); |
457 | |
464 | |
458 | glBegin GL_QUADS; |
465 | my $bg = $tex[0]; |
459 | glTexCoord 0, 0; glVertex 0 , $h - $bottom->{height}; |
|
|
460 | glTexCoord 0, 1; glVertex 0 , $h; |
|
|
461 | glTexCoord 1, 1; glVertex $w , $h; |
|
|
462 | glTexCoord 1, 0; glVertex $w , $h - $bottom->{height}; |
|
|
463 | glEnd; |
|
|
464 | |
|
|
465 | my $bg = $self->{txts}->[0]; |
|
|
466 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
466 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
467 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
467 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
468 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
468 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
469 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
469 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
470 | |
470 | |
471 | my $rep_x = $cw / $bg->{width}; |
471 | my $rep_x = $cw / $bg->{width}; |
472 | my $rep_y = $ch / $bg->{height}; |
472 | my $rep_y = $ch / $bg->{height}; |
473 | |
473 | |
474 | glBegin GL_QUADS; |
474 | $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch); |
475 | glTexCoord 0, 0; glVertex $left->{width}, $top->{height}; |
|
|
476 | glTexCoord 0, $rep_y; glVertex $left->{width}, $top->{height} + $ch; |
|
|
477 | glTexCoord $rep_x, $rep_y; glVertex $left->{width} + $cw , $top->{height} + $ch; |
|
|
478 | glTexCoord $rep_x, 0; glVertex $left->{width} + $cw , $top->{height}; |
|
|
479 | glEnd; |
|
|
480 | |
475 | |
481 | glDisable GL_BLEND; |
476 | glDisable GL_BLEND; |
482 | glDisable GL_TEXTURE_2D; |
477 | glDisable GL_TEXTURE_2D; |
483 | |
478 | |
484 | $self->child->draw; |
479 | $self->child->draw; |
485 | |
480 | |
486 | } |
481 | } |
487 | |
482 | |
488 | ############################################################################# |
483 | ############################################################################# |
489 | |
484 | |
490 | package Crossfire::Client::Widget::Table; |
485 | package CFClient::Widget::Table; |
491 | |
486 | |
492 | our @ISA = Crossfire::Client::Widget::Bin::; |
487 | our @ISA = CFClient::Widget::Bin::; |
493 | |
488 | |
494 | use SDL::OpenGL; |
489 | use SDL::OpenGL; |
495 | |
490 | |
496 | sub add { |
491 | sub add { |
497 | my ($self, $x, $y, $chld) = @_; |
492 | my ($self, $x, $y, $chld) = @_; |
… | |
… | |
572 | } |
567 | } |
573 | } |
568 | } |
574 | |
569 | |
575 | ############################################################################# |
570 | ############################################################################# |
576 | |
571 | |
577 | package Crossfire::Client::Widget::VBox; |
572 | package CFClient::Widget::VBox; |
578 | |
573 | |
579 | our @ISA = Crossfire::Client::Widget::Container::; |
574 | our @ISA = CFClient::Widget::Container::; |
580 | |
575 | |
581 | use SDL::OpenGL; |
576 | use SDL::OpenGL; |
|
|
577 | |
|
|
578 | sub size_request { |
|
|
579 | my ($self) = @_; |
|
|
580 | |
|
|
581 | my @alloc = map [$_->size_request], @{$self->{children}}; |
|
|
582 | |
|
|
583 | ( |
|
|
584 | (List::Util::max map $_->[0], @alloc), |
|
|
585 | (List::Util::sum map $_->[1], @alloc), |
|
|
586 | ) |
|
|
587 | } |
582 | |
588 | |
583 | sub size_allocate { |
589 | sub size_allocate { |
584 | my ($self, $w, $h) = @_; |
590 | my ($self, $w, $h) = @_; |
585 | |
591 | |
586 | $self->w ($w); |
592 | $self->w ($w); |
… | |
… | |
619 | $y += $h; |
625 | $y += $h; |
620 | } |
626 | } |
621 | } |
627 | } |
622 | } |
628 | } |
623 | |
629 | |
624 | sub _draw { |
|
|
625 | my ($self) = @_; |
|
|
626 | |
|
|
627 | my ($x, $y); |
|
|
628 | for (@{$self->{children} || []}) { |
|
|
629 | $_->draw; |
|
|
630 | $y += $_->h; |
|
|
631 | } |
|
|
632 | } |
|
|
633 | |
|
|
634 | ############################################################################# |
630 | ############################################################################# |
635 | |
631 | |
636 | package Crossfire::Client::Widget::Label; |
632 | package CFClient::Widget::Label; |
637 | |
633 | |
638 | our @ISA = Crossfire::Client::Widget::; |
634 | our @ISA = CFClient::Widget::; |
639 | |
635 | |
640 | use SDL::OpenGL; |
636 | use SDL::OpenGL; |
641 | |
637 | |
642 | sub new { |
638 | sub new { |
643 | my ($class, $x, $y, $z, $height, $text) = @_; |
639 | my ($class, %arg) = @_; |
644 | |
640 | |
645 | # TODO: color, and make height, xyz etc. optional |
641 | # TODO: color, and make height, xyz etc. optional |
646 | my $self = $class->SUPER::new (x => $x, y => $y, z => $z, height => $height); |
642 | my $self = $class->SUPER::new ( |
|
|
643 | color => [1, 1, 1], |
|
|
644 | height => $::FONTSIZE, |
|
|
645 | text => "", |
|
|
646 | layout => new CFClient::Layout, |
|
|
647 | %arg |
|
|
648 | ); |
647 | |
649 | |
648 | $self->set_text ($text); |
650 | $self->set_text ($self->{text}); |
649 | |
651 | |
650 | $self |
652 | $self |
651 | } |
653 | } |
652 | |
654 | |
653 | sub set_text { |
655 | sub set_text { |
654 | my ($self, $text) = @_; |
656 | my ($self, $text) = @_; |
655 | |
657 | |
656 | $self->{text} = $text; |
658 | $self->{text} = $text; |
657 | $self->{texture} = new_from_text Crossfire::Client::Texture $text, $self->{height}; |
659 | $self->{layout}->set_markup ($text); |
658 | |
660 | |
659 | $self->update; |
661 | delete $self->{texture}; |
660 | } |
662 | } |
661 | |
663 | |
662 | sub get_text { |
664 | sub get_text { |
663 | my ($self, $text) = @_; |
665 | my ($self, $text) = @_; |
664 | |
666 | |
… | |
… | |
666 | } |
668 | } |
667 | |
669 | |
668 | sub size_request { |
670 | sub size_request { |
669 | my ($self) = @_; |
671 | my ($self) = @_; |
670 | |
672 | |
671 | ( |
673 | $self->{layout}->set_width; |
|
|
674 | $self->{layout}->set_height ($self->{height}); |
|
|
675 | $self->{layout}->size |
|
|
676 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
|
|
677 | # ( |
672 | $self->{texture}{width}, |
678 | # $self->{texture}{width}, |
673 | $self->{texture}{height}, |
679 | # $self->{texture}{height}, |
674 | ) |
680 | # ) |
|
|
681 | # } else { |
|
|
682 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; |
|
|
683 | # |
|
|
684 | # ($w, $h) |
|
|
685 | # } |
|
|
686 | } |
|
|
687 | |
|
|
688 | sub size_allocate { |
|
|
689 | my ($self, $w, $h) = @_; |
|
|
690 | |
|
|
691 | $self->SUPER::size_allocate ($w, $h); |
|
|
692 | delete $self->{texture}; |
675 | } |
693 | } |
676 | |
694 | |
677 | sub _draw { |
695 | sub _draw { |
678 | my ($self) = @_; |
696 | my ($self) = @_; |
679 | |
697 | |
680 | my $tex = $self->{texture}; |
698 | my $tex = $self->{texture} ||= do { |
|
|
699 | $self->{layout}->set_width ($self->{w}); |
|
|
700 | new_from_layout CFClient::Texture $self->{layout}; |
|
|
701 | }; |
681 | |
702 | |
682 | glEnable GL_BLEND; |
703 | glEnable GL_BLEND; |
683 | glEnable GL_TEXTURE_2D; |
704 | glEnable GL_TEXTURE_2D; |
684 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
705 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
685 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
706 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
686 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
687 | |
707 | |
688 | glColor 1, 0, 0, 1; # TODO color |
708 | glColor @{$self->{color}}; |
689 | |
709 | |
690 | glBegin GL_QUADS; |
710 | $tex->draw_quad (0, 0); |
691 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
692 | glTexCoord 0, 1; glVertex 0 , $tex->{height}; |
|
|
693 | glTexCoord 1, 1; glVertex $tex->{width}, $tex->{height}; |
|
|
694 | glTexCoord 1, 0; glVertex $tex->{width}, 0; |
|
|
695 | glEnd; |
|
|
696 | |
711 | |
697 | glDisable GL_BLEND; |
712 | glDisable GL_BLEND; |
698 | glDisable GL_TEXTURE_2D; |
713 | glDisable GL_TEXTURE_2D; |
699 | } |
714 | } |
700 | |
715 | |
701 | ############################################################################# |
716 | ############################################################################# |
702 | |
717 | |
703 | package Crossfire::Client::Widget::TextEntry; |
718 | package CFClient::Widget::Entry; |
704 | |
719 | |
705 | our @ISA = Crossfire::Client::Widget::Label::; |
720 | our @ISA = CFClient::Widget::Label::; |
706 | |
721 | |
707 | use SDL; |
722 | use SDL; |
708 | use SDL::OpenGL; |
723 | use SDL::OpenGL; |
709 | |
724 | |
710 | sub key_down { |
725 | sub key_down { |
711 | my ($self, $ev) = @_; |
726 | my ($self, $ev) = @_; |
712 | |
727 | |
713 | my $mod = $ev->key_mod; |
728 | my $mod = $ev->key_mod; |
714 | my $sym = $ev->key_sym; |
729 | my $sym = $ev->key_sym; |
715 | |
730 | |
716 | $ev->set_unicode (1); |
|
|
717 | my $uni = $ev->key_unicode; |
731 | my $uni = $ev->key_unicode; |
718 | |
732 | |
719 | my $text = $self->get_text; |
733 | my $text = $self->get_text; |
720 | |
734 | |
721 | if ($sym == SDLK_BACKSPACE) { |
735 | if ($sym == SDLK_BACKSPACE) { |
722 | substr $text, -1, 1, ''; |
736 | substr $text, -1, 1, ''; |
723 | |
|
|
724 | } elsif ($uni) { |
737 | } elsif ($uni) { |
725 | $text .= chr $uni; |
738 | $text .= chr $uni; |
726 | } |
739 | } |
|
|
740 | |
727 | $self->set_text ($text); |
741 | $self->set_text ($text); |
728 | } |
742 | } |
729 | |
743 | |
730 | ############################################################################# |
744 | sub button_down { |
|
|
745 | my ($self, $ev) = @_; |
731 | |
746 | |
|
|
747 | $self->focus_in; |
|
|
748 | } |
|
|
749 | |
|
|
750 | sub mouse_motion { |
|
|
751 | my ($self, $ev, $x, $y) = @_; |
|
|
752 | printf "M %d,%d %d,%d\n", $ev->motion_x, $ev->motion_y, $x, $y;#d# |
|
|
753 | } |
|
|
754 | |
|
|
755 | sub _draw { |
|
|
756 | my ($self) = @_; |
|
|
757 | |
|
|
758 | if ($FOCUS == $self) { |
|
|
759 | glColor 1, 1, 1; |
|
|
760 | } else { |
|
|
761 | glColor 0.7, 0.7, 0.7; |
|
|
762 | } |
|
|
763 | |
|
|
764 | glBegin GL_QUADS; |
|
|
765 | glVertex 0 , 0; |
|
|
766 | glVertex 0 , $self->{h} - 1; |
|
|
767 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
768 | glVertex $self->{w} - 1, 0; |
|
|
769 | glEnd; |
|
|
770 | |
|
|
771 | $self->SUPER::_draw; |
|
|
772 | } |
|
|
773 | |
|
|
774 | ############################################################################# |
|
|
775 | |
732 | package Crossfire::Client::Widget::MapWidget; |
776 | package CFClient::Widget::MapWidget; |
733 | |
777 | |
734 | use strict; |
778 | use strict; |
735 | |
779 | |
736 | use List::Util qw(min max); |
780 | use List::Util qw(min max); |
737 | |
781 | |
738 | use SDL; |
782 | use SDL; |
739 | use SDL::OpenGL; |
783 | use SDL::OpenGL; |
740 | use SDL::OpenGL::Constants; |
784 | use SDL::OpenGL::Constants; |
741 | |
785 | |
742 | our @ISA = Crossfire::Client::Widget::; |
786 | our @ISA = CFClient::Widget::; |
|
|
787 | |
|
|
788 | sub new { |
|
|
789 | my $class = shift; |
|
|
790 | |
|
|
791 | $class->SUPER::new (z => -1, @_) |
|
|
792 | } |
743 | |
793 | |
744 | sub key_down { |
794 | sub key_down { |
745 | print "MAPKEYDOWN\n"; |
795 | print "MAPKEYDOWN\n"; |
746 | } |
796 | } |
747 | |
797 | |
748 | sub key_up { |
798 | sub key_up { |
749 | } |
799 | } |
750 | |
800 | |
751 | sub size_request { |
801 | sub size_request { |
752 | |
802 | ( |
753 | } |
803 | 1 + int $::WIDTH / 32, |
754 | |
804 | 1 + int $::HEIGHT / 32, |
755 | sub size_allocate { |
805 | ) |
756 | } |
806 | } |
757 | |
807 | |
758 | sub _draw { |
808 | sub _draw { |
759 | my ($self) = @_; |
809 | my ($self) = @_; |
760 | |
810 | |
… | |
… | |
783 | glEnable GL_TEXTURE_2D; |
833 | glEnable GL_TEXTURE_2D; |
784 | glEnable GL_BLEND; |
834 | glEnable GL_BLEND; |
785 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
835 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
786 | |
836 | |
787 | my $sw4 = ($sw + 3) & ~3; |
837 | my $sw4 = ($sw + 3) & ~3; |
788 | my $lighting = "\x00" x ($sw4 * $sh); |
838 | my $darkness = "\x00" x ($sw4 * $sh); |
789 | |
839 | |
790 | for my $x (0 .. $sw - 1) { |
840 | for my $x (0 .. $sw - 1) { |
|
|
841 | my $row = $map->[$x + $xofs]; |
791 | for my $y (0 .. $sh - 1) { |
842 | for my $y (0 .. $sh - 1) { |
792 | |
843 | |
793 | my $cell = $map->[$x + $xofs][$y + $yofs] |
844 | my $cell = $row->[$y + $yofs] |
794 | or next; |
845 | or next; |
795 | |
846 | |
796 | my $darkness = $cell->[0] * (1 / 255); |
847 | my $dark = $cell->[0]; |
797 | if ($darkness < 0) { |
848 | if ($dark < 0) { |
798 | $darkness = 0.15; |
849 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
850 | } else { |
|
|
851 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
799 | } |
852 | } |
800 | substr $lighting, $y * $sw4 + $x, 1, chr 255 - $darkness * 255; |
|
|
801 | |
853 | |
802 | for my $num (grep $_, @$cell[1,2,3]) { |
854 | for my $num (grep $_, @$cell[1,2,3]) { |
803 | my $tex = $::CONN->{face}[$num]{texture} || next; |
855 | my $tex = $::CONN->{face}[$num]{texture} || next; |
804 | |
856 | |
805 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
806 | |
|
|
807 | my $w = $tex->{width}; |
857 | my $w = $tex->{width}; |
808 | my $h = $tex->{height}; |
858 | my $h = $tex->{height}; |
809 | |
859 | |
810 | my $px = ($x + 1) * 32 - $w; |
860 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
811 | my $py = ($y + 1) * 32 - $h; |
|
|
812 | |
|
|
813 | glBegin GL_QUADS; |
|
|
814 | glTexCoord 0, 0; glVertex $px , $py; |
|
|
815 | glTexCoord 0, 1; glVertex $px , $py + $h; |
|
|
816 | glTexCoord 1, 1; glVertex $px + $w, $py + $h; |
|
|
817 | glTexCoord 1, 0; glVertex $px + $w, $py; |
|
|
818 | glEnd; |
|
|
819 | } |
861 | } |
820 | } |
862 | } |
821 | } |
863 | } |
822 | |
864 | |
823 | # if (1) { # higher quality darkness |
865 | # if (1) { # higher quality darkness |
… | |
… | |
828 | # |
870 | # |
829 | # $lighting = $pb->get_pixels; |
871 | # $lighting = $pb->get_pixels; |
830 | # $lighting =~ s/(.)../$1/gs; |
872 | # $lighting =~ s/(.)../$1/gs; |
831 | # } |
873 | # } |
832 | |
874 | |
833 | $lighting = new Crossfire::Client::Texture |
875 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
876 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
877 | |
|
|
878 | $darkness = new CFClient::Texture |
834 | width => $sw4, |
879 | width => $sw4, |
835 | height => $sh, |
880 | height => $sh, |
836 | data => $lighting, |
881 | data => $darkness, |
837 | internalformat => GL_ALPHA4, |
882 | internalformat => GL_ALPHA, |
838 | format => GL_ALPHA; |
883 | format => GL_ALPHA; |
839 | |
884 | |
840 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
885 | glColor 0.45, 0.45, 0.45, 1; |
841 | glColor 0, 0, 0, 0.75; |
886 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
842 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
843 | glBindTexture GL_TEXTURE_2D, $lighting->{name}; |
|
|
844 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
|
|
845 | glBegin GL_QUADS; |
|
|
846 | glTexCoord 0, 0; glVertex 0 , 0; |
|
|
847 | glTexCoord 0, 1; glVertex 0 , $sh * 32; |
|
|
848 | glTexCoord 1, 1; glVertex $sw4 * 32, $sh * 32; |
|
|
849 | glTexCoord 1, 0; glVertex $sw4 * 32, 0; |
|
|
850 | glEnd; |
|
|
851 | |
887 | |
852 | glDisable GL_TEXTURE_2D; |
888 | glDisable GL_TEXTURE_2D; |
853 | glDisable GL_BLEND; |
889 | glDisable GL_BLEND; |
854 | } |
890 | } |
855 | |
891 | |
… | |
… | |
904 | } |
940 | } |
905 | } |
941 | } |
906 | |
942 | |
907 | ############################################################################# |
943 | ############################################################################# |
908 | |
944 | |
909 | package Crossfire::Client::Widget::Animator; |
945 | package CFClient::Widget::Animator; |
910 | |
946 | |
911 | use SDL::OpenGL; |
947 | use SDL::OpenGL; |
912 | |
948 | |
913 | our @ISA = Crossfire::Client::Widget::Bin::; |
949 | our @ISA = CFClient::Widget::Bin::; |
914 | |
950 | |
915 | sub moveto { |
951 | sub moveto { |
916 | my ($self, $x, $y) = @_; |
952 | my ($self, $x, $y) = @_; |
917 | |
953 | |
918 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
954 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
919 | $self->{speed} = 0.2; |
955 | $self->{speed} = 0.001; |
920 | $self->{time} = 1; |
956 | $self->{time} = 1; |
921 | |
957 | |
922 | ::animation_start $self; |
958 | ::animation_start $self; |
923 | } |
959 | } |
924 | |
960 | |
… | |
… | |
939 | |
975 | |
940 | sub _draw { |
976 | sub _draw { |
941 | my ($self) = @_; |
977 | my ($self) = @_; |
942 | |
978 | |
943 | glPushMatrix; |
979 | glPushMatrix; |
944 | glRotate $self->{time} * 10000, 0, 1, 0; |
980 | glRotate $self->{time} * 1000, 0, 1, 0; |
945 | $self->{children}[0]->draw; |
981 | $self->{children}[0]->draw; |
946 | glPopMatrix; |
982 | glPopMatrix; |
947 | } |
983 | } |
948 | |
984 | |
949 | 1; |
985 | ############################################################################# |
950 | |
986 | |
|
|
987 | package CFClient::Widget::Toplevel; |
|
|
988 | |
|
|
989 | our @ISA = CFClient::Widget::Container::; |
|
|
990 | |
|
|
991 | sub size_request { |
|
|
992 | ($::WIDTH, $::HEIGHT) |
|
|
993 | } |
|
|
994 | |
|
|
995 | sub size_allocate { |
|
|
996 | my ($self, $w, $h) = @_; |
|
|
997 | |
|
|
998 | $self->SUPER::size_allocate ($w, $h); |
|
|
999 | |
|
|
1000 | $_->size_allocate ($_->size_request) |
|
|
1001 | for @{$self->{children}}; |
|
|
1002 | } |
|
|
1003 | |
|
|
1004 | sub translate { |
|
|
1005 | my ($self, $x, $y) = @_; |
|
|
1006 | |
|
|
1007 | ($x, $y) |
|
|
1008 | } |
|
|
1009 | |
|
|
1010 | sub update { |
|
|
1011 | my ($self) = @_; |
|
|
1012 | |
|
|
1013 | $self->size_allocate ($self->size_request); |
|
|
1014 | ::refresh (); |
|
|
1015 | } |
|
|
1016 | |
|
|
1017 | sub add { |
|
|
1018 | my ($self, $widget) = @_; |
|
|
1019 | |
|
|
1020 | $self->SUPER::add ($widget); |
|
|
1021 | |
|
|
1022 | $widget->size_allocate ($widget->size_request); |
|
|
1023 | } |
|
|
1024 | |
|
|
1025 | sub draw { |
|
|
1026 | my ($self) = @_; |
|
|
1027 | |
|
|
1028 | $self->_draw; |
|
|
1029 | } |
|
|
1030 | |
|
|
1031 | ############################################################################# |
|
|
1032 | |
|
|
1033 | package CFClient::Widget; |
|
|
1034 | |
|
|
1035 | $TOPLEVEL = new CFClient::Widget::Toplevel; |
|
|
1036 | |
|
|
1037 | 1 |
|
|
1038 | |