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.162 by root, Mon Apr 24 06:05:35 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};
25 25
26 $tip = $tip->($widget) if CODE:: eq ref $tip; 26 $tip = $tip->($widget) if CODE:: eq ref $tip;
27 27
28 $TOOLTIP->set_text ($widget->{tooltip}); 28 $TOOLTIP->set_markup ($widget->{tooltip});
29 $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0)); 29 $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0));
30 $TOOLTIP->show; 30 $TOOLTIP->show;
31 } 31 }
32 32
33 return; 33 return;
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";
308 glVertex $x + $self->{w}, $y + $self->{h}; 320 glVertex $x + $self->{w}, $y + $self->{h};
309 glVertex $x , $y + $self->{h}; 321 glVertex $x , $y + $self->{h};
310 glEnd; 322 glEnd;
311 glDisable GL_BLEND; 323 glDisable GL_BLEND;
312 } 324 }
325
326 if ($ENV{PCLIENT_DEBUG}) {
327 glPushMatrix;
328 glColor 1, 1, 0, 1;
329 glTranslate $self->{x} + 0.375, $self->{y} + 0.375;
330 glBegin GL_LINE_LOOP;
331 glVertex 0 , 0;
332 glVertex $self->{w}, 0;
333 glVertex $self->{w}, $self->{h};
334 glVertex 0 , $self->{h};
335 glEnd;
336 glPopMatrix;
337 CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
338 }
313} 339}
314 340
315sub _draw { 341sub _draw {
316 my ($self) = @_; 342 my ($self) = @_;
317 343
337} 363}
338 364
339sub check_size { 365sub check_size {
340 my ($self) = @_; 366 my ($self) = @_;
341 367
342 return unless $self->{parent}; 368 $self->{parent}
369 or return 1;
343 370
344 my ($w, $h) = $self->size_request; 371 my ($w, $h) = $self->{user_w} && $self->{user_h}
372 ? @$self{qw(user_w user_h)}
373 : $self->size_request;
345 374
346 if ($w != $self->{req_w} || $h != $self->{req_h}) { 375 if ($w != $self->{req_w} || $h != $self->{req_h}) {
347 $self->{req_w} = $w; 376 $self->{req_w} = $w;
348 $self->{req_h} = $h; 377 $self->{req_h} = $h;
349 378
350 $self->{parent}->check_size; 379 $self->{parent}->check_size
380 or $self->size_allocate (
381 (List::Util::max $self->{w}, $w),
382 (List::Util::max $self->{h}, $h),
383 );
384
385 1
386 } else {
387 0
351 } 388 }
352} 389}
353 390
354sub update { 391sub update {
355 my ($self) = @_; 392 my ($self) = @_;
476 513
477 $self->check_size; 514 $self->check_size;
478 $self->update; 515 $self->update;
479} 516}
480 517
518sub clear {
519 my ($self) = @_;
520
521 delete $_->{parent}
522 for @{ delete $self->{children} };
523
524 $self->{children} = [];
525}
526
481sub find_widget { 527sub find_widget {
482 my ($self, $x, $y) = @_; 528 my ($self, $x, $y) = @_;
483 529
484 $x -= $self->{x}; 530 $x -= $self->{x};
485 $y -= $self->{y}; 531 $y -= $self->{y};
643 border => 0.8, 689 border => 0.8,
644 @_ 690 @_
645 ); 691 );
646 692
647 $self 693 $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} 694}
668 695
669sub _draw { 696sub _draw {
670 my ($self) = @_; 697 my ($self) = @_;
671 698
728 int $_[0]{border} * $::FONTSIZE 755 int $_[0]{border} * $::FONTSIZE
729} 756}
730 757
731sub size_request { 758sub size_request {
732 my ($self) = @_; 759 my ($self) = @_;
733
734 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
735 760
736 my ($w, $h) = $self->SUPER::size_request; 761 my ($w, $h) = $self->SUPER::size_request;
737 762
738 ( 763 (
739 $w + $self->border * 2, 764 $w + $self->border * 2,
1129 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1154 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
1130 1155
1131 $self 1156 $self
1132} 1157}
1133 1158
1134sub escape_text { 1159sub escape {
1135 local $_ = $_[1]; 1160 local $_ = $_[1];
1136 1161
1137 s/&/&/g; 1162 s/&/&/g;
1138 s/>/>/g; 1163 s/>/>/g;
1139 s/</&lt;/g; 1164 s/</&lt;/g;
1616 1641
1617package CFClient::UI::VGauge; 1642package CFClient::UI::VGauge;
1618 1643
1619our @ISA = CFClient::UI::Base::; 1644our @ISA = CFClient::UI::Base::;
1620 1645
1646use List::Util qw(min max);
1647
1621use CFClient::OpenGL; 1648use CFClient::OpenGL;
1622 1649
1623my %tex = ( 1650my %tex = (
1624 food => [ 1651 food => [
1625 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1652 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1626 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1653 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1627 ], 1654 ],
1628 grace => [ 1655 grace => [
1629 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1656 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1630 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1657 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
1631 ], 1658 ],
1632 hp => [ 1659 hp => [
1633 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1660 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1634 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1661 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1635 ], 1662 ],
1636 mana => [ 1663 mana => [
1637 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1664 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1638 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1665 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
1639 ], 1666 ],
1640); 1667);
1641 1668
1642# eg. VGauge->new (gauge => 'food'), default gauge: food 1669# eg. VGauge->new (gauge => 'food'), default gauge: food
1643sub new { 1670sub new {
1681 1708
1682sub _draw { 1709sub _draw {
1683 my ($self) = @_; 1710 my ($self) = @_;
1684 1711
1685 my $tex = $tex{$self->{type}}; 1712 my $tex = $tex{$self->{type}};
1713 my ($t1, $t2, $t3) = @$tex;
1686 1714
1687 my ($w, $h) = ($self->{w}, $self->{h}); 1715 my ($w, $h) = ($self->{w}, $self->{h});
1688 1716
1689 if ($self->{vertical}) { 1717 if ($self->{vertical}) {
1690 glRotate 90, 0, 0, 1; 1718 glRotate 90, 0, 0, 1;
1692 1720
1693 ($w, $h) = ($h, $w); 1721 ($w, $h) = ($h, $w);
1694 } 1722 }
1695 1723
1696 my $ycut = $self->{val} / ($self->{max_val} || 1); 1724 my $ycut = $self->{val} / ($self->{max_val} || 1);
1697 $ycut = 1 if $self->{val} > $self->{max_val};
1698 1725
1699 my $t1 = $tex->[0]; 1726 my $ycut1 = max 0, min 1, $ycut;
1700 my $t2 = $tex->[1]; 1727 my $ycut2 = max 0, min 1, $ycut - 1;
1728
1729 my $h1 = $self->{h} * (1 - $ycut1);
1730 my $h2 = $self->{h} * (1 - $ycut2);
1701 1731
1702 glEnable GL_BLEND; 1732 glEnable GL_BLEND;
1703 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1733 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1704 glEnable GL_TEXTURE_2D; 1734 glEnable GL_TEXTURE_2D;
1705 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1735 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1706 1736
1707 my $h1 = $self->{h} - $ycut * $self->{h};
1708 my $h2 = $ycut * $self->{h};
1709
1710 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1737 glBindTexture GL_TEXTURE_2D, $t1->{name};
1711 glBegin GL_QUADS; 1738 glBegin GL_QUADS;
1712 glTexCoord 0 , 0; glVertex 0 , 0; 1739 glTexCoord 0 , 0; glVertex 0 , 0;
1713 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1740 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1714 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1741 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1715 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1742 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1716 glEnd; 1743 glEnd;
1717 1744
1745 my $ycut1 = List::Util::min 1, $ycut;
1718 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1746 glBindTexture GL_TEXTURE_2D, $t2->{name};
1719 glBegin GL_QUADS; 1747 glBegin GL_QUADS;
1720 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1748 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1721 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1749 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1722 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1750 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1723 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1751 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1724 glEnd; 1752 glEnd;
1753
1754 if ($t3) {
1755 glBindTexture GL_TEXTURE_2D, $t3->{name};
1756 glBegin GL_QUADS;
1757 glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2;
1758 glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h};
1759 glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h};
1760 glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2;
1761 glEnd;
1762 }
1725 1763
1726 glDisable GL_BLEND; 1764 glDisable GL_BLEND;
1727 glDisable GL_TEXTURE_2D; 1765 glDisable GL_TEXTURE_2D;
1728} 1766}
1729 1767
1736sub new { 1774sub new {
1737 my ($class, %arg) = @_; 1775 my ($class, %arg) = @_;
1738 1776
1739 my $self = $class->SUPER::new ( 1777 my $self = $class->SUPER::new (
1740 tooltip => $arg{type}, 1778 tooltip => $arg{type},
1779 can_events => 1,
1780 can_hover => 1,
1741 %arg, 1781 %arg,
1742 ); 1782 );
1743 1783
1744 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); 1784 $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); 1785 $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); 1786 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1747 1787
1748 $self 1788 $self
1749} 1789}
1750 1790
1751sub set_fontsize { 1791sub set_fontsize {
2166 @_, 2206 @_,
2167 can_events => 0, 2207 can_events => 0,
2168 ) 2208 )
2169} 2209}
2170 2210
2171sub set_text { 2211sub set_markup {
2172 my ($self, $text) = @_; 2212 my ($self, $text) = @_;
2173 2213
2174 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; 2214 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2175 $self->{label}->set_text ($text); 2215 $self->{label}->set_markup ($text);
2176 $self->add ($self->{label}); 2216 $self->add ($self->{label});
2177} 2217}
2178 2218
2179sub size_request { 2219sub size_request {
2180 my ($self) = @_; 2220 my ($self) = @_;
2181 2221
2182 $self->child->set_max_size ($::WIDTH * 0.2); 2222 $self->child->set_max_size ($::WIDTH * 0.3);
2183 2223
2184 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2224 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2185 2225
2186 ($w + 4, $h + 4) 2226 ($w + 4, $h + 4)
2227}
2228
2229sub size_allocate {
2230 my ($self, $w, $h) = @_;
2231
2232 $self->SUPER::size_allocate ($w - 4, $h - 4);
2187} 2233}
2188 2234
2189sub _draw { 2235sub _draw {
2190 my ($self) = @_; 2236 my ($self) = @_;
2191 2237
2216 $self->SUPER::_draw; 2262 $self->SUPER::_draw;
2217} 2263}
2218 2264
2219############################################################################# 2265#############################################################################
2220 2266
2267package CFClient::UI::Face;
2268
2269our @ISA = CFClient::UI::Base::;
2270
2271use CFClient::OpenGL;
2272
2273sub new {
2274 my $class = shift;
2275
2276 $class->SUPER::new (
2277 aspect => 1,
2278 @_,
2279 )
2280}
2281
2282sub size_request {
2283 (32, 8)
2284}
2285
2286sub draw {
2287 my ($self) = @_;
2288
2289 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2290
2291 if ($tex) {
2292 glEnable GL_BLEND;
2293 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2294 glEnable GL_TEXTURE_2D;
2295 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2296 glColor 1, 1, 1, 1;
2297 $tex->draw_quad (0, 0, $self->{w}, $self->{h});
2298 glDisable GL_TEXTURE_2D;
2299 glDisable GL_BLEND;
2300 }
2301}
2302
2303#############################################################################
2304
2221package CFClient::UI::Root; 2305package CFClient::UI::Root;
2222 2306
2223our @ISA = CFClient::UI::Container::; 2307our @ISA = CFClient::UI::Container::;
2224 2308
2225use CFClient::OpenGL; 2309use CFClient::OpenGL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines