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.143 by root, Thu Apr 20 21:28:51 2006 UTC vs.
Revision 1.154 by root, Sun Apr 23 02:20:57 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 $TOOLTIP->set_text ($widget->{tooltip});
24 $TOOLTIP->move ($widget->coord2global ($widget->{w}, 0));
25 $TOOLTIP->show;
26 }
27
28 return;
29 }
30 }
31 }
32
33 $TOOLTIP->hide;
34 delete $TOOLTIP->{owner};
35}
14 36
15# class methods for events 37# class methods for events
16sub feed_sdl_key_down_event { 38sub feed_sdl_key_down_event {
17 $FOCUS->key_down ($_[0]) if $FOCUS; 39 $FOCUS->key_down ($_[0]) if $FOCUS;
18} 40}
28 if (!$BUTTON_STATE) { 50 if (!$BUTTON_STATE) {
29 my $widget = $ROOT->find_widget ($x, $y); 51 my $widget = $ROOT->find_widget ($x, $y);
30 52
31 $GRAB = $widget; 53 $GRAB = $widget;
32 $GRAB->update if $GRAB; 54 $GRAB->update if $GRAB;
55
56 check_tooltip;
33 } 57 }
34 58
35 $BUTTON_STATE |= 1 << ($ev->{button} - 1); 59 $BUTTON_STATE |= 1 << ($ev->{button} - 1);
36 60
37 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB; 61 $GRAB->button_down ($ev, $GRAB->coord2local ($x, $y)) if $GRAB;
49 73
50 if (!$BUTTON_STATE) { 74 if (!$BUTTON_STATE) {
51 my $grab = $GRAB; undef $GRAB; 75 my $grab = $GRAB; undef $GRAB;
52 $grab->update if $grab; 76 $grab->update if $grab;
53 $GRAB->update if $GRAB; 77 $GRAB->update if $GRAB;
78
79 check_tooltip;
54 } 80 }
55} 81}
56 82
57sub feed_sdl_motion_event { 83sub feed_sdl_motion_event {
58 my ($ev) = @_; 84 my ($ev) = @_;
63 if ($widget != $HOVER) { 89 if ($widget != $HOVER) {
64 my $hover = $HOVER; $HOVER = $widget; 90 my $hover = $HOVER; $HOVER = $widget;
65 91
66 $hover->update if $hover && $hover->{can_hover}; 92 $hover->update if $hover && $hover->{can_hover};
67 $HOVER->update if $HOVER && $HOVER->{can_hover}; 93 $HOVER->update if $HOVER && $HOVER->{can_hover};
94
95 check_tooltip;
68 } 96 }
69 97
70 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; 98 $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER;
71} 99}
72 100
96 124
97 my $self = bless { 125 my $self = bless {
98 x => 0, 126 x => 0,
99 y => 0, 127 y => 0,
100 z => 0, 128 z => 0,
129 can_events => 1,
101 @_ 130 @_
102 }, $class; 131 }, $class;
103 132
104 for (keys %$self) { 133 for (keys %$self) {
105 if (/^connect_(.*)$/) { 134 if (/^connect_(.*)$/) {
140 0 169 0
141} 170}
142 171
143sub size_request { 172sub size_request {
144 require Carp; 173 require Carp;
145 Carp::confess "size_request is abtract"; 174 Carp::confess "size_request is abstract";
146} 175}
147 176
148sub configure { 177sub configure {
149 my ($self, $x, $y, $w, $h) = @_; 178 my ($self, $x, $y, $w, $h) = @_;
150 179
152 my $w2 = List::Util::min $w, int $h * $self->{aspect}; 181 my $w2 = List::Util::min $w, int $h * $self->{aspect};
153 my $h2 = List::Util::min $h, int $w / $self->{aspect}; 182 my $h2 = List::Util::min $h, int $w / $self->{aspect};
154 183
155 # use alignment to adjust x, y 184 # use alignment to adjust x, y
156 185
157 $x += ($w - $w2) * 0.5; 186 $x += int +($w - $w2) * 0.5;
158 $y += ($h - $h2) * 0.5; 187 $y += int +($h - $h2) * 0.5;
159 188
160 ($w, $h) = ($w2, $h2); 189 ($w, $h) = ($w2, $h2);
161 } 190 }
162 191
163 if ($self->{x} != $x || $self->{y} != $y) { 192 if ($self->{x} != $x || $self->{y} != $y) {
278} 307}
279 308
280sub find_widget { 309sub find_widget {
281 my ($self, $x, $y) = @_; 310 my ($self, $x, $y) = @_;
282 311
312 return () unless $self->{can_events};
313
283 return $self 314 return $self
284 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 315 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
285 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 316 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
286 317
287 () 318 ()
294} 325}
295 326
296sub check_size { 327sub check_size {
297 my ($self) = @_; 328 my ($self) = @_;
298 329
330 return unless $self->{parent};
331
299 my ($w, $h) = $self->size_request; 332 my ($w, $h) = $self->size_request;
300 333
301 if ($w != $self->{req_w} || $h != $self->{req_h}) { 334 if ($w != $self->{req_w} || $h != $self->{req_h}) {
302 $self->{req_w} = $w; 335 $self->{req_w} = $w;
303 $self->{req_h} = $h; 336 $self->{req_h} = $h;
304 337
305 $self->{parent}->check_size 338 $self->{parent}->check_size;
306 if $self->{parent};
307 } 339 }
308} 340}
309 341
310sub update { 342sub update {
311 my ($self) = @_; 343 my ($self) = @_;
378 410
379package CFClient::UI::Empty; 411package CFClient::UI::Empty;
380 412
381our @ISA = CFClient::UI::Base::; 413our @ISA = CFClient::UI::Base::;
382 414
415sub new {
416 my ($class, %arg) = @_;
417 $class->SUPER::new (can_events => 0, %arg);
418}
419
383sub size_request { 420sub size_request {
384 (0, 0) 421 (0, 0)
385} 422}
386 423
387sub draw { } 424sub draw { }
395sub new { 432sub new {
396 my ($class, %arg) = @_; 433 my ($class, %arg) = @_;
397 434
398 my $children = delete $arg{children} || []; 435 my $children = delete $arg{children} || [];
399 436
400 my $self = $class->SUPER::new (children => [], %arg); 437 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
401 $self->add ($_) for @$children; 438 $self->add ($_) for @$children;
402 439
403 $self 440 $self
404} 441}
405 442
424 delete $child->{parent}; 461 delete $child->{parent};
425 462
426 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 463 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
427 464
428 $self->check_size; 465 $self->check_size;
466 $self->update;
429} 467}
430 468
431sub find_widget { 469sub find_widget {
432 my ($self, $x, $y) = @_; 470 my ($self, $x, $y) = @_;
433 471
561sub new { die } 599sub new { die }
562 600
563sub size_request { 601sub size_request {
564 my ($self) = @_; 602 my ($self) = @_;
565 603
566 @$self{qw(child_w child_h)} = $self->child->size_request; 604 @$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)}); 605 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
568 606
569 @$self{qw(child_w child_h)} 607 @$self{qw(child_w child_h)}
570} 608}
571 609
581package CFClient::UI::Frame; 619package CFClient::UI::Frame;
582 620
583our @ISA = CFClient::UI::Bin::; 621our @ISA = CFClient::UI::Bin::;
584 622
585use CFClient::OpenGL; 623use 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 $_ }
631 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
632 624
633sub new { 625sub new {
634 my $class = shift; 626 my $class = shift;
635
636 # TODO: user_x, user_y, overwrite moveto?
637 627
638 my $self = $class->SUPER::new ( 628 my $self = $class->SUPER::new (
639 bg => [1, 1, 1, 1], 629 bg => [1, 1, 1, 1],
640 border_bg => [1, 1, 1, 1], 630 border_bg => [1, 1, 1, 1],
641 border => 0.8, 631 border => 0.8,
642 @_ 632 @_
643 ); 633 );
644 634
635 $self
636}
637
638sub set_size {
639 my ($self, $w, $h) = @_;
640 $self->{req_w} = $w;
641 $self->{req_h} = $h;
642 $self->check_size;
643}
644
645sub size_request {
646 my ($self) = @_;
647 ($self->{req_w}, $self->{req_h})
648}
649
650sub size_allocate {
651 my ($self, $w, $h) = @_;
652 $self->{w} = $w;
653 $self->{h} = $h;
654 $self->child->configure (0, 0, $w, $h);
655}
656
657sub _draw {
658 my ($self) = @_;
659
660 my ($w, $h) = ($self->{w}, $self->{h});
661
662 glEnable GL_BLEND;
663 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
664 glEnable GL_TEXTURE_2D;
665 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
666
667# glBegin GL_QUADS;
668# glColor 0, 0, 0, 0;
669# glVertex 0 , 0;
670# glVertex 0 , $h;
671# glVertex $w, $h;
672# glVertex $w, 0;
673# glEnd;
674
675
676 $self->child->draw;
677 glDisable GL_BLEND;
678 glDisable GL_TEXTURE_2D;
679}
680
681#############################################################################
682
683package CFClient::UI::FancyFrame;
684
685our @ISA = CFClient::UI::Bin::;
686
687use CFClient::OpenGL;
688
689my @tex =
690 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
691 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
692
693sub new {
694 my $class = shift;
695
696 # TODO: user_x, user_y, overwrite moveto?
697
698 my $self = $class->SUPER::new (
699 bg => [1, 1, 1, 1],
700 border_bg => [1, 1, 1, 1],
701 border => 0.8,
702 can_events => 1,
703 @_
704 );
705
645 $self->{title} &&= new CFClient::UI::Label 706 $self->{title} &&= new CFClient::UI::Label
646 align => 0, 707 align => 0,
647 valign => 1, 708 valign => 1,
648 text => $self->{title}, 709 text => $self->{title},
649 fontsize => 1; 710 fontsize => 1;
815 or next; 876 or next;
816 877
817 for my $x (0 .. $#$row) { 878 for my $x (0 .. $#$row) {
818 my $widget = $row->[$x] 879 my $widget = $row->[$x]
819 or next; 880 or next;
820 my ($w, $h) = $widget->size_request; 881 my ($w, $h) = @$widget{qw(req_w req_h)};
821 882
822 $w[$x] = max $w[$x], $w; 883 $w[$x] = max $w[$x], $w;
823 $h[$y] = max $h[$y], $h; 884 $h[$y] = max $h[$y], $h;
824 } 885 }
825 } 886 }
930 991
931 ($h, $w) = ($w, $h); 992 ($h, $w) = ($w, $h);
932 993
933 my $children = $self->{children}; 994 my $children = $self->{children};
934 995
935 my @h = map +($_->size_request)[0], @$children; 996 my @h = map $_->{req_w}, @$children;
936 997
937 my $req_h = List::Util::sum @h; 998 my $req_h = List::Util::sum @h;
938 999
939 if ($req_h > $h) { 1000 if ($req_h > $h) {
940 # ah well, not enough space 1001 # ah well, not enough space
988sub size_allocate { 1049sub size_allocate {
989 my ($self, $w, $h) = @_; 1050 my ($self, $w, $h) = @_;
990 1051
991 my $children = $self->{children}; 1052 my $children = $self->{children};
992 1053
993 my @h = map +($_->size_request)[1], @$children; 1054 my @h = map $_->{req_h}, @$children;
994 1055
995 my $req_h = List::Util::sum @h; 1056 my $req_h = List::Util::sum @h;
996 1057
997 if ($req_h > $h) { 1058 if ($req_h > $h) {
998 # ah well, not enough space 1059 # ah well, not enough space
1039 text => "", 1100 text => "",
1040 align => -1, 1101 align => -1,
1041 valign => -1, 1102 valign => -1,
1042 padding => 2, 1103 padding => 2,
1043 layout => new CFClient::Layout, 1104 layout => new CFClient::Layout,
1105 can_events => 0,
1044 %arg 1106 %arg
1045 ); 1107 );
1046 1108
1047 if (exists $self->{template}) { 1109 if (exists $self->{template}) {
1048 my $layout = new CFClient::Layout; 1110 my $layout = new CFClient::Layout;
1070 my ($self, $text) = @_; 1132 my ($self, $text) = @_;
1071 1133
1072 $self->{layout}->set_text ($text); 1134 $self->{layout}->set_text ($text);
1073 1135
1074 delete $self->{texture}; 1136 delete $self->{texture};
1137 $self->check_size;
1075 $self->update; 1138 $self->update;
1076} 1139}
1077 1140
1078sub set_markup { 1141sub set_markup {
1079 my ($self, $markup) = @_; 1142 my ($self, $markup) = @_;
1080 1143
1081 $self->{layout}->set_markup ($markup); 1144 $self->{layout}->set_markup ($markup);
1082 1145
1083 delete $self->{texture}; 1146 delete $self->{texture};
1147 $self->check_size;
1084 $self->update; 1148 $self->update;
1085} 1149}
1086 1150
1087sub size_request { 1151sub size_request {
1088 my ($self) = @_; 1152 my ($self) = @_;
1109 1173
1110sub size_allocate { 1174sub size_allocate {
1111 my ($self, $w, $h) = @_; 1175 my ($self, $w, $h) = @_;
1112 1176
1113 delete $self->{texture}; 1177 delete $self->{texture};
1178}
1179
1180sub set_fontsize {
1181 my ($self, $fontsize) = @_;
1182
1183 $self->{fontsize} = $fontsize;
1184 delete $self->{texture};
1185 $self->check_size;
1186 $self->update;
1114} 1187}
1115 1188
1116sub _draw { 1189sub _draw {
1117 my ($self) = @_; 1190 my ($self) = @_;
1118 1191
1164 active_bg => [1, 1, 1, 0.5], 1237 active_bg => [1, 1, 1, 0.5],
1165 active_fg => [0, 0, 0], 1238 active_fg => [0, 0, 0],
1166 can_hover => 1, 1239 can_hover => 1,
1167 can_focus => 1, 1240 can_focus => 1,
1168 valign => 0, 1241 valign => 0,
1242 can_events => 1,
1169 @_ 1243 @_
1170 ) 1244 )
1171} 1245}
1172 1246
1173sub _set_text { 1247sub _set_text {
1201} 1275}
1202 1276
1203sub size_allocate { 1277sub size_allocate {
1204 my ($self, $w, $h) = @_; 1278 my ($self, $w, $h) = @_;
1205 1279
1206 $self->_set_text ($self->{text}); 1280 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1207} 1281}
1208 1282
1209sub set_text { 1283sub set_text {
1210 my ($self, $text) = @_; 1284 my ($self, $text) = @_;
1211 1285
1344our @ISA = CFClient::UI::Label::; 1418our @ISA = CFClient::UI::Label::;
1345 1419
1346use CFClient::OpenGL; 1420use CFClient::OpenGL;
1347 1421
1348my @tex = 1422my @tex =
1349 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1423 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1350 qw(b1_button_active.png); 1424 qw(b1_button_active.png);
1351 1425
1352sub new { 1426sub new {
1353 my $class = shift; 1427 my $class = shift;
1354 1428
1358 bg => [1, 1, 1, 0.2], 1432 bg => [1, 1, 1, 0.2],
1359 active_fg => [0, 0, 1], 1433 active_fg => [0, 0, 1],
1360 can_hover => 1, 1434 can_hover => 1,
1361 align => 0, 1435 align => 0,
1362 valign => 0, 1436 valign => 0,
1437 can_events => 1,
1363 @_ 1438 @_
1364 ) 1439 )
1365} 1440}
1366 1441
1367sub button_up { 1442sub button_up {
1401package CFClient::UI::CheckBox; 1476package CFClient::UI::CheckBox;
1402 1477
1403our @ISA = CFClient::UI::DrawBG::; 1478our @ISA = CFClient::UI::DrawBG::;
1404 1479
1405my @tex = 1480my @tex =
1406 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1481 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1407 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1482 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1408 1483
1409use CFClient::OpenGL; 1484use CFClient::OpenGL;
1410 1485
1411sub new { 1486sub new {
1460 glDisable GL_BLEND; 1535 glDisable GL_BLEND;
1461} 1536}
1462 1537
1463############################################################################# 1538#############################################################################
1464 1539
1540package CFClient::UI::Image;
1541
1542our @ISA = CFClient::UI::Base::;
1543
1544use CFClient::OpenGL;
1545use Carp qw/confess/;
1546
1547our %loaded_images;
1548
1549sub new {
1550 my $class = shift;
1551
1552 my $self = $class->SUPER::new (can_events => 0, @_);
1553
1554 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1555
1556 $loaded_images{$self->{image}} ||=
1557 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1558
1559 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1560
1561 Scalar::Util::weaken $loaded_images{$self->{image}};
1562
1563 $self->{aspect} = $tex->{w} / $tex->{h};
1564
1565 $self
1566}
1567
1568sub size_request {
1569 my ($self) = @_;
1570
1571 ($self->{tex}->{w}, $self->{tex}->{h})
1572}
1573
1574sub _draw {
1575 my ($self) = @_;
1576
1577 my $tex = $self->{tex};
1578
1579 my ($w, $h) = ($self->{w}, $self->{h});
1580
1581 if ($self->{rot90}) {
1582 glRotate 90, 0, 0, 1;
1583 glTranslate 0, -$self->{w}, 0;
1584
1585 ($w, $h) = ($h, $w);
1586 }
1587
1588 glEnable GL_BLEND;
1589 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1590 glEnable GL_TEXTURE_2D;
1591 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1592
1593 $tex->draw_quad (0, 0, $w, $h);
1594
1595 glDisable GL_BLEND;
1596 glDisable GL_TEXTURE_2D;
1597}
1598
1599#############################################################################
1600
1465package CFClient::UI::VGauge; 1601package CFClient::UI::VGauge;
1466 1602
1467our @ISA = CFClient::UI::Base::; 1603our @ISA = CFClient::UI::Base::;
1468 1604
1469use CFClient::OpenGL; 1605use CFClient::OpenGL;
1470 1606
1471my %tex = ( 1607my %tex = (
1472 food => [ 1608 food => [
1473 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1609 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1474 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1610 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1475 ], 1611 ],
1476 grace => [ 1612 grace => [
1477 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1613 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1478 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1614 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1479 ], 1615 ],
1480 hp => [ 1616 hp => [
1481 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1617 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1482 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1618 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1483 ], 1619 ],
1484 mana => [ 1620 mana => [
1485 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1621 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1486 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1622 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1487 ], 1623 ],
1488); 1624);
1489 1625
1490# eg. VGauge->new (gauge => 'food'), default gauge: food 1626# eg. VGauge->new (gauge => 'food'), default gauge: food
1580package CFClient::UI::Gauge; 1716package CFClient::UI::Gauge;
1581 1717
1582our @ISA = CFClient::UI::VBox::; 1718our @ISA = CFClient::UI::VBox::;
1583 1719
1584sub new { 1720sub new {
1585 my ($class, %arg) = shift; 1721 my ($class, %arg) = @_;
1586 1722
1587 my $self = $class->SUPER::new ( 1723 my $self = $class->SUPER::new (
1588 @_, 1724 tooltip => $arg{type},
1725 %arg,
1589 ); 1726 );
1590 1727
1591 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1728 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999");
1592 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1729 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1);
1593 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1730 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999");
1594 1731
1595 $self 1732 $self
1733}
1734
1735sub set_fontsize {
1736 my ($self, $fsize) = @_;
1737
1738 $self->{value}->set_fontsize ($fsize);
1739 $self->{max} ->set_fontsize ($fsize);
1596} 1740}
1597 1741
1598sub set_value { 1742sub set_value {
1599 my ($self, $val, $max) = @_; 1743 my ($self, $val, $max) = @_;
1600 1744
1957 my $class = shift; 2101 my $class = shift;
1958 2102
1959 my $self = $class->SUPER::new ( 2103 my $self = $class->SUPER::new (
1960 state => 0, 2104 state => 0,
1961 connect_activate => \&toggle_flopper, 2105 connect_activate => \&toggle_flopper,
2106 can_events => 1,
1962 @_ 2107 @_
1963 ); 2108 );
1964 2109
1965 if ($self->{state}) { 2110 if ($self->{state}) {
1966 $self->{state} = 0; 2111 $self->{state} = 0;
1986 $self->emit (changed => $self->{state}); 2131 $self->emit (changed => $self->{state});
1987} 2132}
1988 2133
1989############################################################################# 2134#############################################################################
1990 2135
2136package CFClient::UI::Tooltip;
2137
2138our @ISA = CFClient::UI::Bin::;
2139
2140use CFClient::OpenGL;
2141
2142sub new {
2143 my $class = shift;
2144
2145 $class->SUPER::new (
2146 @_,
2147 can_events => 0,
2148 )
2149}
2150
2151sub set_text {
2152 my ($self, $text) = @_;
2153
2154 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2155 $self->{label}->set_text ($text);
2156 $self->add ($self->{label});
2157}
2158
2159sub size_request {
2160 my ($self) = @_;
2161
2162 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2163
2164 $w = List::Util::min $::WIDTH * 0.2, $w;
2165 $h = List::Util::max $::HEIGHT * 0.2, $h;
2166
2167 ($w + 4, $h + 4)
2168}
2169
2170sub _draw {
2171 my ($self) = @_;
2172
2173 glPushMatrix;
2174 glTranslate 0.375, 0.375;
2175
2176 my ($w, $h) = @$self{qw(w h)};
2177
2178 glColor 1, 0.8, 0.4;
2179 glBegin GL_QUADS;
2180 glVertex 0 , 0;
2181 glVertex 0 , $h;
2182 glVertex $w, $h;
2183 glVertex $w, 0;
2184 glEnd;
2185
2186 glColor 0, 0, 0;
2187 glBegin GL_LINE_LOOP;
2188 glVertex 0 , 0;
2189 glVertex 0 , $h;
2190 glVertex $w, $h;
2191 glVertex $w, 0;
2192 glEnd;
2193
2194 glPopMatrix;
2195
2196 glTranslate 2, 2;
2197 $self->SUPER::_draw;
2198}
2199
2200#############################################################################
2201
1991package CFClient::UI::Root; 2202package CFClient::UI::Root;
1992 2203
1993our @ISA = CFClient::UI::Container::; 2204our @ISA = CFClient::UI::Container::;
1994 2205
1995use CFClient::OpenGL; 2206use CFClient::OpenGL;
1996 2207
1997sub check_size { 2208sub check_size {
1998 my ($self) = @_; 2209 my ($self) = @_;
1999 2210
2000 $self->configure (0, 0, $::WITH, $::HEIGHT); 2211 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
2001} 2212}
2002 2213
2003sub size_request { 2214sub size_request {
2004 ($::WIDTH, $::HEIGHT) 2215 ($::WIDTH, $::HEIGHT)
2005} 2216}
2007sub configure { 2218sub configure {
2008 my ($self, $x, $y, $w, $h) = @_; 2219 my ($self, $x, $y, $w, $h) = @_;
2009 2220
2010 $self->SUPER::configure ($x, $y, $w, $h); 2221 $self->SUPER::configure ($x, $y, $w, $h);
2011 2222
2012 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2013 for @{$self->{children}}; 2223 for my $child (@{$self->{children}}) {
2224 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2225
2226 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2227 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2228 $child->configure ($X, $Y, $W,$H);
2229 }
2014} 2230}
2015 2231
2016sub _topleft { 2232sub _topleft {
2017 my ($self, $x, $y) = @_; 2233 my ($self, $x, $y) = @_;
2018 2234
2026 ::refresh (); 2242 ::refresh ();
2027} 2243}
2028 2244
2029sub add { 2245sub add {
2030 my ($self, $child) = @_; 2246 my ($self, $child) = @_;
2247
2248 # integerize window positions
2249 $child->{x} = int $child->{x};
2250 $child->{y} = int $child->{y};
2031 2251
2032 $self->SUPER::add ($child); 2252 $self->SUPER::add ($child);
2033} 2253}
2034 2254
2035sub on_refresh { 2255sub on_refresh {
2061############################################################################# 2281#############################################################################
2062 2282
2063package CFClient::UI; 2283package CFClient::UI;
2064 2284
2065$ROOT = new CFClient::UI::Root; 2285$ROOT = new CFClient::UI::Root;
2286$TOOLTIP = new CFClient::UI::Tooltip;
2066 2287
20671 22881
2068 2289

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines