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.155 by root, Sun Apr 23 02:22:54 2006 UTC vs.
Revision 1.161 by root, Mon Apr 24 03:43:51 2006 UTC

14our $BUTTON_STATE; 14our $BUTTON_STATE;
15 15
16sub check_tooltip { 16sub check_tooltip {
17 if (!$GRAB) { 17 if (!$GRAB) {
18 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { 18 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
19 if (exists $widget->{tooltip}) { 19 if (length $widget->{tooltip}) {
20 20
21 if ($TOOLTIP->{owner} != $widget) { 21 if ($TOOLTIP->{owner} != $widget) {
22 $TOOLTIP->{owner} = $widget; 22 $TOOLTIP->{owner} = $widget;
23 23
24 my $tip = $widget->{tooltip}; 24 my $tip = $widget->{tooltip};
142 } 142 }
143 143
144 $self 144 $self
145} 145}
146 146
147sub destroy {
148 my ($self) = @_;
149
150 $self->hide;
151 %$self = ();
152}
153
147sub show { 154sub show {
148 my ($self) = @_; 155 my ($self) = @_;
149 156
150 return if $self->{parent}; 157 return if $self->{parent};
151 158
168 $self->{z} = $z if defined $z; 175 $self->{z} = $z if defined $z;
169 176
170 $self->update; 177 $self->update;
171} 178}
172 179
173sub needs_redraw { 180sub set_size {
174 0 181 my ($self, $w, $h) = @_;
182
183 $self->{user_w} = $w;
184 $self->{user_h} = $h;
185
186 $self->check_size;
175} 187}
176 188
177sub size_request { 189sub size_request {
178 require Carp; 190 require Carp;
179 Carp::confess "size_request is abstract"; 191 Carp::confess "size_request is abstract";
209 } 221 }
210} 222}
211 223
212sub size_allocate { 224sub size_allocate {
213 # nothing to be done 225 # nothing to be done
226}
227
228sub set_max_size {
229 my ($self, $w, $h) = @_;
230
231 delete $self->{max_w}; $self->{max_w} = $w if $w;
232 delete $self->{max_h}; $self->{max_h} = $h if $h;
214} 233}
215 234
216# return top left coordinates 235# return top left coordinates
217sub _topleft { 236sub _topleft {
218 my ($self, $x, $y) = @_; 237 my ($self, $x, $y) = @_;
330} 349}
331 350
332sub check_size { 351sub check_size {
333 my ($self) = @_; 352 my ($self) = @_;
334 353
335 return unless $self->{parent}; 354 $self->{parent}
355 or return 1;
336 356
337 my ($w, $h) = $self->size_request; 357 my ($w, $h) = $self->{user_w} && $self->{user_h}
358 ? @$self{qw(user_w user_h)}
359 : $self->size_request;
338 360
339 if ($w != $self->{req_w} || $h != $self->{req_h}) { 361 if ($w != $self->{req_w} || $h != $self->{req_h}) {
340 $self->{req_w} = $w; 362 $self->{req_w} = $w;
341 $self->{req_h} = $h; 363 $self->{req_h} = $h;
342 364
343 $self->{parent}->check_size; 365 $self->{parent}->check_size
366 or $self->size_allocate (
367 (List::Util::max $self->{w}, $w),
368 (List::Util::max $self->{h}, $h),
369 );
370
371 1
372 } else {
373 0
344 } 374 }
345} 375}
346 376
347sub update { 377sub update {
348 my ($self) = @_; 378 my ($self) = @_;
636 border => 0.8, 666 border => 0.8,
637 @_ 667 @_
638 ); 668 );
639 669
640 $self 670 $self
641}
642
643sub set_size {
644 my ($self, $w, $h) = @_;
645 $self->{req_w} = $w;
646 $self->{req_h} = $h;
647 $self->check_size;
648}
649
650sub size_request {
651 my ($self) = @_;
652 ($self->{req_w}, $self->{req_h})
653}
654
655sub size_allocate {
656 my ($self, $w, $h) = @_;
657 $self->{w} = $w;
658 $self->{h} = $h;
659 $self->child->configure (0, 0, $w, $h);
660} 671}
661 672
662sub _draw { 673sub _draw {
663 my ($self) = @_; 674 my ($self) = @_;
664 675
721 int $_[0]{border} * $::FONTSIZE 732 int $_[0]{border} * $::FONTSIZE
722} 733}
723 734
724sub size_request { 735sub size_request {
725 my ($self) = @_; 736 my ($self) = @_;
726
727 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
728 737
729 my ($w, $h) = $self->SUPER::size_request; 738 my ($w, $h) = $self->SUPER::size_request;
730 739
731 ( 740 (
732 $w + $self->border * 2, 741 $w + $self->border * 2,
1099sub new { 1108sub new {
1100 my ($class, %arg) = @_; 1109 my ($class, %arg) = @_;
1101 1110
1102 my $self = $class->SUPER::new ( 1111 my $self = $class->SUPER::new (
1103 fg => [1, 1, 1], 1112 fg => [1, 1, 1],
1113 #font => default_font
1104 fontsize => 1, 1114 fontsize => 1,
1105 text => "", 1115 text => "",
1106 align => -1, 1116 align => -1,
1107 valign => -1, 1117 valign => -1,
1108 padding => 2, 1118 padding => 2,
1154} 1164}
1155 1165
1156sub size_request { 1166sub size_request {
1157 my ($self) = @_; 1167 my ($self) = @_;
1158 1168
1159 $self->{layout}->set_width; 1169 $self->{layout}->set_font ($self->{font}) if $self->{font};
1170 $self->{layout}->set_width ($self->{max_w} || -1);
1160 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1171 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1161 1172
1162 my ($w, $h) = $self->{layout}->size; 1173 my ($w, $h) = $self->{layout}->size;
1163 1174
1164 if (exists $self->{template}) { 1175 if (exists $self->{template}) {
1176 $self->{template}->set_font ($self->{font}) if $self->{font};
1165 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1177 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1166 1178
1167 my ($w2, $h2) = $self->{template}->size; 1179 my ($w2, $h2) = $self->{template}->size;
1168 1180
1169 $w = List::Util::max $w, $w2; 1181 $w = List::Util::max $w, $w2;
1193 1205
1194sub _draw { 1206sub _draw {
1195 my ($self) = @_; 1207 my ($self) = @_;
1196 1208
1197 my $tex = $self->{texture} ||= do { 1209 my $tex = $self->{texture} ||= do {
1210 $self->{layout}->set_font ($self->{font}) if $self->{font};
1198 $self->{layout}->set_width ($self->{w}); 1211 $self->{layout}->set_width ($self->{w});
1199 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1212 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1200 new_from_layout CFClient::Texture $self->{layout} 1213 new_from_layout CFClient::Texture $self->{layout}
1201 }; 1214 };
1202 1215
1605 1618
1606package CFClient::UI::VGauge; 1619package CFClient::UI::VGauge;
1607 1620
1608our @ISA = CFClient::UI::Base::; 1621our @ISA = CFClient::UI::Base::;
1609 1622
1623use List::Util qw(min max);
1624
1610use CFClient::OpenGL; 1625use CFClient::OpenGL;
1611 1626
1612my %tex = ( 1627my %tex = (
1613 food => [ 1628 food => [
1614 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1629 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1615 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1630 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1616 ], 1631 ],
1617 grace => [ 1632 grace => [
1618 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1633 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1619 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1634 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
1620 ], 1635 ],
1621 hp => [ 1636 hp => [
1622 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1637 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1623 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1638 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1624 ], 1639 ],
1625 mana => [ 1640 mana => [
1626 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1641 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1627 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1642 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
1628 ], 1643 ],
1629); 1644);
1630 1645
1631# eg. VGauge->new (gauge => 'food'), default gauge: food 1646# eg. VGauge->new (gauge => 'food'), default gauge: food
1632sub new { 1647sub new {
1670 1685
1671sub _draw { 1686sub _draw {
1672 my ($self) = @_; 1687 my ($self) = @_;
1673 1688
1674 my $tex = $tex{$self->{type}}; 1689 my $tex = $tex{$self->{type}};
1690 my ($t1, $t2, $t3) = @$tex;
1675 1691
1676 my ($w, $h) = ($self->{w}, $self->{h}); 1692 my ($w, $h) = ($self->{w}, $self->{h});
1677 1693
1678 if ($self->{vertical}) { 1694 if ($self->{vertical}) {
1679 glRotate 90, 0, 0, 1; 1695 glRotate 90, 0, 0, 1;
1681 1697
1682 ($w, $h) = ($h, $w); 1698 ($w, $h) = ($h, $w);
1683 } 1699 }
1684 1700
1685 my $ycut = $self->{val} / ($self->{max_val} || 1); 1701 my $ycut = $self->{val} / ($self->{max_val} || 1);
1686 $ycut = 1 if $self->{val} > $self->{max_val};
1687 1702
1688 my $t1 = $tex->[0]; 1703 my $ycut1 = max 0, min 1, $ycut;
1689 my $t2 = $tex->[1]; 1704 my $ycut2 = max 0, min 1, $ycut - 1;
1705
1706 my $h1 = $self->{h} * (1 - $ycut1);
1707 my $h2 = $self->{h} * (1 - $ycut2);
1690 1708
1691 glEnable GL_BLEND; 1709 glEnable GL_BLEND;
1692 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1710 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1693 glEnable GL_TEXTURE_2D; 1711 glEnable GL_TEXTURE_2D;
1694 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1695 1713
1696 my $h1 = $self->{h} - $ycut * $self->{h};
1697 my $h2 = $ycut * $self->{h};
1698
1699 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1714 glBindTexture GL_TEXTURE_2D, $t1->{name};
1700 glBegin GL_QUADS; 1715 glBegin GL_QUADS;
1701 glTexCoord 0 , 0; glVertex 0 , 0; 1716 glTexCoord 0 , 0; glVertex 0 , 0;
1702 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1717 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1703 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1718 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1704 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1719 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1705 glEnd; 1720 glEnd;
1706 1721
1722 my $ycut1 = List::Util::min 1, $ycut;
1707 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1723 glBindTexture GL_TEXTURE_2D, $t2->{name};
1708 glBegin GL_QUADS; 1724 glBegin GL_QUADS;
1709 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1725 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1710 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1726 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1711 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1727 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1712 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1728 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1713 glEnd; 1729 glEnd;
1730
1731 if ($t3) {
1732 glBindTexture GL_TEXTURE_2D, $t3->{name};
1733 glBegin GL_QUADS;
1734 glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2;
1735 glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h};
1736 glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h};
1737 glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2;
1738 glEnd;
1739 }
1714 1740
1715 glDisable GL_BLEND; 1741 glDisable GL_BLEND;
1716 glDisable GL_TEXTURE_2D; 1742 glDisable GL_TEXTURE_2D;
1717} 1743}
1718 1744
1725sub new { 1751sub new {
1726 my ($class, %arg) = @_; 1752 my ($class, %arg) = @_;
1727 1753
1728 my $self = $class->SUPER::new ( 1754 my $self = $class->SUPER::new (
1729 tooltip => $arg{type}, 1755 tooltip => $arg{type},
1756 can_events => 1,
1757 can_hover => 1,
1730 %arg, 1758 %arg,
1731 ); 1759 );
1732 1760
1733 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 1761 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1734 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1762 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1735 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); 1763 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1736 1764
1737 $self 1765 $self
1738} 1766}
1739 1767
1907sub new { 1935sub new {
1908 my $class = shift; 1936 my $class = shift;
1909 1937
1910 my $self = $class->SUPER::new ( 1938 my $self = $class->SUPER::new (
1911 fontsize => 1, 1939 fontsize => 1,
1940 #font => default_font
1912 @_, 1941 @_,
1913 1942
1914 layout => (new CFClient::Layout), 1943 layout => (new CFClient::Layout),
1915 par => [], 1944 par => [],
1916 height => 0, 1945 height => 0,
1956sub size_allocate { 1985sub size_allocate {
1957 my ($self, $w, $h) = @_; 1986 my ($self, $w, $h) = @_;
1958 1987
1959 $self->SUPER::size_allocate ($w, $h); 1988 $self->SUPER::size_allocate ($w, $h);
1960 1989
1990 $self->{layout}->set_font ($self->{font}) if $self->{font};
1961 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1991 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1962 $self->{layout}->set_width ($self->{children}[0]{w}); 1992 $self->{layout}->set_width ($self->{children}[0]{w});
1963 1993
1964 $self->reflow; 1994 $self->reflow;
1965} 1995}
2017 my $y1 = $top + $self->{h}; 2047 my $y1 = $top + $self->{h};
2018 2048
2019 my $y = 0; 2049 my $y = 0;
2020 2050
2021 my $layout = $self->{layout}; 2051 my $layout = $self->{layout};
2052
2053 $layout->set_font ($self->{font}) if $self->{font};
2022 2054
2023 for my $par (@{$self->{par}}) { 2055 for my $par (@{$self->{par}}) {
2024 my $h = $par->[0]; 2056 my $h = $par->[0];
2025 2057
2026 if ($y0 < $y + $h && $y < $y1) { 2058 if ($y0 < $y + $h && $y < $y1) {
2162} 2194}
2163 2195
2164sub size_request { 2196sub size_request {
2165 my ($self) = @_; 2197 my ($self) = @_;
2166 2198
2199 $self->child->set_max_size ($::WIDTH * 0.3);
2200
2167 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2201 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2168
2169 $w = List::Util::min $::WIDTH * 0.2, $w;
2170 $h = List::Util::max $::HEIGHT * 0.2, $h;
2171 2202
2172 ($w + 4, $h + 4) 2203 ($w + 4, $h + 4)
2173} 2204}
2174 2205
2175sub _draw { 2206sub _draw {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines