1 | package CFClient::Widget; |
1 | package CFClient::UI; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | |
4 | |
5 | use Scalar::Util; |
5 | use Scalar::Util (); |
6 | |
6 | use List::Util (); |
7 | use SDL::OpenGL; |
|
|
8 | use SDL::OpenGL::Constants; |
|
|
9 | |
7 | |
10 | use CFClient; |
8 | use CFClient; |
11 | |
9 | |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
13 | |
11 | |
… | |
… | |
70 | } |
68 | } |
71 | |
69 | |
72 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
70 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
73 | } |
71 | } |
74 | |
72 | |
|
|
73 | ############################################################################# |
|
|
74 | |
|
|
75 | package CFClient::UI::Base; |
|
|
76 | |
|
|
77 | use strict; |
|
|
78 | |
|
|
79 | use SDL::OpenGL; |
|
|
80 | |
75 | sub new { |
81 | sub new { |
76 | my $class = shift; |
82 | my $class = shift; |
77 | |
83 | |
78 | bless { |
84 | bless { |
79 | x => 0, |
85 | x => 0, |
80 | y => 0, |
86 | y => 0, |
81 | z => 0, |
87 | z => 0, |
|
|
88 | w => -1, |
|
|
89 | h => -1, |
82 | @_ |
90 | @_ |
83 | }, $class |
91 | }, $class |
84 | } |
92 | } |
85 | |
93 | |
86 | sub move { |
94 | sub move { |
… | |
… | |
97 | sub size_request { |
105 | sub size_request { |
98 | require Carp; |
106 | require Carp; |
99 | Carp::confess "size_request is abtract"; |
107 | Carp::confess "size_request is abtract"; |
100 | } |
108 | } |
101 | |
109 | |
102 | sub size_allocate { |
110 | sub _size_allocate { |
103 | my ($self, $w, $h) = @_; |
111 | my ($self, $x, $y, $w, $h) = @_; |
|
|
112 | |
|
|
113 | $self->{x} = $x; |
|
|
114 | $self->{y} = $y; |
|
|
115 | |
|
|
116 | return unless $self->{w} != $w || $self->{h} != $h; |
104 | |
117 | |
105 | $self->{w} = $w; |
118 | $self->{w} = $w; |
106 | $self->{h} = $h; |
119 | $self->{h} = $h; |
|
|
120 | |
|
|
121 | 1 |
|
|
122 | } |
|
|
123 | |
|
|
124 | sub size_allocate { |
|
|
125 | my ($self, $x, $y, $w, $h) = @_; |
|
|
126 | |
|
|
127 | $self->_size_allocate ($x, $y, $w, $h); |
107 | } |
128 | } |
108 | |
129 | |
109 | # translate global koordinates to local coordinate system |
130 | # translate global koordinates to local coordinate system |
110 | sub translate { |
131 | sub translate { |
111 | my ($self, $x, $y) = @_; |
132 | my ($self, $x, $y) = @_; |
… | |
… | |
155 | return unless $self->{h} && $self->{w}; |
176 | return unless $self->{h} && $self->{w}; |
156 | |
177 | |
157 | glPushMatrix; |
178 | glPushMatrix; |
158 | glTranslate $self->{x}, $self->{y}, 0; |
179 | glTranslate $self->{x}, $self->{y}, 0; |
159 | $self->_draw; |
180 | $self->_draw; |
|
|
181 | glPopMatrix; |
|
|
182 | |
160 | if ($self == $HOVER) { |
183 | if ($self == $HOVER) { |
|
|
184 | my ($x, $y) = @$self{qw(x y)}; |
|
|
185 | |
161 | glColor 1, 1, 1, 0.4; |
186 | glColor 1, 1, 1, 0.1; |
162 | glEnable GL_BLEND; |
187 | glEnable GL_BLEND; |
|
|
188 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
163 | glBegin GL_QUADS; |
189 | glBegin GL_QUADS; |
164 | glVertex 0 , 0; |
190 | glVertex $x , $y; |
165 | glVertex $self->{w}, 0; |
191 | glVertex $x + $self->{w}, $y; |
166 | glVertex $self->{w}, $self->{h}; |
192 | glVertex $x + $self->{w}, $y + $self->{h}; |
167 | glVertex 0 , $self->{h}; |
193 | glVertex $x , $y + $self->{h}; |
168 | glEnd; |
194 | glEnd; |
169 | glDisable GL_BLEND; |
195 | glDisable GL_BLEND; |
170 | } |
196 | } |
171 | glPopMatrix; |
|
|
172 | } |
197 | } |
173 | |
198 | |
174 | sub _draw { |
199 | sub _draw { |
175 | my ($self) = @_; |
200 | my ($self) = @_; |
176 | |
201 | |
… | |
… | |
216 | |
241 | |
217 | $self->{parent}->update |
242 | $self->{parent}->update |
218 | if $self->{parent}; |
243 | if $self->{parent}; |
219 | } |
244 | } |
220 | |
245 | |
|
|
246 | sub connect { |
|
|
247 | my ($self, $signal, $cb) = @_; |
|
|
248 | |
|
|
249 | push @{ $self->{cb}{$signal} }, $cb; |
|
|
250 | } |
|
|
251 | |
|
|
252 | sub emit { |
|
|
253 | my ($self, $signal, @args) = @_; |
|
|
254 | |
|
|
255 | $_->($self, @args) |
|
|
256 | for @{$self->{cb}{$signal} || []}; |
|
|
257 | } |
|
|
258 | |
221 | sub DESTROY { |
259 | sub DESTROY { |
222 | my ($self) = @_; |
260 | my ($self) = @_; |
223 | |
261 | |
224 | #$self->deactivate; |
262 | #$self->deactivate; |
225 | } |
263 | } |
226 | |
264 | |
227 | ############################################################################# |
265 | ############################################################################# |
228 | |
266 | |
229 | package CFClient::Widget::DrawBG; |
267 | package CFClient::UI::DrawBG; |
230 | |
268 | |
231 | our @ISA = CFClient::Widget::; |
269 | our @ISA = CFClient::UI::Base::; |
232 | |
270 | |
233 | use strict; |
271 | use strict; |
234 | use SDL::OpenGL; |
272 | use SDL::OpenGL; |
235 | |
273 | |
236 | sub new { |
274 | sub new { |
… | |
… | |
259 | glEnd; |
297 | glEnd; |
260 | } |
298 | } |
261 | |
299 | |
262 | ############################################################################# |
300 | ############################################################################# |
263 | |
301 | |
264 | package CFClient::Widget::Empty; |
302 | package CFClient::UI::Empty; |
265 | |
303 | |
266 | our @ISA = CFClient::Widget::; |
304 | our @ISA = CFClient::UI::Base::; |
267 | |
305 | |
268 | sub size_request { |
306 | sub size_request { |
269 | (0, 0) |
307 | (0, 0) |
270 | } |
308 | } |
271 | |
309 | |
272 | sub draw { } |
310 | sub draw { } |
273 | |
311 | |
274 | ############################################################################# |
312 | ############################################################################# |
275 | |
313 | |
276 | package CFClient::Widget::Container; |
314 | package CFClient::UI::Container; |
277 | |
315 | |
278 | our @ISA = CFClient::Widget::; |
316 | our @ISA = CFClient::UI::Base::; |
279 | |
317 | |
280 | sub new { |
318 | sub new { |
281 | my ($class, %arg) = @_; |
319 | my ($class, %arg) = @_; |
282 | |
320 | |
283 | my $children = delete $arg{children} || []; |
321 | my $children = delete $arg{children} || []; |
… | |
… | |
297 | $self->{children} = [ |
335 | $self->{children} = [ |
298 | sort { $a->{z} <=> $b->{z} } |
336 | sort { $a->{z} <=> $b->{z} } |
299 | @{$self->{children}}, $chld |
337 | @{$self->{children}}, $chld |
300 | ]; |
338 | ]; |
301 | |
339 | |
302 | $self->size_allocate ($self->{w}, $self->{h}) |
340 | $self->{w} = $self->{h} = -1; |
303 | if $self->{w}; #TODO: check for "realised state" |
341 | $self->update; |
304 | } |
342 | } |
305 | |
343 | |
306 | sub remove { |
344 | sub remove { |
307 | my ($self, $widget) = @_; |
345 | my ($self, $widget) = @_; |
308 | |
346 | |
309 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
347 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
310 | |
348 | |
311 | $self->size_allocate ($self->{w}, $self->{h}); |
349 | $self->size_allocate (0, 0, $self->{w}, $self->{h}); |
312 | } |
350 | } |
313 | |
351 | |
314 | sub find_widget { |
352 | sub find_widget { |
315 | my ($self, $x, $y) = @_; |
353 | my ($self, $x, $y) = @_; |
316 | |
354 | |
… | |
… | |
333 | $_->draw for @{$self->{children}}; |
371 | $_->draw for @{$self->{children}}; |
334 | } |
372 | } |
335 | |
373 | |
336 | ############################################################################# |
374 | ############################################################################# |
337 | |
375 | |
338 | package CFClient::Widget::Bin; |
376 | package CFClient::UI::Bin; |
339 | |
377 | |
340 | our @ISA = CFClient::Widget::Container::; |
378 | our @ISA = CFClient::UI::Container::; |
341 | |
379 | |
342 | sub new { |
380 | sub new { |
343 | my ($class, %arg) = @_; |
381 | my ($class, %arg) = @_; |
344 | |
382 | |
345 | my $child = (delete $arg{child}) || new CFClient::Widget::Empty::; |
383 | my $child = (delete $arg{child}) || new CFClient::UI::Empty::; |
346 | |
384 | |
347 | $class->SUPER::new (children => [$child], %arg) |
385 | $class->SUPER::new (children => [$child], %arg) |
348 | } |
386 | } |
349 | |
387 | |
350 | sub add { |
388 | sub add { |
… | |
… | |
358 | sub remove { |
396 | sub remove { |
359 | my ($self, $widget) = @_; |
397 | my ($self, $widget) = @_; |
360 | |
398 | |
361 | $self->SUPER::remove ($widget); |
399 | $self->SUPER::remove ($widget); |
362 | |
400 | |
363 | $self->{children} = [new CFClient::Widget::Empty] |
401 | $self->{children} = [new CFClient::UI::Empty] |
364 | unless @{$self->{children}}; |
402 | unless @{$self->{children}}; |
365 | } |
403 | } |
366 | |
404 | |
367 | sub child { $_[0]->{children}[0] } |
405 | sub child { $_[0]->{children}[0] } |
368 | |
406 | |
369 | sub size_request { |
407 | sub size_request { |
370 | $_[0]{children}[0]->size_request |
408 | $_[0]{children}[0]->size_request |
371 | } |
409 | } |
372 | |
410 | |
373 | sub size_allocate { |
411 | sub size_allocate { |
374 | my ($self, $w, $h) = @_; |
412 | my ($self, $x, $y, $w, $h) = @_; |
375 | |
413 | |
376 | return unless $self->{w} != $w || $self->{h} != $h; |
414 | $self->_size_allocate ($x, $y, $w, $h) or return; |
377 | |
415 | |
378 | $self->SUPER::size_allocate ($w, $h); |
|
|
379 | $self->{children}[0]->size_allocate ($w, $h); |
416 | $self->{children}[0]->size_allocate (0, 0, $w, $h); |
380 | } |
417 | } |
381 | |
418 | |
382 | ############################################################################# |
419 | ############################################################################# |
383 | |
420 | |
384 | package CFClient::Widget::Window; |
421 | package CFClient::UI::Window; |
385 | |
422 | |
386 | our @ISA = CFClient::Widget::Bin::; |
423 | our @ISA = CFClient::UI::Bin::; |
387 | |
424 | |
388 | use SDL::OpenGL; |
425 | use SDL::OpenGL; |
389 | |
426 | |
390 | sub new { |
427 | sub new { |
391 | my ($class, %arg) = @_; |
428 | my ($class, %arg) = @_; |
… | |
… | |
409 | $self->{w}, $self->{h}, sub { $self->child->draw } |
446 | $self->{w}, $self->{h}, sub { $self->child->draw } |
410 | ); |
447 | ); |
411 | } |
448 | } |
412 | |
449 | |
413 | sub size_allocate { |
450 | sub size_allocate { |
414 | my ($self, $w, $h) = @_; |
451 | my ($self, $x, $y, $w, $h) = @_; |
415 | |
452 | |
416 | return unless $self->{w} != $w || $self->{h} != $h; |
453 | $self->_size_allocate ($x, $y, $w, $h) or return; |
417 | |
454 | |
418 | $self->{w} = $w; |
|
|
419 | $self->{h} = $h; |
|
|
420 | |
|
|
421 | $self->child->size_allocate ($w, $h); |
455 | $self->child->size_allocate (0, 0, $w, $h); |
422 | |
456 | |
423 | $self->render_chld; |
457 | $self->render_chld; |
424 | } |
458 | } |
425 | |
459 | |
426 | sub _draw { |
460 | sub _draw { |
… | |
… | |
430 | |
464 | |
431 | my $tex = $self->{texture} |
465 | my $tex = $self->{texture} |
432 | or return; |
466 | or return; |
433 | |
467 | |
434 | glEnable GL_BLEND; |
468 | glEnable GL_BLEND; |
|
|
469 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
435 | glEnable GL_TEXTURE_2D; |
470 | glEnable GL_TEXTURE_2D; |
436 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
471 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
437 | |
472 | |
438 | $tex->draw_quad (0, 0, $w, $h); |
473 | $tex->draw_quad (0, 0, $w, $h); |
439 | |
474 | |
… | |
… | |
441 | glDisable GL_TEXTURE_2D; |
476 | glDisable GL_TEXTURE_2D; |
442 | } |
477 | } |
443 | |
478 | |
444 | ############################################################################# |
479 | ############################################################################# |
445 | |
480 | |
446 | package CFClient::Widget::Frame; |
481 | package CFClient::UI::Frame; |
447 | |
482 | |
448 | our @ISA = CFClient::Widget::Bin::; |
483 | our @ISA = CFClient::UI::Bin::; |
449 | |
484 | |
450 | use SDL::OpenGL; |
485 | use SDL::OpenGL; |
451 | |
486 | |
452 | sub size_request { |
487 | sub size_request { |
453 | my ($self) = @_; |
488 | my ($self) = @_; |
… | |
… | |
458 | |
493 | |
459 | map { $_ + 4 } $chld->size_request; |
494 | map { $_ + 4 } $chld->size_request; |
460 | } |
495 | } |
461 | |
496 | |
462 | sub size_allocate { |
497 | sub size_allocate { |
463 | my ($self, $w, $h) = @_; |
498 | my ($self, $x, $y, $w, $h) = @_; |
464 | |
499 | |
465 | return unless $self->{w} != $w || $self->{h} != $h; |
500 | $self->_size_allocate ($x, $y, $w, $h) or return; |
466 | |
501 | |
467 | $self->{w} = $w; |
|
|
468 | $self->{h} = $h; |
|
|
469 | |
|
|
470 | $self->child->size_allocate ($w - 4, $h - 4); |
502 | $self->child->size_allocate (2, 2, $w - 4, $h - 4); |
471 | $self->child->move (2, 2); |
|
|
472 | } |
503 | } |
473 | |
504 | |
474 | sub _draw { |
505 | sub _draw { |
475 | my ($self) = @_; |
506 | my ($self) = @_; |
476 | |
507 | |
… | |
… | |
489 | $chld->draw; |
520 | $chld->draw; |
490 | } |
521 | } |
491 | |
522 | |
492 | ############################################################################# |
523 | ############################################################################# |
493 | |
524 | |
494 | package CFClient::Widget::FancyFrame; |
525 | package CFClient::UI::FancyFrame; |
495 | |
526 | |
496 | our @ISA = CFClient::Widget::Bin::; |
527 | our @ISA = CFClient::UI::Bin::; |
497 | |
528 | |
498 | use SDL::OpenGL; |
529 | use SDL::OpenGL; |
499 | |
530 | |
500 | my @tex = |
531 | my @tex = |
501 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
532 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
504 | sub size_request { |
535 | sub size_request { |
505 | my ($self) = @_; |
536 | my ($self) = @_; |
506 | |
537 | |
507 | my ($w, $h) = $self->SUPER::size_request; |
538 | my ($w, $h) = $self->SUPER::size_request; |
508 | |
539 | |
509 | $h += $tex[1]->{height}; |
540 | $h += $tex[1]->{h}; |
510 | $h += $tex[4]->{height}; |
541 | $h += $tex[4]->{h}; |
511 | $w += $tex[2]->{width}; |
542 | $w += $tex[2]->{w}; |
512 | $w += $tex[3]->{width}; |
543 | $w += $tex[3]->{w}; |
513 | |
544 | |
514 | ($w, $h) |
545 | ($w, $h) |
515 | } |
546 | } |
516 | |
547 | |
517 | sub size_allocate { |
548 | sub size_allocate { |
518 | my ($self, $w, $h) = @_; |
549 | my ($self, $x, $y, $w, $h) = @_; |
519 | |
550 | |
520 | return unless $self->{w} != $w || $self->{h} != $h; |
551 | $self->_size_allocate ($x, $y, $w, $h) or return; |
521 | |
552 | |
522 | $self->SUPER::size_allocate ($w, $h); |
|
|
523 | |
|
|
524 | $h -= $tex[1]->{height}; |
553 | $h -= $tex[1]->{h}; |
525 | $h -= $tex[4]->{height}; |
554 | $h -= $tex[4]->{h}; |
526 | $w -= $tex[2]->{width}; |
555 | $w -= $tex[2]->{w}; |
527 | $w -= $tex[3]->{width}; |
556 | $w -= $tex[3]->{w}; |
528 | |
557 | |
529 | $h = $h < 0 ? 0 : $h; |
558 | $h = $h < 0 ? 0 : $h; |
530 | $w = $w < 0 ? 0 : $w; |
559 | $w = $w < 0 ? 0 : $w; |
531 | |
560 | |
532 | my $child = $self->child; |
561 | my $child = $self->child; |
533 | |
562 | |
534 | $child->size_allocate ($w, $h); |
563 | $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); |
535 | $child->move ($tex[3]->{width}, $tex[1]->{height}); |
|
|
536 | } |
564 | } |
537 | |
565 | |
538 | sub _draw { |
566 | sub _draw { |
539 | my ($self) = @_; |
567 | my ($self) = @_; |
540 | |
568 | |
541 | my ($w, $h) = ($self->{w}, $self->{h}); |
569 | my ($w, $h) = ($self->{w}, $self->{h}); |
542 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
570 | my ($cw, $ch) = ($self->child->{w}, $self->child->{h}); |
543 | |
571 | |
544 | glEnable GL_BLEND; |
572 | glEnable GL_BLEND; |
|
|
573 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
545 | glEnable GL_TEXTURE_2D; |
574 | glEnable GL_TEXTURE_2D; |
546 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
547 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
575 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
548 | |
576 | |
549 | my $top = $tex[1]; |
577 | my $top = $tex[1]; |
550 | $top->draw_quad (0, 0, $w, $top->{height}); |
578 | $top->draw_quad (0, 0, $w, $top->{h}); |
551 | |
579 | |
552 | my $left = $tex[3]; |
580 | my $left = $tex[3]; |
553 | $left->draw_quad (0, $top->{height}, $left->{width}, $ch); |
581 | $left->draw_quad (0, $top->{h}, $left->{w}, $ch); |
554 | |
582 | |
555 | my $right = $tex[2]; |
583 | my $right = $tex[2]; |
556 | $right->draw_quad ($w - $right->{width}, $top->{height}, $right->{width}, $ch); |
584 | $right->draw_quad ($w - $right->{w}, $top->{h}, $right->{w}, $ch); |
557 | |
585 | |
558 | my $bottom = $tex[4]; |
586 | my $bottom = $tex[4]; |
559 | $bottom->draw_quad (0, $h - $bottom->{height}, $w, $bottom->{height}); |
587 | $bottom->draw_quad (0, $h - $bottom->{h}, $w, $bottom->{h}); |
560 | |
588 | |
561 | my $bg = $tex[0]; |
589 | my $bg = $tex[0]; |
562 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
590 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
563 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
591 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
564 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
592 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
565 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
593 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
566 | |
594 | |
567 | my $rep_x = $cw / $bg->{width}; |
595 | my $rep_x = $cw / $bg->{w}; |
568 | my $rep_y = $ch / $bg->{height}; |
596 | my $rep_y = $ch / $bg->{h}; |
569 | |
597 | |
570 | $bg->draw_quad ($left->{width}, $top->{height}, $cw, $ch); |
598 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
571 | |
599 | |
572 | glDisable GL_BLEND; |
600 | glDisable GL_BLEND; |
573 | glDisable GL_TEXTURE_2D; |
601 | glDisable GL_TEXTURE_2D; |
574 | |
602 | |
575 | $self->child->draw; |
603 | $self->child->draw; |
576 | |
604 | |
577 | } |
605 | } |
578 | |
606 | |
579 | ############################################################################# |
607 | ############################################################################# |
580 | |
608 | |
581 | package CFClient::Widget::Table; |
609 | package CFClient::UI::Table; |
582 | |
610 | |
583 | our @ISA = CFClient::Widget::Bin::; |
611 | our @ISA = CFClient::UI::Base::; |
|
|
612 | |
|
|
613 | use List::Util qw(max sum); |
584 | |
614 | |
585 | use SDL::OpenGL; |
615 | use SDL::OpenGL; |
586 | |
616 | |
587 | sub add { |
617 | sub add { |
588 | my ($self, $x, $y, $chld) = @_; |
618 | my ($self, $x, $y, $chld) = @_; |
589 | my $old_chld = $self->{children}[$y][$x]; |
|
|
590 | |
619 | |
591 | $self->{children}[$y][$x] = $chld; |
620 | $self->{children}[$y][$x] = $chld; |
592 | $chld->set_parent ($self); |
621 | $chld->set_parent ($self); |
|
|
622 | |
|
|
623 | $self->{w} = $self->{h} = -1; |
593 | $self->update; |
624 | $self->update; |
594 | } |
625 | } |
595 | |
626 | |
596 | sub max_row_height { |
627 | sub get_wh { |
597 | my ($self, $row) = @_; |
628 | my ($self) = @_; |
598 | |
629 | |
599 | my $hs = 0; |
630 | my (@w, @h); |
600 | for (my $xi = 0; $xi <= $#{$self->{children}->[$row] || []}; $xi++) { |
631 | |
|
|
632 | for my $y (0 .. $#{$self->{children}}) { |
601 | my $c = $self->{children}->[$row]->[$xi]; |
633 | my $row = $self->{children}[$y] |
602 | if ($c) { |
634 | or next; |
|
|
635 | |
|
|
636 | for my $x (0 .. $#$row) { |
|
|
637 | my $widget = $row->[$x] |
|
|
638 | or next; |
603 | my ($w, $h) = $c->size_request; |
639 | my ($w, $h) = $widget->size_request; |
604 | if ($hs < $h) { $hs = $h } |
640 | |
|
|
641 | $w[$x] = max $w[$x], $w; |
|
|
642 | $h[$y] = max $h[$y], $h; |
605 | } |
643 | } |
606 | } |
644 | } |
607 | return $hs; |
|
|
608 | } |
|
|
609 | |
645 | |
610 | sub max_col_width { |
646 | (\@w, \@h) |
|
|
647 | } |
|
|
648 | |
|
|
649 | sub size_request { |
611 | my ($self, $col) = @_; |
650 | my ($self) = @_; |
612 | |
651 | |
|
|
652 | my ($ws, $hs) = $self->get_wh; |
|
|
653 | |
|
|
654 | ( |
|
|
655 | (List::Util::sum @$ws), |
|
|
656 | (List::Util::sum @$hs), |
|
|
657 | ) |
|
|
658 | } |
|
|
659 | |
|
|
660 | sub size_allocate { |
|
|
661 | my ($self, $x, $y, $w, $h) = @_; |
|
|
662 | |
|
|
663 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
664 | |
|
|
665 | my ($ws, $hs) = $self->get_wh; |
|
|
666 | |
|
|
667 | my $req_w = List::Util::sum @$ws; |
|
|
668 | my $req_h = List::Util::sum @$hs; |
|
|
669 | |
|
|
670 | # linearly scale sizes |
|
|
671 | $_ *= $req_w / $w for @$ws; |
|
|
672 | $_ *= $req_h / $h for @$hs; |
|
|
673 | |
|
|
674 | my $y; |
|
|
675 | |
|
|
676 | for my $r (0 .. $#{$self->{children}}) { |
|
|
677 | my $row = $self->{children}[$r] |
|
|
678 | or next; |
|
|
679 | |
613 | my $ws = 0; |
680 | my $x = 0; |
614 | for (my $yi = 0; $yi <= $#{$self->{children} || []}; $yi++) { |
681 | my $row_h = $hs->[$r]; |
615 | my $c = ($self->{children}->[$yi] || [])->[$col]; |
682 | |
616 | if ($c) { |
683 | for my $c (0 .. $#$row) { |
617 | my ($w, $h) = $c->size_request; |
684 | my $widget = $row->[$c] |
618 | if ($ws < $w) { $ws = $w } |
685 | or next; |
|
|
686 | |
|
|
687 | my $col_w = $ws->[$c]; |
|
|
688 | |
|
|
689 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
|
|
690 | |
|
|
691 | $x += $col_w; |
619 | } |
692 | } |
620 | } |
|
|
621 | return $ws; |
|
|
622 | } |
|
|
623 | |
693 | |
624 | sub size_request { |
694 | $y += $row_h; |
625 | my ($self) = @_; |
|
|
626 | |
|
|
627 | my ($hs, $ws) = (0, 0); |
|
|
628 | |
|
|
629 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
|
|
630 | $hs += $self->max_row_height ($yi); |
|
|
631 | } |
695 | } |
632 | |
696 | |
633 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
|
|
634 | my $wm = 0; |
|
|
635 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
|
|
636 | $wm += $self->max_col_width ($xi) |
|
|
637 | } |
|
|
638 | if ($ws < $wm) { $ws = $wm } |
|
|
639 | } |
|
|
640 | |
|
|
641 | return ($ws, $hs); |
|
|
642 | } |
697 | } |
643 | |
698 | |
644 | sub _draw { |
699 | sub _draw { |
645 | my ($self) = @_; |
700 | my ($self) = @_; |
646 | |
701 | |
647 | my $y = 0; |
702 | for (grep $_, @{$self->{children}}) { |
648 | for (my $yi = 0; $yi <= $#{$self->{children}}; $yi++) { |
703 | $_->draw for grep $_, @$_; |
649 | my $x = 0; |
|
|
650 | |
|
|
651 | for (my $xi = 0; $xi <= $#{$self->{children}->[$yi]}; $xi++) { |
|
|
652 | |
|
|
653 | my $c = $self->{children}->[$yi]->[$xi]; |
|
|
654 | if ($c) { |
|
|
655 | $c->move ($x, $y, 0); #TODO: Move to size_request |
|
|
656 | $c->draw if $c; |
|
|
657 | } |
|
|
658 | |
|
|
659 | $x += $self->max_col_width ($xi); |
|
|
660 | } |
|
|
661 | |
|
|
662 | $y += $self->max_row_height ($yi); |
|
|
663 | } |
704 | } |
664 | } |
705 | } |
665 | |
706 | |
666 | ############################################################################# |
707 | ############################################################################# |
667 | |
708 | |
668 | package CFClient::Widget::VBox; |
709 | package CFClient::UI::VBox; |
669 | |
710 | |
670 | our @ISA = CFClient::Widget::Container::; |
711 | our @ISA = CFClient::UI::Container::; |
671 | |
712 | |
672 | use SDL::OpenGL; |
713 | use SDL::OpenGL; |
673 | |
714 | |
674 | sub size_request { |
715 | sub size_request { |
675 | my ($self) = @_; |
716 | my ($self) = @_; |
… | |
… | |
681 | (List::Util::sum map $_->[1], @alloc), |
722 | (List::Util::sum map $_->[1], @alloc), |
682 | ) |
723 | ) |
683 | } |
724 | } |
684 | |
725 | |
685 | sub size_allocate { |
726 | sub size_allocate { |
686 | my ($self, $w, $h) = @_; |
727 | my ($self, $x, $y, $w, $h) = @_; |
687 | |
728 | |
688 | return unless $self->{w} != $w || $self->{h} != $h; |
729 | $self->_size_allocate ($x, $y, $w, $h) or return; |
689 | |
|
|
690 | $self->{w} = $w; |
|
|
691 | $self->{h} = $h; |
|
|
692 | |
730 | |
693 | return unless $self->{h}; |
731 | return unless $self->{h}; |
694 | |
732 | |
695 | my $children = $self->{children}; |
733 | my $children = $self->{children}; |
696 | |
734 | |
… | |
… | |
718 | |
756 | |
719 | my $y = 0; |
757 | my $y = 0; |
720 | for (0 .. $#$children) { |
758 | for (0 .. $#$children) { |
721 | my $child = $children->[$_]; |
759 | my $child = $children->[$_]; |
722 | my $h = $h[$_]; |
760 | my $h = $h[$_]; |
723 | $child->move (0, $y); |
|
|
724 | $child->size_allocate ($w, $h); |
761 | $child->size_allocate (0, $y, $w, $h); |
725 | |
762 | |
726 | $y += $h; |
763 | $y += $h; |
727 | } |
764 | } |
728 | } |
765 | } |
729 | |
766 | |
730 | ############################################################################# |
767 | ############################################################################# |
731 | |
768 | |
732 | package CFClient::Widget::Label; |
769 | package CFClient::UI::Label; |
733 | |
770 | |
734 | our @ISA = CFClient::Widget::; |
771 | our @ISA = CFClient::UI::Base::; |
735 | |
772 | |
736 | use SDL::OpenGL; |
773 | use SDL::OpenGL; |
737 | |
774 | |
738 | sub new { |
775 | sub new { |
739 | my ($class, %arg) = @_; |
776 | my ($class, %arg) = @_; |
740 | |
777 | |
741 | my $self = $class->SUPER::new ( |
778 | my $self = $class->SUPER::new ( |
742 | fg => [1, 1, 1], |
779 | fg => [1, 1, 1], |
743 | height => $::FONTSIZE, |
780 | height => $::FONTSIZE, |
744 | text => "", |
781 | text => "", |
|
|
782 | align => -1, |
745 | layout => new CFClient::Layout, |
783 | layout => new CFClient::Layout, |
746 | %arg |
784 | %arg |
747 | ); |
785 | ); |
748 | |
786 | |
749 | $self->set_text ($self->{text}); |
787 | $self->set_text ($self->{text}); |
… | |
… | |
781 | my ($self) = @_; |
819 | my ($self) = @_; |
782 | |
820 | |
783 | $self->{layout}->set_width; |
821 | $self->{layout}->set_width; |
784 | $self->{layout}->set_height ($self->{height}); |
822 | $self->{layout}->set_height ($self->{height}); |
785 | $self->{layout}->size |
823 | $self->{layout}->size |
786 | # if ($self->{texture}{width} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
824 | # if ($self->{texture}{w} > 1 && $self->{texture}{height} > 1) { #TODO: hack |
787 | # ( |
825 | # ( |
788 | # $self->{texture}{width}, |
826 | # $self->{texture}{w}, |
789 | # $self->{texture}{height}, |
827 | # $self->{texture}{h}, |
790 | # ) |
828 | # ) |
791 | # } else { |
829 | # } else { |
792 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{height}; |
830 | # my ($w, $h, $data) = CFClient::font_render "Yy", $self->{h}; |
793 | # |
831 | # |
794 | # ($w, $h) |
832 | # ($w, $h) |
795 | # } |
833 | # } |
796 | } |
834 | } |
797 | |
835 | |
798 | sub size_allocate { |
836 | sub size_allocate { |
799 | my ($self, $w, $h) = @_; |
837 | my ($self, $x, $y, $w, $h) = @_; |
800 | |
838 | |
801 | return unless $self->{w} != $w || $self->{h} != $h; |
839 | $self->_size_allocate ($x, $y, $w, $h) or return; |
802 | |
840 | |
803 | $self->SUPER::size_allocate ($w, $h); |
|
|
804 | delete $self->{texture}; |
841 | delete $self->{texture}; |
805 | } |
842 | } |
806 | |
843 | |
807 | sub update { |
844 | sub update { |
808 | my ($self) = @_; |
845 | my ($self) = @_; |
… | |
… | |
814 | sub _draw { |
851 | sub _draw { |
815 | my ($self) = @_; |
852 | my ($self) = @_; |
816 | |
853 | |
817 | my $tex = $self->{texture} ||= do { |
854 | my $tex = $self->{texture} ||= do { |
818 | $self->{layout}->set_width ($self->{w}); |
855 | $self->{layout}->set_width ($self->{w}); |
819 | new_from_layout CFClient::Texture $self->{layout}; |
856 | new_from_layout CFClient::Texture $self->{layout} |
820 | }; |
857 | }; |
821 | |
858 | |
822 | glEnable GL_BLEND; |
859 | glEnable GL_BLEND; |
|
|
860 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
823 | glEnable GL_TEXTURE_2D; |
861 | glEnable GL_TEXTURE_2D; |
824 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
825 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
862 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
826 | |
863 | |
827 | glColor @{$self->{fg}}; |
864 | glColor @{$self->{fg}}; |
828 | |
865 | |
|
|
866 | my $x = |
|
|
867 | $self->{align} < 0 ? 0 |
|
|
868 | : $self->{align} > 0 ? $self->{w} - $tex->{w} |
|
|
869 | : ($self->{w} - $tex->{w}) * 0.5; |
|
|
870 | |
829 | $tex->draw_quad (0, 0); |
871 | $tex->draw_quad ($x, 0); |
830 | |
872 | |
|
|
873 | glDisable GL_TEXTURE_2D; |
831 | glDisable GL_BLEND; |
874 | glDisable GL_BLEND; |
832 | glDisable GL_TEXTURE_2D; |
|
|
833 | } |
875 | } |
834 | |
876 | |
835 | ############################################################################# |
877 | ############################################################################# |
836 | |
878 | |
837 | package CFClient::Widget::Entry; |
879 | package CFClient::UI::Entry; |
838 | |
880 | |
839 | our @ISA = CFClient::Widget::Label::; |
881 | our @ISA = CFClient::UI::Label::; |
840 | |
882 | |
841 | use SDL; |
883 | use SDL; |
842 | use SDL::OpenGL; |
884 | use SDL::OpenGL; |
843 | |
885 | |
844 | sub new { |
886 | sub new { |
… | |
… | |
858 | |
900 | |
859 | $self->{last_activity} = $::NOW; |
901 | $self->{last_activity} = $::NOW; |
860 | |
902 | |
861 | $self->{text} = $text; |
903 | $self->{text} = $text; |
862 | $self->{layout}->set_width ($self->{w}); |
904 | $self->{layout}->set_width ($self->{w}); |
|
|
905 | |
|
|
906 | $text =~ s/./*/g if $self->{hidden}; |
|
|
907 | |
|
|
908 | |
863 | $self->{layout}->set_markup ($self->escape_text ($text)); |
909 | $self->{layout}->set_markup ($self->escape_text ($text)); |
864 | |
910 | |
865 | $text = substr $text, 0, $self->{cursor}; |
911 | $text = substr $text, 0, $self->{cursor}; |
866 | utf8::encode $text; |
912 | utf8::encode $text; |
867 | |
913 | |
… | |
… | |
875 | |
921 | |
876 | ($w + 1, $h) # add 1 for cursor |
922 | ($w + 1, $h) # add 1 for cursor |
877 | } |
923 | } |
878 | |
924 | |
879 | sub size_allocate { |
925 | sub size_allocate { |
880 | my ($self, $w, $h) = @_; |
926 | my ($self, $x, $y, $w, $h) = @_; |
881 | |
927 | |
882 | return unless $self->{w} != $w || $self->{h} != $h; |
|
|
883 | |
|
|
884 | $self->SUPER::size_allocate ($w, $h); |
928 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
885 | |
929 | |
886 | $self->_set_text ($self->{text}); |
930 | $self->_set_text ($self->{text}); |
887 | } |
931 | } |
888 | |
932 | |
889 | sub set_text { |
933 | sub set_text { |
… | |
… | |
980 | } |
1024 | } |
981 | } |
1025 | } |
982 | |
1026 | |
983 | ############################################################################# |
1027 | ############################################################################# |
984 | |
1028 | |
985 | package CFClient::Widget::Slider; |
1029 | package CFClient::UI::Slider; |
986 | |
1030 | |
987 | use strict; |
1031 | use strict; |
988 | |
1032 | |
989 | use SDL::OpenGL; |
1033 | use SDL::OpenGL; |
990 | use SDL::OpenGL::Constants; |
|
|
991 | |
1034 | |
992 | our @ISA = CFClient::Widget::DrawBG::; |
1035 | our @ISA = CFClient::UI::DrawBG::; |
993 | |
1036 | |
994 | sub size_request { |
1037 | sub size_request { |
995 | my ($self) = @_; |
1038 | my ($self) = @_; |
996 | |
1039 | |
997 | my $w = 20; |
1040 | my $w = 50; |
998 | my $h = 10; |
1041 | my $h = 10; |
999 | |
1042 | |
1000 | $self->{vertical} ? ($h, $w) : ($w, $h) |
1043 | $self->{vertical} ? ($h, $w) : ($w, $h) |
1001 | } |
1044 | } |
1002 | |
1045 | |
… | |
… | |
1025 | my ($self, $ev, $x, $y) = @_; |
1068 | my ($self, $ev, $x, $y) = @_; |
1026 | |
1069 | |
1027 | if ($GRAB == $self) { |
1070 | if ($GRAB == $self) { |
1028 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1071 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1029 | |
1072 | |
|
|
1073 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
|
|
1074 | |
1030 | $x = $x * ($hi - $lo) / $self->{w} + $lo; |
1075 | $x = $x * ($hi - $lo) / $w + $lo; |
1031 | $x = $lo if $x < $lo; |
1076 | $x = $lo if $x < $lo; |
1032 | $x = $hi - $page if $x > $hi - $page; |
1077 | $x = $hi - $page if $x > $hi - $page; |
1033 | $self->{range}[0] = $x; |
1078 | $self->{range}[0] = $x; |
1034 | |
1079 | |
1035 | $self->{changed}($x) if $self->{changed}; |
1080 | $self->emit (changed => $x); |
1036 | $self->update; |
1081 | $self->update; |
1037 | } |
1082 | } |
1038 | } |
1083 | } |
1039 | |
1084 | |
1040 | sub _draw { |
1085 | sub _draw { |
1041 | my ($self) = @_; |
1086 | my ($self) = @_; |
1042 | |
1087 | |
1043 | $self->SUPER::_draw (); |
1088 | $self->SUPER::_draw (); |
1044 | |
|
|
1045 | glPushMatrix; |
|
|
1046 | |
1089 | |
1047 | my ($w, $h) = @$self{qw(w h)}; |
1090 | my ($w, $h) = @$self{qw(w h)}; |
1048 | |
1091 | |
1049 | if ($self->{vertical}) { |
1092 | if ($self->{vertical}) { |
1050 | # draw a vertical slider like a rotated horizontal slider |
1093 | # draw a vertical slider like a rotated horizontal slider |
1051 | |
1094 | |
1052 | glTranslate 0, $self->{w}; |
|
|
1053 | glRotate 90, 0, 0, 1; |
1095 | glRotate 90, 0, 0, 1; |
|
|
1096 | glTranslate 0, -$self->{w}, 0; |
1054 | |
1097 | |
1055 | ($w, $h) = ($h, $w); |
1098 | ($w, $h) = ($h, $w); |
1056 | } |
1099 | } |
1057 | |
1100 | |
1058 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1101 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
… | |
… | |
1090 | glVertex $knob_a + 1, $h - 1; |
1133 | glVertex $knob_a + 1, $h - 1; |
1091 | glVertex $knob_b - 1, $h - 1; |
1134 | glVertex $knob_b - 1, $h - 1; |
1092 | glVertex $knob_b - 1, 1; |
1135 | glVertex $knob_b - 1, 1; |
1093 | } |
1136 | } |
1094 | glEnd; |
1137 | glEnd; |
1095 | |
|
|
1096 | glPopMatrix; |
|
|
1097 | } |
1138 | } |
1098 | |
1139 | |
1099 | ############################################################################# |
1140 | ############################################################################# |
1100 | |
1141 | |
1101 | package CFClient::Widget::MapWidget; |
1142 | package CFClient::UI::MapWidget; |
1102 | |
1143 | |
1103 | use strict; |
1144 | use strict; |
1104 | |
1145 | |
1105 | use List::Util qw(min max); |
1146 | use List::Util qw(min max); |
1106 | |
1147 | |
1107 | use SDL; |
1148 | use SDL; |
1108 | use SDL::OpenGL; |
1149 | use SDL::OpenGL; |
1109 | use SDL::OpenGL::Constants; |
|
|
1110 | |
1150 | |
1111 | our @ISA = CFClient::Widget::; |
1151 | our @ISA = CFClient::UI::Base::; |
1112 | |
1152 | |
1113 | sub new { |
1153 | sub new { |
1114 | my $class = shift; |
1154 | my $class = shift; |
1115 | |
1155 | |
1116 | $class->SUPER::new ( |
1156 | $class->SUPER::new ( |
… | |
… | |
1136 | |
1176 | |
1137 | sub update { |
1177 | sub update { |
1138 | my ($self) = @_; |
1178 | my ($self) = @_; |
1139 | |
1179 | |
1140 | $self->{need_update} = 1; |
1180 | $self->{need_update} = 1; |
|
|
1181 | $self->SUPER::update; |
1141 | } |
1182 | } |
1142 | |
1183 | |
1143 | sub _draw { |
1184 | sub _draw { |
1144 | my ($self) = @_; |
1185 | my ($self) = @_; |
1145 | |
1186 | |
… | |
… | |
1168 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
1209 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
1169 | } |
1210 | } |
1170 | |
1211 | |
1171 | glEnable GL_TEXTURE_2D; |
1212 | glEnable GL_TEXTURE_2D; |
1172 | glEnable GL_BLEND; |
1213 | glEnable GL_BLEND; |
|
|
1214 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1173 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1215 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1174 | |
1216 | |
1175 | my $sw4 = ($sw + 3) & ~3; |
1217 | my $sw4 = ($sw + 3) & ~3; |
1176 | my $darkness = "\x00" x ($sw4 * $sh); |
1218 | my $darkness = "\x00" x ($sw4 * $sh); |
1177 | |
1219 | |
… | |
… | |
1190 | } |
1232 | } |
1191 | |
1233 | |
1192 | for my $num (grep $_, @$cell[1,2,3]) { |
1234 | for my $num (grep $_, @$cell[1,2,3]) { |
1193 | my $tex = $::CONN->{face}[$num]{texture} || next; |
1235 | my $tex = $::CONN->{face}[$num]{texture} || next; |
1194 | |
1236 | |
1195 | my $w = $tex->{width}; |
1237 | my ($w, $h) = @$tex{qw(w h)}; |
1196 | my $h = $tex->{height}; |
|
|
1197 | |
1238 | |
1198 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1239 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1199 | } |
1240 | } |
1200 | } |
1241 | } |
1201 | } |
1242 | } |
… | |
… | |
1208 | # |
1249 | # |
1209 | # $lighting = $pb->get_pixels; |
1250 | # $lighting = $pb->get_pixels; |
1210 | # $lighting =~ s/(.)../$1/gs; |
1251 | # $lighting =~ s/(.)../$1/gs; |
1211 | # } |
1252 | # } |
1212 | |
1253 | |
1213 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1214 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1254 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1215 | |
1255 | |
1216 | $darkness = new CFClient::Texture |
1256 | $darkness = new CFClient::Texture |
1217 | width => $sw4, |
1257 | w => $sw4, |
1218 | height => $sh, |
1258 | h => $sh, |
1219 | data => $darkness, |
1259 | data => $darkness, |
1220 | internalformat => GL_ALPHA, |
1260 | internalformat => GL_ALPHA, |
1221 | format => GL_ALPHA; |
1261 | format => GL_ALPHA; |
1222 | |
1262 | |
1223 | glColor 0.45, 0.45, 0.45, 1; |
1263 | glColor 0.45, 0.45, 0.45, 1; |
… | |
… | |
1283 | } |
1323 | } |
1284 | } |
1324 | } |
1285 | |
1325 | |
1286 | ############################################################################# |
1326 | ############################################################################# |
1287 | |
1327 | |
1288 | package CFClient::Widget::Animator; |
1328 | package CFClient::UI::Animator; |
1289 | |
1329 | |
1290 | use SDL::OpenGL; |
1330 | use SDL::OpenGL; |
1291 | |
1331 | |
1292 | our @ISA = CFClient::Widget::Bin::; |
1332 | our @ISA = CFClient::UI::Bin::; |
1293 | |
1333 | |
1294 | sub moveto { |
1334 | sub moveto { |
1295 | my ($self, $x, $y) = @_; |
1335 | my ($self, $x, $y) = @_; |
1296 | |
1336 | |
1297 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
1337 | $self->{moveto} = [$self->{x}, $self->{y}, $x, $y]; |
… | |
… | |
1325 | glPopMatrix; |
1365 | glPopMatrix; |
1326 | } |
1366 | } |
1327 | |
1367 | |
1328 | ############################################################################# |
1368 | ############################################################################# |
1329 | |
1369 | |
1330 | package CFClient::Widget::Toplevel; |
1370 | package CFClient::UI::Toplevel; |
1331 | |
1371 | |
1332 | our @ISA = CFClient::Widget::Container::; |
1372 | our @ISA = CFClient::UI::Container::; |
1333 | |
1373 | |
1334 | sub size_request { |
1374 | sub size_request { |
1335 | ($::WIDTH, $::HEIGHT) |
1375 | ($::WIDTH, $::HEIGHT) |
1336 | } |
1376 | } |
1337 | |
1377 | |
1338 | sub size_allocate { |
1378 | sub size_allocate { |
1339 | my ($self, $w, $h) = @_; |
1379 | my ($self, $x, $y, $w, $h) = @_; |
1340 | |
1380 | |
1341 | $self->SUPER::size_allocate ($w, $h); |
1381 | $self->_size_allocate ($x, $y, $w, $h); |
1342 | |
1382 | |
1343 | $_->size_allocate ($_->size_request) |
1383 | $_->size_allocate ($_->{x}, $_->{y}, $_->size_request) |
1344 | for @{$self->{children}}; |
1384 | for @{$self->{children}}; |
1345 | } |
1385 | } |
1346 | |
1386 | |
1347 | sub translate { |
1387 | sub translate { |
1348 | my ($self, $x, $y) = @_; |
1388 | my ($self, $x, $y) = @_; |
… | |
… | |
1351 | } |
1391 | } |
1352 | |
1392 | |
1353 | sub update { |
1393 | sub update { |
1354 | my ($self) = @_; |
1394 | my ($self) = @_; |
1355 | |
1395 | |
1356 | $self->size_allocate ($self->size_request); |
1396 | $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); |
1357 | ::refresh (); |
1397 | ::refresh (); |
1358 | } |
1398 | } |
1359 | |
1399 | |
1360 | sub add { |
1400 | sub add { |
1361 | my ($self, $widget) = @_; |
1401 | my ($self, $widget) = @_; |
1362 | |
1402 | |
1363 | $self->SUPER::add ($widget); |
1403 | $self->SUPER::add ($widget); |
1364 | |
1404 | |
1365 | $widget->size_allocate ($widget->size_request); |
1405 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
1366 | } |
1406 | } |
1367 | |
1407 | |
1368 | sub draw { |
1408 | sub draw { |
1369 | my ($self) = @_; |
1409 | my ($self) = @_; |
1370 | |
1410 | |
1371 | $self->_draw; |
1411 | $self->_draw; |
1372 | } |
1412 | } |
1373 | |
1413 | |
1374 | ############################################################################# |
1414 | ############################################################################# |
1375 | |
1415 | |
1376 | package CFClient::Widget; |
1416 | package CFClient::UI; |
1377 | |
1417 | |
1378 | $TOPLEVEL = new CFClient::Widget::Toplevel; |
1418 | $TOPLEVEL = new CFClient::UI::Toplevel; |
1379 | |
1419 | |
1380 | 1 |
1420 | 1 |
1381 | |
1421 | |