… | |
… | |
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 { |
… | |
… | |
537 | 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); |
538 | |
533 | |
539 | sub size_request { |
534 | sub size_request { |
540 | my ($self) = @_; |
535 | my ($self) = @_; |
541 | |
536 | |
542 | my ($w, $h) = |
537 | return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h}; |
543 | $self->{user_w} && $self->{user_h} |
538 | |
544 | ? ($self->{user_w}, $self->{user_h}) |
|
|
545 | : ($self->SUPER::size_request); |
539 | my ($w, $h) = $self->SUPER::size_request; |
546 | |
540 | |
547 | $h += $tex[1]->{h}; |
541 | $h += $tex[1]->{h}; |
548 | $h += $tex[4]->{h}; |
542 | $h += $tex[4]->{h}; |
549 | $w += $tex[2]->{w}; |
543 | $w += $tex[2]->{w}; |
550 | $w += $tex[3]->{w}; |
544 | $w += $tex[3]->{w}; |
… | |
… | |
643 | |
637 | |
644 | my $bg = $tex[0]; |
638 | my $bg = $tex[0]; |
645 | |
639 | |
646 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
640 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
647 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
641 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
648 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
|
|
649 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
|
|
650 | |
642 | |
651 | my $rep_x = $cw / $bg->{w}; |
643 | my $rep_x = $cw / $bg->{w}; |
652 | my $rep_y = $ch / $bg->{h}; |
644 | my $rep_y = $ch / $bg->{h}; |
653 | |
645 | |
654 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
646 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
… | |
… | |
667 | our @ISA = CFClient::UI::Base::; |
659 | our @ISA = CFClient::UI::Base::; |
668 | |
660 | |
669 | use List::Util qw(max sum); |
661 | use List::Util qw(max sum); |
670 | |
662 | |
671 | 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 | } |
672 | |
673 | |
673 | sub add { |
674 | sub add { |
674 | my ($self, $x, $y, $chld) = @_; |
675 | my ($self, $x, $y, $chld) = @_; |
675 | |
676 | |
676 | $self->{children}[$y][$x] = $chld; |
677 | $self->{children}[$y][$x] = $chld; |
… | |
… | |
706 | my ($self) = @_; |
707 | my ($self) = @_; |
707 | |
708 | |
708 | my ($ws, $hs) = $self->get_wh; |
709 | my ($ws, $hs) = $self->get_wh; |
709 | |
710 | |
710 | ( |
711 | ( |
711 | (List::Util::sum @$ws), |
712 | (sum @$ws), |
712 | (List::Util::sum @$hs), |
713 | (sum @$hs), |
713 | ) |
714 | ) |
714 | } |
715 | } |
715 | |
716 | |
716 | sub size_allocate { |
717 | sub size_allocate { |
717 | my ($self, $x, $y, $w, $h) = @_; |
718 | my ($self, $x, $y, $w, $h) = @_; |
718 | |
719 | |
719 | $self->_size_allocate ($x, $y, $w, $h) or return; |
720 | $self->_size_allocate ($x, $y, $w, $h) or return; |
720 | |
721 | |
721 | my ($ws, $hs) = $self->get_wh; |
722 | my ($ws, $hs) = $self->get_wh; |
722 | |
723 | |
723 | my $req_w = List::Util::sum @$ws; |
724 | my $req_w = sum @$ws; |
724 | 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; |
725 | |
731 | |
726 | # linearly scale sizes |
732 | # linearly scale sizes |
727 | $_ *= $w / $req_w for @$ws; |
733 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
728 | $_ *= $h / $req_h for @$hs; |
734 | $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; |
729 | |
735 | |
730 | my $y; |
736 | my $y; |
731 | |
737 | |
732 | for my $r (0 .. $#{$self->{children}}) { |
738 | for my $r (0 .. $#{$self->{children}}) { |
733 | my $row = $self->{children}[$r] |
739 | my $row = $self->{children}[$r] |
… | |
… | |
735 | |
741 | |
736 | my $x = 0; |
742 | my $x = 0; |
737 | my $row_h = $hs->[$r]; |
743 | my $row_h = $hs->[$r]; |
738 | |
744 | |
739 | for my $c (0 .. $#$row) { |
745 | for my $c (0 .. $#$row) { |
740 | my $widget = $row->[$c] |
|
|
741 | or next; |
|
|
742 | |
|
|
743 | my $col_w = $ws->[$c]; |
746 | my $col_w = $ws->[$c]; |
744 | |
747 | |
|
|
748 | if (my $widget = $row->[$c]) { |
745 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
749 | $widget->size_allocate ($x, $y, $col_w, $row_h); |
|
|
750 | } |
746 | |
751 | |
747 | $x += $col_w; |
752 | $x += $col_w; |
748 | } |
753 | } |
749 | |
754 | |
750 | $y += $row_h; |
755 | $y += $row_h; |
… | |
… | |
796 | } |
801 | } |
797 | |
802 | |
798 | sub size_allocate { |
803 | sub size_allocate { |
799 | my ($self, $x, $y, $w, $h) = @_; |
804 | my ($self, $x, $y, $w, $h) = @_; |
800 | |
805 | |
801 | $self->_size_allocate ($x, $y, $w, $h) or return; |
806 | $self->_size_allocate ($x, $y, $w, $h); |
802 | |
|
|
803 | return unless $self->{w}; |
|
|
804 | |
807 | |
805 | ($h, $w) = ($w, $h); |
808 | ($h, $w) = ($w, $h); |
806 | |
809 | |
807 | my $children = $self->{children}; |
810 | my $children = $self->{children}; |
808 | |
811 | |
… | |
… | |
810 | |
813 | |
811 | my $req_h = List::Util::sum @h; |
814 | my $req_h = List::Util::sum @h; |
812 | |
815 | |
813 | if ($req_h > $h) { |
816 | if ($req_h > $h) { |
814 | # ah well, not enough space |
817 | # ah well, not enough space |
815 | $_ = $h[$_] * $h / $req_h for @h; |
818 | $_ *= $h / $req_h for @h; |
816 | } else { |
819 | } else { |
817 | my $exp = List::Util::sum map $_->{expand}, @$children; |
820 | my $exp = List::Util::sum map $_->{expand}, @$children; |
818 | $exp ||= 1; |
821 | $exp ||= 1; |
819 | |
822 | |
820 | for (0 .. $#$children) { |
823 | for (0 .. $#$children) { |
… | |
… | |
856 | } |
859 | } |
857 | |
860 | |
858 | sub size_allocate { |
861 | sub size_allocate { |
859 | my ($self, $x, $y, $w, $h) = @_; |
862 | my ($self, $x, $y, $w, $h) = @_; |
860 | |
863 | |
861 | $self->_size_allocate ($x, $y, $w, $h) or return; |
864 | $self->_size_allocate ($x, $y, $w, $h); |
862 | |
|
|
863 | return unless $self->{h}; |
|
|
864 | |
865 | |
865 | my $children = $self->{children}; |
866 | my $children = $self->{children}; |
866 | |
867 | |
867 | my @h = map +($_->size_request)[1], @$children; |
868 | my @h = map +($_->size_request)[1], @$children; |
868 | |
869 | |
869 | my $req_h = List::Util::sum @h; |
870 | my $req_h = List::Util::sum @h; |
870 | |
871 | |
871 | if ($req_h > $h) { |
872 | if ($req_h > $h) { |
872 | # ah well, not enough space |
873 | # ah well, not enough space |
873 | $_ = $h[$_] * $h / $req_h for @h; |
874 | $_ *= $h / $req_h for @h; |
874 | } else { |
875 | } else { |
875 | my $exp = List::Util::sum map $_->{expand}, @$children; |
876 | my $exp = List::Util::sum map $_->{expand}, @$children; |
876 | $exp ||= 1; |
877 | $exp ||= 1; |
877 | |
878 | |
878 | for (0 .. $#$children) { |
879 | for (0 .. $#$children) { |
… | |
… | |
933 | |
934 | |
934 | $self->{text} = $text; |
935 | $self->{text} = $text; |
935 | $self->{layout}->set_markup ($text); |
936 | $self->{layout}->set_markup ($text); |
936 | |
937 | |
937 | delete $self->{texture}; |
938 | delete $self->{texture}; |
|
|
939 | # $self->{w} = $self->{h} = -1; |
938 | $self->update; |
940 | $self->update; |
939 | } |
941 | } |
940 | |
942 | |
941 | sub get_text { |
943 | sub get_text { |
942 | my ($self, $text) = @_; |
944 | my ($self, $text) = @_; |
… | |
… | |
975 | sub _draw { |
977 | sub _draw { |
976 | my ($self) = @_; |
978 | my ($self) = @_; |
977 | |
979 | |
978 | my $tex = $self->{texture} ||= do { |
980 | my $tex = $self->{texture} ||= do { |
979 | $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}); |
980 | new_from_layout CFClient::Texture $self->{layout} |
983 | new_from_layout CFClient::Texture $self->{layout} |
981 | }; |
984 | }; |
982 | |
985 | |
983 | glEnable GL_BLEND; |
986 | glEnable GL_BLEND; |
984 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
987 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
990 | my $x = |
993 | my $x = |
991 | $self->{align} < 0 ? $self->{padding} |
994 | $self->{align} < 0 ? $self->{padding} |
992 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
995 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
993 | : ($self->{w} - $tex->{w}) * 0.5; |
996 | : ($self->{w} - $tex->{w}) * 0.5; |
994 | |
997 | |
995 | $tex->draw_quad ($x, $self->{padding}); |
998 | glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0; |
|
|
999 | $tex->draw_quad (0, 0); |
996 | |
1000 | |
997 | glDisable GL_TEXTURE_2D; |
1001 | glDisable GL_TEXTURE_2D; |
998 | glDisable GL_BLEND; |
1002 | glDisable GL_BLEND; |
999 | } |
1003 | } |
1000 | |
1004 | |
… | |
… | |
1011 | my $class = shift; |
1015 | my $class = shift; |
1012 | |
1016 | |
1013 | $class->SUPER::new ( |
1017 | $class->SUPER::new ( |
1014 | fg => [1, 1, 1], |
1018 | fg => [1, 1, 1], |
1015 | bg => [0, 0, 0, 0.2], |
1019 | bg => [0, 0, 0, 0.2], |
1016 | active_bg => [1, 1, 1], |
1020 | active_bg => [1, 1, 1, 0.5], |
1017 | active_fg => [0, 0, 0], |
1021 | active_fg => [0, 0, 0], |
1018 | @_ |
1022 | @_ |
1019 | ) |
1023 | ) |
1020 | } |
1024 | } |
1021 | |
1025 | |
… | |
… | |
1024 | |
1028 | |
1025 | $self->{last_activity} = $::NOW; |
1029 | $self->{last_activity} = $::NOW; |
1026 | |
1030 | |
1027 | $self->{text} = $text; |
1031 | $self->{text} = $text; |
1028 | $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}); |
1029 | |
1034 | |
1030 | $text =~ s/./*/g if $self->{hidden}; |
1035 | $text =~ s/./*/g if $self->{hidden}; |
1031 | |
1036 | |
1032 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1037 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1033 | |
1038 | |
… | |
… | |
1154 | } |
1159 | } |
1155 | } |
1160 | } |
1156 | |
1161 | |
1157 | ############################################################################# |
1162 | ############################################################################# |
1158 | |
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 | |
1159 | package CFClient::UI::Slider; |
1296 | package CFClient::UI::Slider; |
1160 | |
1297 | |
1161 | use strict; |
1298 | use strict; |
1162 | |
1299 | |
1163 | use SDL::OpenGL; |
1300 | use SDL::OpenGL; |
… | |
… | |
1241 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1378 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1242 | |
1379 | |
1243 | $w -= $page; |
1380 | $w -= $page; |
1244 | $page &= ~1; |
1381 | $page &= ~1; |
1245 | glTranslate $page * 0.5, 0, 0; |
1382 | glTranslate $page * 0.5, 0, 0; |
|
|
1383 | $page ||= 2; |
1246 | |
1384 | |
1247 | glColor @$fg; |
1385 | glColor @$fg; |
1248 | glBegin GL_LINES; |
1386 | glBegin GL_LINES; |
1249 | glVertex 0, 0; glVertex 0, $h; |
1387 | glVertex 0, 0; glVertex 0, $h; |
1250 | glVertex $w - 1, 0; glVertex $w - 1, $h; |
1388 | glVertex $w - 1, 0; glVertex $w - 1, $h; |
… | |
… | |
1345 | |
1483 | |
1346 | glEnable GL_TEXTURE_2D; |
1484 | glEnable GL_TEXTURE_2D; |
1347 | glEnable GL_BLEND; |
1485 | glEnable GL_BLEND; |
1348 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1486 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1349 | 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; |
1350 | |
1489 | |
1351 | my $sw4 = ($sw + 3) & ~3; |
1490 | my $sw4 = ($sw + 3) & ~3; |
1352 | my $darkness = "\x00" x ($sw4 * $sh); |
1491 | my $darkness = "\x00" x ($sw4 * $sh); |
1353 | |
1492 | |
1354 | for my $x (0 .. $sw - 1) { |
1493 | for my $x (0 .. $sw - 1) { |
… | |
… | |
1385 | # $lighting =~ s/(.)../$1/gs; |
1524 | # $lighting =~ s/(.)../$1/gs; |
1386 | # } |
1525 | # } |
1387 | |
1526 | |
1388 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1527 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1389 | |
1528 | |
|
|
1529 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1530 | my @conv = ( |
|
|
1531 | 0.05, 0.05, 0.05, |
|
|
1532 | 0.05, 0.60, 0.05, |
|
|
1533 | 0.05, 0.05, 0.05, |
|
|
1534 | ); |
|
|
1535 | CFClient::glConvolutionParameteri GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_REPLICATE_BORDER; |
|
|
1536 | CFClient::glConvolutionFilter2D GL_CONVOLUTION_2D, |
|
|
1537 | GL_ALPHA, 3, 3, GL_ALPHA, GL_FLOAT, |
|
|
1538 | pack "f*", @conv; |
|
|
1539 | glEnable GL_CONVOLUTION_2D; |
|
|
1540 | } |
|
|
1541 | |
1390 | $darkness = new CFClient::Texture |
1542 | $darkness = new CFClient::Texture |
1391 | w => $sw4, |
1543 | w => $sw4, |
1392 | h => $sh, |
1544 | h => $sh, |
1393 | data => $darkness, |
1545 | data => $darkness, |
1394 | internalformat => GL_ALPHA, |
1546 | internalformat => GL_ALPHA, |
1395 | format => GL_ALPHA; |
1547 | format => GL_ALPHA; |
1396 | |
1548 | |
1397 | glColor 0.45, 0.45, 0.45, 1; |
1549 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1398 | $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}; |
1399 | |
1553 | |
1400 | glDisable GL_TEXTURE_2D; |
1554 | glDisable GL_TEXTURE_2D; |
1401 | glDisable GL_BLEND; |
1555 | glDisable GL_BLEND; |
1402 | |
1556 | |
1403 | glEndList; |
1557 | glEndList; |
1404 | } |
1558 | } |
1405 | |
1559 | |
1406 | 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 | } |
1407 | } |
1573 | } |
1408 | |
1574 | |
1409 | my %DIR = ( |
1575 | my %DIR = ( |
1410 | SDLK_KP8, [1, "north"], |
1576 | SDLK_KP8, [1, "north"], |
1411 | SDLK_KP9, [2, "northeast"], |
1577 | SDLK_KP9, [2, "northeast"], |
… | |
… | |
1427 | |
1593 | |
1428 | my $mod = $ev->key_mod; |
1594 | my $mod = $ev->key_mod; |
1429 | my $sym = $ev->key_sym; |
1595 | my $sym = $ev->key_sym; |
1430 | |
1596 | |
1431 | if ($sym == SDLK_KP5) { |
1597 | if ($sym == SDLK_KP5) { |
1432 | $::CONN->send ("command stay fire"); |
1598 | $::CONN->user_send ("command stay fire"); |
|
|
1599 | } elsif ($sym == SDLK_a) { |
|
|
1600 | $::CONN->user_send ("command apply"); |
1433 | } elsif (exists $DIR{$sym}) { |
1601 | } elsif (exists $DIR{$sym}) { |
1434 | if ($mod & KMOD_SHIFT) { |
1602 | if ($mod & KMOD_SHIFT) { |
1435 | $self->{shft}++; |
1603 | $self->{shft}++; |
1436 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1604 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1437 | } elsif ($mod & KMOD_CTRL) { |
1605 | } elsif ($mod & KMOD_CTRL) { |
1438 | $self->{ctrl}++; |
1606 | $self->{ctrl}++; |
1439 | $::CONN->send ("command run $DIR{$sym}[0]"); |
1607 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
1440 | } else { |
1608 | } else { |
1441 | $::CONN->send ("command $DIR{$sym}[1]"); |
1609 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
1442 | } |
1610 | } |
1443 | } |
1611 | } |
1444 | } |
1612 | } |
1445 | |
1613 | |
1446 | sub key_up { |
1614 | sub key_up { |
… | |
… | |
1448 | |
1616 | |
1449 | my $mod = $ev->key_mod; |
1617 | my $mod = $ev->key_mod; |
1450 | my $sym = $ev->key_sym; |
1618 | my $sym = $ev->key_sym; |
1451 | |
1619 | |
1452 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1620 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1453 | $::CONN->send ("command fire_stop"); |
1621 | $::CONN->user_send ("command fire_stop"); |
1454 | } |
1622 | } |
1455 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1623 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1456 | $::CONN->send ("command run_stop"); |
1624 | $::CONN->user_send ("command run_stop"); |
1457 | } |
1625 | } |
1458 | } |
1626 | } |
1459 | |
1627 | |
1460 | ############################################################################# |
1628 | ############################################################################# |
1461 | |
1629 | |