… | |
… | |
801 | } |
801 | } |
802 | |
802 | |
803 | sub size_allocate { |
803 | sub size_allocate { |
804 | my ($self, $x, $y, $w, $h) = @_; |
804 | my ($self, $x, $y, $w, $h) = @_; |
805 | |
805 | |
806 | $self->_size_allocate ($x, $y, $w, $h) or return; |
806 | $self->_size_allocate ($x, $y, $w, $h); |
807 | |
|
|
808 | return unless $self->{w}; |
|
|
809 | |
807 | |
810 | ($h, $w) = ($w, $h); |
808 | ($h, $w) = ($w, $h); |
811 | |
809 | |
812 | my $children = $self->{children}; |
810 | my $children = $self->{children}; |
813 | |
811 | |
… | |
… | |
861 | } |
859 | } |
862 | |
860 | |
863 | sub size_allocate { |
861 | sub size_allocate { |
864 | my ($self, $x, $y, $w, $h) = @_; |
862 | my ($self, $x, $y, $w, $h) = @_; |
865 | |
863 | |
866 | $self->_size_allocate ($x, $y, $w, $h) or return; |
864 | $self->_size_allocate ($x, $y, $w, $h); |
867 | |
|
|
868 | return unless $self->{h}; |
|
|
869 | |
865 | |
870 | my $children = $self->{children}; |
866 | my $children = $self->{children}; |
871 | |
867 | |
872 | my @h = map +($_->size_request)[1], @$children; |
868 | my @h = map +($_->size_request)[1], @$children; |
873 | |
869 | |
… | |
… | |
1224 | $self->SUPER::_draw; |
1220 | $self->SUPER::_draw; |
1225 | } |
1221 | } |
1226 | |
1222 | |
1227 | ############################################################################# |
1223 | ############################################################################# |
1228 | |
1224 | |
|
|
1225 | package CFClient::UI::CheckBox; |
|
|
1226 | |
|
|
1227 | our @ISA = CFClient::UI::DrawBG::; |
|
|
1228 | |
|
|
1229 | use SDL; |
|
|
1230 | use SDL::OpenGL; |
|
|
1231 | |
|
|
1232 | sub new { |
|
|
1233 | my $class = shift; |
|
|
1234 | |
|
|
1235 | $class->SUPER::new ( |
|
|
1236 | padding => 2, |
|
|
1237 | fg => [1, 1, 1], |
|
|
1238 | active_fg => [1, 1, 0], |
|
|
1239 | state => 0, |
|
|
1240 | @_ |
|
|
1241 | ) |
|
|
1242 | } |
|
|
1243 | |
|
|
1244 | sub size_request { |
|
|
1245 | my ($self) = @_; |
|
|
1246 | |
|
|
1247 | ($self->{padding} * 2 + 6) x 2 |
|
|
1248 | } |
|
|
1249 | |
|
|
1250 | sub size_allocate { |
|
|
1251 | my ($self, $x, $y, $w, $h) = @_; |
|
|
1252 | |
|
|
1253 | $self->_size_allocate ($x, $y, $w, $h); |
|
|
1254 | } |
|
|
1255 | |
|
|
1256 | sub button_down { |
|
|
1257 | my ($self, $ev, $x, $y) = @_; |
|
|
1258 | |
|
|
1259 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
|
|
1260 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
|
|
1261 | $self->{state} = !$self->{state}; |
|
|
1262 | $self->emit (changed => $self->{state}); |
|
|
1263 | } |
|
|
1264 | } |
|
|
1265 | |
|
|
1266 | sub _draw { |
|
|
1267 | my ($self) = @_; |
|
|
1268 | |
|
|
1269 | $self->SUPER::_draw; |
|
|
1270 | |
|
|
1271 | glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; |
|
|
1272 | |
|
|
1273 | my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; |
|
|
1274 | |
|
|
1275 | glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; |
|
|
1276 | |
|
|
1277 | glBegin GL_LINE_LOOP; |
|
|
1278 | glVertex 0 , 0; |
|
|
1279 | glVertex 0 , $s; |
|
|
1280 | glVertex $s, $s; |
|
|
1281 | glVertex $s, 0; |
|
|
1282 | glEnd; |
|
|
1283 | |
|
|
1284 | if ($self->{state}) { |
|
|
1285 | glBegin GL_LINES; |
|
|
1286 | glVertex 0 , 0; |
|
|
1287 | glVertex $s, $s; |
|
|
1288 | glVertex $s, 0; |
|
|
1289 | glVertex 0 , $s; |
|
|
1290 | glEnd; |
|
|
1291 | } |
|
|
1292 | } |
|
|
1293 | |
|
|
1294 | ############################################################################# |
|
|
1295 | |
1229 | package CFClient::UI::Slider; |
1296 | package CFClient::UI::Slider; |
1230 | |
1297 | |
1231 | use strict; |
1298 | use strict; |
1232 | |
1299 | |
1233 | use SDL::OpenGL; |
1300 | use SDL::OpenGL; |
… | |
… | |
1416 | |
1483 | |
1417 | glEnable GL_TEXTURE_2D; |
1484 | glEnable GL_TEXTURE_2D; |
1418 | glEnable GL_BLEND; |
1485 | glEnable GL_BLEND; |
1419 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1486 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1420 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1487 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1488 | glColor 1, 1, 1, 1; |
1421 | |
1489 | |
1422 | my $sw4 = ($sw + 3) & ~3; |
1490 | my $sw4 = ($sw + 3) & ~3; |
1423 | my $darkness = "\x00" x ($sw4 * $sh); |
1491 | my $darkness = "\x00" x ($sw4 * $sh); |
1424 | |
1492 | |
1425 | for my $x (0 .. $sw - 1) { |
1493 | for my $x (0 .. $sw - 1) { |
… | |
… | |
1456 | # $lighting =~ s/(.)../$1/gs; |
1524 | # $lighting =~ s/(.)../$1/gs; |
1457 | # } |
1525 | # } |
1458 | |
1526 | |
1459 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1527 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1460 | |
1528 | |
|
|
1529 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1530 | my @conv = ( |
|
|
1531 | 0.1, 0.1, 0.1, |
|
|
1532 | 0.1, 0.2, 0.1, |
|
|
1533 | 0.1, 0.1, 0.1, |
|
|
1534 | ); |
|
|
1535 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1536 | glConvolutionFilter2D GL_CONVOLUTION_2D, |
|
|
1537 | GL_ALPHA, 3, 3, GL_ALPHA, GL_FLOAT, |
|
|
1538 | pack "f*", @conv; |
|
|
1539 | glEnable GL_CONVOLUTION_2D; |
|
|
1540 | } |
|
|
1541 | |
1461 | $darkness = new CFClient::Texture |
1542 | $darkness = new CFClient::Texture |
1462 | w => $sw4, |
1543 | w => $sw4, |
1463 | h => $sh, |
1544 | h => $sh, |
1464 | data => $darkness, |
1545 | data => $darkness, |
1465 | internalformat => GL_ALPHA, |
1546 | internalformat => GL_ALPHA, |
1466 | format => GL_ALPHA; |
1547 | format => GL_ALPHA; |
1467 | |
1548 | |
1468 | glColor 0.45, 0.45, 0.45, 1; |
1549 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1469 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
1550 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
|
|
1551 | |
|
|
1552 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1470 | |
1553 | |
1471 | glDisable GL_TEXTURE_2D; |
1554 | glDisable GL_TEXTURE_2D; |
1472 | glDisable GL_BLEND; |
1555 | glDisable GL_BLEND; |
1473 | |
1556 | |
1474 | glEndList; |
1557 | glEndList; |
1475 | } |
1558 | } |
1476 | |
1559 | |
1477 | glCallList $self->{list}; |
1560 | glCallList $self->{list}; |
|
|
1561 | |
|
|
1562 | if ($FOCUS != $self) { |
|
|
1563 | glEnable GL_BLEND; |
|
|
1564 | glColor 0, 0, 1, 0.4; |
|
|
1565 | glBegin GL_QUADS; |
|
|
1566 | glVertex 0, 0; |
|
|
1567 | glVertex 0, $::HEIGHT; |
|
|
1568 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1569 | glVertex $::WIDTH, 0; |
|
|
1570 | glEnd; |
|
|
1571 | glDisable GL_BLEND; |
|
|
1572 | } |
1478 | } |
1573 | } |
1479 | |
1574 | |
1480 | my %DIR = ( |
1575 | my %DIR = ( |
1481 | SDLK_KP8, [1, "north"], |
1576 | SDLK_KP8, [1, "north"], |
1482 | SDLK_KP9, [2, "northeast"], |
1577 | SDLK_KP9, [2, "northeast"], |
… | |
… | |
1498 | |
1593 | |
1499 | my $mod = $ev->key_mod; |
1594 | my $mod = $ev->key_mod; |
1500 | my $sym = $ev->key_sym; |
1595 | my $sym = $ev->key_sym; |
1501 | |
1596 | |
1502 | if ($sym == SDLK_KP5) { |
1597 | if ($sym == SDLK_KP5) { |
1503 | $::CONN->send ("command stay fire"); |
1598 | $::CONN->user_send ("command stay fire"); |
1504 | } elsif ($sym == SDLK_a) { |
1599 | } elsif ($sym == SDLK_a) { |
1505 | $::CONN->send ("command apply"); |
1600 | $::CONN->user_send ("command apply"); |
1506 | } elsif (exists $DIR{$sym}) { |
1601 | } elsif (exists $DIR{$sym}) { |
1507 | if ($mod & KMOD_SHIFT) { |
1602 | if ($mod & KMOD_SHIFT) { |
1508 | $self->{shft}++; |
1603 | $self->{shft}++; |
1509 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1604 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1510 | } elsif ($mod & KMOD_CTRL) { |
1605 | } elsif ($mod & KMOD_CTRL) { |
1511 | $self->{ctrl}++; |
1606 | $self->{ctrl}++; |
1512 | $::CONN->send ("command run $DIR{$sym}[0]"); |
1607 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
1513 | } else { |
1608 | } else { |
1514 | $::CONN->send ("command $DIR{$sym}[1]"); |
1609 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
1515 | } |
1610 | } |
1516 | } |
1611 | } |
1517 | } |
1612 | } |
1518 | |
1613 | |
1519 | sub key_up { |
1614 | sub key_up { |
… | |
… | |
1521 | |
1616 | |
1522 | my $mod = $ev->key_mod; |
1617 | my $mod = $ev->key_mod; |
1523 | my $sym = $ev->key_sym; |
1618 | my $sym = $ev->key_sym; |
1524 | |
1619 | |
1525 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1620 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1526 | $::CONN->send ("command fire_stop"); |
1621 | $::CONN->user_send ("command fire_stop"); |
1527 | } |
1622 | } |
1528 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1623 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1529 | $::CONN->send ("command run_stop"); |
1624 | $::CONN->user_send ("command run_stop"); |
1530 | } |
1625 | } |
1531 | } |
1626 | } |
1532 | |
1627 | |
1533 | ############################################################################# |
1628 | ############################################################################# |
1534 | |
1629 | |