… | |
… | |
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; |
… | |
… | |
1340 | range => [0, 0, 100, 10], |
1350 | range => [0, 0, 100, 10], |
1341 | req_w => 40, |
1351 | req_w => 40, |
1342 | req_h => 13, |
1352 | req_h => 13, |
1343 | vertical => 0, |
1353 | vertical => 0, |
1344 | can_hover => 1, |
1354 | can_hover => 1, |
|
|
1355 | inner_pad => 5, |
1345 | @_ |
1356 | @_ |
1346 | ); |
1357 | ); |
1347 | |
1358 | |
1348 | $self |
1359 | $self |
1349 | } |
1360 | } |
… | |
… | |
1370 | if ($GRAB == $self) { |
1381 | if ($GRAB == $self) { |
1371 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1382 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1372 | |
1383 | |
1373 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
1384 | my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); |
1374 | |
1385 | |
|
|
1386 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
|
|
1387 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
|
|
1388 | |
|
|
1389 | $x -= $inner_pad_px; # substract the padding |
1375 | $x = $x * ($hi - $lo) / $w + $lo; |
1390 | $x = $x * ($hi - $lo) / $inner_w + $lo; |
1376 | $x = $lo if $x < $lo; |
1391 | $x = $lo if $x < $lo; |
1377 | $x = $hi - $page if $x > $hi - $page; |
1392 | $x = $hi - $page if $x > $hi - $page; |
1378 | $self->{range}[0] = $x; |
1393 | $self->{range}[0] = $x; |
1379 | |
1394 | |
1380 | $self->emit (changed => $x); |
1395 | $self->emit (changed => $x); |
1381 | $self->update; |
1396 | $self->update; |
1382 | } |
1397 | } |
|
|
1398 | } |
|
|
1399 | |
|
|
1400 | # the inner_* stuff is for generating a padding for the slider handle, |
|
|
1401 | # so that the handle doesn't leave the texture. This calculation isn't 100% |
|
|
1402 | # correct propably, but it does the job for now |
|
|
1403 | sub _calc_inner_pad_px { |
|
|
1404 | my ($self, $w) = @_; |
|
|
1405 | ($w / 100) * $self->{inner_pad} # % to pixels |
1383 | } |
1406 | } |
1384 | |
1407 | |
1385 | sub _draw { |
1408 | sub _draw { |
1386 | my ($self) = @_; |
1409 | my ($self) = @_; |
1387 | |
1410 | |
… | |
… | |
1401 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1424 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1402 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
1425 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
1403 | |
1426 | |
1404 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1427 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1405 | |
1428 | |
1406 | # the inner_* stuff is for generating a padding for the slider handle, |
1429 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
1407 | # so that the handle doesn't leave the texture. This calculation isn't 100% |
|
|
1408 | # correct propably, but it does the job for now |
|
|
1409 | my $inner_pad = 5; # 5% of width for slider bg texture border |
|
|
1410 | my $inner_pad_px = ($w / 100) * $inner_pad; # % to pixels |
|
|
1411 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
1430 | my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right |
1412 | |
1431 | |
1413 | $page = int $page * $inner_w / ($hi - $lo); |
1432 | $page = int $page * $inner_w / ($hi - $lo); |
1414 | $value = int +($value - $lo) * $inner_w / ($hi - $lo); |
1433 | $value = int +($value - $lo) * $inner_w / ($hi - $lo); |
1415 | |
1434 | |
1416 | $w -= $page; |
1435 | $w -= $page; |
… | |
… | |
1641 | |
1660 | |
1642 | if ($sym == SDLK_KP5) { |
1661 | if ($sym == SDLK_KP5) { |
1643 | $::CONN->user_send ("command stay fire"); |
1662 | $::CONN->user_send ("command stay fire"); |
1644 | } elsif ($sym == SDLK_a) { |
1663 | } elsif ($sym == SDLK_a) { |
1645 | $::CONN->user_send ("command apply"); |
1664 | $::CONN->user_send ("command apply"); |
|
|
1665 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1666 | $self->emit ('activate_console'); |
1646 | } elsif (exists $DIR{$sym}) { |
1667 | } elsif (exists $DIR{$sym}) { |
1647 | if ($mod & KMOD_SHIFT) { |
1668 | if ($mod & KMOD_SHIFT) { |
1648 | $self->{shft}++; |
1669 | $self->{shft}++; |
1649 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1670 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1650 | } elsif ($mod & KMOD_CTRL) { |
1671 | } elsif ($mod & KMOD_CTRL) { |