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.150 by elmex, Sun Apr 23 00:08:29 2006 UTC vs.
Revision 1.162 by root, Mon Apr 24 06:05:35 2006 UTC

8use CFClient; 8use CFClient;
9 9
10our ($FOCUS, $HOVER, $GRAB); # various widgets 10our ($FOCUS, $HOVER, $GRAB); # various widgets
11 11
12our $ROOT; 12our $ROOT;
13our $TOOLTIP;
13our $BUTTON_STATE; 14our $BUTTON_STATE;
15
16sub check_tooltip {
17 if (!$GRAB) {
18 for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) {
19 if (length $widget->{tooltip}) {
20
21 if ($TOOLTIP->{owner} != $widget) {
22 $TOOLTIP->{owner} = $widget;
23
24 my $tip = $widget->{tooltip};
25
26 $tip = $tip->($widget) if CODE:: eq ref $tip;
27
28 $TOOLTIP->set_markup ($widget->{tooltip});
29 $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0));
30 $TOOLTIP->show;
31 }
32
33 return;
34 }
35 }
36 }
37
38 $TOOLTIP->hide;
39 delete $TOOLTIP->{owner};
40}
14 41
15# class methods for events 42# class methods for events
16sub feed_sdl_key_down_event { 43sub feed_sdl_key_down_event {
17 $FOCUS->key_down ($_[0]) if $FOCUS; 44 $FOCUS->key_down ($_[0]) if $FOCUS;
18} 45}
28 if (!$BUTTON_STATE) { 55 if (!$BUTTON_STATE) {
29 my $widget = $ROOT->find_widget ($x, $y); 56 my $widget = $ROOT->find_widget ($x, $y);
30 57
31 $GRAB = $widget; 58 $GRAB = $widget;
32 $GRAB->update if $GRAB; 59 $GRAB->update if $GRAB;
60
61 check_tooltip;
33 } 62 }
34 63
35 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 64 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
36 65
37 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 66 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
49 78
50 if (!$BUTTON_STATE) { 79 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 80 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 81 $grab->update if $grab;
53 $GRAB->update if $GRAB; 82 $GRAB->update if $GRAB;
83
84 check_tooltip;
54 } 85 }
55} 86}
56 87
57sub feed_sdl_motion_event { 88sub feed_sdl_motion_event {
58 my ($ev) = @_; 89 my ($ev) = @_;
63 if ($widget != $HOVER) { 94 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget; 95 my $hover = $HOVER; $HOVER = $widget;
65 96
66 $hover->update if $hover && $hover->{can_hover}; 97 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER && $HOVER->{can_hover}; 98 $HOVER->update if $HOVER && $HOVER->{can_hover};
99
100 check_tooltip;
68 } 101 }
69 102
70 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; 103 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER;
71} 104}
72 105
109 } 142 }
110 143
111 $self 144 $self
112} 145}
113 146
147sub destroy {
148 my ($self) = @_;
149
150 $self->hide;
151 %$self = ();
152}
153
114sub show { 154sub show {
115 my ($self) = @_; 155 my ($self) = @_;
116 156
117 return if $self->{parent}; 157 return if $self->{parent};
118 158
135 $self->{z} = $z if defined $z; 175 $self->{z} = $z if defined $z;
136 176
137 $self->update; 177 $self->update;
138} 178}
139 179
140sub needs_redraw { 180sub set_size {
141 0 181 my ($self, $w, $h) = @_;
182
183 $self->{user_w} = $w;
184 $self->{user_h} = $h;
185
186 $self->check_size;
142} 187}
143 188
144sub size_request { 189sub size_request {
145 require Carp; 190 require Carp;
146 Carp::confess "size_request is abstract"; 191 Carp::confess "size_request is abstract";
176 } 221 }
177} 222}
178 223
179sub size_allocate { 224sub size_allocate {
180 # 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;
181} 233}
182 234
183# return top left coordinates 235# return top left coordinates
184sub _topleft { 236sub _topleft {
185 my ($self, $x, $y) = @_; 237 my ($self, $x, $y) = @_;
268 glVertex $x + $self->{w}, $y + $self->{h}; 320 glVertex $x + $self->{w}, $y + $self->{h};
269 glVertex $x , $y + $self->{h}; 321 glVertex $x , $y + $self->{h};
270 glEnd; 322 glEnd;
271 glDisable GL_BLEND; 323 glDisable GL_BLEND;
272 } 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 }
273} 339}
274 340
275sub _draw { 341sub _draw {
276 my ($self) = @_; 342 my ($self) = @_;
277 343
297} 363}
298 364
299sub check_size { 365sub check_size {
300 my ($self) = @_; 366 my ($self) = @_;
301 367
302 return unless $self->{parent}; 368 $self->{parent}
369 or return 1;
303 370
304 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;
305 374
306 if ($w != $self->{req_w} || $h != $self->{req_h}) { 375 if ($w != $self->{req_w} || $h != $self->{req_h}) {
307 $self->{req_w} = $w; 376 $self->{req_w} = $w;
308 $self->{req_h} = $h; 377 $self->{req_h} = $h;
309 378
310 $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
311 } 388 }
312} 389}
313 390
314sub update { 391sub update {
315 my ($self) = @_; 392 my ($self) = @_;
433 delete $child->{parent}; 510 delete $child->{parent};
434 511
435 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 512 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
436 513
437 $self->check_size; 514 $self->check_size;
515 $self->update;
516}
517
518sub clear {
519 my ($self) = @_;
520
521 delete $_->{parent}
522 for @{ delete $self->{children} };
523
524 $self->{children} = [];
438} 525}
439 526
440sub find_widget { 527sub find_widget {
441 my ($self, $x, $y) = @_; 528 my ($self, $x, $y) = @_;
442 529
602 border => 0.8, 689 border => 0.8,
603 @_ 690 @_
604 ); 691 );
605 692
606 $self 693 $self
607}
608
609sub set_size {
610 my ($self, $w, $h) = @_;
611 $self->{req_w} = $w;
612 $self->{req_h} = $h;
613 $self->check_size;
614}
615
616sub size_request {
617 my ($self) = @_;
618 ($self->{req_w}, $self->{req_h})
619}
620
621sub size_allocate {
622 my ($self, $w, $h) = @_;
623 $self->{w} = $w;
624 $self->{h} = $h;
625 $self->child->configure (0, 0, $w, $h);
626} 694}
627 695
628sub _draw { 696sub _draw {
629 my ($self) = @_; 697 my ($self) = @_;
630 698
687 int $_[0]{border} * $::FONTSIZE 755 int $_[0]{border} * $::FONTSIZE
688} 756}
689 757
690sub size_request { 758sub size_request {
691 my ($self) = @_; 759 my ($self) = @_;
692
693 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
694 760
695 my ($w, $h) = $self->SUPER::size_request; 761 my ($w, $h) = $self->SUPER::size_request;
696 762
697 ( 763 (
698 $w + $self->border * 2, 764 $w + $self->border * 2,
1065sub new { 1131sub new {
1066 my ($class, %arg) = @_; 1132 my ($class, %arg) = @_;
1067 1133
1068 my $self = $class->SUPER::new ( 1134 my $self = $class->SUPER::new (
1069 fg => [1, 1, 1], 1135 fg => [1, 1, 1],
1136 #font => default_font
1070 fontsize => 1, 1137 fontsize => 1,
1071 text => "", 1138 text => "",
1072 align => -1, 1139 align => -1,
1073 valign => -1, 1140 valign => -1,
1074 padding => 2, 1141 padding => 2,
1087 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1154 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
1088 1155
1089 $self 1156 $self
1090} 1157}
1091 1158
1092sub escape_text { 1159sub escape {
1093 local $_ = $_[1]; 1160 local $_ = $_[1];
1094 1161
1095 s/&/&amp;/g; 1162 s/&/&amp;/g;
1096 s/>/&gt;/g; 1163 s/>/&gt;/g;
1097 s/</&lt;/g; 1164 s/</&lt;/g;
1120} 1187}
1121 1188
1122sub size_request { 1189sub size_request {
1123 my ($self) = @_; 1190 my ($self) = @_;
1124 1191
1125 $self->{layout}->set_width; 1192 $self->{layout}->set_font ($self->{font}) if $self->{font};
1193 $self->{layout}->set_width ($self->{max_w} || -1);
1126 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1194 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1127 1195
1128 my ($w, $h) = $self->{layout}->size; 1196 my ($w, $h) = $self->{layout}->size;
1129 1197
1130 if (exists $self->{template}) { 1198 if (exists $self->{template}) {
1199 $self->{template}->set_font ($self->{font}) if $self->{font};
1131 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1200 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1132 1201
1133 my ($w2, $h2) = $self->{template}->size; 1202 my ($w2, $h2) = $self->{template}->size;
1134 1203
1135 $w = List::Util::max $w, $w2; 1204 $w = List::Util::max $w, $w2;
1150 1219
1151sub set_fontsize { 1220sub set_fontsize {
1152 my ($self, $fontsize) = @_; 1221 my ($self, $fontsize) = @_;
1153 1222
1154 $self->{fontsize} = $fontsize; 1223 $self->{fontsize} = $fontsize;
1224 delete $self->{texture};
1155 $self->check_size; 1225 $self->check_size;
1226 $self->update;
1156} 1227}
1157 1228
1158sub _draw { 1229sub _draw {
1159 my ($self) = @_; 1230 my ($self) = @_;
1160 1231
1161 my $tex = $self->{texture} ||= do { 1232 my $tex = $self->{texture} ||= do {
1233 $self->{layout}->set_font ($self->{font}) if $self->{font};
1162 $self->{layout}->set_width ($self->{w}); 1234 $self->{layout}->set_width ($self->{w});
1163 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1235 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1164 new_from_layout CFClient::Texture $self->{layout} 1236 new_from_layout CFClient::Texture $self->{layout}
1165 }; 1237 };
1166 1238
1569 1641
1570package CFClient::UI::VGauge; 1642package CFClient::UI::VGauge;
1571 1643
1572our @ISA = CFClient::UI::Base::; 1644our @ISA = CFClient::UI::Base::;
1573 1645
1646use List::Util qw(min max);
1647
1574use CFClient::OpenGL; 1648use CFClient::OpenGL;
1575 1649
1576my %tex = ( 1650my %tex = (
1577 food => [ 1651 food => [
1578 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1652 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1579 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1653 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1580 ], 1654 ],
1581 grace => [ 1655 grace => [
1582 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1656 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1583 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/
1584 ], 1658 ],
1585 hp => [ 1659 hp => [
1586 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1660 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1587 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1661 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1588 ], 1662 ],
1589 mana => [ 1663 mana => [
1590 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1664 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1591 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/
1592 ], 1666 ],
1593); 1667);
1594 1668
1595# eg. VGauge->new (gauge => 'food'), default gauge: food 1669# eg. VGauge->new (gauge => 'food'), default gauge: food
1596sub new { 1670sub new {
1634 1708
1635sub _draw { 1709sub _draw {
1636 my ($self) = @_; 1710 my ($self) = @_;
1637 1711
1638 my $tex = $tex{$self->{type}}; 1712 my $tex = $tex{$self->{type}};
1713 my ($t1, $t2, $t3) = @$tex;
1639 1714
1640 my ($w, $h) = ($self->{w}, $self->{h}); 1715 my ($w, $h) = ($self->{w}, $self->{h});
1641 1716
1642 if ($self->{vertical}) { 1717 if ($self->{vertical}) {
1643 glRotate 90, 0, 0, 1; 1718 glRotate 90, 0, 0, 1;
1645 1720
1646 ($w, $h) = ($h, $w); 1721 ($w, $h) = ($h, $w);
1647 } 1722 }
1648 1723
1649 my $ycut = $self->{val} / ($self->{max_val} || 1); 1724 my $ycut = $self->{val} / ($self->{max_val} || 1);
1650 $ycut = 1 if $self->{val} > $self->{max_val};
1651 1725
1652 my $t1 = $tex->[0]; 1726 my $ycut1 = max 0, min 1, $ycut;
1653 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);
1654 1731
1655 glEnable GL_BLEND; 1732 glEnable GL_BLEND;
1656 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1733 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1657 glEnable GL_TEXTURE_2D; 1734 glEnable GL_TEXTURE_2D;
1658 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1735 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1659 1736
1660 my $h1 = $self->{h} - $ycut * $self->{h};
1661 my $h2 = $ycut * $self->{h};
1662
1663 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1737 glBindTexture GL_TEXTURE_2D, $t1->{name};
1664 glBegin GL_QUADS; 1738 glBegin GL_QUADS;
1665 glTexCoord 0 , 0; glVertex 0 , 0; 1739 glTexCoord 0 , 0; glVertex 0 , 0;
1666 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1740 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1667 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1741 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1668 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1742 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1669 glEnd; 1743 glEnd;
1670 1744
1745 my $ycut1 = List::Util::min 1, $ycut;
1671 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1746 glBindTexture GL_TEXTURE_2D, $t2->{name};
1672 glBegin GL_QUADS; 1747 glBegin GL_QUADS;
1673 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1748 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1674 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1749 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1675 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1750 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1676 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1751 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1677 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 }
1678 1763
1679 glDisable GL_BLEND; 1764 glDisable GL_BLEND;
1680 glDisable GL_TEXTURE_2D; 1765 glDisable GL_TEXTURE_2D;
1681} 1766}
1682 1767
1685package CFClient::UI::Gauge; 1770package CFClient::UI::Gauge;
1686 1771
1687our @ISA = CFClient::UI::VBox::; 1772our @ISA = CFClient::UI::VBox::;
1688 1773
1689sub new { 1774sub new {
1690 my ($class, %arg) = shift; 1775 my ($class, %arg) = @_;
1691 1776
1692 my $self = $class->SUPER::new ( 1777 my $self = $class->SUPER::new (
1693 @_, 1778 tooltip => $arg{type},
1779 can_events => 1,
1780 can_hover => 1,
1781 %arg,
1694 ); 1782 );
1695 1783
1696 $self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"; 1784 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1785 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1697 $self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"; 1786 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1698 $self->add ($self->{value});
1699 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1700 $self->add ($self->{max});
1701 1787
1702 $self 1788 $self
1703}
1704
1705sub size_request {
1706 my ($self) = @_;
1707 (($self->{max}->size_request)[0], 0)
1708} 1789}
1709 1790
1710sub set_fontsize { 1791sub set_fontsize {
1711 my ($self, $fsize) = @_; 1792 my ($self, $fsize) = @_;
1712 1793
1877sub new { 1958sub new {
1878 my $class = shift; 1959 my $class = shift;
1879 1960
1880 my $self = $class->SUPER::new ( 1961 my $self = $class->SUPER::new (
1881 fontsize => 1, 1962 fontsize => 1,
1963 #font => default_font
1882 @_, 1964 @_,
1883 1965
1884 layout => (new CFClient::Layout), 1966 layout => (new CFClient::Layout),
1885 par => [], 1967 par => [],
1886 height => 0, 1968 height => 0,
1926sub size_allocate { 2008sub size_allocate {
1927 my ($self, $w, $h) = @_; 2009 my ($self, $w, $h) = @_;
1928 2010
1929 $self->SUPER::size_allocate ($w, $h); 2011 $self->SUPER::size_allocate ($w, $h);
1930 2012
2013 $self->{layout}->set_font ($self->{font}) if $self->{font};
1931 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 2014 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1932 $self->{layout}->set_width ($self->{children}[0]{w}); 2015 $self->{layout}->set_width ($self->{children}[0]{w});
1933 2016
1934 $self->reflow; 2017 $self->reflow;
1935} 2018}
1987 my $y1 = $top + $self->{h}; 2070 my $y1 = $top + $self->{h};
1988 2071
1989 my $y = 0; 2072 my $y = 0;
1990 2073
1991 my $layout = $self->{layout}; 2074 my $layout = $self->{layout};
2075
2076 $layout->set_font ($self->{font}) if $self->{font};
1992 2077
1993 for my $par (@{$self->{par}}) { 2078 for my $par (@{$self->{par}}) {
1994 my $h = $par->[0]; 2079 my $h = $par->[0];
1995 2080
1996 if ($y0 < $y + $h && $y < $y1) { 2081 if ($y0 < $y + $h && $y < $y1) {
2106 $self->emit (changed => $self->{state}); 2191 $self->emit (changed => $self->{state});
2107} 2192}
2108 2193
2109############################################################################# 2194#############################################################################
2110 2195
2196package CFClient::UI::Tooltip;
2197
2198our @ISA = CFClient::UI::Bin::;
2199
2200use CFClient::OpenGL;
2201
2202sub new {
2203 my $class = shift;
2204
2205 $class->SUPER::new (
2206 @_,
2207 can_events => 0,
2208 )
2209}
2210
2211sub set_markup {
2212 my ($self, $text) = @_;
2213
2214 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2215 $self->{label}->set_markup ($text);
2216 $self->add ($self->{label});
2217}
2218
2219sub size_request {
2220 my ($self) = @_;
2221
2222 $self->child->set_max_size ($::WIDTH * 0.3);
2223
2224 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2225
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);
2233}
2234
2235sub _draw {
2236 my ($self) = @_;
2237
2238 glPushMatrix;
2239 glTranslate 0.375, 0.375;
2240
2241 my ($w, $h) = @$self{qw(w h)};
2242
2243 glColor 1, 0.8, 0.4;
2244 glBegin GL_QUADS;
2245 glVertex 0 , 0;
2246 glVertex 0 , $h;
2247 glVertex $w, $h;
2248 glVertex $w, 0;
2249 glEnd;
2250
2251 glColor 0, 0, 0;
2252 glBegin GL_LINE_LOOP;
2253 glVertex 0 , 0;
2254 glVertex 0 , $h;
2255 glVertex $w, $h;
2256 glVertex $w, 0;
2257 glEnd;
2258
2259 glPopMatrix;
2260
2261 glTranslate 2, 2;
2262 $self->SUPER::_draw;
2263}
2264
2265#############################################################################
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
2111package CFClient::UI::Root; 2305package CFClient::UI::Root;
2112 2306
2113our @ISA = CFClient::UI::Container::; 2307our @ISA = CFClient::UI::Container::;
2114 2308
2115use CFClient::OpenGL; 2309use CFClient::OpenGL;
2190############################################################################# 2384#############################################################################
2191 2385
2192package CFClient::UI; 2386package CFClient::UI;
2193 2387
2194$ROOT = new CFClient::UI::Root; 2388$ROOT = new CFClient::UI::Root;
2389$TOOLTIP = new CFClient::UI::Tooltip;
2195 2390
21961 23911
2197 2392

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines