… | |
… | |
61 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
61 | my $widget = $GRAB || $TOPLEVEL->find_widget ($x, $y); |
62 | |
62 | |
63 | if ($widget != $HOVER) { |
63 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
64 | my $hover = $HOVER; $HOVER = $widget; |
65 | |
65 | |
66 | $hover->update if $hover; |
66 | $hover->update if $hover && $hover->{can_hover}; |
67 | $HOVER->update if $HOVER; |
67 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
68 | } |
68 | } |
69 | |
69 | |
70 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
70 | $HOVER->mouse_motion ($ev, $HOVER->translate ($x, $y)) if $HOVER; |
71 | } |
71 | } |
72 | |
72 | |
… | |
… | |
439 | } |
439 | } |
440 | |
440 | |
441 | sub render_chld { |
441 | sub render_chld { |
442 | my ($self) = @_; |
442 | my ($self) = @_; |
443 | |
443 | |
444 | $self->{texture} = |
444 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
445 | CFClient::Texture->new_from_opengl ( |
445 | glClearColor 0, 0, 0, 1; |
446 | $self->{w}, $self->{h}, sub { $self->child->draw } |
446 | glClear GL_COLOR_BUFFER_BIT; |
447 | ); |
447 | $self->child->draw; |
|
|
448 | }; |
448 | } |
449 | } |
449 | |
450 | |
450 | sub size_allocate { |
451 | sub size_allocate { |
451 | my ($self, $x, $y, $w, $h) = @_; |
452 | my ($self, $x, $y, $w, $h) = @_; |
452 | |
453 | |
… | |
… | |
639 | # TODO: repeat texture not scale |
640 | # TODO: repeat texture not scale |
640 | my $rep_x = $cw / $bg->{w}; |
641 | my $rep_x = $cw / $bg->{w}; |
641 | my $rep_y = $ch / $bg->{h}; |
642 | my $rep_y = $ch / $bg->{h}; |
642 | |
643 | |
643 | glColor @{ $self->{bg} }; |
644 | glColor @{ $self->{bg} }; |
|
|
645 | |
|
|
646 | $bg->{s} = $rep_x; |
|
|
647 | $bg->{t} = $rep_y; |
|
|
648 | $bg->{wrap_mode} = 1; |
644 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
649 | $bg->draw_quad ($self->{border}, $self->{border}, $cw, $ch); |
645 | |
650 | |
646 | glDisable GL_TEXTURE_2D; |
651 | glDisable GL_TEXTURE_2D; |
647 | glDisable GL_BLEND; |
652 | glDisable GL_BLEND; |
648 | |
653 | |
… | |
… | |
827 | } |
832 | } |
828 | |
833 | |
829 | my $y = 0; |
834 | my $y = 0; |
830 | for (0 .. $#$children) { |
835 | for (0 .. $#$children) { |
831 | my $child = $children->[$_]; |
836 | my $child = $children->[$_]; |
832 | my $h = $h[$_]; |
837 | my $h = int $h[$_]; |
833 | $child->size_allocate ($y, 0, $h, $w); |
838 | $child->size_allocate ($y, 0, $h, $w); |
834 | |
839 | |
835 | $y += $h; |
840 | $y += $h; |
836 | } |
841 | } |
837 | } |
842 | } |
… | |
… | |
881 | } |
886 | } |
882 | |
887 | |
883 | my $y = 0; |
888 | my $y = 0; |
884 | for (0 .. $#$children) { |
889 | for (0 .. $#$children) { |
885 | my $child = $children->[$_]; |
890 | my $child = $children->[$_]; |
886 | my $h = $h[$_]; |
891 | my $h = int $h[$_]; |
887 | $child->size_allocate (0, $y, $w, $h); |
892 | $child->size_allocate (0, $y, $w, $h); |
888 | |
893 | |
889 | $y += $h; |
894 | $y += $h; |
890 | } |
895 | } |
891 | } |
896 | } |
… | |
… | |
900 | |
905 | |
901 | sub new { |
906 | sub new { |
902 | my ($class, %arg) = @_; |
907 | my ($class, %arg) = @_; |
903 | |
908 | |
904 | my $self = $class->SUPER::new ( |
909 | my $self = $class->SUPER::new ( |
905 | fg => [1, 1, 1], |
910 | fg => [1, 1, 1], |
906 | height => $::FONTSIZE, |
911 | fontsize => $::FONTSIZE, |
907 | text => "", |
912 | text => "", |
908 | align => -1, |
913 | align => -1, |
909 | padding => 2, |
914 | padding => 2, |
910 | layout => new CFClient::Layout, |
915 | layout => new CFClient::Layout, |
911 | %arg |
916 | %arg |
912 | ); |
917 | ); |
913 | |
918 | |
914 | $self->set_text ($self->{text}); |
919 | $self->set_text ($self->{text}); |
915 | |
920 | |
… | |
… | |
945 | |
950 | |
946 | sub size_request { |
951 | sub size_request { |
947 | my ($self) = @_; |
952 | my ($self) = @_; |
948 | |
953 | |
949 | $self->{layout}->set_width; |
954 | $self->{layout}->set_width; |
950 | $self->{layout}->set_height ($self->{height}); |
955 | $self->{layout}->set_height ($self->{fontsize}); |
951 | my ($w, $h) = $self->{layout}->size; |
956 | my ($w, $h) = $self->{layout}->size; |
952 | |
957 | |
953 | ( |
958 | ( |
954 | $w + $self->{padding} * 2, |
959 | $w + $self->{padding} * 2, |
955 | $h + $self->{padding} * 2, |
960 | $h + $self->{padding} * 2, |
… | |
… | |
974 | sub _draw { |
979 | sub _draw { |
975 | my ($self) = @_; |
980 | my ($self) = @_; |
976 | |
981 | |
977 | my $tex = $self->{texture} ||= do { |
982 | my $tex = $self->{texture} ||= do { |
978 | $self->{layout}->set_width ($self->{w}); |
983 | $self->{layout}->set_width ($self->{w}); |
979 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); |
984 | $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize}); |
980 | new_from_layout CFClient::Texture $self->{layout} |
985 | new_from_layout CFClient::Texture $self->{layout} |
981 | }; |
986 | }; |
982 | |
987 | |
983 | glEnable GL_BLEND; |
988 | glEnable GL_BLEND; |
984 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
989 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
985 | glEnable GL_TEXTURE_2D; |
990 | glEnable GL_TEXTURE_2D; |
986 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
991 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
987 | |
992 | |
988 | glColor @{$self->{fg}}; |
993 | glColor @{$self->{fg}}; |
989 | |
994 | |
990 | my $x = |
995 | my $x = |
991 | $self->{align} < 0 ? $self->{padding} |
996 | $self->{align} < 0 ? $self->{padding} |
992 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
997 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
993 | : ($self->{w} - $tex->{w}) * 0.5; |
998 | : ($self->{w} - $tex->{w}) * 0.5; |
994 | |
999 | |
995 | glTranslate int $x, int +($self->{h} - $tex->{h}) * 0.5, 0; |
1000 | $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5); |
996 | $tex->draw_quad (0, 0); |
|
|
997 | |
1001 | |
998 | glDisable GL_TEXTURE_2D; |
1002 | glDisable GL_TEXTURE_2D; |
999 | glDisable GL_BLEND; |
1003 | glDisable GL_BLEND; |
1000 | } |
1004 | } |
1001 | |
1005 | |
… | |
… | |
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->{fontsize}); |
1033 | |
1039 | |
1034 | $text =~ s/./*/g if $self->{hidden}; |
1040 | $text =~ s/./*/g if $self->{hidden}; |
1035 | |
1041 | |
1036 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
1042 | $self->{layout}->set_markup ($self->escape_text ($text) . " "); |
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; |
… | |
… | |
1446 | |
1465 | |
1447 | sub new { |
1466 | sub new { |
1448 | my $class = shift; |
1467 | my $class = shift; |
1449 | |
1468 | |
1450 | my $self = $class->SUPER::new ( |
1469 | my $self = $class->SUPER::new ( |
|
|
1470 | req_w => $::WIDTH / 6, |
|
|
1471 | req_h => $::HEIGHT / 6, |
|
|
1472 | fontsize => $::FONTSIZE, |
|
|
1473 | @_, |
|
|
1474 | |
|
|
1475 | layout => (new CFClient::Layout), |
1451 | par => [], |
1476 | par => [], |
1452 | @_, |
1477 | height => 0, |
1453 | children => [ |
1478 | children => [ |
1454 | (new CFClient::UI::Empty expand => 1), |
1479 | (new CFClient::UI::Empty expand => 1), |
1455 | (new CFClient::UI::Slider vertical => 1), |
1480 | (new CFClient::UI::Slider vertical => 1), |
1456 | ], |
1481 | ], |
1457 | ); |
1482 | ); |
1458 | |
1483 | |
1459 | $self |
1484 | $self |
1460 | } |
1485 | } |
1461 | |
1486 | |
|
|
1487 | sub text_height { |
|
|
1488 | my ($self, $text) = @_; |
|
|
1489 | |
|
|
1490 | my $layout = $self->{layout}; |
|
|
1491 | |
|
|
1492 | $layout->set_height ($self->{fontsize}); |
|
|
1493 | $layout->set_width ($self->{w}); |
|
|
1494 | $layout->set_text ($text); |
|
|
1495 | |
|
|
1496 | ($layout->size)[1] |
|
|
1497 | } |
|
|
1498 | |
|
|
1499 | sub reflow { |
|
|
1500 | my ($self) = @_; |
|
|
1501 | |
|
|
1502 | my $height = 0; |
|
|
1503 | |
|
|
1504 | for (@{$self->{par}}) { |
|
|
1505 | $height += $_->[0] = $self->text_height ($_->[2]); |
|
|
1506 | } |
|
|
1507 | |
|
|
1508 | $self->{height} = $height; |
|
|
1509 | |
|
|
1510 | $self->{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
|
|
1511 | } |
|
|
1512 | |
|
|
1513 | sub size_request { |
|
|
1514 | my ($self) = @_; |
|
|
1515 | |
|
|
1516 | ($self->{req_w}, $self->{req_h}) |
|
|
1517 | } |
|
|
1518 | |
|
|
1519 | sub size_allocate { |
|
|
1520 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1521 | |
|
|
1522 | $self->SUPER::size_allocate ($x, $y, $w, $h); |
|
|
1523 | |
|
|
1524 | $self->{layout}->set_height ($self->{fontsize}); |
|
|
1525 | $self->{layout}->set_width ($self->{w}); |
|
|
1526 | |
|
|
1527 | $self->reflow; |
|
|
1528 | $self->update; |
|
|
1529 | } |
|
|
1530 | |
1462 | sub add_paragraph { |
1531 | sub add_paragraph { |
1463 | my ($self, $color, $text) = @_; |
1532 | my ($self, $color, $text) = @_; |
1464 | |
1533 | |
|
|
1534 | #TODO: intelligently "reformat" paragraph |
|
|
1535 | |
|
|
1536 | my $height = $self->text_height ($text); |
|
|
1537 | |
|
|
1538 | $self->{height} += $height; |
|
|
1539 | |
1465 | push @{$self->{par}}, [$color, $text]; |
1540 | push @{$self->{par}}, [$height, $color, $text]; |
1466 | my $count = scalar @{$self->{par}}; |
1541 | |
1467 | $self->{children}[1]{range} = [$count - 1, 0, $count, 1]; |
1542 | $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}]; |
1468 | $self->{children}[1]->update; |
1543 | $self->{children}[1]->update; |
1469 | } |
1544 | } |
1470 | |
1545 | |
|
|
1546 | sub update { |
|
|
1547 | my ($self) = @_; |
|
|
1548 | |
|
|
1549 | $self->SUPER::update; |
|
|
1550 | |
|
|
1551 | return unless $self->{h} > 0; |
|
|
1552 | |
|
|
1553 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
|
|
1554 | glClearColor 0, 0, 0, 1; |
|
|
1555 | glClear GL_COLOR_BUFFER_BIT; |
|
|
1556 | |
|
|
1557 | my $y0 = $self->{height} - $self->{h}; |
|
|
1558 | my $y1 = $self->{height}; |
|
|
1559 | |
|
|
1560 | glEnable GL_BLEND; |
|
|
1561 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1562 | glEnable GL_TEXTURE_2D; |
|
|
1563 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1564 | |
|
|
1565 | my $y = 0; |
|
|
1566 | |
|
|
1567 | my $layout = $self->{layout}; |
|
|
1568 | |
|
|
1569 | for my $par (@{$self->{par}}) { |
|
|
1570 | my $h = $par->[0]; |
|
|
1571 | |
|
|
1572 | if ($y0 < $y + $h && $y < $y1) { |
|
|
1573 | $layout->set_text ($par->[2]); |
|
|
1574 | |
|
|
1575 | glColor @{ $par->[1] }; |
|
|
1576 | my ($W, $H) = $layout->size; |
|
|
1577 | CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); |
|
|
1578 | } |
|
|
1579 | |
|
|
1580 | $y += $h; |
|
|
1581 | } |
|
|
1582 | |
|
|
1583 | glDisable GL_TEXTURE_2D; |
|
|
1584 | glDisable GL_BLEND; |
|
|
1585 | }; |
|
|
1586 | } |
|
|
1587 | |
1471 | sub _draw { |
1588 | sub _draw { |
1472 | my ($self) = @_; |
1589 | my ($self) = @_; |
1473 | |
1590 | |
1474 | my $par = $self->{par}; |
1591 | if ($self->{texture}) { |
1475 | |
|
|
1476 | my $bottom = (scalar @$par) - 1; |
|
|
1477 | |
|
|
1478 | my $w = $self->{children}[0]{w}; |
|
|
1479 | my $y = $self->{h}; |
|
|
1480 | |
|
|
1481 | glEnable GL_BLEND; |
|
|
1482 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1483 | glEnable GL_TEXTURE_2D; |
1592 | glEnable GL_TEXTURE_2D; |
1484 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1593 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1485 | |
1594 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
1486 | # TODO: everything! |
|
|
1487 | while ($y > 0 && $bottom >= 0) { |
|
|
1488 | my $par = $par->[$bottom--]; |
|
|
1489 | |
|
|
1490 | my $layout = new CFClient::Layout; |
|
|
1491 | |
|
|
1492 | $layout->set_height ($::FONTSIZE); |
|
|
1493 | $layout->set_width ($w); |
|
|
1494 | $layout->set_text ($par->[1]); |
|
|
1495 | my $tex = new_from_layout CFClient::Texture $layout; |
|
|
1496 | $y -= $tex->{h}; |
|
|
1497 | |
|
|
1498 | glColor @{ $par->[0] }; |
|
|
1499 | $tex->draw_quad (0, $y); |
|
|
1500 | } |
|
|
1501 | |
|
|
1502 | glDisable GL_TEXTURE_2D; |
1595 | glDisable GL_TEXTURE_2D; |
1503 | glDisable GL_BLEND; |
1596 | } |
|
|
1597 | |
1504 | } |
1598 | } |
1505 | |
1599 | |
1506 | ############################################################################# |
1600 | ############################################################################# |
1507 | |
1601 | |
1508 | package CFClient::UI::MapWidget; |
1602 | package CFClient::UI::MapWidget; |
… | |
… | |
1641 | |
1735 | |
1642 | if ($sym == SDLK_KP5) { |
1736 | if ($sym == SDLK_KP5) { |
1643 | $::CONN->user_send ("command stay fire"); |
1737 | $::CONN->user_send ("command stay fire"); |
1644 | } elsif ($sym == SDLK_a) { |
1738 | } elsif ($sym == SDLK_a) { |
1645 | $::CONN->user_send ("command apply"); |
1739 | $::CONN->user_send ("command apply"); |
|
|
1740 | } elsif ($sym == SDLK_QUOTE) { |
|
|
1741 | $self->emit ('activate_console'); |
|
|
1742 | } elsif ($sym == SDLK_SLASH) { |
|
|
1743 | $self->emit ('activate_console' => '/'); |
1646 | } elsif (exists $DIR{$sym}) { |
1744 | } elsif (exists $DIR{$sym}) { |
1647 | if ($mod & KMOD_SHIFT) { |
1745 | if ($mod & KMOD_SHIFT) { |
1648 | $self->{shft}++; |
1746 | $self->{shft}++; |
1649 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1747 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1650 | } elsif ($mod & KMOD_CTRL) { |
1748 | } elsif ($mod & KMOD_CTRL) { |