… | |
… | |
5 | |
5 | |
6 | use Scalar::Util (); |
6 | use Scalar::Util (); |
7 | use List::Util (); |
7 | use List::Util (); |
8 | |
8 | |
9 | use CFClient; |
9 | use CFClient; |
|
|
10 | use CFClient::Texture; |
10 | |
11 | |
11 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | |
13 | |
|
|
14 | our $LAYOUT; |
13 | our $ROOT; |
15 | our $ROOT; |
14 | our $TOOLTIP; |
16 | our $TOOLTIP; |
15 | our $BUTTON_STATE; |
17 | our $BUTTON_STATE; |
16 | |
18 | |
17 | our %WIDGET; # all widgets, weak-referenced |
19 | our %WIDGET; # all widgets, weak-referenced |
|
|
20 | |
|
|
21 | sub get_layout { |
|
|
22 | for (grep { $_->{name} } values %WIDGET) { |
|
|
23 | $LAYOUT->{$_->{name}} = { |
|
|
24 | x => $_->{x} / $::WIDTH, |
|
|
25 | y => $_->{y} / $::HEIGHT, |
|
|
26 | w => $_->{w} / $::WIDTH, |
|
|
27 | h => $_->{h} / $::HEIGHT |
|
|
28 | }; |
|
|
29 | } |
|
|
30 | |
|
|
31 | return $LAYOUT; |
|
|
32 | } |
|
|
33 | |
|
|
34 | sub set_layout { |
|
|
35 | my ($layout) = @_; |
|
|
36 | $LAYOUT = $layout; |
|
|
37 | } |
18 | |
38 | |
19 | sub check_tooltip { |
39 | sub check_tooltip { |
20 | if (!$GRAB) { |
40 | if (!$GRAB) { |
21 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
41 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
22 | if (length $widget->{tooltip}) { |
42 | if (length $widget->{tooltip}) { |
… | |
… | |
155 | for my $widget (values %WIDGET) { |
175 | for my $widget (values %WIDGET) { |
156 | if ($widget->{is_toplevel}) { |
176 | if ($widget->{is_toplevel}) { |
157 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
177 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
158 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
178 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
159 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
179 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
160 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
|
|
161 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
180 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
162 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
181 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
163 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
182 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
164 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
|
|
165 | } |
183 | } |
166 | } |
184 | } |
167 | |
185 | |
168 | reconfigure_widgets; |
186 | reconfigure_widgets; |
169 | } |
187 | } |
… | |
… | |
186 | can_events => 1, |
204 | can_events => 1, |
187 | @_ |
205 | @_ |
188 | }, $class; |
206 | }, $class; |
189 | |
207 | |
190 | for (keys %$self) { |
208 | for (keys %$self) { |
191 | if (/^connect_(.*)$/) { |
209 | if (/^on_(.*)$/) { |
192 | $self->connect ($1 => delete $self->{$_}); |
210 | $self->connect ($1 => delete $self->{$_}); |
193 | } |
211 | } |
194 | } |
212 | } |
195 | |
213 | |
196 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
214 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
197 | |
215 | |
|
|
216 | if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) { |
|
|
217 | $self->{req_x} = $layout->{x} * $::WIDTH; |
|
|
218 | $self->{req_y} = $layout->{y} * $::HEIGHT; |
|
|
219 | $self->{def_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH; |
|
|
220 | $self->{def_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT; |
|
|
221 | } |
|
|
222 | |
198 | $self |
223 | $self |
|
|
224 | } |
|
|
225 | |
|
|
226 | sub toggle_visibility { |
|
|
227 | my ($self) = @_; |
|
|
228 | |
|
|
229 | if ($self->{visible}) { |
|
|
230 | $self->hide; |
|
|
231 | } else { |
|
|
232 | $self->show; |
|
|
233 | } |
199 | } |
234 | } |
200 | |
235 | |
201 | sub destroy { |
236 | sub destroy { |
202 | my ($self) = @_; |
237 | my ($self) = @_; |
203 | |
238 | |
… | |
… | |
210 | return if $self->{parent}; |
245 | return if $self->{parent}; |
211 | |
246 | |
212 | $CFClient::UI::ROOT->add ($self); |
247 | $CFClient::UI::ROOT->add ($self); |
213 | } |
248 | } |
214 | |
249 | |
215 | sub show_centered { |
250 | sub center { |
216 | my ($self) = @_; |
251 | my ($self) = @_; |
217 | return if $self->{parent}; |
|
|
218 | |
|
|
219 | $self->show; |
|
|
220 | |
252 | |
221 | $CFClient::UI::ROOT->on_post_alloc ( |
253 | $CFClient::UI::ROOT->on_post_alloc ( |
222 | "centered $self" => sub { |
254 | "center_$self" => sub { |
223 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
255 | $self->move (($::WIDTH - $self->{w}) * 0.5, ($::HEIGHT - $self->{h}) * 0.5); |
224 | }, |
256 | }, |
225 | ); |
257 | ); |
|
|
258 | |
|
|
259 | $self->update; |
|
|
260 | } |
|
|
261 | |
|
|
262 | sub set_visible { |
|
|
263 | my ($self) = @_; |
|
|
264 | |
|
|
265 | return if $self->{visible}; |
|
|
266 | |
|
|
267 | $self->{root} = $self->{parent}{root}; |
|
|
268 | $self->{visible} = $self->{parent}{visible} + 1; |
|
|
269 | |
|
|
270 | $self->emit (visibility_change => 1) |
226 | } |
271 | } |
227 | |
272 | |
228 | sub set_invisible { |
273 | sub set_invisible { |
229 | my ($self) = @_; |
274 | my ($self) = @_; |
230 | |
275 | |
|
|
276 | return unless $self->{visible}; |
|
|
277 | |
231 | # broken show/hide model |
278 | # broken show/hide model |
232 | |
279 | |
|
|
280 | delete $self->{root}; |
233 | delete $self->{visible}; |
281 | delete $self->{visible}; |
234 | |
282 | |
235 | undef $GRAB if $GRAB == $self; |
283 | undef $GRAB if $GRAB == $self; |
236 | undef $HOVER if $HOVER == $self; |
284 | undef $HOVER if $HOVER == $self; |
237 | |
285 | |
|
|
286 | CFClient::UI::check_tooltip |
|
|
287 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
|
|
288 | |
238 | $self->focus_out; |
289 | $self->focus_out; |
|
|
290 | |
|
|
291 | $self->emit (visibility_change => 0); |
239 | } |
292 | } |
240 | |
293 | |
241 | sub hide { |
294 | sub hide { |
242 | my ($self) = @_; |
295 | my ($self) = @_; |
243 | |
296 | |
… | |
… | |
258 | } |
311 | } |
259 | |
312 | |
260 | sub set_size { |
313 | sub set_size { |
261 | my ($self, $w, $h) = @_; |
314 | my ($self, $w, $h) = @_; |
262 | |
315 | |
263 | $self->{user_w} = $w; |
316 | $self->{def_w} = $w; |
264 | $self->{user_h} = $h; |
317 | $self->{def_h} = $h; |
265 | |
318 | |
266 | $self->check_size; |
319 | $self->check_size; |
267 | } |
320 | } |
268 | |
321 | |
269 | sub size_request { |
322 | sub size_request { |
… | |
… | |
318 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
371 | delete $self->{max_h}; $self->{max_h} = $h if $h; |
319 | } |
372 | } |
320 | |
373 | |
321 | sub set_tooltip { |
374 | sub set_tooltip { |
322 | my ($self, $tooltip) = @_; |
375 | my ($self, $tooltip) = @_; |
|
|
376 | |
|
|
377 | $tooltip =~ s/^\s+//; |
|
|
378 | $tooltip =~ s/\s+$//; |
|
|
379 | |
|
|
380 | return if $self->{tooltip} eq $tooltip; |
323 | |
381 | |
324 | $self->{tooltip} = $tooltip; |
382 | $self->{tooltip} = $tooltip; |
325 | |
383 | |
326 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
384 | if ($CFClient::UI::TOOLTIP->{owner} == $self) { |
327 | delete $CFClient::UI::TOOLTIP->{owner}; |
385 | delete $CFClient::UI::TOOLTIP->{owner}; |
… | |
… | |
417 | if ($ENV{PCLIENT_DEBUG}) { |
475 | if ($ENV{PCLIENT_DEBUG}) { |
418 | glPushMatrix; |
476 | glPushMatrix; |
419 | glColor 1, 1, 0, 1; |
477 | glColor 1, 1, 0, 1; |
420 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
478 | glTranslate $self->{x} + 0.375, $self->{y} + 0.375; |
421 | glBegin GL_LINE_LOOP; |
479 | glBegin GL_LINE_LOOP; |
422 | glVertex 0 , 0; |
480 | glVertex 0 , 0; |
423 | glVertex $self->{w}, 0; |
481 | glVertex $self->{w} - 1, 0; |
424 | glVertex $self->{w}, $self->{h}; |
482 | glVertex $self->{w} - 1, $self->{h} - 1; |
425 | glVertex 0 , $self->{h}; |
483 | glVertex 0 , $self->{h} - 1; |
426 | glEnd; |
484 | glEnd; |
427 | glPopMatrix; |
485 | glPopMatrix; |
428 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
486 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
429 | } |
487 | } |
430 | } |
488 | } |
… | |
… | |
450 | sub set_parent { |
508 | sub set_parent { |
451 | my ($self, $parent) = @_; |
509 | my ($self, $parent) = @_; |
452 | |
510 | |
453 | Scalar::Util::weaken ($self->{parent} = $parent); |
511 | Scalar::Util::weaken ($self->{parent} = $parent); |
454 | |
512 | |
455 | # TODO: req_w _does_change after ->reconfigure |
513 | $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible}; |
|
|
514 | |
456 | $self->check_size |
515 | $self->check_size; |
457 | unless exists $self->{req_w}; |
|
|
458 | |
|
|
459 | $self->show; |
|
|
460 | } |
516 | } |
461 | |
517 | |
462 | sub check_size { |
518 | sub check_size { |
463 | my ($self, $forced) = @_; |
519 | my ($self, $forced) = @_; |
464 | |
520 | |
… | |
… | |
488 | sub emit { |
544 | sub emit { |
489 | my ($self, $signal, @args) = @_; |
545 | my ($self, $signal, @args) = @_; |
490 | |
546 | |
491 | $self->_emit ($signal, @args) |
547 | $self->_emit ($signal, @args) |
492 | || $self->$signal (@args); |
548 | || $self->$signal (@args); |
|
|
549 | } |
|
|
550 | |
|
|
551 | sub visibility_change { |
|
|
552 | #my ($self, $visible) = @_; |
493 | } |
553 | } |
494 | |
554 | |
495 | sub DESTROY { |
555 | sub DESTROY { |
496 | my ($self) = @_; |
556 | my ($self) = @_; |
497 | |
557 | |
… | |
… | |
610 | delete $child->{parent}; |
670 | delete $child->{parent}; |
611 | $child->hide; |
671 | $child->hide; |
612 | |
672 | |
613 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
673 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
614 | |
674 | |
615 | $self->check_size; |
675 | $self->check_size (1); |
616 | $self->update; |
676 | $self->update; |
617 | } |
677 | } |
618 | |
678 | |
619 | sub clear { |
679 | sub clear { |
620 | my ($self) = @_; |
680 | my ($self) = @_; |
… | |
… | |
760 | |
820 | |
761 | package CFClient::UI::ViewPort; |
821 | package CFClient::UI::ViewPort; |
762 | |
822 | |
763 | our @ISA = CFClient::UI::Window::; |
823 | our @ISA = CFClient::UI::Window::; |
764 | |
824 | |
|
|
825 | sub new { |
|
|
826 | my $class = shift; |
|
|
827 | |
|
|
828 | $class->SUPER::new ( |
|
|
829 | scroll_x => 0, |
|
|
830 | scroll_y => 1, |
|
|
831 | @_, |
|
|
832 | ) |
|
|
833 | } |
|
|
834 | |
765 | sub size_request { |
835 | sub size_request { |
766 | my ($self) = @_; |
836 | my ($self) = @_; |
767 | |
837 | |
768 | @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
838 | my ($w, $h) = @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; |
769 | |
839 | |
770 | @$self{qw(child_w child_h)} |
840 | $w = 10 if $self->{scroll_x}; |
|
|
841 | $h = 10 if $self->{scroll_y}; |
|
|
842 | |
|
|
843 | ($w, $h) |
771 | } |
844 | } |
772 | |
845 | |
773 | sub size_allocate { |
846 | sub size_allocate { |
774 | my ($self, $w, $h) = @_; |
847 | my ($self, $w, $h) = @_; |
775 | |
848 | |
776 | my ($cw, $ch) = @$self{qw(child_w child_h)}; |
849 | $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; |
777 | # $w = $self->{w}; |
850 | $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; |
|
|
851 | |
778 | $self->child->configure (0, 0, $cw, $ch); |
852 | $self->child->configure (0, 0, $w, $h); |
779 | $self->update; |
853 | $self->update; |
780 | } |
854 | } |
781 | |
855 | |
782 | sub set_offset { |
856 | sub set_offset { |
783 | my ($self, $x, $y) = @_; |
857 | my ($self, $x, $y) = @_; |
… | |
… | |
834 | my $class = shift; |
908 | my $class = shift; |
835 | |
909 | |
836 | my $self; |
910 | my $self; |
837 | |
911 | |
838 | my $slider = new CFClient::UI::Slider |
912 | my $slider = new CFClient::UI::Slider |
839 | vertical => 1, |
913 | vertical => 1, |
840 | range => [0, 0, 1, 0.01], # HACK fix |
914 | range => [0, 0, 1, 0.01], # HACK fix |
841 | connect_changed => sub { |
915 | on_changed => sub { |
842 | $self->{vp}->set_offset (0, $_[1]); |
916 | $self->{vp}->set_offset (0, $_[1]); |
843 | }, |
917 | }, |
844 | ; |
918 | ; |
845 | |
919 | |
846 | $self = $class->SUPER::new ( |
920 | $self = $class->SUPER::new ( |
… | |
… | |
852 | $self->{vp}->add ($self->{scrolled}); |
926 | $self->{vp}->add ($self->{scrolled}); |
853 | $self->add ($self->{vp}); |
927 | $self->add ($self->{vp}); |
854 | $self->add ($self->{slider}); |
928 | $self->add ($self->{slider}); |
855 | |
929 | |
856 | $self |
930 | $self |
|
|
931 | } |
|
|
932 | |
|
|
933 | sub update { |
|
|
934 | my ($self) = @_; |
|
|
935 | |
|
|
936 | $self->SUPER::update; |
|
|
937 | |
|
|
938 | # todo: overwrite size_allocate of child |
|
|
939 | my $child = $self->{vp}->child; |
|
|
940 | $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); |
857 | } |
941 | } |
858 | |
942 | |
859 | sub size_allocate { |
943 | sub size_allocate { |
860 | my ($self, $w, $h) = @_; |
944 | my ($self, $w, $h) = @_; |
861 | |
945 | |
… | |
… | |
920 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
1004 | map { new_from_file CFClient::Texture CFClient::find_rcfile $_, mipmap => 1 } |
921 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1005 | qw(d1_bg.png d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
922 | |
1006 | |
923 | sub new { |
1007 | sub new { |
924 | my $class = shift; |
1008 | my $class = shift; |
925 | |
|
|
926 | # TODO: user_x, user_y, overwrite moveto? |
|
|
927 | |
1009 | |
928 | my $self = $class->SUPER::new ( |
1010 | my $self = $class->SUPER::new ( |
929 | bg => [1, 1, 1, 1], |
1011 | bg => [1, 1, 1, 1], |
930 | border_bg => [1, 1, 1, 1], |
1012 | border_bg => [1, 1, 1, 1], |
931 | border => 0.6, |
1013 | border => 0.6, |
… | |
… | |
991 | my ($ev, $x, $y) = @_; |
1073 | my ($ev, $x, $y) = @_; |
992 | |
1074 | |
993 | my $dx = $ev->{x} - $ox; |
1075 | my $dx = $ev->{x} - $ox; |
994 | my $dy = $ev->{y} - $oy; |
1076 | my $dy = $ev->{y} - $oy; |
995 | |
1077 | |
|
|
1078 | $self->{user_x} = $wx + $dx * $mx; |
|
|
1079 | $self->{user_y} = $wy + $dy * $my; |
996 | $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); |
1080 | $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); |
997 | $self->{user_h} = $bh + $dy * ($my ? -1 : 1); |
1081 | $self->{def_h} = $bh + $dy * ($my ? -1 : 1); |
998 | $self->move ($wx + $dx * $mx, $wy + $dy * $my); |
1082 | $self->move ($self->{user_x}, $self->{user_y}); |
999 | $self->check_size; |
1083 | $self->check_size; |
1000 | }; |
1084 | }; |
1001 | |
1085 | |
1002 | } elsif ($lr ^ $td) { |
1086 | } elsif ($lr ^ $td) { |
1003 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1087 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
… | |
… | |
1006 | $self->{motion} = sub { |
1090 | $self->{motion} = sub { |
1007 | my ($ev, $x, $y) = @_; |
1091 | my ($ev, $x, $y) = @_; |
1008 | |
1092 | |
1009 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1093 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1010 | |
1094 | |
1011 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
1095 | $self->{user_x} = $bx + $x - $ox; |
|
|
1096 | $self->{user_y} = $by + $y - $oy; |
|
|
1097 | |
|
|
1098 | $self->move ($self->{user_x}, $self->{user_y}); |
1012 | $self->update; |
1099 | $self->update; |
1013 | }; |
1100 | }; |
1014 | } |
1101 | } |
1015 | } |
1102 | } |
1016 | |
1103 | |
… | |
… | |
1078 | sub new { |
1165 | sub new { |
1079 | my $class = shift; |
1166 | my $class = shift; |
1080 | |
1167 | |
1081 | $class->SUPER::new ( |
1168 | $class->SUPER::new ( |
1082 | col_expand => [], |
1169 | col_expand => [], |
1083 | @_ |
1170 | @_, |
1084 | ) |
1171 | ) |
|
|
1172 | } |
|
|
1173 | |
|
|
1174 | sub children { |
|
|
1175 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
1085 | } |
1176 | } |
1086 | |
1177 | |
1087 | sub add { |
1178 | sub add { |
1088 | my ($self, $x, $y, $child) = @_; |
1179 | my ($self, $x, $y, $child) = @_; |
1089 | |
1180 | |
1090 | $child->set_parent ($self); |
1181 | $child->set_parent ($self); |
1091 | $self->{children}[$y][$x] = $child; |
1182 | $self->{children}[$y][$x] = $child; |
1092 | |
1183 | |
1093 | $child->check_size; |
1184 | $self->check_size (1); |
1094 | } |
1185 | } |
1095 | |
1186 | |
1096 | sub children { |
|
|
1097 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1098 | } |
|
|
1099 | |
|
|
1100 | # TODO: move to container class maybe? send childs a signal on removal? |
1187 | # TODO: move to container class maybe? send children a signal on removal? |
1101 | sub clear { |
1188 | sub clear { |
1102 | my ($self) = @_; |
1189 | my ($self) = @_; |
1103 | |
1190 | |
1104 | my @children = $self->children; |
1191 | my @children = $self->children; |
1105 | delete $self->{children}; |
1192 | delete $self->{children}; |
… | |
… | |
1107 | for (@children) { |
1194 | for (@children) { |
1108 | delete $_->{parent}; |
1195 | delete $_->{parent}; |
1109 | $_->hide; |
1196 | $_->hide; |
1110 | } |
1197 | } |
1111 | |
1198 | |
|
|
1199 | $self->check_size (1); |
1112 | $self->update; |
1200 | $self->update; |
1113 | } |
1201 | } |
1114 | |
1202 | |
1115 | sub get_wh { |
1203 | sub get_wh { |
1116 | my ($self) = @_; |
1204 | my ($self) = @_; |
… | |
… | |
1148 | sub size_allocate { |
1236 | sub size_allocate { |
1149 | my ($self, $w, $h) = @_; |
1237 | my ($self, $w, $h) = @_; |
1150 | |
1238 | |
1151 | my ($ws, $hs) = $self->get_wh; |
1239 | my ($ws, $hs) = $self->get_wh; |
1152 | |
1240 | |
1153 | my $req_w = sum @$ws; |
1241 | my $req_w = (sum @$ws) || 1; |
1154 | my $req_h = sum @$hs; |
1242 | my $req_h = (sum @$hs) || 1; |
1155 | |
1243 | |
1156 | # TODO: nicer code && do row_expand |
1244 | # TODO: nicer code && do row_expand |
1157 | my @col_expand = @{$self->{col_expand}}; |
1245 | my @col_expand = @{$self->{col_expand}}; |
1158 | @col_expand = (1) x @$ws unless @col_expand; |
1246 | @col_expand = (1) x @$ws unless @col_expand; |
1159 | my $col_expand = (sum @col_expand) || 1; |
1247 | my $col_expand = (sum @col_expand) || 1; |
… | |
… | |
1213 | } |
1301 | } |
1214 | } |
1302 | } |
1215 | |
1303 | |
1216 | ############################################################################# |
1304 | ############################################################################# |
1217 | |
1305 | |
1218 | package CFClient::UI::HBox; |
1306 | package CFClient::UI::Box; |
1219 | |
|
|
1220 | # TODO: wrap into common Box base class |
|
|
1221 | |
1307 | |
1222 | our @ISA = CFClient::UI::Container::; |
1308 | our @ISA = CFClient::UI::Container::; |
1223 | |
1309 | |
1224 | sub size_request { |
1310 | sub size_request { |
1225 | my ($self) = @_; |
1311 | my ($self) = @_; |
1226 | |
1312 | |
1227 | my @alloc = map [$_->size_request], @{$self->{children}}; |
1313 | $self->{vertical} |
1228 | |
1314 | ? ( |
1229 | ( |
1315 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1230 | (List::Util::sum map $_->[0], @alloc), |
1316 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1231 | (List::Util::max map $_->[1], @alloc), |
1317 | ) |
1232 | ) |
1318 | : ( |
|
|
1319 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
|
|
1320 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
|
|
1321 | ) |
1233 | } |
1322 | } |
1234 | |
1323 | |
1235 | sub size_allocate { |
1324 | sub size_allocate { |
1236 | my ($self, $w, $h) = @_; |
1325 | my ($self, $w, $h) = @_; |
1237 | |
1326 | |
1238 | ($h, $w) = ($w, $h); |
1327 | my $space = $self->{vertical} ? $h : $w; |
1239 | |
|
|
1240 | my $children = $self->{children}; |
1328 | my $children = $self->{children}; |
1241 | |
1329 | |
1242 | my @h = map $_->{req_w}, @$children; |
1330 | my @req; |
1243 | |
1331 | |
1244 | my $req_h = List::Util::sum @h; |
1332 | if ($self->{homogeneous}) { |
1245 | |
1333 | @req = ($space / (@$children || 1)) x @$children; |
1246 | if ($req_h > $h) { |
|
|
1247 | # ah well, not enough space |
|
|
1248 | $_ *= $h / $req_h for @h; |
|
|
1249 | } else { |
1334 | } else { |
|
|
1335 | @req = map $_->{$self->{vertical} ? "req_h" : "req_w"}, @$children; |
|
|
1336 | my $req = List::Util::sum @req; |
|
|
1337 | |
|
|
1338 | if ($req > $space) { |
|
|
1339 | # ah well, not enough space |
|
|
1340 | $_ *= $space / $req for @req; |
|
|
1341 | } else { |
1250 | my $exp = List::Util::sum map $_->{expand}, @$children; |
1342 | my $expand = (List::Util::sum map $_->{expand}, @$children) || 1; |
1251 | $exp ||= 1; |
|
|
1252 | |
1343 | |
|
|
1344 | $space = ($space - $req) / $expand; # remaining space to give away |
|
|
1345 | |
|
|
1346 | $req[$_] += $space * $children->[$_]{expand} |
1253 | for (0 .. $#$children) { |
1347 | for 0 .. $#$children; |
1254 | my $child = $children->[$_]; |
|
|
1255 | |
|
|
1256 | my $alloc_h = $h[$_]; |
|
|
1257 | $alloc_h += ($h - $req_h) * $child->{expand} / $exp; |
|
|
1258 | $h[$_] = $alloc_h; |
|
|
1259 | } |
1348 | } |
1260 | } |
1349 | } |
1261 | |
1350 | |
1262 | CFClient::UI::harmonize \@h; |
1351 | CFClient::UI::harmonize \@req; |
1263 | |
1352 | |
1264 | my $y = 0; |
1353 | my $pos = 0; |
1265 | for (0 .. $#$children) { |
1354 | for (0 .. $#$children) { |
1266 | my $child = $children->[$_]; |
|
|
1267 | my $h = $h[$_]; |
1355 | my $alloc = $req[$_]; |
1268 | $child->configure ($y, 0, $h, $w); |
1356 | $children->[$_]->configure ($self->{vertical} ? (0, $pos, $w, $alloc) : ($pos, 0, $alloc, $h)); |
1269 | |
1357 | |
1270 | $y += $h; |
1358 | $pos += $alloc; |
1271 | } |
1359 | } |
1272 | |
1360 | |
1273 | 1 |
1361 | 1 |
1274 | } |
1362 | } |
1275 | |
1363 | |
1276 | ############################################################################# |
1364 | ############################################################################# |
1277 | |
1365 | |
|
|
1366 | package CFClient::UI::HBox; |
|
|
1367 | |
|
|
1368 | our @ISA = CFClient::UI::Box::; |
|
|
1369 | |
|
|
1370 | sub new { |
|
|
1371 | my $class = shift; |
|
|
1372 | |
|
|
1373 | $class->SUPER::new ( |
|
|
1374 | vertical => 0, |
|
|
1375 | @_, |
|
|
1376 | ) |
|
|
1377 | } |
|
|
1378 | |
|
|
1379 | ############################################################################# |
|
|
1380 | |
1278 | package CFClient::UI::VBox; |
1381 | package CFClient::UI::VBox; |
1279 | |
1382 | |
1280 | # TODO: wrap into common Box base class |
|
|
1281 | |
|
|
1282 | our @ISA = CFClient::UI::Container::; |
1383 | our @ISA = CFClient::UI::Box::; |
1283 | |
1384 | |
1284 | sub size_request { |
1385 | sub new { |
1285 | my ($self) = @_; |
1386 | my $class = shift; |
1286 | |
1387 | |
1287 | my @alloc = map [$_->size_request], @{$self->{children}}; |
1388 | $class->SUPER::new ( |
1288 | |
1389 | vertical => 1, |
1289 | ( |
1390 | @_, |
1290 | (List::Util::max map $_->[0], @alloc), |
|
|
1291 | (List::Util::sum map $_->[1], @alloc), |
|
|
1292 | ) |
1391 | ) |
1293 | } |
|
|
1294 | |
|
|
1295 | sub size_allocate { |
|
|
1296 | my ($self, $w, $h) = @_; |
|
|
1297 | |
|
|
1298 | Carp::confess "negative size" if $w < 0 || $h < 0;#d# |
|
|
1299 | |
|
|
1300 | my $children = $self->{children}; |
|
|
1301 | |
|
|
1302 | my @h = map $_->{req_h}, @$children; |
|
|
1303 | |
|
|
1304 | my $req_h = List::Util::sum @h; |
|
|
1305 | |
|
|
1306 | if ($req_h > $h) { |
|
|
1307 | # ah well, not enough space |
|
|
1308 | $_ *= $h / $req_h for @h; |
|
|
1309 | } else { |
|
|
1310 | my $exp = List::Util::sum map $_->{expand}, @$children; |
|
|
1311 | $exp ||= 1; |
|
|
1312 | |
|
|
1313 | for (0 .. $#$children) { |
|
|
1314 | my $child = $children->[$_]; |
|
|
1315 | |
|
|
1316 | $h[$_] += ($h - $req_h) * $child->{expand} / $exp; |
|
|
1317 | } |
|
|
1318 | } |
|
|
1319 | |
|
|
1320 | CFClient::UI::harmonize \@h; |
|
|
1321 | |
|
|
1322 | my $y = 0; |
|
|
1323 | for (0 .. $#$children) { |
|
|
1324 | my $child = $children->[$_]; |
|
|
1325 | my $h = $h[$_]; |
|
|
1326 | $child->configure (0, $y, $w, $h); |
|
|
1327 | |
|
|
1328 | $y += $h; |
|
|
1329 | } |
|
|
1330 | |
|
|
1331 | 1 |
|
|
1332 | } |
1392 | } |
1333 | |
1393 | |
1334 | ############################################################################# |
1394 | ############################################################################# |
1335 | |
1395 | |
1336 | package CFClient::UI::Label; |
1396 | package CFClient::UI::Label; |
… | |
… | |
1562 | my ($self) = @_; |
1622 | my ($self) = @_; |
1563 | |
1623 | |
1564 | my ($w, $h) = $self->SUPER::size_request; |
1624 | my ($w, $h) = $self->SUPER::size_request; |
1565 | |
1625 | |
1566 | ($w + 1, $h) # add 1 for cursor |
1626 | ($w + 1, $h) # add 1 for cursor |
1567 | } |
|
|
1568 | |
|
|
1569 | sub size_allocate { |
|
|
1570 | my ($self, $w, $h) = @_; |
|
|
1571 | |
|
|
1572 | $self->_set_text (delete $self->{text});#d# don't check for == inside _set_text |
|
|
1573 | } |
1627 | } |
1574 | |
1628 | |
1575 | sub key_down { |
1629 | sub key_down { |
1576 | my ($self, $ev) = @_; |
1630 | my ($self, $ev) = @_; |
1577 | |
1631 | |
… | |
… | |
2119 | } |
2173 | } |
2120 | |
2174 | |
2121 | sub set_range { |
2175 | sub set_range { |
2122 | my ($self, $range) = @_; |
2176 | my ($self, $range) = @_; |
2123 | |
2177 | |
2124 | $self->{range} = $range; |
2178 | ($range, $self->{range}) = ($self->{range}, $range); |
2125 | |
2179 | |
2126 | $self->update; |
2180 | $self->update |
|
|
2181 | if "@$range" ne "@{$self->{range}}"; |
2127 | } |
2182 | } |
2128 | |
2183 | |
2129 | sub set_value { |
2184 | sub set_value { |
2130 | my ($self, $value) = @_; |
2185 | my ($self, $value) = @_; |
2131 | |
2186 | |
… | |
… | |
2514 | |
2569 | |
2515 | sub new { |
2570 | sub new { |
2516 | my $class = shift; |
2571 | my $class = shift; |
2517 | |
2572 | |
2518 | my $self = $class->SUPER::new ( |
2573 | my $self = $class->SUPER::new ( |
2519 | state => 0, |
2574 | state => 0, |
2520 | connect_activate => \&toggle_flopper, |
2575 | on_activate => \&toggle_flopper, |
2521 | @_ |
2576 | @_ |
2522 | ); |
2577 | ); |
2523 | |
2578 | |
2524 | if ($self->{state}) { |
|
|
2525 | $self->{state} = 0; |
|
|
2526 | $self->toggle_flopper; |
|
|
2527 | } |
|
|
2528 | |
|
|
2529 | $self |
2579 | $self |
2530 | } |
2580 | } |
2531 | |
2581 | |
2532 | sub toggle_flopper { |
2582 | sub toggle_flopper { |
2533 | my ($self) = @_; |
2583 | my ($self) = @_; |
2534 | |
2584 | |
2535 | # TODO: use animation |
2585 | $self->{other}->toggle_visibility; |
2536 | if ($self->{state} = !$self->{state}) { |
|
|
2537 | $CFClient::UI::ROOT->add ($self->{other}); |
|
|
2538 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
|
|
2539 | $self->_emit ("open"); |
|
|
2540 | } else { |
|
|
2541 | $CFClient::UI::ROOT->remove ($self->{other}); |
|
|
2542 | $self->_emit ("close"); |
|
|
2543 | } |
|
|
2544 | |
|
|
2545 | $self->_emit (changed => $self->{state}); |
|
|
2546 | } |
2586 | } |
2547 | |
2587 | |
2548 | ############################################################################# |
2588 | ############################################################################# |
2549 | |
2589 | |
2550 | package CFClient::UI::Tooltip; |
2590 | package CFClient::UI::Tooltip; |
… | |
… | |
2626 | |
2666 | |
2627 | sub new { |
2667 | sub new { |
2628 | my $class = shift; |
2668 | my $class = shift; |
2629 | |
2669 | |
2630 | my $self = $class->SUPER::new ( |
2670 | my $self = $class->SUPER::new ( |
2631 | aspect => 1, |
2671 | aspect => 1, |
|
|
2672 | can_events => 0, |
2632 | @_, |
2673 | @_, |
2633 | ); |
2674 | ); |
2634 | |
2675 | |
2635 | if ($self->{anim} && $self->{animspeed}) { |
2676 | if ($self->{anim} && $self->{animspeed}) { |
2636 | Scalar::Util::weaken (my $widget = $self); |
2677 | Scalar::Util::weaken (my $widget = $self); |
… | |
… | |
2695 | $self->SUPER::DESTROY; |
2736 | $self->SUPER::DESTROY; |
2696 | } |
2737 | } |
2697 | |
2738 | |
2698 | ############################################################################# |
2739 | ############################################################################# |
2699 | |
2740 | |
2700 | package CFClient::UI::InventoryItem; |
2741 | package CFClient::UI::Inventory; |
2701 | |
2742 | |
2702 | our @ISA = CFClient::UI::HBox::; |
2743 | our @ISA = CFClient::UI::ScrolledWindow::; |
2703 | |
|
|
2704 | sub _item_to_desc { |
|
|
2705 | my ($item) = @_; |
|
|
2706 | |
|
|
2707 | my $desc = |
|
|
2708 | $item->{nrof} < 2 |
|
|
2709 | ? $item->{name} |
|
|
2710 | : "$item->{nrof} × $item->{name_pl}"; |
|
|
2711 | |
|
|
2712 | $item->{flags} & Crossfire::Protocol::F_OPEN |
|
|
2713 | and $desc .= " (open)"; |
|
|
2714 | $item->{flags} & Crossfire::Protocol::F_APPLIED |
|
|
2715 | and $desc .= " (applied)"; |
|
|
2716 | $item->{flags} & Crossfire::Protocol::F_UNPAID |
|
|
2717 | and $desc .= " (unpaid)"; |
|
|
2718 | $item->{flags} & Crossfire::Protocol::F_MAGIC |
|
|
2719 | and $desc .= " (magic)"; |
|
|
2720 | $item->{flags} & Crossfire::Protocol::F_CURSED |
|
|
2721 | and $desc .= " (cursed)"; |
|
|
2722 | $item->{flags} & Crossfire::Protocol::F_DAMNED |
|
|
2723 | and $desc .= " (damned)"; |
|
|
2724 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2725 | and $desc .= " *"; |
|
|
2726 | |
|
|
2727 | $desc |
|
|
2728 | } |
|
|
2729 | |
2744 | |
2730 | sub new { |
2745 | sub new { |
2731 | my $class = shift; |
2746 | my $class = shift; |
2732 | |
2747 | |
2733 | my %args = @_; |
|
|
2734 | |
|
|
2735 | my $item = delete $args{item}; |
|
|
2736 | |
|
|
2737 | my $desc = _item_to_desc ($item); |
|
|
2738 | |
|
|
2739 | my $self = $class->SUPER::new ( |
2748 | my $self = $class->SUPER::new ( |
2740 | can_hover => 1, |
|
|
2741 | can_events => 1, |
|
|
2742 | tooltip => ((CFClient::UI::Label::escape $desc) |
|
|
2743 | . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"), |
|
|
2744 | connect_button_down => sub { |
|
|
2745 | my ($self, $ev, $x, $y) = @_; |
|
|
2746 | |
|
|
2747 | # todo: maybe put examine on 1? but should just be a tooltip :( |
|
|
2748 | if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) { |
|
|
2749 | my $targ = $::CONN->{player}{tag}; |
|
|
2750 | |
|
|
2751 | if ($item->{container} == $::CONN->{player}{tag}) { |
|
|
2752 | $targ = $main::OPENCONT; |
|
|
2753 | } |
|
|
2754 | |
|
|
2755 | $::CONN->send ("move $targ $item->{tag} 0"); |
|
|
2756 | } elsif ($ev->{button} == 1) { |
|
|
2757 | $::CONN->send ("examine $item->{tag}"); |
|
|
2758 | } elsif ($ev->{button} == 2) { |
|
|
2759 | $::CONN->send ("apply $item->{tag}"); |
|
|
2760 | } elsif ($ev->{button} == 3) { |
|
|
2761 | my @menu_items = ( |
|
|
2762 | ["examine", sub { $::CONN->send ("examine $item->{tag}") }], |
|
|
2763 | ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }], |
|
|
2764 | ["apply", sub { $::CONN->send ("apply $item->{tag}") }], |
|
|
2765 | ( |
|
|
2766 | $item->{flags} & Crossfire::Protocol::F_LOCKED |
|
|
2767 | ? ( |
|
|
2768 | ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }], |
|
|
2769 | ) |
|
|
2770 | : ( |
|
|
2771 | ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }], |
|
|
2772 | ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }], |
|
|
2773 | ) |
|
|
2774 | ), |
|
|
2775 | ); |
|
|
2776 | |
|
|
2777 | CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev); |
|
|
2778 | } |
|
|
2779 | |
|
|
2780 | 1 |
|
|
2781 | }, |
|
|
2782 | %args |
|
|
2783 | ); |
|
|
2784 | |
|
|
2785 | |
|
|
2786 | $self->add (new CFClient::UI::Face |
|
|
2787 | can_events => 0, |
|
|
2788 | face => $item->{face}, |
|
|
2789 | anim => $item->{anim}, |
|
|
2790 | animspeed => $item->{animspeed}, |
|
|
2791 | ); |
|
|
2792 | |
|
|
2793 | $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0); |
|
|
2794 | |
|
|
2795 | $self->{item} = $item; |
|
|
2796 | |
|
|
2797 | $self->update_item; |
|
|
2798 | |
|
|
2799 | $self |
|
|
2800 | } |
|
|
2801 | |
|
|
2802 | sub update_item { |
|
|
2803 | my ($self) = @_; |
|
|
2804 | |
|
|
2805 | my $desc = _item_to_desc ($self->{item}); |
|
|
2806 | |
|
|
2807 | $self->{name_lbl}->set_text ($desc); |
|
|
2808 | } |
|
|
2809 | |
|
|
2810 | ############################################################################# |
|
|
2811 | |
|
|
2812 | package CFClient::UI::Inventory; |
|
|
2813 | |
|
|
2814 | our @ISA = CFClient::UI::ScrolledWindow::; |
|
|
2815 | |
|
|
2816 | sub new { |
|
|
2817 | my $class = shift; |
|
|
2818 | |
|
|
2819 | my $self = $class->SUPER::new ( |
|
|
2820 | scrolled => (new CFClient::UI::Table), |
2749 | scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]), |
2821 | @_, |
2750 | @_, |
2822 | ); |
2751 | ); |
2823 | |
2752 | |
2824 | $self |
2753 | $self |
2825 | } |
2754 | } |
… | |
… | |
2835 | or ($a->{name} cmp $b->{name}) |
2764 | or ($a->{name} cmp $b->{name}) |
2836 | } @$items; |
2765 | } @$items; |
2837 | |
2766 | |
2838 | $self->{real_items} = \@items; |
2767 | $self->{real_items} = \@items; |
2839 | |
2768 | |
|
|
2769 | my $row = 0; |
2840 | for my $item (@items) { |
2770 | for my $item (@items) { |
2841 | $item->{item} = $item; |
2771 | CFClient::Item::update_widgets $item; |
2842 | $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item; |
|
|
2843 | $item->update_item (); |
|
|
2844 | } |
|
|
2845 | |
2772 | |
2846 | my $i = 0; |
2773 | $self->{scrolled}->add (0, $row, $item->{face_widget}); |
2847 | for (@items) { |
2774 | $self->{scrolled}->add (1, $row, $item->{desc_widget}); |
2848 | $self->{scrolled}->add (0, $i, $_); |
2775 | $self->{scrolled}->add (2, $row, $item->{weight_widget}); |
2849 | my $nrof = $_->{item}->{nrof} || 1; |
|
|
2850 | $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000); |
|
|
2851 | } |
|
|
2852 | |
2776 | |
2853 | # $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; |
2777 | $row++; |
2854 | } |
2778 | } |
2855 | |
|
|
2856 | sub size_request { |
|
|
2857 | my ($self) = @_; |
|
|
2858 | ($self->{req_w}, $self->{req_h}); |
|
|
2859 | } |
2779 | } |
2860 | |
2780 | |
2861 | ############################################################################# |
2781 | ############################################################################# |
2862 | |
2782 | |
2863 | package CFClient::UI::Menu; |
2783 | package CFClient::UI::Menu; |
… | |
… | |
2995 | sub add { |
2915 | sub add { |
2996 | my ($self, $text, %arg) = @_; |
2916 | my ($self, $text, %arg) = @_; |
2997 | |
2917 | |
2998 | $text =~ s/^\s+//; |
2918 | $text =~ s/^\s+//; |
2999 | $text =~ s/\s+$//; |
2919 | $text =~ s/\s+$//; |
|
|
2920 | |
|
|
2921 | return unless $text; |
3000 | |
2922 | |
3001 | my $timeout = time + ((delete $arg{timeout}) || 60); |
2923 | my $timeout = time + ((delete $arg{timeout}) || 60); |
3002 | |
2924 | |
3003 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
2925 | my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; |
3004 | |
2926 | |
… | |
… | |
3048 | |
2970 | |
3049 | sub new { |
2971 | sub new { |
3050 | my $class = shift; |
2972 | my $class = shift; |
3051 | |
2973 | |
3052 | $class->SUPER::new ( |
2974 | $class->SUPER::new ( |
|
|
2975 | visible => 1, |
3053 | @_, |
2976 | @_, |
3054 | ) |
2977 | ) |
3055 | } |
2978 | } |
3056 | |
2979 | |
3057 | sub configure { |
2980 | sub configure { |
… | |
… | |
3084 | if exists $child->{req_x}; |
3007 | if exists $child->{req_x}; |
3085 | |
3008 | |
3086 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3009 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3087 | if exists $child->{req_y}; |
3010 | if exists $child->{req_y}; |
3088 | |
3011 | |
|
|
3012 | delete @$child{qw(req_x req_y)}; |
|
|
3013 | |
3089 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3014 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3090 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3015 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3091 | |
3016 | |
3092 | $child->configure ($X, $Y, $W, $H); |
3017 | $child->configure ($X, $Y, $W, $H); |
3093 | } |
3018 | } |
… | |
… | |
3112 | $::WANT_REFRESH++; |
3037 | $::WANT_REFRESH++; |
3113 | } |
3038 | } |
3114 | |
3039 | |
3115 | sub add { |
3040 | sub add { |
3116 | my ($self, @children) = @_; |
3041 | my ($self, @children) = @_; |
3117 | |
|
|
3118 | for (my @widgets = @children; my $w = pop @widgets; ) { |
|
|
3119 | push @widgets, $w->children; |
|
|
3120 | $w->{root} = $self; |
|
|
3121 | $w->{visible} = 1; |
|
|
3122 | } |
|
|
3123 | |
3042 | |
3124 | for my $child (@children) { |
3043 | for my $child (@children) { |
3125 | $child->{is_toplevel} = 1; |
3044 | $child->{is_toplevel} = 1; |
3126 | |
3045 | |
3127 | # integerise window positions |
3046 | # integerise window positions |
3128 | $child->{x} = int $child->{x}; |
3047 | $child->{x} = int $child->{x}; |
3129 | $child->{y} = int $child->{y}; |
3048 | $child->{y} = int $child->{y}; |
3130 | } |
3049 | } |
3131 | |
3050 | |
3132 | $self->SUPER::add (@children); |
3051 | $self->SUPER::add (@children); |
|
|
3052 | |
|
|
3053 | for (my @widgets = @children; my $w = pop @widgets; ) { |
|
|
3054 | push @widgets, $w->children; |
|
|
3055 | $w->set_visible; |
|
|
3056 | } |
|
|
3057 | |
3133 | } |
3058 | } |
3134 | |
3059 | |
3135 | sub remove { |
3060 | sub remove { |
3136 | my ($self, @children) = @_; |
3061 | my ($self, @children) = @_; |
3137 | |
3062 | |
… | |
… | |
3163 | $_->() |
3088 | $_->() |
3164 | for values %{delete $self->{refresh_hook}}; |
3089 | for values %{delete $self->{refresh_hook}}; |
3165 | } |
3090 | } |
3166 | |
3091 | |
3167 | if ($self->{check_size}) { |
3092 | if ($self->{check_size}) { |
3168 | my @queue = ([], []); |
3093 | my @queue; |
3169 | |
3094 | |
3170 | for (;;) { |
3095 | for (;;) { |
3171 | if ($self->{check_size}) { |
3096 | if ($self->{check_size}) { |
3172 | # heuristic: check containers last |
3097 | #TODO use array-of-depth approach |
3173 | push @{ $queue[ ! ! $_->isa ("CFClient::UI::Container") ] }, $_ |
3098 | |
|
|
3099 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3174 | for values %{delete $self->{check_size}} |
3100 | @queue, values %{delete $self->{check_size}}; |
3175 | } |
3101 | } |
3176 | |
3102 | |
3177 | my $widget = (pop @{ $queue[0] }) || (pop @{ $queue[1] }) || last; |
3103 | my $widget = pop @queue || last; |
3178 | |
3104 | |
|
|
3105 | defined $widget->{visible} or last; # do not resize invisible widgets |
|
|
3106 | |
3179 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
3107 | my ($w, $h) = $widget->{def_w} && $widget->{def_h} |
3180 | ? @$widget{qw(user_w user_h)} |
3108 | ? @$widget{qw(def_w def_h)} |
3181 | : $widget->size_request; |
3109 | : $widget->size_request; |
3182 | |
3110 | |
3183 | if (delete $widget->{force_alloc} |
3111 | if (delete $widget->{force_alloc} |
3184 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
3112 | or $w != $widget->{req_w} or $h != $widget->{req_h}) { |
3185 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |
3113 | Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# |