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.156 by elmex, Sun Apr 23 02:50: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_(.*)$/) {
140 0 174 0
141} 175}
142 176
143sub size_request { 177sub size_request {
144 require Carp; 178 require Carp;
145 Carp::confess "size_request is abtract"; 179 Carp::confess "size_request is abstract";
146} 180}
147 181
148sub configure { 182sub configure {
149 my ($self, $x, $y, $w, $h) = @_; 183 my ($self, $x, $y, $w, $h) = @_;
150 184
152 my $w2 = List::Util::min $w, int $h * $self->{aspect}; 186 my $w2 = List::Util::min $w, int $h * $self->{aspect};
153 my $h2 = List::Util::min $h, int $w / $self->{aspect}; 187 my $h2 = List::Util::min $h, int $w / $self->{aspect};
154 188
155 # use alignment to adjust x, y 189 # use alignment to adjust x, y
156 190
157 $x += ($w - $w2) * 0.5; 191 $x += int +($w - $w2) * 0.5;
158 $y += ($h - $h2) * 0.5; 192 $y += int +($h - $h2) * 0.5;
159 193
160 ($w, $h) = ($w2, $h2); 194 ($w, $h) = ($w2, $h2);
161 } 195 }
162 196
163 if ($self->{x} != $x || $self->{y} != $y) { 197 if ($self->{x} != $x || $self->{y} != $y) {
278} 312}
279 313
280sub find_widget { 314sub find_widget {
281 my ($self, $x, $y) = @_; 315 my ($self, $x, $y) = @_;
282 316
317 return () unless $self->{can_events};
318
283 return $self 319 return $self
284 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 320 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
285 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 321 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
286 322
287 () 323 ()
294} 330}
295 331
296sub check_size { 332sub check_size {
297 my ($self) = @_; 333 my ($self) = @_;
298 334
335 return unless $self->{parent};
336
299 my ($w, $h) = $self->size_request; 337 my ($w, $h) = $self->size_request;
300 338
301 if ($w != $self->{req_w} || $h != $self->{req_h}) { 339 if ($w != $self->{req_w} || $h != $self->{req_h}) {
302 $self->{req_w} = $w; 340 $self->{req_w} = $w;
303 $self->{req_h} = $h; 341 $self->{req_h} = $h;
304 342
305 $self->{parent}->check_size 343 $self->{parent}->check_size;
306 if $self->{parent};
307 } 344 }
308} 345}
309 346
310sub update { 347sub update {
311 my ($self) = @_; 348 my ($self) = @_;
378 415
379package CFClient::UI::Empty; 416package CFClient::UI::Empty;
380 417
381our @ISA = CFClient::UI::Base::; 418our @ISA = CFClient::UI::Base::;
382 419
420sub new {
421 my ($class, %arg) = @_;
422 $class->SUPER::new (can_events => 0, %arg);
423}
424
383sub size_request { 425sub size_request {
384 (0, 0) 426 (0, 0)
385} 427}
386 428
387sub draw { } 429sub draw { }
395sub new { 437sub new {
396 my ($class, %arg) = @_; 438 my ($class, %arg) = @_;
397 439
398 my $children = delete $arg{children} || []; 440 my $children = delete $arg{children} || [];
399 441
400 my $self = $class->SUPER::new (children => [], %arg); 442 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
401 $self->add ($_) for @$children; 443 $self->add ($_) for @$children;
402 444
403 $self 445 $self
404} 446}
405 447
424 delete $child->{parent}; 466 delete $child->{parent};
425 467
426 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 468 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
427 469
428 $self->check_size; 470 $self->check_size;
471 $self->update;
429} 472}
430 473
431sub find_widget { 474sub find_widget {
432 my ($self, $x, $y) = @_; 475 my ($self, $x, $y) = @_;
433 476
561sub new { die } 604sub new { die }
562 605
563sub size_request { 606sub size_request {
564 my ($self) = @_; 607 my ($self) = @_;
565 608
566 @$self{qw(child_w child_h)} = $self->child->size_request; 609 @$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)}); 610 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
568 611
569 @$self{qw(child_w child_h)} 612 @$self{qw(child_w child_h)}
570} 613}
571 614
581package CFClient::UI::Frame; 624package CFClient::UI::Frame;
582 625
583our @ISA = CFClient::UI::Bin::; 626our @ISA = CFClient::UI::Bin::;
584 627
585use CFClient::OpenGL; 628use 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 629
633sub new { 630sub new {
634 my $class = shift; 631 my $class = shift;
635
636 # TODO: user_x, user_y, overwrite moveto?
637 632
638 my $self = $class->SUPER::new ( 633 my $self = $class->SUPER::new (
639 bg => [1, 1, 1, 1], 634 bg => [1, 1, 1, 1],
640 border_bg => [1, 1, 1, 1], 635 border_bg => [1, 1, 1, 1],
641 border => 0.8, 636 border => 0.8,
642 @_ 637 @_
643 ); 638 );
644 639
640 $self
641}
642
643sub set_size {
644 my ($self, $w, $h) = @_;
645 $self->{req_w} = $w;
646 $self->{req_h} = $h;
647 $self->check_size;
648}
649
650sub size_request {
651 my ($self) = @_;
652 ($self->{req_w}, $self->{req_h})
653}
654
655sub size_allocate {
656 my ($self, $w, $h) = @_;
657 $self->{w} = $w;
658 $self->{h} = $h;
659 $self->child->configure (0, 0, $w, $h);
660}
661
662sub _draw {
663 my ($self) = @_;
664
665 my ($w, $h) = ($self->{w}, $self->{h});
666
667 glEnable GL_BLEND;
668 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
669 glEnable GL_TEXTURE_2D;
670 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
671
672# glBegin GL_QUADS;
673# glColor 0, 0, 0, 0;
674# glVertex 0 , 0;
675# glVertex 0 , $h;
676# glVertex $w, $h;
677# glVertex $w, 0;
678# glEnd;
679
680
681 $self->child->draw;
682 glDisable GL_BLEND;
683 glDisable GL_TEXTURE_2D;
684}
685
686#############################################################################
687
688package CFClient::UI::FancyFrame;
689
690our @ISA = CFClient::UI::Bin::;
691
692use CFClient::OpenGL;
693
694my @tex =
695 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
696 qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
697
698sub new {
699 my $class = shift;
700
701 # TODO: user_x, user_y, overwrite moveto?
702
703 my $self = $class->SUPER::new (
704 bg => [1, 1, 1, 1],
705 border_bg => [1, 1, 1, 1],
706 border => 0.8,
707 can_events => 1,
708 @_
709 );
710
645 $self->{title} &&= new CFClient::UI::Label 711 $self->{title} &&= new CFClient::UI::Label
646 align => 0, 712 align => 0,
647 valign => 1, 713 valign => 1,
648 text => $self->{title}, 714 text => $self->{title},
649 fontsize => 1; 715 fontsize => 1;
815 or next; 881 or next;
816 882
817 for my $x (0 .. $#$row) { 883 for my $x (0 .. $#$row) {
818 my $widget = $row->[$x] 884 my $widget = $row->[$x]
819 or next; 885 or next;
820 my ($w, $h) = $widget->size_request; 886 my ($w, $h) = @$widget{qw(req_w req_h)};
821 887
822 $w[$x] = max $w[$x], $w; 888 $w[$x] = max $w[$x], $w;
823 $h[$y] = max $h[$y], $h; 889 $h[$y] = max $h[$y], $h;
824 } 890 }
825 } 891 }
930 996
931 ($h, $w) = ($w, $h); 997 ($h, $w) = ($w, $h);
932 998
933 my $children = $self->{children}; 999 my $children = $self->{children};
934 1000
935 my @h = map +($_->size_request)[0], @$children; 1001 my @h = map $_->{req_w}, @$children;
936 1002
937 my $req_h = List::Util::sum @h; 1003 my $req_h = List::Util::sum @h;
938 1004
939 if ($req_h > $h) { 1005 if ($req_h > $h) {
940 # ah well, not enough space 1006 # ah well, not enough space
988sub size_allocate { 1054sub size_allocate {
989 my ($self, $w, $h) = @_; 1055 my ($self, $w, $h) = @_;
990 1056
991 my $children = $self->{children}; 1057 my $children = $self->{children};
992 1058
993 my @h = map +($_->size_request)[1], @$children; 1059 my @h = map $_->{req_h}, @$children;
994 1060
995 my $req_h = List::Util::sum @h; 1061 my $req_h = List::Util::sum @h;
996 1062
997 if ($req_h > $h) { 1063 if ($req_h > $h) {
998 # ah well, not enough space 1064 # ah well, not enough space
1039 text => "", 1105 text => "",
1040 align => -1, 1106 align => -1,
1041 valign => -1, 1107 valign => -1,
1042 padding => 2, 1108 padding => 2,
1043 layout => new CFClient::Layout, 1109 layout => new CFClient::Layout,
1110 can_events => 0,
1044 %arg 1111 %arg
1045 ); 1112 );
1046 1113
1047 if (exists $self->{template}) { 1114 if (exists $self->{template}) {
1048 my $layout = new CFClient::Layout; 1115 my $layout = new CFClient::Layout;
1070 my ($self, $text) = @_; 1137 my ($self, $text) = @_;
1071 1138
1072 $self->{layout}->set_text ($text); 1139 $self->{layout}->set_text ($text);
1073 1140
1074 delete $self->{texture}; 1141 delete $self->{texture};
1142 $self->check_size;
1075 $self->update; 1143 $self->update;
1076} 1144}
1077 1145
1078sub set_markup { 1146sub set_markup {
1079 my ($self, $markup) = @_; 1147 my ($self, $markup) = @_;
1080 1148
1081 $self->{layout}->set_markup ($markup); 1149 $self->{layout}->set_markup ($markup);
1082 1150
1083 delete $self->{texture}; 1151 delete $self->{texture};
1152 $self->check_size;
1084 $self->update; 1153 $self->update;
1085} 1154}
1086 1155
1087sub size_request { 1156sub size_request {
1088 my ($self) = @_; 1157 my ($self) = @_;
1109 1178
1110sub size_allocate { 1179sub size_allocate {
1111 my ($self, $w, $h) = @_; 1180 my ($self, $w, $h) = @_;
1112 1181
1113 delete $self->{texture}; 1182 delete $self->{texture};
1183}
1184
1185sub set_fontsize {
1186 my ($self, $fontsize) = @_;
1187
1188 $self->{fontsize} = $fontsize;
1189 delete $self->{texture};
1190 $self->check_size;
1191 $self->update;
1114} 1192}
1115 1193
1116sub _draw { 1194sub _draw {
1117 my ($self) = @_; 1195 my ($self) = @_;
1118 1196
1164 active_bg => [1, 1, 1, 0.5], 1242 active_bg => [1, 1, 1, 0.5],
1165 active_fg => [0, 0, 0], 1243 active_fg => [0, 0, 0],
1166 can_hover => 1, 1244 can_hover => 1,
1167 can_focus => 1, 1245 can_focus => 1,
1168 valign => 0, 1246 valign => 0,
1247 can_events => 1,
1169 @_ 1248 @_
1170 ) 1249 )
1171} 1250}
1172 1251
1173sub _set_text { 1252sub _set_text {
1201} 1280}
1202 1281
1203sub size_allocate { 1282sub size_allocate {
1204 my ($self, $w, $h) = @_; 1283 my ($self, $w, $h) = @_;
1205 1284
1206 $self->_set_text ($self->{text}); 1285 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1207} 1286}
1208 1287
1209sub set_text { 1288sub set_text {
1210 my ($self, $text) = @_; 1289 my ($self, $text) = @_;
1211 1290
1344our @ISA = CFClient::UI::Label::; 1423our @ISA = CFClient::UI::Label::;
1345 1424
1346use CFClient::OpenGL; 1425use CFClient::OpenGL;
1347 1426
1348my @tex = 1427my @tex =
1349 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1428 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1350 qw(b1_button_active.png); 1429 qw(b1_button_active.png);
1351 1430
1352sub new { 1431sub new {
1353 my $class = shift; 1432 my $class = shift;
1354 1433
1358 bg => [1, 1, 1, 0.2], 1437 bg => [1, 1, 1, 0.2],
1359 active_fg => [0, 0, 1], 1438 active_fg => [0, 0, 1],
1360 can_hover => 1, 1439 can_hover => 1,
1361 align => 0, 1440 align => 0,
1362 valign => 0, 1441 valign => 0,
1442 can_events => 1,
1363 @_ 1443 @_
1364 ) 1444 )
1365} 1445}
1366 1446
1367sub button_up { 1447sub button_up {
1401package CFClient::UI::CheckBox; 1481package CFClient::UI::CheckBox;
1402 1482
1403our @ISA = CFClient::UI::DrawBG::; 1483our @ISA = CFClient::UI::DrawBG::;
1404 1484
1405my @tex = 1485my @tex =
1406 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1486 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1407 qw(c1_checkbox_bg.png c1_checkbox_active.png); 1487 qw(c1_checkbox_bg.png c1_checkbox_active.png);
1408 1488
1409use CFClient::OpenGL; 1489use CFClient::OpenGL;
1410 1490
1411sub new { 1491sub new {
1460 glDisable GL_BLEND; 1540 glDisable GL_BLEND;
1461} 1541}
1462 1542
1463############################################################################# 1543#############################################################################
1464 1544
1545package CFClient::UI::Image;
1546
1547our @ISA = CFClient::UI::Base::;
1548
1549use CFClient::OpenGL;
1550use Carp qw/confess/;
1551
1552our %loaded_images;
1553
1554sub new {
1555 my $class = shift;
1556
1557 my $self = $class->SUPER::new (can_events => 0, @_);
1558
1559 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1560
1561 $loaded_images{$self->{image}} ||=
1562 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1563
1564 my $tex = $self->{tex} = $loaded_images{$self->{image}};
1565
1566 Scalar::Util::weaken $loaded_images{$self->{image}};
1567
1568 $self->{aspect} = $tex->{w} / $tex->{h};
1569
1570 $self
1571}
1572
1573sub size_request {
1574 my ($self) = @_;
1575
1576 ($self->{tex}->{w}, $self->{tex}->{h})
1577}
1578
1579sub _draw {
1580 my ($self) = @_;
1581
1582 my $tex = $self->{tex};
1583
1584 my ($w, $h) = ($self->{w}, $self->{h});
1585
1586 if ($self->{rot90}) {
1587 glRotate 90, 0, 0, 1;
1588 glTranslate 0, -$self->{w}, 0;
1589
1590 ($w, $h) = ($h, $w);
1591 }
1592
1593 glEnable GL_BLEND;
1594 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1595 glEnable GL_TEXTURE_2D;
1596 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1597
1598 $tex->draw_quad (0, 0, $w, $h);
1599
1600 glDisable GL_BLEND;
1601 glDisable GL_TEXTURE_2D;
1602}
1603
1604#############################################################################
1605
1465package CFClient::UI::VGauge; 1606package CFClient::UI::VGauge;
1466 1607
1467our @ISA = CFClient::UI::Base::; 1608our @ISA = CFClient::UI::Base::;
1468 1609
1469use CFClient::OpenGL; 1610use CFClient::OpenGL;
1470 1611
1471my %tex = ( 1612my %tex = (
1472 food => [ 1613 food => [
1473 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1614 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1474 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1615 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1475 ], 1616 ],
1476 grace => [ 1617 grace => [
1477 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1618 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1478 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1619 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/
1479 ], 1620 ],
1480 hp => [ 1621 hp => [
1481 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1622 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1482 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1623 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1483 ], 1624 ],
1484 mana => [ 1625 mana => [
1485 map { new_from_file CFClient::Texture CFClient::find_rcfile $_ } 1626 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1486 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1627 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/
1487 ], 1628 ],
1488); 1629);
1489 1630
1490# eg. VGauge->new (gauge => 'food'), default gauge: food 1631# eg. VGauge->new (gauge => 'food'), default gauge: food
1580package CFClient::UI::Gauge; 1721package CFClient::UI::Gauge;
1581 1722
1582our @ISA = CFClient::UI::VBox::; 1723our @ISA = CFClient::UI::VBox::;
1583 1724
1584sub new { 1725sub new {
1585 my ($class, %arg) = shift; 1726 my ($class, %arg) = @_;
1586 1727
1587 my $self = $class->SUPER::new ( 1728 my $self = $class->SUPER::new (
1588 @_, 1729 tooltip => $arg{type},
1730 %arg,
1589 ); 1731 );
1590 1732
1591 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1733 $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1);
1592 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); 1734 $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1);
1593 $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1735 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1);
1594 1736
1595 $self 1737 $self
1738}
1739
1740sub set_fontsize {
1741 my ($self, $fsize) = @_;
1742
1743 $self->{value}->set_fontsize ($fsize);
1744 $self->{max} ->set_fontsize ($fsize);
1596} 1745}
1597 1746
1598sub set_value { 1747sub set_value {
1599 my ($self, $val, $max) = @_; 1748 my ($self, $val, $max) = @_;
1600 1749
1957 my $class = shift; 2106 my $class = shift;
1958 2107
1959 my $self = $class->SUPER::new ( 2108 my $self = $class->SUPER::new (
1960 state => 0, 2109 state => 0,
1961 connect_activate => \&toggle_flopper, 2110 connect_activate => \&toggle_flopper,
2111 can_events => 1,
1962 @_ 2112 @_
1963 ); 2113 );
1964 2114
1965 if ($self->{state}) { 2115 if ($self->{state}) {
1966 $self->{state} = 0; 2116 $self->{state} = 0;
1986 $self->emit (changed => $self->{state}); 2136 $self->emit (changed => $self->{state});
1987} 2137}
1988 2138
1989############################################################################# 2139#############################################################################
1990 2140
2141package CFClient::UI::Tooltip;
2142
2143our @ISA = CFClient::UI::Bin::;
2144
2145use CFClient::OpenGL;
2146
2147sub new {
2148 my $class = shift;
2149
2150 $class->SUPER::new (
2151 @_,
2152 can_events => 0,
2153 )
2154}
2155
2156sub set_text {
2157 my ($self, $text) = @_;
2158
2159 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2160 $self->{label}->set_text ($text);
2161 $self->add ($self->{label});
2162}
2163
2164sub size_request {
2165 my ($self) = @_;
2166
2167 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2168
2169 $w = List::Util::min $::WIDTH * 0.2, $w;
2170 $h = List::Util::max $::HEIGHT * 0.2, $h;
2171
2172 ($w + 4, $h + 4)
2173}
2174
2175sub _draw {
2176 my ($self) = @_;
2177
2178 glPushMatrix;
2179 glTranslate 0.375, 0.375;
2180
2181 my ($w, $h) = @$self{qw(w h)};
2182
2183 glColor 1, 0.8, 0.4;
2184 glBegin GL_QUADS;
2185 glVertex 0 , 0;
2186 glVertex 0 , $h;
2187 glVertex $w, $h;
2188 glVertex $w, 0;
2189 glEnd;
2190
2191 glColor 0, 0, 0;
2192 glBegin GL_LINE_LOOP;
2193 glVertex 0 , 0;
2194 glVertex 0 , $h;
2195 glVertex $w, $h;
2196 glVertex $w, 0;
2197 glEnd;
2198
2199 glPopMatrix;
2200
2201 glTranslate 2, 2;
2202 $self->SUPER::_draw;
2203}
2204
2205#############################################################################
2206
1991package CFClient::UI::Root; 2207package CFClient::UI::Root;
1992 2208
1993our @ISA = CFClient::UI::Container::; 2209our @ISA = CFClient::UI::Container::;
1994 2210
1995use CFClient::OpenGL; 2211use CFClient::OpenGL;
1996 2212
1997sub check_size { 2213sub check_size {
1998 my ($self) = @_; 2214 my ($self) = @_;
1999 2215
2000 $self->configure (0, 0, $::WITH, $::HEIGHT); 2216 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
2001} 2217}
2002 2218
2003sub size_request { 2219sub size_request {
2004 ($::WIDTH, $::HEIGHT) 2220 ($::WIDTH, $::HEIGHT)
2005} 2221}
2007sub configure { 2223sub configure {
2008 my ($self, $x, $y, $w, $h) = @_; 2224 my ($self, $x, $y, $w, $h) = @_;
2009 2225
2010 $self->SUPER::configure ($x, $y, $w, $h); 2226 $self->SUPER::configure ($x, $y, $w, $h);
2011 2227
2012 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2013 for @{$self->{children}}; 2228 for my $child (@{$self->{children}}) {
2229 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2230
2231 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2232 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2233 $child->configure ($X, $Y, $W,$H);
2234 }
2014} 2235}
2015 2236
2016sub _topleft { 2237sub _topleft {
2017 my ($self, $x, $y) = @_; 2238 my ($self, $x, $y) = @_;
2018 2239
2026 ::refresh (); 2247 ::refresh ();
2027} 2248}
2028 2249
2029sub add { 2250sub add {
2030 my ($self, $child) = @_; 2251 my ($self, $child) = @_;
2252
2253 # integerize window positions
2254 $child->{x} = int $child->{x};
2255 $child->{y} = int $child->{y};
2031 2256
2032 $self->SUPER::add ($child); 2257 $self->SUPER::add ($child);
2033} 2258}
2034 2259
2035sub on_refresh { 2260sub on_refresh {
2061############################################################################# 2286#############################################################################
2062 2287
2063package CFClient::UI; 2288package CFClient::UI;
2064 2289
2065$ROOT = new CFClient::UI::Root; 2290$ROOT = new CFClient::UI::Root;
2291$TOOLTIP = new CFClient::UI::Tooltip;
2066 2292
20671 22931
2068 2294

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines