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.158 by root, Mon Apr 24 02:41:48 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_(.*)$/) {
134 $self->{z} = $z if defined $z; 168 $self->{z} = $z if defined $z;
135 169
136 $self->update; 170 $self->update;
137} 171}
138 172
139sub needs_redraw { 173sub set_size {
140 0 174 my ($self, $w, $h) = @_;
175
176 $self->{user_w} = $w;
177 $self->{user_h} = $h;
178
179 $self->check_size;
141} 180}
142 181
143sub size_request { 182sub size_request {
144 require Carp; 183 require Carp;
145 Carp::confess "size_request is abstract"; 184 Carp::confess "size_request is abstract";
175 } 214 }
176} 215}
177 216
178sub size_allocate { 217sub size_allocate {
179 # nothing to be done 218 # nothing to be done
219}
220
221sub set_max_size {
222 my ($self, $w, $h) = @_;
223
224 delete $self->{max_w}; $self->{max_w} = $w if $w;
225 delete $self->{max_h}; $self->{max_h} = $h if $h;
180} 226}
181 227
182# return top left coordinates 228# return top left coordinates
183sub _topleft { 229sub _topleft {
184 my ($self, $x, $y) = @_; 230 my ($self, $x, $y) = @_;
278} 324}
279 325
280sub find_widget { 326sub find_widget {
281 my ($self, $x, $y) = @_; 327 my ($self, $x, $y) = @_;
282 328
329 return () unless $self->{can_events};
330
283 return $self 331 return $self
284 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 332 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
285 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 333 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
286 334
287 () 335 ()
294} 342}
295 343
296sub check_size { 344sub check_size {
297 my ($self) = @_; 345 my ($self) = @_;
298 346
299 return unless $self->{parent}; 347 $self->{parent}
348 or return 1;
300 349
301 my ($w, $h) = $self->size_request; 350 my ($w, $h) = $self->{user_w} && $self->{user_h}
351 ? @$self{qw(user_w user_h)}
352 : $self->size_request;
302 353
303 if ($w != $self->{req_w} || $h != $self->{req_h}) { 354 if ($w != $self->{req_w} || $h != $self->{req_h}) {
304 $self->{req_w} = $w; 355 $self->{req_w} = $w;
305 $self->{req_h} = $h; 356 $self->{req_h} = $h;
306 357
307 $self->{parent}->check_size; 358 $self->{parent}->check_size
359 or $self->size_allocate (
360 (List::Util::max $self->{w}, $w),
361 (List::Util::max $self->{h}, $h),
362 );
363
364 1
365 } else {
366 0
308 } 367 }
309} 368}
310 369
311sub update { 370sub update {
312 my ($self) = @_; 371 my ($self) = @_;
379 438
380package CFClient::UI::Empty; 439package CFClient::UI::Empty;
381 440
382our @ISA = CFClient::UI::Base::; 441our @ISA = CFClient::UI::Base::;
383 442
443sub new {
444 my ($class, %arg) = @_;
445 $class->SUPER::new (can_events => 0, %arg);
446}
447
384sub size_request { 448sub size_request {
385 (0, 0) 449 (0, 0)
386} 450}
387 451
388sub draw { } 452sub draw { }
396sub new { 460sub new {
397 my ($class, %arg) = @_; 461 my ($class, %arg) = @_;
398 462
399 my $children = delete $arg{children} || []; 463 my $children = delete $arg{children} || [];
400 464
401 my $self = $class->SUPER::new (children => [], %arg); 465 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
402 $self->add ($_) for @$children; 466 $self->add ($_) for @$children;
403 467
404 $self 468 $self
405} 469}
406 470
425 delete $child->{parent}; 489 delete $child->{parent};
426 490
427 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 491 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
428 492
429 $self->check_size; 493 $self->check_size;
494 $self->update;
430} 495}
431 496
432sub find_widget { 497sub find_widget {
433 my ($self, $x, $y) = @_; 498 my ($self, $x, $y) = @_;
434 499
594 border => 0.8, 659 border => 0.8,
595 @_ 660 @_
596 ); 661 );
597 662
598 $self 663 $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} 664}
619 665
620sub _draw { 666sub _draw {
621 my ($self) = @_; 667 my ($self) = @_;
622 668
660 706
661 my $self = $class->SUPER::new ( 707 my $self = $class->SUPER::new (
662 bg => [1, 1, 1, 1], 708 bg => [1, 1, 1, 1],
663 border_bg => [1, 1, 1, 1], 709 border_bg => [1, 1, 1, 1],
664 border => 0.8, 710 border => 0.8,
711 can_events => 1,
665 @_ 712 @_
666 ); 713 );
667 714
668 $self->{title} &&= new CFClient::UI::Label 715 $self->{title} &&= new CFClient::UI::Label
669 align => 0, 716 align => 0,
678 int $_[0]{border} * $::FONTSIZE 725 int $_[0]{border} * $::FONTSIZE
679} 726}
680 727
681sub size_request { 728sub size_request {
682 my ($self) = @_; 729 my ($self) = @_;
683
684 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
685 730
686 my ($w, $h) = $self->SUPER::size_request; 731 my ($w, $h) = $self->SUPER::size_request;
687 732
688 ( 733 (
689 $w + $self->border * 2, 734 $w + $self->border * 2,
1056sub new { 1101sub new {
1057 my ($class, %arg) = @_; 1102 my ($class, %arg) = @_;
1058 1103
1059 my $self = $class->SUPER::new ( 1104 my $self = $class->SUPER::new (
1060 fg => [1, 1, 1], 1105 fg => [1, 1, 1],
1106 #font => default_font
1061 fontsize => 1, 1107 fontsize => 1,
1062 text => "", 1108 text => "",
1063 align => -1, 1109 align => -1,
1064 valign => -1, 1110 valign => -1,
1065 padding => 2, 1111 padding => 2,
1066 layout => new CFClient::Layout, 1112 layout => new CFClient::Layout,
1113 can_events => 0,
1067 %arg 1114 %arg
1068 ); 1115 );
1069 1116
1070 if (exists $self->{template}) { 1117 if (exists $self->{template}) {
1071 my $layout = new CFClient::Layout; 1118 my $layout = new CFClient::Layout;
1110} 1157}
1111 1158
1112sub size_request { 1159sub size_request {
1113 my ($self) = @_; 1160 my ($self) = @_;
1114 1161
1115 $self->{layout}->set_width; 1162 $self->{layout}->set_font ($self->{font}) if $self->{font};
1163 $self->{layout}->set_width ($self->{max_w} || -1);
1116 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1164 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1117 1165
1118 my ($w, $h) = $self->{layout}->size; 1166 my ($w, $h) = $self->{layout}->size;
1119 1167
1120 if (exists $self->{template}) { 1168 if (exists $self->{template}) {
1169 $self->{template}->set_font ($self->{font}) if $self->{font};
1121 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1170 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1122 1171
1123 my ($w2, $h2) = $self->{template}->size; 1172 my ($w2, $h2) = $self->{template}->size;
1124 1173
1125 $w = List::Util::max $w, $w2; 1174 $w = List::Util::max $w, $w2;
1140 1189
1141sub set_fontsize { 1190sub set_fontsize {
1142 my ($self, $fontsize) = @_; 1191 my ($self, $fontsize) = @_;
1143 1192
1144 $self->{fontsize} = $fontsize; 1193 $self->{fontsize} = $fontsize;
1194 delete $self->{texture};
1145 $self->check_size; 1195 $self->check_size;
1196 $self->update;
1146} 1197}
1147 1198
1148sub _draw { 1199sub _draw {
1149 my ($self) = @_; 1200 my ($self) = @_;
1150 1201
1151 my $tex = $self->{texture} ||= do { 1202 my $tex = $self->{texture} ||= do {
1203 $self->{layout}->set_font ($self->{font}) if $self->{font};
1152 $self->{layout}->set_width ($self->{w}); 1204 $self->{layout}->set_width ($self->{w});
1153 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1205 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1154 new_from_layout CFClient::Texture $self->{layout} 1206 new_from_layout CFClient::Texture $self->{layout}
1155 }; 1207 };
1156 1208
1196 active_bg => [1, 1, 1, 0.5], 1248 active_bg => [1, 1, 1, 0.5],
1197 active_fg => [0, 0, 0], 1249 active_fg => [0, 0, 0],
1198 can_hover => 1, 1250 can_hover => 1,
1199 can_focus => 1, 1251 can_focus => 1,
1200 valign => 0, 1252 valign => 0,
1253 can_events => 1,
1201 @_ 1254 @_
1202 ) 1255 )
1203} 1256}
1204 1257
1205sub _set_text { 1258sub _set_text {
1390 bg => [1, 1, 1, 0.2], 1443 bg => [1, 1, 1, 0.2],
1391 active_fg => [0, 0, 1], 1444 active_fg => [0, 0, 1],
1392 can_hover => 1, 1445 can_hover => 1,
1393 align => 0, 1446 align => 0,
1394 valign => 0, 1447 valign => 0,
1448 can_events => 1,
1395 @_ 1449 @_
1396 ) 1450 )
1397} 1451}
1398 1452
1399sub button_up { 1453sub button_up {
1504our %loaded_images; 1558our %loaded_images;
1505 1559
1506sub new { 1560sub new {
1507 my $class = shift; 1561 my $class = shift;
1508 1562
1509 my $self = $class->SUPER::new (@_); 1563 my $self = $class->SUPER::new (can_events => 0, @_);
1510 1564
1511 $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; 1565 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1512 1566
1513 $loaded_images{$self->{image}} ||= 1567 $loaded_images{$self->{image}} ||=
1514 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; 1568 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1556############################################################################# 1610#############################################################################
1557 1611
1558package CFClient::UI::VGauge; 1612package CFClient::UI::VGauge;
1559 1613
1560our @ISA = CFClient::UI::Base::; 1614our @ISA = CFClient::UI::Base::;
1615
1616use List::Util qw(min max);
1561 1617
1562use CFClient::OpenGL; 1618use CFClient::OpenGL;
1563 1619
1564my %tex = ( 1620my %tex = (
1565 food => [ 1621 food => [
1566 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1622 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1567 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1623 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1568 ], 1624 ],
1569 grace => [ 1625 grace => [
1570 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1626 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1571 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1627 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
1572 ], 1628 ],
1573 hp => [ 1629 hp => [
1574 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1630 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1575 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1631 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1576 ], 1632 ],
1577 mana => [ 1633 mana => [
1578 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1634 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1579 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1635 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
1580 ], 1636 ],
1581); 1637);
1582 1638
1583# eg. VGauge->new (gauge => 'food'), default gauge: food 1639# eg. VGauge->new (gauge => 'food'), default gauge: food
1584sub new { 1640sub new {
1622 1678
1623sub _draw { 1679sub _draw {
1624 my ($self) = @_; 1680 my ($self) = @_;
1625 1681
1626 my $tex = $tex{$self->{type}}; 1682 my $tex = $tex{$self->{type}};
1683 my ($t1, $t2, $t3) = @$tex;
1627 1684
1628 my ($w, $h) = ($self->{w}, $self->{h}); 1685 my ($w, $h) = ($self->{w}, $self->{h});
1629 1686
1630 if ($self->{vertical}) { 1687 if ($self->{vertical}) {
1631 glRotate 90, 0, 0, 1; 1688 glRotate 90, 0, 0, 1;
1633 1690
1634 ($w, $h) = ($h, $w); 1691 ($w, $h) = ($h, $w);
1635 } 1692 }
1636 1693
1637 my $ycut = $self->{val} / ($self->{max_val} || 1); 1694 my $ycut = $self->{val} / ($self->{max_val} || 1);
1638 $ycut = 1 if $self->{val} > $self->{max_val};
1639 1695
1640 my $t1 = $tex->[0]; 1696 my $ycut1 = max 0, min 1, $ycut;
1641 my $t2 = $tex->[1]; 1697 my $ycut2 = max 0, min 1, $ycut - 1;
1698
1699 my $h1 = $self->{h} * (1 - $ycut1);
1700 my $h2 = $self->{h} * (1 - $ycut2);
1642 1701
1643 glEnable GL_BLEND; 1702 glEnable GL_BLEND;
1644 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1703 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1645 glEnable GL_TEXTURE_2D; 1704 glEnable GL_TEXTURE_2D;
1646 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1705 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1647 1706
1648 my $h1 = $self->{h} - $ycut * $self->{h};
1649 my $h2 = $ycut * $self->{h};
1650
1651 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1707 glBindTexture GL_TEXTURE_2D, $t1->{name};
1652 glBegin GL_QUADS; 1708 glBegin GL_QUADS;
1653 glTexCoord 0 , 0; glVertex 0 , 0; 1709 glTexCoord 0 , 0; glVertex 0 , 0;
1654 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1710 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1655 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1711 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1656 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1712 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1657 glEnd; 1713 glEnd;
1658 1714
1715 my $ycut1 = List::Util::min 1, $ycut;
1659 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1716 glBindTexture GL_TEXTURE_2D, $t2->{name};
1660 glBegin GL_QUADS; 1717 glBegin GL_QUADS;
1661 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1718 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1662 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1719 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1663 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1720 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1664 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1721 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1665 glEnd; 1722 glEnd;
1723
1724 if ($t3) {
1725 glBindTexture GL_TEXTURE_2D, $t3->{name};
1726 glBegin GL_QUADS;
1727 glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2;
1728 glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h};
1729 glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h};
1730 glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2;
1731 glEnd;
1732 }
1666 1733
1667 glDisable GL_BLEND; 1734 glDisable GL_BLEND;
1668 glDisable GL_TEXTURE_2D; 1735 glDisable GL_TEXTURE_2D;
1669} 1736}
1670 1737
1673package CFClient::UI::Gauge; 1740package CFClient::UI::Gauge;
1674 1741
1675our @ISA = CFClient::UI::VBox::; 1742our @ISA = CFClient::UI::VBox::;
1676 1743
1677sub new { 1744sub new {
1678 my ($class, %arg) = shift; 1745 my ($class, %arg) = @_;
1679 1746
1680 my $self = $class->SUPER::new ( 1747 my $self = $class->SUPER::new (
1681 @_, 1748 tooltip => $arg{type},
1749 %arg,
1682 ); 1750 );
1683 1751
1684 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1752 $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); 1753 $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"); 1754 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1);
1687 1755
1688 $self 1756 $self
1689} 1757}
1690 1758
1691sub set_fontsize { 1759sub set_fontsize {
1858sub new { 1926sub new {
1859 my $class = shift; 1927 my $class = shift;
1860 1928
1861 my $self = $class->SUPER::new ( 1929 my $self = $class->SUPER::new (
1862 fontsize => 1, 1930 fontsize => 1,
1931 #font => default_font
1863 @_, 1932 @_,
1864 1933
1865 layout => (new CFClient::Layout), 1934 layout => (new CFClient::Layout),
1866 par => [], 1935 par => [],
1867 height => 0, 1936 height => 0,
1907sub size_allocate { 1976sub size_allocate {
1908 my ($self, $w, $h) = @_; 1977 my ($self, $w, $h) = @_;
1909 1978
1910 $self->SUPER::size_allocate ($w, $h); 1979 $self->SUPER::size_allocate ($w, $h);
1911 1980
1981 $self->{layout}->set_font ($self->{font}) if $self->{font};
1912 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1982 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1913 $self->{layout}->set_width ($self->{children}[0]{w}); 1983 $self->{layout}->set_width ($self->{children}[0]{w});
1914 1984
1915 $self->reflow; 1985 $self->reflow;
1916} 1986}
1968 my $y1 = $top + $self->{h}; 2038 my $y1 = $top + $self->{h};
1969 2039
1970 my $y = 0; 2040 my $y = 0;
1971 2041
1972 my $layout = $self->{layout}; 2042 my $layout = $self->{layout};
2043
2044 $layout->set_font ($self->{font}) if $self->{font};
1973 2045
1974 for my $par (@{$self->{par}}) { 2046 for my $par (@{$self->{par}}) {
1975 my $h = $par->[0]; 2047 my $h = $par->[0];
1976 2048
1977 if ($y0 < $y + $h && $y < $y1) { 2049 if ($y0 < $y + $h && $y < $y1) {
2057 my $class = shift; 2129 my $class = shift;
2058 2130
2059 my $self = $class->SUPER::new ( 2131 my $self = $class->SUPER::new (
2060 state => 0, 2132 state => 0,
2061 connect_activate => \&toggle_flopper, 2133 connect_activate => \&toggle_flopper,
2134 can_events => 1,
2062 @_ 2135 @_
2063 ); 2136 );
2064 2137
2065 if ($self->{state}) { 2138 if ($self->{state}) {
2066 $self->{state} = 0; 2139 $self->{state} = 0;
2086 $self->emit (changed => $self->{state}); 2159 $self->emit (changed => $self->{state});
2087} 2160}
2088 2161
2089############################################################################# 2162#############################################################################
2090 2163
2164package CFClient::UI::Tooltip;
2165
2166our @ISA = CFClient::UI::Bin::;
2167
2168use CFClient::OpenGL;
2169
2170sub new {
2171 my $class = shift;
2172
2173 $class->SUPER::new (
2174 @_,
2175 can_events => 0,
2176 )
2177}
2178
2179sub set_text {
2180 my ($self, $text) = @_;
2181
2182 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2183 $self->{label}->set_text ($text);
2184 $self->add ($self->{label});
2185}
2186
2187sub size_request {
2188 my ($self) = @_;
2189
2190 $self->child->set_max_size ($::WIDTH * 0.2);
2191
2192 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2193
2194 ($w + 4, $h + 4)
2195}
2196
2197sub _draw {
2198 my ($self) = @_;
2199
2200 glPushMatrix;
2201 glTranslate 0.375, 0.375;
2202
2203 my ($w, $h) = @$self{qw(w h)};
2204
2205 glColor 1, 0.8, 0.4;
2206 glBegin GL_QUADS;
2207 glVertex 0 , 0;
2208 glVertex 0 , $h;
2209 glVertex $w, $h;
2210 glVertex $w, 0;
2211 glEnd;
2212
2213 glColor 0, 0, 0;
2214 glBegin GL_LINE_LOOP;
2215 glVertex 0 , 0;
2216 glVertex 0 , $h;
2217 glVertex $w, $h;
2218 glVertex $w, 0;
2219 glEnd;
2220
2221 glPopMatrix;
2222
2223 glTranslate 2, 2;
2224 $self->SUPER::_draw;
2225}
2226
2227#############################################################################
2228
2091package CFClient::UI::Root; 2229package CFClient::UI::Root;
2092 2230
2093our @ISA = CFClient::UI::Container::; 2231our @ISA = CFClient::UI::Container::;
2094 2232
2095use CFClient::OpenGL; 2233use CFClient::OpenGL;
2170############################################################################# 2308#############################################################################
2171 2309
2172package CFClient::UI; 2310package CFClient::UI;
2173 2311
2174$ROOT = new CFClient::UI::Root; 2312$ROOT = new CFClient::UI::Root;
2313$TOOLTIP = new CFClient::UI::Tooltip;
2175 2314
21761 23151
2177 2316

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines