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.100 by elmex, Fri Apr 14 11:32:22 2006 UTC vs.
Revision 1.109 by root, Sat Apr 15 01:13:47 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} 71}
72 72
439} 439}
440 440
441sub render_chld { 441sub render_chld {
442 my ($self) = @_; 442 my ($self) = @_;
443 443
444 $self->{texture} = 444 $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
445 CFClient::Texture->new_from_opengl ( 445 glClearColor 0, 0, 0, 1;
446 $self->{w}, $self->{h}, sub { $self->child->draw } 446 glClear GL_COLOR_BUFFER_BIT;
447 ); 447 $self->child->draw;
448 };
448} 449}
449 450
450sub size_allocate { 451sub size_allocate {
451 my ($self, $x, $y, $w, $h) = @_; 452 my ($self, $x, $y, $w, $h) = @_;
452 453
731 my $col_expand = (sum @col_expand) || 1; 732 my $col_expand = (sum @col_expand) || 1;
732 733
733 # linearly scale sizes 734 # linearly scale sizes
734 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 735 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
735 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 736 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
737
738 $_ = int $_ for @$ws; #TODO: avoid rounding problems
739 $_ = int $_ for @$hs; #TODO: avoid rounding problems
736 740
737 my $y; 741 my $y;
738 742
739 for my $r (0 .. $#{$self->{children}}) { 743 for my $r (0 .. $#{$self->{children}}) {
740 my $row = $self->{children}[$r] 744 my $row = $self->{children}[$r]
831 } 835 }
832 836
833 my $y = 0; 837 my $y = 0;
834 for (0 .. $#$children) { 838 for (0 .. $#$children) {
835 my $child = $children->[$_]; 839 my $child = $children->[$_];
836 my $h = $h[$_]; 840 my $h = int $h[$_];
837 $child->size_allocate ($y, 0, $h, $w); 841 $child->size_allocate ($y, 0, $h, $w);
838 842
839 $y += $h; 843 $y += $h;
840 } 844 }
841} 845}
885 } 889 }
886 890
887 my $y = 0; 891 my $y = 0;
888 for (0 .. $#$children) { 892 for (0 .. $#$children) {
889 my $child = $children->[$_]; 893 my $child = $children->[$_];
890 my $h = $h[$_]; 894 my $h = int $h[$_];
891 $child->size_allocate (0, $y, $w, $h); 895 $child->size_allocate (0, $y, $w, $h);
892 896
893 $y += $h; 897 $y += $h;
894 } 898 }
895} 899}
904 908
905sub new { 909sub new {
906 my ($class, %arg) = @_; 910 my ($class, %arg) = @_;
907 911
908 my $self = $class->SUPER::new ( 912 my $self = $class->SUPER::new (
909 fg => [1, 1, 1], 913 fg => [1, 1, 1],
910 height => $::FONTSIZE, 914 fontsize => $::FONTSIZE,
911 text => "", 915 text => "",
912 align => -1, 916 align => -1,
913 padding => 2, 917 padding => 2,
914 layout => new CFClient::Layout, 918 layout => new CFClient::Layout,
915 %arg 919 %arg
916 ); 920 );
917 921
918 $self->set_text ($self->{text}); 922 $self->set_text ($self->{text});
919 923
949 953
950sub size_request { 954sub size_request {
951 my ($self) = @_; 955 my ($self) = @_;
952 956
953 $self->{layout}->set_width; 957 $self->{layout}->set_width;
954 $self->{layout}->set_height ($self->{height}); 958 $self->{layout}->set_height ($self->{fontsize});
955 my ($w, $h) = $self->{layout}->size; 959 my ($w, $h) = $self->{layout}->size;
956 960
957 ( 961 (
958 $w + $self->{padding} * 2, 962 $w + $self->{padding} * 2,
959 $h + $self->{padding} * 2, 963 $h + $self->{padding} * 2,
978sub _draw { 982sub _draw {
979 my ($self) = @_; 983 my ($self) = @_;
980 984
981 my $tex = $self->{texture} ||= do { 985 my $tex = $self->{texture} ||= do {
982 $self->{layout}->set_width ($self->{w}); 986 $self->{layout}->set_width ($self->{w});
983 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); 987 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
984 new_from_layout CFClient::Texture $self->{layout} 988 new_from_layout CFClient::Texture $self->{layout}
985 }; 989 };
986 990
987 glEnable GL_BLEND; 991 glEnable GL_BLEND;
988 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 992 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
989 glEnable GL_TEXTURE_2D; 993 glEnable GL_TEXTURE_2D;
990 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 994 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
991 995
992 glColor @{$self->{fg}}; 996 glColor @{$self->{fg}};
993 997
994 my $x = 998 my $x =
995 $self->{align} < 0 ? $self->{padding} 999 $self->{align} < 0 ? $self->{padding}
996 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding} 1000 : $self->{align} > 0 ? $self->{w} - $tex->{w} - $self->{padding}
997 : ($self->{w} - $tex->{w}) * 0.5; 1001 : ($self->{w} - $tex->{w}) * 0.5;
998 1002
999 glTranslate int $x, int +($self->{h} - $tex->{h}) * 0.5, 0; 1003 $tex->draw_quad (int $x, int +($self->{h} - $tex->{h}) * 0.5);
1000 $tex->draw_quad (0, 0);
1001 1004
1002 glDisable GL_TEXTURE_2D; 1005 glDisable GL_TEXTURE_2D;
1003 glDisable GL_BLEND; 1006 glDisable GL_BLEND;
1004} 1007}
1005 1008
1033 1036
1034 $self->{last_activity} = $::NOW; 1037 $self->{last_activity} = $::NOW;
1035 1038
1036 $self->{text} = $text; 1039 $self->{text} = $text;
1037 $self->{layout}->set_width ($self->{w}); 1040 $self->{layout}->set_width ($self->{w});
1038 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{height}); 1041 $self->{layout}->set_height (List::Util::min $self->{h} - $self->{padding} * 2, $self->{fontsize});
1039 1042
1040 $text =~ s/./*/g if $self->{hidden}; 1043 $text =~ s/./*/g if $self->{hidden};
1041 1044
1042 $self->{layout}->set_markup ($self->escape_text ($text) . " "); 1045 $self->{layout}->set_markup ($self->escape_text ($text) . " ");
1043 1046
1094 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1097 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1095 } elsif ($sym == SDLK_HOME) { 1098 } elsif ($sym == SDLK_HOME) {
1096 $self->{cursor} = 0; 1099 $self->{cursor} = 0;
1097 } elsif ($sym == SDLK_END) { 1100 } elsif ($sym == SDLK_END) {
1098 $self->{cursor} = length $text; 1101 $self->{cursor} = length $text;
1102 } elsif ($sym == SDLK_ESCAPE) {
1103 $self->emit ('escape');
1099 } elsif ($uni) { 1104 } elsif ($uni) {
1100 substr $text, $self->{cursor}++, 0, chr $uni; 1105 substr $text, $self->{cursor}++, 0, chr $uni;
1101 } 1106 }
1102 1107
1103 $self->_set_text ($text); 1108 $self->_set_text ($text);
1253 1258
1254package CFClient::UI::CheckBox; 1259package CFClient::UI::CheckBox;
1255 1260
1256our @ISA = CFClient::UI::DrawBG::; 1261our @ISA = CFClient::UI::DrawBG::;
1257 1262
1263my @tex =
1264 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ }
1265 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1266
1258use SDL; 1267use SDL;
1259use SDL::OpenGL; 1268use SDL::OpenGL;
1260 1269
1261sub new { 1270sub new {
1262 my $class = shift; 1271 my $class = shift;
1299 $self->SUPER::_draw; 1308 $self->SUPER::_draw;
1300 1309
1301 glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0; 1310 glTranslate $self->{padding} + 0.375, $self->{padding} + 0.375, 0;
1302 1311
1303 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2; 1312 my $s = (List::Util::min @$self{qw(w h)}) - $self->{padding} * 2;
1304 1313
1305 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} }; 1314 glColor @{ $FOCUS == $self ? $self->{active_fg} : $self->{fg} };
1306 1315
1307 glBegin GL_LINE_LOOP; 1316 glEnable GL_BLEND;
1308 glVertex 0 , 0; 1317 glEnable GL_TEXTURE_2D;
1309 glVertex 0 , $s; 1318 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1310 glVertex $s, $s;
1311 glVertex $s, 0;
1312 glEnd;
1313 1319
1314 if ($self->{state}) { 1320 my $tex = $self->{state} ? $tex[1] : $tex[0];
1315 glBegin GL_LINES; 1321
1316 glVertex 0 , 0; 1322 $tex->draw_quad (0, 0, $s, $s);
1317 glVertex $s, $s; 1323
1318 glVertex $s, 0; 1324 glDisable GL_TEXTURE_2D;
1319 glVertex 0 , $s; 1325 glDisable GL_BLEND;
1320 glEnd;
1321 }
1322} 1326}
1323 1327
1324############################################################################# 1328#############################################################################
1325 1329
1326package CFClient::UI::Slider; 1330package CFClient::UI::Slider;
1349 range => [0, 0, 100, 10], 1353 range => [0, 0, 100, 10],
1350 req_w => 40, 1354 req_w => 40,
1351 req_h => 13, 1355 req_h => 13,
1352 vertical => 0, 1356 vertical => 0,
1353 can_hover => 1, 1357 can_hover => 1,
1358 inner_pad => 5,
1354 @_ 1359 @_
1355 ); 1360 );
1356 1361
1357 $self 1362 $self
1358} 1363}
1379 if ($GRAB == $self) { 1384 if ($GRAB == $self) {
1380 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1385 my ($value, $lo, $hi, $page) = @{$self->{range}};
1381 1386
1382 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w}); 1387 my ($x, $w) = $self->{vertical} ? ($y, $self->{h}) : ($x, $self->{w});
1383 1388
1389 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
1390 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1391
1392 $x -= $inner_pad_px; # substract the padding
1384 $x = $x * ($hi - $lo) / $w + $lo; 1393 $x = $x * ($hi - $lo) / $inner_w + $lo;
1385 $x = $lo if $x < $lo; 1394 $x = $lo if $x < $lo;
1386 $x = $hi - $page if $x > $hi - $page; 1395 $x = $hi - $page if $x > $hi - $page;
1387 $self->{range}[0] = $x; 1396 $self->{range}[0] = $x;
1388 1397
1389 $self->emit (changed => $x); 1398 $self->emit (changed => $x);
1390 $self->update; 1399 $self->update;
1391 } 1400 }
1401}
1402
1403# the inner_* stuff is for generating a padding for the slider handle,
1404# so that the handle doesn't leave the texture. This calculation isn't 100%
1405# correct propably, but it does the job for now
1406sub _calc_inner_pad_px {
1407 my ($self, $w) = @_;
1408 ($w / 100) * $self->{inner_pad} # % to pixels
1392} 1409}
1393 1410
1394sub _draw { 1411sub _draw {
1395 my ($self) = @_; 1412 my ($self) = @_;
1396 1413
1410 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; 1427 my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg};
1411 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; 1428 my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg};
1412 1429
1413 my ($value, $lo, $hi, $page) = @{$self->{range}}; 1430 my ($value, $lo, $hi, $page) = @{$self->{range}};
1414 1431
1415 # the inner_* stuff is for generating a padding for the slider handle, 1432 $hi = $value + 1 if $lo == $hi;
1416 # so that the handle doesn't leave the texture. This calculation isn't 100% 1433
1417 # correct propably, but it does the job for now 1434 my $inner_pad_px = $self->_calc_inner_pad_px ($w);
1418 my $inner_pad = 5; # 5% of width for slider bg texture border
1419 my $inner_pad_px = ($w / 100) * $inner_pad; # % to pixels
1420 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right 1435 my $inner_w = $w - $inner_pad_px * 2; # * 2 for left & right
1421 1436
1422 $page = int $page * $inner_w / ($hi - $lo); 1437 $page = int $page * $inner_w / ($hi - $lo);
1423 $value = int +($value - $lo) * $inner_w / ($hi - $lo); 1438 $value = int +($value - $lo) * $inner_w / ($hi - $lo);
1424 1439
1425 $w -= $page; 1440 $w -= $page;
1455 1470
1456sub new { 1471sub new {
1457 my $class = shift; 1472 my $class = shift;
1458 1473
1459 my $self = $class->SUPER::new ( 1474 my $self = $class->SUPER::new (
1475 req_w => $::WIDTH / 6,
1476 req_h => $::HEIGHT / 6,
1477 fontsize => $::FONTSIZE,
1478 @_,
1479
1480 layout => (new CFClient::Layout),
1460 par => [], 1481 par => [],
1461 @_, 1482 height => 0,
1462 children => [ 1483 children => [
1463 (new CFClient::UI::Empty expand => 1), 1484 (new CFClient::UI::Empty expand => 1),
1464 (new CFClient::UI::Slider vertical => 1), 1485 (new CFClient::UI::Slider vertical => 1),
1465 ], 1486 ],
1466 ); 1487 );
1467 1488
1489 $self->{children}[1]->connect (changed => sub {
1490 $self->update;
1491 });
1492
1468 $self 1493 $self
1494}
1495
1496sub set_fontsize {
1497 my ($self, $fontsize) = @_;
1498
1499 $self->{fontsize} = $fontsize;
1500 $self->reflow;
1501}
1502
1503sub text_height {
1504 my ($self, $text) = @_;
1505
1506 my $layout = $self->{layout};
1507
1508 $layout->set_height ($self->{fontsize});
1509 $layout->set_width ($self->{w});
1510 $layout->set_text ($text);
1511
1512 ($layout->size)[1]
1513}
1514
1515sub reflow {
1516 my ($self) = @_;
1517
1518 $self->{need_reflow}++;
1519 $self->update;
1520}
1521
1522sub size_request {
1523 my ($self) = @_;
1524
1525 ($self->{req_w}, $self->{req_h})
1526}
1527
1528sub size_allocate {
1529 my ($self, $x, $y, $w, $h) = @_;
1530
1531 $self->SUPER::size_allocate ($x, $y, $w, $h);
1532
1533 $self->{layout}->set_height ($self->{fontsize});
1534 $self->{layout}->set_width ($self->{w});
1535
1536 $self->reflow;
1469} 1537}
1470 1538
1471sub add_paragraph { 1539sub add_paragraph {
1472 my ($self, $color, $text) = @_; 1540 my ($self, $color, $text) = @_;
1473 1541
1542 #TODO: intelligently "reformat" paragraph
1543
1544 my $height = $self->text_height ($text);
1545
1546 $self->{height} += $height;
1547
1474 push @{$self->{par}}, [$color, $text]; 1548 push @{$self->{par}}, [$height, $color, $text];
1475 my $count = scalar @{$self->{par}}; 1549
1476 $self->{children}[1]{range} = [$count - 1, 0, $count, 1]; 1550 $self->{children}[1]{range} = [$self->{height} - $self->{h}, 0, $self->{height}, $self->{h}];
1477 $self->{children}[1]->update; 1551 $self->{children}[1]->update;
1478} 1552}
1479 1553
1554sub update {
1555 my ($self) = @_;
1556
1557 $self->SUPER::update;
1558
1559 return unless $self->{h} > 0;
1560
1561 delete $self->{texture};
1562
1563 $TOPLEVEL->on_refresh ($self, sub {
1564 if (delete $self->{need_reflow}) {
1565 my $height = 0;
1566
1567 $height += $_->[0] = $self->text_height ($_->[2])
1568 for @{$self->{par}};
1569
1570 $self->{height} = $height;
1571
1572 $self->{children}[1]{range} = [$height - $self->{h}, 0, $height, $self->{h}];
1573
1574 delete $self->{texture};
1575 }
1576
1577 $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub {
1578 glClearColor 0, 0, 0, 1;
1579 glClear GL_COLOR_BUFFER_BIT;
1580
1581 glEnable GL_BLEND;
1582 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1583 glEnable GL_TEXTURE_2D;
1584 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1585
1586 my $top = int $self->{children}[1]{range}[0];
1587
1588 my $y0 = $top;
1589 my $y1 = $top + $self->{h};
1590
1591 my $y = 0;
1592
1593 my $layout = $self->{layout};
1594
1595 for my $par (@{$self->{par}}) {
1596 my $h = $par->[0];
1597
1598 if ($y0 < $y + $h && $y < $y1) {
1599 $layout->set_text ($par->[2]);
1600
1601 glColor @{ $par->[1] };
1602 my ($W, $H) = $layout->size;
1603 CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0);
1604 }
1605
1606 $y += $h;
1607 }
1608
1609 glDisable GL_TEXTURE_2D;
1610 glDisable GL_BLEND;
1611 };
1612 });
1613}
1614
1480sub _draw { 1615sub _draw {
1481 my ($self) = @_; 1616 my ($self) = @_;
1482 1617
1483 my $par = $self->{par}; 1618 if ($self->{texture}) {
1484
1485 my $bottom = (scalar @$par) - 1;
1486
1487 my $w = $self->{children}[0]{w};
1488 my $y = $self->{h};
1489
1490 glEnable GL_BLEND;
1491 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1492 glEnable GL_TEXTURE_2D; 1619 glEnable GL_TEXTURE_2D;
1493 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1620 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1494 1621 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
1495 # TODO: everything!
1496 while ($y > 0 && $bottom >= 0) {
1497 my $par = $par->[$bottom--];
1498
1499 my $layout = new CFClient::Layout;
1500
1501 $layout->set_height ($::FONTSIZE);
1502 $layout->set_width ($w);
1503 $layout->set_text ($par->[1]);
1504 my $tex = new_from_layout CFClient::Texture $layout;
1505 $y -= $tex->{h};
1506
1507 glColor @{ $par->[0] };
1508 $tex->draw_quad (0, $y);
1509 }
1510
1511 glDisable GL_TEXTURE_2D; 1622 glDisable GL_TEXTURE_2D;
1512 glDisable GL_BLEND; 1623 }
1624
1625 $self->{children}[1]->draw;
1626
1513} 1627}
1514 1628
1515############################################################################# 1629#############################################################################
1516 1630
1517package CFClient::UI::MapWidget; 1631package CFClient::UI::MapWidget;
1541} 1655}
1542 1656
1543sub key_up { 1657sub key_up {
1544} 1658}
1545 1659
1660sub button_down {
1661 my ($self, $ev, $x, $y) = @_;
1662
1663 $self->focus_in;
1664
1665 if ($ev->button == 2) {
1666 my ($ox, $oy) = ($ev->button_x, $ev->button_y);
1667 my ($bw, $bh) = ($::CFG->{map_shift_x}, $::CFG->{map_shift_y});
1668
1669 $self->{motion} = sub {
1670 my ($ev, $x, $y) = @_;
1671
1672 ($x, $y) = ($ev->motion_x, $ev->motion_y);
1673
1674 $::CFG->{map_shift_x} = $bw + $x - $ox;
1675 $::CFG->{map_shift_y} = $bh + $y - $oy;
1676
1677 $self->update;
1678 };
1679 }
1680}
1681
1682sub button_up {
1683 my ($self, $ev, $x, $y) = @_;
1684
1685 delete $self->{motion};
1686}
1687
1688sub mouse_motion {
1689 my ($self, $ev, $x, $y) = @_;
1690
1691 $self->{motion}->($ev, $x, $y) if $self->{motion};
1692}
1693
1546sub size_request { 1694sub size_request {
1547 ( 1695 (
1548 1 + 32 * int $::WIDTH / 32, 1696 1 + 32 * int $::WIDTH / 32,
1549 1 + 32 * int $::HEIGHT / 32, 1697 1 + 32 * int $::HEIGHT / 32,
1550 ) 1698 )
1558} 1706}
1559 1707
1560sub draw { 1708sub draw {
1561 my ($self) = @_; 1709 my ($self) = @_;
1562 1710
1563 $self->{need_update}++;#d#
1564 if (delete $self->{need_update}) { 1711 if (delete $self->{need_update}) {
1565 glNewList $self->{list}, GL_COMPILE; 1712 glNewList $self->{list}, GL_COMPILE;
1566 1713
1567 my $sw = int $::WIDTH / 32;
1568 my $sh = int $::HEIGHT / 32;
1569
1570 if ($::MAP) { 1714 if ($::MAP) {
1715 my $sw = int $::WIDTH / 32;
1716 my $sh = int $::HEIGHT / 32;
1717
1718 my $sx = $::CFG->{map_shift_x};
1719 my $sy = $::CFG->{map_shift_y};
1720
1721 glTranslate +($sx & 31) - 32, ($sy & 31) - 32, 0;
1722
1571 my ($w, $h, $data) = $::MAP->draw (0, 0, $sw, $sh); 1723 my ($w, $h, $data) = $::MAP->draw ($sx >> 5, $sy >> 5, 0, 0, $sw + 1, $sh + 1);
1572 1724
1573 if ($::CFG->{fow_enable}) { 1725 if ($::CFG->{fow_enable}) {
1574 if ($::CFG->{fow_smooth}) { # smooth fog of war 1726 if ($::CFG->{fow_smooth}) { # smooth fog of war
1575 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; 1727 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1576 glConvolutionFilter2D 1728 glConvolutionFilter2D
1594 format => GL_ALPHA; 1746 format => GL_ALPHA;
1595 1747
1596 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; 1748 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
1597 1749
1598 glEnable GL_BLEND; 1750 glEnable GL_BLEND;
1751 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1599 glEnable GL_TEXTURE_2D; 1752 glEnable GL_TEXTURE_2D;
1600 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1753 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1601 1754
1602 glColor +($::CFG->{fow_intensity}) x 3, 1; 1755 glColor +($::CFG->{fow_intensity}) x 3, 1;
1603 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1756 $tex->draw_quad (0, 0, $w * 32, $h * 32);
1604 1757
1605 glDisable GL_TEXTURE_2D; 1758 glDisable GL_TEXTURE_2D;
1606 glDisable GL_BLEND; 1759 glDisable GL_BLEND;
1607 } 1760 }
1761
1762 # HACK BEGIN
1763 {
1764 my ($w, $h) = (250, 250);
1765
1766 glEnable GL_BLEND;
1767 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1768 glEnable GL_TEXTURE_2D;
1769 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1770
1771 CFClient::Texture->new (
1772 w => $w,
1773 h => $h,
1774 data => $::MAP->mapmap ($w, $h),
1775 type => GL_UNSIGNED_INT_8_8_8_8_REV
1776 )->draw_quad (100, 100);
1777
1778 glDisable GL_TEXTURE_2D;
1779 glDisable GL_BLEND;
1780 }
1781 # HACK END
1608 } 1782 }
1609 1783
1610 glEndList; 1784 glEndList;
1611 } 1785 }
1612 1786
1787 glPushMatrix;
1613 glCallList $self->{list}; 1788 glCallList $self->{list};
1789 glPopMatrix;
1614 1790
1615 if ($FOCUS != $self) { 1791 if ($FOCUS != $self) {
1616 glColor 64/255, 64/255, 64/255; 1792 glColor 64/255, 64/255, 64/255;
1617 glLogicOp GL_AND; 1793 glLogicOp GL_AND;
1618 glEnable GL_COLOR_LOGIC_OP; 1794 glEnable GL_COLOR_LOGIC_OP;
1650 1826
1651 if ($sym == SDLK_KP5) { 1827 if ($sym == SDLK_KP5) {
1652 $::CONN->user_send ("command stay fire"); 1828 $::CONN->user_send ("command stay fire");
1653 } elsif ($sym == SDLK_a) { 1829 } elsif ($sym == SDLK_a) {
1654 $::CONN->user_send ("command apply"); 1830 $::CONN->user_send ("command apply");
1831 } elsif ($sym == SDLK_QUOTE) {
1832 $self->emit ('activate_console');
1833 } elsif ($sym == SDLK_SLASH) {
1834 $self->emit ('activate_console' => '/');
1655 } elsif (exists $DIR{$sym}) { 1835 } elsif (exists $DIR{$sym}) {
1656 if ($mod & KMOD_SHIFT) { 1836 if ($mod & KMOD_SHIFT) {
1657 $self->{shft}++; 1837 $self->{shft}++;
1658 $::CONN->user_send ("command fire $DIR{$sym}[0]"); 1838 $::CONN->user_send ("command fire $DIR{$sym}[0]");
1659 } elsif ($mod & KMOD_CTRL) { 1839 } elsif ($mod & KMOD_CTRL) {
1763 1943
1764package CFClient::UI::Toplevel; 1944package CFClient::UI::Toplevel;
1765 1945
1766our @ISA = CFClient::UI::Container::; 1946our @ISA = CFClient::UI::Container::;
1767 1947
1948use SDL::OpenGL;
1949
1768sub size_request { 1950sub size_request {
1769 ($::WIDTH, $::HEIGHT) 1951 ($::WIDTH, $::HEIGHT)
1770} 1952}
1771 1953
1772sub size_allocate { 1954sub size_allocate {
1797 $self->SUPER::add ($widget); 1979 $self->SUPER::add ($widget);
1798 1980
1799 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); 1981 $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request);
1800} 1982}
1801 1983
1984sub on_refresh {
1985 my ($self, $id, $cb) = @_;
1986
1987 $self->{refresh_hook}{$id} = $cb;
1988}
1989
1802sub draw { 1990sub draw {
1803 my ($self) = @_; 1991 my ($self) = @_;
1804 1992
1993 while (my $rcb = delete $self->{refresh_hook}) {
1994 $_->() for values %$rcb;
1995 }
1996
1997 glViewport 0, 0, $::WIDTH, $::HEIGHT;
1998 glClearColor +($::CFG->{fow_intensity}) x 3, 1;
1999 glClear GL_COLOR_BUFFER_BIT;
2000
2001 glMatrixMode GL_PROJECTION;
2002 glLoadIdentity;
2003 glOrtho 0, $::WIDTH, $::HEIGHT, 0, -10000 , 10000;
2004 glMatrixMode GL_MODELVIEW;
2005 glLoadIdentity;
2006
1805 $self->_draw; 2007 $self->_draw;
1806} 2008}
1807 2009
1808############################################################################# 2010#############################################################################
1809 2011

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines