… | |
… | |
732 | my $col_expand = (sum @col_expand) || 1; |
732 | my $col_expand = (sum @col_expand) || 1; |
733 | |
733 | |
734 | # linearly scale sizes |
734 | # linearly scale sizes |
735 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
735 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
736 | $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 |
737 | |
740 | |
738 | my $y; |
741 | my $y; |
739 | |
742 | |
740 | for my $r (0 .. $#{$self->{children}}) { |
743 | for my $r (0 .. $#{$self->{children}}) { |
741 | my $row = $self->{children}[$r] |
744 | my $row = $self->{children}[$r] |
… | |
… | |
1424 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1427 | my $fg = $FOCUS == $self ? $self->{active_fg} : $self->{fg}; |
1425 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
1428 | my $bg = $FOCUS == $self ? $self->{active_bg} : $self->{bg}; |
1426 | |
1429 | |
1427 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1430 | my ($value, $lo, $hi, $page) = @{$self->{range}}; |
1428 | |
1431 | |
|
|
1432 | $hi = $value + 1 if $lo == $hi; |
|
|
1433 | |
1429 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
1434 | my $inner_pad_px = $self->_calc_inner_pad_px ($w); |
1430 | 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 |
1431 | |
1436 | |
1432 | $page = int $page * $inner_w / ($hi - $lo); |
1437 | $page = int $page * $inner_w / ($hi - $lo); |
1433 | $value = int +($value - $lo) * $inner_w / ($hi - $lo); |
1438 | $value = int +($value - $lo) * $inner_w / ($hi - $lo); |
… | |
… | |
1479 | (new CFClient::UI::Empty expand => 1), |
1484 | (new CFClient::UI::Empty expand => 1), |
1480 | (new CFClient::UI::Slider vertical => 1), |
1485 | (new CFClient::UI::Slider vertical => 1), |
1481 | ], |
1486 | ], |
1482 | ); |
1487 | ); |
1483 | |
1488 | |
|
|
1489 | $self->{children}[1]->connect (changed => sub { |
|
|
1490 | $self->update; |
|
|
1491 | }); |
|
|
1492 | |
1484 | $self |
1493 | $self |
|
|
1494 | } |
|
|
1495 | |
|
|
1496 | sub set_fontsize { |
|
|
1497 | my ($self, $fontsize) = @_; |
|
|
1498 | |
|
|
1499 | $self->{fontsize} = $fontsize; |
|
|
1500 | $self->reflow; |
1485 | } |
1501 | } |
1486 | |
1502 | |
1487 | sub text_height { |
1503 | sub text_height { |
1488 | my ($self, $text) = @_; |
1504 | my ($self, $text) = @_; |
1489 | |
1505 | |
… | |
… | |
1497 | } |
1513 | } |
1498 | |
1514 | |
1499 | sub reflow { |
1515 | sub reflow { |
1500 | my ($self) = @_; |
1516 | my ($self) = @_; |
1501 | |
1517 | |
1502 | my $height = 0; |
1518 | $self->{need_reflow}++; |
1503 | |
1519 | $self->update; |
1504 | for (@{$self->{par}}) { |
|
|
1505 | $height += $_->[0] = $self->text_height ($_->[2]); |
|
|
1506 | } |
|
|
1507 | |
|
|
1508 | $self->{height} = $height; |
|
|
1509 | |
|
|
1510 | $self->{range} = [$height - $self->{h}, 0, $height, $self->{h}]; |
|
|
1511 | } |
1520 | } |
1512 | |
1521 | |
1513 | sub size_request { |
1522 | sub size_request { |
1514 | my ($self) = @_; |
1523 | my ($self) = @_; |
1515 | |
1524 | |
… | |
… | |
1523 | |
1532 | |
1524 | $self->{layout}->set_height ($self->{fontsize}); |
1533 | $self->{layout}->set_height ($self->{fontsize}); |
1525 | $self->{layout}->set_width ($self->{w}); |
1534 | $self->{layout}->set_width ($self->{w}); |
1526 | |
1535 | |
1527 | $self->reflow; |
1536 | $self->reflow; |
1528 | $self->update; |
|
|
1529 | } |
1537 | } |
1530 | |
1538 | |
1531 | sub add_paragraph { |
1539 | sub add_paragraph { |
1532 | my ($self, $color, $text) = @_; |
1540 | my ($self, $color, $text) = @_; |
1533 | |
1541 | |
… | |
… | |
1548 | |
1556 | |
1549 | $self->SUPER::update; |
1557 | $self->SUPER::update; |
1550 | |
1558 | |
1551 | return unless $self->{h} > 0; |
1559 | return unless $self->{h} > 0; |
1552 | |
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 | |
1553 | $self->{texture} = new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
1577 | $self->{texture} ||= new_from_opengl CFClient::Texture $self->{w}, $self->{h}, sub { |
1554 | glClearColor 0, 0, 0, 1; |
1578 | glClearColor 0, 0, 0, 1; |
1555 | glClear GL_COLOR_BUFFER_BIT; |
1579 | glClear GL_COLOR_BUFFER_BIT; |
1556 | |
1580 | |
1557 | my $y0 = $self->{height} - $self->{h}; |
|
|
1558 | my $y1 = $self->{height}; |
|
|
1559 | |
|
|
1560 | glEnable GL_BLEND; |
1581 | glEnable GL_BLEND; |
1561 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1582 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1562 | glEnable GL_TEXTURE_2D; |
1583 | glEnable GL_TEXTURE_2D; |
1563 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1584 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1564 | |
1585 | |
|
|
1586 | my $top = int $self->{children}[1]{range}[0]; |
|
|
1587 | |
|
|
1588 | my $y0 = $top; |
|
|
1589 | my $y1 = $top + $self->{h}; |
|
|
1590 | |
1565 | my $y = 0; |
1591 | my $y = 0; |
1566 | |
1592 | |
1567 | my $layout = $self->{layout}; |
1593 | my $layout = $self->{layout}; |
1568 | |
1594 | |
1569 | for my $par (@{$self->{par}}) { |
1595 | for my $par (@{$self->{par}}) { |
1570 | my $h = $par->[0]; |
1596 | my $h = $par->[0]; |
1571 | |
1597 | |
1572 | if ($y0 < $y + $h && $y < $y1) { |
1598 | if ($y0 < $y + $h && $y < $y1) { |
1573 | $layout->set_text ($par->[2]); |
1599 | $layout->set_text ($par->[2]); |
1574 | |
1600 | |
1575 | glColor @{ $par->[1] }; |
1601 | glColor @{ $par->[1] }; |
1576 | my ($W, $H) = $layout->size; |
1602 | my ($W, $H) = $layout->size; |
1577 | CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); |
1603 | CFClient::Texture->new_from_layout ($layout)->draw_quad (0, $y - $y0); |
|
|
1604 | } |
|
|
1605 | |
|
|
1606 | $y += $h; |
1578 | } |
1607 | } |
1579 | |
1608 | |
1580 | $y += $h; |
|
|
1581 | } |
|
|
1582 | |
|
|
1583 | glDisable GL_TEXTURE_2D; |
1609 | glDisable GL_TEXTURE_2D; |
1584 | glDisable GL_BLEND; |
1610 | glDisable GL_BLEND; |
|
|
1611 | }; |
1585 | }; |
1612 | }); |
1586 | } |
1613 | } |
1587 | |
1614 | |
1588 | sub _draw { |
1615 | sub _draw { |
1589 | my ($self) = @_; |
1616 | my ($self) = @_; |
1590 | |
1617 | |
… | |
… | |
1592 | glEnable GL_TEXTURE_2D; |
1619 | glEnable GL_TEXTURE_2D; |
1593 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1620 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
1594 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
1621 | $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); |
1595 | glDisable GL_TEXTURE_2D; |
1622 | glDisable GL_TEXTURE_2D; |
1596 | } |
1623 | } |
|
|
1624 | |
|
|
1625 | $self->{children}[1]->draw; |
1597 | |
1626 | |
1598 | } |
1627 | } |
1599 | |
1628 | |
1600 | ############################################################################# |
1629 | ############################################################################# |
1601 | |
1630 | |
… | |
… | |
1626 | } |
1655 | } |
1627 | |
1656 | |
1628 | sub key_up { |
1657 | sub key_up { |
1629 | } |
1658 | } |
1630 | |
1659 | |
|
|
1660 | sub 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 | |
|
|
1682 | sub button_up { |
|
|
1683 | my ($self, $ev, $x, $y) = @_; |
|
|
1684 | |
|
|
1685 | delete $self->{motion}; |
|
|
1686 | } |
|
|
1687 | |
|
|
1688 | sub mouse_motion { |
|
|
1689 | my ($self, $ev, $x, $y) = @_; |
|
|
1690 | |
|
|
1691 | $self->{motion}->($ev, $x, $y) if $self->{motion}; |
|
|
1692 | } |
|
|
1693 | |
1631 | sub size_request { |
1694 | sub size_request { |
1632 | ( |
1695 | ( |
1633 | 1 + 32 * int $::WIDTH / 32, |
1696 | 1 + 32 * int $::WIDTH / 32, |
1634 | 1 + 32 * int $::HEIGHT / 32, |
1697 | 1 + 32 * int $::HEIGHT / 32, |
1635 | ) |
1698 | ) |
… | |
… | |
1643 | } |
1706 | } |
1644 | |
1707 | |
1645 | sub draw { |
1708 | sub draw { |
1646 | my ($self) = @_; |
1709 | my ($self) = @_; |
1647 | |
1710 | |
1648 | $self->{need_update}++;#d# |
|
|
1649 | if (delete $self->{need_update}) { |
1711 | if (delete $self->{need_update}) { |
1650 | glNewList $self->{list}, GL_COMPILE; |
1712 | glNewList $self->{list}, GL_COMPILE; |
1651 | |
1713 | |
1652 | my $sw = int $::WIDTH / 32; |
|
|
1653 | my $sh = int $::HEIGHT / 32; |
|
|
1654 | |
|
|
1655 | 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 | |
1656 | 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); |
1657 | |
1724 | |
1658 | if ($::CFG->{fow_enable}) { |
1725 | if ($::CFG->{fow_enable}) { |
1659 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
1726 | if ($::CFG->{fow_smooth}) { # smooth fog of war |
1660 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
1727 | glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; |
1661 | glConvolutionFilter2D |
1728 | glConvolutionFilter2D |
… | |
… | |
1679 | format => GL_ALPHA; |
1746 | format => GL_ALPHA; |
1680 | |
1747 | |
1681 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1748 | glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; |
1682 | |
1749 | |
1683 | glEnable GL_BLEND; |
1750 | glEnable GL_BLEND; |
|
|
1751 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
1684 | glEnable GL_TEXTURE_2D; |
1752 | glEnable GL_TEXTURE_2D; |
1685 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1753 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1686 | |
1754 | |
1687 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1755 | glColor +($::CFG->{fow_intensity}) x 3, 1; |
1688 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
1756 | $tex->draw_quad (0, 0, $w * 32, $h * 32); |
1689 | |
1757 | |
1690 | glDisable GL_TEXTURE_2D; |
1758 | glDisable GL_TEXTURE_2D; |
1691 | glDisable GL_BLEND; |
1759 | glDisable GL_BLEND; |
1692 | } |
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 |
1693 | } |
1782 | } |
1694 | |
1783 | |
1695 | glEndList; |
1784 | glEndList; |
1696 | } |
1785 | } |
1697 | |
1786 | |
|
|
1787 | glPushMatrix; |
1698 | glCallList $self->{list}; |
1788 | glCallList $self->{list}; |
|
|
1789 | glPopMatrix; |
1699 | |
1790 | |
1700 | if ($FOCUS != $self) { |
1791 | if ($FOCUS != $self) { |
1701 | glColor 64/255, 64/255, 64/255; |
1792 | glColor 64/255, 64/255, 64/255; |
1702 | glLogicOp GL_AND; |
1793 | glLogicOp GL_AND; |
1703 | glEnable GL_COLOR_LOGIC_OP; |
1794 | glEnable GL_COLOR_LOGIC_OP; |
… | |
… | |
1852 | |
1943 | |
1853 | package CFClient::UI::Toplevel; |
1944 | package CFClient::UI::Toplevel; |
1854 | |
1945 | |
1855 | our @ISA = CFClient::UI::Container::; |
1946 | our @ISA = CFClient::UI::Container::; |
1856 | |
1947 | |
|
|
1948 | use SDL::OpenGL; |
|
|
1949 | |
1857 | sub size_request { |
1950 | sub size_request { |
1858 | ($::WIDTH, $::HEIGHT) |
1951 | ($::WIDTH, $::HEIGHT) |
1859 | } |
1952 | } |
1860 | |
1953 | |
1861 | sub size_allocate { |
1954 | sub size_allocate { |
… | |
… | |
1886 | $self->SUPER::add ($widget); |
1979 | $self->SUPER::add ($widget); |
1887 | |
1980 | |
1888 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
1981 | $widget->size_allocate ($widget->{x}, $widget->{y}, $widget->size_request); |
1889 | } |
1982 | } |
1890 | |
1983 | |
|
|
1984 | sub on_refresh { |
|
|
1985 | my ($self, $id, $cb) = @_; |
|
|
1986 | |
|
|
1987 | $self->{refresh_hook}{$id} = $cb; |
|
|
1988 | } |
|
|
1989 | |
1891 | sub draw { |
1990 | sub draw { |
1892 | my ($self) = @_; |
1991 | my ($self) = @_; |
1893 | |
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 | |
1894 | $self->_draw; |
2007 | $self->_draw; |
1895 | } |
2008 | } |
1896 | |
2009 | |
1897 | ############################################################################# |
2010 | ############################################################################# |
1898 | |
2011 | |