ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.85 by elmex, Wed Apr 12 12:55:56 2006 UTC vs.
Revision 1.95 by root, Thu Apr 13 23:31:43 2006 UTC

801} 801}
802 802
803sub size_allocate { 803sub 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
863sub size_allocate { 861sub 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
1225package CFClient::UI::CheckBox;
1226
1227our @ISA = CFClient::UI::DrawBG::;
1228
1229use SDL;
1230use SDL::OpenGL;
1231
1232sub 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
1244sub size_request {
1245 my ($self) = @_;
1246
1247 ($self->{padding} * 2 + 6) x 2
1248}
1249
1250sub size_allocate {
1251 my ($self, $x, $y, $w, $h) = @_;
1252
1253 $self->_size_allocate ($x, $y, $w, $h);
1254}
1255
1256sub 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
1266sub _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
1229package CFClient::UI::Slider; 1296package CFClient::UI::Slider;
1230 1297
1231use strict; 1298use strict;
1232 1299
1233use SDL::OpenGL; 1300use SDL::OpenGL;
1387} 1454}
1388 1455
1389sub draw { 1456sub draw {
1390 my ($self) = @_; 1457 my ($self) = @_;
1391 1458
1459 $self->{need_update}++;#d#
1392 if (delete $self->{need_update}) { 1460 if (delete $self->{need_update}) {
1393 glNewList $self->{list}, GL_COMPILE; 1461 glNewList $self->{list}, GL_COMPILE;
1394 1462
1395 my $mx = $::CONN->{mapx};
1396 my $my = $::CONN->{mapy};
1397
1398 my $map = $::CONN->{map};
1399
1400 my ($xofs, $yofs);
1401
1402 my $sw = 1 + int $::WIDTH / 32; 1463 my $sw = int $::WIDTH / 32;
1403 my $sh = 1 + int $::HEIGHT / 32; 1464 my $sh = int $::HEIGHT / 32;
1404 1465
1405 if ($::CONN->{mapw} > $sw) { 1466 if ($::MAP) {
1406 $xofs = $mx + ($::CONN->{mapw} - $sw) * 0.5; 1467 my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh);
1407 } else {
1408 $xofs = $self->{xofs} = min $mx, max $mx + $::CONN->{mapw} - $sw + 1, $self->{xofs};
1409 }
1410 1468
1411 if ($::CONN->{maph} > $sh) { 1469 if ($::CFG->{fow_enable}) {
1412 $yofs = $my + ($::CONN->{maph} - $sh) * 0.5; 1470 if ($::CFG->{fow_smooth}) { # smooth fog of war
1413 } else { 1471 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1414 $yofs = $self->{yofs} = min $my, max $my + $::CONN->{maph} - $sh + 1, $self->{yofs}; 1472 glConvolutionFilter2D
1415 } 1473 GL_CONVOLUTION_2D,
1416 1474 GL_ALPHA,
1417 glEnable GL_TEXTURE_2D; 1475 3, 3,
1418 glEnable GL_BLEND; 1476 GL_ALPHA, GL_FLOAT,
1419 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1477 pack "f*",
1420 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1478 0.1, 0.1, 0.1,
1421 1479 0.1, 0.2, 0.1,
1422 my $sw4 = ($sw + 3) & ~3; 1480 0.1, 0.1, 0.1,
1423 my $darkness = "\x00" x ($sw4 * $sh);
1424
1425 for my $x (0 .. $sw - 1) {
1426 my $row = $map->[$x + $xofs];
1427 for my $y (0 .. $sh - 1) {
1428
1429 my $cell = $row->[$y + $yofs]
1430 or next; 1481 ;
1431 1482 glEnable GL_CONVOLUTION_2D;
1432 my $dark = $cell->[0];
1433 if ($dark < 0) {
1434 substr $darkness, $y * $sw4 + $x, 1, chr 224;
1435 } else {
1436 substr $darkness, $y * $sw4 + $x, 1, chr 255 - $dark;
1437 } 1483 }
1438 1484
1439 for my $num (grep $_, @$cell[1,2,3]) { 1485 my $tex = new CFClient::Texture
1440 my $tex = $::CONN->{face}[$num]{texture} || next; 1486 w => $w,
1441 1487 h => $h,
1442 my ($w, $h) = @$tex{qw(w h)}; 1488 data => $data,
1489 internalformat => GL_ALPHA,
1490 format => GL_ALPHA;
1443 1491
1444 $tex->draw_quad (($x + 1) * 32 - $w, ($y + 1) * 32 - $h, $w, $h); 1492 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
1445 } 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;
1446 } 1503 }
1447 } 1504 }
1448 1505
1449# if (1) { # higher quality darkness 1506 glEndList;
1450# $lighting =~ s/(.)/$1$1$1/gs;
1451# my $pb = new_from_data Gtk2::Gdk::Pixbuf $lighting, "rgb", 0, 8, $sw4, $sh, $sw4 * 3;
1452#
1453# $pb = $pb->scale_simple ($sw4 * 0.5, $sh * 0.5, "bilinear");
1454#
1455# $lighting = $pb->get_pixels;
1456# $lighting =~ s/(.)../$1/gs;
1457# } 1507 }
1458 1508
1459 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1509 glCallList $self->{list};
1460 1510
1461 $darkness = new CFClient::Texture 1511 if ($FOCUS != $self) {
1462 w => $sw4, 1512 glEnable GL_BLEND;
1463 h => $sh, 1513 glColor 0, 0, 1, 0.4;
1464 data => $darkness, 1514 glBegin GL_QUADS;
1465 internalformat => GL_ALPHA, 1515 glVertex 0, 0;
1466 format => GL_ALPHA; 1516 glVertex 0, $::HEIGHT;
1467 1517 glVertex $::WIDTH, $::HEIGHT;
1468 glColor 0.45, 0.45, 0.45, 1; 1518 glVertex $::WIDTH, 0;
1469 $darkness->draw_quad (0, 0, $sw4 * 32, $sh * 32); 1519 glEnd;
1470
1471 glDisable GL_TEXTURE_2D;
1472 glDisable GL_BLEND; 1520 glDisable GL_BLEND;
1473
1474 glEndList;
1475 } 1521 }
1476
1477 glCallList $self->{list};
1478} 1522}
1479 1523
1480my %DIR = ( 1524my %DIR = (
1481 SDLK_KP8, [1, "north"], 1525 SDLK_KP8, [1, "north"],
1482 SDLK_KP9, [2, "northeast"], 1526 SDLK_KP9, [2, "northeast"],
1498 1542
1499 my $mod = $ev->key_mod; 1543 my $mod = $ev->key_mod;
1500 my $sym = $ev->key_sym; 1544 my $sym = $ev->key_sym;
1501 1545
1502 if ($sym == SDLK_KP5) { 1546 if ($sym == SDLK_KP5) {
1503 $::CONN->send ("command stay fire"); 1547 $::CONN->user_send ("command stay fire");
1504 } elsif ($sym == SDLK_a) { 1548 } elsif ($sym == SDLK_a) {
1505 $::CONN->send ("command apply"); 1549 $::CONN->user_send ("command apply");
1506 } elsif (exists $DIR{$sym}) { 1550 } elsif (exists $DIR{$sym}) {
1507 if ($mod & KMOD_SHIFT) { 1551 if ($mod & KMOD_SHIFT) {
1508 $self->{shft}++; 1552 $self->{shft}++;
1509 $::CONN->send ("command fire $DIR{$sym}[0]"); 1553 $::CONN->user_send ("command fire $DIR{$sym}[0]");
1510 } elsif ($mod & KMOD_CTRL) { 1554 } elsif ($mod & KMOD_CTRL) {
1511 $self->{ctrl}++; 1555 $self->{ctrl}++;
1512 $::CONN->send ("command run $DIR{$sym}[0]"); 1556 $::CONN->user_send ("command run $DIR{$sym}[0]");
1513 } else { 1557 } else {
1514 $::CONN->send ("command $DIR{$sym}[1]"); 1558 $::CONN->user_send ("command $DIR{$sym}[1]");
1515 } 1559 }
1516 } 1560 }
1517} 1561}
1518 1562
1519sub key_up { 1563sub key_up {
1521 1565
1522 my $mod = $ev->key_mod; 1566 my $mod = $ev->key_mod;
1523 my $sym = $ev->key_sym; 1567 my $sym = $ev->key_sym;
1524 1568
1525 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) { 1569 if (!($mod & KMOD_SHIFT) && delete $self->{shft}) {
1526 $::CONN->send ("command fire_stop"); 1570 $::CONN->user_send ("command fire_stop");
1527 } 1571 }
1528 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) { 1572 if (!($mod & KMOD_CTRL ) && delete $self->{ctrl}) {
1529 $::CONN->send ("command run_stop"); 1573 $::CONN->user_send ("command run_stop");
1530 } 1574 }
1531} 1575}
1532 1576
1533############################################################################# 1577#############################################################################
1534 1578

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines