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.147 by root, Sat Apr 22 03:50:25 2006 UTC vs.
Revision 1.157 by root, Sun Apr 23 21:47:32 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_(.*)$/) {
175 } 209 }
176} 210}
177 211
178sub size_allocate { 212sub size_allocate {
179 # nothing to be done 213 # nothing to be done
214}
215
216sub set_max_size {
217 my ($self, $w, $h) = @_;
218
219 delete $self->{max_w}; $self->{max_w} = $w if $w;
220 delete $self->{max_h}; $self->{max_h} = $h if $h;
180} 221}
181 222
182# return top left coordinates 223# return top left coordinates
183sub _topleft { 224sub _topleft {
184 my ($self, $x, $y) = @_; 225 my ($self, $x, $y) = @_;
278} 319}
279 320
280sub find_widget { 321sub find_widget {
281 my ($self, $x, $y) = @_; 322 my ($self, $x, $y) = @_;
282 323
324 return () unless $self->{can_events};
325
283 return $self 326 return $self
284 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 327 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
285 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 328 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
286 329
287 () 330 ()
294} 337}
295 338
296sub check_size { 339sub check_size {
297 my ($self) = @_; 340 my ($self) = @_;
298 341
342 return unless $self->{parent};
343
299 my ($w, $h) = $self->size_request; 344 my ($w, $h) = $self->size_request;
300 345
301 if ($w != $self->{req_w} || $h != $self->{req_h}) { 346 if ($w != $self->{req_w} || $h != $self->{req_h}) {
302 $self->{req_w} = $w; 347 $self->{req_w} = $w;
303 $self->{req_h} = $h; 348 $self->{req_h} = $h;
304 349
305 $self->{parent}->check_size 350 $self->{parent}->check_size;
306 if $self->{parent};
307 } 351 }
308} 352}
309 353
310sub update { 354sub update {
311 my ($self) = @_; 355 my ($self) = @_;
378 422
379package CFClient::UI::Empty; 423package CFClient::UI::Empty;
380 424
381our @ISA = CFClient::UI::Base::; 425our @ISA = CFClient::UI::Base::;
382 426
427sub new {
428 my ($class, %arg) = @_;
429 $class->SUPER::new (can_events => 0, %arg);
430}
431
383sub size_request { 432sub size_request {
384 (0, 0) 433 (0, 0)
385} 434}
386 435
387sub draw { } 436sub draw { }
395sub new { 444sub new {
396 my ($class, %arg) = @_; 445 my ($class, %arg) = @_;
397 446
398 my $children = delete $arg{children} || []; 447 my $children = delete $arg{children} || [];
399 448
400 my $self = $class->SUPER::new (children => [], %arg); 449 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
401 $self->add ($_) for @$children; 450 $self->add ($_) for @$children;
402 451
403 $self 452 $self
404} 453}
405 454
424 delete $child->{parent}; 473 delete $child->{parent};
425 474
426 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 475 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
427 476
428 $self->check_size; 477 $self->check_size;
478 $self->update;
429} 479}
430 480
431sub find_widget { 481sub find_widget {
432 my ($self, $x, $y) = @_; 482 my ($self, $x, $y) = @_;
433 483
561sub new { die } 611sub new { die }
562 612
563sub size_request { 613sub size_request {
564 my ($self) = @_; 614 my ($self) = @_;
565 615
566 @$self{qw(child_w child_h)} = $self->child->size_request; 616 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
567 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); 617 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
568 618
569 @$self{qw(child_w child_h)} 619 @$self{qw(child_w child_h)}
570} 620}
571 621
581package CFClient::UI::Frame; 631package CFClient::UI::Frame;
582 632
583our @ISA = CFClient::UI::Bin::; 633our @ISA = CFClient::UI::Bin::;
584 634
585use CFClient::OpenGL; 635use CFClient::OpenGL;
586
587sub size_request {
588 my ($self) = @_;
589 my $chld = $self->child
590 or return (0, 0);
591
592 $chld->move (2, 2);
593
594 map { $_ + 4 } $chld->size_request;
595}
596
597sub size_allocate {
598 my ($self, $x, $y, $w, $h) = @_;
599
600 $self->child->configure (2, 2, $w - 4, $h - 4);
601}
602
603sub _draw {
604 my ($self) = @_;
605
606 my $chld = $self->child;
607
608 my ($w, $h) = $chld->size_request;
609
610 glBegin GL_QUADS;
611 glColor 0, 0, 0;
612 glVertex 0 , 0;
613 glVertex 0 , $h + 4;
614 glVertex $w + 4 , $h + 4;
615 glVertex $w + 4 , 0;
616 glEnd;
617
618 $chld->draw;
619}
620
621#############################################################################
622
623package CFClient::UI::FancyFrame;
624
625our @ISA = CFClient::UI::Bin::;
626
627use CFClient::OpenGL;
628
629my @tex =
630 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
631 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
632 636
633sub new { 637sub new {
634 my $class = shift; 638 my $class = shift;
635
636 # TODO: user_x, user_y, overwrite moveto?
637 639
638 my $self = $class->SUPER::new ( 640 my $self = $class->SUPER::new (
639 bg => [1, 1, 1, 1], 641 bg => [1, 1, 1, 1],
640 border_bg => [1, 1, 1, 1], 642 border_bg => [1, 1, 1, 1],
641 border => 0.8, 643 border => 0.8,
642 @_ 644 @_
643 ); 645 );
644 646
647 $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}
668
669sub _draw {
670 my ($self) = @_;
671
672 my ($w, $h) = ($self->{w}, $self->{h});
673
674 glEnable GL_BLEND;
675 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
676 glEnable GL_TEXTURE_2D;
677 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
678
679# glBegin GL_QUADS;
680# glColor 0, 0, 0, 0;
681# glVertex 0 , 0;
682# glVertex 0 , $h;
683# glVertex $w, $h;
684# glVertex $w, 0;
685# glEnd;
686
687
688 $self->child->draw;
689 glDisable GL_BLEND;
690 glDisable GL_TEXTURE_2D;
691}
692
693#############################################################################
694
695package CFClient::UI::FancyFrame;
696
697our @ISA = CFClient::UI::Bin::;
698
699use CFClient::OpenGL;
700
701my @tex =
702 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
703 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
704
705sub new {
706 my $class = shift;
707
708 # TODO: user_x, user_y, overwrite moveto?
709
710 my $self = $class->SUPER::new (
711 bg => [1, 1, 1, 1],
712 border_bg => [1, 1, 1, 1],
713 border => 0.8,
714 can_events => 1,
715 @_
716 );
717
645 $self->{title} &&= new CFClient::UI::Label 718 $self->{title} &&= new CFClient::UI::Label
646 align => 0, 719 align => 0,
647 valign => 1, 720 valign => 1,
648 text => $self->{title}, 721 text => $self->{title},
649 fontsize => 1; 722 fontsize => 1;
815 or next; 888 or next;
816 889
817 for my $x (0 .. $#$row) { 890 for my $x (0 .. $#$row) {
818 my $widget = $row->[$x] 891 my $widget = $row->[$x]
819 or next; 892 or next;
820 my ($w, $h) = $widget->size_request; 893 my ($w, $h) = @$widget{qw(req_w req_h)};
821 894
822 $w[$x] = max $w[$x], $w; 895 $w[$x] = max $w[$x], $w;
823 $h[$y] = max $h[$y], $h; 896 $h[$y] = max $h[$y], $h;
824 } 897 }
825 } 898 }
930 1003
931 ($h, $w) = ($w, $h); 1004 ($h, $w) = ($w, $h);
932 1005
933 my $children = $self->{children}; 1006 my $children = $self->{children};
934 1007
935 my @h = map +($_->size_request)[0], @$children; 1008 my @h = map $_->{req_w}, @$children;
936 1009
937 my $req_h = List::Util::sum @h; 1010 my $req_h = List::Util::sum @h;
938 1011
939 if ($req_h > $h) { 1012 if ($req_h > $h) {
940 # ah well, not enough space 1013 # ah well, not enough space
988sub size_allocate { 1061sub size_allocate {
989 my ($self, $w, $h) = @_; 1062 my ($self, $w, $h) = @_;
990 1063
991 my $children = $self->{children}; 1064 my $children = $self->{children};
992 1065
993 my @h = map +($_->size_request)[1], @$children; 1066 my @h = map $_->{req_h}, @$children;
994 1067
995 my $req_h = List::Util::sum @h; 1068 my $req_h = List::Util::sum @h;
996 1069
997 if ($req_h > $h) { 1070 if ($req_h > $h) {
998 # ah well, not enough space 1071 # ah well, not enough space
1033sub new { 1106sub new {
1034 my ($class, %arg) = @_; 1107 my ($class, %arg) = @_;
1035 1108
1036 my $self = $class->SUPER::new ( 1109 my $self = $class->SUPER::new (
1037 fg => [1, 1, 1], 1110 fg => [1, 1, 1],
1111 #font => default_font
1038 fontsize => 1, 1112 fontsize => 1,
1039 text => "", 1113 text => "",
1040 align => -1, 1114 align => -1,
1041 valign => -1, 1115 valign => -1,
1042 padding => 2, 1116 padding => 2,
1043 layout => new CFClient::Layout, 1117 layout => new CFClient::Layout,
1118 can_events => 0,
1044 %arg 1119 %arg
1045 ); 1120 );
1046 1121
1047 if (exists $self->{template}) { 1122 if (exists $self->{template}) {
1048 my $layout = new CFClient::Layout; 1123 my $layout = new CFClient::Layout;
1070 my ($self, $text) = @_; 1145 my ($self, $text) = @_;
1071 1146
1072 $self->{layout}->set_text ($text); 1147 $self->{layout}->set_text ($text);
1073 1148
1074 delete $self->{texture}; 1149 delete $self->{texture};
1150 $self->check_size;
1075 $self->update; 1151 $self->update;
1076} 1152}
1077 1153
1078sub set_markup { 1154sub set_markup {
1079 my ($self, $markup) = @_; 1155 my ($self, $markup) = @_;
1080 1156
1081 $self->{layout}->set_markup ($markup); 1157 $self->{layout}->set_markup ($markup);
1082 1158
1083 delete $self->{texture}; 1159 delete $self->{texture};
1160 $self->check_size;
1084 $self->update; 1161 $self->update;
1085} 1162}
1086 1163
1087sub size_request { 1164sub size_request {
1088 my ($self) = @_; 1165 my ($self) = @_;
1089 1166
1090 $self->{layout}->set_width; 1167 $self->{layout}->set_font ($self->{font}) if $self->{font};
1168 $self->{layout}->set_width ($self->{max_w} || -1);
1091 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1169 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1092 1170
1093 my ($w, $h) = $self->{layout}->size; 1171 my ($w, $h) = $self->{layout}->size;
1094 1172
1095 if (exists $self->{template}) { 1173 if (exists $self->{template}) {
1174 $self->{template}->set_font ($self->{font}) if $self->{font};
1096 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1175 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1097 1176
1098 my ($w2, $h2) = $self->{template}->size; 1177 my ($w2, $h2) = $self->{template}->size;
1099 1178
1100 $w = List::Util::max $w, $w2; 1179 $w = List::Util::max $w, $w2;
1115 1194
1116sub set_fontsize { 1195sub set_fontsize {
1117 my ($self, $fontsize) = @_; 1196 my ($self, $fontsize) = @_;
1118 1197
1119 $self->{fontsize} = $fontsize; 1198 $self->{fontsize} = $fontsize;
1199 delete $self->{texture};
1120 $self->check_size; 1200 $self->check_size;
1201 $self->update;
1121} 1202}
1122 1203
1123sub _draw { 1204sub _draw {
1124 my ($self) = @_; 1205 my ($self) = @_;
1125 1206
1126 my $tex = $self->{texture} ||= do { 1207 my $tex = $self->{texture} ||= do {
1208 $self->{layout}->set_font ($self->{font}) if $self->{font};
1127 $self->{layout}->set_width ($self->{w}); 1209 $self->{layout}->set_width ($self->{w});
1128 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1210 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1129 new_from_layout CFClient::Texture $self->{layout} 1211 new_from_layout CFClient::Texture $self->{layout}
1130 }; 1212 };
1131 1213
1171 active_bg => [1, 1, 1, 0.5], 1253 active_bg => [1, 1, 1, 0.5],
1172 active_fg => [0, 0, 0], 1254 active_fg => [0, 0, 0],
1173 can_hover => 1, 1255 can_hover => 1,
1174 can_focus => 1, 1256 can_focus => 1,
1175 valign => 0, 1257 valign => 0,
1258 can_events => 1,
1176 @_ 1259 @_
1177 ) 1260 )
1178} 1261}
1179 1262
1180sub _set_text { 1263sub _set_text {
1208} 1291}
1209 1292
1210sub size_allocate { 1293sub size_allocate {
1211 my ($self, $w, $h) = @_; 1294 my ($self, $w, $h) = @_;
1212 1295
1213 $self->_set_text ($self->{text}); 1296 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1214} 1297}
1215 1298
1216sub set_text { 1299sub set_text {
1217 my ($self, $text) = @_; 1300 my ($self, $text) = @_;
1218 1301
1365 bg => [1, 1, 1, 0.2], 1448 bg => [1, 1, 1, 0.2],
1366 active_fg => [0, 0, 1], 1449 active_fg => [0, 0, 1],
1367 can_hover => 1, 1450 can_hover => 1,
1368 align => 0, 1451 align => 0,
1369 valign => 0, 1452 valign => 0,
1453 can_events => 1,
1370 @_ 1454 @_
1371 ) 1455 )
1372} 1456}
1373 1457
1374sub button_up { 1458sub button_up {
1479our %loaded_images; 1563our %loaded_images;
1480 1564
1481sub new { 1565sub new {
1482 my $class = shift; 1566 my $class = shift;
1483 1567
1484 my $self = $class->SUPER::new (@_); 1568 my $self = $class->SUPER::new (can_events => 0, @_);
1485 1569
1486 $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; 1570 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1487 1571
1488 $loaded_images{$self->{image}} ||= 1572 $loaded_images{$self->{image}} ||=
1489 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; 1573 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1648package CFClient::UI::Gauge; 1732package CFClient::UI::Gauge;
1649 1733
1650our @ISA = CFClient::UI::VBox::; 1734our @ISA = CFClient::UI::VBox::;
1651 1735
1652sub new { 1736sub new {
1653 my ($class, %arg) = shift; 1737 my ($class, %arg) = @_;
1654 1738
1655 my $self = $class->SUPER::new ( 1739 my $self = $class->SUPER::new (
1656 @_, 1740 tooltip => $arg{type},
1741 %arg,
1657 ); 1742 );
1658 1743
1659 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1744 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1);
1660 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1745 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1);
1661 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1746 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1);
1662 1747
1663 $self 1748 $self
1664} 1749}
1665 1750
1666sub set_fontsize { 1751sub set_fontsize {
1833sub new { 1918sub new {
1834 my $class = shift; 1919 my $class = shift;
1835 1920
1836 my $self = $class->SUPER::new ( 1921 my $self = $class->SUPER::new (
1837 fontsize => 1, 1922 fontsize => 1,
1923 #font => default_font
1838 @_, 1924 @_,
1839 1925
1840 layout => (new CFClient::Layout), 1926 layout => (new CFClient::Layout),
1841 par => [], 1927 par => [],
1842 height => 0, 1928 height => 0,
1882sub size_allocate { 1968sub size_allocate {
1883 my ($self, $w, $h) = @_; 1969 my ($self, $w, $h) = @_;
1884 1970
1885 $self->SUPER::size_allocate ($w, $h); 1971 $self->SUPER::size_allocate ($w, $h);
1886 1972
1973 $self->{layout}->set_font ($self->{font}) if $self->{font};
1887 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1974 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1888 $self->{layout}->set_width ($self->{children}[0]{w}); 1975 $self->{layout}->set_width ($self->{children}[0]{w});
1889 1976
1890 $self->reflow; 1977 $self->reflow;
1891} 1978}
1943 my $y1 = $top + $self->{h}; 2030 my $y1 = $top + $self->{h};
1944 2031
1945 my $y = 0; 2032 my $y = 0;
1946 2033
1947 my $layout = $self->{layout}; 2034 my $layout = $self->{layout};
2035
2036 $layout->set_font ($self->{font}) if $self->{font};
1948 2037
1949 for my $par (@{$self->{par}}) { 2038 for my $par (@{$self->{par}}) {
1950 my $h = $par->[0]; 2039 my $h = $par->[0];
1951 2040
1952 if ($y0 < $y + $h && $y < $y1) { 2041 if ($y0 < $y + $h && $y < $y1) {
2032 my $class = shift; 2121 my $class = shift;
2033 2122
2034 my $self = $class->SUPER::new ( 2123 my $self = $class->SUPER::new (
2035 state => 0, 2124 state => 0,
2036 connect_activate => \&toggle_flopper, 2125 connect_activate => \&toggle_flopper,
2126 can_events => 1,
2037 @_ 2127 @_
2038 ); 2128 );
2039 2129
2040 if ($self->{state}) { 2130 if ($self->{state}) {
2041 $self->{state} = 0; 2131 $self->{state} = 0;
2061 $self->emit (changed => $self->{state}); 2151 $self->emit (changed => $self->{state});
2062} 2152}
2063 2153
2064############################################################################# 2154#############################################################################
2065 2155
2156package CFClient::UI::Tooltip;
2157
2158our @ISA = CFClient::UI::Bin::;
2159
2160use CFClient::OpenGL;
2161
2162sub new {
2163 my $class = shift;
2164
2165 $class->SUPER::new (
2166 @_,
2167 can_events => 0,
2168 )
2169}
2170
2171sub set_text {
2172 my ($self, $text) = @_;
2173
2174 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2175 $self->{label}->set_text ($text);
2176 $self->add ($self->{label});
2177}
2178
2179sub size_request {
2180 my ($self) = @_;
2181
2182 $self->child->set_max_size ($::WIDTH * 0.2);
2183
2184 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2185
2186 ($w + 4, $h + 4)
2187}
2188
2189sub _draw {
2190 my ($self) = @_;
2191
2192 glPushMatrix;
2193 glTranslate 0.375, 0.375;
2194
2195 my ($w, $h) = @$self{qw(w h)};
2196
2197 glColor 1, 0.8, 0.4;
2198 glBegin GL_QUADS;
2199 glVertex 0 , 0;
2200 glVertex 0 , $h;
2201 glVertex $w, $h;
2202 glVertex $w, 0;
2203 glEnd;
2204
2205 glColor 0, 0, 0;
2206 glBegin GL_LINE_LOOP;
2207 glVertex 0 , 0;
2208 glVertex 0 , $h;
2209 glVertex $w, $h;
2210 glVertex $w, 0;
2211 glEnd;
2212
2213 glPopMatrix;
2214
2215 glTranslate 2, 2;
2216 $self->SUPER::_draw;
2217}
2218
2219#############################################################################
2220
2066package CFClient::UI::Root; 2221package CFClient::UI::Root;
2067 2222
2068our @ISA = CFClient::UI::Container::; 2223our @ISA = CFClient::UI::Container::;
2069 2224
2070use CFClient::OpenGL; 2225use CFClient::OpenGL;
2071 2226
2072sub check_size { 2227sub check_size {
2073 my ($self) = @_; 2228 my ($self) = @_;
2074 2229
2075 $self->configure (0, 0, $::WITH, $::HEIGHT); 2230 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
2076} 2231}
2077 2232
2078sub size_request { 2233sub size_request {
2079 ($::WIDTH, $::HEIGHT) 2234 ($::WIDTH, $::HEIGHT)
2080} 2235}
2082sub configure { 2237sub configure {
2083 my ($self, $x, $y, $w, $h) = @_; 2238 my ($self, $x, $y, $w, $h) = @_;
2084 2239
2085 $self->SUPER::configure ($x, $y, $w, $h); 2240 $self->SUPER::configure ($x, $y, $w, $h);
2086 2241
2087 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2088 for @{$self->{children}}; 2242 for my $child (@{$self->{children}}) {
2243 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2244
2245 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2246 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2247 $child->configure ($X, $Y, $W,$H);
2248 }
2089} 2249}
2090 2250
2091sub _topleft { 2251sub _topleft {
2092 my ($self, $x, $y) = @_; 2252 my ($self, $x, $y) = @_;
2093 2253
2140############################################################################# 2300#############################################################################
2141 2301
2142package CFClient::UI; 2302package CFClient::UI;
2143 2303
2144$ROOT = new CFClient::UI::Root; 2304$ROOT = new CFClient::UI::Root;
2305$TOOLTIP = new CFClient::UI::Tooltip;
2145 2306
21461 23071
2147 2308

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines