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.160 by root, Mon Apr 24 03:33:51 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 (length $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_(.*)$/) {
108 } 142 }
109 143
110 $self 144 $self
111} 145}
112 146
147sub destroy {
148 my ($self) = @_;
149
150 $self->hide;
151 %$self = ();
152}
153
113sub show { 154sub show {
114 my ($self) = @_; 155 my ($self) = @_;
115 156
116 return if $self->{parent}; 157 return if $self->{parent};
117 158
134 $self->{z} = $z if defined $z; 175 $self->{z} = $z if defined $z;
135 176
136 $self->update; 177 $self->update;
137} 178}
138 179
139sub needs_redraw { 180sub set_size {
140 0 181 my ($self, $w, $h) = @_;
182
183 $self->{user_w} = $w;
184 $self->{user_h} = $h;
185
186 $self->check_size;
141} 187}
142 188
143sub size_request { 189sub size_request {
144 require Carp; 190 require Carp;
145 Carp::confess "size_request is abstract"; 191 Carp::confess "size_request is abstract";
175 } 221 }
176} 222}
177 223
178sub size_allocate { 224sub size_allocate {
179 # nothing to be done 225 # nothing to be done
226}
227
228sub set_max_size {
229 my ($self, $w, $h) = @_;
230
231 delete $self->{max_w}; $self->{max_w} = $w if $w;
232 delete $self->{max_h}; $self->{max_h} = $h if $h;
180} 233}
181 234
182# return top left coordinates 235# return top left coordinates
183sub _topleft { 236sub _topleft {
184 my ($self, $x, $y) = @_; 237 my ($self, $x, $y) = @_;
278} 331}
279 332
280sub find_widget { 333sub find_widget {
281 my ($self, $x, $y) = @_; 334 my ($self, $x, $y) = @_;
282 335
336 return () unless $self->{can_events};
337
283 return $self 338 return $self
284 if $x >= $self->{x} && $x < $self->{x} + $self->{w} 339 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
285 && $y >= $self->{y} && $y < $self->{y} + $self->{h}; 340 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
286 341
287 () 342 ()
294} 349}
295 350
296sub check_size { 351sub check_size {
297 my ($self) = @_; 352 my ($self) = @_;
298 353
299 my ($w, $h) = $self->size_request; 354 $self->{parent}
355 or return 1;
300 356
357 my ($w, $h) = $self->{user_w} && $self->{user_h}
358 ? @$self{qw(user_w user_h)}
359 : $self->size_request;
360
301 if ($w != $self->{req_w} || $h != $self->{req_h}) { 361 if ($w != $self->{req_w} || $h != $self->{req_h}) {
302 $self->{req_w} = $w; 362 $self->{req_w} = $w;
303 $self->{req_h} = $h; 363 $self->{req_h} = $h;
304 364
305 $self->{parent}->check_size 365 $self->{parent}->check_size
306 if $self->{parent}; 366 or $self->size_allocate (
367 (List::Util::max $self->{w}, $w),
368 (List::Util::max $self->{h}, $h),
369 );
370
371 1
372 } else {
373 0
307 } 374 }
308} 375}
309 376
310sub update { 377sub update {
311 my ($self) = @_; 378 my ($self) = @_;
378 445
379package CFClient::UI::Empty; 446package CFClient::UI::Empty;
380 447
381our @ISA = CFClient::UI::Base::; 448our @ISA = CFClient::UI::Base::;
382 449
450sub new {
451 my ($class, %arg) = @_;
452 $class->SUPER::new (can_events => 0, %arg);
453}
454
383sub size_request { 455sub size_request {
384 (0, 0) 456 (0, 0)
385} 457}
386 458
387sub draw { } 459sub draw { }
395sub new { 467sub new {
396 my ($class, %arg) = @_; 468 my ($class, %arg) = @_;
397 469
398 my $children = delete $arg{children} || []; 470 my $children = delete $arg{children} || [];
399 471
400 my $self = $class->SUPER::new (children => [], %arg); 472 my $self = $class->SUPER::new (children => [], can_events => 0, %arg);
401 $self->add ($_) for @$children; 473 $self->add ($_) for @$children;
402 474
403 $self 475 $self
404} 476}
405 477
424 delete $child->{parent}; 496 delete $child->{parent};
425 497
426 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 498 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
427 499
428 $self->check_size; 500 $self->check_size;
501 $self->update;
429} 502}
430 503
431sub find_widget { 504sub find_widget {
432 my ($self, $x, $y) = @_; 505 my ($self, $x, $y) = @_;
433 506
561sub new { die } 634sub new { die }
562 635
563sub size_request { 636sub size_request {
564 my ($self) = @_; 637 my ($self) = @_;
565 638
566 @$self{qw(child_w child_h)} = $self->child->size_request; 639 @$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)}); 640 $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)});
568 641
569 @$self{qw(child_w child_h)} 642 @$self{qw(child_w child_h)}
570} 643}
571 644
593 border => 0.8, 666 border => 0.8,
594 @_ 667 @_
595 ); 668 );
596 669
597 $self 670 $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} 671}
618 672
619sub _draw { 673sub _draw {
620 my ($self) = @_; 674 my ($self) = @_;
621 675
659 713
660 my $self = $class->SUPER::new ( 714 my $self = $class->SUPER::new (
661 bg => [1, 1, 1, 1], 715 bg => [1, 1, 1, 1],
662 border_bg => [1, 1, 1, 1], 716 border_bg => [1, 1, 1, 1],
663 border => 0.8, 717 border => 0.8,
718 can_events => 1,
664 @_ 719 @_
665 ); 720 );
666 721
667 $self->{title} &&= new CFClient::UI::Label 722 $self->{title} &&= new CFClient::UI::Label
668 align => 0, 723 align => 0,
678} 733}
679 734
680sub size_request { 735sub size_request {
681 my ($self) = @_; 736 my ($self) = @_;
682 737
683 return ($self->{user_w}, $self->{user_h}) if $self->{user_w} && $self->{user_h};
684
685 my ($w, $h) = $self->SUPER::size_request; 738 my ($w, $h) = $self->SUPER::size_request;
686 739
687 ( 740 (
688 $w + $self->border * 2, 741 $w + $self->border * 2,
689 $h + $self->border * 2, 742 $h + $self->border * 2,
837 or next; 890 or next;
838 891
839 for my $x (0 .. $#$row) { 892 for my $x (0 .. $#$row) {
840 my $widget = $row->[$x] 893 my $widget = $row->[$x]
841 or next; 894 or next;
842 my ($w, $h) = $widget->size_request; 895 my ($w, $h) = @$widget{qw(req_w req_h)};
843 896
844 $w[$x] = max $w[$x], $w; 897 $w[$x] = max $w[$x], $w;
845 $h[$y] = max $h[$y], $h; 898 $h[$y] = max $h[$y], $h;
846 } 899 }
847 } 900 }
952 1005
953 ($h, $w) = ($w, $h); 1006 ($h, $w) = ($w, $h);
954 1007
955 my $children = $self->{children}; 1008 my $children = $self->{children};
956 1009
957 my @h = map +($_->size_request)[0], @$children; 1010 my @h = map $_->{req_w}, @$children;
958 1011
959 my $req_h = List::Util::sum @h; 1012 my $req_h = List::Util::sum @h;
960 1013
961 if ($req_h > $h) { 1014 if ($req_h > $h) {
962 # ah well, not enough space 1015 # ah well, not enough space
1010sub size_allocate { 1063sub size_allocate {
1011 my ($self, $w, $h) = @_; 1064 my ($self, $w, $h) = @_;
1012 1065
1013 my $children = $self->{children}; 1066 my $children = $self->{children};
1014 1067
1015 my @h = map +($_->size_request)[1], @$children; 1068 my @h = map $_->{req_h}, @$children;
1016 1069
1017 my $req_h = List::Util::sum @h; 1070 my $req_h = List::Util::sum @h;
1018 1071
1019 if ($req_h > $h) { 1072 if ($req_h > $h) {
1020 # ah well, not enough space 1073 # ah well, not enough space
1055sub new { 1108sub new {
1056 my ($class, %arg) = @_; 1109 my ($class, %arg) = @_;
1057 1110
1058 my $self = $class->SUPER::new ( 1111 my $self = $class->SUPER::new (
1059 fg => [1, 1, 1], 1112 fg => [1, 1, 1],
1113 #font => default_font
1060 fontsize => 1, 1114 fontsize => 1,
1061 text => "", 1115 text => "",
1062 align => -1, 1116 align => -1,
1063 valign => -1, 1117 valign => -1,
1064 padding => 2, 1118 padding => 2,
1065 layout => new CFClient::Layout, 1119 layout => new CFClient::Layout,
1120 can_events => 0,
1066 %arg 1121 %arg
1067 ); 1122 );
1068 1123
1069 if (exists $self->{template}) { 1124 if (exists $self->{template}) {
1070 my $layout = new CFClient::Layout; 1125 my $layout = new CFClient::Layout;
1092 my ($self, $text) = @_; 1147 my ($self, $text) = @_;
1093 1148
1094 $self->{layout}->set_text ($text); 1149 $self->{layout}->set_text ($text);
1095 1150
1096 delete $self->{texture}; 1151 delete $self->{texture};
1152 $self->check_size;
1097 $self->update; 1153 $self->update;
1098} 1154}
1099 1155
1100sub set_markup { 1156sub set_markup {
1101 my ($self, $markup) = @_; 1157 my ($self, $markup) = @_;
1102 1158
1103 $self->{layout}->set_markup ($markup); 1159 $self->{layout}->set_markup ($markup);
1104 1160
1105 delete $self->{texture}; 1161 delete $self->{texture};
1162 $self->check_size;
1106 $self->update; 1163 $self->update;
1107} 1164}
1108 1165
1109sub size_request { 1166sub size_request {
1110 my ($self) = @_; 1167 my ($self) = @_;
1111 1168
1112 $self->{layout}->set_width; 1169 $self->{layout}->set_font ($self->{font}) if $self->{font};
1170 $self->{layout}->set_width ($self->{max_w} || -1);
1113 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1171 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1114 1172
1115 my ($w, $h) = $self->{layout}->size; 1173 my ($w, $h) = $self->{layout}->size;
1116 1174
1117 if (exists $self->{template}) { 1175 if (exists $self->{template}) {
1176 $self->{template}->set_font ($self->{font}) if $self->{font};
1118 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1177 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1119 1178
1120 my ($w2, $h2) = $self->{template}->size; 1179 my ($w2, $h2) = $self->{template}->size;
1121 1180
1122 $w = List::Util::max $w, $w2; 1181 $w = List::Util::max $w, $w2;
1137 1196
1138sub set_fontsize { 1197sub set_fontsize {
1139 my ($self, $fontsize) = @_; 1198 my ($self, $fontsize) = @_;
1140 1199
1141 $self->{fontsize} = $fontsize; 1200 $self->{fontsize} = $fontsize;
1201 delete $self->{texture};
1142 $self->check_size; 1202 $self->check_size;
1203 $self->update;
1143} 1204}
1144 1205
1145sub _draw { 1206sub _draw {
1146 my ($self) = @_; 1207 my ($self) = @_;
1147 1208
1148 my $tex = $self->{texture} ||= do { 1209 my $tex = $self->{texture} ||= do {
1210 $self->{layout}->set_font ($self->{font}) if $self->{font};
1149 $self->{layout}->set_width ($self->{w}); 1211 $self->{layout}->set_width ($self->{w});
1150 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); 1212 $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE);
1151 new_from_layout CFClient::Texture $self->{layout} 1213 new_from_layout CFClient::Texture $self->{layout}
1152 }; 1214 };
1153 1215
1193 active_bg => [1, 1, 1, 0.5], 1255 active_bg => [1, 1, 1, 0.5],
1194 active_fg => [0, 0, 0], 1256 active_fg => [0, 0, 0],
1195 can_hover => 1, 1257 can_hover => 1,
1196 can_focus => 1, 1258 can_focus => 1,
1197 valign => 0, 1259 valign => 0,
1260 can_events => 1,
1198 @_ 1261 @_
1199 ) 1262 )
1200} 1263}
1201 1264
1202sub _set_text { 1265sub _set_text {
1230} 1293}
1231 1294
1232sub size_allocate { 1295sub size_allocate {
1233 my ($self, $w, $h) = @_; 1296 my ($self, $w, $h) = @_;
1234 1297
1235 $self->_set_text ($self->{text}); 1298 $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text
1236} 1299}
1237 1300
1238sub set_text { 1301sub set_text {
1239 my ($self, $text) = @_; 1302 my ($self, $text) = @_;
1240 1303
1387 bg => [1, 1, 1, 0.2], 1450 bg => [1, 1, 1, 0.2],
1388 active_fg => [0, 0, 1], 1451 active_fg => [0, 0, 1],
1389 can_hover => 1, 1452 can_hover => 1,
1390 align => 0, 1453 align => 0,
1391 valign => 0, 1454 valign => 0,
1455 can_events => 1,
1392 @_ 1456 @_
1393 ) 1457 )
1394} 1458}
1395 1459
1396sub button_up { 1460sub button_up {
1501our %loaded_images; 1565our %loaded_images;
1502 1566
1503sub new { 1567sub new {
1504 my $class = shift; 1568 my $class = shift;
1505 1569
1506 my $self = $class->SUPER::new (@_); 1570 my $self = $class->SUPER::new (can_events => 0, @_);
1507 1571
1508 $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; 1572 $self->{image} or confess "Image has 'image' not set. This is a fatal error!";
1509 1573
1510 $loaded_images{$self->{image}} ||= 1574 $loaded_images{$self->{image}} ||=
1511 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; 1575 new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1;
1553############################################################################# 1617#############################################################################
1554 1618
1555package CFClient::UI::VGauge; 1619package CFClient::UI::VGauge;
1556 1620
1557our @ISA = CFClient::UI::Base::; 1621our @ISA = CFClient::UI::Base::;
1622
1623use List::Util qw(min max);
1558 1624
1559use CFClient::OpenGL; 1625use CFClient::OpenGL;
1560 1626
1561my %tex = ( 1627my %tex = (
1562 food => [ 1628 food => [
1563 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1629 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1564 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 1630 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
1565 ], 1631 ],
1566 grace => [ 1632 grace => [
1567 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1633 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1568 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png/ 1634 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
1569 ], 1635 ],
1570 hp => [ 1636 hp => [
1571 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1637 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1572 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 1638 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
1573 ], 1639 ],
1574 mana => [ 1640 mana => [
1575 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } 1641 map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 }
1576 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png/ 1642 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
1577 ], 1643 ],
1578); 1644);
1579 1645
1580# eg. VGauge->new (gauge => 'food'), default gauge: food 1646# eg. VGauge->new (gauge => 'food'), default gauge: food
1581sub new { 1647sub new {
1619 1685
1620sub _draw { 1686sub _draw {
1621 my ($self) = @_; 1687 my ($self) = @_;
1622 1688
1623 my $tex = $tex{$self->{type}}; 1689 my $tex = $tex{$self->{type}};
1690 my ($t1, $t2, $t3) = @$tex;
1624 1691
1625 my ($w, $h) = ($self->{w}, $self->{h}); 1692 my ($w, $h) = ($self->{w}, $self->{h});
1626 1693
1627 if ($self->{vertical}) { 1694 if ($self->{vertical}) {
1628 glRotate 90, 0, 0, 1; 1695 glRotate 90, 0, 0, 1;
1630 1697
1631 ($w, $h) = ($h, $w); 1698 ($w, $h) = ($h, $w);
1632 } 1699 }
1633 1700
1634 my $ycut = $self->{val} / ($self->{max_val} || 1); 1701 my $ycut = $self->{val} / ($self->{max_val} || 1);
1635 $ycut = 1 if $self->{val} > $self->{max_val};
1636 1702
1637 my $t1 = $tex->[0]; 1703 my $ycut1 = max 0, min 1, $ycut;
1638 my $t2 = $tex->[1]; 1704 my $ycut2 = max 0, min 1, $ycut - 1;
1705
1706 my $h1 = $self->{h} * (1 - $ycut1);
1707 my $h2 = $self->{h} * (1 - $ycut2);
1639 1708
1640 glEnable GL_BLEND; 1709 glEnable GL_BLEND;
1641 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 1710 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
1642 glEnable GL_TEXTURE_2D; 1711 glEnable GL_TEXTURE_2D;
1643 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 1712 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
1644 1713
1645 my $h1 = $self->{h} - $ycut * $self->{h};
1646 my $h2 = $ycut * $self->{h};
1647
1648 glBindTexture GL_TEXTURE_2D, $t1->{name}; 1714 glBindTexture GL_TEXTURE_2D, $t1->{name};
1649 glBegin GL_QUADS; 1715 glBegin GL_QUADS;
1650 glTexCoord 0 , 0; glVertex 0 , 0; 1716 glTexCoord 0 , 0; glVertex 0 , 0;
1651 glTexCoord 0 , $t1->{t} * (1 - $ycut); glVertex 0 , $h1; 1717 glTexCoord 0 , $t1->{t} * (1 - $ycut1); glVertex 0 , $h1;
1652 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut); glVertex $w, $h1; 1718 glTexCoord $t1->{s}, $t1->{t} * (1 - $ycut1); glVertex $w, $h1;
1653 glTexCoord $t1->{s}, 0; glVertex $w, 0; 1719 glTexCoord $t1->{s}, 0; glVertex $w, 0;
1654 glEnd; 1720 glEnd;
1655 1721
1722 my $ycut1 = List::Util::min 1, $ycut;
1656 glBindTexture GL_TEXTURE_2D, $t2->{name}; 1723 glBindTexture GL_TEXTURE_2D, $t2->{name};
1657 glBegin GL_QUADS; 1724 glBegin GL_QUADS;
1658 glTexCoord 0 , $t2->{t} * (1 - $ycut); glVertex 0 , $h1; 1725 glTexCoord 0 , $t2->{t} * (1 - $ycut1); glVertex 0 , $h1;
1659 glTexCoord 0 , $t2->{t}; glVertex 0 , $h1 + $h2; 1726 glTexCoord 0 , $t2->{t} * (1 - $ycut2); glVertex 0 , $h2;
1660 glTexCoord $t2->{s}, $t2->{t}; glVertex $w, $h1 + $h2; 1727 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut2); glVertex $w, $h2;
1661 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut); glVertex $w, $h1; 1728 glTexCoord $t2->{s}, $t2->{t} * (1 - $ycut1); glVertex $w, $h1;
1662 glEnd; 1729 glEnd;
1730
1731 if ($t3) {
1732 glBindTexture GL_TEXTURE_2D, $t3->{name};
1733 glBegin GL_QUADS;
1734 glTexCoord 0 , $t3->{t} * (1 - $ycut2); glVertex 0 , $h2;
1735 glTexCoord 0 , $t3->{t}; glVertex 0 , $self->{h};
1736 glTexCoord $t3->{s}, $t3->{t}; glVertex $w, $self->{h};
1737 glTexCoord $t3->{s}, $t3->{t} * (1 - $ycut2); glVertex $w, $h2;
1738 glEnd;
1739 }
1663 1740
1664 glDisable GL_BLEND; 1741 glDisable GL_BLEND;
1665 glDisable GL_TEXTURE_2D; 1742 glDisable GL_TEXTURE_2D;
1666} 1743}
1667 1744
1670package CFClient::UI::Gauge; 1747package CFClient::UI::Gauge;
1671 1748
1672our @ISA = CFClient::UI::VBox::; 1749our @ISA = CFClient::UI::VBox::;
1673 1750
1674sub new { 1751sub new {
1675 my ($class, %arg) = shift; 1752 my ($class, %arg) = @_;
1676 1753
1677 my $self = $class->SUPER::new ( 1754 my $self = $class->SUPER::new (
1678 @_, 1755 tooltip => $arg{type},
1756 %arg,
1679 ); 1757 );
1680 1758
1681 $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); 1759 $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); 1760 $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"); 1761 $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1);
1684 1762
1685 $self 1763 $self
1686} 1764}
1687 1765
1688sub set_fontsize { 1766sub set_fontsize {
1855sub new { 1933sub new {
1856 my $class = shift; 1934 my $class = shift;
1857 1935
1858 my $self = $class->SUPER::new ( 1936 my $self = $class->SUPER::new (
1859 fontsize => 1, 1937 fontsize => 1,
1938 #font => default_font
1860 @_, 1939 @_,
1861 1940
1862 layout => (new CFClient::Layout), 1941 layout => (new CFClient::Layout),
1863 par => [], 1942 par => [],
1864 height => 0, 1943 height => 0,
1904sub size_allocate { 1983sub size_allocate {
1905 my ($self, $w, $h) = @_; 1984 my ($self, $w, $h) = @_;
1906 1985
1907 $self->SUPER::size_allocate ($w, $h); 1986 $self->SUPER::size_allocate ($w, $h);
1908 1987
1988 $self->{layout}->set_font ($self->{font}) if $self->{font};
1909 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1989 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1910 $self->{layout}->set_width ($self->{children}[0]{w}); 1990 $self->{layout}->set_width ($self->{children}[0]{w});
1911 1991
1912 $self->reflow; 1992 $self->reflow;
1913} 1993}
1965 my $y1 = $top + $self->{h}; 2045 my $y1 = $top + $self->{h};
1966 2046
1967 my $y = 0; 2047 my $y = 0;
1968 2048
1969 my $layout = $self->{layout}; 2049 my $layout = $self->{layout};
2050
2051 $layout->set_font ($self->{font}) if $self->{font};
1970 2052
1971 for my $par (@{$self->{par}}) { 2053 for my $par (@{$self->{par}}) {
1972 my $h = $par->[0]; 2054 my $h = $par->[0];
1973 2055
1974 if ($y0 < $y + $h && $y < $y1) { 2056 if ($y0 < $y + $h && $y < $y1) {
2054 my $class = shift; 2136 my $class = shift;
2055 2137
2056 my $self = $class->SUPER::new ( 2138 my $self = $class->SUPER::new (
2057 state => 0, 2139 state => 0,
2058 connect_activate => \&toggle_flopper, 2140 connect_activate => \&toggle_flopper,
2141 can_events => 1,
2059 @_ 2142 @_
2060 ); 2143 );
2061 2144
2062 if ($self->{state}) { 2145 if ($self->{state}) {
2063 $self->{state} = 0; 2146 $self->{state} = 0;
2083 $self->emit (changed => $self->{state}); 2166 $self->emit (changed => $self->{state});
2084} 2167}
2085 2168
2086############################################################################# 2169#############################################################################
2087 2170
2171package CFClient::UI::Tooltip;
2172
2173our @ISA = CFClient::UI::Bin::;
2174
2175use CFClient::OpenGL;
2176
2177sub new {
2178 my $class = shift;
2179
2180 $class->SUPER::new (
2181 @_,
2182 can_events => 0,
2183 )
2184}
2185
2186sub set_text {
2187 my ($self, $text) = @_;
2188
2189 $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0];
2190 $self->{label}->set_text ($text);
2191 $self->add ($self->{label});
2192}
2193
2194sub size_request {
2195 my ($self) = @_;
2196
2197 $self->child->set_max_size ($::WIDTH * 0.3);
2198
2199 my ($w, $h) = @{$self->child}{qw(req_w req_h)};
2200
2201 ($w + 4, $h + 4)
2202}
2203
2204sub _draw {
2205 my ($self) = @_;
2206
2207 glPushMatrix;
2208 glTranslate 0.375, 0.375;
2209
2210 my ($w, $h) = @$self{qw(w h)};
2211
2212 glColor 1, 0.8, 0.4;
2213 glBegin GL_QUADS;
2214 glVertex 0 , 0;
2215 glVertex 0 , $h;
2216 glVertex $w, $h;
2217 glVertex $w, 0;
2218 glEnd;
2219
2220 glColor 0, 0, 0;
2221 glBegin GL_LINE_LOOP;
2222 glVertex 0 , 0;
2223 glVertex 0 , $h;
2224 glVertex $w, $h;
2225 glVertex $w, 0;
2226 glEnd;
2227
2228 glPopMatrix;
2229
2230 glTranslate 2, 2;
2231 $self->SUPER::_draw;
2232}
2233
2234#############################################################################
2235
2088package CFClient::UI::Root; 2236package CFClient::UI::Root;
2089 2237
2090our @ISA = CFClient::UI::Container::; 2238our @ISA = CFClient::UI::Container::;
2091 2239
2092use CFClient::OpenGL; 2240use CFClient::OpenGL;
2093 2241
2094sub check_size { 2242sub check_size {
2095 my ($self) = @_; 2243 my ($self) = @_;
2096 2244
2097 $self->configure (0, 0, $::WITH, $::HEIGHT); 2245 $self->configure (0, 0, $::WIDTH, $::HEIGHT);
2098} 2246}
2099 2247
2100sub size_request { 2248sub size_request {
2101 ($::WIDTH, $::HEIGHT) 2249 ($::WIDTH, $::HEIGHT)
2102} 2250}
2104sub configure { 2252sub configure {
2105 my ($self, $x, $y, $w, $h) = @_; 2253 my ($self, $x, $y, $w, $h) = @_;
2106 2254
2107 $self->SUPER::configure ($x, $y, $w, $h); 2255 $self->SUPER::configure ($x, $y, $w, $h);
2108 2256
2109 $_->configure ($_->{x}, $_->{y}, $_->size_request)
2110 for @{$self->{children}}; 2257 for my $child (@{$self->{children}}) {
2258 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
2259
2260 $X = List::Util::max 0, List::Util::min $w - $W, $X;
2261 $Y = List::Util::max 0, List::Util::min $h - $H, $Y;
2262 $child->configure ($X, $Y, $W,$H);
2263 }
2111} 2264}
2112 2265
2113sub _topleft { 2266sub _topleft {
2114 my ($self, $x, $y) = @_; 2267 my ($self, $x, $y) = @_;
2115 2268
2162############################################################################# 2315#############################################################################
2163 2316
2164package CFClient::UI; 2317package CFClient::UI;
2165 2318
2166$ROOT = new CFClient::UI::Root; 2319$ROOT = new CFClient::UI::Root;
2320$TOOLTIP = new CFClient::UI::Tooltip;
2167 2321
21681 23221
2169 2323

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines