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.157 by root, Sun Apr 23 21:47:32 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";
337} 349}
338 350
339sub check_size { 351sub check_size {
340 my ($self) = @_; 352 my ($self) = @_;
341 353
342 return unless $self->{parent}; 354 $self->{parent}
355 or return 1;
343 356
344 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;
345 360
346 if ($w != $self->{req_w} || $h != $self->{req_h}) { 361 if ($w != $self->{req_w} || $h != $self->{req_h}) {
347 $self->{req_w} = $w; 362 $self->{req_w} = $w;
348 $self->{req_h} = $h; 363 $self->{req_h} = $h;
349 364
350 $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
351 } 374 }
352} 375}
353 376
354sub update { 377sub update {
355 my ($self) = @_; 378 my ($self) = @_;
643 border => 0.8, 666 border => 0.8,
644 @_ 667 @_
645 ); 668 );
646 669
647 $self 670 $self
648}
649
650sub set_size {
651 my ($self, $w, $h) = @_;
652 $self->{req_w} = $w;
653 $self->{req_h} = $h;
654 $self->check_size;
655}
656
657sub size_request {
658 my ($self) = @_;
659 ($self->{req_w}, $self->{req_h})
660}
661
662sub size_allocate {
663 my ($self, $w, $h) = @_;
664 $self->{w} = $w;
665 $self->{h} = $h;
666 $self->child->configure (0, 0, $w, $h);
667} 671}
668 672
669sub _draw { 673sub _draw {
670 my ($self) = @_; 674 my ($self) = @_;
671 675
728 int $_[0]{border} * $::FONTSIZE 732 int $_[0]{border} * $::FONTSIZE
729} 733}
730 734
731sub size_request { 735sub size_request {
732 my ($self) = @_; 736 my ($self) = @_;
733
734 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
735 737
736 my ($w, $h) = $self->SUPER::size_request; 738 my ($w, $h) = $self->SUPER::size_request;
737 739
738 ( 740 (
739 $w + $self->border * 2, 741 $w + $self->border * 2,
1616 1618
1617package CFClient::UI::VGauge; 1619package CFClient::UI::VGauge;
1618 1620
1619our @ISA = CFClient::UI::Base::; 1621our @ISA = CFClient::UI::Base::;
1620 1622
1623use List::Util qw(min max);
1624
1621use CFClient::OpenGL; 1625use CFClient::OpenGL;
1622 1626
1623my %tex = ( 1627my %tex = (
1624 food => [ 1628 food => [
1625 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1629 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1626 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1630 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1627 ], 1631 ],
1628 grace => [ 1632 grace => [
1629 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1633 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1630 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/
1631 ], 1635 ],
1632 hp => [ 1636 hp => [
1633 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1637 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1634 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1638 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1635 ], 1639 ],
1636 mana => [ 1640 mana => [
1637 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1641 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1638 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/
1639 ], 1643 ],
1640); 1644);
1641 1645
1642# eg. VGauge->new (gauge => 'food'), default gauge: food 1646# eg. VGauge->new (gauge => 'food'), default gauge: food
1643sub new { 1647sub new {
1681 1685
1682sub _draw { 1686sub _draw {
1683 my ($self) = @_; 1687 my ($self) = @_;
1684 1688
1685 my $tex = $tex{$self->{type}}; 1689 my $tex = $tex{$self->{type}};
1690 my ($t1, $t2, $t3) = @$tex;
1686 1691
1687 my ($w, $h) = ($self->{w}, $self->{h}); 1692 my ($w, $h) = ($self->{w}, $self->{h});
1688 1693
1689 if ($self->{vertical}) { 1694 if ($self->{vertical}) {
1690 glRotate 90, 0, 0, 1; 1695 glRotate 90, 0, 0, 1;
1692 1697
1693 ($w, $h) = ($h, $w); 1698 ($w, $h) = ($h, $w);
1694 } 1699 }
1695 1700
1696 my $ycut = $self->{val} / ($self->{max_val} || 1); 1701 my $ycut = $self->{val} / ($self->{max_val} || 1);
1697 $ycut = 1 if $self->{val} > $self->{max_val};
1698 1702
1699 my $t1 = $tex->[0]; 1703 my $ycut1 = max 0, min 1, $ycut;
1700 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);
1701 1708
1702 glEnable GL_BLEND; 1709 glEnable GL_BLEND;
1703 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1710 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1704 glEnable GL_TEXTURE_2D; 1711 glEnable GL_TEXTURE_2D;
1705 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1706 1713
1707 my $h1 = $self->{h} - $ycut * $self->{h};
1708 my $h2 = $ycut * $self->{h};
1709
1710 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1714 glBindTexture GL_TEXTURE_2D, $t1->{name};
1711 glBegin GL_QUADS; 1715 glBegin GL_QUADS;
1712 glTexCoord 0 , 0; glVertex 0 , 0; 1716 glTexCoord 0 , 0; glVertex 0 , 0;
1713 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1717 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1714 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1718 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1715 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1719 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1716 glEnd; 1720 glEnd;
1717 1721
1722 my $ycut1 = List::Util::min 1, $ycut;
1718 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1723 glBindTexture GL_TEXTURE_2D, $t2->{name};
1719 glBegin GL_QUADS; 1724 glBegin GL_QUADS;
1720 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1725 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1721 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1726 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1722 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1727 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1723 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1728 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1724 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 }
1725 1740
1726 glDisable GL_BLEND; 1741 glDisable GL_BLEND;
1727 glDisable GL_TEXTURE_2D; 1742 glDisable GL_TEXTURE_2D;
1728} 1743}
1729 1744
1736sub new { 1751sub new {
1737 my ($class, %arg) = @_; 1752 my ($class, %arg) = @_;
1738 1753
1739 my $self = $class->SUPER::new ( 1754 my $self = $class->SUPER::new (
1740 tooltip => $arg{type}, 1755 tooltip => $arg{type},
1756 can_events => 1,
1757 can_hover => 1,
1741 %arg, 1758 %arg,
1742 ); 1759 );
1743 1760
1744 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); 1761 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1745 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1); 1762 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1746 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1); 1763 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1747 1764
1748 $self 1765 $self
1749} 1766}
1750 1767
1751sub set_fontsize { 1768sub set_fontsize {
2177} 2194}
2178 2195
2179sub size_request { 2196sub size_request {
2180 my ($self) = @_; 2197 my ($self) = @_;
2181 2198
2182 $self->child->set_max_size ($::WIDTH * 0.2); 2199 $self->child->set_max_size ($::WIDTH * 0.3);
2183 2200
2184 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2201 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2185 2202
2186 ($w + 4, $h + 4) 2203 ($w + 4, $h + 4)
2187} 2204}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines