… | |
… | |
176 | |
176 | |
177 | return if $FOCUS == $self; |
177 | return if $FOCUS == $self; |
178 | return unless $self->{can_focus}; |
178 | return unless $self->{can_focus}; |
179 | |
179 | |
180 | my $focus = $FOCUS; $FOCUS = $self; |
180 | my $focus = $FOCUS; $FOCUS = $self; |
|
|
181 | |
|
|
182 | $self->emit (focus_in => $focus); |
|
|
183 | |
181 | $focus->update if $focus; |
184 | $focus->update if $focus; |
182 | $FOCUS->update; |
185 | $FOCUS->update; |
183 | } |
186 | } |
184 | |
187 | |
185 | sub focus_out { |
188 | sub focus_out { |
186 | my ($self) = @_; |
189 | my ($self) = @_; |
187 | |
190 | |
188 | return unless $FOCUS == $self; |
191 | return unless $FOCUS == $self; |
189 | |
192 | |
190 | my $focus = $FOCUS; undef $FOCUS; |
193 | my $focus = $FOCUS; undef $FOCUS; |
|
|
194 | |
|
|
195 | $self->emit (focus_out => $focus); |
|
|
196 | |
191 | $focus->update if $focus; #? |
197 | $focus->update if $focus; #? |
192 | } |
198 | } |
193 | |
199 | |
194 | sub mouse_motion { } |
200 | sub mouse_motion { } |
195 | sub button_up { } |
201 | sub button_up { } |
… | |
… | |
219 | glPopMatrix; |
225 | glPopMatrix; |
220 | |
226 | |
221 | if ($self == $HOVER && $self->{can_hover}) { |
227 | if ($self == $HOVER && $self->{can_hover}) { |
222 | my ($x, $y) = @$self{qw(x y)}; |
228 | my ($x, $y) = @$self{qw(x y)}; |
223 | |
229 | |
224 | glColor 0, 0, 1, 0.2; |
230 | glColor 1, 0.8, 0.5, 0.2; |
225 | glEnable GL_BLEND; |
231 | glEnable GL_BLEND; |
226 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
232 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
227 | glBegin GL_QUADS; |
233 | glBegin GL_QUADS; |
228 | glVertex $x , $y; |
234 | glVertex $x , $y; |
229 | glVertex $x + $self->{w}, $y; |
235 | glVertex $x + $self->{w}, $y; |
… | |
… | |
254 | my ($self, $parent) = @_; |
260 | my ($self, $parent) = @_; |
255 | |
261 | |
256 | Scalar::Util::weaken ($self->{parent} = $parent); |
262 | Scalar::Util::weaken ($self->{parent} = $parent); |
257 | } |
263 | } |
258 | |
264 | |
|
|
265 | sub check_size { |
|
|
266 | my ($self) = @_; |
|
|
267 | |
|
|
268 | my ($w, $h) = $self->size_request; |
|
|
269 | |
|
|
270 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
|
|
271 | $self->{req_w} = $w; |
|
|
272 | $self->{req_h} = $h; |
|
|
273 | |
|
|
274 | $self->{parent}->check_size |
|
|
275 | if $self->{parent}; |
|
|
276 | } |
|
|
277 | } |
|
|
278 | |
259 | sub update { |
279 | sub update { |
260 | my ($self) = @_; |
280 | my ($self) = @_; |
261 | |
281 | |
262 | $self->{parent}->update |
282 | $self->{parent}->update |
263 | if $self->{parent}; |
283 | if $self->{parent}; |
… | |
… | |
370 | sub remove { |
390 | sub remove { |
371 | my ($self, $widget) = @_; |
391 | my ($self, $widget) = @_; |
372 | |
392 | |
373 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
393 | $self->{children} = [ grep $_ != $widget, @{ $self->{children} } ]; |
374 | |
394 | |
375 | $self->size_allocate (0, 0, $self->{w}, $self->{h}); |
395 | $self->check_size; |
376 | } |
396 | } |
377 | |
397 | |
378 | sub find_widget { |
398 | sub find_widget { |
379 | my ($self, $x, $y) = @_; |
399 | my ($self, $x, $y) = @_; |
380 | |
400 | |
… | |
… | |
500 | $tex->draw_quad (0, 0, $w, $h); |
520 | $tex->draw_quad (0, 0, $w, $h); |
501 | |
521 | |
502 | glDisable GL_BLEND; |
522 | glDisable GL_BLEND; |
503 | glDisable GL_TEXTURE_2D; |
523 | glDisable GL_TEXTURE_2D; |
504 | } |
524 | } |
|
|
525 | |
|
|
526 | ############################################################################# |
|
|
527 | |
|
|
528 | package CFClient::UI::ViewPort; |
|
|
529 | |
|
|
530 | our @ISA = CFClient::UI::Window::; |
|
|
531 | |
|
|
532 | sub new { die } |
|
|
533 | |
|
|
534 | sub size_request { |
|
|
535 | my ($self) = @_; |
|
|
536 | |
|
|
537 | @$self{qw(child_w child_h)} = $self->child->size_request; |
|
|
538 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
|
|
539 | |
|
|
540 | @$self{qw(child_w child_h)} |
|
|
541 | } |
|
|
542 | |
|
|
543 | sub size_allocate { |
|
|
544 | my ($self, $x, $y, $w, $h) = @_; |
|
|
545 | |
|
|
546 | $self->_size_allocate ($x, $y, $w, $h) or return; |
|
|
547 | } |
|
|
548 | |
|
|
549 | sub _draw { |
|
|
550 | my ($self) = @_; |
|
|
551 | |
|
|
552 | $self->{children}[1]->draw; |
|
|
553 | } |
|
|
554 | |
505 | |
555 | |
506 | ############################################################################# |
556 | ############################################################################# |
507 | |
557 | |
508 | package CFClient::UI::Frame; |
558 | package CFClient::UI::Frame; |
509 | |
559 | |
… | |
… | |
840 | } |
890 | } |
841 | |
891 | |
842 | sub size_allocate { |
892 | sub size_allocate { |
843 | my ($self, $x, $y, $w, $h) = @_; |
893 | my ($self, $x, $y, $w, $h) = @_; |
844 | |
894 | |
845 | $self->_size_allocate ($x, $y, $w, $h); |
895 | $self->_size_allocate ($x, $y, $w, $h) or return; |
846 | |
896 | |
847 | ($h, $w) = ($w, $h); |
897 | ($h, $w) = ($w, $h); |
848 | |
898 | |
849 | my $children = $self->{children}; |
899 | my $children = $self->{children}; |
850 | |
900 | |
… | |
… | |
876 | my $h = $h[$_]; |
926 | my $h = $h[$_]; |
877 | $child->size_allocate ($y, 0, $h, $w); |
927 | $child->size_allocate ($y, 0, $h, $w); |
878 | |
928 | |
879 | $y += $h; |
929 | $y += $h; |
880 | } |
930 | } |
|
|
931 | |
|
|
932 | 1 |
881 | } |
933 | } |
882 | |
934 | |
883 | ############################################################################# |
935 | ############################################################################# |
884 | |
936 | |
885 | package CFClient::UI::VBox; |
937 | package CFClient::UI::VBox; |
… | |
… | |
900 | } |
952 | } |
901 | |
953 | |
902 | sub size_allocate { |
954 | sub size_allocate { |
903 | my ($self, $x, $y, $w, $h) = @_; |
955 | my ($self, $x, $y, $w, $h) = @_; |
904 | |
956 | |
905 | $self->_size_allocate ($x, $y, $w, $h); |
957 | $self->_size_allocate ($x, $y, $w, $h) or return; |
906 | |
958 | |
907 | my $children = $self->{children}; |
959 | my $children = $self->{children}; |
908 | |
960 | |
909 | my @h = map +($_->size_request)[1], @$children; |
961 | my @h = map +($_->size_request)[1], @$children; |
910 | |
962 | |
… | |
… | |
932 | my $h = $h[$_]; |
984 | my $h = $h[$_]; |
933 | $child->size_allocate (0, $y, $w, $h); |
985 | $child->size_allocate (0, $y, $w, $h); |
934 | |
986 | |
935 | $y += $h; |
987 | $y += $h; |
936 | } |
988 | } |
|
|
989 | |
|
|
990 | 1 |
937 | } |
991 | } |
938 | |
992 | |
939 | ############################################################################# |
993 | ############################################################################# |
940 | |
994 | |
941 | package CFClient::UI::Label; |
995 | package CFClient::UI::Label; |
… | |
… | |
956 | padding => 2, |
1010 | padding => 2, |
957 | layout => new CFClient::Layout, |
1011 | layout => new CFClient::Layout, |
958 | %arg |
1012 | %arg |
959 | ); |
1013 | ); |
960 | |
1014 | |
961 | $self->set_text ($self->{text}); |
1015 | $self->{xxx}++ if $self->{text} eq "Client Setup" && $self->{align};#d# |
|
|
1016 | |
|
|
1017 | $self->set_text (delete $self->{text}) if exists $self->{text}; |
|
|
1018 | $self->set_markup (delete $self->{markup}) if exists $self->{markup}; |
962 | |
1019 | |
963 | $self |
1020 | $self |
964 | } |
1021 | } |
965 | |
1022 | |
966 | sub escape_text { |
1023 | sub escape_text { |
… | |
… | |
974 | } |
1031 | } |
975 | |
1032 | |
976 | sub set_text { |
1033 | sub set_text { |
977 | my ($self, $text) = @_; |
1034 | my ($self, $text) = @_; |
978 | |
1035 | |
979 | $self->{text} = $text; |
|
|
980 | $self->{layout}->set_markup ($text); |
1036 | $self->{layout}->set_text ($text); |
981 | |
1037 | |
982 | delete $self->{texture}; |
1038 | delete $self->{texture}; |
983 | # $self->{w} = $self->{h} = -1; |
|
|
984 | $self->update; |
1039 | $self->update; |
985 | } |
1040 | } |
986 | |
1041 | |
987 | sub get_text { |
1042 | sub set_markup { |
988 | my ($self, $text) = @_; |
1043 | my ($self, $markup) = @_; |
989 | |
1044 | |
990 | $self->{text} |
1045 | $self->{layout}->set_markup ($markup); |
|
|
1046 | |
|
|
1047 | delete $self->{texture}; |
|
|
1048 | $self->update; |
991 | } |
1049 | } |
992 | |
1050 | |
993 | sub size_request { |
1051 | sub size_request { |
994 | my ($self) = @_; |
1052 | my ($self) = @_; |
995 | |
1053 | |
996 | $self->{layout}->set_width; |
1054 | $self->{layout}->set_width; |
997 | $self->{layout}->set_height ($self->{fontsize}); |
1055 | $self->{layout}->set_height ($self->{fontsize}); |
|
|
1056 | |
998 | my ($w, $h) = $self->{layout}->size; |
1057 | my ($w, $h) = $self->{layout}->size; |
999 | |
1058 | |
1000 | ( |
1059 | ( |
1001 | $w + $self->{padding} * 2, |
1060 | $w + $self->{padding} * 2, |
1002 | $h + $self->{padding} * 2, |
1061 | $h + $self->{padding} * 2, |
… | |
… | |
1021 | sub _draw { |
1080 | sub _draw { |
1022 | my ($self) = @_; |
1081 | my ($self) = @_; |
1023 | |
1082 | |
1024 | my $tex = $self->{texture} ||= do { |
1083 | my $tex = $self->{texture} ||= do { |
1025 | $self->{layout}->set_width ($self->{w}); |
1084 | $self->{layout}->set_width ($self->{w}); |
1026 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
1085 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize}); |
1027 | new_from_layout CFClient::Texture $self->{layout} |
1086 | new_from_layout CFClient::Texture $self->{layout} |
1028 | }; |
1087 | }; |
1029 | |
1088 | |
1030 | glEnable GL_BLEND; |
1089 | glEnable GL_BLEND; |
1031 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1090 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1032 | glEnable GL_TEXTURE_2D; |
1091 | glEnable GL_TEXTURE_2D; |
1033 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1092 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1034 | |
1093 | |
1035 | glColor @{$self->{fg}}; |
1094 | glColor @{$self->{fg}}; |
1036 | |
1095 | |
1037 | my $x = |
1096 | $self->{ox} = int ( |
1038 | $self->{align} < 0 ? $self->{padding} |
1097 | $self->{align} < 0 ? $self->{padding} |
1039 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1098 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1040 | : ($self->{w} - $tex->{w}) * 0.5; |
1099 | : ($self->{w} - $tex->{w}) * 0.5 |
|
|
1100 | ); |
1041 | |
1101 | |
1042 | my $y = |
1102 | $self->{oy} = int ( |
1043 | $self->{valign} < 0 ? $self->{padding} |
1103 | $self->{valign} < 0 ? $self->{padding} |
1044 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1104 | : $self->{valign} > 0 ? $self->{h} - $tex->{h} - $self->{padding} |
1045 | : ($self->{h} - $tex->{h}) * 0.5; |
1105 | : ($self->{h} - $tex->{h}) * 0.5 |
|
|
1106 | ); |
1046 | |
1107 | |
1047 | $tex->draw_quad (int $x, int $y); |
1108 | $tex->draw_quad ($self->{ox}, $self->{oy}); |
1048 | |
1109 | |
1049 | glDisable GL_TEXTURE_2D; |
1110 | glDisable GL_TEXTURE_2D; |
1050 | glDisable GL_BLEND; |
1111 | glDisable GL_BLEND; |
1051 | } |
1112 | } |
1052 | |
1113 | |
1053 | ############################################################################# |
1114 | ############################################################################# |
1054 | |
1115 | |
1055 | package CFClient::UI::Entry; |
1116 | package CFClient::UI::EntryBase; |
1056 | |
1117 | |
1057 | our @ISA = CFClient::UI::Label::; |
1118 | our @ISA = CFClient::UI::Label::; |
1058 | |
1119 | |
1059 | use SDL; |
1120 | use SDL; |
1060 | use SDL::OpenGL; |
1121 | use SDL::OpenGL; |
… | |
… | |
1075 | } |
1136 | } |
1076 | |
1137 | |
1077 | sub _set_text { |
1138 | sub _set_text { |
1078 | my ($self, $text) = @_; |
1139 | my ($self, $text) = @_; |
1079 | |
1140 | |
1080 | my $old_text = $self->{text}; |
1141 | delete $self->{cur_h}; |
|
|
1142 | |
|
|
1143 | return if $self->{text} eq $text; |
1081 | |
1144 | |
1082 | $self->{last_activity} = $::NOW; |
1145 | $self->{last_activity} = $::NOW; |
1083 | |
|
|
1084 | $self->{text} = $text; |
1146 | $self->{text} = $text; |
1085 | $self->{layout}->set_width ($self->{w}); |
|
|
1086 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
|
|
1087 | |
1147 | |
1088 | $text =~ s/./*/g if $self->{hidden}; |
1148 | $text =~ s/./*/g if $self->{hidden}; |
|
|
1149 | $self->{layout}->set_text ("$text "); |
1089 | |
1150 | |
1090 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1151 | $self->emit (changed => $self->{text}); |
|
|
1152 | } |
1091 | |
1153 | |
1092 | $text = substr $text, 0, $self->{cursor}; |
1154 | sub get_text { |
1093 | utf8::encode $text; |
1155 | $_[0]{text} |
1094 | |
|
|
1095 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
1096 | |
|
|
1097 | $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? |
|
|
1098 | if $old_text ne $self->{text}; |
|
|
1099 | } |
1156 | } |
1100 | |
1157 | |
1101 | sub size_request { |
1158 | sub size_request { |
1102 | my ($self) = @_; |
1159 | my ($self) = @_; |
1103 | |
1160 | |
… | |
… | |
1107 | } |
1164 | } |
1108 | |
1165 | |
1109 | sub size_allocate { |
1166 | sub size_allocate { |
1110 | my ($self, $x, $y, $w, $h) = @_; |
1167 | my ($self, $x, $y, $w, $h) = @_; |
1111 | |
1168 | |
1112 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
1169 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
1113 | |
1170 | |
1114 | $self->_set_text ($self->{text}); |
1171 | $self->_set_text ($self->{text}); |
1115 | } |
1172 | } |
1116 | |
1173 | |
1117 | sub set_text { |
1174 | sub set_text { |
… | |
… | |
1207 | |
1264 | |
1208 | $self->SUPER::_draw; |
1265 | $self->SUPER::_draw; |
1209 | |
1266 | |
1210 | #TODO: force update every cursor change :( |
1267 | #TODO: force update every cursor change :( |
1211 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
1268 | if ($FOCUS == $self && (($::NOW - $self->{last_activity}) & 1023) < 600) { |
|
|
1269 | |
|
|
1270 | unless (exists $self->{cur_h}) { |
|
|
1271 | my $text = substr $self->{text}, 0, $self->{cursor}; |
|
|
1272 | utf8::encode $text; |
|
|
1273 | |
|
|
1274 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
|
|
1275 | } |
|
|
1276 | |
1212 | glColor @{$self->{fg}}; |
1277 | glColor @{$self->{fg}}; |
1213 | glBegin GL_LINES; |
1278 | glBegin GL_LINES; |
1214 | glVertex $self->{cur_x}, $self->{cur_y}; |
|
|
1215 | glVertex $self->{cur_x}, $self->{cur_y} + $self->{cur_h}; |
1279 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
|
|
1280 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1216 | glEnd; |
1281 | glEnd; |
1217 | } |
1282 | } |
1218 | } |
1283 | } |
1219 | |
1284 | |
1220 | package CFClient::UI::LineEntry; |
1285 | package CFClient::UI::Entry; |
1221 | |
1286 | |
1222 | our @ISA = CFClient::UI::Entry::; |
1287 | our @ISA = CFClient::UI::EntryBase::; |
1223 | |
1288 | |
1224 | use SDL; |
1289 | use SDL; |
1225 | use SDL::OpenGL; |
1290 | use SDL::OpenGL; |
1226 | |
1291 | |
1227 | sub key_down { |
1292 | sub key_down { |
… | |
… | |
1257 | |
1322 | |
1258 | $class->SUPER::new ( |
1323 | $class->SUPER::new ( |
1259 | padding => 4, |
1324 | padding => 4, |
1260 | fg => [1, 1, 1], |
1325 | fg => [1, 1, 1], |
1261 | bg => [1, 1, 1, 0.2], |
1326 | bg => [1, 1, 1, 0.2], |
1262 | active_fg => [1, 1, 0], |
1327 | active_fg => [0, 0, 1], |
1263 | can_hover => 1, |
1328 | can_hover => 1, |
1264 | @_ |
1329 | @_ |
1265 | ) |
1330 | ) |
1266 | } |
1331 | } |
1267 | |
1332 | |
… | |
… | |
1330 | } |
1395 | } |
1331 | |
1396 | |
1332 | sub size_allocate { |
1397 | sub size_allocate { |
1333 | my ($self, $x, $y, $w, $h) = @_; |
1398 | my ($self, $x, $y, $w, $h) = @_; |
1334 | |
1399 | |
1335 | $self->_size_allocate ($x, $y, $w, $h); |
1400 | $self->_size_allocate ($x, $y, $w, $h) or return; |
1336 | } |
1401 | } |
1337 | |
1402 | |
1338 | sub button_down { |
1403 | sub button_down { |
1339 | my ($self, $ev, $x, $y) = @_; |
1404 | my ($self, $ev, $x, $y) = @_; |
1340 | |
1405 | |
… | |
… | |
1364 | |
1429 | |
1365 | $tex->draw_quad (0, 0, $s, $s); |
1430 | $tex->draw_quad (0, 0, $s, $s); |
1366 | |
1431 | |
1367 | glDisable GL_TEXTURE_2D; |
1432 | glDisable GL_TEXTURE_2D; |
1368 | glDisable GL_BLEND; |
1433 | glDisable GL_BLEND; |
|
|
1434 | } |
|
|
1435 | |
|
|
1436 | ############################################################################# |
|
|
1437 | |
|
|
1438 | package CFClient::UI::VGauge; |
|
|
1439 | |
|
|
1440 | our @ISA = CFClient::UI::Base::; |
|
|
1441 | |
|
|
1442 | use SDL::OpenGL; |
|
|
1443 | |
|
|
1444 | my %tex = ( |
|
|
1445 | food => [ |
|
|
1446 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1447 | qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ |
|
|
1448 | ], |
|
|
1449 | grace => [ |
|
|
1450 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1451 | qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ |
|
|
1452 | ], |
|
|
1453 | hp => [ |
|
|
1454 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1455 | qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ |
|
|
1456 | ], |
|
|
1457 | mana => [ |
|
|
1458 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1459 | qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ |
|
|
1460 | ], |
|
|
1461 | ); |
|
|
1462 | |
|
|
1463 | # eg. VGauge->new (gauge => 'food'), default gauge: food |
|
|
1464 | sub new { |
|
|
1465 | my $class = shift; |
|
|
1466 | |
|
|
1467 | my $self = $class->SUPER::new (gauge => 'food', @_); |
|
|
1468 | |
|
|
1469 | $self |
|
|
1470 | } |
|
|
1471 | |
|
|
1472 | sub size_request { |
|
|
1473 | my ($self) = @_; |
|
|
1474 | |
|
|
1475 | ($self->{w}, $self->{h}) |
|
|
1476 | } |
|
|
1477 | |
|
|
1478 | sub set_max { |
|
|
1479 | my ($self, $max) = @_; |
|
|
1480 | $self->{max_val} = $max; |
|
|
1481 | } |
|
|
1482 | |
|
|
1483 | sub set_value { |
|
|
1484 | my ($self, $val, $max) = @_; |
|
|
1485 | |
|
|
1486 | $self->set_max ($max) |
|
|
1487 | if defined $max; |
|
|
1488 | |
|
|
1489 | $max = $self->{max_val}; |
|
|
1490 | $self->{val} = $val; |
|
|
1491 | |
|
|
1492 | $self->update; |
|
|
1493 | } |
|
|
1494 | |
|
|
1495 | sub _draw { |
|
|
1496 | my ($self) = @_; |
|
|
1497 | |
|
|
1498 | my $tex = $tex{$self->{gauge}}; |
|
|
1499 | |
|
|
1500 | my ($w, $h) = ($self->{w}, $self->{h}); |
|
|
1501 | |
|
|
1502 | my $ycut = $self->{val} / ($self->{max_val} || 1); |
|
|
1503 | $ycut = 1 if $self->{val} > $self->{max_val}; |
|
|
1504 | |
|
|
1505 | my $t1 = $tex->[0]; |
|
|
1506 | my $t2 = $tex->[1]; |
|
|
1507 | |
|
|
1508 | glEnable GL_BLEND; |
|
|
1509 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1510 | glEnable GL_TEXTURE_2D; |
|
|
1511 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1512 | |
|
|
1513 | my $h1 = $self->{h} - $ycut * $self->{h}; |
|
|
1514 | my $h2 = $ycut * $self->{h}; |
|
|
1515 | |
|
|
1516 | my $yp = 0; |
|
|
1517 | |
|
|
1518 | glBindTexture (GL_TEXTURE_2D, $t1->{name}); |
|
|
1519 | glBegin (GL_QUADS); |
|
|
1520 | glTexCoord (0, 0); glVertex (0 , $yp); |
|
|
1521 | glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp + $h1); |
|
|
1522 | glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp + $h1); |
|
|
1523 | glTexCoord (1, 0); glVertex (0 + $w, $yp); |
|
|
1524 | glEnd (); |
|
|
1525 | |
|
|
1526 | $yp += $h1; |
|
|
1527 | |
|
|
1528 | glBindTexture (GL_TEXTURE_2D, $t2->{name}); |
|
|
1529 | glBegin (GL_QUADS); |
|
|
1530 | glTexCoord (0, (1 - $ycut)); glVertex (0 , $yp); |
|
|
1531 | glTexCoord (0, 1); glVertex (0 , $yp + $h2); |
|
|
1532 | glTexCoord (1, 1); glVertex (0 + $w, $yp + $h2); |
|
|
1533 | glTexCoord (1, (1 - $ycut)); glVertex (0 + $w, $yp); |
|
|
1534 | glEnd (); |
|
|
1535 | |
|
|
1536 | glDisable GL_BLEND; |
|
|
1537 | glDisable GL_TEXTURE_2D; |
1369 | } |
1538 | } |
1370 | |
1539 | |
1371 | ############################################################################# |
1540 | ############################################################################# |
1372 | |
1541 | |
1373 | package CFClient::UI::Slider; |
1542 | package CFClient::UI::Slider; |
… | |
… | |
1569 | } |
1738 | } |
1570 | |
1739 | |
1571 | sub size_allocate { |
1740 | sub size_allocate { |
1572 | my ($self, $x, $y, $w, $h) = @_; |
1741 | my ($self, $x, $y, $w, $h) = @_; |
1573 | |
1742 | |
1574 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
1743 | $self->SUPER::size_allocate ($x, $y, $w, $h) or return; |
1575 | |
1744 | |
1576 | $self->{layout}->set_height ($self->{fontsize}); |
1745 | $self->{layout}->set_height ($self->{fontsize}); |
1577 | $self->{layout}->set_width ($self->{w}); |
1746 | $self->{layout}->set_width ($self->{w}); |
1578 | |
1747 | |
1579 | $self->reflow; |
1748 | $self->reflow; |
|
|
1749 | $self->update; |
1580 | } |
1750 | } |
1581 | |
1751 | |
1582 | sub add_paragraph { |
1752 | sub add_paragraph { |
1583 | my ($self, $color, $text) = @_; |
1753 | my ($self, $color, $text) = @_; |
1584 | |
1754 | |
… | |
… | |
1869 | |
2039 | |
1870 | my $mod = $ev->key_mod; |
2040 | my $mod = $ev->key_mod; |
1871 | my $sym = $ev->key_sym; |
2041 | my $sym = $ev->key_sym; |
1872 | |
2042 | |
1873 | if ($sym == SDLK_KP5) { |
2043 | if ($sym == SDLK_KP5) { |
1874 | $::CONN->user_send ("command stay fire"); |
2044 | $::CONN->user_send ("stay fire"); |
1875 | } elsif ($sym == SDLK_a) { |
2045 | } elsif ($sym == SDLK_a) { |
1876 | $::CONN->user_send ("command apply"); |
2046 | $::CONN->user_send ("apply"); |
1877 | } elsif ($sym == SDLK_QUOTE) { |
2047 | } elsif ($sym == SDLK_QUOTE) { |
1878 | $self->emit ('activate_console'); |
2048 | $self->emit ('activate_console'); |
1879 | } elsif ($sym == SDLK_SLASH) { |
2049 | } elsif ($sym == SDLK_SLASH) { |
1880 | $self->emit ('activate_console' => '/'); |
2050 | $self->emit ('activate_console' => '/'); |
1881 | } elsif (exists $DIR{$sym}) { |
2051 | } elsif (exists $DIR{$sym}) { |
1882 | if ($mod & KMOD_SHIFT) { |
2052 | if ($mod & KMOD_SHIFT) { |
1883 | $self->{shft}++; |
2053 | $self->{shft}++; |
1884 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
2054 | $::CONN->user_send ("fire $DIR{$sym}[0]"); |
1885 | } elsif ($mod & KMOD_CTRL) { |
2055 | } elsif ($mod & KMOD_CTRL) { |
1886 | $self->{ctrl}++; |
2056 | $self->{ctrl}++; |
1887 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
2057 | $::CONN->user_send ("run $DIR{$sym}[0]"); |
1888 | } else { |
2058 | } else { |
1889 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
2059 | $::CONN->user_send ("$DIR{$sym}[1]"); |
1890 | } |
2060 | } |
1891 | } |
2061 | } |
1892 | } |
2062 | } |
1893 | |
2063 | |
1894 | sub key_up { |
2064 | sub key_up { |
… | |
… | |
1896 | |
2066 | |
1897 | my $mod = $ev->key_mod; |
2067 | my $mod = $ev->key_mod; |
1898 | my $sym = $ev->key_sym; |
2068 | my $sym = $ev->key_sym; |
1899 | |
2069 | |
1900 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
2070 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1901 | $::CONN->user_send ("command fire_stop"); |
2071 | $::CONN->user_send ("fire_stop"); |
1902 | } |
2072 | } |
1903 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
2073 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1904 | $::CONN->user_send ("command run_stop"); |
2074 | $::CONN->user_send ("run_stop"); |
1905 | } |
2075 | } |
1906 | } |
2076 | } |
1907 | |
2077 | |
1908 | ############################################################################# |
2078 | ############################################################################# |
1909 | |
2079 | |
… | |
… | |
1992 | |
2162 | |
1993 | our @ISA = CFClient::UI::Container::; |
2163 | our @ISA = CFClient::UI::Container::; |
1994 | |
2164 | |
1995 | use SDL::OpenGL; |
2165 | use SDL::OpenGL; |
1996 | |
2166 | |
|
|
2167 | sub check_size { |
|
|
2168 | my ($self) = @_; |
|
|
2169 | |
|
|
2170 | $self->size_allocate (0, 0, $::WITH, $::HEIGHT); |
|
|
2171 | } |
|
|
2172 | |
1997 | sub size_request { |
2173 | sub size_request { |
1998 | ($::WIDTH, $::HEIGHT) |
2174 | ($::WIDTH, $::HEIGHT) |
1999 | } |
2175 | } |
2000 | |
2176 | |
2001 | sub size_allocate { |
2177 | sub size_allocate { |
… | |
… | |
2014 | } |
2190 | } |
2015 | |
2191 | |
2016 | sub update { |
2192 | sub update { |
2017 | my ($self) = @_; |
2193 | my ($self) = @_; |
2018 | |
2194 | |
2019 | $self->size_allocate (0, 0, $::WIDTH, $::HEIGHT); |
2195 | $self->check_size; |
2020 | ::refresh (); |
2196 | ::refresh (); |
2021 | } |
2197 | } |
2022 | |
2198 | |
2023 | sub add { |
2199 | sub add { |
2024 | my ($self, $widget) = @_; |
2200 | my ($self, $widget) = @_; |