… | |
… | |
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 | } |
… | |
… | |
263 | |
271 | |
264 | # range [value, low, high, page] |
272 | # range [value, low, high, page] |
265 | |
273 | |
266 | $class->SUPER::new ( |
274 | $class->SUPER::new ( |
267 | bg => [0, 0, 0, 0.2], |
275 | bg => [0, 0, 0, 0.2], |
268 | active_bg => [1, 1, 1], |
276 | active_bg => [1, 1, 1, 0.5], |
269 | @_ |
277 | @_ |
270 | ) |
278 | ) |
271 | } |
279 | } |
272 | |
280 | |
273 | sub _draw { |
281 | sub _draw { |
… | |
… | |
629 | |
637 | |
630 | my $bg = $tex[0]; |
638 | my $bg = $tex[0]; |
631 | |
639 | |
632 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
640 | glBindTexture GL_TEXTURE_2D, $bg->{name}; |
633 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
641 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
634 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT; |
|
|
635 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT; |
|
|
636 | |
642 | |
637 | my $rep_x = $cw / $bg->{w}; |
643 | my $rep_x = $cw / $bg->{w}; |
638 | my $rep_y = $ch / $bg->{h}; |
644 | my $rep_y = $ch / $bg->{h}; |
639 | |
645 | |
640 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
646 | $bg->draw_quad ($left->{w}, $top->{h}, $cw, $ch); |
… | |
… | |
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; |
… | |
… | |
933 | |
938 | |
934 | $self->{text} = $text; |
939 | $self->{text} = $text; |
935 | $self->{layout}->set_markup ($text); |
940 | $self->{layout}->set_markup ($text); |
936 | |
941 | |
937 | delete $self->{texture}; |
942 | delete $self->{texture}; |
|
|
943 | # $self->{w} = $self->{h} = -1; |
938 | $self->update; |
944 | $self->update; |
939 | } |
945 | } |
940 | |
946 | |
941 | sub get_text { |
947 | sub get_text { |
942 | my ($self, $text) = @_; |
948 | my ($self, $text) = @_; |
… | |
… | |
975 | sub _draw { |
981 | sub _draw { |
976 | my ($self) = @_; |
982 | my ($self) = @_; |
977 | |
983 | |
978 | my $tex = $self->{texture} ||= do { |
984 | my $tex = $self->{texture} ||= do { |
979 | $self->{layout}->set_width ($self->{w}); |
985 | $self->{layout}->set_width ($self->{w}); |
980 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{height}); |
986 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
981 | new_from_layout CFClient::Texture $self->{layout} |
987 | new_from_layout CFClient::Texture $self->{layout} |
982 | }; |
988 | }; |
983 | |
989 | |
984 | glEnable GL_BLEND; |
990 | glEnable GL_BLEND; |
985 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
991 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
… | |
… | |
991 | my $x = |
997 | my $x = |
992 | $self->{align} < 0 ? $self->{padding} |
998 | $self->{align} < 0 ? $self->{padding} |
993 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
999 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
994 | : ($self->{w} - $tex->{w}) * 0.5; |
1000 | : ($self->{w} - $tex->{w}) * 0.5; |
995 | |
1001 | |
996 | $tex->draw_quad ($x, $self->{padding}); |
1002 | glTranslate $x, $self->{padding}, 0; |
|
|
1003 | $tex->draw_quad (0, 0); |
997 | |
1004 | |
998 | glDisable GL_TEXTURE_2D; |
1005 | glDisable GL_TEXTURE_2D; |
999 | glDisable GL_BLEND; |
1006 | glDisable GL_BLEND; |
1000 | } |
1007 | } |
1001 | |
1008 | |
… | |
… | |
1012 | my $class = shift; |
1019 | my $class = shift; |
1013 | |
1020 | |
1014 | $class->SUPER::new ( |
1021 | $class->SUPER::new ( |
1015 | fg => [1, 1, 1], |
1022 | fg => [1, 1, 1], |
1016 | bg => [0, 0, 0, 0.2], |
1023 | bg => [0, 0, 0, 0.2], |
1017 | active_bg => [1, 1, 1], |
1024 | active_bg => [1, 1, 1, 0.5], |
1018 | active_fg => [0, 0, 0], |
1025 | active_fg => [0, 0, 0], |
1019 | @_ |
1026 | @_ |
1020 | ) |
1027 | ) |
1021 | } |
1028 | } |
1022 | |
1029 | |
… | |
… | |
1025 | |
1032 | |
1026 | $self->{last_activity} = $::NOW; |
1033 | $self->{last_activity} = $::NOW; |
1027 | |
1034 | |
1028 | $self->{text} = $text; |
1035 | $self->{text} = $text; |
1029 | $self->{layout}->set_width ($self->{w}); |
1036 | $self->{layout}->set_width ($self->{w}); |
|
|
1037 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
1030 | |
1038 | |
1031 | $text =~ s/./*/g if $self->{hidden}; |
1039 | $text =~ s/./*/g if $self->{hidden}; |
1032 | |
1040 | |
1033 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1041 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1034 | |
1042 | |
… | |
… | |
1155 | } |
1163 | } |
1156 | } |
1164 | } |
1157 | |
1165 | |
1158 | ############################################################################# |
1166 | ############################################################################# |
1159 | |
1167 | |
|
|
1168 | package CFClient::UI::Button; |
|
|
1169 | |
|
|
1170 | our @ISA = CFClient::UI::Label::; |
|
|
1171 | |
|
|
1172 | use SDL; |
|
|
1173 | use SDL::OpenGL; |
|
|
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_bg => [0, 0, 0, 0.5], |
|
|
1183 | active_fg => [1, 1, 0], |
|
|
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 | |
|
|
1203 | glEnable GL_BLEND; |
|
|
1204 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1205 | |
|
|
1206 | glTranslate 0.375, 0.375, 0; # make line and polyogon coordinates behave similarly |
|
|
1207 | |
|
|
1208 | glBegin GL_LINE_LOOP; |
|
|
1209 | glColor @{$self->{border_fg}}; |
|
|
1210 | glVertex 1 , 1; |
|
|
1211 | glVertex 1 , $self->{h} - 2; |
|
|
1212 | glVertex $self->{w} - 2, $self->{h} - 2; |
|
|
1213 | glVertex $self->{w} - 2, 1; |
|
|
1214 | glEnd; |
|
|
1215 | |
|
|
1216 | if ($GRAB == $self) { |
|
|
1217 | glColor @{$self->{active_bg}}; |
|
|
1218 | $self->{fg} = $self->{active_fg}; |
|
|
1219 | } else { |
|
|
1220 | glColor @{$self->{bg}}; |
|
|
1221 | } |
|
|
1222 | |
|
|
1223 | glBegin GL_QUADS; |
|
|
1224 | glVertex 2 , 2; |
|
|
1225 | glVertex 2 , $self->{h} - 2; |
|
|
1226 | glVertex $self->{w} - 2, $self->{h} - 2; |
|
|
1227 | glVertex $self->{w} - 2, 2; |
|
|
1228 | glEnd; |
|
|
1229 | glDisable GL_BLEND; |
|
|
1230 | |
|
|
1231 | $self->SUPER::_draw; |
|
|
1232 | } |
|
|
1233 | |
|
|
1234 | ############################################################################# |
|
|
1235 | |
1160 | package CFClient::UI::Slider; |
1236 | package CFClient::UI::Slider; |
1161 | |
1237 | |
1162 | use strict; |
1238 | use strict; |
1163 | |
1239 | |
1164 | use SDL::OpenGL; |
1240 | use SDL::OpenGL; |
… | |
… | |
1242 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1318 | $value = int +($value - $lo) * $w / ($hi - $lo); |
1243 | |
1319 | |
1244 | $w -= $page; |
1320 | $w -= $page; |
1245 | $page &= ~1; |
1321 | $page &= ~1; |
1246 | glTranslate $page * 0.5, 0, 0; |
1322 | glTranslate $page * 0.5, 0, 0; |
|
|
1323 | $page ||= 2; |
1247 | |
1324 | |
1248 | glColor @$fg; |
1325 | glColor @$fg; |
1249 | glBegin GL_LINES; |
1326 | glBegin GL_LINES; |
1250 | glVertex 0, 0; glVertex 0, $h; |
1327 | glVertex 0, 0; glVertex 0, $h; |
1251 | glVertex $w - 1, 0; glVertex $w - 1, $h; |
1328 | glVertex $w - 1, 0; glVertex $w - 1, $h; |