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.149 by root, Sat Apr 22 23:11:32 2006 UTC vs.
Revision 1.159 by root, Mon Apr 24 03:19:42 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 (exists $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_text ($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
96 129
97 my $self = bless { 130 my $self = bless {
98 x => 0, 131 x => 0,
99 y => 0, 132 y => 0,
100 z => 0, 133 z => 0,
134 can_events => 1,
101 @_ 135 @_
102 }, $class; 136 }, $class;
103 137
104 for (keys %$self) { 138 for (keys %$self) {
105 if (/^connect_(.*)$/) { 139 if (/^connect_(.*)$/) {
108 } 142 }
109 143
110 $self 144 $self
111} 145}
112 146
147sub destroy {
148 my ($self) = @_;
149
150 $self->hide;
151 %$self = ();
152}
153
113sub show { 154sub show {
114 my ($self) = @_; 155 my ($self) = @_;
115 156
116 return if $self->{parent}; 157 return if $self->{parent};
117 158
134 $self->{z} = $z if defined $z; 175 $self->{z} = $z if defined $z;
135 176
136 $self->update; 177 $self->update;
137} 178}
138 179
139sub needs_redraw { 180sub set_size {
140 0 181 my ($self, $w, $h) = @_;
182
183 $self->{user_w} = $w;
184 $self->{user_h} = $h;
185
186 $self->check_size;
141} 187}
142 188
143sub size_request { 189sub size_request {
144 require Carp; 190 require Carp;
145 Carp::confess "size_request is abstract"; 191 Carp::confess "size_request is abstract";
175 } 221 }
176} 222}
177 223
178sub size_allocate { 224sub size_allocate {
179 # 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;
180} 233}
181 234
182# return top left coordinates 235# return top left coordinates
183sub _topleft { 236sub _topleft {
184 my ($self, $x, $y) = @_; 237 my ($self, $x, $y) = @_;
278} 331}
279 332
280sub find_widget { 333sub find_widget {
281 my ($self, $x, $y) = @_; 334 my ($self, $x, $y) = @_;
282 335
336 return () unless $self->{can_events};
337
283 return $self 338 return $self
284 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 339 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
285 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 340 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
286 341
287 () 342 ()
294} 349}
295 350
296sub check_size { 351sub check_size {
297 my ($self) = @_; 352 my ($self) = @_;
298 353
299 return unless $self->{parent}; 354 $self->{parent}
355 or return 1;
300 356
301 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;
302 360
303 if ($w != $self->{req_w} || $h != $self->{req_h}) { 361 if ($w != $self->{req_w} || $h != $self->{req_h}) {
304 $self->{req_w} = $w; 362 $self->{req_w} = $w;
305 $self->{req_h} = $h; 363 $self->{req_h} = $h;
306 364
307 $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
308 } 374 }
309} 375}
310 376
311sub update { 377sub update {
312 my ($self) = @_; 378 my ($self) = @_;
379 445
380package CFClient::UI::Empty; 446package CFClient::UI::Empty;
381 447
382our @ISA = CFClient::UI::Base::; 448our @ISA = CFClient::UI::Base::;
383 449
450sub new {
451 my ($class, %arg) = @_;
452 $class->SUPER::new (can_events => 0, %arg);
453}
454
384sub size_request { 455sub size_request {
385 (0, 0) 456 (0, 0)
386} 457}
387 458
388sub draw { } 459sub draw { }
396sub new { 467sub new {
397 my ($class, %arg) = @_; 468 my ($class, %arg) = @_;
398 469
399 my $children = delete $arg{children} || []; 470 my $children = delete $arg{children} || [];
400 471
401 my $self = $class->SUPER::new (children => [], %arg); 472 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
402 $self->add ($_) for @$children; 473 $self->add ($_) for @$children;
403 474
404 $self 475 $self
405} 476}
406 477
425 delete $child->{parent}; 496 delete $child->{parent};
426 497
427 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 498 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
428 499
429 $self->check_size; 500 $self->check_size;
501 $self->update;
430} 502}
431 503
432sub find_widget { 504sub find_widget {
433 my ($self, $x, $y) = @_; 505 my ($self, $x, $y) = @_;
434 506
594 border => 0.8, 666 border => 0.8,
595 @_ 667 @_
596 ); 668 );
597 669
598 $self 670 $self
599}
600
601sub set_size {
602 my ($self, $w, $h) = @_;
603 $self->{req_w} = $w;
604 $self->{req_h} = $h;
605 $self->check_size;
606}
607
608sub size_request {
609 my ($self) = @_;
610 ($self->{req_w}, $self->{req_h})
611}
612
613sub size_allocate {
614 my ($self, $w, $h) = @_;
615 $self->{w} = $w;
616 $self->{h} = $h;
617 $self->child->configure (0, 0, $w, $h);
618} 671}
619 672
620sub _draw { 673sub _draw {
621 my ($self) = @_; 674 my ($self) = @_;
622 675
660 713
661 my $self = $class->SUPER::new ( 714 my $self = $class->SUPER::new (
662 bg => [1, 1, 1, 1], 715 bg => [1, 1, 1, 1],
663 border_bg => [1, 1, 1, 1], 716 border_bg => [1, 1, 1, 1],
664 border => 0.8, 717 border => 0.8,
718 can_events => 1,
665 @_ 719 @_
666 ); 720 );
667 721
668 $self->{title} &&= new CFClient::UI::Label 722 $self->{title} &&= new CFClient::UI::Label
669 align => 0, 723 align => 0,
678 int $_[0]{border} * $::FONTSIZE 732 int $_[0]{border} * $::FONTSIZE
679} 733}
680 734
681sub size_request { 735sub size_request {
682 my ($self) = @_; 736 my ($self) = @_;
683
684 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
685 737
686 my ($w, $h) = $self->SUPER::size_request; 738 my ($w, $h) = $self->SUPER::size_request;
687 739
688 ( 740 (
689 $w + $self->border * 2, 741 $w + $self->border * 2,
1056sub new { 1108sub new {
1057 my ($class, %arg) = @_; 1109 my ($class, %arg) = @_;
1058 1110
1059 my $self = $class->SUPER::new ( 1111 my $self = $class->SUPER::new (
1060 fg => [1, 1, 1], 1112 fg => [1, 1, 1],
1113 #font => default_font
1061 fontsize => 1, 1114 fontsize => 1,
1062 text => "", 1115 text => "",
1063 align => -1, 1116 align => -1,
1064 valign => -1, 1117 valign => -1,
1065 padding => 2, 1118 padding => 2,
1066 layout => new CFClient::Layout, 1119 layout => new CFClient::Layout,
1120 can_events => 0,
1067 %arg 1121 %arg
1068 ); 1122 );
1069 1123
1070 if (exists $self->{template}) { 1124 if (exists $self->{template}) {
1071 my $layout = new CFClient::Layout; 1125 my $layout = new CFClient::Layout;
1110} 1164}
1111 1165
1112sub size_request { 1166sub size_request {
1113 my ($self) = @_; 1167 my ($self) = @_;
1114 1168
1115 $self->{layout}->set_width; 1169 $self->{layout}->set_font ($self->{font}) if $self->{font};
1170 $self->{layout}->set_width ($self->{max_w} || -1);
1116 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1171 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1117 1172
1118 my ($w, $h) = $self->{layout}->size; 1173 my ($w, $h) = $self->{layout}->size;
1119 1174
1120 if (exists $self->{template}) { 1175 if (exists $self->{template}) {
1176 $self->{template}->set_font ($self->{font}) if $self->{font};
1121 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1177 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1122 1178
1123 my ($w2, $h2) = $self->{template}->size; 1179 my ($w2, $h2) = $self->{template}->size;
1124 1180
1125 $w = List::Util::max $w, $w2; 1181 $w = List::Util::max $w, $w2;
1140 1196
1141sub set_fontsize { 1197sub set_fontsize {
1142 my ($self, $fontsize) = @_; 1198 my ($self, $fontsize) = @_;
1143 1199
1144 $self->{fontsize} = $fontsize; 1200 $self->{fontsize} = $fontsize;
1201 delete $self->{texture};
1145 $self->check_size; 1202 $self->check_size;
1203 $self->update;
1146} 1204}
1147 1205
1148sub _draw { 1206sub _draw {
1149 my ($self) = @_; 1207 my ($self) = @_;
1150 1208
1151 my $tex = $self->{texture} ||= do { 1209 my $tex = $self->{texture} ||= do {
1210 $self->{layout}->set_font ($self->{font}) if $self->{font};
1152 $self->{layout}->set_width ($self->{w}); 1211 $self->{layout}->set_width ($self->{w});
1153 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1212 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1154 new_from_layout CFClient::Texture $self->{layout} 1213 new_from_layout CFClient::Texture $self->{layout}
1155 }; 1214 };
1156 1215
1196 active_bg => [1, 1, 1, 0.5], 1255 active_bg => [1, 1, 1, 0.5],
1197 active_fg => [0, 0, 0], 1256 active_fg => [0, 0, 0],
1198 can_hover => 1, 1257 can_hover => 1,
1199 can_focus => 1, 1258 can_focus => 1,
1200 valign => 0, 1259 valign => 0,
1260 can_events => 1,
1201 @_ 1261 @_
1202 ) 1262 )
1203} 1263}
1204 1264
1205sub _set_text { 1265sub _set_text {
1390 bg => [1, 1, 1, 0.2], 1450 bg => [1, 1, 1, 0.2],
1391 active_fg => [0, 0, 1], 1451 active_fg => [0, 0, 1],
1392 can_hover => 1, 1452 can_hover => 1,
1393 align => 0, 1453 align => 0,
1394 valign => 0, 1454 valign => 0,
1455 can_events => 1,
1395 @_ 1456 @_
1396 ) 1457 )
1397} 1458}
1398 1459
1399sub button_up { 1460sub button_up {
1504our %loaded_images; 1565our %loaded_images;
1505 1566
1506sub new { 1567sub new {
1507 my $class = shift; 1568 my $class = shift;
1508 1569
1509 my $self = $class->SUPER::new (@_); 1570 my $self = $class->SUPER::new (can_events => 0, @_);
1510 1571
1511 $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; 1572 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1512 1573
1513 $loaded_images{$self->{image}} ||= 1574 $loaded_images{$self->{image}} ||=
1514 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; 1575 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1556############################################################################# 1617#############################################################################
1557 1618
1558package CFClient::UI::VGauge; 1619package CFClient::UI::VGauge;
1559 1620
1560our @ISA = CFClient::UI::Base::; 1621our @ISA = CFClient::UI::Base::;
1622
1623use List::Util qw(min max);
1561 1624
1562use CFClient::OpenGL; 1625use CFClient::OpenGL;
1563 1626
1564my %tex = ( 1627my %tex = (
1565 food => [ 1628 food => [
1566 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1629 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1567 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1630 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1568 ], 1631 ],
1569 grace => [ 1632 grace => [
1570 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1633 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1571 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/
1572 ], 1635 ],
1573 hp => [ 1636 hp => [
1574 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1637 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1575 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1638 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1576 ], 1639 ],
1577 mana => [ 1640 mana => [
1578 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1641 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1579 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/
1580 ], 1643 ],
1581); 1644);
1582 1645
1583# eg. VGauge->new (gauge => 'food'), default gauge: food 1646# eg. VGauge->new (gauge => 'food'), default gauge: food
1584sub new { 1647sub new {
1622 1685
1623sub _draw { 1686sub _draw {
1624 my ($self) = @_; 1687 my ($self) = @_;
1625 1688
1626 my $tex = $tex{$self->{type}}; 1689 my $tex = $tex{$self->{type}};
1690 my ($t1, $t2, $t3) = @$tex;
1627 1691
1628 my ($w, $h) = ($self->{w}, $self->{h}); 1692 my ($w, $h) = ($self->{w}, $self->{h});
1629 1693
1630 if ($self->{vertical}) { 1694 if ($self->{vertical}) {
1631 glRotate 90, 0, 0, 1; 1695 glRotate 90, 0, 0, 1;
1633 1697
1634 ($w, $h) = ($h, $w); 1698 ($w, $h) = ($h, $w);
1635 } 1699 }
1636 1700
1637 my $ycut = $self->{val} / ($self->{max_val} || 1); 1701 my $ycut = $self->{val} / ($self->{max_val} || 1);
1638 $ycut = 1 if $self->{val} > $self->{max_val};
1639 1702
1640 my $t1 = $tex->[0]; 1703 my $ycut1 = max 0, min 1, $ycut;
1641 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);
1642 1708
1643 glEnable GL_BLEND; 1709 glEnable GL_BLEND;
1644 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1710 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1645 glEnable GL_TEXTURE_2D; 1711 glEnable GL_TEXTURE_2D;
1646 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1647 1713
1648 my $h1 = $self->{h} - $ycut * $self->{h};
1649 my $h2 = $ycut * $self->{h};
1650
1651 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1714 glBindTexture GL_TEXTURE_2D, $t1->{name};
1652 glBegin GL_QUADS; 1715 glBegin GL_QUADS;
1653 glTexCoord 0 , 0; glVertex 0 , 0; 1716 glTexCoord 0 , 0; glVertex 0 , 0;
1654 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1717 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1655 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1718 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1656 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1719 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1657 glEnd; 1720 glEnd;
1658 1721
1722 my $ycut1 = List::Util::min 1, $ycut;
1659 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1723 glBindTexture GL_TEXTURE_2D, $t2->{name};
1660 glBegin GL_QUADS; 1724 glBegin GL_QUADS;
1661 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1725 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1662 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1726 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1663 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1727 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1664 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1728 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1665 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 }
1666 1740
1667 glDisable GL_BLEND; 1741 glDisable GL_BLEND;
1668 glDisable GL_TEXTURE_2D; 1742 glDisable GL_TEXTURE_2D;
1669} 1743}
1670 1744
1673package CFClient::UI::Gauge; 1747package CFClient::UI::Gauge;
1674 1748
1675our @ISA = CFClient::UI::VBox::; 1749our @ISA = CFClient::UI::VBox::;
1676 1750
1677sub new { 1751sub new {
1678 my ($class, %arg) = shift; 1752 my ($class, %arg) = @_;
1679 1753
1680 my $self = $class->SUPER::new ( 1754 my $self = $class->SUPER::new (
1681 @_, 1755 tooltip => $arg{type},
1756 %arg,
1682 ); 1757 );
1683 1758
1684 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1759 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1);
1685 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1760 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1);
1686 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1761 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1);
1687 1762
1688 $self 1763 $self
1689} 1764}
1690 1765
1691sub set_fontsize { 1766sub set_fontsize {
1858sub new { 1933sub new {
1859 my $class = shift; 1934 my $class = shift;
1860 1935
1861 my $self = $class->SUPER::new ( 1936 my $self = $class->SUPER::new (
1862 fontsize => 1, 1937 fontsize => 1,
1938 #font => default_font
1863 @_, 1939 @_,
1864 1940
1865 layout => (new CFClient::Layout), 1941 layout => (new CFClient::Layout),
1866 par => [], 1942 par => [],
1867 height => 0, 1943 height => 0,
1907sub size_allocate { 1983sub size_allocate {
1908 my ($self, $w, $h) = @_; 1984 my ($self, $w, $h) = @_;
1909 1985
1910 $self->SUPER::size_allocate ($w, $h); 1986 $self->SUPER::size_allocate ($w, $h);
1911 1987
1988 $self->{layout}->set_font ($self->{font}) if $self->{font};
1912 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1989 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1913 $self->{layout}->set_width ($self->{children}[0]{w}); 1990 $self->{layout}->set_width ($self->{children}[0]{w});
1914 1991
1915 $self->reflow; 1992 $self->reflow;
1916} 1993}
1968 my $y1 = $top + $self->{h}; 2045 my $y1 = $top + $self->{h};
1969 2046
1970 my $y = 0; 2047 my $y = 0;
1971 2048
1972 my $layout = $self->{layout}; 2049 my $layout = $self->{layout};
2050
2051 $layout->set_font ($self->{font}) if $self->{font};
1973 2052
1974 for my $par (@{$self->{par}}) { 2053 for my $par (@{$self->{par}}) {
1975 my $h = $par->[0]; 2054 my $h = $par->[0];
1976 2055
1977 if ($y0 < $y + $h && $y < $y1) { 2056 if ($y0 < $y + $h && $y < $y1) {
2057 my $class = shift; 2136 my $class = shift;
2058 2137
2059 my $self = $class->SUPER::new ( 2138 my $self = $class->SUPER::new (
2060 state => 0, 2139 state => 0,
2061 connect_activate => \&toggle_flopper, 2140 connect_activate => \&toggle_flopper,
2141 can_events => 1,
2062 @_ 2142 @_
2063 ); 2143 );
2064 2144
2065 if ($self->{state}) { 2145 if ($self->{state}) {
2066 $self->{state} = 0; 2146 $self->{state} = 0;
2086 $self->emit (changed => $self->{state}); 2166 $self->emit (changed => $self->{state});
2087} 2167}
2088 2168
2089############################################################################# 2169#############################################################################
2090 2170
2171package CFClient::UI::Tooltip;
2172
2173our @ISA = CFClient::UI::Bin::;
2174
2175use CFClient::OpenGL;
2176
2177sub new {
2178 my $class = shift;
2179
2180 $class->SUPER::new (
2181 @_,
2182 can_events => 0,
2183 )
2184}
2185
2186sub set_text {
2187 my ($self, $text) = @_;
2188
2189 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2190 $self->{label}->set_text ($text);
2191 $self->add ($self->{label});
2192}
2193
2194sub size_request {
2195 my ($self) = @_;
2196
2197 $self->child->set_max_size ($::WIDTH * 0.2);
2198
2199 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2200
2201 ($w + 4, $h + 4)
2202}
2203
2204sub _draw {
2205 my ($self) = @_;
2206
2207 glPushMatrix;
2208 glTranslate 0.375, 0.375;
2209
2210 my ($w, $h) = @$self{qw(w h)};
2211
2212 glColor 1, 0.8, 0.4;
2213 glBegin GL_QUADS;
2214 glVertex 0 , 0;
2215 glVertex 0 , $h;
2216 glVertex $w, $h;
2217 glVertex $w, 0;
2218 glEnd;
2219
2220 glColor 0, 0, 0;
2221 glBegin GL_LINE_LOOP;
2222 glVertex 0 , 0;
2223 glVertex 0 , $h;
2224 glVertex $w, $h;
2225 glVertex $w, 0;
2226 glEnd;
2227
2228 glPopMatrix;
2229
2230 glTranslate 2, 2;
2231 $self->SUPER::_draw;
2232}
2233
2234#############################################################################
2235
2091package CFClient::UI::Root; 2236package CFClient::UI::Root;
2092 2237
2093our @ISA = CFClient::UI::Container::; 2238our @ISA = CFClient::UI::Container::;
2094 2239
2095use CFClient::OpenGL; 2240use CFClient::OpenGL;
2170############################################################################# 2315#############################################################################
2171 2316
2172package CFClient::UI; 2317package CFClient::UI;
2173 2318
2174$ROOT = new CFClient::UI::Root; 2319$ROOT = new CFClient::UI::Root;
2320$TOOLTIP = new CFClient::UI::Tooltip;
2175 2321
21761 23221
2177 2323

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines