… | |
… | |
1227 | our @ISA = CFClient::UI::DrawBG::; |
1227 | our @ISA = CFClient::UI::DrawBG::; |
1228 | |
1228 | |
1229 | use SDL; |
1229 | use SDL; |
1230 | use SDL::OpenGL; |
1230 | use SDL::OpenGL; |
1231 | |
1231 | |
1232 | my @tex = |
|
|
1233 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1234 | qw(b1_button_active.png); |
|
|
1235 | |
|
|
1236 | sub new { |
1232 | sub new { |
1237 | my $class = shift; |
1233 | my $class = shift; |
1238 | |
1234 | |
1239 | $class->SUPER::new ( |
1235 | $class->SUPER::new ( |
1240 | padding => 4, |
1236 | padding => 2, |
1241 | fg => [1, 1, 1], |
1237 | fg => [1, 1, 1], |
1242 | active_fg => [1, 1, 0], |
1238 | active_fg => [1, 1, 0], |
1243 | state => 0, |
1239 | state => 0, |
1244 | @_ |
1240 | @_ |
1245 | ) |
1241 | ) |
1246 | } |
1242 | } |
1247 | |
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 | |
1248 | sub button_down { |
1256 | sub button_down { |
1249 | my ($self, $ev, $x, $y) = @_; |
1257 | my ($self, $ev, $x, $y) = @_; |
1250 | |
1258 | |
1251 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1259 | if ($x >= $self->{padding} && $x < $self->{w} - $self->{padding} |
1252 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1260 | && $y >= $self->{padding} && $y < $self->{h} - $self->{padding}) { |
1253 | $self->{state} = !$self->{state}; |
1261 | $self->{state} = !$self->{state}; |
1254 | $self->emit ("changed"); |
1262 | $self->emit (changed => $self->{state}); |
1255 | } |
1263 | } |
1256 | } |
1264 | } |
1257 | |
1265 | |
1258 | sub _draw { |
1266 | sub _draw { |
1259 | my ($self) = @_; |
1267 | my ($self) = @_; |
1260 | |
1268 | |
1261 | local $self->{fg} = $self->{fg}; |
|
|
1262 | my $tex = $tex[0]; |
|
|
1263 | |
|
|
1264 | glEnable GL_BLEND; |
|
|
1265 | glEnable GL_TEXTURE_2D; |
|
|
1266 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
|
|
1267 | |
|
|
1268 | if ($GRAB == $self) { |
|
|
1269 | $self->{fg} = $self->{active_fg}; |
|
|
1270 | } |
|
|
1271 | |
|
|
1272 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
1273 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1274 | |
|
|
1275 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
|
|
1276 | |
|
|
1277 | glDisable GL_TEXTURE_2D; |
|
|
1278 | glDisable GL_BLEND; |
|
|
1279 | |
|
|
1280 | $self->SUPER::_draw; |
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 | } |
1281 | } |
1292 | } |
1282 | |
1293 | |
1283 | ############################################################################# |
1294 | ############################################################################# |
1284 | |
1295 | |
1285 | package CFClient::UI::Slider; |
1296 | package CFClient::UI::Slider; |
… | |
… | |
1443 | } |
1454 | } |
1444 | |
1455 | |
1445 | sub draw { |
1456 | sub draw { |
1446 | my ($self) = @_; |
1457 | my ($self) = @_; |
1447 | |
1458 | |
|
|
1459 | $self->{need_update}++;#d# |
1448 | if (delete $self->{need_update}) { |
1460 | if (delete $self->{need_update}) { |
1449 | glNewList $self->{list}, GL_COMPILE; |
1461 | glNewList $self->{list}, GL_COMPILE; |
|
|
1462 | |
|
|
1463 | my $sw = int $::WIDTH / 32; |
|
|
1464 | my $sh = int $::HEIGHT / 32; |
|
|
1465 | |
|
|
1466 | $::MAP->draw (0, 0, $sw, $sh) if $::MAP; |
|
|
1467 | |
|
|
1468 | if (0) { |
1450 | |
1469 | |
1451 | my $mx = $::CONN->{mapx}; |
1470 | my $mx = $::CONN->{mapx}; |
1452 | my $my = $::CONN->{mapy}; |
1471 | my $my = $::CONN->{mapy}; |
1453 | |
1472 | |
1454 | my $map = $::CONN->{map}; |
1473 | my $map = $::CONN->{map}; |
… | |
… | |
1472 | |
1491 | |
1473 | glEnable GL_TEXTURE_2D; |
1492 | glEnable GL_TEXTURE_2D; |
1474 | glEnable GL_BLEND; |
1493 | glEnable GL_BLEND; |
1475 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1494 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1476 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1495 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1496 | glColor 1, 1, 1, 1; |
1477 | |
1497 | |
1478 | my $sw4 = ($sw + 3) & ~3; |
1498 | my $sw4 = ($sw + 3) & ~3; |
1479 | my $darkness = "\x00" x ($sw4 * $sh); |
1499 | my $darkness = "\x00" x ($sw4 * $sh); |
1480 | |
1500 | |
1481 | for my $x (0 .. $sw - 1) { |
1501 | for my $x (0 .. $sw - 1) { |
… | |
… | |
1500 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1520 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1501 | } |
1521 | } |
1502 | } |
1522 | } |
1503 | } |
1523 | } |
1504 | |
1524 | |
1505 | # if (1) { # higher quality darkness |
|
|
1506 | # $lighting =~ s/(.)/$1$1$1/gs; |
|
|
1507 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
|
|
1508 | # |
|
|
1509 | # $pb = $pb->scale_simple ($sw4 * 0.5, $sh * 0.5, "bilinear"); |
|
|
1510 | # |
|
|
1511 | # $lighting = $pb->get_pixels; |
|
|
1512 | # $lighting =~ s/(.)../$1/gs; |
|
|
1513 | # } |
|
|
1514 | |
|
|
1515 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1525 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1526 | |
|
|
1527 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
|
|
1528 | my @conv = ( |
|
|
1529 | 0.1, 0.1, 0.1, |
|
|
1530 | 0.1, 0.2, 0.1, |
|
|
1531 | 0.1, 0.1, 0.1, |
|
|
1532 | ); |
|
|
1533 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
|
|
1534 | glConvolutionFilter2D GL_CONVOLUTION_2D, |
|
|
1535 | GL_ALPHA, 3, 3, GL_ALPHA, GL_FLOAT, |
|
|
1536 | pack "f*", @conv; |
|
|
1537 | glEnable GL_CONVOLUTION_2D; |
|
|
1538 | } |
1516 | |
1539 | |
1517 | $darkness = new CFClient::Texture |
1540 | $darkness = new CFClient::Texture |
1518 | w => $sw4, |
1541 | w => $sw4, |
1519 | h => $sh, |
1542 | h => $sh, |
1520 | data => $darkness, |
1543 | data => $darkness, |
1521 | internalformat => GL_ALPHA, |
1544 | internalformat => GL_ALPHA, |
1522 | format => GL_ALPHA; |
1545 | format => GL_ALPHA; |
1523 | |
1546 | |
1524 | glColor 0.45, 0.45, 0.45, 1; |
1547 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1525 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
1548 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
|
|
1549 | |
|
|
1550 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1526 | |
1551 | |
1527 | glDisable GL_TEXTURE_2D; |
1552 | glDisable GL_TEXTURE_2D; |
1528 | glDisable GL_BLEND; |
1553 | glDisable GL_BLEND; |
|
|
1554 | } |
1529 | |
1555 | |
1530 | glEndList; |
1556 | glEndList; |
1531 | } |
1557 | } |
1532 | |
1558 | |
1533 | glCallList $self->{list}; |
1559 | glCallList $self->{list}; |
|
|
1560 | |
|
|
1561 | if ($FOCUS != $self) { |
|
|
1562 | glEnable GL_BLEND; |
|
|
1563 | glColor 0, 0, 1, 0.4; |
|
|
1564 | glBegin GL_QUADS; |
|
|
1565 | glVertex 0, 0; |
|
|
1566 | glVertex 0, $::HEIGHT; |
|
|
1567 | glVertex $::WIDTH, $::HEIGHT; |
|
|
1568 | glVertex $::WIDTH, 0; |
|
|
1569 | glEnd; |
|
|
1570 | glDisable GL_BLEND; |
|
|
1571 | } |
1534 | } |
1572 | } |
1535 | |
1573 | |
1536 | my %DIR = ( |
1574 | my %DIR = ( |
1537 | SDLK_KP8, [1, "north"], |
1575 | SDLK_KP8, [1, "north"], |
1538 | SDLK_KP9, [2, "northeast"], |
1576 | SDLK_KP9, [2, "northeast"], |
… | |
… | |
1554 | |
1592 | |
1555 | my $mod = $ev->key_mod; |
1593 | my $mod = $ev->key_mod; |
1556 | my $sym = $ev->key_sym; |
1594 | my $sym = $ev->key_sym; |
1557 | |
1595 | |
1558 | if ($sym == SDLK_KP5) { |
1596 | if ($sym == SDLK_KP5) { |
1559 | $::CONN->send ("command stay fire"); |
1597 | $::CONN->user_send ("command stay fire"); |
1560 | } elsif ($sym == SDLK_a) { |
1598 | } elsif ($sym == SDLK_a) { |
1561 | $::CONN->send ("command apply"); |
1599 | $::CONN->user_send ("command apply"); |
1562 | } elsif (exists $DIR{$sym}) { |
1600 | } elsif (exists $DIR{$sym}) { |
1563 | if ($mod & KMOD_SHIFT) { |
1601 | if ($mod & KMOD_SHIFT) { |
1564 | $self->{shft}++; |
1602 | $self->{shft}++; |
1565 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1603 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1566 | } elsif ($mod & KMOD_CTRL) { |
1604 | } elsif ($mod & KMOD_CTRL) { |
1567 | $self->{ctrl}++; |
1605 | $self->{ctrl}++; |
1568 | $::CONN->send ("command run $DIR{$sym}[0]"); |
1606 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
1569 | } else { |
1607 | } else { |
1570 | $::CONN->send ("command $DIR{$sym}[1]"); |
1608 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
1571 | } |
1609 | } |
1572 | } |
1610 | } |
1573 | } |
1611 | } |
1574 | |
1612 | |
1575 | sub key_up { |
1613 | sub key_up { |
… | |
… | |
1577 | |
1615 | |
1578 | my $mod = $ev->key_mod; |
1616 | my $mod = $ev->key_mod; |
1579 | my $sym = $ev->key_sym; |
1617 | my $sym = $ev->key_sym; |
1580 | |
1618 | |
1581 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1619 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1582 | $::CONN->send ("command fire_stop"); |
1620 | $::CONN->user_send ("command fire_stop"); |
1583 | } |
1621 | } |
1584 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1622 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1585 | $::CONN->send ("command run_stop"); |
1623 | $::CONN->user_send ("command run_stop"); |
1586 | } |
1624 | } |
1587 | } |
1625 | } |
1588 | |
1626 | |
1589 | ############################################################################# |
1627 | ############################################################################# |
1590 | |
1628 | |