… | |
… | |
43 | |
43 | |
44 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
44 | my $widget = $GRAB || $TOPLEVEL->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_down ($ev, $GRAB->translate ($x, $y)) if $GRAB; |
48 | $GRAB->button_up ($ev, $GRAB->translate ($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; |
52 | $grab->update if $grab; |
52 | $grab->update if $grab; |
53 | $GRAB->update if $GRAB; |
53 | $GRAB->update if $GRAB; |
… | |
… | |
79 | use SDL::OpenGL; |
79 | use SDL::OpenGL; |
80 | |
80 | |
81 | sub new { |
81 | sub new { |
82 | my $class = shift; |
82 | my $class = shift; |
83 | |
83 | |
84 | bless { |
84 | my $self = bless { |
85 | x => 0, |
85 | x => 0, |
86 | y => 0, |
86 | y => 0, |
87 | z => 0, |
87 | z => 0, |
88 | w => -1, |
88 | w => -1, |
89 | h => -1, |
89 | h => -1, |
90 | @_ |
90 | @_ |
91 | }, $class |
91 | }, $class; |
|
|
92 | |
|
|
93 | for (keys %$self) { |
|
|
94 | if (/^connect_(.*)$/) { |
|
|
95 | $self->connect ($1 => delete $self->{$_}); |
|
|
96 | } |
|
|
97 | } |
|
|
98 | |
|
|
99 | $self |
92 | } |
100 | } |
93 | |
101 | |
94 | sub move { |
102 | sub move { |
95 | my ($self, $x, $y, $z) = @_; |
103 | my ($self, $x, $y, $z) = @_; |
96 | $self->{x} = $x; |
104 | $self->{x} = $x; |
… | |
… | |
125 | my ($self, $x, $y, $w, $h) = @_; |
133 | my ($self, $x, $y, $w, $h) = @_; |
126 | |
134 | |
127 | $self->_size_allocate ($x, $y, $w, $h); |
135 | $self->_size_allocate ($x, $y, $w, $h); |
128 | } |
136 | } |
129 | |
137 | |
130 | # translate global koordinates to local coordinate system |
138 | # translate global coordinates to local coordinate system |
131 | sub translate { |
139 | sub translate { |
132 | my ($self, $x, $y) = @_; |
140 | my ($self, $x, $y) = @_; |
133 | |
141 | |
134 | $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); |
142 | $self->{parent}->translate ($x - $self->{x}, $y - $self->{y}); |
135 | } |
143 | } |
… | |
… | |
200 | my ($self) = @_; |
208 | my ($self) = @_; |
201 | |
209 | |
202 | warn "no draw defined for $self\n"; |
210 | warn "no draw defined for $self\n"; |
203 | } |
211 | } |
204 | |
212 | |
205 | sub bbox { |
|
|
206 | my ($self) = @_; |
|
|
207 | my ($w, $h) = $self->size_request; |
|
|
208 | ( |
|
|
209 | $self->{x}, |
|
|
210 | $self->{y}, |
|
|
211 | $self->{x} = $w, |
|
|
212 | $self->{y} = $h |
|
|
213 | ) |
|
|
214 | } |
|
|
215 | |
|
|
216 | sub find_widget { |
213 | sub find_widget { |
217 | my ($self, $x, $y) = @_; |
214 | my ($self, $x, $y) = @_; |
218 | |
215 | |
219 | return $self |
216 | return $self |
220 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
217 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
221 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
218 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
222 | |
219 | |
223 | () |
220 | () |
224 | } |
221 | } |
225 | |
222 | |
226 | sub del_parent { $_[0]->{parent} = undef } |
|
|
227 | |
|
|
228 | sub set_parent { |
223 | sub set_parent { |
229 | my ($self, $par) = @_; |
224 | my ($self, $par) = @_; |
230 | |
225 | |
231 | $self->{parent} = $par; |
226 | $self->{parent} = $par; |
232 | Scalar::Util::weaken $self->{parent}; |
227 | Scalar::Util::weaken $self->{parent}; |
… | |
… | |
276 | |
271 | |
277 | # range [value, low, high, page] |
272 | # range [value, low, high, page] |
278 | |
273 | |
279 | $class->SUPER::new ( |
274 | $class->SUPER::new ( |
280 | bg => [0, 0, 0, 0.2], |
275 | bg => [0, 0, 0, 0.2], |
281 | active_bg => [1, 1, 1], |
276 | active_bg => [1, 1, 1, 0.5], |
282 | @_ |
277 | @_ |
283 | ) |
278 | ) |
284 | } |
279 | } |
285 | |
280 | |
286 | sub _draw { |
281 | sub _draw { |
… | |
… | |
330 | |
325 | |
331 | $self |
326 | $self |
332 | } |
327 | } |
333 | |
328 | |
334 | sub add { |
329 | sub add { |
335 | my ($self, $chld, $expand) = @_; |
330 | my ($self, $chld) = @_; |
336 | |
331 | |
337 | $chld->{expand} = $expand; |
|
|
338 | $chld->set_parent ($self); |
332 | $chld->set_parent ($self); |
339 | |
333 | |
340 | $self->{children} = [ |
334 | $self->{children} = [ |
341 | sort { $a->{z} <=> $b->{z} } |
335 | sort { $a->{z} <=> $b->{z} } |
342 | @{$self->{children}}, $chld |
336 | @{$self->{children}}, $chld |
… | |
… | |
538 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
532 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
539 | |
533 | |
540 | sub size_request { |
534 | sub size_request { |
541 | my ($self) = @_; |
535 | my ($self) = @_; |
542 | |
536 | |
|
|
537 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
|
|
538 | |
543 | my ($w, $h) = $self->SUPER::size_request; |
539 | my ($w, $h) = $self->SUPER::size_request; |
544 | |
540 | |
545 | $h += $tex[1]->{h}; |
541 | $h += $tex[1]->{h}; |
546 | $h += $tex[4]->{h}; |
542 | $h += $tex[4]->{h}; |
547 | $w += $tex[2]->{w}; |
543 | $w += $tex[2]->{w}; |
… | |
… | |
553 | sub size_allocate { |
549 | sub size_allocate { |
554 | my ($self, $x, $y, $w, $h) = @_; |
550 | my ($self, $x, $y, $w, $h) = @_; |
555 | |
551 | |
556 | $self->_size_allocate ($x, $y, $w, $h) or return; |
552 | $self->_size_allocate ($x, $y, $w, $h) or return; |
557 | |
553 | |
558 | $h -= $tex[1]->{h}; |
554 | $h -= $tex[1]{h}; |
559 | $h -= $tex[4]->{h}; |
555 | $h -= $tex[4]{h}; |
560 | $w -= $tex[2]->{w}; |
556 | $w -= $tex[2]{w}; |
561 | $w -= $tex[3]->{w}; |
557 | $w -= $tex[3]{w}; |
562 | |
558 | |
563 | $h = $h < 0 ? 0 : $h; |
559 | $h = $h < 0 ? 0 : $h; |
564 | $w = $w < 0 ? 0 : $w; |
560 | $w = $w < 0 ? 0 : $w; |
565 | |
561 | |
566 | my $child = $self->child; |
562 | my $child = $self->child; |
567 | |
563 | |
568 | $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); |
564 | $child->size_allocate ($tex[3]->{w}, $tex[1]->{h}, $w, $h); |
|
|
565 | } |
|
|
566 | |
|
|
567 | sub button_down { |
|
|
568 | my ($self, $ev, $x, $y) = @_; |
|
|
569 | |
|
|
570 | if ($x < $self->{w} && $x >= $self->{w} - $tex[2]{w} |
|
|
571 | && $y < $self->{h} && $y >= $self->{h} - $tex[4]{h}) { |
|
|
572 | |
|
|
573 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
574 | my ($bw, $bh) = ($self->{w}, $self->{h}); |
|
|
575 | |
|
|
576 | $self->{motion} = sub { |
|
|
577 | my ($ev, $x, $y) = @_; |
|
|
578 | |
|
|
579 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
580 | |
|
|
581 | $self->{user_w} = $bw + $x - $ox; |
|
|
582 | $self->{user_h} = $bh + $y - $oy; |
|
|
583 | $self->update; |
|
|
584 | }; |
|
|
585 | |
|
|
586 | } elsif ($x >= 0 && $x < $self->{w} |
|
|
587 | && $y >= 0 && $y < $tex[1]{h}) { |
|
|
588 | |
|
|
589 | my ($ox, $oy) = ($ev->button_x, $ev->button_y); |
|
|
590 | my ($bx, $by) = ($self->{x}, $self->{y}); |
|
|
591 | |
|
|
592 | $self->{motion} = sub { |
|
|
593 | my ($ev, $x, $y) = @_; |
|
|
594 | |
|
|
595 | ($x, $y) = ($ev->motion_x, $ev->motion_y); |
|
|
596 | |
|
|
597 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
|
|
598 | $self->update; |
|
|
599 | }; |
|
|
600 | } |
|
|
601 | } |
|
|
602 | |
|
|
603 | sub button_up { |
|
|
604 | my ($self, $ev, $x, $y) = @_; |
|
|
605 | |
|
|
606 | delete $self->{motion}; |
|
|
607 | } |
|
|
608 | |
|
|
609 | sub mouse_motion { |
|
|
610 | my ($self, $ev, $x, $y) = @_; |
|
|
611 | |
|
|
612 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
569 | } |
613 | } |
570 | |
614 | |
571 | sub _draw { |
615 | sub _draw { |
572 | my ($self) = @_; |
616 | my ($self) = @_; |
573 | |
617 | |
… | |
… | |
593 | |
637 | |
594 | my $bg = $tex[0]; |
638 | my $bg = $tex[0]; |
595 | |
639 | |
596 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
640 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
597 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
641 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
598 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
|
|
599 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
|
|
600 | |
642 | |
601 | my $rep_x = $cw / $bg->{w}; |
643 | my $rep_x = $cw / $bg->{w}; |
602 | my $rep_y = $ch / $bg->{h}; |
644 | my $rep_y = $ch / $bg->{h}; |
603 | |
645 | |
604 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
646 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
… | |
… | |
617 | our @ISA = CFClient::UI::Base::; |
659 | our @ISA = CFClient::UI::Base::; |
618 | |
660 | |
619 | use List::Util qw(max sum); |
661 | use List::Util qw(max sum); |
620 | |
662 | |
621 | use SDL::OpenGL; |
663 | use SDL::OpenGL; |
|
|
664 | |
|
|
665 | sub new { |
|
|
666 | my $class = shift; |
|
|
667 | |
|
|
668 | $class->SUPER::new ( |
|
|
669 | col_expand => [], |
|
|
670 | @_ |
|
|
671 | ) |
|
|
672 | } |
622 | |
673 | |
623 | sub add { |
674 | sub add { |
624 | my ($self, $x, $y, $chld) = @_; |
675 | my ($self, $x, $y, $chld) = @_; |
625 | |
676 | |
626 | $self->{children}[$y][$x] = $chld; |
677 | $self->{children}[$y][$x] = $chld; |
… | |
… | |
656 | my ($self) = @_; |
707 | my ($self) = @_; |
657 | |
708 | |
658 | my ($ws, $hs) = $self->get_wh; |
709 | my ($ws, $hs) = $self->get_wh; |
659 | |
710 | |
660 | ( |
711 | ( |
661 | (List::Util::sum @$ws), |
712 | (sum @$ws), |
662 | (List::Util::sum @$hs), |
713 | (sum @$hs), |
663 | ) |
714 | ) |
664 | } |
715 | } |
665 | |
716 | |
666 | sub size_allocate { |
717 | sub size_allocate { |
667 | my ($self, $x, $y, $w, $h) = @_; |
718 | my ($self, $x, $y, $w, $h) = @_; |
668 | |
719 | |
669 | $self->_size_allocate ($x, $y, $w, $h) or return; |
720 | $self->_size_allocate ($x, $y, $w, $h) or return; |
670 | |
721 | |
671 | my ($ws, $hs) = $self->get_wh; |
722 | my ($ws, $hs) = $self->get_wh; |
672 | |
723 | |
673 | my $req_w = List::Util::sum @$ws; |
724 | my $req_w = sum @$ws; |
674 | my $req_h = List::Util::sum @$hs; |
725 | my $req_h = sum @$hs; |
|
|
726 | |
|
|
727 | # TODO: nicer code && do row_expand |
|
|
728 | my @col_expand = @{$self->{col_expand}}; |
|
|
729 | @col_expand = (1) x @$ws unless @col_expand; |
|
|
730 | my $col_expand = (sum @col_expand) || 1; |
675 | |
731 | |
676 | # linearly scale sizes |
732 | # linearly scale sizes |
677 | $_ *= $req_w / $w for @$ws; |
733 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
678 | $_ *= $req_h / $h for @$hs; |
734 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
679 | |
735 | |
680 | my $y; |
736 | my $y; |
681 | |
737 | |
682 | for my $r (0 .. $#{$self->{children}}) { |
738 | for my $r (0 .. $#{$self->{children}}) { |
683 | my $row = $self->{children}[$r] |
739 | my $row = $self->{children}[$r] |
… | |
… | |
685 | |
741 | |
686 | my $x = 0; |
742 | my $x = 0; |
687 | my $row_h = $hs->[$r]; |
743 | my $row_h = $hs->[$r]; |
688 | |
744 | |
689 | for my $c (0 .. $#$row) { |
745 | for my $c (0 .. $#$row) { |
690 | my $widget = $row->[$c] |
|
|
691 | or next; |
|
|
692 | |
|
|
693 | my $col_w = $ws->[$c]; |
746 | my $col_w = $ws->[$c]; |
694 | |
747 | |
|
|
748 | if (my $widget = $row->[$c]) { |
695 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
749 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
|
|
750 | } |
696 | |
751 | |
697 | $x += $col_w; |
752 | $x += $col_w; |
698 | } |
753 | } |
699 | |
754 | |
700 | $y += $row_h; |
755 | $y += $row_h; |
… | |
… | |
746 | } |
801 | } |
747 | |
802 | |
748 | sub size_allocate { |
803 | sub size_allocate { |
749 | my ($self, $x, $y, $w, $h) = @_; |
804 | my ($self, $x, $y, $w, $h) = @_; |
750 | |
805 | |
751 | $self->_size_allocate ($x, $y, $w, $h) or return; |
806 | $self->_size_allocate ($x, $y, $w, $h); |
752 | |
|
|
753 | return unless $self->{w}; |
|
|
754 | |
807 | |
755 | ($h, $w) = ($w, $h); |
808 | ($h, $w) = ($w, $h); |
756 | |
809 | |
757 | my $children = $self->{children}; |
810 | my $children = $self->{children}; |
758 | |
811 | |
… | |
… | |
760 | |
813 | |
761 | my $req_h = List::Util::sum @h; |
814 | my $req_h = List::Util::sum @h; |
762 | |
815 | |
763 | if ($req_h > $h) { |
816 | if ($req_h > $h) { |
764 | # ah well, not enough space |
817 | # ah well, not enough space |
765 | $_ = $h[$_] * $h / $req_h for @h; |
818 | $_ *= $h / $req_h for @h; |
766 | } else { |
819 | } else { |
767 | my @exp = grep $_->{expand}, @$children; |
820 | my $exp = List::Util::sum map $_->{expand}, @$children; |
768 | @exp = @$children unless @exp; |
821 | $exp ||= 1; |
769 | |
822 | |
770 | my %exp = map +($_ => 1), @exp; |
|
|
771 | |
|
|
772 | for (0 .. $#$children) { |
823 | for (0 .. $#$children) { |
773 | my $child = $children->[$_]; |
824 | my $child = $children->[$_]; |
774 | |
825 | |
775 | my $alloc_h = $h[$_]; |
826 | my $alloc_h = $h[$_]; |
776 | $alloc_h += ($h - $req_h) / @exp if $exp{$child}; |
827 | $alloc_h += ($h - $req_h) * $child->{expand} / $exp; |
777 | $h[$_] = $alloc_h; |
828 | $h[$_] = $alloc_h; |
778 | } |
829 | } |
779 | } |
830 | } |
780 | |
831 | |
781 | my $y = 0; |
832 | my $y = 0; |
… | |
… | |
808 | } |
859 | } |
809 | |
860 | |
810 | sub size_allocate { |
861 | sub size_allocate { |
811 | my ($self, $x, $y, $w, $h) = @_; |
862 | my ($self, $x, $y, $w, $h) = @_; |
812 | |
863 | |
813 | $self->_size_allocate ($x, $y, $w, $h) or return; |
864 | $self->_size_allocate ($x, $y, $w, $h); |
814 | |
|
|
815 | return unless $self->{h}; |
|
|
816 | |
865 | |
817 | my $children = $self->{children}; |
866 | my $children = $self->{children}; |
818 | |
867 | |
819 | my @h = map +($_->size_request)[1], @$children; |
868 | my @h = map +($_->size_request)[1], @$children; |
820 | |
869 | |
821 | my $req_h = List::Util::sum @h; |
870 | my $req_h = List::Util::sum @h; |
822 | |
871 | |
823 | if ($req_h > $h) { |
872 | if ($req_h > $h) { |
824 | # ah well, not enough space |
873 | # ah well, not enough space |
825 | $_ = $h[$_] * $h / $req_h for @h; |
874 | $_ *= $h / $req_h for @h; |
826 | } else { |
875 | } else { |
827 | my @exp = grep $_->{expand}, @$children; |
876 | my $exp = List::Util::sum map $_->{expand}, @$children; |
828 | @exp = @$children unless @exp; |
877 | $exp ||= 1; |
829 | |
878 | |
830 | my %exp = map +($_ => 1), @exp; |
|
|
831 | |
|
|
832 | for (0 .. $#$children) { |
879 | for (0 .. $#$children) { |
833 | my $child = $children->[$_]; |
880 | my $child = $children->[$_]; |
834 | |
881 | |
835 | my $alloc_h = $h[$_]; |
882 | $h[$_] += ($h - $req_h) * $child->{expand} / $exp; |
836 | $alloc_h += ($h - $req_h) / @exp if $exp{$child}; |
|
|
837 | $h[$_] = $alloc_h; |
|
|
838 | } |
883 | } |
839 | } |
884 | } |
840 | |
885 | |
841 | my $y = 0; |
886 | my $y = 0; |
842 | for (0 .. $#$children) { |
887 | for (0 .. $#$children) { |
… | |
… | |
889 | |
934 | |
890 | $self->{text} = $text; |
935 | $self->{text} = $text; |
891 | $self->{layout}->set_markup ($text); |
936 | $self->{layout}->set_markup ($text); |
892 | |
937 | |
893 | delete $self->{texture}; |
938 | delete $self->{texture}; |
|
|
939 | # $self->{w} = $self->{h} = -1; |
894 | $self->update; |
940 | $self->update; |
895 | } |
941 | } |
896 | |
942 | |
897 | sub get_text { |
943 | sub get_text { |
898 | my ($self, $text) = @_; |
944 | my ($self, $text) = @_; |
… | |
… | |
931 | sub _draw { |
977 | sub _draw { |
932 | my ($self) = @_; |
978 | my ($self) = @_; |
933 | |
979 | |
934 | my $tex = $self->{texture} ||= do { |
980 | my $tex = $self->{texture} ||= do { |
935 | $self->{layout}->set_width ($self->{w}); |
981 | $self->{layout}->set_width ($self->{w}); |
|
|
982 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
936 | new_from_layout CFClient::Texture $self->{layout} |
983 | new_from_layout CFClient::Texture $self->{layout} |
937 | }; |
984 | }; |
938 | |
985 | |
939 | glEnable GL_BLEND; |
986 | glEnable GL_BLEND; |
940 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
987 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
946 | my $x = |
993 | my $x = |
947 | $self->{align} < 0 ? $self->{padding} |
994 | $self->{align} < 0 ? $self->{padding} |
948 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
995 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
949 | : ($self->{w} - $tex->{w}) * 0.5; |
996 | : ($self->{w} - $tex->{w}) * 0.5; |
950 | |
997 | |
|
|
998 | glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0; |
951 | $tex->draw_quad ($x, 0); |
999 | $tex->draw_quad (0, 0); |
952 | |
1000 | |
953 | glDisable GL_TEXTURE_2D; |
1001 | glDisable GL_TEXTURE_2D; |
954 | glDisable GL_BLEND; |
1002 | glDisable GL_BLEND; |
955 | } |
1003 | } |
956 | |
1004 | |
… | |
… | |
967 | my $class = shift; |
1015 | my $class = shift; |
968 | |
1016 | |
969 | $class->SUPER::new ( |
1017 | $class->SUPER::new ( |
970 | fg => [1, 1, 1], |
1018 | fg => [1, 1, 1], |
971 | bg => [0, 0, 0, 0.2], |
1019 | bg => [0, 0, 0, 0.2], |
972 | active_bg => [1, 1, 1], |
1020 | active_bg => [1, 1, 1, 0.5], |
973 | active_fg => [0, 0, 0], |
1021 | active_fg => [0, 0, 0], |
974 | @_ |
1022 | @_ |
975 | ) |
1023 | ) |
976 | } |
1024 | } |
977 | |
1025 | |
… | |
… | |
980 | |
1028 | |
981 | $self->{last_activity} = $::NOW; |
1029 | $self->{last_activity} = $::NOW; |
982 | |
1030 | |
983 | $self->{text} = $text; |
1031 | $self->{text} = $text; |
984 | $self->{layout}->set_width ($self->{w}); |
1032 | $self->{layout}->set_width ($self->{w}); |
|
|
1033 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
985 | |
1034 | |
986 | $text =~ s/./*/g if $self->{hidden}; |
1035 | $text =~ s/./*/g if $self->{hidden}; |
987 | |
1036 | |
988 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1037 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
989 | |
1038 | |
… | |
… | |
1110 | } |
1159 | } |
1111 | } |
1160 | } |
1112 | |
1161 | |
1113 | ############################################################################# |
1162 | ############################################################################# |
1114 | |
1163 | |
|
|
1164 | package CFClient::UI::Button; |
|
|
1165 | |
|
|
1166 | our @ISA = CFClient::UI::Label::; |
|
|
1167 | |
|
|
1168 | use SDL; |
|
|
1169 | use SDL::OpenGL; |
|
|
1170 | |
|
|
1171 | my @tex = |
|
|
1172 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1173 | qw(b1_button_active.png); |
|
|
1174 | |
|
|
1175 | sub new { |
|
|
1176 | my $class = shift; |
|
|
1177 | |
|
|
1178 | $class->SUPER::new ( |
|
|
1179 | padding => 4, |
|
|
1180 | fg => [1, 1, 1], |
|
|
1181 | bg => [1, 1, 1, 0.2], |
|
|
1182 | active_fg => [1, 1, 0], |
|
|
1183 | # active_bg => [0, 0, 0, 0.5], |
|
|
1184 | # border_fg => [1, 1, 0], |
|
|
1185 | @_ |
|
|
1186 | ) |
|
|
1187 | } |
|
|
1188 | |
|
|
1189 | sub button_up { |
|
|
1190 | my ($self, $ev, $x, $y) = @_; |
|
|
1191 | |
|
|
1192 | if ($x >= 0 && $x < $self->{w} |
|
|
1193 | && $y >= 0 && $y < $self->{h}) { |
|
|
1194 | $self->emit ("activate"); |
|
|
1195 | } |
|
|
1196 | } |
|
|
1197 | |
|
|
1198 | sub _draw { |
|
|
1199 | my ($self) = @_; |
|
|
1200 | |
|
|
1201 | local $self->{fg} = $self->{fg}; |
|
|
1202 | my $tex = $tex[0]; |
|
|
1203 | |
|
|
1204 | glEnable GL_BLEND; |
|
|
1205 | glEnable GL_TEXTURE_2D; |
|
|
1206 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1207 | |
|
|
1208 | if ($GRAB == $self) { |
|
|
1209 | $self->{fg} = $self->{active_fg}; |
|
|
1210 | } |
|
|
1211 | |
|
|
1212 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
1213 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1214 | |
|
|
1215 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
|
|
1216 | |
|
|
1217 | glDisable GL_TEXTURE_2D; |
|
|
1218 | glDisable GL_BLEND; |
|
|
1219 | |
|
|
1220 | $self->SUPER::_draw; |
|
|
1221 | } |
|
|
1222 | |
|
|
1223 | ############################################################################# |
|
|
1224 | |
|
|
1225 | package CFClient::UI::CheckBox; |
|
|
1226 | |
|
|
1227 | our @ISA = CFClient::UI::DrawBG::; |
|
|
1228 | |
|
|
1229 | use SDL; |
|
|
1230 | use SDL::OpenGL; |
|
|
1231 | |
|
|
1232 | sub new { |
|
|
1233 | my $class = shift; |
|
|
1234 | |
|
|
1235 | $class->SUPER::new ( |
|
|
1236 | padding => 2, |
|
|
1237 | fg => [1, 1, 1], |
|
|
1238 | active_fg => [1, 1, 0], |
|
|
1239 | state => 0, |
|
|
1240 | @_ |
|
|
1241 | ) |
|
|
1242 | } |
|
|
1243 | |
|
|
1244 | sub size_request { |
|
|
1245 | my ($self) = @_; |
|
|
1246 | |
|
|
1247 | ($self->{padding} * 2 + 6) x 2 |
|
|
1248 | } |
|
|
1249 | |
|
|
1250 | sub size_allocate { |
|
|
1251 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1252 | |
|
|
1253 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
1254 | } |
|
|
1255 | |
|
|
1256 | sub button_down { |
|
|
1257 | my ($self, $ev, $x, $y) = @_; |
|
|
1258 | |
|
|
1259 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
|
|
1260 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
|
|
1261 | $self->{state} = !$self->{state}; |
|
|
1262 | $self->emit (changed => $self->{state}); |
|
|
1263 | } |
|
|
1264 | } |
|
|
1265 | |
|
|
1266 | sub _draw { |
|
|
1267 | my ($self) = @_; |
|
|
1268 | |
|
|
1269 | $self->SUPER::_draw; |
|
|
1270 | |
|
|
1271 | glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; |
|
|
1272 | |
|
|
1273 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
|
|
1274 | |
|
|
1275 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
|
|
1276 | |
|
|
1277 | glBegin GL_LINE_LOOP; |
|
|
1278 | glVertex 0 , 0; |
|
|
1279 | glVertex 0 , $s; |
|
|
1280 | glVertex $s, $s; |
|
|
1281 | glVertex $s, 0; |
|
|
1282 | glEnd; |
|
|
1283 | |
|
|
1284 | if ($self->{state}) { |
|
|
1285 | glBegin GL_LINES; |
|
|
1286 | glVertex 0 , 0; |
|
|
1287 | glVertex $s, $s; |
|
|
1288 | glVertex $s, 0; |
|
|
1289 | glVertex 0 , $s; |
|
|
1290 | glEnd; |
|
|
1291 | } |
|
|
1292 | } |
|
|
1293 | |
|
|
1294 | ############################################################################# |
|
|
1295 | |
1115 | package CFClient::UI::Slider; |
1296 | package CFClient::UI::Slider; |
1116 | |
1297 | |
1117 | use strict; |
1298 | use strict; |
1118 | |
1299 | |
1119 | use SDL::OpenGL; |
1300 | use SDL::OpenGL; |
… | |
… | |
1197 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1378 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1198 | |
1379 | |
1199 | $w -= $page; |
1380 | $w -= $page; |
1200 | $page &= ~1; |
1381 | $page &= ~1; |
1201 | glTranslate $page * 0.5, 0, 0; |
1382 | glTranslate $page * 0.5, 0, 0; |
|
|
1383 | $page ||= 2; |
1202 | |
1384 | |
1203 | glColor @$fg; |
1385 | glColor @$fg; |
1204 | glBegin GL_LINES; |
1386 | glBegin GL_LINES; |
1205 | glVertex 0, 0; glVertex 0, $h; |
1387 | glVertex 0, 0; glVertex 0, $h; |
1206 | glVertex $w - 1, 0; glVertex $w - 1, $h; |
1388 | glVertex $w - 1, 0; glVertex $w - 1, $h; |
… | |
… | |
1257 | sub key_up { |
1439 | sub key_up { |
1258 | } |
1440 | } |
1259 | |
1441 | |
1260 | sub size_request { |
1442 | sub size_request { |
1261 | ( |
1443 | ( |
1262 | 1 + int $::WIDTH / 32, |
1444 | 1 + 32 * int $::WIDTH / 32, |
1263 | 1 + int $::HEIGHT / 32, |
1445 | 1 + 32 * int $::HEIGHT / 32, |
1264 | ) |
1446 | ) |
1265 | } |
1447 | } |
1266 | |
1448 | |
1267 | sub update { |
1449 | sub update { |
1268 | my ($self) = @_; |
1450 | my ($self) = @_; |
1269 | |
1451 | |
1270 | $self->{need_update} = 1; |
1452 | $self->{need_update} = 1; |
1271 | $self->SUPER::update; |
1453 | $self->SUPER::update; |
1272 | } |
1454 | } |
1273 | |
1455 | |
1274 | sub _draw { |
1456 | sub draw { |
1275 | my ($self) = @_; |
1457 | my ($self) = @_; |
1276 | |
1458 | |
1277 | if (delete $self->{need_update}) { |
1459 | if (delete $self->{need_update}) { |
1278 | glNewList $self->{list}, GL_COMPILE; |
1460 | glNewList $self->{list}, GL_COMPILE; |
1279 | |
1461 | |
… | |
… | |
1301 | |
1483 | |
1302 | glEnable GL_TEXTURE_2D; |
1484 | glEnable GL_TEXTURE_2D; |
1303 | glEnable GL_BLEND; |
1485 | glEnable GL_BLEND; |
1304 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1486 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1305 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1487 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1488 | glColor 1, 1, 1, 1; |
1306 | |
1489 | |
1307 | my $sw4 = ($sw + 3) & ~3; |
1490 | my $sw4 = ($sw + 3) & ~3; |
1308 | my $darkness = "\x00" x ($sw4 * $sh); |
1491 | my $darkness = "\x00" x ($sw4 * $sh); |
1309 | |
1492 | |
1310 | for my $x (0 .. $sw - 1) { |
1493 | for my $x (0 .. $sw - 1) { |
… | |
… | |
1341 | # $lighting =~ s/(.)../$1/gs; |
1524 | # $lighting =~ s/(.)../$1/gs; |
1342 | # } |
1525 | # } |
1343 | |
1526 | |
1344 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1527 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1345 | |
1528 | |
|
|
1529 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1530 | my @conv = ( |
|
|
1531 | 0.1, 0.1, 0.1, |
|
|
1532 | 0.1, 0.2, 0.1, |
|
|
1533 | 0.1, 0.1, 0.1, |
|
|
1534 | ); |
|
|
1535 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1536 | glConvolutionFilter2D GL_CONVOLUTION_2D, |
|
|
1537 | GL_ALPHA, 3, 3, GL_ALPHA, GL_FLOAT, |
|
|
1538 | pack "f*", @conv; |
|
|
1539 | glEnable GL_CONVOLUTION_2D; |
|
|
1540 | } |
|
|
1541 | |
1346 | $darkness = new CFClient::Texture |
1542 | $darkness = new CFClient::Texture |
1347 | w => $sw4, |
1543 | w => $sw4, |
1348 | h => $sh, |
1544 | h => $sh, |
1349 | data => $darkness, |
1545 | data => $darkness, |
1350 | internalformat => GL_ALPHA, |
1546 | internalformat => GL_ALPHA, |
1351 | format => GL_ALPHA; |
1547 | format => GL_ALPHA; |
1352 | |
1548 | |
1353 | glColor 0.45, 0.45, 0.45, 1; |
1549 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1354 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
1550 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
|
|
1551 | |
|
|
1552 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1355 | |
1553 | |
1356 | glDisable GL_TEXTURE_2D; |
1554 | glDisable GL_TEXTURE_2D; |
1357 | glDisable GL_BLEND; |
1555 | glDisable GL_BLEND; |
1358 | |
1556 | |
1359 | glEndList; |
1557 | glEndList; |
1360 | } |
1558 | } |
1361 | |
1559 | |
1362 | glCallList $self->{list}; |
1560 | glCallList $self->{list}; |
|
|
1561 | |
|
|
1562 | if ($FOCUS != $self) { |
|
|
1563 | glEnable GL_BLEND; |
|
|
1564 | glColor 0, 0, 1, 0.4; |
|
|
1565 | glBegin GL_QUADS; |
|
|
1566 | glVertex 0, 0; |
|
|
1567 | glVertex 0, $::HEIGHT; |
|
|
1568 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1569 | glVertex $::WIDTH, 0; |
|
|
1570 | glEnd; |
|
|
1571 | glDisable GL_BLEND; |
|
|
1572 | } |
1363 | } |
1573 | } |
1364 | |
1574 | |
1365 | my %DIR = ( |
1575 | my %DIR = ( |
1366 | SDLK_KP8, [1, "north"], |
1576 | SDLK_KP8, [1, "north"], |
1367 | SDLK_KP9, [2, "northeast"], |
1577 | SDLK_KP9, [2, "northeast"], |
… | |
… | |
1383 | |
1593 | |
1384 | my $mod = $ev->key_mod; |
1594 | my $mod = $ev->key_mod; |
1385 | my $sym = $ev->key_sym; |
1595 | my $sym = $ev->key_sym; |
1386 | |
1596 | |
1387 | if ($sym == SDLK_KP5) { |
1597 | if ($sym == SDLK_KP5) { |
1388 | $::CONN->send ("command stay fire"); |
1598 | $::CONN->user_send ("command stay fire"); |
|
|
1599 | } elsif ($sym == SDLK_a) { |
|
|
1600 | $::CONN->user_send ("command apply"); |
1389 | } elsif (exists $DIR{$sym}) { |
1601 | } elsif (exists $DIR{$sym}) { |
1390 | if ($mod & KMOD_SHIFT) { |
1602 | if ($mod & KMOD_SHIFT) { |
1391 | $self->{shft}++; |
1603 | $self->{shft}++; |
1392 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1604 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1393 | } elsif ($mod & KMOD_CTRL) { |
1605 | } elsif ($mod & KMOD_CTRL) { |
1394 | $self->{ctrl}++; |
1606 | $self->{ctrl}++; |
1395 | $::CONN->send ("command run $DIR{$sym}[0]"); |
1607 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
1396 | } else { |
1608 | } else { |
1397 | $::CONN->send ("command $DIR{$sym}[1]"); |
1609 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
1398 | } |
1610 | } |
1399 | } |
1611 | } |
1400 | } |
1612 | } |
1401 | |
1613 | |
1402 | sub key_up { |
1614 | sub key_up { |
… | |
… | |
1404 | |
1616 | |
1405 | my $mod = $ev->key_mod; |
1617 | my $mod = $ev->key_mod; |
1406 | my $sym = $ev->key_sym; |
1618 | my $sym = $ev->key_sym; |
1407 | |
1619 | |
1408 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1620 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1409 | $::CONN->send ("command fire_stop"); |
1621 | $::CONN->user_send ("command fire_stop"); |
1410 | } |
1622 | } |
1411 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1623 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1412 | $::CONN->send ("command run_stop"); |
1624 | $::CONN->user_send ("command run_stop"); |
1413 | } |
1625 | } |
1414 | } |
1626 | } |
1415 | |
1627 | |
1416 | ############################################################################# |
1628 | ############################################################################# |
1417 | |
1629 | |