… | |
… | |
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 | |
… | |
… | |
997 | my $x = |
993 | my $x = |
998 | $self->{align} < 0 ? $self->{padding} |
994 | $self->{align} < 0 ? $self->{padding} |
999 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
995 | : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} |
1000 | : ($self->{w} - $tex->{w}) * 0.5; |
996 | : ($self->{w} - $tex->{w}) * 0.5; |
1001 | |
997 | |
1002 | glTranslate $x, $self->{padding}, 0; |
998 | glTranslate $x, ($self->{h} - $tex->{h}) * 0.5, 0; |
1003 | $tex->draw_quad (0, 0); |
999 | $tex->draw_quad (0, 0); |
1004 | |
1000 | |
1005 | glDisable GL_TEXTURE_2D; |
1001 | glDisable GL_TEXTURE_2D; |
1006 | glDisable GL_BLEND; |
1002 | glDisable GL_BLEND; |
1007 | } |
1003 | } |
… | |
… | |
1170 | our @ISA = CFClient::UI::Label::; |
1166 | our @ISA = CFClient::UI::Label::; |
1171 | |
1167 | |
1172 | use SDL; |
1168 | use SDL; |
1173 | use SDL::OpenGL; |
1169 | use SDL::OpenGL; |
1174 | |
1170 | |
|
|
1171 | my @tex = |
|
|
1172 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } |
|
|
1173 | qw(b1_button_active.png); |
|
|
1174 | |
1175 | sub new { |
1175 | sub new { |
1176 | my $class = shift; |
1176 | my $class = shift; |
1177 | |
1177 | |
1178 | $class->SUPER::new ( |
1178 | $class->SUPER::new ( |
1179 | padding => 4, |
1179 | padding => 4, |
1180 | fg => [1, 1, 1], |
1180 | fg => [1, 1, 1], |
1181 | bg => [1, 1, 1, 0.2], |
1181 | bg => [1, 1, 1, 0.2], |
1182 | active_bg => [0, 0, 0, 0.5], |
|
|
1183 | active_fg => [1, 1, 0], |
1182 | active_fg => [1, 1, 0], |
|
|
1183 | # active_bg => [0, 0, 0, 0.5], |
1184 | border_fg => [1, 1, 0], |
1184 | # border_fg => [1, 1, 0], |
1185 | @_ |
1185 | @_ |
1186 | ) |
1186 | ) |
1187 | } |
1187 | } |
1188 | |
1188 | |
1189 | sub button_up { |
1189 | sub button_up { |
… | |
… | |
1197 | |
1197 | |
1198 | sub _draw { |
1198 | sub _draw { |
1199 | my ($self) = @_; |
1199 | my ($self) = @_; |
1200 | |
1200 | |
1201 | local $self->{fg} = $self->{fg}; |
1201 | local $self->{fg} = $self->{fg}; |
|
|
1202 | my $tex = $tex[0]; |
1202 | |
1203 | |
1203 | glEnable GL_BLEND; |
1204 | glEnable GL_BLEND; |
|
|
1205 | glEnable GL_TEXTURE_2D; |
1204 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1206 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1205 | |
1207 | |
1206 | glTranslate 0.375, 0.375, 0; # make line and polyogon coordinates behave similarly |
1208 | if ($GRAB == $self) { |
|
|
1209 | $self->{fg} = $self->{active_fg}; |
|
|
1210 | } |
|
|
1211 | |
|
|
1212 | glBindTexture GL_TEXTURE_2D, $tex->{name}; |
|
|
1213 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
1214 | |
|
|
1215 | $tex->draw_quad (0, 0, $self->{w}, $self->{h}); |
|
|
1216 | |
|
|
1217 | glDisable GL_TEXTURE_2D; |
|
|
1218 | glDisable GL_BLEND; |
|
|
1219 | |
|
|
1220 | $self->SUPER::_draw; |
|
|
1221 | } |
|
|
1222 | |
|
|
1223 | ############################################################################# |
|
|
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} }; |
1207 | |
1276 | |
1208 | glBegin GL_LINE_LOOP; |
1277 | glBegin GL_LINE_LOOP; |
1209 | glColor @{$self->{border_fg}}; |
1278 | glVertex 0 , 0; |
1210 | glVertex 1 , 1; |
1279 | glVertex 0 , $s; |
1211 | glVertex 1 , $self->{h} - 2; |
1280 | glVertex $s, $s; |
1212 | glVertex $self->{w} - 2, $self->{h} - 2; |
1281 | glVertex $s, 0; |
1213 | glVertex $self->{w} - 2, 1; |
|
|
1214 | glEnd; |
1282 | glEnd; |
1215 | |
|
|
1216 | if ($GRAB == $self) { |
|
|
1217 | glColor @{$self->{active_bg}}; |
|
|
1218 | $self->{fg} = $self->{active_fg}; |
|
|
1219 | } else { |
|
|
1220 | glColor @{$self->{bg}}; |
|
|
1221 | } |
|
|
1222 | |
1283 | |
1223 | glBegin GL_QUADS; |
1284 | if ($self->{state}) { |
1224 | glVertex 2 , 2; |
1285 | glBegin GL_LINES; |
1225 | glVertex 2 , $self->{h} - 2; |
1286 | glVertex 0 , 0; |
1226 | glVertex $self->{w} - 2, $self->{h} - 2; |
1287 | glVertex $s, $s; |
1227 | glVertex $self->{w} - 2, 2; |
1288 | glVertex $s, 0; |
|
|
1289 | glVertex 0 , $s; |
1228 | glEnd; |
1290 | glEnd; |
1229 | glDisable GL_BLEND; |
1291 | } |
1230 | |
|
|
1231 | $self->SUPER::_draw; |
|
|
1232 | } |
1292 | } |
1233 | |
1293 | |
1234 | ############################################################################# |
1294 | ############################################################################# |
1235 | |
1295 | |
1236 | package CFClient::UI::Slider; |
1296 | package CFClient::UI::Slider; |
… | |
… | |
1394 | } |
1454 | } |
1395 | |
1455 | |
1396 | sub draw { |
1456 | sub draw { |
1397 | my ($self) = @_; |
1457 | my ($self) = @_; |
1398 | |
1458 | |
|
|
1459 | $self->{need_update}++;#d# |
1399 | if (delete $self->{need_update}) { |
1460 | if (delete $self->{need_update}) { |
1400 | glNewList $self->{list}, GL_COMPILE; |
1461 | glNewList $self->{list}, GL_COMPILE; |
1401 | |
1462 | |
1402 | my $mx = $::CONN->{mapx}; |
|
|
1403 | my $my = $::CONN->{mapy}; |
|
|
1404 | |
|
|
1405 | my $map = $::CONN->{map}; |
|
|
1406 | |
|
|
1407 | my ($xofs, $yofs); |
|
|
1408 | |
|
|
1409 | my $sw = 1 + int $::WIDTH / 32; |
1463 | my $sw = int $::WIDTH / 32; |
1410 | my $sh = 1 + int $::HEIGHT / 32; |
1464 | my $sh = int $::HEIGHT / 32; |
1411 | |
1465 | |
1412 | if ($::CONN->{mapw} > $sw) { |
1466 | if ($::MAP) { |
1413 | $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; |
1467 | my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh); |
1414 | } else { |
|
|
1415 | $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs}; |
|
|
1416 | } |
|
|
1417 | |
1468 | |
1418 | if ($::CONN->{maph} > $sh) { |
1469 | if ($::CFG->{fow_enable}) { |
1419 | $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; |
1470 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
1420 | } else { |
1471 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
1421 | $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; |
1472 | glConvolutionFilter2D |
1422 | } |
1473 | GL_CONVOLUTION_2D, |
1423 | |
1474 | GL_ALPHA, |
1424 | glEnable GL_TEXTURE_2D; |
1475 | 3, 3, |
1425 | glEnable GL_BLEND; |
1476 | GL_ALPHA, GL_FLOAT, |
1426 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1477 | pack "f*", |
1427 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1478 | 0.1, 0.1, 0.1, |
1428 | |
1479 | 0.1, 0.2, 0.1, |
1429 | my $sw4 = ($sw + 3) & ~3; |
1480 | 0.1, 0.1, 0.1, |
1430 | my $darkness = "\x00" x ($sw4 * $sh); |
|
|
1431 | |
|
|
1432 | for my $x (0 .. $sw - 1) { |
|
|
1433 | my $row = $map->[$x + $xofs]; |
|
|
1434 | for my $y (0 .. $sh - 1) { |
|
|
1435 | |
|
|
1436 | my $cell = $row->[$y + $yofs] |
|
|
1437 | or next; |
1481 | ; |
1438 | |
1482 | glEnable GL_CONVOLUTION_2D; |
1439 | my $dark = $cell->[0]; |
|
|
1440 | if ($dark < 0) { |
|
|
1441 | substr $darkness, $y * $sw4 + $x, 1, chr 224; |
|
|
1442 | } else { |
|
|
1443 | substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark; |
|
|
1444 | } |
1483 | } |
1445 | |
1484 | |
1446 | for my $num (grep $_, @$cell[1,2,3]) { |
1485 | my $tex = new CFClient::Texture |
1447 | my $tex = $::CONN->{face}[$num]{texture} || next; |
1486 | w => $w, |
1448 | |
1487 | h => $h, |
1449 | my ($w, $h) = @$tex{qw(w h)}; |
1488 | data => $data, |
|
|
1489 | internalformat => GL_ALPHA, |
|
|
1490 | format => GL_ALPHA; |
1450 | |
1491 | |
1451 | $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); |
1492 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1452 | } |
1493 | |
|
|
1494 | glEnable GL_BLEND; |
|
|
1495 | glEnable GL_TEXTURE_2D; |
|
|
1496 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
|
|
1497 | |
|
|
1498 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
|
|
1499 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
|
|
1500 | |
|
|
1501 | glDisable GL_TEXTURE_2D; |
|
|
1502 | glDisable GL_BLEND; |
1453 | } |
1503 | } |
1454 | } |
1504 | } |
1455 | |
1505 | |
1456 | # if (1) { # higher quality darkness |
1506 | glEndList; |
1457 | # $lighting =~ s/(.)/$1$1$1/gs; |
|
|
1458 | # my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3; |
|
|
1459 | # |
|
|
1460 | # $pb = $pb->scale_simple ($sw4 * 0.5, $sh * 0.5, "bilinear"); |
|
|
1461 | # |
|
|
1462 | # $lighting = $pb->get_pixels; |
|
|
1463 | # $lighting =~ s/(.)../$1/gs; |
|
|
1464 | # } |
1507 | } |
1465 | |
1508 | |
1466 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1509 | glCallList $self->{list}; |
1467 | |
1510 | |
1468 | $darkness = new CFClient::Texture |
1511 | if ($FOCUS != $self) { |
1469 | w => $sw4, |
1512 | glEnable GL_BLEND; |
1470 | h => $sh, |
1513 | glColor 0, 0, 1, 0.4; |
1471 | data => $darkness, |
1514 | glBegin GL_QUADS; |
1472 | internalformat => GL_ALPHA, |
1515 | glVertex 0, 0; |
1473 | format => GL_ALPHA; |
1516 | glVertex 0, $::HEIGHT; |
1474 | |
1517 | glVertex $::WIDTH, $::HEIGHT; |
1475 | glColor 0.45, 0.45, 0.45, 1; |
1518 | glVertex $::WIDTH, 0; |
1476 | $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); |
1519 | glEnd; |
1477 | |
|
|
1478 | glDisable GL_TEXTURE_2D; |
|
|
1479 | glDisable GL_BLEND; |
1520 | glDisable GL_BLEND; |
1480 | |
|
|
1481 | glEndList; |
|
|
1482 | } |
1521 | } |
1483 | |
|
|
1484 | glCallList $self->{list}; |
|
|
1485 | } |
1522 | } |
1486 | |
1523 | |
1487 | my %DIR = ( |
1524 | my %DIR = ( |
1488 | SDLK_KP8, [1, "north"], |
1525 | SDLK_KP8, [1, "north"], |
1489 | SDLK_KP9, [2, "northeast"], |
1526 | SDLK_KP9, [2, "northeast"], |
… | |
… | |
1505 | |
1542 | |
1506 | my $mod = $ev->key_mod; |
1543 | my $mod = $ev->key_mod; |
1507 | my $sym = $ev->key_sym; |
1544 | my $sym = $ev->key_sym; |
1508 | |
1545 | |
1509 | if ($sym == SDLK_KP5) { |
1546 | if ($sym == SDLK_KP5) { |
1510 | $::CONN->send ("command stay fire"); |
1547 | $::CONN->user_send ("command stay fire"); |
|
|
1548 | } elsif ($sym == SDLK_a) { |
|
|
1549 | $::CONN->user_send ("command apply"); |
1511 | } elsif (exists $DIR{$sym}) { |
1550 | } elsif (exists $DIR{$sym}) { |
1512 | if ($mod & KMOD_SHIFT) { |
1551 | if ($mod & KMOD_SHIFT) { |
1513 | $self->{shft}++; |
1552 | $self->{shft}++; |
1514 | $::CONN->send ("command fire $DIR{$sym}[0]"); |
1553 | $::CONN->user_send ("command fire $DIR{$sym}[0]"); |
1515 | } elsif ($mod & KMOD_CTRL) { |
1554 | } elsif ($mod & KMOD_CTRL) { |
1516 | $self->{ctrl}++; |
1555 | $self->{ctrl}++; |
1517 | $::CONN->send ("command run $DIR{$sym}[0]"); |
1556 | $::CONN->user_send ("command run $DIR{$sym}[0]"); |
1518 | } else { |
1557 | } else { |
1519 | $::CONN->send ("command $DIR{$sym}[1]"); |
1558 | $::CONN->user_send ("command $DIR{$sym}[1]"); |
1520 | } |
1559 | } |
1521 | } |
1560 | } |
1522 | } |
1561 | } |
1523 | |
1562 | |
1524 | sub key_up { |
1563 | sub key_up { |
… | |
… | |
1526 | |
1565 | |
1527 | my $mod = $ev->key_mod; |
1566 | my $mod = $ev->key_mod; |
1528 | my $sym = $ev->key_sym; |
1567 | my $sym = $ev->key_sym; |
1529 | |
1568 | |
1530 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1569 | if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { |
1531 | $::CONN->send ("command fire_stop"); |
1570 | $::CONN->user_send ("command fire_stop"); |
1532 | } |
1571 | } |
1533 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1572 | if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { |
1534 | $::CONN->send ("command run_stop"); |
1573 | $::CONN->user_send ("command run_stop"); |
1535 | } |
1574 | } |
1536 | } |
1575 | } |
1537 | |
1576 | |
1538 | ############################################################################# |
1577 | ############################################################################# |
1539 | |
1578 | |