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.158 by root, Mon Apr 24 02:41:48 2006 UTC

168 $self->{z} = $z if defined $z; 168 $self->{z} = $z if defined $z;
169 169
170 $self->update; 170 $self->update;
171} 171}
172 172
173sub needs_redraw { 173sub set_size {
174 0 174 my ($self, $w, $h) = @_;
175
176 $self->{user_w} = $w;
177 $self->{user_h} = $h;
178
179 $self->check_size;
175} 180}
176 181
177sub size_request { 182sub size_request {
178 require Carp; 183 require Carp;
179 Carp::confess "size_request is abstract"; 184 Carp::confess "size_request is abstract";
209 } 214 }
210} 215}
211 216
212sub size_allocate { 217sub size_allocate {
213 # nothing to be done 218 # nothing to be done
219}
220
221sub set_max_size {
222 my ($self, $w, $h) = @_;
223
224 delete $self->{max_w}; $self->{max_w} = $w if $w;
225 delete $self->{max_h}; $self->{max_h} = $h if $h;
214} 226}
215 227
216# return top left coordinates 228# return top left coordinates
217sub _topleft { 229sub _topleft {
218 my ($self, $x, $y) = @_; 230 my ($self, $x, $y) = @_;
330} 342}
331 343
332sub check_size { 344sub check_size {
333 my ($self) = @_; 345 my ($self) = @_;
334 346
335 return unless $self->{parent}; 347 $self->{parent}
348 or return 1;
336 349
337 my ($w, $h) = $self->size_request; 350 my ($w, $h) = $self->{user_w} && $self->{user_h}
351 ? @$self{qw(user_w user_h)}
352 : $self->size_request;
338 353
339 if ($w != $self->{req_w} || $h != $self->{req_h}) { 354 if ($w != $self->{req_w} || $h != $self->{req_h}) {
340 $self->{req_w} = $w; 355 $self->{req_w} = $w;
341 $self->{req_h} = $h; 356 $self->{req_h} = $h;
342 357
343 $self->{parent}->check_size; 358 $self->{parent}->check_size
359 or $self->size_allocate (
360 (List::Util::max $self->{w}, $w),
361 (List::Util::max $self->{h}, $h),
362 );
363
364 1
365 } else {
366 0
344 } 367 }
345} 368}
346 369
347sub update { 370sub update {
348 my ($self) = @_; 371 my ($self) = @_;
636 border => 0.8, 659 border => 0.8,
637 @_ 660 @_
638 ); 661 );
639 662
640 $self 663 $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} 664}
661 665
662sub _draw { 666sub _draw {
663 my ($self) = @_; 667 my ($self) = @_;
664 668
721 int $_[0]{border} * $::FONTSIZE 725 int $_[0]{border} * $::FONTSIZE
722} 726}
723 727
724sub size_request { 728sub size_request {
725 my ($self) = @_; 729 my ($self) = @_;
726
727 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
728 730
729 my ($w, $h) = $self->SUPER::size_request; 731 my ($w, $h) = $self->SUPER::size_request;
730 732
731 ( 733 (
732 $w + $self->border * 2, 734 $w + $self->border * 2,
1099sub new { 1101sub new {
1100 my ($class, %arg) = @_; 1102 my ($class, %arg) = @_;
1101 1103
1102 my $self = $class->SUPER::new ( 1104 my $self = $class->SUPER::new (
1103 fg => [1, 1, 1], 1105 fg => [1, 1, 1],
1106 #font => default_font
1104 fontsize => 1, 1107 fontsize => 1,
1105 text => "", 1108 text => "",
1106 align => -1, 1109 align => -1,
1107 valign => -1, 1110 valign => -1,
1108 padding => 2, 1111 padding => 2,
1154} 1157}
1155 1158
1156sub size_request { 1159sub size_request {
1157 my ($self) = @_; 1160 my ($self) = @_;
1158 1161
1159 $self->{layout}->set_width; 1162 $self->{layout}->set_font ($self->{font}) if $self->{font};
1163 $self->{layout}->set_width ($self->{max_w} || -1);
1160 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1164 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1161 1165
1162 my ($w, $h) = $self->{layout}->size; 1166 my ($w, $h) = $self->{layout}->size;
1163 1167
1164 if (exists $self->{template}) { 1168 if (exists $self->{template}) {
1169 $self->{template}->set_font ($self->{font}) if $self->{font};
1165 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1170 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1166 1171
1167 my ($w2, $h2) = $self->{template}->size; 1172 my ($w2, $h2) = $self->{template}->size;
1168 1173
1169 $w = List::Util::max $w, $w2; 1174 $w = List::Util::max $w, $w2;
1193 1198
1194sub _draw { 1199sub _draw {
1195 my ($self) = @_; 1200 my ($self) = @_;
1196 1201
1197 my $tex = $self->{texture} ||= do { 1202 my $tex = $self->{texture} ||= do {
1203 $self->{layout}->set_font ($self->{font}) if $self->{font};
1198 $self->{layout}->set_width ($self->{w}); 1204 $self->{layout}->set_width ($self->{w});
1199 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1205 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1200 new_from_layout CFClient::Texture $self->{layout} 1206 new_from_layout CFClient::Texture $self->{layout}
1201 }; 1207 };
1202 1208
1605 1611
1606package CFClient::UI::VGauge; 1612package CFClient::UI::VGauge;
1607 1613
1608our @ISA = CFClient::UI::Base::; 1614our @ISA = CFClient::UI::Base::;
1609 1615
1616use List::Util qw(min max);
1617
1610use CFClient::OpenGL; 1618use CFClient::OpenGL;
1611 1619
1612my %tex = ( 1620my %tex = (
1613 food => [ 1621 food => [
1614 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1622 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1615 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1623 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1616 ], 1624 ],
1617 grace => [ 1625 grace => [
1618 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1626 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1619 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1627 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
1620 ], 1628 ],
1621 hp => [ 1629 hp => [
1622 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1630 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1623 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1631 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1624 ], 1632 ],
1625 mana => [ 1633 mana => [
1626 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1634 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1627 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1635 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
1628 ], 1636 ],
1629); 1637);
1630 1638
1631# eg. VGauge->new (gauge => 'food'), default gauge: food 1639# eg. VGauge->new (gauge => 'food'), default gauge: food
1632sub new { 1640sub new {
1670 1678
1671sub _draw { 1679sub _draw {
1672 my ($self) = @_; 1680 my ($self) = @_;
1673 1681
1674 my $tex = $tex{$self->{type}}; 1682 my $tex = $tex{$self->{type}};
1683 my ($t1, $t2, $t3) = @$tex;
1675 1684
1676 my ($w, $h) = ($self->{w}, $self->{h}); 1685 my ($w, $h) = ($self->{w}, $self->{h});
1677 1686
1678 if ($self->{vertical}) { 1687 if ($self->{vertical}) {
1679 glRotate 90, 0, 0, 1; 1688 glRotate 90, 0, 0, 1;
1681 1690
1682 ($w, $h) = ($h, $w); 1691 ($w, $h) = ($h, $w);
1683 } 1692 }
1684 1693
1685 my $ycut = $self->{val} / ($self->{max_val} || 1); 1694 my $ycut = $self->{val} / ($self->{max_val} || 1);
1686 $ycut = 1 if $self->{val} > $self->{max_val};
1687 1695
1688 my $t1 = $tex->[0]; 1696 my $ycut1 = max 0, min 1, $ycut;
1689 my $t2 = $tex->[1]; 1697 my $ycut2 = max 0, min 1, $ycut - 1;
1698
1699 my $h1 = $self->{h} * (1 - $ycut1);
1700 my $h2 = $self->{h} * (1 - $ycut2);
1690 1701
1691 glEnable GL_BLEND; 1702 glEnable GL_BLEND;
1692 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1703 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1693 glEnable GL_TEXTURE_2D; 1704 glEnable GL_TEXTURE_2D;
1694 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1705 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1695 1706
1696 my $h1 = $self->{h} - $ycut * $self->{h};
1697 my $h2 = $ycut * $self->{h};
1698
1699 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1707 glBindTexture GL_TEXTURE_2D, $t1->{name};
1700 glBegin GL_QUADS; 1708 glBegin GL_QUADS;
1701 glTexCoord 0 , 0; glVertex 0 , 0; 1709 glTexCoord 0 , 0; glVertex 0 , 0;
1702 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1710 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1703 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1711 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1704 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1712 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1705 glEnd; 1713 glEnd;
1706 1714
1715 my $ycut1 = List::Util::min 1, $ycut;
1707 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1716 glBindTexture GL_TEXTURE_2D, $t2->{name};
1708 glBegin GL_QUADS; 1717 glBegin GL_QUADS;
1709 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1718 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1710 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1719 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1711 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1720 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1712 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1721 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1713 glEnd; 1722 glEnd;
1723
1724 if ($t3) {
1725 glBindTexture GL_TEXTURE_2D, $t3->{name};
1726 glBegin GL_QUADS;
1727 glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2;
1728 glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h};
1729 glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h};
1730 glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2;
1731 glEnd;
1732 }
1714 1733
1715 glDisable GL_BLEND; 1734 glDisable GL_BLEND;
1716 glDisable GL_TEXTURE_2D; 1735 glDisable GL_TEXTURE_2D;
1717} 1736}
1718 1737
1728 my $self = $class->SUPER::new ( 1747 my $self = $class->SUPER::new (
1729 tooltip => $arg{type}, 1748 tooltip => $arg{type},
1730 %arg, 1749 %arg,
1731 ); 1750 );
1732 1751
1733 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999"); 1752 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1);
1734 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1753 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1);
1735 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999"); 1754 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1);
1736 1755
1737 $self 1756 $self
1738} 1757}
1739 1758
1740sub set_fontsize { 1759sub set_fontsize {
1907sub new { 1926sub new {
1908 my $class = shift; 1927 my $class = shift;
1909 1928
1910 my $self = $class->SUPER::new ( 1929 my $self = $class->SUPER::new (
1911 fontsize => 1, 1930 fontsize => 1,
1931 #font => default_font
1912 @_, 1932 @_,
1913 1933
1914 layout => (new CFClient::Layout), 1934 layout => (new CFClient::Layout),
1915 par => [], 1935 par => [],
1916 height => 0, 1936 height => 0,
1956sub size_allocate { 1976sub size_allocate {
1957 my ($self, $w, $h) = @_; 1977 my ($self, $w, $h) = @_;
1958 1978
1959 $self->SUPER::size_allocate ($w, $h); 1979 $self->SUPER::size_allocate ($w, $h);
1960 1980
1981 $self->{layout}->set_font ($self->{font}) if $self->{font};
1961 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1982 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1962 $self->{layout}->set_width ($self->{children}[0]{w}); 1983 $self->{layout}->set_width ($self->{children}[0]{w});
1963 1984
1964 $self->reflow; 1985 $self->reflow;
1965} 1986}
2017 my $y1 = $top + $self->{h}; 2038 my $y1 = $top + $self->{h};
2018 2039
2019 my $y = 0; 2040 my $y = 0;
2020 2041
2021 my $layout = $self->{layout}; 2042 my $layout = $self->{layout};
2043
2044 $layout->set_font ($self->{font}) if $self->{font};
2022 2045
2023 for my $par (@{$self->{par}}) { 2046 for my $par (@{$self->{par}}) {
2024 my $h = $par->[0]; 2047 my $h = $par->[0];
2025 2048
2026 if ($y0 < $y + $h && $y < $y1) { 2049 if ($y0 < $y + $h && $y < $y1) {
2162} 2185}
2163 2186
2164sub size_request { 2187sub size_request {
2165 my ($self) = @_; 2188 my ($self) = @_;
2166 2189
2190 $self->child->set_max_size ($::WIDTH * 0.2);
2191
2167 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2192 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 2193
2172 ($w + 4, $h + 4) 2194 ($w + 4, $h + 4)
2173} 2195}
2174 2196
2175sub _draw { 2197sub _draw {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines