… | |
… | |
8 | use CFClient; |
8 | use CFClient; |
9 | |
9 | |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
10 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
11 | |
11 | |
12 | our $ROOT; |
12 | our $ROOT; |
|
|
13 | our $TOOLTIP; |
13 | our $BUTTON_STATE; |
14 | our $BUTTON_STATE; |
|
|
15 | |
|
|
16 | sub 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 |
16 | sub feed_sdl_key_down_event { |
43 | sub 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 | |
57 | sub feed_sdl_motion_event { |
88 | sub feed_sdl_motion_event { |
58 | my ($ev) = @_; |
89 | my ($ev) = @_; |
… | |
… | |
63 | if ($widget != $HOVER) { |
94 | if ($widget != $HOVER) { |
64 | my $hover = $HOVER; $HOVER = $widget; |
95 | my $hover = $HOVER; $HOVER = $widget; |
65 | |
96 | |
66 | $hover->update if $hover && $hover->{can_hover}; |
97 | $hover->update if $hover && $hover->{can_hover}; |
67 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
98 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
|
|
99 | |
|
|
100 | check_tooltip; |
68 | } |
101 | } |
69 | |
102 | |
70 | $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; |
103 | $HOVER->mouse_motion ($ev, $HOVER->coord2local ($x, $y)) if $HOVER; |
71 | } |
104 | } |
72 | |
105 | |
… | |
… | |
96 | |
129 | |
97 | my $self = bless { |
130 | my $self = bless { |
98 | x => 0, |
131 | x => 0, |
99 | y => 0, |
132 | y => 0, |
100 | z => 0, |
133 | z => 0, |
|
|
134 | can_events => 1, |
101 | @_ |
135 | @_ |
102 | }, $class; |
136 | }, $class; |
103 | |
137 | |
104 | for (keys %$self) { |
138 | for (keys %$self) { |
105 | if (/^connect_(.*)$/) { |
139 | if (/^connect_(.*)$/) { |
… | |
… | |
175 | } |
209 | } |
176 | } |
210 | } |
177 | |
211 | |
178 | sub size_allocate { |
212 | sub size_allocate { |
179 | # nothing to be done |
213 | # nothing to be done |
|
|
214 | } |
|
|
215 | |
|
|
216 | sub set_max_size { |
|
|
217 | my ($self, $w, $h) = @_; |
|
|
218 | |
|
|
219 | delete $self->{max_w}; $self->{max_w} = $w if $w; |
|
|
220 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
180 | } |
221 | } |
181 | |
222 | |
182 | # return top left coordinates |
223 | # return top left coordinates |
183 | sub _topleft { |
224 | sub _topleft { |
184 | my ($self, $x, $y) = @_; |
225 | my ($self, $x, $y) = @_; |
… | |
… | |
278 | } |
319 | } |
279 | |
320 | |
280 | sub find_widget { |
321 | sub find_widget { |
281 | my ($self, $x, $y) = @_; |
322 | my ($self, $x, $y) = @_; |
282 | |
323 | |
|
|
324 | return () unless $self->{can_events}; |
|
|
325 | |
283 | return $self |
326 | return $self |
284 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
327 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
285 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
328 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
286 | |
329 | |
287 | () |
330 | () |
… | |
… | |
294 | } |
337 | } |
295 | |
338 | |
296 | sub check_size { |
339 | sub check_size { |
297 | my ($self) = @_; |
340 | my ($self) = @_; |
298 | |
341 | |
|
|
342 | return unless $self->{parent}; |
|
|
343 | |
299 | my ($w, $h) = $self->size_request; |
344 | my ($w, $h) = $self->size_request; |
300 | |
345 | |
301 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
346 | if ($w != $self->{req_w} || $h != $self->{req_h}) { |
302 | $self->{req_w} = $w; |
347 | $self->{req_w} = $w; |
303 | $self->{req_h} = $h; |
348 | $self->{req_h} = $h; |
304 | |
349 | |
305 | $self->{parent}->check_size |
350 | $self->{parent}->check_size; |
306 | if $self->{parent}; |
|
|
307 | } |
351 | } |
308 | } |
352 | } |
309 | |
353 | |
310 | sub update { |
354 | sub update { |
311 | my ($self) = @_; |
355 | my ($self) = @_; |
… | |
… | |
378 | |
422 | |
379 | package CFClient::UI::Empty; |
423 | package CFClient::UI::Empty; |
380 | |
424 | |
381 | our @ISA = CFClient::UI::Base::; |
425 | our @ISA = CFClient::UI::Base::; |
382 | |
426 | |
|
|
427 | sub new { |
|
|
428 | my ($class, %arg) = @_; |
|
|
429 | $class->SUPER::new (can_events => 0, %arg); |
|
|
430 | } |
|
|
431 | |
383 | sub size_request { |
432 | sub size_request { |
384 | (0, 0) |
433 | (0, 0) |
385 | } |
434 | } |
386 | |
435 | |
387 | sub draw { } |
436 | sub draw { } |
… | |
… | |
395 | sub new { |
444 | sub new { |
396 | my ($class, %arg) = @_; |
445 | my ($class, %arg) = @_; |
397 | |
446 | |
398 | my $children = delete $arg{children} || []; |
447 | my $children = delete $arg{children} || []; |
399 | |
448 | |
400 | my $self = $class->SUPER::new (children => [], %arg); |
449 | my $self = $class->SUPER::new (children => [], can_events => 0, %arg); |
401 | $self->add ($_) for @$children; |
450 | $self->add ($_) for @$children; |
402 | |
451 | |
403 | $self |
452 | $self |
404 | } |
453 | } |
405 | |
454 | |
… | |
… | |
424 | delete $child->{parent}; |
473 | delete $child->{parent}; |
425 | |
474 | |
426 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
475 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
427 | |
476 | |
428 | $self->check_size; |
477 | $self->check_size; |
|
|
478 | $self->update; |
429 | } |
479 | } |
430 | |
480 | |
431 | sub find_widget { |
481 | sub find_widget { |
432 | my ($self, $x, $y) = @_; |
482 | my ($self, $x, $y) = @_; |
433 | |
483 | |
… | |
… | |
561 | sub new { die } |
611 | sub new { die } |
562 | |
612 | |
563 | sub size_request { |
613 | sub size_request { |
564 | my ($self) = @_; |
614 | my ($self) = @_; |
565 | |
615 | |
566 | @$self{qw(child_w child_h)} = $self->child->size_request; |
616 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
567 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
617 | $self->child->size_allocate (0, 0, @$self{qw(child_w child_h)}); |
568 | |
618 | |
569 | @$self{qw(child_w child_h)} |
619 | @$self{qw(child_w child_h)} |
570 | } |
620 | } |
571 | |
621 | |
… | |
… | |
659 | |
709 | |
660 | my $self = $class->SUPER::new ( |
710 | my $self = $class->SUPER::new ( |
661 | bg => [1, 1, 1, 1], |
711 | bg => [1, 1, 1, 1], |
662 | border_bg => [1, 1, 1, 1], |
712 | border_bg => [1, 1, 1, 1], |
663 | border => 0.8, |
713 | border => 0.8, |
|
|
714 | can_events => 1, |
664 | @_ |
715 | @_ |
665 | ); |
716 | ); |
666 | |
717 | |
667 | $self->{title} &&= new CFClient::UI::Label |
718 | $self->{title} &&= new CFClient::UI::Label |
668 | align => 0, |
719 | align => 0, |
… | |
… | |
837 | or next; |
888 | or next; |
838 | |
889 | |
839 | for my $x (0 .. $#$row) { |
890 | for my $x (0 .. $#$row) { |
840 | my $widget = $row->[$x] |
891 | my $widget = $row->[$x] |
841 | or next; |
892 | or next; |
842 | my ($w, $h) = $widget->size_request; |
893 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
843 | |
894 | |
844 | $w[$x] = max $w[$x], $w; |
895 | $w[$x] = max $w[$x], $w; |
845 | $h[$y] = max $h[$y], $h; |
896 | $h[$y] = max $h[$y], $h; |
846 | } |
897 | } |
847 | } |
898 | } |
… | |
… | |
952 | |
1003 | |
953 | ($h, $w) = ($w, $h); |
1004 | ($h, $w) = ($w, $h); |
954 | |
1005 | |
955 | my $children = $self->{children}; |
1006 | my $children = $self->{children}; |
956 | |
1007 | |
957 | my @h = map +($_->size_request)[0], @$children; |
1008 | my @h = map $_->{req_w}, @$children; |
958 | |
1009 | |
959 | my $req_h = List::Util::sum @h; |
1010 | my $req_h = List::Util::sum @h; |
960 | |
1011 | |
961 | if ($req_h > $h) { |
1012 | if ($req_h > $h) { |
962 | # ah well, not enough space |
1013 | # ah well, not enough space |
… | |
… | |
1010 | sub size_allocate { |
1061 | sub size_allocate { |
1011 | my ($self, $w, $h) = @_; |
1062 | my ($self, $w, $h) = @_; |
1012 | |
1063 | |
1013 | my $children = $self->{children}; |
1064 | my $children = $self->{children}; |
1014 | |
1065 | |
1015 | my @h = map +($_->size_request)[1], @$children; |
1066 | my @h = map $_->{req_h}, @$children; |
1016 | |
1067 | |
1017 | my $req_h = List::Util::sum @h; |
1068 | my $req_h = List::Util::sum @h; |
1018 | |
1069 | |
1019 | if ($req_h > $h) { |
1070 | if ($req_h > $h) { |
1020 | # ah well, not enough space |
1071 | # ah well, not enough space |
… | |
… | |
1055 | sub new { |
1106 | sub new { |
1056 | my ($class, %arg) = @_; |
1107 | my ($class, %arg) = @_; |
1057 | |
1108 | |
1058 | my $self = $class->SUPER::new ( |
1109 | my $self = $class->SUPER::new ( |
1059 | fg => [1, 1, 1], |
1110 | fg => [1, 1, 1], |
|
|
1111 | #font => default_font |
1060 | fontsize => 1, |
1112 | fontsize => 1, |
1061 | text => "", |
1113 | text => "", |
1062 | align => -1, |
1114 | align => -1, |
1063 | valign => -1, |
1115 | valign => -1, |
1064 | padding => 2, |
1116 | padding => 2, |
1065 | layout => new CFClient::Layout, |
1117 | layout => new CFClient::Layout, |
|
|
1118 | can_events => 0, |
1066 | %arg |
1119 | %arg |
1067 | ); |
1120 | ); |
1068 | |
1121 | |
1069 | if (exists $self->{template}) { |
1122 | if (exists $self->{template}) { |
1070 | my $layout = new CFClient::Layout; |
1123 | my $layout = new CFClient::Layout; |
… | |
… | |
1092 | my ($self, $text) = @_; |
1145 | my ($self, $text) = @_; |
1093 | |
1146 | |
1094 | $self->{layout}->set_text ($text); |
1147 | $self->{layout}->set_text ($text); |
1095 | |
1148 | |
1096 | delete $self->{texture}; |
1149 | delete $self->{texture}; |
|
|
1150 | $self->check_size; |
1097 | $self->update; |
1151 | $self->update; |
1098 | } |
1152 | } |
1099 | |
1153 | |
1100 | sub set_markup { |
1154 | sub set_markup { |
1101 | my ($self, $markup) = @_; |
1155 | my ($self, $markup) = @_; |
1102 | |
1156 | |
1103 | $self->{layout}->set_markup ($markup); |
1157 | $self->{layout}->set_markup ($markup); |
1104 | |
1158 | |
1105 | delete $self->{texture}; |
1159 | delete $self->{texture}; |
|
|
1160 | $self->check_size; |
1106 | $self->update; |
1161 | $self->update; |
1107 | } |
1162 | } |
1108 | |
1163 | |
1109 | sub size_request { |
1164 | sub size_request { |
1110 | my ($self) = @_; |
1165 | my ($self) = @_; |
1111 | |
1166 | |
1112 | $self->{layout}->set_width; |
1167 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
|
|
1168 | $self->{layout}->set_width ($self->{max_w} || -1); |
1113 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1169 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1114 | |
1170 | |
1115 | my ($w, $h) = $self->{layout}->size; |
1171 | my ($w, $h) = $self->{layout}->size; |
1116 | |
1172 | |
1117 | if (exists $self->{template}) { |
1173 | if (exists $self->{template}) { |
|
|
1174 | $self->{template}->set_font ($self->{font}) if $self->{font}; |
1118 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1175 | $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); |
1119 | |
1176 | |
1120 | my ($w2, $h2) = $self->{template}->size; |
1177 | my ($w2, $h2) = $self->{template}->size; |
1121 | |
1178 | |
1122 | $w = List::Util::max $w, $w2; |
1179 | $w = List::Util::max $w, $w2; |
… | |
… | |
1137 | |
1194 | |
1138 | sub set_fontsize { |
1195 | sub set_fontsize { |
1139 | my ($self, $fontsize) = @_; |
1196 | my ($self, $fontsize) = @_; |
1140 | |
1197 | |
1141 | $self->{fontsize} = $fontsize; |
1198 | $self->{fontsize} = $fontsize; |
|
|
1199 | delete $self->{texture}; |
1142 | $self->check_size; |
1200 | $self->check_size; |
|
|
1201 | $self->update; |
1143 | } |
1202 | } |
1144 | |
1203 | |
1145 | sub _draw { |
1204 | sub _draw { |
1146 | my ($self) = @_; |
1205 | my ($self) = @_; |
1147 | |
1206 | |
1148 | my $tex = $self->{texture} ||= do { |
1207 | my $tex = $self->{texture} ||= do { |
|
|
1208 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1149 | $self->{layout}->set_width ($self->{w}); |
1209 | $self->{layout}->set_width ($self->{w}); |
1150 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1210 | $self->{layout}->set_height (List::Util::min $self->{h}, $self->{fontsize} * $::FONTSIZE); |
1151 | new_from_layout CFClient::Texture $self->{layout} |
1211 | new_from_layout CFClient::Texture $self->{layout} |
1152 | }; |
1212 | }; |
1153 | |
1213 | |
… | |
… | |
1193 | active_bg => [1, 1, 1, 0.5], |
1253 | active_bg => [1, 1, 1, 0.5], |
1194 | active_fg => [0, 0, 0], |
1254 | active_fg => [0, 0, 0], |
1195 | can_hover => 1, |
1255 | can_hover => 1, |
1196 | can_focus => 1, |
1256 | can_focus => 1, |
1197 | valign => 0, |
1257 | valign => 0, |
|
|
1258 | can_events => 1, |
1198 | @_ |
1259 | @_ |
1199 | ) |
1260 | ) |
1200 | } |
1261 | } |
1201 | |
1262 | |
1202 | sub _set_text { |
1263 | sub _set_text { |
… | |
… | |
1230 | } |
1291 | } |
1231 | |
1292 | |
1232 | sub size_allocate { |
1293 | sub size_allocate { |
1233 | my ($self, $w, $h) = @_; |
1294 | my ($self, $w, $h) = @_; |
1234 | |
1295 | |
1235 | $self->_set_text ($self->{text}); |
1296 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
1236 | } |
1297 | } |
1237 | |
1298 | |
1238 | sub set_text { |
1299 | sub set_text { |
1239 | my ($self, $text) = @_; |
1300 | my ($self, $text) = @_; |
1240 | |
1301 | |
… | |
… | |
1387 | bg => [1, 1, 1, 0.2], |
1448 | bg => [1, 1, 1, 0.2], |
1388 | active_fg => [0, 0, 1], |
1449 | active_fg => [0, 0, 1], |
1389 | can_hover => 1, |
1450 | can_hover => 1, |
1390 | align => 0, |
1451 | align => 0, |
1391 | valign => 0, |
1452 | valign => 0, |
|
|
1453 | can_events => 1, |
1392 | @_ |
1454 | @_ |
1393 | ) |
1455 | ) |
1394 | } |
1456 | } |
1395 | |
1457 | |
1396 | sub button_up { |
1458 | sub button_up { |
… | |
… | |
1501 | our %loaded_images; |
1563 | our %loaded_images; |
1502 | |
1564 | |
1503 | sub new { |
1565 | sub new { |
1504 | my $class = shift; |
1566 | my $class = shift; |
1505 | |
1567 | |
1506 | my $self = $class->SUPER::new (@_); |
1568 | my $self = $class->SUPER::new (can_events => 0, @_); |
1507 | |
1569 | |
1508 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
1570 | $self->{image} or confess "Image has 'image' not set. This is a fatal error!"; |
1509 | |
1571 | |
1510 | $loaded_images{$self->{image}} ||= |
1572 | $loaded_images{$self->{image}} ||= |
1511 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
1573 | new_from_file CFClient::Texture CFClient::find_rcfile $self->{image}, mipmap => 1; |
… | |
… | |
1670 | package CFClient::UI::Gauge; |
1732 | package CFClient::UI::Gauge; |
1671 | |
1733 | |
1672 | our @ISA = CFClient::UI::VBox::; |
1734 | our @ISA = CFClient::UI::VBox::; |
1673 | |
1735 | |
1674 | sub new { |
1736 | sub new { |
1675 | my ($class, %arg) = shift; |
1737 | my ($class, %arg) = @_; |
1676 | |
1738 | |
1677 | my $self = $class->SUPER::new ( |
1739 | my $self = $class->SUPER::new ( |
1678 | @_, |
1740 | tooltip => $arg{type}, |
|
|
1741 | %arg, |
1679 | ); |
1742 | ); |
1680 | |
1743 | |
1681 | $self->add ($self->{value} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
1744 | $self->add ($self->{value} = new CFClient::UI::Label valign => +1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1682 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1); |
1745 | $self->add ($self->{gauge} = new CFClient::UI::VGauge type => $self->{type}, expand => 1, can_events => 1, can_hover => 1); |
1683 | $self->add ($self->{max} = new CFClient::UI::Label valign => 1, align => 0, template => "999"); |
1746 | $self->add ($self->{max} = new CFClient::UI::Label valign => -1, align => 0, template => "999", can_events => 1, can_hover => 1); |
1684 | |
1747 | |
1685 | $self |
1748 | $self |
1686 | } |
1749 | } |
1687 | |
1750 | |
1688 | sub set_fontsize { |
1751 | sub set_fontsize { |
… | |
… | |
1855 | sub new { |
1918 | sub new { |
1856 | my $class = shift; |
1919 | my $class = shift; |
1857 | |
1920 | |
1858 | my $self = $class->SUPER::new ( |
1921 | my $self = $class->SUPER::new ( |
1859 | fontsize => 1, |
1922 | fontsize => 1, |
|
|
1923 | #font => default_font |
1860 | @_, |
1924 | @_, |
1861 | |
1925 | |
1862 | layout => (new CFClient::Layout), |
1926 | layout => (new CFClient::Layout), |
1863 | par => [], |
1927 | par => [], |
1864 | height => 0, |
1928 | height => 0, |
… | |
… | |
1904 | sub size_allocate { |
1968 | sub size_allocate { |
1905 | my ($self, $w, $h) = @_; |
1969 | my ($self, $w, $h) = @_; |
1906 | |
1970 | |
1907 | $self->SUPER::size_allocate ($w, $h); |
1971 | $self->SUPER::size_allocate ($w, $h); |
1908 | |
1972 | |
|
|
1973 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1909 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1974 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1910 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1975 | $self->{layout}->set_width ($self->{children}[0]{w}); |
1911 | |
1976 | |
1912 | $self->reflow; |
1977 | $self->reflow; |
1913 | } |
1978 | } |
… | |
… | |
1965 | my $y1 = $top + $self->{h}; |
2030 | my $y1 = $top + $self->{h}; |
1966 | |
2031 | |
1967 | my $y = 0; |
2032 | my $y = 0; |
1968 | |
2033 | |
1969 | my $layout = $self->{layout}; |
2034 | my $layout = $self->{layout}; |
|
|
2035 | |
|
|
2036 | $layout->set_font ($self->{font}) if $self->{font}; |
1970 | |
2037 | |
1971 | for my $par (@{$self->{par}}) { |
2038 | for my $par (@{$self->{par}}) { |
1972 | my $h = $par->[0]; |
2039 | my $h = $par->[0]; |
1973 | |
2040 | |
1974 | if ($y0 < $y + $h && $y < $y1) { |
2041 | if ($y0 < $y + $h && $y < $y1) { |
… | |
… | |
2054 | my $class = shift; |
2121 | my $class = shift; |
2055 | |
2122 | |
2056 | my $self = $class->SUPER::new ( |
2123 | my $self = $class->SUPER::new ( |
2057 | state => 0, |
2124 | state => 0, |
2058 | connect_activate => \&toggle_flopper, |
2125 | connect_activate => \&toggle_flopper, |
|
|
2126 | can_events => 1, |
2059 | @_ |
2127 | @_ |
2060 | ); |
2128 | ); |
2061 | |
2129 | |
2062 | if ($self->{state}) { |
2130 | if ($self->{state}) { |
2063 | $self->{state} = 0; |
2131 | $self->{state} = 0; |
… | |
… | |
2083 | $self->emit (changed => $self->{state}); |
2151 | $self->emit (changed => $self->{state}); |
2084 | } |
2152 | } |
2085 | |
2153 | |
2086 | ############################################################################# |
2154 | ############################################################################# |
2087 | |
2155 | |
|
|
2156 | package CFClient::UI::Tooltip; |
|
|
2157 | |
|
|
2158 | our @ISA = CFClient::UI::Bin::; |
|
|
2159 | |
|
|
2160 | use CFClient::OpenGL; |
|
|
2161 | |
|
|
2162 | sub new { |
|
|
2163 | my $class = shift; |
|
|
2164 | |
|
|
2165 | $class->SUPER::new ( |
|
|
2166 | @_, |
|
|
2167 | can_events => 0, |
|
|
2168 | ) |
|
|
2169 | } |
|
|
2170 | |
|
|
2171 | sub set_text { |
|
|
2172 | my ($self, $text) = @_; |
|
|
2173 | |
|
|
2174 | $self->{label} ||= new CFClient::UI::Label fontsize => 0.8, fg => [0, 0, 0]; |
|
|
2175 | $self->{label}->set_text ($text); |
|
|
2176 | $self->add ($self->{label}); |
|
|
2177 | } |
|
|
2178 | |
|
|
2179 | sub size_request { |
|
|
2180 | my ($self) = @_; |
|
|
2181 | |
|
|
2182 | $self->child->set_max_size ($::WIDTH * 0.2); |
|
|
2183 | |
|
|
2184 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
|
|
2185 | |
|
|
2186 | ($w + 4, $h + 4) |
|
|
2187 | } |
|
|
2188 | |
|
|
2189 | sub _draw { |
|
|
2190 | my ($self) = @_; |
|
|
2191 | |
|
|
2192 | glPushMatrix; |
|
|
2193 | glTranslate 0.375, 0.375; |
|
|
2194 | |
|
|
2195 | my ($w, $h) = @$self{qw(w h)}; |
|
|
2196 | |
|
|
2197 | glColor 1, 0.8, 0.4; |
|
|
2198 | glBegin GL_QUADS; |
|
|
2199 | glVertex 0 , 0; |
|
|
2200 | glVertex 0 , $h; |
|
|
2201 | glVertex $w, $h; |
|
|
2202 | glVertex $w, 0; |
|
|
2203 | glEnd; |
|
|
2204 | |
|
|
2205 | glColor 0, 0, 0; |
|
|
2206 | glBegin GL_LINE_LOOP; |
|
|
2207 | glVertex 0 , 0; |
|
|
2208 | glVertex 0 , $h; |
|
|
2209 | glVertex $w, $h; |
|
|
2210 | glVertex $w, 0; |
|
|
2211 | glEnd; |
|
|
2212 | |
|
|
2213 | glPopMatrix; |
|
|
2214 | |
|
|
2215 | glTranslate 2, 2; |
|
|
2216 | $self->SUPER::_draw; |
|
|
2217 | } |
|
|
2218 | |
|
|
2219 | ############################################################################# |
|
|
2220 | |
2088 | package CFClient::UI::Root; |
2221 | package CFClient::UI::Root; |
2089 | |
2222 | |
2090 | our @ISA = CFClient::UI::Container::; |
2223 | our @ISA = CFClient::UI::Container::; |
2091 | |
2224 | |
2092 | use CFClient::OpenGL; |
2225 | use CFClient::OpenGL; |
2093 | |
2226 | |
2094 | sub check_size { |
2227 | sub check_size { |
2095 | my ($self) = @_; |
2228 | my ($self) = @_; |
2096 | |
2229 | |
2097 | $self->configure (0, 0, $::WITH, $::HEIGHT); |
2230 | $self->configure (0, 0, $::WIDTH, $::HEIGHT); |
2098 | } |
2231 | } |
2099 | |
2232 | |
2100 | sub size_request { |
2233 | sub size_request { |
2101 | ($::WIDTH, $::HEIGHT) |
2234 | ($::WIDTH, $::HEIGHT) |
2102 | } |
2235 | } |
… | |
… | |
2104 | sub configure { |
2237 | sub configure { |
2105 | my ($self, $x, $y, $w, $h) = @_; |
2238 | my ($self, $x, $y, $w, $h) = @_; |
2106 | |
2239 | |
2107 | $self->SUPER::configure ($x, $y, $w, $h); |
2240 | $self->SUPER::configure ($x, $y, $w, $h); |
2108 | |
2241 | |
2109 | $_->configure ($_->{x}, $_->{y}, $_->size_request) |
|
|
2110 | for @{$self->{children}}; |
2242 | for my $child (@{$self->{children}}) { |
|
|
2243 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
|
|
2244 | |
|
|
2245 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
|
|
2246 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
|
|
2247 | $child->configure ($X, $Y, $W,$H); |
|
|
2248 | } |
2111 | } |
2249 | } |
2112 | |
2250 | |
2113 | sub _topleft { |
2251 | sub _topleft { |
2114 | my ($self, $x, $y) = @_; |
2252 | my ($self, $x, $y) = @_; |
2115 | |
2253 | |
… | |
… | |
2162 | ############################################################################# |
2300 | ############################################################################# |
2163 | |
2301 | |
2164 | package CFClient::UI; |
2302 | package CFClient::UI; |
2165 | |
2303 | |
2166 | $ROOT = new CFClient::UI::Root; |
2304 | $ROOT = new CFClient::UI::Root; |
|
|
2305 | $TOOLTIP = new CFClient::UI::Tooltip; |
2167 | |
2306 | |
2168 | 1 |
2307 | 1 |
2169 | |
2308 | |