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.148 by elmex, Sat Apr 22 12:14:45 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 my ($w, $h) = $self->size_request; 347 $self->{parent}
348 or return 1;
300 349
350 my ($w, $h) = $self->{user_w} && $self->{user_h}
351 ? @$self{qw(user_w user_h)}
352 : $self->size_request;
353
301 if ($w != $self->{req_w} || $h != $self->{req_h}) { 354 if ($w != $self->{req_w} || $h != $self->{req_h}) {
302 $self->{req_w} = $w; 355 $self->{req_w} = $w;
303 $self->{req_h} = $h; 356 $self->{req_h} = $h;
304 357
305 $self->{parent}->check_size 358 $self->{parent}->check_size
306 if $self->{parent}; 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
307 } 367 }
308} 368}
309 369
310sub update { 370sub update {
311 my ($self) = @_; 371 my ($self) = @_;
378 438
379package CFClient::UI::Empty; 439package CFClient::UI::Empty;
380 440
381our @ISA = CFClient::UI::Base::; 441our @ISA = CFClient::UI::Base::;
382 442
443sub new {
444 my ($class, %arg) = @_;
445 $class->SUPER::new (can_events => 0, %arg);
446}
447
383sub size_request { 448sub size_request {
384 (0, 0) 449 (0, 0)
385} 450}
386 451
387sub draw { } 452sub draw { }
395sub new { 460sub new {
396 my ($class, %arg) = @_; 461 my ($class, %arg) = @_;
397 462
398 my $children = delete $arg{children} || []; 463 my $children = delete $arg{children} || [];
399 464
400 my $self = $class->SUPER::new (children => [], %arg); 465 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
401 $self->add ($_) for @$children; 466 $self->add ($_) for @$children;
402 467
403 $self 468 $self
404} 469}
405 470
424 delete $child->{parent}; 489 delete $child->{parent};
425 490
426 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 491 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
427 492
428 $self->check_size; 493 $self->check_size;
494 $self->update;
429} 495}
430 496
431sub find_widget { 497sub find_widget {
432 my ($self, $x, $y) = @_; 498 my ($self, $x, $y) = @_;
433 499
561sub new { die } 627sub new { die }
562 628
563sub size_request { 629sub size_request {
564 my ($self) = @_; 630 my ($self) = @_;
565 631
566 @$self{qw(child_w child_h)} = $self->child->size_request; 632 @$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)}); 633 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
568 634
569 @$self{qw(child_w child_h)} 635 @$self{qw(child_w child_h)}
570} 636}
571 637
593 border => 0.8, 659 border => 0.8,
594 @_ 660 @_
595 ); 661 );
596 662
597 $self 663 $self
598}
599
600sub set_size {
601 my ($self, $w, $h) = @_;
602 $self->{req_w} = $w;
603 $self->{req_h} = $h;
604 $self->check_size;
605}
606
607sub size_request {
608 my ($self) = @_;
609 ($self->{req_w}, $self->{req_h})
610}
611
612sub size_allocate {
613 my ($self, $w, $h) = @_;
614 $self->{w} = $w;
615 $self->{h} = $h;
616 $self->child->configure (0, 0, $w, $h);
617} 664}
618 665
619sub _draw { 666sub _draw {
620 my ($self) = @_; 667 my ($self) = @_;
621 668
659 706
660 my $self = $class->SUPER::new ( 707 my $self = $class->SUPER::new (
661 bg => [1, 1, 1, 1], 708 bg => [1, 1, 1, 1],
662 border_bg => [1, 1, 1, 1], 709 border_bg => [1, 1, 1, 1],
663 border => 0.8, 710 border => 0.8,
711 can_events => 1,
664 @_ 712 @_
665 ); 713 );
666 714
667 $self->{title} &&= new CFClient::UI::Label 715 $self->{title} &&= new CFClient::UI::Label
668 align => 0, 716 align => 0,
678} 726}
679 727
680sub size_request { 728sub size_request {
681 my ($self) = @_; 729 my ($self) = @_;
682 730
683 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
684
685 my ($w, $h) = $self->SUPER::size_request; 731 my ($w, $h) = $self->SUPER::size_request;
686 732
687 ( 733 (
688 $w + $self->border * 2, 734 $w + $self->border * 2,
689 $h + $self->border * 2, 735 $h + $self->border * 2,
837 or next; 883 or next;
838 884
839 for my $x (0 .. $#$row) { 885 for my $x (0 .. $#$row) {
840 my $widget = $row->[$x] 886 my $widget = $row->[$x]
841 or next; 887 or next;
842 my ($w, $h) = $widget->size_request; 888 my ($w, $h) = @$widget{qw(req_w req_h)};
843 889
844 $w[$x] = max $w[$x], $w; 890 $w[$x] = max $w[$x], $w;
845 $h[$y] = max $h[$y], $h; 891 $h[$y] = max $h[$y], $h;
846 } 892 }
847 } 893 }
952 998
953 ($h, $w) = ($w, $h); 999 ($h, $w) = ($w, $h);
954 1000
955 my $children = $self->{children}; 1001 my $children = $self->{children};
956 1002
957 my @h = map +($_->size_request)[0], @$children; 1003 my @h = map $_->{req_w}, @$children;
958 1004
959 my $req_h = List::Util::sum @h; 1005 my $req_h = List::Util::sum @h;
960 1006
961 if ($req_h > $h) { 1007 if ($req_h > $h) {
962 # ah well, not enough space 1008 # ah well, not enough space
1010sub size_allocate { 1056sub size_allocate {
1011 my ($self, $w, $h) = @_; 1057 my ($self, $w, $h) = @_;
1012 1058
1013 my $children = $self->{children}; 1059 my $children = $self->{children};
1014 1060
1015 my @h = map +($_->size_request)[1], @$children; 1061 my @h = map $_->{req_h}, @$children;
1016 1062
1017 my $req_h = List::Util::sum @h; 1063 my $req_h = List::Util::sum @h;
1018 1064
1019 if ($req_h > $h) { 1065 if ($req_h > $h) {
1020 # ah well, not enough space 1066 # ah well, not enough space
1055sub new { 1101sub new {
1056 my ($class, %arg) = @_; 1102 my ($class, %arg) = @_;
1057 1103
1058 my $self = $class->SUPER::new ( 1104 my $self = $class->SUPER::new (
1059 fg => [1, 1, 1], 1105 fg => [1, 1, 1],
1106 #font => default_font
1060 fontsize => 1, 1107 fontsize => 1,
1061 text => "", 1108 text => "",
1062 align => -1, 1109 align => -1,
1063 valign => -1, 1110 valign => -1,
1064 padding => 2, 1111 padding => 2,
1065 layout => new CFClient::Layout, 1112 layout => new CFClient::Layout,
1113 can_events => 0,
1066 %arg 1114 %arg
1067 ); 1115 );
1068 1116
1069 if (exists $self->{template}) { 1117 if (exists $self->{template}) {
1070 my $layout = new CFClient::Layout; 1118 my $layout = new CFClient::Layout;
1092 my ($self, $text) = @_; 1140 my ($self, $text) = @_;
1093 1141
1094 $self->{layout}->set_text ($text); 1142 $self->{layout}->set_text ($text);
1095 1143
1096 delete $self->{texture}; 1144 delete $self->{texture};
1145 $self->check_size;
1097 $self->update; 1146 $self->update;
1098} 1147}
1099 1148
1100sub set_markup { 1149sub set_markup {
1101 my ($self, $markup) = @_; 1150 my ($self, $markup) = @_;
1102 1151
1103 $self->{layout}->set_markup ($markup); 1152 $self->{layout}->set_markup ($markup);
1104 1153
1105 delete $self->{texture}; 1154 delete $self->{texture};
1155 $self->check_size;
1106 $self->update; 1156 $self->update;
1107} 1157}
1108 1158
1109sub size_request { 1159sub size_request {
1110 my ($self) = @_; 1160 my ($self) = @_;
1111 1161
1112 $self->{layout}->set_width; 1162 $self->{layout}->set_font ($self->{font}) if $self->{font};
1163 $self->{layout}->set_width ($self->{max_w} || -1);
1113 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1164 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1114 1165
1115 my ($w, $h) = $self->{layout}->size; 1166 my ($w, $h) = $self->{layout}->size;
1116 1167
1117 if (exists $self->{template}) { 1168 if (exists $self->{template}) {
1169 $self->{template}->set_font ($self->{font}) if $self->{font};
1118 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1170 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1119 1171
1120 my ($w2, $h2) = $self->{template}->size; 1172 my ($w2, $h2) = $self->{template}->size;
1121 1173
1122 $w = List::Util::max $w, $w2; 1174 $w = List::Util::max $w, $w2;
1137 1189
1138sub set_fontsize { 1190sub set_fontsize {
1139 my ($self, $fontsize) = @_; 1191 my ($self, $fontsize) = @_;
1140 1192
1141 $self->{fontsize} = $fontsize; 1193 $self->{fontsize} = $fontsize;
1194 delete $self->{texture};
1142 $self->check_size; 1195 $self->check_size;
1196 $self->update;
1143} 1197}
1144 1198
1145sub _draw { 1199sub _draw {
1146 my ($self) = @_; 1200 my ($self) = @_;
1147 1201
1148 my $tex = $self->{texture} ||= do { 1202 my $tex = $self->{texture} ||= do {
1203 $self->{layout}->set_font ($self->{font}) if $self->{font};
1149 $self->{layout}->set_width ($self->{w}); 1204 $self->{layout}->set_width ($self->{w});
1150 $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);
1151 new_from_layout CFClient::Texture $self->{layout} 1206 new_from_layout CFClient::Texture $self->{layout}
1152 }; 1207 };
1153 1208
1193 active_bg => [1, 1, 1, 0.5], 1248 active_bg => [1, 1, 1, 0.5],
1194 active_fg => [0, 0, 0], 1249 active_fg => [0, 0, 0],
1195 can_hover => 1, 1250 can_hover => 1,
1196 can_focus => 1, 1251 can_focus => 1,
1197 valign => 0, 1252 valign => 0,
1253 can_events => 1,
1198 @_ 1254 @_
1199 ) 1255 )
1200} 1256}
1201 1257
1202sub _set_text { 1258sub _set_text {
1230} 1286}
1231 1287
1232sub size_allocate { 1288sub size_allocate {
1233 my ($self, $w, $h) = @_; 1289 my ($self, $w, $h) = @_;
1234 1290
1235 $self->_set_text ($self->{text}); 1291 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1236} 1292}
1237 1293
1238sub set_text { 1294sub set_text {
1239 my ($self, $text) = @_; 1295 my ($self, $text) = @_;
1240 1296
1387 bg => [1, 1, 1, 0.2], 1443 bg => [1, 1, 1, 0.2],
1388 active_fg => [0, 0, 1], 1444 active_fg => [0, 0, 1],
1389 can_hover => 1, 1445 can_hover => 1,
1390 align => 0, 1446 align => 0,
1391 valign => 0, 1447 valign => 0,
1448 can_events => 1,
1392 @_ 1449 @_
1393 ) 1450 )
1394} 1451}
1395 1452
1396sub button_up { 1453sub button_up {
1501our %loaded_images; 1558our %loaded_images;
1502 1559
1503sub new { 1560sub new {
1504 my $class = shift; 1561 my $class = shift;
1505 1562
1506 my $self = $class->SUPER::new (@_); 1563 my $self = $class->SUPER::new (can_events => 0, @_);
1507 1564
1508 $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!";
1509 1566
1510 $loaded_images{$self->{image}} ||= 1567 $loaded_images{$self->{image}} ||=
1511 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;
1553############################################################################# 1610#############################################################################
1554 1611
1555package CFClient::UI::VGauge; 1612package CFClient::UI::VGauge;
1556 1613
1557our @ISA = CFClient::UI::Base::; 1614our @ISA = CFClient::UI::Base::;
1615
1616use List::Util qw(min max);
1558 1617
1559use CFClient::OpenGL; 1618use CFClient::OpenGL;
1560 1619
1561my %tex = ( 1620my %tex = (
1562 food => [ 1621 food => [
1563 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1622 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1564 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1623 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1565 ], 1624 ],
1566 grace => [ 1625 grace => [
1567 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1626 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1568 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/
1569 ], 1628 ],
1570 hp => [ 1629 hp => [
1571 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1630 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1572 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1631 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1573 ], 1632 ],
1574 mana => [ 1633 mana => [
1575 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1634 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1576 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/
1577 ], 1636 ],
1578); 1637);
1579 1638
1580# eg. VGauge->new (gauge => 'food'), default gauge: food 1639# eg. VGauge->new (gauge => 'food'), default gauge: food
1581sub new { 1640sub new {
1619 1678
1620sub _draw { 1679sub _draw {
1621 my ($self) = @_; 1680 my ($self) = @_;
1622 1681
1623 my $tex = $tex{$self->{type}}; 1682 my $tex = $tex{$self->{type}};
1683 my ($t1, $t2, $t3) = @$tex;
1624 1684
1625 my ($w, $h) = ($self->{w}, $self->{h}); 1685 my ($w, $h) = ($self->{w}, $self->{h});
1626 1686
1627 if ($self->{vertical}) { 1687 if ($self->{vertical}) {
1628 glRotate 90, 0, 0, 1; 1688 glRotate 90, 0, 0, 1;
1630 1690
1631 ($w, $h) = ($h, $w); 1691 ($w, $h) = ($h, $w);
1632 } 1692 }
1633 1693
1634 my $ycut = $self->{val} / ($self->{max_val} || 1); 1694 my $ycut = $self->{val} / ($self->{max_val} || 1);
1635 $ycut = 1 if $self->{val} > $self->{max_val};
1636 1695
1637 my $t1 = $tex->[0]; 1696 my $ycut1 = max 0, min 1, $ycut;
1638 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);
1639 1701
1640 glEnable GL_BLEND; 1702 glEnable GL_BLEND;
1641 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1703 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1642 glEnable GL_TEXTURE_2D; 1704 glEnable GL_TEXTURE_2D;
1643 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1705 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1644 1706
1645 my $h1 = $self->{h} - $ycut * $self->{h};
1646 my $h2 = $ycut * $self->{h};
1647
1648 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1707 glBindTexture GL_TEXTURE_2D, $t1->{name};
1649 glBegin GL_QUADS; 1708 glBegin GL_QUADS;
1650 glTexCoord 0 , 0; glVertex 0 , 0; 1709 glTexCoord 0 , 0; glVertex 0 , 0;
1651 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1710 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1652 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1711 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1653 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1712 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1654 glEnd; 1713 glEnd;
1655 1714
1715 my $ycut1 = List::Util::min 1, $ycut;
1656 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1716 glBindTexture GL_TEXTURE_2D, $t2->{name};
1657 glBegin GL_QUADS; 1717 glBegin GL_QUADS;
1658 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1718 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1659 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1719 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1660 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1720 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1661 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1721 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1662 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 }
1663 1733
1664 glDisable GL_BLEND; 1734 glDisable GL_BLEND;
1665 glDisable GL_TEXTURE_2D; 1735 glDisable GL_TEXTURE_2D;
1666} 1736}
1667 1737
1670package CFClient::UI::Gauge; 1740package CFClient::UI::Gauge;
1671 1741
1672our @ISA = CFClient::UI::VBox::; 1742our @ISA = CFClient::UI::VBox::;
1673 1743
1674sub new { 1744sub new {
1675 my ($class, %arg) = shift; 1745 my ($class, %arg) = @_;
1676 1746
1677 my $self = $class->SUPER::new ( 1747 my $self = $class->SUPER::new (
1678 @_, 1748 tooltip => $arg{type},
1749 %arg,
1679 ); 1750 );
1680 1751
1681 $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);
1682 $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);
1683 $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);
1684 1755
1685 $self 1756 $self
1686} 1757}
1687 1758
1688sub set_fontsize { 1759sub set_fontsize {
1855sub new { 1926sub new {
1856 my $class = shift; 1927 my $class = shift;
1857 1928
1858 my $self = $class->SUPER::new ( 1929 my $self = $class->SUPER::new (
1859 fontsize => 1, 1930 fontsize => 1,
1931 #font => default_font
1860 @_, 1932 @_,
1861 1933
1862 layout => (new CFClient::Layout), 1934 layout => (new CFClient::Layout),
1863 par => [], 1935 par => [],
1864 height => 0, 1936 height => 0,
1904sub size_allocate { 1976sub size_allocate {
1905 my ($self, $w, $h) = @_; 1977 my ($self, $w, $h) = @_;
1906 1978
1907 $self->SUPER::size_allocate ($w, $h); 1979 $self->SUPER::size_allocate ($w, $h);
1908 1980
1981 $self->{layout}->set_font ($self->{font}) if $self->{font};
1909 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1982 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1910 $self->{layout}->set_width ($self->{children}[0]{w}); 1983 $self->{layout}->set_width ($self->{children}[0]{w});
1911 1984
1912 $self->reflow; 1985 $self->reflow;
1913} 1986}
1965 my $y1 = $top + $self->{h}; 2038 my $y1 = $top + $self->{h};
1966 2039
1967 my $y = 0; 2040 my $y = 0;
1968 2041
1969 my $layout = $self->{layout}; 2042 my $layout = $self->{layout};
2043
2044 $layout->set_font ($self->{font}) if $self->{font};
1970 2045
1971 for my $par (@{$self->{par}}) { 2046 for my $par (@{$self->{par}}) {
1972 my $h = $par->[0]; 2047 my $h = $par->[0];
1973 2048
1974 if ($y0 < $y + $h && $y < $y1) { 2049 if ($y0 < $y + $h && $y < $y1) {
2054 my $class = shift; 2129 my $class = shift;
2055 2130
2056 my $self = $class->SUPER::new ( 2131 my $self = $class->SUPER::new (
2057 state => 0, 2132 state => 0,
2058 connect_activate => \&toggle_flopper, 2133 connect_activate => \&toggle_flopper,
2134 can_events => 1,
2059 @_ 2135 @_
2060 ); 2136 );
2061 2137
2062 if ($self->{state}) { 2138 if ($self->{state}) {
2063 $self->{state} = 0; 2139 $self->{state} = 0;
2083 $self->emit (changed => $self->{state}); 2159 $self->emit (changed => $self->{state});
2084} 2160}
2085 2161
2086############################################################################# 2162#############################################################################
2087 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
2088package CFClient::UI::Root; 2229package CFClient::UI::Root;
2089 2230
2090our @ISA = CFClient::UI::Container::; 2231our @ISA = CFClient::UI::Container::;
2091 2232
2092use CFClient::OpenGL; 2233use CFClient::OpenGL;
2093 2234
2094sub check_size { 2235sub check_size {
2095 my ($self) = @_; 2236 my ($self) = @_;
2096 2237
2097 $self->configure (0, 0, $::WITH, $::HEIGHT); 2238 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
2098} 2239}
2099 2240
2100sub size_request { 2241sub size_request {
2101 ($::WIDTH, $::HEIGHT) 2242 ($::WIDTH, $::HEIGHT)
2102} 2243}
2104sub configure { 2245sub configure {
2105 my ($self, $x, $y, $w, $h) = @_; 2246 my ($self, $x, $y, $w, $h) = @_;
2106 2247
2107 $self->SUPER::configure ($x, $y, $w, $h); 2248 $self->SUPER::configure ($x, $y, $w, $h);
2108 2249
2109 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2110 for @{$self->{children}}; 2250 for my $child (@{$self->{children}}) {
2251 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2252
2253 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2254 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2255 $child->configure ($X, $Y, $W,$H);
2256 }
2111} 2257}
2112 2258
2113sub _topleft { 2259sub _topleft {
2114 my ($self, $x, $y) = @_; 2260 my ($self, $x, $y) = @_;
2115 2261
2162############################################################################# 2308#############################################################################
2163 2309
2164package CFClient::UI; 2310package CFClient::UI;
2165 2311
2166$ROOT = new CFClient::UI::Root; 2312$ROOT = new CFClient::UI::Root;
2313$TOOLTIP = new CFClient::UI::Tooltip;
2167 2314
21681 23151
2169 2316

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines