… | |
… | |
87 | |
87 | |
88 | package CFClient::UI::Base; |
88 | package CFClient::UI::Base; |
89 | |
89 | |
90 | use strict; |
90 | use strict; |
91 | |
91 | |
92 | use SDL::OpenGL; |
92 | use CFClient::OpenGL; |
93 | |
93 | |
94 | sub new { |
94 | sub new { |
95 | my $class = shift; |
95 | my $class = shift; |
96 | |
96 | |
97 | my $self = bless { |
97 | my $self = bless { |
98 | x => 0, |
98 | x => 0, |
99 | y => 0, |
99 | y => 0, |
100 | z => 0, |
100 | z => 0, |
|
|
101 | can_events => 1, |
101 | @_ |
102 | @_ |
102 | }, $class; |
103 | }, $class; |
103 | |
104 | |
104 | for (keys %$self) { |
105 | for (keys %$self) { |
105 | if (/^connect_(.*)$/) { |
106 | if (/^connect_(.*)$/) { |
… | |
… | |
140 | 0 |
141 | 0 |
141 | } |
142 | } |
142 | |
143 | |
143 | sub size_request { |
144 | sub size_request { |
144 | require Carp; |
145 | require Carp; |
145 | Carp::confess "size_request is abtract"; |
146 | Carp::confess "size_request is abstract"; |
146 | } |
147 | } |
147 | |
148 | |
148 | sub configure { |
149 | sub configure { |
149 | my ($self, $x, $y, $w, $h) = @_; |
150 | my ($self, $x, $y, $w, $h) = @_; |
150 | |
151 | |
|
|
152 | if ($self->{aspect}) { |
|
|
153 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
|
|
154 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
|
|
155 | |
|
|
156 | # use alignment to adjust x, y |
|
|
157 | |
|
|
158 | $x += int +($w - $w2) * 0.5; |
|
|
159 | $y += int +($h - $h2) * 0.5; |
|
|
160 | |
|
|
161 | ($w, $h) = ($w2, $h2); |
|
|
162 | } |
|
|
163 | |
|
|
164 | if ($self->{x} != $x || $self->{y} != $y) { |
151 | $self->{x} = $x; |
165 | $self->{x} = $x; |
152 | $self->{y} = $y; |
166 | $self->{y} = $y; |
|
|
167 | $self->update; |
|
|
168 | } |
153 | |
169 | |
154 | return unless $self->{w} != $w || $self->{h} != $h; |
170 | if ($self->{w} != $w || $self->{h} != $h) { |
155 | |
|
|
156 | $self->{w} = $w; |
171 | $self->{w} = $w; |
157 | $self->{h} = $h; |
172 | $self->{h} = $h; |
158 | |
173 | |
159 | $self->size_allocate ($w, $h); |
174 | $self->size_allocate ($w, $h); |
160 | $self->update; |
175 | $self->update; |
|
|
176 | } |
161 | } |
177 | } |
162 | |
178 | |
163 | sub size_allocate { |
179 | sub size_allocate { |
164 | # nothing to be done |
180 | # nothing to be done |
165 | } |
181 | } |
… | |
… | |
263 | } |
279 | } |
264 | |
280 | |
265 | sub find_widget { |
281 | sub find_widget { |
266 | my ($self, $x, $y) = @_; |
282 | my ($self, $x, $y) = @_; |
267 | |
283 | |
|
|
284 | return () unless $self->{can_events}; |
|
|
285 | |
268 | return $self |
286 | return $self |
269 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
287 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
270 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
288 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
271 | |
289 | |
272 | () |
290 | () |
… | |
… | |
279 | } |
297 | } |
280 | |
298 | |
281 | sub check_size { |
299 | sub check_size { |
282 | my ($self) = @_; |
300 | my ($self) = @_; |
283 | |
301 | |
|
|
302 | return unless $self->{parent}; |
|
|
303 | |
284 | my ($w, $h) = $self->size_request; |
304 | my ($w, $h) = $self->size_request; |
285 | |
305 | |
286 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
306 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
287 | $self->{req_w} = $w; |
307 | $self->{req_w} = $w; |
288 | $self->{req_h} = $h; |
308 | $self->{req_h} = $h; |
289 | |
309 | |
290 | $self->{parent}->check_size |
310 | $self->{parent}->check_size; |
291 | if $self->{parent}; |
|
|
292 | } |
311 | } |
293 | } |
312 | } |
294 | |
313 | |
295 | sub update { |
314 | sub update { |
296 | my ($self) = @_; |
315 | my ($self) = @_; |
… | |
… | |
324 | package CFClient::UI::DrawBG; |
343 | package CFClient::UI::DrawBG; |
325 | |
344 | |
326 | our @ISA = CFClient::UI::Base::; |
345 | our @ISA = CFClient::UI::Base::; |
327 | |
346 | |
328 | use strict; |
347 | use strict; |
329 | use SDL::OpenGL; |
348 | use CFClient::OpenGL; |
330 | |
349 | |
331 | sub new { |
350 | sub new { |
332 | my $class = shift; |
351 | my $class = shift; |
333 | |
352 | |
334 | # range [value, low, high, page] |
353 | # range [value, low, high, page] |
… | |
… | |
363 | |
382 | |
364 | package CFClient::UI::Empty; |
383 | package CFClient::UI::Empty; |
365 | |
384 | |
366 | our @ISA = CFClient::UI::Base::; |
385 | our @ISA = CFClient::UI::Base::; |
367 | |
386 | |
|
|
387 | sub new { |
|
|
388 | my ($class, %arg) = @_; |
|
|
389 | $class->SUPER::new (can_events => 0, %arg); |
|
|
390 | } |
|
|
391 | |
368 | sub size_request { |
392 | sub size_request { |
369 | (0, 0) |
393 | (0, 0) |
370 | } |
394 | } |
371 | |
395 | |
372 | sub draw { } |
396 | sub draw { } |
… | |
… | |
380 | sub new { |
404 | sub new { |
381 | my ($class, %arg) = @_; |
405 | my ($class, %arg) = @_; |
382 | |
406 | |
383 | my $children = delete $arg{children} || []; |
407 | my $children = delete $arg{children} || []; |
384 | |
408 | |
385 | my $self = $class->SUPER::new (children => [], %arg); |
409 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
386 | $self->add ($_) for @$children; |
410 | $self->add ($_) for @$children; |
387 | |
411 | |
388 | $self |
412 | $self |
389 | } |
413 | } |
390 | |
414 | |
… | |
… | |
482 | |
506 | |
483 | package CFClient::UI::Window; |
507 | package CFClient::UI::Window; |
484 | |
508 | |
485 | our @ISA = CFClient::UI::Bin::; |
509 | our @ISA = CFClient::UI::Bin::; |
486 | |
510 | |
487 | use SDL::OpenGL; |
511 | use CFClient::OpenGL; |
488 | |
512 | |
489 | sub new { |
513 | sub new { |
490 | my ($class, %arg) = @_; |
514 | my ($class, %arg) = @_; |
491 | |
515 | |
492 | my $self = $class->SUPER::new (%arg); |
516 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
546 | sub new { die } |
570 | sub new { die } |
547 | |
571 | |
548 | sub size_request { |
572 | sub size_request { |
549 | my ($self) = @_; |
573 | my ($self) = @_; |
550 | |
574 | |
551 | @$self{qw(child_w child_h)} = $self->child->size_request; |
575 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
552 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
576 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
553 | |
577 | |
554 | @$self{qw(child_w child_h)} |
578 | @$self{qw(child_w child_h)} |
555 | } |
579 | } |
556 | |
580 | |
… | |
… | |
565 | |
589 | |
566 | package CFClient::UI::Frame; |
590 | package CFClient::UI::Frame; |
567 | |
591 | |
568 | our @ISA = CFClient::UI::Bin::; |
592 | our @ISA = CFClient::UI::Bin::; |
569 | |
593 | |
570 | use SDL::OpenGL; |
594 | use CFClient::OpenGL; |
571 | |
|
|
572 | sub size_request { |
|
|
573 | my ($self) = @_; |
|
|
574 | my $chld = $self->child |
|
|
575 | or return (0, 0); |
|
|
576 | |
|
|
577 | $chld->move (2, 2); |
|
|
578 | |
|
|
579 | map { $_ + 4 } $chld->size_request; |
|
|
580 | } |
|
|
581 | |
|
|
582 | sub size_allocate { |
|
|
583 | my ($self, $x, $y, $w, $h) = @_; |
|
|
584 | |
|
|
585 | $self->child->configure (2, 2, $w - 4, $h - 4); |
|
|
586 | } |
|
|
587 | |
|
|
588 | sub _draw { |
|
|
589 | my ($self) = @_; |
|
|
590 | |
|
|
591 | my $chld = $self->child; |
|
|
592 | |
|
|
593 | my ($w, $h) = $chld->size_request; |
|
|
594 | |
|
|
595 | glBegin GL_QUADS; |
|
|
596 | glColor 0, 0, 0; |
|
|
597 | glVertex 0 , 0; |
|
|
598 | glVertex 0 , $h + 4; |
|
|
599 | glVertex $w + 4 , $h + 4; |
|
|
600 | glVertex $w + 4 , 0; |
|
|
601 | glEnd; |
|
|
602 | |
|
|
603 | $chld->draw; |
|
|
604 | } |
|
|
605 | |
|
|
606 | ############################################################################# |
|
|
607 | |
|
|
608 | package CFClient::UI::FancyFrame; |
|
|
609 | |
|
|
610 | our @ISA = CFClient::UI::Bin::; |
|
|
611 | |
|
|
612 | use SDL::OpenGL; |
|
|
613 | |
|
|
614 | my @tex = |
|
|
615 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
616 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
617 | |
595 | |
618 | sub new { |
596 | sub new { |
619 | my $class = shift; |
597 | my $class = shift; |
620 | |
598 | |
621 | # TODO: user_x, user_y, overwrite moveto? |
|
|
622 | |
|
|
623 | $class->SUPER::new ( |
599 | my $self = $class->SUPER::new ( |
624 | bg => [1, 1, 1, 1], |
600 | bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
601 | border_bg => [1, 1, 1, 1], |
626 | border => 0.8, |
602 | border => 0.8, |
627 | @_ |
603 | @_ |
628 | ) |
604 | ); |
|
|
605 | |
|
|
606 | $self |
|
|
607 | } |
|
|
608 | |
|
|
609 | sub set_size { |
|
|
610 | my ($self, $w, $h) = @_; |
|
|
611 | $self->{req_w} = $w; |
|
|
612 | $self->{req_h} = $h; |
|
|
613 | $self->check_size; |
|
|
614 | } |
|
|
615 | |
|
|
616 | sub size_request { |
|
|
617 | my ($self) = @_; |
|
|
618 | ($self->{req_w}, $self->{req_h}) |
|
|
619 | } |
|
|
620 | |
|
|
621 | sub size_allocate { |
|
|
622 | my ($self, $w, $h) = @_; |
|
|
623 | $self->{w} = $w; |
|
|
624 | $self->{h} = $h; |
|
|
625 | $self->child->configure (0, 0, $w, $h); |
|
|
626 | } |
|
|
627 | |
|
|
628 | sub _draw { |
|
|
629 | my ($self) = @_; |
|
|
630 | |
|
|
631 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
632 | |
|
|
633 | glEnable GL_BLEND; |
|
|
634 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
635 | glEnable GL_TEXTURE_2D; |
|
|
636 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
637 | |
|
|
638 | # glBegin GL_QUADS; |
|
|
639 | # glColor 0, 0, 0, 0; |
|
|
640 | # glVertex 0 , 0; |
|
|
641 | # glVertex 0 , $h; |
|
|
642 | # glVertex $w, $h; |
|
|
643 | # glVertex $w, 0; |
|
|
644 | # glEnd; |
|
|
645 | |
|
|
646 | |
|
|
647 | $self->child->draw; |
|
|
648 | glDisable GL_BLEND; |
|
|
649 | glDisable GL_TEXTURE_2D; |
|
|
650 | } |
|
|
651 | |
|
|
652 | ############################################################################# |
|
|
653 | |
|
|
654 | package CFClient::UI::FancyFrame; |
|
|
655 | |
|
|
656 | our @ISA = CFClient::UI::Bin::; |
|
|
657 | |
|
|
658 | use CFClient::OpenGL; |
|
|
659 | |
|
|
660 | my @tex = |
|
|
661 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
662 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
663 | |
|
|
664 | sub new { |
|
|
665 | my $class = shift; |
|
|
666 | |
|
|
667 | # TODO: user_x, user_y, overwrite moveto? |
|
|
668 | |
|
|
669 | my $self = $class->SUPER::new ( |
|
|
670 | bg => [1, 1, 1, 1], |
|
|
671 | border_bg => [1, 1, 1, 1], |
|
|
672 | border => 0.8, |
|
|
673 | can_events => 1, |
|
|
674 | @_ |
|
|
675 | ); |
|
|
676 | |
|
|
677 | $self->{title} &&= new CFClient::UI::Label |
|
|
678 | align => 0, |
|
|
679 | valign => 1, |
|
|
680 | text => $self->{title}, |
|
|
681 | fontsize => 1; |
|
|
682 | |
|
|
683 | $self |
629 | } |
684 | } |
630 | |
685 | |
631 | sub border { |
686 | sub border { |
632 | int $_[0]{border} * $::FONTSIZE |
687 | int $_[0]{border} * $::FONTSIZE |
633 | } |
688 | } |
… | |
… | |
649 | my ($self, $w, $h) = @_; |
704 | my ($self, $w, $h) = @_; |
650 | |
705 | |
651 | $h -= List::Util::max 0, $self->border * 2; |
706 | $h -= List::Util::max 0, $self->border * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
707 | $w -= List::Util::max 0, $self->border * 2; |
653 | |
708 | |
|
|
709 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
710 | if $self->{title}; |
|
|
711 | |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
712 | $self->child->configure ($self->border, $self->border, $w, $h); |
655 | } |
713 | } |
656 | |
714 | |
657 | sub button_down { |
715 | sub button_down { |
658 | my ($self, $ev, $x, $y) = @_; |
716 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
660 | my $border = $self->border; |
718 | my $border = $self->border; |
661 | |
719 | |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
720 | if ($x < $self->{w} && $x >= $self->{w} - $border |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
721 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
664 | |
722 | |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
723 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
724 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
667 | |
725 | |
668 | $self->{motion} = sub { |
726 | $self->{motion} = sub { |
669 | my ($ev, $x, $y) = @_; |
727 | my ($ev, $x, $y) = @_; |
670 | |
728 | |
671 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
729 | ($x, $y) = ($ev->{x}, $ev->{y}); |
672 | |
730 | |
673 | $self->{user_w} = $bw + $x - $ox; |
731 | $self->{user_w} = $bw + $x - $ox; |
674 | $self->{user_h} = $bh + $y - $oy; |
732 | $self->{user_h} = $bh + $y - $oy; |
675 | $self->check_size; |
733 | $self->check_size; |
676 | }; |
734 | }; |
677 | |
735 | |
678 | } elsif ($x >= 0 && $x < $self->{w} |
736 | } elsif ($x >= 0 && $x < $self->{w} |
679 | && $y >= 0 && $y < $border) { |
737 | && $y >= 0 && $y < $border) { |
680 | |
738 | |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
739 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
740 | my ($bx, $by) = ($self->{x}, $self->{y}); |
683 | |
741 | |
684 | $self->{motion} = sub { |
742 | $self->{motion} = sub { |
685 | my ($ev, $x, $y) = @_; |
743 | my ($ev, $x, $y) = @_; |
686 | |
744 | |
687 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
745 | ($x, $y) = ($ev->{x}, $ev->{y}); |
688 | |
746 | |
689 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
747 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
690 | $self->update; |
748 | $self->update; |
691 | }; |
749 | }; |
692 | } |
750 | } |
… | |
… | |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
795 | $bg->draw_quad ($border, $border, $cw, $ch); |
738 | |
796 | |
739 | glDisable GL_TEXTURE_2D; |
797 | glDisable GL_TEXTURE_2D; |
740 | glDisable GL_BLEND; |
798 | glDisable GL_BLEND; |
741 | |
799 | |
|
|
800 | $self->{title}->draw if $self->{title}; |
742 | $self->child->draw; |
801 | $self->child->draw; |
743 | } |
802 | } |
744 | |
803 | |
745 | ############################################################################# |
804 | ############################################################################# |
746 | |
805 | |
… | |
… | |
748 | |
807 | |
749 | our @ISA = CFClient::UI::Base::; |
808 | our @ISA = CFClient::UI::Base::; |
750 | |
809 | |
751 | use List::Util qw(max sum); |
810 | use List::Util qw(max sum); |
752 | |
811 | |
753 | use SDL::OpenGL; |
812 | use CFClient::OpenGL; |
754 | |
813 | |
755 | sub new { |
814 | sub new { |
756 | my $class = shift; |
815 | my $class = shift; |
757 | |
816 | |
758 | $class->SUPER::new ( |
817 | $class->SUPER::new ( |
… | |
… | |
788 | or next; |
847 | or next; |
789 | |
848 | |
790 | for my $x (0 .. $#$row) { |
849 | for my $x (0 .. $#$row) { |
791 | my $widget = $row->[$x] |
850 | my $widget = $row->[$x] |
792 | or next; |
851 | or next; |
793 | my ($w, $h) = $widget->size_request; |
852 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
794 | |
853 | |
795 | $w[$x] = max $w[$x], $w; |
854 | $w[$x] = max $w[$x], $w; |
796 | $h[$y] = max $h[$y], $h; |
855 | $h[$y] = max $h[$y], $h; |
797 | } |
856 | } |
798 | } |
857 | } |
… | |
… | |
903 | |
962 | |
904 | ($h, $w) = ($w, $h); |
963 | ($h, $w) = ($w, $h); |
905 | |
964 | |
906 | my $children = $self->{children}; |
965 | my $children = $self->{children}; |
907 | |
966 | |
908 | my @h = map +($_->size_request)[0], @$children; |
967 | my @h = map $_->{req_w}, @$children; |
909 | |
968 | |
910 | my $req_h = List::Util::sum @h; |
969 | my $req_h = List::Util::sum @h; |
911 | |
970 | |
912 | if ($req_h > $h) { |
971 | if ($req_h > $h) { |
913 | # ah well, not enough space |
972 | # ah well, not enough space |
… | |
… | |
961 | sub size_allocate { |
1020 | sub size_allocate { |
962 | my ($self, $w, $h) = @_; |
1021 | my ($self, $w, $h) = @_; |
963 | |
1022 | |
964 | my $children = $self->{children}; |
1023 | my $children = $self->{children}; |
965 | |
1024 | |
966 | my @h = map +($_->size_request)[1], @$children; |
1025 | my @h = map $_->{req_h}, @$children; |
967 | |
1026 | |
968 | my $req_h = List::Util::sum @h; |
1027 | my $req_h = List::Util::sum @h; |
969 | |
1028 | |
970 | if ($req_h > $h) { |
1029 | if ($req_h > $h) { |
971 | # ah well, not enough space |
1030 | # ah well, not enough space |
… | |
… | |
999 | |
1058 | |
1000 | package CFClient::UI::Label; |
1059 | package CFClient::UI::Label; |
1001 | |
1060 | |
1002 | our @ISA = CFClient::UI::Base::; |
1061 | our @ISA = CFClient::UI::Base::; |
1003 | |
1062 | |
1004 | use SDL::OpenGL; |
1063 | use CFClient::OpenGL; |
1005 | |
1064 | |
1006 | sub new { |
1065 | sub new { |
1007 | my ($class, %arg) = @_; |
1066 | my ($class, %arg) = @_; |
1008 | |
1067 | |
1009 | my $self = $class->SUPER::new ( |
1068 | my $self = $class->SUPER::new ( |
… | |
… | |
1012 | text => "", |
1071 | text => "", |
1013 | align => -1, |
1072 | align => -1, |
1014 | valign => -1, |
1073 | valign => -1, |
1015 | padding => 2, |
1074 | padding => 2, |
1016 | layout => new CFClient::Layout, |
1075 | layout => new CFClient::Layout, |
|
|
1076 | can_events => 0, |
1017 | %arg |
1077 | %arg |
1018 | ); |
1078 | ); |
1019 | |
1079 | |
1020 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
1080 | if (exists $self->{template}) { |
|
|
1081 | my $layout = new CFClient::Layout; |
|
|
1082 | $layout->set_text (delete $self->{template}); |
|
|
1083 | $self->{template} = $layout; |
|
|
1084 | } |
1021 | |
1085 | |
1022 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1086 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1023 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1087 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1024 | |
1088 | |
1025 | $self |
1089 | $self |
… | |
… | |
1039 | my ($self, $text) = @_; |
1103 | my ($self, $text) = @_; |
1040 | |
1104 | |
1041 | $self->{layout}->set_text ($text); |
1105 | $self->{layout}->set_text ($text); |
1042 | |
1106 | |
1043 | delete $self->{texture}; |
1107 | delete $self->{texture}; |
|
|
1108 | $self->check_size; |
1044 | $self->update; |
1109 | $self->update; |
1045 | } |
1110 | } |
1046 | |
1111 | |
1047 | sub set_markup { |
1112 | sub set_markup { |
1048 | my ($self, $markup) = @_; |
1113 | my ($self, $markup) = @_; |
1049 | |
1114 | |
1050 | $self->{layout}->set_markup ($markup); |
1115 | $self->{layout}->set_markup ($markup); |
1051 | |
1116 | |
1052 | delete $self->{texture}; |
1117 | delete $self->{texture}; |
|
|
1118 | $self->check_size; |
1053 | $self->update; |
1119 | $self->update; |
1054 | } |
1120 | } |
1055 | |
1121 | |
1056 | sub size_request { |
1122 | sub size_request { |
1057 | my ($self) = @_; |
1123 | my ($self) = @_; |
1058 | |
1124 | |
1059 | $self->{layout}->set_width; |
1125 | $self->{layout}->set_width; |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1126 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1061 | |
1127 | |
1062 | my ($w, $h) = $self->{layout}->size; |
1128 | my ($w, $h) = $self->{layout}->size; |
|
|
1129 | |
|
|
1130 | if (exists $self->{template}) { |
|
|
1131 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1132 | |
|
|
1133 | my ($w2, $h2) = $self->{template}->size; |
|
|
1134 | |
|
|
1135 | $w = List::Util::max $w, $w2; |
|
|
1136 | $h = List::Util::max $h, $h2; |
|
|
1137 | } |
1063 | |
1138 | |
1064 | ( |
1139 | ( |
1065 | $w + $self->{padding} * 2, |
1140 | $w + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1141 | $h + $self->{padding} * 2, |
1067 | ) |
1142 | ) |
… | |
… | |
1069 | |
1144 | |
1070 | sub size_allocate { |
1145 | sub size_allocate { |
1071 | my ($self, $w, $h) = @_; |
1146 | my ($self, $w, $h) = @_; |
1072 | |
1147 | |
1073 | delete $self->{texture}; |
1148 | delete $self->{texture}; |
|
|
1149 | } |
|
|
1150 | |
|
|
1151 | sub set_fontsize { |
|
|
1152 | my ($self, $fontsize) = @_; |
|
|
1153 | |
|
|
1154 | $self->{fontsize} = $fontsize; |
|
|
1155 | $self->check_size; |
1074 | } |
1156 | } |
1075 | |
1157 | |
1076 | sub _draw { |
1158 | sub _draw { |
1077 | my ($self) = @_; |
1159 | my ($self) = @_; |
1078 | |
1160 | |
… | |
… | |
1111 | |
1193 | |
1112 | package CFClient::UI::EntryBase; |
1194 | package CFClient::UI::EntryBase; |
1113 | |
1195 | |
1114 | our @ISA = CFClient::UI::Label::; |
1196 | our @ISA = CFClient::UI::Label::; |
1115 | |
1197 | |
1116 | use SDL::OpenGL; |
1198 | use CFClient::OpenGL; |
1117 | |
1199 | |
1118 | sub new { |
1200 | sub new { |
1119 | my $class = shift; |
1201 | my $class = shift; |
1120 | |
1202 | |
1121 | $class->SUPER::new ( |
1203 | $class->SUPER::new ( |
… | |
… | |
1124 | active_bg => [1, 1, 1, 0.5], |
1206 | active_bg => [1, 1, 1, 0.5], |
1125 | active_fg => [0, 0, 0], |
1207 | active_fg => [0, 0, 0], |
1126 | can_hover => 1, |
1208 | can_hover => 1, |
1127 | can_focus => 1, |
1209 | can_focus => 1, |
1128 | valign => 0, |
1210 | valign => 0, |
|
|
1211 | can_events => 1, |
1129 | @_ |
1212 | @_ |
1130 | ) |
1213 | ) |
1131 | } |
1214 | } |
1132 | |
1215 | |
1133 | sub _set_text { |
1216 | sub _set_text { |
… | |
… | |
1161 | } |
1244 | } |
1162 | |
1245 | |
1163 | sub size_allocate { |
1246 | sub size_allocate { |
1164 | my ($self, $w, $h) = @_; |
1247 | my ($self, $w, $h) = @_; |
1165 | |
1248 | |
1166 | $self->_set_text ($self->{text}); |
1249 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1167 | } |
1250 | } |
1168 | |
1251 | |
1169 | sub set_text { |
1252 | sub set_text { |
1170 | my ($self, $text) = @_; |
1253 | my ($self, $text) = @_; |
1171 | |
1254 | |
… | |
… | |
1278 | |
1361 | |
1279 | package CFClient::UI::Entry; |
1362 | package CFClient::UI::Entry; |
1280 | |
1363 | |
1281 | our @ISA = CFClient::UI::EntryBase::; |
1364 | our @ISA = CFClient::UI::EntryBase::; |
1282 | |
1365 | |
1283 | use SDL::OpenGL; |
1366 | use CFClient::OpenGL; |
1284 | |
1367 | |
1285 | sub key_down { |
1368 | sub key_down { |
1286 | my ($self, $ev) = @_; |
1369 | my ($self, $ev) = @_; |
1287 | |
1370 | |
1288 | my $sym = $ev->{sym}; |
1371 | my $sym = $ev->{sym}; |
… | |
… | |
1301 | |
1384 | |
1302 | package CFClient::UI::Button; |
1385 | package CFClient::UI::Button; |
1303 | |
1386 | |
1304 | our @ISA = CFClient::UI::Label::; |
1387 | our @ISA = CFClient::UI::Label::; |
1305 | |
1388 | |
1306 | use SDL::OpenGL; |
1389 | use CFClient::OpenGL; |
1307 | |
1390 | |
1308 | my @tex = |
1391 | my @tex = |
1309 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1392 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1310 | qw(b1_button_active.png); |
1393 | qw(b1_button_active.png); |
1311 | |
1394 | |
1312 | sub new { |
1395 | sub new { |
1313 | my $class = shift; |
1396 | my $class = shift; |
1314 | |
1397 | |
… | |
… | |
1318 | bg => [1, 1, 1, 0.2], |
1401 | bg => [1, 1, 1, 0.2], |
1319 | active_fg => [0, 0, 1], |
1402 | active_fg => [0, 0, 1], |
1320 | can_hover => 1, |
1403 | can_hover => 1, |
1321 | align => 0, |
1404 | align => 0, |
1322 | valign => 0, |
1405 | valign => 0, |
|
|
1406 | can_events => 1, |
1323 | @_ |
1407 | @_ |
1324 | ) |
1408 | ) |
1325 | } |
1409 | } |
1326 | |
1410 | |
1327 | sub button_up { |
1411 | sub button_up { |
… | |
… | |
1361 | package CFClient::UI::CheckBox; |
1445 | package CFClient::UI::CheckBox; |
1362 | |
1446 | |
1363 | our @ISA = CFClient::UI::DrawBG::; |
1447 | our @ISA = CFClient::UI::DrawBG::; |
1364 | |
1448 | |
1365 | my @tex = |
1449 | my @tex = |
1366 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1450 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1367 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1451 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1368 | |
1452 | |
1369 | use SDL::OpenGL; |
1453 | use CFClient::OpenGL; |
1370 | |
1454 | |
1371 | sub new { |
1455 | sub new { |
1372 | my $class = shift; |
1456 | my $class = shift; |
1373 | |
1457 | |
1374 | $class->SUPER::new ( |
1458 | $class->SUPER::new ( |
… | |
… | |
1420 | glDisable GL_BLEND; |
1504 | glDisable GL_BLEND; |
1421 | } |
1505 | } |
1422 | |
1506 | |
1423 | ############################################################################# |
1507 | ############################################################################# |
1424 | |
1508 | |
1425 | package CFClient::UI::VGauge; |
1509 | package CFClient::UI::Image; |
1426 | |
1510 | |
1427 | our @ISA = CFClient::UI::Base::; |
1511 | our @ISA = CFClient::UI::Base::; |
1428 | |
1512 | |
1429 | use SDL::OpenGL; |
1513 | use CFClient::OpenGL; |
|
|
1514 | use Carp qw/confess/; |
1430 | |
1515 | |
1431 | my %tex = ( |
1516 | our %loaded_images; |
1432 | food => [ |
|
|
1433 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1434 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1435 | ], |
|
|
1436 | grace => [ |
|
|
1437 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1438 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1439 | ], |
|
|
1440 | hp => [ |
|
|
1441 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1442 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1443 | ], |
|
|
1444 | mana => [ |
|
|
1445 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1446 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1447 | ], |
|
|
1448 | ); |
|
|
1449 | |
1517 | |
1450 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1451 | sub new { |
1518 | sub new { |
1452 | my $class = shift; |
1519 | my $class = shift; |
1453 | |
1520 | |
1454 | my $self = $class->SUPER::new (gauge => 'food', @_); |
1521 | my $self = $class->SUPER::new (can_events => 0, @_); |
|
|
1522 | |
|
|
1523 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1524 | |
|
|
1525 | $loaded_images{$self->{image}} ||= |
|
|
1526 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1527 | |
|
|
1528 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1529 | |
|
|
1530 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1531 | |
|
|
1532 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1455 | |
1533 | |
1456 | $self |
1534 | $self |
1457 | } |
1535 | } |
1458 | |
1536 | |
1459 | sub size_request { |
1537 | sub size_request { |
1460 | my ($self) = @_; |
1538 | my ($self) = @_; |
1461 | |
1539 | |
1462 | my $tex = $tex{$self->{gauge}}[0]; |
1540 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1463 | |
|
|
1464 | @$tex{qw(w h)} |
|
|
1465 | } |
|
|
1466 | |
|
|
1467 | sub set_max { |
|
|
1468 | my ($self, $max) = @_; |
|
|
1469 | |
|
|
1470 | $self->{max_val} = $max; |
|
|
1471 | } |
|
|
1472 | |
|
|
1473 | sub set_value { |
|
|
1474 | my ($self, $val, $max) = @_; |
|
|
1475 | |
|
|
1476 | $self->set_max ($max) |
|
|
1477 | if defined $max; |
|
|
1478 | |
|
|
1479 | $max = $self->{max_val}; |
|
|
1480 | $self->{val} = $val; |
|
|
1481 | |
|
|
1482 | $self->update; |
|
|
1483 | } |
1541 | } |
1484 | |
1542 | |
1485 | sub _draw { |
1543 | sub _draw { |
1486 | my ($self) = @_; |
1544 | my ($self) = @_; |
1487 | |
1545 | |
1488 | my $tex = $tex{$self->{gauge}}; |
1546 | my $tex = $self->{tex}; |
1489 | |
1547 | |
1490 | my ($w, $h) = ($self->{w}, $self->{h}); |
1548 | my ($w, $h) = ($self->{w}, $self->{h}); |
1491 | |
1549 | |
1492 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1550 | if ($self->{rot90}) { |
1493 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1551 | glRotate 90, 0, 0, 1; |
|
|
1552 | glTranslate 0, -$self->{w}, 0; |
1494 | |
1553 | |
1495 | my $t1 = $tex->[0]; |
1554 | ($w, $h) = ($h, $w); |
1496 | my $t2 = $tex->[1]; |
1555 | } |
1497 | |
1556 | |
1498 | glEnable GL_BLEND; |
1557 | glEnable GL_BLEND; |
1499 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1558 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1500 | glEnable GL_TEXTURE_2D; |
1559 | glEnable GL_TEXTURE_2D; |
1501 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1560 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1502 | |
1561 | |
|
|
1562 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1563 | |
|
|
1564 | glDisable GL_BLEND; |
|
|
1565 | glDisable GL_TEXTURE_2D; |
|
|
1566 | } |
|
|
1567 | |
|
|
1568 | ############################################################################# |
|
|
1569 | |
|
|
1570 | package CFClient::UI::VGauge; |
|
|
1571 | |
|
|
1572 | our @ISA = CFClient::UI::Base::; |
|
|
1573 | |
|
|
1574 | use CFClient::OpenGL; |
|
|
1575 | |
|
|
1576 | my %tex = ( |
|
|
1577 | food => [ |
|
|
1578 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1579 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1580 | ], |
|
|
1581 | grace => [ |
|
|
1582 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1583 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1584 | ], |
|
|
1585 | hp => [ |
|
|
1586 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1587 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1588 | ], |
|
|
1589 | mana => [ |
|
|
1590 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1591 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1592 | ], |
|
|
1593 | ); |
|
|
1594 | |
|
|
1595 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1596 | sub new { |
|
|
1597 | my $class = shift; |
|
|
1598 | |
|
|
1599 | my $self = $class->SUPER::new ( |
|
|
1600 | type => 'food', |
|
|
1601 | @_ |
|
|
1602 | ); |
|
|
1603 | |
|
|
1604 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1605 | |
|
|
1606 | $self |
|
|
1607 | } |
|
|
1608 | |
|
|
1609 | sub size_request { |
|
|
1610 | my ($self) = @_; |
|
|
1611 | |
|
|
1612 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1613 | #@$tex{qw(w h)} |
|
|
1614 | (0, 0) |
|
|
1615 | } |
|
|
1616 | |
|
|
1617 | sub set_max { |
|
|
1618 | my ($self, $max) = @_; |
|
|
1619 | |
|
|
1620 | $self->{max_val} = $max; |
|
|
1621 | } |
|
|
1622 | |
|
|
1623 | sub set_value { |
|
|
1624 | my ($self, $val, $max) = @_; |
|
|
1625 | |
|
|
1626 | $self->set_max ($max) |
|
|
1627 | if defined $max; |
|
|
1628 | |
|
|
1629 | $max = $self->{max_val}; |
|
|
1630 | $self->{val} = $val; |
|
|
1631 | |
|
|
1632 | $self->update; |
|
|
1633 | } |
|
|
1634 | |
|
|
1635 | sub _draw { |
|
|
1636 | my ($self) = @_; |
|
|
1637 | |
|
|
1638 | my $tex = $tex{$self->{type}}; |
|
|
1639 | |
|
|
1640 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1641 | |
|
|
1642 | if ($self->{vertical}) { |
|
|
1643 | glRotate 90, 0, 0, 1; |
|
|
1644 | glTranslate 0, -$self->{w}, 0; |
|
|
1645 | |
|
|
1646 | ($w, $h) = ($h, $w); |
|
|
1647 | } |
|
|
1648 | |
|
|
1649 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1650 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1651 | |
|
|
1652 | my $t1 = $tex->[0]; |
|
|
1653 | my $t2 = $tex->[1]; |
|
|
1654 | |
|
|
1655 | glEnable GL_BLEND; |
|
|
1656 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1657 | glEnable GL_TEXTURE_2D; |
|
|
1658 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1659 | |
1503 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1660 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1504 | my $h2 = $ycut * $self->{h}; |
1661 | my $h2 = $ycut * $self->{h}; |
1505 | |
1662 | |
1506 | my $yp = 0; |
|
|
1507 | |
|
|
1508 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1663 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1509 | glBegin GL_QUADS; |
1664 | glBegin GL_QUADS; |
1510 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1665 | glTexCoord 0 , 0; glVertex 0 , 0; |
1511 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1666 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1512 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1667 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1513 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1668 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1514 | glEnd; |
1669 | glEnd; |
1515 | |
|
|
1516 | $yp += $h1; |
|
|
1517 | |
1670 | |
1518 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1671 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1519 | glBegin GL_QUADS; |
1672 | glBegin GL_QUADS; |
1520 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1673 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1521 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1674 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1522 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
1675 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1523 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1676 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1524 | glEnd; |
1677 | glEnd; |
1525 | |
1678 | |
1526 | glDisable GL_BLEND; |
1679 | glDisable GL_BLEND; |
1527 | glDisable GL_TEXTURE_2D; |
1680 | glDisable GL_TEXTURE_2D; |
1528 | } |
1681 | } |
1529 | |
1682 | |
1530 | ############################################################################# |
1683 | ############################################################################# |
1531 | |
1684 | |
|
|
1685 | package CFClient::UI::Gauge; |
|
|
1686 | |
|
|
1687 | our @ISA = CFClient::UI::VBox::; |
|
|
1688 | |
|
|
1689 | sub new { |
|
|
1690 | my ($class, %arg) = shift; |
|
|
1691 | |
|
|
1692 | my $self = $class->SUPER::new ( |
|
|
1693 | @_, |
|
|
1694 | ); |
|
|
1695 | |
|
|
1696 | $self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"; |
|
|
1697 | $self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"; |
|
|
1698 | $self->add ($self->{value}); |
|
|
1699 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
|
|
1700 | $self->add ($self->{max}); |
|
|
1701 | |
|
|
1702 | $self |
|
|
1703 | } |
|
|
1704 | |
|
|
1705 | sub size_request { |
|
|
1706 | my ($self) = @_; |
|
|
1707 | (($self->{max}->size_request)[0], 0) |
|
|
1708 | } |
|
|
1709 | |
|
|
1710 | sub set_fontsize { |
|
|
1711 | my ($self, $fsize) = @_; |
|
|
1712 | |
|
|
1713 | $self->{value}->set_fontsize ($fsize); |
|
|
1714 | $self->{max} ->set_fontsize ($fsize); |
|
|
1715 | } |
|
|
1716 | |
|
|
1717 | sub set_value { |
|
|
1718 | my ($self, $val, $max) = @_; |
|
|
1719 | |
|
|
1720 | $self->set_max ($max) |
|
|
1721 | if defined $max; |
|
|
1722 | |
|
|
1723 | $self->{gauge}->set_value ($val, $max); |
|
|
1724 | $self->{value}->set_text ($val); |
|
|
1725 | } |
|
|
1726 | |
|
|
1727 | sub set_max { |
|
|
1728 | my ($self, $max) = @_; |
|
|
1729 | |
|
|
1730 | $self->{gauge}->set_max ($max); |
|
|
1731 | $self->{max}->set_text ($max); |
|
|
1732 | } |
|
|
1733 | |
|
|
1734 | ############################################################################# |
|
|
1735 | |
1532 | package CFClient::UI::Slider; |
1736 | package CFClient::UI::Slider; |
1533 | |
1737 | |
1534 | use strict; |
1738 | use strict; |
1535 | |
1739 | |
1536 | use SDL::OpenGL; |
1740 | use CFClient::OpenGL; |
1537 | |
1741 | |
1538 | our @ISA = CFClient::UI::DrawBG::; |
1742 | our @ISA = CFClient::UI::DrawBG::; |
1539 | |
1743 | |
1540 | my @tex = |
1744 | my @tex = |
1541 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1745 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1666 | |
1870 | |
1667 | package CFClient::UI::TextView; |
1871 | package CFClient::UI::TextView; |
1668 | |
1872 | |
1669 | our @ISA = CFClient::UI::HBox::; |
1873 | our @ISA = CFClient::UI::HBox::; |
1670 | |
1874 | |
1671 | use SDL::OpenGL; |
1875 | use CFClient::OpenGL; |
1672 | |
1876 | |
1673 | sub new { |
1877 | sub new { |
1674 | my $class = shift; |
1878 | my $class = shift; |
1675 | |
1879 | |
1676 | my $self = $class->SUPER::new ( |
1880 | my $self = $class->SUPER::new ( |
… | |
… | |
1822 | |
2026 | |
1823 | ############################################################################# |
2027 | ############################################################################# |
1824 | |
2028 | |
1825 | package CFClient::UI::Animator; |
2029 | package CFClient::UI::Animator; |
1826 | |
2030 | |
1827 | use SDL::OpenGL; |
2031 | use CFClient::OpenGL; |
1828 | |
2032 | |
1829 | our @ISA = CFClient::UI::Bin::; |
2033 | our @ISA = CFClient::UI::Bin::; |
1830 | |
2034 | |
1831 | sub moveto { |
2035 | sub moveto { |
1832 | my ($self, $x, $y) = @_; |
2036 | my ($self, $x, $y) = @_; |
… | |
… | |
1872 | my $class = shift; |
2076 | my $class = shift; |
1873 | |
2077 | |
1874 | my $self = $class->SUPER::new ( |
2078 | my $self = $class->SUPER::new ( |
1875 | state => 0, |
2079 | state => 0, |
1876 | connect_activate => \&toggle_flopper, |
2080 | connect_activate => \&toggle_flopper, |
|
|
2081 | can_events => 1, |
1877 | @_ |
2082 | @_ |
1878 | ); |
2083 | ); |
1879 | |
2084 | |
1880 | if ($self->{state}) { |
2085 | if ($self->{state}) { |
1881 | $self->{state} = 0; |
2086 | $self->{state} = 0; |
… | |
… | |
1905 | |
2110 | |
1906 | package CFClient::UI::Root; |
2111 | package CFClient::UI::Root; |
1907 | |
2112 | |
1908 | our @ISA = CFClient::UI::Container::; |
2113 | our @ISA = CFClient::UI::Container::; |
1909 | |
2114 | |
1910 | use SDL::OpenGL; |
2115 | use CFClient::OpenGL; |
1911 | |
2116 | |
1912 | sub check_size { |
2117 | sub check_size { |
1913 | my ($self) = @_; |
2118 | my ($self) = @_; |
1914 | |
2119 | |
1915 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2120 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
1916 | } |
2121 | } |
1917 | |
2122 | |
1918 | sub size_request { |
2123 | sub size_request { |
1919 | ($::WIDTH, $::HEIGHT) |
2124 | ($::WIDTH, $::HEIGHT) |
1920 | } |
2125 | } |
… | |
… | |
1922 | sub configure { |
2127 | sub configure { |
1923 | my ($self, $x, $y, $w, $h) = @_; |
2128 | my ($self, $x, $y, $w, $h) = @_; |
1924 | |
2129 | |
1925 | $self->SUPER::configure ($x, $y, $w, $h); |
2130 | $self->SUPER::configure ($x, $y, $w, $h); |
1926 | |
2131 | |
1927 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
1928 | for @{$self->{children}}; |
2132 | for my $child (@{$self->{children}}) { |
|
|
2133 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2134 | |
|
|
2135 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2136 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2137 | $child->configure ($X, $Y, $W,$H); |
|
|
2138 | } |
1929 | } |
2139 | } |
1930 | |
2140 | |
1931 | sub _topleft { |
2141 | sub _topleft { |
1932 | my ($self, $x, $y) = @_; |
2142 | my ($self, $x, $y) = @_; |
1933 | |
2143 | |
… | |
… | |
1941 | ::refresh (); |
2151 | ::refresh (); |
1942 | } |
2152 | } |
1943 | |
2153 | |
1944 | sub add { |
2154 | sub add { |
1945 | my ($self, $child) = @_; |
2155 | my ($self, $child) = @_; |
|
|
2156 | |
|
|
2157 | # integerize window positions |
|
|
2158 | $child->{x} = int $child->{x}; |
|
|
2159 | $child->{y} = int $child->{y}; |
1946 | |
2160 | |
1947 | $self->SUPER::add ($child); |
2161 | $self->SUPER::add ($child); |
1948 | } |
2162 | } |
1949 | |
2163 | |
1950 | sub on_refresh { |
2164 | sub on_refresh { |