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.102 by elmex, Fri Apr 14 12:17:06 2006 UTC vs.
Revision 1.112 by root, Sat Apr 15 12:29:46 2006 UTC

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}
72
73# convert position array to integers
74sub harmonize {
75 my ($vals) = @_;
76
77 my $rem = 0;
78
79 for ($vals) {
80 my $i = int $_ + $rem;
81 $rem += $_ - $i;
82 $_ = $i;
83 }
71} 84}
72 85
73############################################################################# 86#############################################################################
74 87
75package CFClient::UI::Base; 88package CFClient::UI::Base;
439} 452}
440 453
441sub render_chld { 454sub render_chld {
442 my ($self) = @_; 455 my ($self) = @_;
443 456
444 $self->{texture} = 457 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
445 CFClient::Texture->new_from_opengl ( 458 glClearColor 0, 0, 0, 1;
446 $self->{w}, $self->{h}, sub { $self->child->draw } 459 glClear GL_COLOR_BUFFER_BIT;
447 ); 460 $self->child->draw;
461 };
448} 462}
449 463
450sub size_allocate { 464sub size_allocate {
451 my ($self, $x, $y, $w, $h) = @_; 465 my ($self, $x, $y, $w, $h) = @_;
452 466
731 my $col_expand = (sum @col_expand) || 1; 745 my $col_expand = (sum @col_expand) || 1;
732 746
733 # linearly scale sizes 747 # linearly scale sizes
734 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 748 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
735 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 749 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
750
751 CFClient::UI::harmonize $ws;
752 CFClient::UI::harmonize $hs;
736 753
737 my $y; 754 my $y;
738 755
739 for my $r (0 .. $#{$self->{children}}) { 756 for my $r (0 .. $#{$self->{children}}) {
740 my $row = $self->{children}[$r] 757 my $row = $self->{children}[$r]
828 $alloc_h += ($h - $req_h) * $child->{expand} / $exp; 845 $alloc_h += ($h - $req_h) * $child->{expand} / $exp;
829 $h[$_] = $alloc_h; 846 $h[$_] = $alloc_h;
830 } 847 }
831 } 848 }
832 849
850 CFClient::UI::harmonize \@h;
851
833 my $y = 0; 852 my $y = 0;
834 for (0 .. $#$children) { 853 for (0 .. $#$children) {
835 my $child = $children->[$_]; 854 my $child = $children->[$_];
836 my $h = $h[$_]; 855 my $h = $h[$_];
837 $child->size_allocate ($y, 0, $h, $w); 856 $child->size_allocate ($y, 0, $h, $w);
882 901
883 $h[$_] += ($h - $req_h) * $child->{expand} / $exp; 902 $h[$_] += ($h - $req_h) * $child->{expand} / $exp;
884 } 903 }
885 } 904 }
886 905
906 CFClient::UI::harmonize \@h;
907
887 my $y = 0; 908 my $y = 0;
888 for (0 .. $#$children) { 909 for (0 .. $#$children) {
889 my $child = $children->[$_]; 910 my $child = $children->[$_];
890 my $h = $h[$_]; 911 my $h = $h[$_];
891 $child->size_allocate (0, $y, $w, $h); 912 $child->size_allocate (0, $y, $w, $h);
904 925
905sub new { 926sub new {
906 my ($class, %arg) = @_; 927 my ($class, %arg) = @_;
907 928
908 my $self = $class->SUPER::new ( 929 my $self = $class->SUPER::new (
909 fg => [1, 1, 1], 930 fg => [1, 1, 1],
910 height => $::FONTSIZE, 931 fontsize => $::FONTSIZE,
911 text => "", 932 text => "",
912 align => -1, 933 align => -1,
913 padding => 2, 934 padding => 2,
914 layout => new CFClient::Layout, 935 layout => new CFClient::Layout,
915 %arg 936 %arg
916 ); 937 );
917 938
918 $self->set_text ($self->{text}); 939 $self->set_text ($self->{text});
919 940
949 970
950sub size_request { 971sub size_request {
951 my ($self) = @_; 972 my ($self) = @_;
952 973
953 $self->{layout}->set_width; 974 $self->{layout}->set_width;
954 $self->{layout}->set_height ($self->{height}); 975 $self->{layout}->set_height ($self->{fontsize});
955 my ($w, $h) = $self->{layout}->size; 976 my ($w, $h) = $self->{layout}->size;
956 977
957 ( 978 (
958 $w + $self->{padding} * 2, 979 $w + $self->{padding} * 2,
959 $h + $self->{padding} * 2, 980 $h + $self->{padding} * 2,
978sub _draw { 999sub _draw {
979 my ($self) = @_; 1000 my ($self) = @_;
980 1001
981 my $tex = $self->{texture} ||= do { 1002 my $tex = $self->{texture} ||= do {
982 $self->{layout}->set_width ($self->{w}); 1003 $self->{layout}->set_width ($self->{w});
983 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); 1004 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
984 new_from_layout CFClient::Texture $self->{layout} 1005 new_from_layout CFClient::Texture $self->{layout}
985 }; 1006 };
986 1007
987 glEnable GL_BLEND; 1008 glEnable GL_BLEND;
988 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1009 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
989 glEnable GL_TEXTURE_2D; 1010 glEnable GL_TEXTURE_2D;
990 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1011 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
991 1012
992 glColor @{$self->{fg}}; 1013 glColor @{$self->{fg}};
993 1014
994 my $x = 1015 my $x =
995 $self->{align} < 0 ? $self->{padding} 1016 $self->{align} < 0 ? $self->{padding}
996 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1017 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
997 : ($self->{w} - $tex->{w}) * 0.5; 1018 : ($self->{w} - $tex->{w}) * 0.5;
998 1019
999 glTranslate int $x, int +($self->{h} - $tex->{h}) * 0.5, 0; 1020 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5);
1000 $tex->draw_quad (0, 0);
1001 1021
1002 glDisable GL_TEXTURE_2D; 1022 glDisable GL_TEXTURE_2D;
1003 glDisable GL_BLEND; 1023 glDisable GL_BLEND;
1004} 1024}
1005 1025
1033 1053
1034 $self->{last_activity} = $::NOW; 1054 $self->{last_activity} = $::NOW;
1035 1055
1036 $self->{text} = $text; 1056 $self->{text} = $text;
1037 $self->{layout}->set_width ($self->{w}); 1057 $self->{layout}->set_width ($self->{w});
1038 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); 1058 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1039 1059
1040 $text =~ s/./*/g if $self->{hidden}; 1060 $text =~ s/./*/g if $self->{hidden};
1041 1061
1042 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1062 $self->{layout}->set_markup ($self->escape_text ($text) . " ");
1043 1063
1350 range => [0, 0, 100, 10], 1370 range => [0, 0, 100, 10],
1351 req_w => 40, 1371 req_w => 40,
1352 req_h => 13, 1372 req_h => 13,
1353 vertical => 0, 1373 vertical => 0,
1354 can_hover => 1, 1374 can_hover => 1,
1375 inner_pad => 5,
1355 @_ 1376 @_
1356 ); 1377 );
1357 1378
1358 $self 1379 $self
1359} 1380}
1380 if ($GRAB == $self) { 1401 if ($GRAB == $self) {
1381 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1402 my ($value, $lo, $hi, $page) = @{$self->{range}};
1382 1403
1383 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 1404 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
1384 1405
1406 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
1407 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1408
1409 $x -= $inner_pad_px; # substract the padding
1385 $x = $x * ($hi - $lo) / $w + $lo; 1410 $x = $x * ($hi - $lo) / $inner_w + $lo;
1386 $x = $lo if $x < $lo; 1411 $x = $lo if $x < $lo;
1387 $x = $hi - $page if $x > $hi - $page; 1412 $x = $hi - $page if $x > $hi - $page;
1388 $self->{range}[0] = $x; 1413 $self->{range}[0] = $x;
1389 1414
1390 $self->emit (changed => $x); 1415 $self->emit (changed => $x);
1391 $self->update; 1416 $self->update;
1392 } 1417 }
1418}
1419
1420# the inner_* stuff is for generating a padding for the slider handle,
1421# so that the handle doesn't leave the texture. This calculation isn't 100%
1422# correct propably, but it does the job for now
1423sub _calc_inner_pad_px {
1424 my ($self, $w) = @_;
1425 ($w / 100) * $self->{inner_pad} # % to pixels
1393} 1426}
1394 1427
1395sub _draw { 1428sub _draw {
1396 my ($self) = @_; 1429 my ($self) = @_;
1397 1430
1411 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1444 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1412 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 1445 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1413 1446
1414 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1447 my ($value, $lo, $hi, $page) = @{$self->{range}};
1415 1448
1416 # the inner_* stuff is for generating a padding for the slider handle, 1449 $hi = $value + 1 if $lo == $hi;
1417 # so that the handle doesn't leave the texture. This calculation isn't 100% 1450
1418 # correct propably, but it does the job for now 1451 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
1419 my $inner_pad = 5; # 5% of width for slider bg texture border
1420 my $inner_pad_px = ($w / 100) * $inner_pad; # % to pixels
1421 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right 1452 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1422 1453
1423 $page = int $page * $inner_w / ($hi - $lo); 1454 $page = int $page * $inner_w / ($hi - $lo);
1424 $value = int +($value - $lo) * $inner_w / ($hi - $lo); 1455 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
1425 1456
1426 $w -= $page; 1457 $w -= $page;
1456 1487
1457sub new { 1488sub new {
1458 my $class = shift; 1489 my $class = shift;
1459 1490
1460 my $self = $class->SUPER::new ( 1491 my $self = $class->SUPER::new (
1492 req_w => $::WIDTH / 6,
1493 req_h => $::HEIGHT / 6,
1494 fontsize => $::FONTSIZE,
1495 @_,
1496
1497 layout => (new CFClient::Layout),
1461 par => [], 1498 par => [],
1462 @_, 1499 height => 0,
1463 children => [ 1500 children => [
1464 (new CFClient::UI::Empty expand => 1), 1501 (new CFClient::UI::Empty expand => 1),
1465 (new CFClient::UI::Slider vertical => 1), 1502 (new CFClient::UI::Slider vertical => 1),
1466 ], 1503 ],
1467 ); 1504 );
1468 1505
1506 $self->{children}[1]->connect (changed => sub {
1507 $self->update;
1508 });
1509
1469 $self 1510 $self
1511}
1512
1513sub set_fontsize {
1514 my ($self, $fontsize) = @_;
1515
1516 $self->{fontsize} = $fontsize;
1517 $self->reflow;
1518}
1519
1520sub text_height {
1521 my ($self, $text) = @_;
1522
1523 my $layout = $self->{layout};
1524
1525 $layout->set_height ($self->{fontsize});
1526 $layout->set_width ($self->{w});
1527 $layout->set_text ($text);
1528
1529 ($layout->size)[1]
1530}
1531
1532sub reflow {
1533 my ($self) = @_;
1534
1535 $self->{need_reflow}++;
1536 $self->update;
1537}
1538
1539sub size_request {
1540 my ($self) = @_;
1541
1542 ($self->{req_w}, $self->{req_h})
1543}
1544
1545sub size_allocate {
1546 my ($self, $x, $y, $w, $h) = @_;
1547
1548 $self->SUPER::size_allocate ($x, $y, $w, $h);
1549
1550 $self->{layout}->set_height ($self->{fontsize});
1551 $self->{layout}->set_width ($self->{w});
1552
1553 $self->reflow;
1470} 1554}
1471 1555
1472sub add_paragraph { 1556sub add_paragraph {
1473 my ($self, $color, $text) = @_; 1557 my ($self, $color, $text) = @_;
1474 1558
1559 #TODO: intelligently "reformat" paragraph
1560
1561 my $height = $self->text_height ($text);
1562
1563 $self->{height} += $height;
1564
1475 push @{$self->{par}}, [$color, $text]; 1565 push @{$self->{par}}, [$height, $color, $text];
1476 my $count = scalar @{$self->{par}}; 1566
1477 $self->{children}[1]{range} = [$count - 1, 0, $count, 1]; 1567 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
1478 $self->{children}[1]->update; 1568 $self->{children}[1]->update;
1479} 1569}
1480 1570
1571sub update {
1572 my ($self) = @_;
1573
1574 $self->SUPER::update;
1575
1576 return unless $self->{h} > 0;
1577
1578 delete $self->{texture};
1579
1580 $TOPLEVEL->on_refresh ($self, sub {
1581 if (delete $self->{need_reflow}) {
1582 my $height = 0;
1583
1584 $height += $_->[0] = $self->text_height ($_->[2])
1585 for @{$self->{par}};
1586
1587 $self->{height} = $height;
1588
1589 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
1590
1591 delete $self->{texture};
1592 }
1593
1594 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
1595 glClearColor 0, 0, 0, 1;
1596 glClear GL_COLOR_BUFFER_BIT;
1597
1598 glEnable GL_BLEND;
1599 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1600 glEnable GL_TEXTURE_2D;
1601 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1602
1603 my $top = int $self->{children}[1]{range}[0];
1604
1605 my $y0 = $top;
1606 my $y1 = $top + $self->{h};
1607
1608 my $y = 0;
1609
1610 my $layout = $self->{layout};
1611
1612 for my $par (@{$self->{par}}) {
1613 my $h = $par->[0];
1614
1615 if ($y0 < $y + $h && $y < $y1) {
1616 $layout->set_text ($par->[2]);
1617
1618 glColor @{ $par->[1] };
1619 my ($W, $H) = $layout->size;
1620 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0);
1621 }
1622
1623 $y += $h;
1624 }
1625
1626 glDisable GL_TEXTURE_2D;
1627 glDisable GL_BLEND;
1628 };
1629 });
1630}
1631
1481sub _draw { 1632sub _draw {
1482 my ($self) = @_; 1633 my ($self) = @_;
1483 1634
1484 my $par = $self->{par}; 1635 if ($self->{texture}) {
1485
1486 my $bottom = (scalar @$par) - 1;
1487
1488 my $w = $self->{children}[0]{w};
1489 my $y = $self->{h};
1490
1491 glEnable GL_BLEND;
1492 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1493 glEnable GL_TEXTURE_2D; 1636 glEnable GL_TEXTURE_2D;
1494 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1637 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1495 1638 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
1496 # TODO: everything!
1497 while ($y > 0 && $bottom >= 0) {
1498 my $par = $par->[$bottom--];
1499
1500 my $layout = new CFClient::Layout;
1501
1502 $layout->set_height ($::FONTSIZE);
1503 $layout->set_width ($w);
1504 $layout->set_text ($par->[1]);
1505 my $tex = new_from_layout CFClient::Texture $layout;
1506 $y -= $tex->{h};
1507
1508 glColor @{ $par->[0] };
1509 $tex->draw_quad (0, $y);
1510 }
1511
1512 glDisable GL_TEXTURE_2D; 1639 glDisable GL_TEXTURE_2D;
1513 glDisable GL_BLEND; 1640 }
1641
1642 $self->{children}[1]->draw;
1643
1514} 1644}
1515 1645
1516############################################################################# 1646#############################################################################
1517 1647
1518package CFClient::UI::MapWidget; 1648package CFClient::UI::MapWidget;
1542} 1672}
1543 1673
1544sub key_up { 1674sub key_up {
1545} 1675}
1546 1676
1677sub button_down {
1678 my ($self, $ev, $x, $y) = @_;
1679
1680 $self->focus_in;
1681
1682 if ($ev->button == 2) {
1683 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
1684 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
1685
1686 $self->{motion} = sub {
1687 my ($ev, $x, $y) = @_;
1688
1689 ($x, $y) = ($ev->motion_x, $ev->motion_y);
1690
1691 $::CFG->{map_shift_x} = $bw + $x - $ox;
1692 $::CFG->{map_shift_y} = $bh + $y - $oy;
1693
1694 $self->update;
1695 };
1696 }
1697}
1698
1699sub button_up {
1700 my ($self, $ev, $x, $y) = @_;
1701
1702 delete $self->{motion};
1703}
1704
1705sub mouse_motion {
1706 my ($self, $ev, $x, $y) = @_;
1707
1708 $self->{motion}->($ev, $x, $y) if $self->{motion};
1709}
1710
1547sub size_request { 1711sub size_request {
1548 ( 1712 (
1549 1 + 32 * int $::WIDTH / 32, 1713 1 + 32 * int $::WIDTH / 32,
1550 1 + 32 * int $::HEIGHT / 32, 1714 1 + 32 * int $::HEIGHT / 32,
1551 ) 1715 )
1559} 1723}
1560 1724
1561sub draw { 1725sub draw {
1562 my ($self) = @_; 1726 my ($self) = @_;
1563 1727
1564 $self->{need_update}++;#d#
1565 if (delete $self->{need_update}) { 1728 if (delete $self->{need_update}) {
1566 glNewList $self->{list}, GL_COMPILE; 1729 glNewList $self->{list}, GL_COMPILE;
1567 1730
1568 my $sw = int $::WIDTH / 32;
1569 my $sh = int $::HEIGHT / 32;
1570
1571 if ($::MAP) { 1731 if ($::MAP) {
1732 my $sw = int $::WIDTH / 32;
1733 my $sh = int $::HEIGHT / 32;
1734
1735 my $sx = $::CFG->{map_shift_x}; my $sx0 = $sx & 31; $sx = ($sx - $sx0) / 32;
1736 my $sy = $::CFG->{map_shift_y}; my $sy0 = $sy & 31; $sy = ($sy - $sy0) / 32;
1737
1738 glTranslate $sx0 - 32, $sy0 - 32, 0;
1739
1572 my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh); 1740 my ($w, $h, $data) = $::MAP->draw ($sx, $sy, 0, 0, $sw + 1, $sh + 1);
1573 1741
1574 if ($::CFG->{fow_enable}) { 1742 if ($::CFG->{fow_enable}) {
1575 if ($::CFG->{fow_smooth}) { # smooth fog of war 1743 if ($::CFG->{fow_smooth}) { # smooth fog of war
1576 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; 1744 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1577 glConvolutionFilter2D 1745 glConvolutionFilter2D
1595 format => GL_ALPHA; 1763 format => GL_ALPHA;
1596 1764
1597 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; 1765 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
1598 1766
1599 glEnable GL_BLEND; 1767 glEnable GL_BLEND;
1768 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1600 glEnable GL_TEXTURE_2D; 1769 glEnable GL_TEXTURE_2D;
1601 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1770 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1602 1771
1603 glColor +($::CFG->{fow_intensity}) x 3, 1; 1772 glColor +($::CFG->{fow_intensity}) x 3, 1;
1604 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1773 $tex->draw_quad (0, 0, $w * 32, $h * 32);
1605 1774
1606 glDisable GL_TEXTURE_2D; 1775 glDisable GL_TEXTURE_2D;
1607 glDisable GL_BLEND; 1776 glDisable GL_BLEND;
1608 } 1777 }
1778
1779 # HACK BEGIN
1780 {
1781 glTranslate -($sx0 - 32), -($sy0 - 32), 0;#remove
1782 my ($w, $h) = (250, 250);
1783
1784 glEnable GL_BLEND;
1785 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1786 glEnable GL_TEXTURE_2D;
1787 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1788
1789 CFClient::Texture->new (
1790 w => $w,
1791 h => $h,
1792 data => $::MAP->mapmap ($w, $h),
1793 type => GL_UNSIGNED_INT_8_8_8_8_REV
1794 )->draw_quad (100, 100);
1795
1796 glDisable GL_TEXTURE_2D;
1797 glDisable GL_BLEND;
1798 }
1799 # HACK END
1609 } 1800 }
1610 1801
1611 glEndList; 1802 glEndList;
1612 } 1803 }
1613 1804
1805 glPushMatrix;
1614 glCallList $self->{list}; 1806 glCallList $self->{list};
1807 glPopMatrix;
1615 1808
1616 if ($FOCUS != $self) { 1809 if ($FOCUS != $self) {
1617 glColor 64/255, 64/255, 64/255; 1810 glColor 64/255, 64/255, 64/255;
1618 glLogicOp GL_AND; 1811 glLogicOp GL_AND;
1619 glEnable GL_COLOR_LOGIC_OP; 1812 glEnable GL_COLOR_LOGIC_OP;
1653 $::CONN->user_send ("command stay fire"); 1846 $::CONN->user_send ("command stay fire");
1654 } elsif ($sym == SDLK_a) { 1847 } elsif ($sym == SDLK_a) {
1655 $::CONN->user_send ("command apply"); 1848 $::CONN->user_send ("command apply");
1656 } elsif ($sym == SDLK_QUOTE) { 1849 } elsif ($sym == SDLK_QUOTE) {
1657 $self->emit ('activate_console'); 1850 $self->emit ('activate_console');
1851 } elsif ($sym == SDLK_SLASH) {
1852 $self->emit ('activate_console' => '/');
1658 } elsif (exists $DIR{$sym}) { 1853 } elsif (exists $DIR{$sym}) {
1659 if ($mod & KMOD_SHIFT) { 1854 if ($mod & KMOD_SHIFT) {
1660 $self->{shft}++; 1855 $self->{shft}++;
1661 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 1856 $::CONN->user_send ("command fire $DIR{$sym}[0]");
1662 } elsif ($mod & KMOD_CTRL) { 1857 } elsif ($mod & KMOD_CTRL) {
1766 1961
1767package CFClient::UI::Toplevel; 1962package CFClient::UI::Toplevel;
1768 1963
1769our @ISA = CFClient::UI::Container::; 1964our @ISA = CFClient::UI::Container::;
1770 1965
1966use SDL::OpenGL;
1967
1771sub size_request { 1968sub size_request {
1772 ($::WIDTH, $::HEIGHT) 1969 ($::WIDTH, $::HEIGHT)
1773} 1970}
1774 1971
1775sub size_allocate { 1972sub size_allocate {
1800 $self->SUPER::add ($widget); 1997 $self->SUPER::add ($widget);
1801 1998
1802 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 1999 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
1803} 2000}
1804 2001
2002sub on_refresh {
2003 my ($self, $id, $cb) = @_;
2004
2005 $self->{refresh_hook}{$id} = $cb;
2006}
2007
1805sub draw { 2008sub draw {
1806 my ($self) = @_; 2009 my ($self) = @_;
1807 2010
2011 while (my $rcb = delete $self->{refresh_hook}) {
2012 $_->() for values %$rcb;
2013 }
2014
2015 glViewport 0, 0, $::WIDTH, $::HEIGHT;
2016 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
2017 glClear GL_COLOR_BUFFER_BIT;
2018
2019 glMatrixMode GL_PROJECTION;
2020 glLoadIdentity;
2021 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000;
2022 glMatrixMode GL_MODELVIEW;
2023 glLoadIdentity;
2024
1808 $self->_draw; 2025 $self->_draw;
1809} 2026}
1810 2027
1811############################################################################# 2028#############################################################################
1812 2029

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines