… | |
… | |
639 | # TODO: repeat texture not scale |
639 | # TODO: repeat texture not scale |
640 | my $rep_x = $cw / $bg->{w}; |
640 | my $rep_x = $cw / $bg->{w}; |
641 | my $rep_y = $ch / $bg->{h}; |
641 | my $rep_y = $ch / $bg->{h}; |
642 | |
642 | |
643 | glColor @{ $self->{bg} }; |
643 | glColor @{ $self->{bg} }; |
|
|
644 | |
|
|
645 | $bg->{s} = $rep_x; |
|
|
646 | $bg->{t} = $rep_y; |
|
|
647 | $bg->{wrap_mode} = 1; |
644 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
648 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
645 | |
649 | |
646 | glDisable GL_TEXTURE_2D; |
650 | glDisable GL_TEXTURE_2D; |
647 | glDisable GL_BLEND; |
651 | glDisable GL_BLEND; |
648 | |
652 | |
… | |
… | |
1023 | } |
1027 | } |
1024 | |
1028 | |
1025 | sub _set_text { |
1029 | sub _set_text { |
1026 | my ($self, $text) = @_; |
1030 | my ($self, $text) = @_; |
1027 | |
1031 | |
|
|
1032 | my $old_text = $self->{text}; |
|
|
1033 | |
1028 | $self->{last_activity} = $::NOW; |
1034 | $self->{last_activity} = $::NOW; |
1029 | |
1035 | |
1030 | $self->{text} = $text; |
1036 | $self->{text} = $text; |
1031 | $self->{layout}->set_width ($self->{w}); |
1037 | $self->{layout}->set_width ($self->{w}); |
1032 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
1038 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
… | |
… | |
1037 | |
1043 | |
1038 | $text = substr $text, 0, $self->{cursor}; |
1044 | $text = substr $text, 0, $self->{cursor}; |
1039 | utf8::encode $text; |
1045 | utf8::encode $text; |
1040 | |
1046 | |
1041 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
1047 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
|
|
1048 | |
|
|
1049 | $self->emit (changed => $self->{text}) # XXX: is this the right place to do this? |
|
|
1050 | if $old_text ne $self->{text}; |
1042 | } |
1051 | } |
1043 | |
1052 | |
1044 | sub size_request { |
1053 | sub size_request { |
1045 | my ($self) = @_; |
1054 | my ($self) = @_; |
1046 | |
1055 | |
… | |
… | |
1085 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1094 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1086 | } elsif ($sym == SDLK_HOME) { |
1095 | } elsif ($sym == SDLK_HOME) { |
1087 | $self->{cursor} = 0; |
1096 | $self->{cursor} = 0; |
1088 | } elsif ($sym == SDLK_END) { |
1097 | } elsif ($sym == SDLK_END) { |
1089 | $self->{cursor} = length $text; |
1098 | $self->{cursor} = length $text; |
|
|
1099 | } elsif ($sym == SDLK_ESCAPE) { |
|
|
1100 | $self->emit ('escape'); |
1090 | } elsif ($uni) { |
1101 | } elsif ($uni) { |
1091 | substr $text, $self->{cursor}++, 0, chr $uni; |
1102 | substr $text, $self->{cursor}++, 0, chr $uni; |
1092 | } |
1103 | } |
1093 | |
1104 | |
1094 | $self->_set_text ($text); |
1105 | $self->_set_text ($text); |
… | |
… | |
1244 | |
1255 | |
1245 | package CFClient::UI::CheckBox; |
1256 | package CFClient::UI::CheckBox; |
1246 | |
1257 | |
1247 | our @ISA = CFClient::UI::DrawBG::; |
1258 | our @ISA = CFClient::UI::DrawBG::; |
1248 | |
1259 | |
|
|
1260 | my @tex = |
|
|
1261 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1262 | qw(c1_checkbox_bg.png c1_checkbox_active.png); |
|
|
1263 | |
1249 | use SDL; |
1264 | use SDL; |
1250 | use SDL::OpenGL; |
1265 | use SDL::OpenGL; |
1251 | |
1266 | |
1252 | sub new { |
1267 | sub new { |
1253 | my $class = shift; |
1268 | my $class = shift; |
… | |
… | |
1290 | $self->SUPER::_draw; |
1305 | $self->SUPER::_draw; |
1291 | |
1306 | |
1292 | glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; |
1307 | glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; |
1293 | |
1308 | |
1294 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1309 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
1295 | |
1310 | |
1296 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1311 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
1297 | |
1312 | |
1298 | glBegin GL_LINE_LOOP; |
1313 | glEnable GL_BLEND; |
1299 | glVertex 0 , 0; |
1314 | glEnable GL_TEXTURE_2D; |
1300 | glVertex 0 , $s; |
1315 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1301 | glVertex $s, $s; |
|
|
1302 | glVertex $s, 0; |
|
|
1303 | glEnd; |
|
|
1304 | |
1316 | |
1305 | if ($self->{state}) { |
1317 | my $tex = $self->{state} ? $tex[1] : $tex[0]; |
1306 | glBegin GL_LINES; |
1318 | |
1307 | glVertex 0 , 0; |
1319 | $tex->draw_quad (0, 0, $s, $s); |
1308 | glVertex $s, $s; |
1320 | |
1309 | glVertex $s, 0; |
1321 | glDisable GL_TEXTURE_2D; |
1310 | glVertex 0 , $s; |
1322 | glDisable GL_BLEND; |
1311 | glEnd; |
|
|
1312 | } |
|
|
1313 | } |
1323 | } |
1314 | |
1324 | |
1315 | ############################################################################# |
1325 | ############################################################################# |
1316 | |
1326 | |
1317 | package CFClient::UI::Slider; |
1327 | package CFClient::UI::Slider; |
… | |
… | |
1641 | |
1651 | |
1642 | if ($sym == SDLK_KP5) { |
1652 | if ($sym == SDLK_KP5) { |
1643 | $::CONN->user_send ("command stay fire"); |
1653 | $::CONN->user_send ("command stay fire"); |
1644 | } elsif ($sym == SDLK_a) { |
1654 | } elsif ($sym == SDLK_a) { |
1645 | $::CONN->user_send ("command apply"); |
1655 | $::CONN->user_send ("command apply"); |
|
|
1656 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1657 | $self->emit ('activate_console'); |
1646 | } elsif (exists $DIR{$sym}) { |
1658 | } elsif (exists $DIR{$sym}) { |
1647 | if ($mod & KMOD_SHIFT) { |
1659 | if ($mod & KMOD_SHIFT) { |
1648 | $self->{shft}++; |
1660 | $self->{shft}++; |
1649 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1661 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1650 | } elsif ($mod & KMOD_CTRL) { |
1662 | } elsif ($mod & KMOD_CTRL) { |