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.107 by root, Fri Apr 14 20:27:35 2006 UTC vs.
Revision 1.112 by root, Sat Apr 15 12:29:46 2006 UTC

66 $hover->update if $hover && $hover->{can_hover}; 66 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER && $HOVER->{can_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;
733 746
734 # linearly scale sizes 747 # linearly scale sizes
735 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; 748 $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws;
736 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs; 749 $hs->[$_] *= 1 * $h / $req_h for 0 .. $#$hs;
737 750
738 $_ = int $_ for @$ws; #TODO: avoid rounding problems 751 CFClient::UI::harmonize $ws;
739 $_ = int $_ for @$hs; #TODO: avoid rounding problems 752 CFClient::UI::harmonize $hs;
740 753
741 my $y; 754 my $y;
742 755
743 for my $r (0 .. $#{$self->{children}}) { 756 for my $r (0 .. $#{$self->{children}}) {
744 my $row = $self->{children}[$r] 757 my $row = $self->{children}[$r]
832 $alloc_h += ($h - $req_h) * $child->{expand} / $exp; 845 $alloc_h += ($h - $req_h) * $child->{expand} / $exp;
833 $h[$_] = $alloc_h; 846 $h[$_] = $alloc_h;
834 } 847 }
835 } 848 }
836 849
850 CFClient::UI::harmonize \@h;
851
837 my $y = 0; 852 my $y = 0;
838 for (0 .. $#$children) { 853 for (0 .. $#$children) {
839 my $child = $children->[$_]; 854 my $child = $children->[$_];
840 my $h = int $h[$_]; 855 my $h = $h[$_];
841 $child->size_allocate ($y, 0, $h, $w); 856 $child->size_allocate ($y, 0, $h, $w);
842 857
843 $y += $h; 858 $y += $h;
844 } 859 }
845} 860}
886 901
887 $h[$_] += ($h - $req_h) * $child->{expand} / $exp; 902 $h[$_] += ($h - $req_h) * $child->{expand} / $exp;
888 } 903 }
889 } 904 }
890 905
906 CFClient::UI::harmonize \@h;
907
891 my $y = 0; 908 my $y = 0;
892 for (0 .. $#$children) { 909 for (0 .. $#$children) {
893 my $child = $children->[$_]; 910 my $child = $children->[$_];
894 my $h = int $h[$_]; 911 my $h = $h[$_];
895 $child->size_allocate (0, $y, $w, $h); 912 $child->size_allocate (0, $y, $w, $h);
896 913
897 $y += $h; 914 $y += $h;
898 } 915 }
899} 916}
1655} 1672}
1656 1673
1657sub key_up { 1674sub key_up {
1658} 1675}
1659 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
1660sub size_request { 1711sub size_request {
1661 ( 1712 (
1662 1 + 32 * int $::WIDTH / 32, 1713 1 + 32 * int $::WIDTH / 32,
1663 1 + 32 * int $::HEIGHT / 32, 1714 1 + 32 * int $::HEIGHT / 32,
1664 ) 1715 )
1672} 1723}
1673 1724
1674sub draw { 1725sub draw {
1675 my ($self) = @_; 1726 my ($self) = @_;
1676 1727
1677 $self->{need_update}++;#d#
1678 if (delete $self->{need_update}) { 1728 if (delete $self->{need_update}) {
1679 glNewList $self->{list}, GL_COMPILE; 1729 glNewList $self->{list}, GL_COMPILE;
1680 1730
1681 my $sw = int $::WIDTH / 32;
1682 my $sh = int $::HEIGHT / 32;
1683
1684 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
1685 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);
1686 1741
1687 if ($::CFG->{fow_enable}) { 1742 if ($::CFG->{fow_enable}) {
1688 if ($::CFG->{fow_smooth}) { # smooth fog of war 1743 if ($::CFG->{fow_smooth}) { # smooth fog of war
1689 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER; 1744 glConvolutionParameter GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER;
1690 glConvolutionFilter2D 1745 glConvolutionFilter2D
1708 format => GL_ALPHA; 1763 format => GL_ALPHA;
1709 1764
1710 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth}; 1765 glDisable GL_CONVOLUTION_2D if $::CFG->{fow_smooth};
1711 1766
1712 glEnable GL_BLEND; 1767 glEnable GL_BLEND;
1768 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1713 glEnable GL_TEXTURE_2D; 1769 glEnable GL_TEXTURE_2D;
1714 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 1770 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
1715 1771
1716 glColor +($::CFG->{fow_intensity}) x 3, 1; 1772 glColor +($::CFG->{fow_intensity}) x 3, 1;
1717 $tex->draw_quad (0, 0, $w * 32, $h * 32); 1773 $tex->draw_quad (0, 0, $w * 32, $h * 32);
1718 1774
1719 glDisable GL_TEXTURE_2D; 1775 glDisable GL_TEXTURE_2D;
1720 glDisable GL_BLEND; 1776 glDisable GL_BLEND;
1721 } 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
1722 } 1800 }
1723 1801
1724 glEndList; 1802 glEndList;
1725 } 1803 }
1726 1804
1805 glPushMatrix;
1727 glCallList $self->{list}; 1806 glCallList $self->{list};
1807 glPopMatrix;
1728 1808
1729 if ($FOCUS != $self) { 1809 if ($FOCUS != $self) {
1730 glColor 64/255, 64/255, 64/255; 1810 glColor 64/255, 64/255, 64/255;
1731 glLogicOp GL_AND; 1811 glLogicOp GL_AND;
1732 glEnable GL_COLOR_LOGIC_OP; 1812 glEnable GL_COLOR_LOGIC_OP;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines