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.158 by root, Mon Apr 24 02:41:48 2006 UTC vs.
Revision 1.173 by root, Tue Apr 25 10:30:48 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;
39 delete $TOOLTIP->{owner}; 39 delete $TOOLTIP->{owner};
40} 40}
41 41
42# class methods for events 42# class methods for events
43sub feed_sdl_key_down_event { 43sub feed_sdl_key_down_event {
44 $FOCUS->key_down ($_[0]) if $FOCUS; 44 $FOCUS->emit (key_down => $_[0]) || $FOCUS->key_down ($_[0])
45 if $FOCUS;
45} 46}
46 47
47sub feed_sdl_key_up_event { 48sub feed_sdl_key_up_event {
48 $FOCUS->key_up ($_[0]) if $FOCUS; 49 $FOCUS->emit (key_up => $_[0]) || $FOCUS->key_up ($_[0])
50 if $FOCUS;
49} 51}
50 52
51sub feed_sdl_button_down_event { 53sub feed_sdl_button_down_event {
52 my ($ev) = @_; 54 my ($ev) = @_;
53 my ($x, $y) = ($ev->{x}, $ev->{y}); 55 my ($x, $y) = ($ev->{x}, $ev->{y});
61 check_tooltip; 63 check_tooltip;
62 } 64 }
63 65
64 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 66 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
65 67
66 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 68 if ($GRAB) {
69 ($x, $y) = $GRAB->coord2local ($x, $y);
70 $GRAB->emit (button_down => $ev, $x, $y) || $GRAB->button_down ($ev, $x, $y);
71 }
67} 72}
68 73
69sub feed_sdl_button_up_event { 74sub feed_sdl_button_up_event {
70 my ($ev) = @_; 75 my ($ev) = @_;
71 my ($x, $y) = ($ev->{x}, $ev->{y}); 76 my ($x, $y) = ($ev->{x}, $ev->{y});
72 77
73 my $widget = $GRAB || $ROOT->find_widget ($x, $y); 78 my $widget = $GRAB || $ROOT->find_widget ($x, $y);
74 79
75 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1)); 80 $BUTTON_STATE &= ~(1 << ($ev->{button} - 1));
76 81
77 $GRAB->button_up ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 82 if ($GRAB) {
83 ($x, $y) = $GRAB->coord2local ($x, $y);
84 $GRAB->emit (button_up => $ev, $x, $y) || $GRAB->button_up ($ev, $x, $y);
85 }
78 86
79 if (!$BUTTON_STATE) { 87 if (!$BUTTON_STATE) {
80 my $grab = $GRAB; undef $GRAB; 88 my $grab = $GRAB; undef $GRAB;
81 $grab->update if $grab; 89 $grab->update if $grab;
82 $GRAB->update if $GRAB; 90 $GRAB->update if $GRAB;
98 $HOVER->update if $HOVER && $HOVER->{can_hover}; 106 $HOVER->update if $HOVER && $HOVER->{can_hover};
99 107
100 check_tooltip; 108 check_tooltip;
101 } 109 }
102 110
103 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; 111 if ($HOVER) {
112 ($x, $y) = $HOVER->coord2local ($x, $y);
113 $HOVER->emit (mouse_motion => $ev, $x, $y) || $HOVER->mouse_motion ($ev, $x, $y);
114 }
104} 115}
105 116
106# convert position array to integers 117# convert position array to integers
107sub harmonize { 118sub harmonize {
108 my ($vals) = @_; 119 my ($vals) = @_;
126 137
127sub new { 138sub new {
128 my $class = shift; 139 my $class = shift;
129 140
130 my $self = bless { 141 my $self = bless {
131 x => 0, 142 x => 0,
132 y => 0, 143 y => 0,
133 z => 0, 144 z => 0,
134 can_events => 1, 145 can_events => 1,
135 @_ 146 @_
136 }, $class; 147 }, $class;
137 148
138 for (keys %$self) { 149 for (keys %$self) {
142 } 153 }
143 154
144 $self 155 $self
145} 156}
146 157
158sub destroy {
159 my ($self) = @_;
160
161 $self->hide;
162 %$self = ();
163}
164
147sub show { 165sub show {
148 my ($self) = @_; 166 my ($self) = @_;
149 167
150 return if $self->{parent}; 168 return if $self->{parent};
151 169
153} 171}
154 172
155sub hide { 173sub hide {
156 my ($self) = @_; 174 my ($self) = @_;
157 175
158 return unless $self->{parent}; 176 undef $GRAB if $GRAB == $self;
177 undef $HOVER if $HOVER == $self;
159 178
160 $self->{parent}->remove ($self); 179 $self->{parent}->remove ($self)
180 if $self->{parent};
161} 181}
162 182
163sub move { 183sub move {
164 my ($self, $x, $y, $z) = @_; 184 my ($self, $x, $y, $z) = @_;
165 185
216 236
217sub size_allocate { 237sub size_allocate {
218 # nothing to be done 238 # nothing to be done
219} 239}
220 240
241sub children {
242}
243
244# call when resoltuion changes etc.
245sub reconfigure {
246 my ($self) = @_;
247
248 $_->reconfigure
249 for $self->children;
250
251 $_->check_size;
252}
253
221sub set_max_size { 254sub set_max_size {
222 my ($self, $w, $h) = @_; 255 my ($self, $w, $h) = @_;
223 256
224 delete $self->{max_w}; $self->{max_w} = $w if $w; 257 delete $self->{max_w}; $self->{max_w} = $w if $w;
225 delete $self->{max_h}; $self->{max_h} = $h if $h; 258 delete $self->{max_h}; $self->{max_h} = $h if $h;
226} 259}
227 260
228# return top left coordinates 261# return top left coordinates
229sub _topleft { 262sub _topleft {
230 my ($self, $x, $y) = @_; 263 my ($self, $x, $y) = @_;
264
265 $self->{parent}
266 or Carp::confess "no parent widget in _topleft\n";#d#
231 267
232 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y}); 268 $self->{parent}->_topleft ($x + $self->{x}, $y + $self->{y});
233} 269}
234 270
235# translate global coordinates to local coordinate system 271# translate global coordinates to local coordinate system
313 glVertex $x + $self->{w}, $y + $self->{h}; 349 glVertex $x + $self->{w}, $y + $self->{h};
314 glVertex $x , $y + $self->{h}; 350 glVertex $x , $y + $self->{h};
315 glEnd; 351 glEnd;
316 glDisable GL_BLEND; 352 glDisable GL_BLEND;
317 } 353 }
354
355 if ($ENV{PCLIENT_DEBUG}) {
356 glPushMatrix;
357 glColor 1, 1, 0, 1;
358 glTranslate $self->{x} + 0.375, $self->{y} + 0.375;
359 glBegin GL_LINE_LOOP;
360 glVertex 0 , 0;
361 glVertex $self->{w}, 0;
362 glVertex $self->{w}, $self->{h};
363 glVertex 0 , $self->{h};
364 glEnd;
365 glPopMatrix;
366 CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
367 }
318} 368}
319 369
320sub _draw { 370sub _draw {
321 my ($self) = @_; 371 my ($self) = @_;
322 372
381} 431}
382 432
383sub emit { 433sub emit {
384 my ($self, $signal, @args) = @_; 434 my ($self, $signal, @args) = @_;
385 435
386 for my $cb (@{$self->{signal_cb}{$signal} || []}) { 436 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}
387 $cb->($self, @args);
388 }
389} 437}
390 438
391sub DESTROY { 439sub DESTROY {
392 my ($self) = @_; 440 my ($self) = @_;
393 441
460sub new { 508sub new {
461 my ($class, %arg) = @_; 509 my ($class, %arg) = @_;
462 510
463 my $children = delete $arg{children} || []; 511 my $children = delete $arg{children} || [];
464 512
465 my $self = $class->SUPER::new (children => [], can_events => 0, %arg); 513 my $self = $class->SUPER::new (
514 children => [],
515 can_events => 0,
516 %arg,
517 );
466 $self->add ($_) for @$children; 518 $self->add ($_) for @$children;
467 519
468 $self 520 $self
469} 521}
470 522
481 ]; 533 ];
482 534
483 $child->check_size; 535 $child->check_size;
484} 536}
485 537
538sub children {
539 @{ $_[0]{children} }
540}
541
486sub remove { 542sub remove {
487 my ($self, $child) = @_; 543 my ($self, $child) = @_;
488 544
489 delete $child->{parent}; 545 delete $child->{parent};
546 $child->hide;
490 547
491 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 548 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
492 549
493 $self->check_size; 550 $self->check_size;
494 $self->update; 551 $self->update;
552}
553
554sub clear {
555 my ($self) = @_;
556
557 my $children = delete $self->{children};
558 $self->{children} = [];
559
560 for (@$children) {
561 delete $_->{parent};
562 $_->hide;
563 }
495} 564}
496 565
497sub find_widget { 566sub find_widget {
498 my ($self, $x, $y) = @_; 567 my ($self, $x, $y) = @_;
499 568
703 my $class = shift; 772 my $class = shift;
704 773
705 # TODO: user_x, user_y, overwrite moveto? 774 # TODO: user_x, user_y, overwrite moveto?
706 775
707 my $self = $class->SUPER::new ( 776 my $self = $class->SUPER::new (
708 bg => [1, 1, 1, 1], 777 bg => [1, 1, 1, 1],
709 border_bg => [1, 1, 1, 1], 778 border_bg => [1, 1, 1, 1],
710 border => 0.8, 779 border => 0.8,
711 can_events => 1, 780 can_events => 1,
712 @_ 781 @_
713 ); 782 );
714 783
715 $self->{title} &&= new CFClient::UI::Label 784 $self->{title} &&= new CFClient::UI::Label
863 $self->{children}[$y][$x] = $child; 932 $self->{children}[$y][$x] = $child;
864 933
865 $child->check_size; 934 $child->check_size;
866} 935}
867 936
937sub children {
938 grep $_, map @$_, grep $_, @{ $_[0]{children} }
939}
940
868# TODO: move to container class maybe? send childs a signal on removal? 941# TODO: move to container class maybe? send childs a signal on removal?
869sub clear { 942sub clear {
870 my ($self) = @_; 943 my ($self) = @_;
871 944
945 my @children = $self->children;
872 delete $self->{children}; 946 delete $self->{children};
947
948 for (@children) {
949 delete $_->{parent};
950 $_->hide;
951 }
952
873 $self->update; 953 $self->update;
874} 954}
875 955
876sub get_wh { 956sub get_wh {
877 my ($self) = @_; 957 my ($self) = @_;
1100 1180
1101sub new { 1181sub new {
1102 my ($class, %arg) = @_; 1182 my ($class, %arg) = @_;
1103 1183
1104 my $self = $class->SUPER::new ( 1184 my $self = $class->SUPER::new (
1105 fg => [1, 1, 1], 1185 fg => [1, 1, 1],
1106 #font => default_font 1186 #font => default_font
1107 fontsize => 1, 1187 fontsize => 1,
1108 text => "", 1188 text => "",
1109 align => -1, 1189 align => -1,
1110 valign => -1, 1190 valign => -1,
1111 padding => 2, 1191 padding => 2,
1112 layout => new CFClient::Layout, 1192 layout => new CFClient::Layout,
1113 can_events => 0, 1193 can_events => 0,
1114 %arg 1194 %arg
1115 ); 1195 );
1116 1196
1117 if (exists $self->{template}) { 1197 if (exists $self->{template}) {
1124 $self->set_markup (delete $self->{markup}) if exists $self->{markup}; 1204 $self->set_markup (delete $self->{markup}) if exists $self->{markup};
1125 1205
1126 $self 1206 $self
1127} 1207}
1128 1208
1129sub escape_text { 1209sub escape {
1130 local $_ = $_[1]; 1210 local $_ = $_[1];
1131 1211
1132 s/&/&amp;/g; 1212 s/&/&amp;/g;
1133 s/>/&gt;/g; 1213 s/>/&gt;/g;
1134 s/</&lt;/g; 1214 s/</&lt;/g;
1135 1215
1136 $_[1] 1216 $_[1]
1137} 1217}
1138 1218
1219sub update {
1220 my ($self) = @_;
1221
1222 delete $self->{texture};
1223 $self->SUPER::update;
1224}
1225
1226sub reconfigure {
1227 my ($self) = @_;
1228
1229 delete $self->{texture};
1230}
1231
1139sub set_text { 1232sub set_text {
1140 my ($self, $text) = @_; 1233 my ($self, $text) = @_;
1141 1234
1235 return if $self->{text} eq "T$text";
1236 $self->{text} = "T$text";
1237
1142 $self->{layout}->set_text ($text); 1238 $self->{layout}->set_text ($text);
1143 1239
1144 delete $self->{texture}; 1240 delete $self->{texture};
1241 $self->update;
1145 $self->check_size; 1242 $self->check_size;
1146 $self->update;
1147} 1243}
1148 1244
1149sub set_markup { 1245sub set_markup {
1150 my ($self, $markup) = @_; 1246 my ($self, $markup) = @_;
1151 1247
1248 return if $self->{text} eq "M$markup";
1249 $self->{text} = "M$markup";
1250
1152 $self->{layout}->set_markup ($markup); 1251 $self->{layout}->set_markup ($markup);
1153 1252
1154 delete $self->{texture}; 1253 delete $self->{texture};
1254 $self->update;
1155 $self->check_size; 1255 $self->check_size;
1156 $self->update;
1157} 1256}
1158 1257
1159sub size_request { 1258sub size_request {
1160 my ($self) = @_; 1259 my ($self) = @_;
1161 1260
1241 1340
1242sub new { 1341sub new {
1243 my $class = shift; 1342 my $class = shift;
1244 1343
1245 $class->SUPER::new ( 1344 $class->SUPER::new (
1246 fg => [1, 1, 1], 1345 fg => [1, 1, 1],
1247 bg => [0, 0, 0, 0.2], 1346 bg => [0, 0, 0, 0.2],
1248 active_bg => [1, 1, 1, 0.5], 1347 active_bg => [1, 1, 1, 0.5],
1249 active_fg => [0, 0, 0], 1348 active_fg => [0, 0, 0],
1250 can_hover => 1, 1349 can_hover => 1,
1251 can_focus => 1, 1350 can_focus => 1,
1252 valign => 0, 1351 valign => 0,
1253 can_events => 1, 1352 can_events => 1,
1254 @_ 1353 @_
1255 ) 1354 )
1256} 1355}
1257 1356
1411 my ($self, $ev) = @_; 1510 my ($self, $ev) = @_;
1412 1511
1413 my $sym = $ev->{sym}; 1512 my $sym = $ev->{sym};
1414 1513
1415 if ($sym == 13) { 1514 if ($sym == 13) {
1515 unshift @{$self->{history}},
1516 my $txt = $self->get_text;
1517 $self->{history_pointer} = -1;
1518 $self->{history_saveback} = '';
1416 $self->emit (activate => $self->get_text); 1519 $self->emit (activate => $txt);
1417 $self->update; 1520 $self->update;
1521
1522 } elsif ($sym == CFClient::SDLK_UP) {
1523 if ($self->{history_pointer} < 0) {
1524 $self->{history_saveback} = $self->get_text;
1525 }
1526 if (@{$self->{history} || []} > 0) {
1527 $self->{history_pointer}++;
1528 if ($self->{history_pointer} >= @{$self->{history} || []}) {
1529 $self->{history_pointer} = @{$self->{history} || []} - 1;
1530 }
1531 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1532 }
1533
1534 } elsif ($sym == CFClient::SDLK_DOWN) {
1535 $self->{history_pointer}--;
1536 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
1537
1538 if ($self->{history_pointer} >= 0) {
1539 $self->set_text ($self->{history}->[$self->{history_pointer}]);
1540 } else {
1541 $self->set_text ($self->{history_saveback});
1542 }
1418 1543
1419 } else { 1544 } else {
1420 $self->SUPER::key_down ($ev); 1545 $self->SUPER::key_down ($ev);
1421 } 1546 }
1422 1547
1436 1561
1437sub new { 1562sub new {
1438 my $class = shift; 1563 my $class = shift;
1439 1564
1440 $class->SUPER::new ( 1565 $class->SUPER::new (
1441 padding => 4, 1566 padding => 4,
1442 fg => [1, 1, 1], 1567 fg => [1, 1, 1],
1443 bg => [1, 1, 1, 0.2], 1568 bg => [1, 1, 1, 0.2],
1444 active_fg => [0, 0, 1], 1569 active_fg => [0, 0, 1],
1445 can_hover => 1, 1570 can_hover => 1,
1446 align => 0, 1571 align => 0,
1447 valign => 0, 1572 valign => 0,
1448 can_events => 1, 1573 can_events => 1,
1449 @_ 1574 @_
1450 ) 1575 )
1451} 1576}
1452 1577
1659} 1784}
1660 1785
1661sub set_max { 1786sub set_max {
1662 my ($self, $max) = @_; 1787 my ($self, $max) = @_;
1663 1788
1789 return if $self->{max_val} == $max;
1790
1664 $self->{max_val} = $max; 1791 $self->{max_val} = $max;
1792 $self->update;
1665} 1793}
1666 1794
1667sub set_value { 1795sub set_value {
1668 my ($self, $val, $max) = @_; 1796 my ($self, $val, $max) = @_;
1669 1797
1670 $self->set_max ($max) 1798 $self->set_max ($max)
1671 if defined $max; 1799 if defined $max;
1672 1800
1673 $max = $self->{max_val}; 1801 return if $self->{val} == $val;
1802
1674 $self->{val} = $val; 1803 $self->{val} = $val;
1675
1676 $self->update; 1804 $self->update;
1677} 1805}
1678 1806
1679sub _draw { 1807sub _draw {
1680 my ($self) = @_; 1808 my ($self) = @_;
1743 1871
1744sub new { 1872sub new {
1745 my ($class, %arg) = @_; 1873 my ($class, %arg) = @_;
1746 1874
1747 my $self = $class->SUPER::new ( 1875 my $self = $class->SUPER::new (
1748 tooltip => $arg{type}, 1876 tooltip => $arg{type},
1877 can_hover => 1,
1878 can_events => 1,
1749 %arg, 1879 %arg,
1750 ); 1880 );
1751 1881
1752 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); 1882 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1753 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1); 1883 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
1754 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1); 1884 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1755 1885
1756 $self 1886 $self
1757} 1887}
1758 1888
1759sub set_fontsize { 1889sub set_fontsize {
1761 1891
1762 $self->{value}->set_fontsize ($fsize); 1892 $self->{value}->set_fontsize ($fsize);
1763 $self->{max} ->set_fontsize ($fsize); 1893 $self->{max} ->set_fontsize ($fsize);
1764} 1894}
1765 1895
1896sub set_max {
1897 my ($self, $max) = @_;
1898
1899 $self->{gauge}->set_max ($max);
1900 $self->{max}->set_text ($max);
1901}
1902
1766sub set_value { 1903sub set_value {
1767 my ($self, $val, $max) = @_; 1904 my ($self, $val, $max) = @_;
1768 1905
1769 $self->set_max ($max) 1906 $self->set_max ($max)
1770 if defined $max; 1907 if defined $max;
1771 1908
1772 $self->{gauge}->set_value ($val, $max); 1909 $self->{gauge}->set_value ($val, $max);
1773 $self->{value}->set_text ($val); 1910 $self->{value}->set_text ($val);
1774}
1775
1776sub set_max {
1777 my ($self, $max) = @_;
1778
1779 $self->{gauge}->set_max ($max);
1780 $self->{max}->set_text ($max);
1781} 1911}
1782 1912
1783############################################################################# 1913#############################################################################
1784 1914
1785package CFClient::UI::Slider; 1915package CFClient::UI::Slider;
1925 2055
1926sub new { 2056sub new {
1927 my $class = shift; 2057 my $class = shift;
1928 2058
1929 my $self = $class->SUPER::new ( 2059 my $self = $class->SUPER::new (
1930 fontsize => 1, 2060 fontsize => 1,
2061 can_events => 0,
1931 #font => default_font 2062 #font => default_font
1932 @_, 2063 @_,
1933 2064
1934 layout => (new CFClient::Layout), 2065 layout => (new CFClient::Layout),
1935 par => [], 2066 par => [],
1936 height => 0, 2067 height => 0,
1937 children => [ 2068 children => [
1938 (new CFClient::UI::Empty expand => 1), 2069 (new CFClient::UI::Empty expand => 1),
1939 (new CFClient::UI::Slider vertical => 1), 2070 (new CFClient::UI::Slider vertical => 1),
1940 ], 2071 ],
1941 ); 2072 );
1942 2073
2067 my ($self) = @_; 2198 my ($self) = @_;
2068 2199
2069 if ($self->{texture}) { 2200 if ($self->{texture}) {
2070 glEnable GL_TEXTURE_2D; 2201 glEnable GL_TEXTURE_2D;
2071 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2202 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2203 glColor 1, 1, 1, 1;
2072 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h}); 2204 $self->{texture}->draw_quad (0, 0, $self->{w}, $self->{h});
2073 glDisable GL_TEXTURE_2D; 2205 glDisable GL_TEXTURE_2D;
2074 } 2206 }
2075 2207
2076 $self->{children}[1]->draw; 2208 $self->{children}[1]->draw;
2127 2259
2128sub new { 2260sub new {
2129 my $class = shift; 2261 my $class = shift;
2130 2262
2131 my $self = $class->SUPER::new ( 2263 my $self = $class->SUPER::new (
2132 state => 0, 2264 state => 0,
2133 connect_activate => \&toggle_flopper, 2265 connect_activate => \&toggle_flopper,
2134 can_events => 1,
2135 @_ 2266 @_
2136 ); 2267 );
2137 2268
2138 if ($self->{state}) { 2269 if ($self->{state}) {
2139 $self->{state} = 0; 2270 $self->{state} = 0;
2174 @_, 2305 @_,
2175 can_events => 0, 2306 can_events => 0,
2176 ) 2307 )
2177} 2308}
2178 2309
2179sub set_text { 2310sub set_markup {
2180 my ($self, $text) = @_; 2311 my ($self, $text) = @_;
2181 2312
2182 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; 2313 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2183 $self->{label}->set_text ($text); 2314 $self->{label}->set_markup ($text);
2184 $self->add ($self->{label}); 2315 $self->add ($self->{label});
2185} 2316}
2186 2317
2187sub size_request { 2318sub size_request {
2188 my ($self) = @_; 2319 my ($self) = @_;
2189 2320
2190 $self->child->set_max_size ($::WIDTH * 0.2); 2321 $self->child->set_max_size ($::WIDTH * 0.3);
2191 2322
2192 my ($w, $h) = @{$self->child}{qw(req_w req_h)}; 2323 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2193 2324
2194 ($w + 4, $h + 4) 2325 ($w + 4, $h + 4)
2326}
2327
2328sub size_allocate {
2329 my ($self, $w, $h) = @_;
2330
2331 $self->SUPER::size_allocate ($w - 4, $h - 4);
2195} 2332}
2196 2333
2197sub _draw { 2334sub _draw {
2198 my ($self) = @_; 2335 my ($self) = @_;
2199 2336
2224 $self->SUPER::_draw; 2361 $self->SUPER::_draw;
2225} 2362}
2226 2363
2227############################################################################# 2364#############################################################################
2228 2365
2366package CFClient::UI::Face;
2367
2368our @ISA = CFClient::UI::Base::;
2369
2370use CFClient::OpenGL;
2371
2372sub new {
2373 my $class = shift;
2374
2375 $class->SUPER::new (
2376 aspect => 1,
2377 @_,
2378 )
2379}
2380
2381sub size_request {
2382 (32, 8)
2383}
2384
2385sub draw {
2386 my ($self) = @_;
2387
2388 my $tex = $::CONN->{texture}[$::CONN->{faceid}[$self->{face}]];
2389
2390 if ($tex) {
2391 glEnable GL_BLEND;
2392 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
2393 glEnable GL_TEXTURE_2D;
2394 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2395 glColor 1, 1, 1, 1;
2396 $tex->draw_quad (0, 0, $self->{w}, $self->{h});
2397 glDisable GL_TEXTURE_2D;
2398 glDisable GL_BLEND;
2399 }
2400}
2401
2402#############################################################################
2403
2229package CFClient::UI::Root; 2404package CFClient::UI::Root;
2230 2405
2231our @ISA = CFClient::UI::Container::; 2406our @ISA = CFClient::UI::Container::;
2232 2407
2233use CFClient::OpenGL; 2408use CFClient::OpenGL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines