… | |
… | |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
21 | $FOCUS->key_up ($_[0]) if $FOCUS; |
22 | } |
22 | } |
23 | |
23 | |
24 | sub feed_sdl_button_down_event { |
24 | sub feed_sdl_button_down_event { |
25 | my ($ev) = @_; |
25 | my ($ev) = @_; |
26 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
26 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
27 | |
27 | |
28 | if (!$BUTTON_STATE) { |
28 | if (!$BUTTON_STATE) { |
29 | my $widget = $ROOT->find_widget ($x, $y); |
29 | my $widget = $ROOT->find_widget ($x, $y); |
30 | |
30 | |
31 | $GRAB = $widget; |
31 | $GRAB = $widget; |
32 | $GRAB->update if $GRAB; |
32 | $GRAB->update if $GRAB; |
33 | } |
33 | } |
34 | |
34 | |
35 | $BUTTON_STATE |= 1 << ($ev->button - 1); |
35 | $BUTTON_STATE |= 1 << ($ev->{button} - 1); |
36 | |
36 | |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
37 | $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
38 | } |
38 | } |
39 | |
39 | |
40 | sub feed_sdl_button_up_event { |
40 | sub feed_sdl_button_up_event { |
41 | my ($ev) = @_; |
41 | my ($ev) = @_; |
42 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
42 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
43 | |
43 | |
44 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
44 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
45 | |
45 | |
46 | $BUTTON_STATE &= ~(1 << ($ev->button - 1)); |
46 | $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); |
47 | |
47 | |
48 | $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
48 | $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; |
49 | |
49 | |
50 | if (!$BUTTON_STATE) { |
50 | if (!$BUTTON_STATE) { |
51 | my $grab = $GRAB; undef $GRAB; |
51 | my $grab = $GRAB; undef $GRAB; |
… | |
… | |
54 | } |
54 | } |
55 | } |
55 | } |
56 | |
56 | |
57 | sub feed_sdl_motion_event { |
57 | sub feed_sdl_motion_event { |
58 | my ($ev) = @_; |
58 | my ($ev) = @_; |
59 | my ($x, $y) = ($ev->motion_x, $ev->motion_y); |
59 | my ($x, $y) = ($ev->{x}, $ev->{y}); |
60 | |
60 | |
61 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
61 | my $widget = $GRAB || $ROOT->find_widget ($x, $y); |
62 | |
62 | |
63 | if ($widget != $HOVER) { |
63 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
64 | my $hover = $HOVER; $HOVER = $widget; |
… | |
… | |
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 { |
… | |
… | |
140 | 0 |
140 | 0 |
141 | } |
141 | } |
142 | |
142 | |
143 | sub size_request { |
143 | sub size_request { |
144 | require Carp; |
144 | require Carp; |
145 | Carp::confess "size_request is abtract"; |
145 | Carp::confess "size_request is abstract"; |
146 | } |
146 | } |
147 | |
147 | |
148 | sub configure { |
148 | sub configure { |
149 | my ($self, $x, $y, $w, $h) = @_; |
149 | my ($self, $x, $y, $w, $h) = @_; |
150 | |
150 | |
|
|
151 | if ($self->{aspect}) { |
|
|
152 | my $w2 = List::Util::min $w, int $h * $self->{aspect}; |
|
|
153 | my $h2 = List::Util::min $h, int $w / $self->{aspect}; |
|
|
154 | |
|
|
155 | # use alignment to adjust x, y |
|
|
156 | |
|
|
157 | $x += int +($w - $w2) * 0.5; |
|
|
158 | $y += int +($h - $h2) * 0.5; |
|
|
159 | |
|
|
160 | ($w, $h) = ($w2, $h2); |
|
|
161 | } |
|
|
162 | |
|
|
163 | if ($self->{x} != $x || $self->{y} != $y) { |
151 | $self->{x} = $x; |
164 | $self->{x} = $x; |
152 | $self->{y} = $y; |
165 | $self->{y} = $y; |
|
|
166 | $self->update; |
|
|
167 | } |
153 | |
168 | |
154 | return unless $self->{w} != $w || $self->{h} != $h; |
169 | if ($self->{w} != $w || $self->{h} != $h) { |
155 | |
|
|
156 | $self->{w} = $w; |
170 | $self->{w} = $w; |
157 | $self->{h} = $h; |
171 | $self->{h} = $h; |
158 | |
172 | |
159 | $self->size_allocate ($w, $h); |
173 | $self->size_allocate ($w, $h); |
160 | $self->update; |
174 | $self->update; |
|
|
175 | } |
161 | } |
176 | } |
162 | |
177 | |
163 | sub size_allocate { |
178 | sub size_allocate { |
164 | # nothing to be done |
179 | # nothing to be done |
165 | } |
180 | } |
… | |
… | |
279 | } |
294 | } |
280 | |
295 | |
281 | sub check_size { |
296 | sub check_size { |
282 | my ($self) = @_; |
297 | my ($self) = @_; |
283 | |
298 | |
|
|
299 | return unless $self->{parent}; |
|
|
300 | |
284 | my ($w, $h) = $self->size_request; |
301 | my ($w, $h) = $self->size_request; |
285 | |
302 | |
286 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
303 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
287 | $self->{req_w} = $w; |
304 | $self->{req_w} = $w; |
288 | $self->{req_h} = $h; |
305 | $self->{req_h} = $h; |
289 | |
306 | |
290 | $self->{parent}->check_size |
307 | $self->{parent}->check_size; |
291 | if $self->{parent}; |
|
|
292 | } |
308 | } |
293 | } |
309 | } |
294 | |
310 | |
295 | sub update { |
311 | sub update { |
296 | my ($self) = @_; |
312 | my ($self) = @_; |
… | |
… | |
324 | package CFClient::UI::DrawBG; |
340 | package CFClient::UI::DrawBG; |
325 | |
341 | |
326 | our @ISA = CFClient::UI::Base::; |
342 | our @ISA = CFClient::UI::Base::; |
327 | |
343 | |
328 | use strict; |
344 | use strict; |
329 | use SDL::OpenGL; |
345 | use CFClient::OpenGL; |
330 | |
346 | |
331 | sub new { |
347 | sub new { |
332 | my $class = shift; |
348 | my $class = shift; |
333 | |
349 | |
334 | # range [value, low, high, page] |
350 | # range [value, low, high, page] |
… | |
… | |
482 | |
498 | |
483 | package CFClient::UI::Window; |
499 | package CFClient::UI::Window; |
484 | |
500 | |
485 | our @ISA = CFClient::UI::Bin::; |
501 | our @ISA = CFClient::UI::Bin::; |
486 | |
502 | |
487 | use SDL::OpenGL; |
503 | use CFClient::OpenGL; |
488 | |
504 | |
489 | sub new { |
505 | sub new { |
490 | my ($class, %arg) = @_; |
506 | my ($class, %arg) = @_; |
491 | |
507 | |
492 | my $self = $class->SUPER::new (%arg); |
508 | my $self = $class->SUPER::new (%arg); |
… | |
… | |
546 | sub new { die } |
562 | sub new { die } |
547 | |
563 | |
548 | sub size_request { |
564 | sub size_request { |
549 | my ($self) = @_; |
565 | my ($self) = @_; |
550 | |
566 | |
551 | @$self{qw(child_w child_h)} = $self->child->size_request; |
567 | @$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)}); |
568 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
553 | |
569 | |
554 | @$self{qw(child_w child_h)} |
570 | @$self{qw(child_w child_h)} |
555 | } |
571 | } |
556 | |
572 | |
… | |
… | |
565 | |
581 | |
566 | package CFClient::UI::Frame; |
582 | package CFClient::UI::Frame; |
567 | |
583 | |
568 | our @ISA = CFClient::UI::Bin::; |
584 | our @ISA = CFClient::UI::Bin::; |
569 | |
585 | |
570 | use SDL::OpenGL; |
586 | 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 | |
587 | |
618 | sub new { |
588 | sub new { |
619 | my $class = shift; |
589 | my $class = shift; |
620 | |
590 | |
621 | # TODO: user_x, user_y, overwrite moveto? |
|
|
622 | |
|
|
623 | $class->SUPER::new ( |
591 | my $self = $class->SUPER::new ( |
624 | bg => [1, 1, 1, 1], |
592 | bg => [1, 1, 1, 1], |
625 | border_bg => [1, 1, 1, 1], |
593 | border_bg => [1, 1, 1, 1], |
626 | border => 0.8, |
594 | border => 0.8, |
627 | @_ |
595 | @_ |
628 | ) |
596 | ); |
|
|
597 | |
|
|
598 | $self |
|
|
599 | } |
|
|
600 | |
|
|
601 | sub set_size { |
|
|
602 | my ($self, $w, $h) = @_; |
|
|
603 | $self->{req_w} = $w; |
|
|
604 | $self->{req_h} = $h; |
|
|
605 | $self->check_size; |
|
|
606 | } |
|
|
607 | |
|
|
608 | sub size_request { |
|
|
609 | my ($self) = @_; |
|
|
610 | ($self->{req_w}, $self->{req_h}) |
|
|
611 | } |
|
|
612 | |
|
|
613 | sub size_allocate { |
|
|
614 | my ($self, $w, $h) = @_; |
|
|
615 | $self->{w} = $w; |
|
|
616 | $self->{h} = $h; |
|
|
617 | $self->child->configure (0, 0, $w, $h); |
|
|
618 | } |
|
|
619 | |
|
|
620 | sub _draw { |
|
|
621 | my ($self) = @_; |
|
|
622 | |
|
|
623 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
624 | |
|
|
625 | glEnable GL_BLEND; |
|
|
626 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
627 | glEnable GL_TEXTURE_2D; |
|
|
628 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
629 | |
|
|
630 | # glBegin GL_QUADS; |
|
|
631 | # glColor 0, 0, 0, 0; |
|
|
632 | # glVertex 0 , 0; |
|
|
633 | # glVertex 0 , $h; |
|
|
634 | # glVertex $w, $h; |
|
|
635 | # glVertex $w, 0; |
|
|
636 | # glEnd; |
|
|
637 | |
|
|
638 | |
|
|
639 | $self->child->draw; |
|
|
640 | glDisable GL_BLEND; |
|
|
641 | glDisable GL_TEXTURE_2D; |
|
|
642 | } |
|
|
643 | |
|
|
644 | ############################################################################# |
|
|
645 | |
|
|
646 | package CFClient::UI::FancyFrame; |
|
|
647 | |
|
|
648 | our @ISA = CFClient::UI::Bin::; |
|
|
649 | |
|
|
650 | use CFClient::OpenGL; |
|
|
651 | |
|
|
652 | my @tex = |
|
|
653 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
654 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
|
|
655 | |
|
|
656 | sub new { |
|
|
657 | my $class = shift; |
|
|
658 | |
|
|
659 | # TODO: user_x, user_y, overwrite moveto? |
|
|
660 | |
|
|
661 | my $self = $class->SUPER::new ( |
|
|
662 | bg => [1, 1, 1, 1], |
|
|
663 | border_bg => [1, 1, 1, 1], |
|
|
664 | border => 0.8, |
|
|
665 | @_ |
|
|
666 | ); |
|
|
667 | |
|
|
668 | $self->{title} &&= new CFClient::UI::Label |
|
|
669 | align => 0, |
|
|
670 | valign => 1, |
|
|
671 | text => $self->{title}, |
|
|
672 | fontsize => 1; |
|
|
673 | |
|
|
674 | $self |
629 | } |
675 | } |
630 | |
676 | |
631 | sub border { |
677 | sub border { |
632 | int $_[0]{border} * $::FONTSIZE |
678 | int $_[0]{border} * $::FONTSIZE |
633 | } |
679 | } |
… | |
… | |
649 | my ($self, $w, $h) = @_; |
695 | my ($self, $w, $h) = @_; |
650 | |
696 | |
651 | $h -= List::Util::max 0, $self->border * 2; |
697 | $h -= List::Util::max 0, $self->border * 2; |
652 | $w -= List::Util::max 0, $self->border * 2; |
698 | $w -= List::Util::max 0, $self->border * 2; |
653 | |
699 | |
|
|
700 | $self->{title}->configure ($self->border, $self->border - $::FONTSIZE * 2, $w, $::FONTSIZE * 2) |
|
|
701 | if $self->{title}; |
|
|
702 | |
654 | $self->child->configure ($self->border, $self->border, $w, $h); |
703 | $self->child->configure ($self->border, $self->border, $w, $h); |
655 | } |
704 | } |
656 | |
705 | |
657 | sub button_down { |
706 | sub button_down { |
658 | my ($self, $ev, $x, $y) = @_; |
707 | my ($self, $ev, $x, $y) = @_; |
… | |
… | |
660 | my $border = $self->border; |
709 | my $border = $self->border; |
661 | |
710 | |
662 | if ($x < $self->{w} && $x >= $self->{w} - $border |
711 | if ($x < $self->{w} && $x >= $self->{w} - $border |
663 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
712 | && $y < $self->{h} && $y >= $self->{h} - $border) { |
664 | |
713 | |
665 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
714 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
666 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
715 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
667 | |
716 | |
668 | $self->{motion} = sub { |
717 | $self->{motion} = sub { |
669 | my ($ev, $x, $y) = @_; |
718 | my ($ev, $x, $y) = @_; |
670 | |
719 | |
671 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
720 | ($x, $y) = ($ev->{x}, $ev->{y}); |
672 | |
721 | |
673 | $self->{user_w} = $bw + $x - $ox; |
722 | $self->{user_w} = $bw + $x - $ox; |
674 | $self->{user_h} = $bh + $y - $oy; |
723 | $self->{user_h} = $bh + $y - $oy; |
675 | $self->check_size; |
724 | $self->check_size; |
676 | }; |
725 | }; |
677 | |
726 | |
678 | } elsif ($x >= 0 && $x < $self->{w} |
727 | } elsif ($x >= 0 && $x < $self->{w} |
679 | && $y >= 0 && $y < $border) { |
728 | && $y >= 0 && $y < $border) { |
680 | |
729 | |
681 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
730 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
682 | my ($bx, $by) = ($self->{x}, $self->{y}); |
731 | my ($bx, $by) = ($self->{x}, $self->{y}); |
683 | |
732 | |
684 | $self->{motion} = sub { |
733 | $self->{motion} = sub { |
685 | my ($ev, $x, $y) = @_; |
734 | my ($ev, $x, $y) = @_; |
686 | |
735 | |
687 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
736 | ($x, $y) = ($ev->{x}, $ev->{y}); |
688 | |
737 | |
689 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
738 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
690 | $self->update; |
739 | $self->update; |
691 | }; |
740 | }; |
692 | } |
741 | } |
… | |
… | |
737 | $bg->draw_quad ($border, $border, $cw, $ch); |
786 | $bg->draw_quad ($border, $border, $cw, $ch); |
738 | |
787 | |
739 | glDisable GL_TEXTURE_2D; |
788 | glDisable GL_TEXTURE_2D; |
740 | glDisable GL_BLEND; |
789 | glDisable GL_BLEND; |
741 | |
790 | |
|
|
791 | $self->{title}->draw if $self->{title}; |
742 | $self->child->draw; |
792 | $self->child->draw; |
743 | } |
793 | } |
744 | |
794 | |
745 | ############################################################################# |
795 | ############################################################################# |
746 | |
796 | |
… | |
… | |
748 | |
798 | |
749 | our @ISA = CFClient::UI::Base::; |
799 | our @ISA = CFClient::UI::Base::; |
750 | |
800 | |
751 | use List::Util qw(max sum); |
801 | use List::Util qw(max sum); |
752 | |
802 | |
753 | use SDL::OpenGL; |
803 | use CFClient::OpenGL; |
754 | |
804 | |
755 | sub new { |
805 | sub new { |
756 | my $class = shift; |
806 | my $class = shift; |
757 | |
807 | |
758 | $class->SUPER::new ( |
808 | $class->SUPER::new ( |
… | |
… | |
788 | or next; |
838 | or next; |
789 | |
839 | |
790 | for my $x (0 .. $#$row) { |
840 | for my $x (0 .. $#$row) { |
791 | my $widget = $row->[$x] |
841 | my $widget = $row->[$x] |
792 | or next; |
842 | or next; |
793 | my ($w, $h) = $widget->size_request; |
843 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
794 | |
844 | |
795 | $w[$x] = max $w[$x], $w; |
845 | $w[$x] = max $w[$x], $w; |
796 | $h[$y] = max $h[$y], $h; |
846 | $h[$y] = max $h[$y], $h; |
797 | } |
847 | } |
798 | } |
848 | } |
… | |
… | |
903 | |
953 | |
904 | ($h, $w) = ($w, $h); |
954 | ($h, $w) = ($w, $h); |
905 | |
955 | |
906 | my $children = $self->{children}; |
956 | my $children = $self->{children}; |
907 | |
957 | |
908 | my @h = map +($_->size_request)[0], @$children; |
958 | my @h = map $_->{req_w}, @$children; |
909 | |
959 | |
910 | my $req_h = List::Util::sum @h; |
960 | my $req_h = List::Util::sum @h; |
911 | |
961 | |
912 | if ($req_h > $h) { |
962 | if ($req_h > $h) { |
913 | # ah well, not enough space |
963 | # ah well, not enough space |
… | |
… | |
961 | sub size_allocate { |
1011 | sub size_allocate { |
962 | my ($self, $w, $h) = @_; |
1012 | my ($self, $w, $h) = @_; |
963 | |
1013 | |
964 | my $children = $self->{children}; |
1014 | my $children = $self->{children}; |
965 | |
1015 | |
966 | my @h = map +($_->size_request)[1], @$children; |
1016 | my @h = map $_->{req_h}, @$children; |
967 | |
1017 | |
968 | my $req_h = List::Util::sum @h; |
1018 | my $req_h = List::Util::sum @h; |
969 | |
1019 | |
970 | if ($req_h > $h) { |
1020 | if ($req_h > $h) { |
971 | # ah well, not enough space |
1021 | # ah well, not enough space |
… | |
… | |
999 | |
1049 | |
1000 | package CFClient::UI::Label; |
1050 | package CFClient::UI::Label; |
1001 | |
1051 | |
1002 | our @ISA = CFClient::UI::Base::; |
1052 | our @ISA = CFClient::UI::Base::; |
1003 | |
1053 | |
1004 | use SDL::OpenGL; |
1054 | use CFClient::OpenGL; |
1005 | |
1055 | |
1006 | sub new { |
1056 | sub new { |
1007 | my ($class, %arg) = @_; |
1057 | my ($class, %arg) = @_; |
1008 | |
1058 | |
1009 | my $self = $class->SUPER::new ( |
1059 | my $self = $class->SUPER::new ( |
… | |
… | |
1015 | padding => 2, |
1065 | padding => 2, |
1016 | layout => new CFClient::Layout, |
1066 | layout => new CFClient::Layout, |
1017 | %arg |
1067 | %arg |
1018 | ); |
1068 | ); |
1019 | |
1069 | |
1020 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
1070 | if (exists $self->{template}) { |
|
|
1071 | my $layout = new CFClient::Layout; |
|
|
1072 | $layout->set_text (delete $self->{template}); |
|
|
1073 | $self->{template} = $layout; |
|
|
1074 | } |
1021 | |
1075 | |
1022 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1076 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
1023 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1077 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
1024 | |
1078 | |
1025 | $self |
1079 | $self |
… | |
… | |
1039 | my ($self, $text) = @_; |
1093 | my ($self, $text) = @_; |
1040 | |
1094 | |
1041 | $self->{layout}->set_text ($text); |
1095 | $self->{layout}->set_text ($text); |
1042 | |
1096 | |
1043 | delete $self->{texture}; |
1097 | delete $self->{texture}; |
|
|
1098 | $self->check_size; |
1044 | $self->update; |
1099 | $self->update; |
1045 | } |
1100 | } |
1046 | |
1101 | |
1047 | sub set_markup { |
1102 | sub set_markup { |
1048 | my ($self, $markup) = @_; |
1103 | my ($self, $markup) = @_; |
1049 | |
1104 | |
1050 | $self->{layout}->set_markup ($markup); |
1105 | $self->{layout}->set_markup ($markup); |
1051 | |
1106 | |
1052 | delete $self->{texture}; |
1107 | delete $self->{texture}; |
|
|
1108 | $self->check_size; |
1053 | $self->update; |
1109 | $self->update; |
1054 | } |
1110 | } |
1055 | |
1111 | |
1056 | sub size_request { |
1112 | sub size_request { |
1057 | my ($self) = @_; |
1113 | my ($self) = @_; |
1058 | |
1114 | |
1059 | $self->{layout}->set_width; |
1115 | $self->{layout}->set_width; |
1060 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1116 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1061 | |
1117 | |
1062 | my ($w, $h) = $self->{layout}->size; |
1118 | my ($w, $h) = $self->{layout}->size; |
|
|
1119 | |
|
|
1120 | if (exists $self->{template}) { |
|
|
1121 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
|
|
1122 | |
|
|
1123 | my ($w2, $h2) = $self->{template}->size; |
|
|
1124 | |
|
|
1125 | $w = List::Util::max $w, $w2; |
|
|
1126 | $h = List::Util::max $h, $h2; |
|
|
1127 | } |
1063 | |
1128 | |
1064 | ( |
1129 | ( |
1065 | $w + $self->{padding} * 2, |
1130 | $w + $self->{padding} * 2, |
1066 | $h + $self->{padding} * 2, |
1131 | $h + $self->{padding} * 2, |
1067 | ) |
1132 | ) |
… | |
… | |
1069 | |
1134 | |
1070 | sub size_allocate { |
1135 | sub size_allocate { |
1071 | my ($self, $w, $h) = @_; |
1136 | my ($self, $w, $h) = @_; |
1072 | |
1137 | |
1073 | delete $self->{texture}; |
1138 | delete $self->{texture}; |
|
|
1139 | } |
|
|
1140 | |
|
|
1141 | sub set_fontsize { |
|
|
1142 | my ($self, $fontsize) = @_; |
|
|
1143 | |
|
|
1144 | $self->{fontsize} = $fontsize; |
|
|
1145 | $self->check_size; |
1074 | } |
1146 | } |
1075 | |
1147 | |
1076 | sub _draw { |
1148 | sub _draw { |
1077 | my ($self) = @_; |
1149 | my ($self) = @_; |
1078 | |
1150 | |
… | |
… | |
1111 | |
1183 | |
1112 | package CFClient::UI::EntryBase; |
1184 | package CFClient::UI::EntryBase; |
1113 | |
1185 | |
1114 | our @ISA = CFClient::UI::Label::; |
1186 | our @ISA = CFClient::UI::Label::; |
1115 | |
1187 | |
1116 | use SDL::OpenGL; |
1188 | use CFClient::OpenGL; |
1117 | |
1189 | |
1118 | sub new { |
1190 | sub new { |
1119 | my $class = shift; |
1191 | my $class = shift; |
1120 | |
1192 | |
1121 | $class->SUPER::new ( |
1193 | $class->SUPER::new ( |
… | |
… | |
1161 | } |
1233 | } |
1162 | |
1234 | |
1163 | sub size_allocate { |
1235 | sub size_allocate { |
1164 | my ($self, $w, $h) = @_; |
1236 | my ($self, $w, $h) = @_; |
1165 | |
1237 | |
1166 | $self->_set_text ($self->{text}); |
1238 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1167 | } |
1239 | } |
1168 | |
1240 | |
1169 | sub set_text { |
1241 | sub set_text { |
1170 | my ($self, $text) = @_; |
1242 | my ($self, $text) = @_; |
1171 | |
1243 | |
… | |
… | |
1175 | } |
1247 | } |
1176 | |
1248 | |
1177 | sub key_down { |
1249 | sub key_down { |
1178 | my ($self, $ev) = @_; |
1250 | my ($self, $ev) = @_; |
1179 | |
1251 | |
1180 | my $mod = $ev->key_mod; |
1252 | my $mod = $ev->{mod}; |
1181 | my $sym = $ev->key_sym; |
1253 | my $sym = $ev->{sym}; |
1182 | |
|
|
1183 | my $uni = $ev->key_unicode; |
1254 | my $uni = $ev->{unicode}; |
1184 | |
1255 | |
1185 | my $text = $self->get_text; |
1256 | my $text = $self->get_text; |
1186 | |
1257 | |
1187 | if ($sym == 8) { |
1258 | if ($sym == 8) { |
1188 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
1259 | substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; |
… | |
… | |
1279 | |
1350 | |
1280 | package CFClient::UI::Entry; |
1351 | package CFClient::UI::Entry; |
1281 | |
1352 | |
1282 | our @ISA = CFClient::UI::EntryBase::; |
1353 | our @ISA = CFClient::UI::EntryBase::; |
1283 | |
1354 | |
1284 | use SDL::OpenGL; |
1355 | use CFClient::OpenGL; |
1285 | |
1356 | |
1286 | sub key_down { |
1357 | sub key_down { |
1287 | my ($self, $ev) = @_; |
1358 | my ($self, $ev) = @_; |
1288 | |
1359 | |
1289 | my $sym = $ev->key_sym; |
1360 | my $sym = $ev->{sym}; |
1290 | |
1361 | |
1291 | if ($sym == 13) { |
1362 | if ($sym == 13) { |
1292 | $self->emit (activate => $self->get_text); |
1363 | $self->emit (activate => $self->get_text); |
1293 | $self->update; |
1364 | $self->update; |
1294 | |
1365 | |
… | |
… | |
1302 | |
1373 | |
1303 | package CFClient::UI::Button; |
1374 | package CFClient::UI::Button; |
1304 | |
1375 | |
1305 | our @ISA = CFClient::UI::Label::; |
1376 | our @ISA = CFClient::UI::Label::; |
1306 | |
1377 | |
1307 | use SDL::OpenGL; |
1378 | use CFClient::OpenGL; |
1308 | |
1379 | |
1309 | my @tex = |
1380 | my @tex = |
1310 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1381 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1311 | qw(b1_button_active.png); |
1382 | qw(b1_button_active.png); |
1312 | |
1383 | |
1313 | sub new { |
1384 | sub new { |
1314 | my $class = shift; |
1385 | my $class = shift; |
1315 | |
1386 | |
… | |
… | |
1362 | package CFClient::UI::CheckBox; |
1433 | package CFClient::UI::CheckBox; |
1363 | |
1434 | |
1364 | our @ISA = CFClient::UI::DrawBG::; |
1435 | our @ISA = CFClient::UI::DrawBG::; |
1365 | |
1436 | |
1366 | my @tex = |
1437 | my @tex = |
1367 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1368 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1439 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
1369 | |
1440 | |
1370 | use SDL::OpenGL; |
1441 | use CFClient::OpenGL; |
1371 | |
1442 | |
1372 | sub new { |
1443 | sub new { |
1373 | my $class = shift; |
1444 | my $class = shift; |
1374 | |
1445 | |
1375 | $class->SUPER::new ( |
1446 | $class->SUPER::new ( |
… | |
… | |
1421 | glDisable GL_BLEND; |
1492 | glDisable GL_BLEND; |
1422 | } |
1493 | } |
1423 | |
1494 | |
1424 | ############################################################################# |
1495 | ############################################################################# |
1425 | |
1496 | |
1426 | package CFClient::UI::VGauge; |
1497 | package CFClient::UI::Image; |
1427 | |
1498 | |
1428 | our @ISA = CFClient::UI::Base::; |
1499 | our @ISA = CFClient::UI::Base::; |
1429 | |
1500 | |
1430 | use SDL::OpenGL; |
1501 | use CFClient::OpenGL; |
|
|
1502 | use Carp qw/confess/; |
1431 | |
1503 | |
1432 | my %tex = ( |
1504 | our %loaded_images; |
1433 | food => [ |
|
|
1434 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1435 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1436 | ], |
|
|
1437 | grace => [ |
|
|
1438 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1439 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1440 | ], |
|
|
1441 | hp => [ |
|
|
1442 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1443 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1444 | ], |
|
|
1445 | mana => [ |
|
|
1446 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1447 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1448 | ], |
|
|
1449 | ); |
|
|
1450 | |
1505 | |
1451 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1452 | sub new { |
1506 | sub new { |
1453 | my $class = shift; |
1507 | my $class = shift; |
1454 | |
1508 | |
1455 | my $self = $class->SUPER::new (gauge => 'food', @_); |
1509 | my $self = $class->SUPER::new (@_); |
|
|
1510 | |
|
|
1511 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
|
|
1512 | |
|
|
1513 | $loaded_images{$self->{image}} ||= |
|
|
1514 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
|
|
1515 | |
|
|
1516 | my $tex = $self->{tex} = $loaded_images{$self->{image}}; |
|
|
1517 | |
|
|
1518 | Scalar::Util::weaken $loaded_images{$self->{image}}; |
|
|
1519 | |
|
|
1520 | $self->{aspect} = $tex->{w} / $tex->{h}; |
1456 | |
1521 | |
1457 | $self |
1522 | $self |
1458 | } |
1523 | } |
1459 | |
1524 | |
1460 | sub size_request { |
1525 | sub size_request { |
1461 | my ($self) = @_; |
1526 | my ($self) = @_; |
1462 | |
1527 | |
1463 | my $tex = $tex{$self->{gauge}}[0]; |
1528 | ($self->{tex}->{w}, $self->{tex}->{h}) |
1464 | |
|
|
1465 | @$tex{qw(w h)} |
|
|
1466 | } |
|
|
1467 | |
|
|
1468 | sub set_max { |
|
|
1469 | my ($self, $max) = @_; |
|
|
1470 | |
|
|
1471 | $self->{max_val} = $max; |
|
|
1472 | } |
|
|
1473 | |
|
|
1474 | sub set_value { |
|
|
1475 | my ($self, $val, $max) = @_; |
|
|
1476 | |
|
|
1477 | $self->set_max ($max) |
|
|
1478 | if defined $max; |
|
|
1479 | |
|
|
1480 | $max = $self->{max_val}; |
|
|
1481 | $self->{val} = $val; |
|
|
1482 | |
|
|
1483 | $self->update; |
|
|
1484 | } |
1529 | } |
1485 | |
1530 | |
1486 | sub _draw { |
1531 | sub _draw { |
1487 | my ($self) = @_; |
1532 | my ($self) = @_; |
1488 | |
1533 | |
1489 | my $tex = $tex{$self->{gauge}}; |
1534 | my $tex = $self->{tex}; |
1490 | |
1535 | |
1491 | my ($w, $h) = ($self->{w}, $self->{h}); |
1536 | my ($w, $h) = ($self->{w}, $self->{h}); |
1492 | |
1537 | |
1493 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
1538 | if ($self->{rot90}) { |
1494 | $ycut = 1 if $self->{val} > $self->{max_val}; |
1539 | glRotate 90, 0, 0, 1; |
|
|
1540 | glTranslate 0, -$self->{w}, 0; |
1495 | |
1541 | |
1496 | my $t1 = $tex->[0]; |
1542 | ($w, $h) = ($h, $w); |
1497 | my $t2 = $tex->[1]; |
1543 | } |
1498 | |
1544 | |
1499 | glEnable GL_BLEND; |
1545 | glEnable GL_BLEND; |
1500 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1546 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1501 | glEnable GL_TEXTURE_2D; |
1547 | glEnable GL_TEXTURE_2D; |
1502 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1548 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1503 | |
1549 | |
|
|
1550 | $tex->draw_quad (0, 0, $w, $h); |
|
|
1551 | |
|
|
1552 | glDisable GL_BLEND; |
|
|
1553 | glDisable GL_TEXTURE_2D; |
|
|
1554 | } |
|
|
1555 | |
|
|
1556 | ############################################################################# |
|
|
1557 | |
|
|
1558 | package CFClient::UI::VGauge; |
|
|
1559 | |
|
|
1560 | our @ISA = CFClient::UI::Base::; |
|
|
1561 | |
|
|
1562 | use CFClient::OpenGL; |
|
|
1563 | |
|
|
1564 | my %tex = ( |
|
|
1565 | food => [ |
|
|
1566 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1567 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1568 | ], |
|
|
1569 | grace => [ |
|
|
1570 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1571 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1572 | ], |
|
|
1573 | hp => [ |
|
|
1574 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1575 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1576 | ], |
|
|
1577 | mana => [ |
|
|
1578 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
|
|
1579 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1580 | ], |
|
|
1581 | ); |
|
|
1582 | |
|
|
1583 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1584 | sub new { |
|
|
1585 | my $class = shift; |
|
|
1586 | |
|
|
1587 | my $self = $class->SUPER::new ( |
|
|
1588 | type => 'food', |
|
|
1589 | @_ |
|
|
1590 | ); |
|
|
1591 | |
|
|
1592 | $self->{aspect} = $tex{$self->{type}}[0]{w} / $tex{$self->{type}}[0]{h}; |
|
|
1593 | |
|
|
1594 | $self |
|
|
1595 | } |
|
|
1596 | |
|
|
1597 | sub size_request { |
|
|
1598 | my ($self) = @_; |
|
|
1599 | |
|
|
1600 | #my $tex = $tex{$self->{type}}[0]; |
|
|
1601 | #@$tex{qw(w h)} |
|
|
1602 | (0, 0) |
|
|
1603 | } |
|
|
1604 | |
|
|
1605 | sub set_max { |
|
|
1606 | my ($self, $max) = @_; |
|
|
1607 | |
|
|
1608 | $self->{max_val} = $max; |
|
|
1609 | } |
|
|
1610 | |
|
|
1611 | sub set_value { |
|
|
1612 | my ($self, $val, $max) = @_; |
|
|
1613 | |
|
|
1614 | $self->set_max ($max) |
|
|
1615 | if defined $max; |
|
|
1616 | |
|
|
1617 | $max = $self->{max_val}; |
|
|
1618 | $self->{val} = $val; |
|
|
1619 | |
|
|
1620 | $self->update; |
|
|
1621 | } |
|
|
1622 | |
|
|
1623 | sub _draw { |
|
|
1624 | my ($self) = @_; |
|
|
1625 | |
|
|
1626 | my $tex = $tex{$self->{type}}; |
|
|
1627 | |
|
|
1628 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1629 | |
|
|
1630 | if ($self->{vertical}) { |
|
|
1631 | glRotate 90, 0, 0, 1; |
|
|
1632 | glTranslate 0, -$self->{w}, 0; |
|
|
1633 | |
|
|
1634 | ($w, $h) = ($h, $w); |
|
|
1635 | } |
|
|
1636 | |
|
|
1637 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1638 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1639 | |
|
|
1640 | my $t1 = $tex->[0]; |
|
|
1641 | my $t2 = $tex->[1]; |
|
|
1642 | |
|
|
1643 | glEnable GL_BLEND; |
|
|
1644 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1645 | glEnable GL_TEXTURE_2D; |
|
|
1646 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1647 | |
1504 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1648 | my $h1 = $self->{h} - $ycut * $self->{h}; |
1505 | my $h2 = $ycut * $self->{h}; |
1649 | my $h2 = $ycut * $self->{h}; |
1506 | |
1650 | |
1507 | my $yp = 0; |
|
|
1508 | |
|
|
1509 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1651 | glBindTexture GL_TEXTURE_2D, $t1->{name}; |
1510 | glBegin GL_QUADS; |
1652 | glBegin GL_QUADS; |
1511 | glTexCoord 0 , 0; glVertex 0 , $yp; |
1653 | glTexCoord 0 , 0; glVertex 0 , 0; |
1512 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $yp + $h1; |
1654 | glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; |
1513 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex 0 + $w, $yp + $h1; |
1655 | glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; |
1514 | glTexCoord $t1->{s}, 0; glVertex 0 + $w, $yp; |
1656 | glTexCoord $t1->{s}, 0; glVertex $w, 0; |
1515 | glEnd; |
1657 | glEnd; |
1516 | |
|
|
1517 | $yp += $h1; |
|
|
1518 | |
1658 | |
1519 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1659 | glBindTexture GL_TEXTURE_2D, $t2->{name}; |
1520 | glBegin GL_QUADS; |
1660 | glBegin GL_QUADS; |
1521 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $yp; |
1661 | glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; |
1522 | glTexCoord 0 , $t2->{t}; glVertex 0 , $yp + $h2; |
1662 | glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; |
1523 | glTexCoord $t2->{s}, $t2->{t}; glVertex 0 + $w, $yp + $h2; |
1663 | glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; |
1524 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex 0 + $w, $yp; |
1664 | glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; |
1525 | glEnd; |
1665 | glEnd; |
1526 | |
1666 | |
1527 | glDisable GL_BLEND; |
1667 | glDisable GL_BLEND; |
1528 | glDisable GL_TEXTURE_2D; |
1668 | glDisable GL_TEXTURE_2D; |
1529 | } |
1669 | } |
1530 | |
1670 | |
1531 | ############################################################################# |
1671 | ############################################################################# |
1532 | |
1672 | |
|
|
1673 | package CFClient::UI::Gauge; |
|
|
1674 | |
|
|
1675 | our @ISA = CFClient::UI::VBox::; |
|
|
1676 | |
|
|
1677 | sub new { |
|
|
1678 | my ($class, %arg) = shift; |
|
|
1679 | |
|
|
1680 | my $self = $class->SUPER::new ( |
|
|
1681 | @_, |
|
|
1682 | ); |
|
|
1683 | |
|
|
1684 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1685 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
|
|
1686 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
|
|
1687 | |
|
|
1688 | $self |
|
|
1689 | } |
|
|
1690 | |
|
|
1691 | sub set_fontsize { |
|
|
1692 | my ($self, $fsize) = @_; |
|
|
1693 | |
|
|
1694 | $self->{value}->set_fontsize ($fsize); |
|
|
1695 | $self->{max} ->set_fontsize ($fsize); |
|
|
1696 | } |
|
|
1697 | |
|
|
1698 | sub set_value { |
|
|
1699 | my ($self, $val, $max) = @_; |
|
|
1700 | |
|
|
1701 | $self->set_max ($max) |
|
|
1702 | if defined $max; |
|
|
1703 | |
|
|
1704 | $self->{gauge}->set_value ($val, $max); |
|
|
1705 | $self->{value}->set_text ($val); |
|
|
1706 | } |
|
|
1707 | |
|
|
1708 | sub set_max { |
|
|
1709 | my ($self, $max) = @_; |
|
|
1710 | |
|
|
1711 | $self->{gauge}->set_max ($max); |
|
|
1712 | $self->{max}->set_text ($max); |
|
|
1713 | } |
|
|
1714 | |
|
|
1715 | ############################################################################# |
|
|
1716 | |
1533 | package CFClient::UI::Slider; |
1717 | package CFClient::UI::Slider; |
1534 | |
1718 | |
1535 | use strict; |
1719 | use strict; |
1536 | |
1720 | |
1537 | use SDL::OpenGL; |
1721 | use CFClient::OpenGL; |
1538 | |
1722 | |
1539 | our @ISA = CFClient::UI::DrawBG::; |
1723 | our @ISA = CFClient::UI::DrawBG::; |
1540 | |
1724 | |
1541 | my @tex = |
1725 | my @tex = |
1542 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
1726 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
… | |
… | |
1667 | |
1851 | |
1668 | package CFClient::UI::TextView; |
1852 | package CFClient::UI::TextView; |
1669 | |
1853 | |
1670 | our @ISA = CFClient::UI::HBox::; |
1854 | our @ISA = CFClient::UI::HBox::; |
1671 | |
1855 | |
1672 | use SDL::OpenGL; |
1856 | use CFClient::OpenGL; |
1673 | |
1857 | |
1674 | sub new { |
1858 | sub new { |
1675 | my $class = shift; |
1859 | my $class = shift; |
1676 | |
1860 | |
1677 | my $self = $class->SUPER::new ( |
1861 | my $self = $class->SUPER::new ( |
… | |
… | |
1823 | |
2007 | |
1824 | ############################################################################# |
2008 | ############################################################################# |
1825 | |
2009 | |
1826 | package CFClient::UI::Animator; |
2010 | package CFClient::UI::Animator; |
1827 | |
2011 | |
1828 | use SDL::OpenGL; |
2012 | use CFClient::OpenGL; |
1829 | |
2013 | |
1830 | our @ISA = CFClient::UI::Bin::; |
2014 | our @ISA = CFClient::UI::Bin::; |
1831 | |
2015 | |
1832 | sub moveto { |
2016 | sub moveto { |
1833 | my ($self, $x, $y) = @_; |
2017 | my ($self, $x, $y) = @_; |
… | |
… | |
1906 | |
2090 | |
1907 | package CFClient::UI::Root; |
2091 | package CFClient::UI::Root; |
1908 | |
2092 | |
1909 | our @ISA = CFClient::UI::Container::; |
2093 | our @ISA = CFClient::UI::Container::; |
1910 | |
2094 | |
1911 | use SDL::OpenGL; |
2095 | use CFClient::OpenGL; |
1912 | |
2096 | |
1913 | sub check_size { |
2097 | sub check_size { |
1914 | my ($self) = @_; |
2098 | my ($self) = @_; |
1915 | |
2099 | |
1916 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2100 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
1917 | } |
2101 | } |
1918 | |
2102 | |
1919 | sub size_request { |
2103 | sub size_request { |
1920 | ($::WIDTH, $::HEIGHT) |
2104 | ($::WIDTH, $::HEIGHT) |
1921 | } |
2105 | } |
… | |
… | |
1923 | sub configure { |
2107 | sub configure { |
1924 | my ($self, $x, $y, $w, $h) = @_; |
2108 | my ($self, $x, $y, $w, $h) = @_; |
1925 | |
2109 | |
1926 | $self->SUPER::configure ($x, $y, $w, $h); |
2110 | $self->SUPER::configure ($x, $y, $w, $h); |
1927 | |
2111 | |
1928 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
1929 | for @{$self->{children}}; |
2112 | for my $child (@{$self->{children}}) { |
|
|
2113 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2114 | |
|
|
2115 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2116 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2117 | $child->configure ($X, $Y, $W,$H); |
|
|
2118 | } |
1930 | } |
2119 | } |
1931 | |
2120 | |
1932 | sub _topleft { |
2121 | sub _topleft { |
1933 | my ($self, $x, $y) = @_; |
2122 | my ($self, $x, $y) = @_; |
1934 | |
2123 | |
… | |
… | |
1942 | ::refresh (); |
2131 | ::refresh (); |
1943 | } |
2132 | } |
1944 | |
2133 | |
1945 | sub add { |
2134 | sub add { |
1946 | my ($self, $child) = @_; |
2135 | my ($self, $child) = @_; |
|
|
2136 | |
|
|
2137 | # integerize window positions |
|
|
2138 | $child->{x} = int $child->{x}; |
|
|
2139 | $child->{y} = int $child->{y}; |
1947 | |
2140 | |
1948 | $self->SUPER::add ($child); |
2141 | $self->SUPER::add ($child); |
1949 | } |
2142 | } |
1950 | |
2143 | |
1951 | sub on_refresh { |
2144 | sub on_refresh { |