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.232 by root, Thu May 25 02:23:14 2006 UTC vs.
Revision 1.244 by root, Sat May 27 21:06:09 2006 UTC

5 5
6use Scalar::Util (); 6use Scalar::Util ();
7use List::Util (); 7use List::Util ();
8 8
9use CFClient; 9use CFClient;
10use CFClient::Texture;
10 11
11our ($FOCUS, $HOVER, $GRAB); # various widgets 12our ($FOCUS, $HOVER, $GRAB); # various widgets
12 13
14our $LAYOUT;
13our $ROOT; 15our $ROOT;
14our $TOOLTIP; 16our $TOOLTIP;
15our $BUTTON_STATE; 17our $BUTTON_STATE;
16 18
17our %WIDGET; # all widgets, weak-referenced 19our %WIDGET; # all widgets, weak-referenced
20
21sub 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
34sub set_layout {
35 my ($layout) = @_;
36 $LAYOUT = $layout;
37}
18 38
19sub check_tooltip { 39sub 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}) {
186 can_events => 1, 206 can_events => 1,
187 @_ 207 @_
188 }, $class; 208 }, $class;
189 209
190 for (keys %$self) { 210 for (keys %$self) {
191 if (/^connect_(.*)$/) { 211 if (/^on_(.*)$/) {
192 $self->connect ($1 => delete $self->{$_}); 212 $self->connect ($1 => delete $self->{$_});
193 } 213 }
194 } 214 }
195 215
196 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); 216 Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self);
217
218 if (my $layout = $CFClient::UI::LAYOUT->{$self->{name}}) {
219 $self->{user_x} = $layout->{x} * $::WIDTH;
220 $self->{user_y} = $layout->{y} * $::HEIGHT;
221 $self->{user_w} = ($layout->{w} != 0 ? $layout->{w} : 1) * $::WIDTH;
222 $self->{user_h} = ($layout->{h} != 0 ? $layout->{h} : 1) * $::HEIGHT;
223 }
197 224
198 $self 225 $self
199} 226}
200 227
201sub destroy { 228sub destroy {
226} 253}
227 254
228sub set_invisible { 255sub set_invisible {
229 my ($self) = @_; 256 my ($self) = @_;
230 257
258 return unless $self->{visible};
259
231 # broken show/hide model 260 # broken show/hide model
232 261
262 delete $self->{root};
233 delete $self->{visible}; 263 delete $self->{visible};
234 264
235 undef $GRAB if $GRAB == $self; 265 undef $GRAB if $GRAB == $self;
236 undef $HOVER if $HOVER == $self; 266 undef $HOVER if $HOVER == $self;
237 267
238 CFClient::UI::check_tooltip 268 CFClient::UI::check_tooltip
239 if $CFClient::UI::TOOLTIP->{owner} == $self; 269 if $CFClient::UI::TOOLTIP->{owner} == $self;
240 270
241 $self->focus_out; 271 $self->focus_out;
272
273 $self->emit (visibility_change => 0);
242} 274}
243 275
244sub hide { 276sub hide {
245 my ($self) = @_; 277 my ($self) = @_;
246 278
321 delete $self->{max_h}; $self->{max_h} = $h if $h; 353 delete $self->{max_h}; $self->{max_h} = $h if $h;
322} 354}
323 355
324sub set_tooltip { 356sub set_tooltip {
325 my ($self, $tooltip) = @_; 357 my ($self, $tooltip) = @_;
358
359 $tooltip =~ s/^\s+//;
360 $tooltip =~ s/\s+$//;
361
362 return if $self->{tooltip} eq $tooltip;
326 363
327 $self->{tooltip} = $tooltip; 364 $self->{tooltip} = $tooltip;
328 365
329 if ($CFClient::UI::TOOLTIP->{owner} == $self) { 366 if ($CFClient::UI::TOOLTIP->{owner} == $self) {
330 delete $CFClient::UI::TOOLTIP->{owner}; 367 delete $CFClient::UI::TOOLTIP->{owner};
420 if ($ENV{PCLIENT_DEBUG}) { 457 if ($ENV{PCLIENT_DEBUG}) {
421 glPushMatrix; 458 glPushMatrix;
422 glColor 1, 1, 0, 1; 459 glColor 1, 1, 0, 1;
423 glTranslate $self->{x} + 0.375, $self->{y} + 0.375; 460 glTranslate $self->{x} + 0.375, $self->{y} + 0.375;
424 glBegin GL_LINE_LOOP; 461 glBegin GL_LINE_LOOP;
425 glVertex 0 , 0; 462 glVertex 0 , 0;
426 glVertex $self->{w}, 0; 463 glVertex $self->{w} - 1, 0;
427 glVertex $self->{w}, $self->{h}; 464 glVertex $self->{w} - 1, $self->{h} - 1;
428 glVertex 0 , $self->{h}; 465 glVertex 0 , $self->{h} - 1;
429 glEnd; 466 glEnd;
430 glPopMatrix; 467 glPopMatrix;
431 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; 468 #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw;
432 } 469 }
433} 470}
453sub set_parent { 490sub set_parent {
454 my ($self, $parent) = @_; 491 my ($self, $parent) = @_;
455 492
456 Scalar::Util::weaken ($self->{parent} = $parent); 493 Scalar::Util::weaken ($self->{parent} = $parent);
457 494
495 if ($parent->{visible} || 1) {
496 $self->{root} = $parent->{root};
497 $self->{visible} = $parent->{visible} + 1;
498
499 $self->emit (visibility_change => 1)
500 unless $self->{parent}{visible};
501 }
502
458 # TODO: req_w _does_change after ->reconfigure 503 # TODO: req_w _does_change after ->reconfigure
459 $self->check_size 504 $self->check_size
460 unless exists $self->{req_w}; 505 unless exists $self->{req_w};
461 506
462 $self->show; 507 $self->show;
491sub emit { 536sub emit {
492 my ($self, $signal, @args) = @_; 537 my ($self, $signal, @args) = @_;
493 538
494 $self->_emit ($signal, @args) 539 $self->_emit ($signal, @args)
495 || $self->$signal (@args); 540 || $self->$signal (@args);
541}
542
543sub visibility_change {
544 #my ($self, $visible) = @_;
496} 545}
497 546
498sub DESTROY { 547sub DESTROY {
499 my ($self) = @_; 548 my ($self) = @_;
500 549
613 delete $child->{parent}; 662 delete $child->{parent};
614 $child->hide; 663 $child->hide;
615 664
616 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 665 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
617 666
618 $self->check_size; 667 $self->check_size (1);
619 $self->update; 668 $self->update;
620} 669}
621 670
622sub clear { 671sub clear {
623 my ($self) = @_; 672 my ($self) = @_;
763 812
764package CFClient::UI::ViewPort; 813package CFClient::UI::ViewPort;
765 814
766our @ISA = CFClient::UI::Window::; 815our @ISA = CFClient::UI::Window::;
767 816
817sub new {
818 my $class = shift;
819
820 $class->SUPER::new (
821 scroll_x => 0,
822 scroll_y => 1,
823 @_,
824 )
825}
826
768sub size_request { 827sub size_request {
769 my ($self) = @_; 828 my ($self) = @_;
770 829
771 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)}; 830 @$self{qw(child_w child_h)} = @{$self->child}{qw(req_w req_h)};
772 831
774} 833}
775 834
776sub size_allocate { 835sub size_allocate {
777 my ($self, $w, $h) = @_; 836 my ($self, $w, $h) = @_;
778 837
779 my ($cw, $ch) = @$self{qw(child_w child_h)}; 838 $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w};
780# $w = $self->{w}; 839 $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h};
840
781 $self->child->configure (0, 0, $cw, $ch); 841 $self->child->configure (0, 0, $w, $h);
782 $self->update; 842 $self->update;
783} 843}
784 844
785sub set_offset { 845sub set_offset {
786 my ($self, $x, $y) = @_; 846 my ($self, $x, $y) = @_;
837 my $class = shift; 897 my $class = shift;
838 898
839 my $self; 899 my $self;
840 900
841 my $slider = new CFClient::UI::Slider 901 my $slider = new CFClient::UI::Slider
842 vertical => 1, 902 vertical => 1,
843 range => [0, 0, 1, 0.01], # HACK fix 903 range => [0, 0, 1, 0.01], # HACK fix
844 connect_changed => sub { 904 on_changed => sub {
845 $self->{vp}->set_offset (0, $_[1]); 905 $self->{vp}->set_offset (0, $_[1]);
846 }, 906 },
847 ; 907 ;
848 908
849 $self = $class->SUPER::new ( 909 $self = $class->SUPER::new (
855 $self->{vp}->add ($self->{scrolled}); 915 $self->{vp}->add ($self->{scrolled});
856 $self->add ($self->{vp}); 916 $self->add ($self->{vp});
857 $self->add ($self->{slider}); 917 $self->add ($self->{slider});
858 918
859 $self 919 $self
920}
921
922sub update {
923 my ($self) = @_;
924
925 $self->SUPER::update;
926
927 # todo: overwrite size_allocate of child
928 my $child = $self->{vp}->child;
929 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
860} 930}
861 931
862sub size_allocate { 932sub size_allocate {
863 my ($self, $w, $h) = @_; 933 my ($self, $w, $h) = @_;
864 934
994 my ($ev, $x, $y) = @_; 1064 my ($ev, $x, $y) = @_;
995 1065
996 my $dx = $ev->{x} - $ox; 1066 my $dx = $ev->{x} - $ox;
997 my $dy = $ev->{y} - $oy; 1067 my $dy = $ev->{y} - $oy;
998 1068
1069 $self->{user_x} = $wx + $dx * $mx;
1070 $self->{user_y} = $wy + $dy * $my;
999 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); 1071 $self->{user_w} = $bw + $dx * ($mx ? -1 : 1);
1000 $self->{user_h} = $bh + $dy * ($my ? -1 : 1); 1072 $self->{user_h} = $bh + $dy * ($my ? -1 : 1);
1001 $self->move ($wx + $dx * $mx, $wy + $dy * $my); 1073 $self->move ($self->{user_x}, $self->{user_y});
1002 $self->check_size; 1074 $self->check_size;
1003 }; 1075 };
1004 1076
1005 } elsif ($lr ^ $td) { 1077 } elsif ($lr ^ $td) {
1006 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1078 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1009 $self->{motion} = sub { 1081 $self->{motion} = sub {
1010 my ($ev, $x, $y) = @_; 1082 my ($ev, $x, $y) = @_;
1011 1083
1012 ($x, $y) = ($ev->{x}, $ev->{y}); 1084 ($x, $y) = ($ev->{x}, $ev->{y});
1013 1085
1014 $self->move ($bx + $x - $ox, $by + $y - $oy); 1086 $self->{user_x} = $bx + $x - $ox;
1087 $self->{user_y} = $by + $y - $oy;
1088 $self->move ($self->{user_x}, $self->{user_y});
1015 $self->update; 1089 $self->update;
1016 }; 1090 };
1017 } 1091 }
1018} 1092}
1019 1093
1081sub new { 1155sub new {
1082 my $class = shift; 1156 my $class = shift;
1083 1157
1084 $class->SUPER::new ( 1158 $class->SUPER::new (
1085 col_expand => [], 1159 col_expand => [],
1086 @_ 1160 @_,
1087 ) 1161 )
1162}
1163
1164sub children {
1165 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1088} 1166}
1089 1167
1090sub add { 1168sub add {
1091 my ($self, $x, $y, $child) = @_; 1169 my ($self, $x, $y, $child) = @_;
1092 1170
1093 $child->set_parent ($self); 1171 $child->set_parent ($self);
1094 $self->{children}[$y][$x] = $child; 1172 $self->{children}[$y][$x] = $child;
1095 1173
1096 $child->check_size; 1174 $self->check_size (1);
1097} 1175}
1098 1176
1099sub children {
1100 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1101}
1102
1103# TODO: move to container class maybe? send childs a signal on removal? 1177# TODO: move to container class maybe? send children a signal on removal?
1104sub clear { 1178sub clear {
1105 my ($self) = @_; 1179 my ($self) = @_;
1106 1180
1107 my @children = $self->children; 1181 my @children = $self->children;
1108 delete $self->{children}; 1182 delete $self->{children};
1110 for (@children) { 1184 for (@children) {
1111 delete $_->{parent}; 1185 delete $_->{parent};
1112 $_->hide; 1186 $_->hide;
1113 } 1187 }
1114 1188
1189 $self->check_size (1);
1115 $self->update; 1190 $self->update;
1116} 1191}
1117 1192
1118sub get_wh { 1193sub get_wh {
1119 my ($self) = @_; 1194 my ($self) = @_;
1151sub size_allocate { 1226sub size_allocate {
1152 my ($self, $w, $h) = @_; 1227 my ($self, $w, $h) = @_;
1153 1228
1154 my ($ws, $hs) = $self->get_wh; 1229 my ($ws, $hs) = $self->get_wh;
1155 1230
1156 my $req_w = sum @$ws; 1231 my $req_w = (sum @$ws) || 1;
1157 my $req_h = sum @$hs; 1232 my $req_h = (sum @$hs) || 1;
1158 1233
1159 # TODO: nicer code && do row_expand 1234 # TODO: nicer code && do row_expand
1160 my @col_expand = @{$self->{col_expand}}; 1235 my @col_expand = @{$self->{col_expand}};
1161 @col_expand = (1) x @$ws unless @col_expand; 1236 @col_expand = (1) x @$ws unless @col_expand;
1162 my $col_expand = (sum @col_expand) || 1; 1237 my $col_expand = (sum @col_expand) || 1;
2116} 2191}
2117 2192
2118sub set_range { 2193sub set_range {
2119 my ($self, $range) = @_; 2194 my ($self, $range) = @_;
2120 2195
2121 $self->{range} = $range; 2196 ($range, $self->{range}) = ($self->{range}, $range);
2122 2197
2123 $self->update; 2198 $self->update
2199 if "@$range" ne "@{$self->{range}}";
2124} 2200}
2125 2201
2126sub set_value { 2202sub set_value {
2127 my ($self, $value) = @_; 2203 my ($self, $value) = @_;
2128 2204
2511 2587
2512sub new { 2588sub new {
2513 my $class = shift; 2589 my $class = shift;
2514 2590
2515 my $self = $class->SUPER::new ( 2591 my $self = $class->SUPER::new (
2516 state => 0, 2592 state => 0,
2517 connect_activate => \&toggle_flopper, 2593 on_activate => \&toggle_flopper,
2518 @_ 2594 @_
2519 ); 2595 );
2520 2596
2521 if ($self->{state}) { 2597 if ($self->{state}) {
2522 $self->{state} = 0; 2598 $self->{state} = 0;
2623 2699
2624sub new { 2700sub new {
2625 my $class = shift; 2701 my $class = shift;
2626 2702
2627 my $self = $class->SUPER::new ( 2703 my $self = $class->SUPER::new (
2628 aspect => 1, 2704 aspect => 1,
2705 can_events => 0,
2629 @_, 2706 @_,
2630 ); 2707 );
2631 2708
2632 if ($self->{anim} && $self->{animspeed}) { 2709 if ($self->{anim} && $self->{animspeed}) {
2633 Scalar::Util::weaken (my $widget = $self); 2710 Scalar::Util::weaken (my $widget = $self);
2692 $self->SUPER::DESTROY; 2769 $self->SUPER::DESTROY;
2693} 2770}
2694 2771
2695############################################################################# 2772#############################################################################
2696 2773
2697package CFClient::UI::InventoryItem; 2774package CFClient::UI::Inventory;
2698 2775
2699our @ISA = CFClient::UI::HBox::; 2776our @ISA = CFClient::UI::ScrolledWindow::;
2700
2701sub _item_to_desc {
2702 my ($item) = @_;
2703
2704 my $desc =
2705 $item->{nrof} < 2
2706 ? $item->{name}
2707 : "$item->{nrof} × $item->{name_pl}";
2708
2709 $item->{flags} & Crossfire::Protocol::F_OPEN
2710 and $desc .= " (open)";
2711 $item->{flags} & Crossfire::Protocol::F_APPLIED
2712 and $desc .= " (applied)";
2713 $item->{flags} & Crossfire::Protocol::F_UNPAID
2714 and $desc .= " (unpaid)";
2715 $item->{flags} & Crossfire::Protocol::F_MAGIC
2716 and $desc .= " (magic)";
2717 $item->{flags} & Crossfire::Protocol::F_CURSED
2718 and $desc .= " (cursed)";
2719 $item->{flags} & Crossfire::Protocol::F_DAMNED
2720 and $desc .= " (damned)";
2721 $item->{flags} & Crossfire::Protocol::F_LOCKED
2722 and $desc .= " *";
2723
2724 $desc
2725}
2726 2777
2727sub new { 2778sub new {
2728 my $class = shift; 2779 my $class = shift;
2729 2780
2730 my %args = @_;
2731
2732 my $item = delete $args{item};
2733
2734 my $desc = _item_to_desc ($item);
2735
2736 my $self = $class->SUPER::new ( 2781 my $self = $class->SUPER::new (
2737 can_hover => 1,
2738 can_events => 1,
2739 tooltip => ((CFClient::UI::Label::escape $desc)
2740 . "\n<small>leftclick - examine\nshift+leftclick - move/pickup/drop\nmiddle click - apply\nrightclick - menu</small>"),
2741 connect_button_down => sub {
2742 my ($self, $ev, $x, $y) = @_;
2743
2744 # todo: maybe put examine on 1? but should just be a tooltip :(
2745 if (($ev->{mod} & CFClient::KMOD_SHIFT) && $ev->{button} == 1) {
2746 my $targ = $::CONN->{player}{tag};
2747
2748 if ($item->{container} == $::CONN->{player}{tag}) {
2749 $targ = $main::OPENCONT;
2750 }
2751
2752 $::CONN->send ("move $targ $item->{tag} 0");
2753 } elsif ($ev->{button} == 1) {
2754 $::CONN->send ("examine $item->{tag}");
2755 } elsif ($ev->{button} == 2) {
2756 $::CONN->send ("apply $item->{tag}");
2757 } elsif ($ev->{button} == 3) {
2758 my @menu_items = (
2759 ["examine", sub { $::CONN->send ("examine $item->{tag}") }],
2760 ["mark", sub { $::CONN->send ("mark ". pack "N", $item->{tag}) }],
2761 ["apply", sub { $::CONN->send ("apply $item->{tag}") }],
2762 (
2763 $item->{flags} & Crossfire::Protocol::F_LOCKED
2764 ? (
2765 ["unlock", sub { $::CONN->send ("lock " . pack "CN", 0, $item->{tag}) }],
2766 )
2767 : (
2768 ["lock", sub { $::CONN->send ("lock " . pack "CN", 1, $item->{tag}) }],
2769 ["drop", sub { $::CONN->send ("move $main::OPENCONT $item->{tag} 0") }],
2770 )
2771 ),
2772 );
2773
2774 CFClient::UI::Menu->new (items => \@menu_items)->popup ($ev);
2775 }
2776
2777 1
2778 },
2779 %args
2780 );
2781
2782
2783 $self->add (new CFClient::UI::Face
2784 can_events => 0,
2785 face => $item->{face},
2786 anim => $item->{anim},
2787 animspeed => $item->{animspeed},
2788 );
2789
2790 $self->add ($self->{name_lbl} = new CFClient::UI::Label can_events => 0);
2791
2792 $self->{item} = $item;
2793
2794 $self->update_item;
2795
2796 $self
2797}
2798
2799sub update_item {
2800 my ($self) = @_;
2801
2802 my $desc = _item_to_desc ($self->{item});
2803
2804 $self->{name_lbl}->set_text ($desc);
2805}
2806
2807#############################################################################
2808
2809package CFClient::UI::Inventory;
2810
2811our @ISA = CFClient::UI::ScrolledWindow::;
2812
2813sub new {
2814 my $class = shift;
2815
2816 my $self = $class->SUPER::new (
2817 scrolled => (new CFClient::UI::Table), 2782 scrolled => (new CFClient::UI::Table col_expand => [0, 1, 0]),
2818 @_, 2783 @_,
2819 ); 2784 );
2820 2785
2821 $self 2786 $self
2822} 2787}
2832 or ($a->{name} cmp $b->{name}) 2797 or ($a->{name} cmp $b->{name})
2833 } @$items; 2798 } @$items;
2834 2799
2835 $self->{real_items} = \@items; 2800 $self->{real_items} = \@items;
2836 2801
2802 my $row = 0;
2837 for my $item (@items) { 2803 for my $item (@items) {
2838 $item->{item} = $item; 2804 CFClient::Item::update_widgets $item;
2839 $item = $item->{widget} ||= new CFClient::UI::InventoryItem item => $item;
2840 $item->update_item ();
2841 }
2842 2805
2843 my $i = 0; 2806 $self->{scrolled}->add (0, $row, $item->{face_widget});
2844 for (@items) { 2807 $self->{scrolled}->add (1, $row, $item->{desc_widget});
2845 $self->{scrolled}->add (0, $i, $_); 2808 $self->{scrolled}->add (2, $row, $item->{weight_widget});
2846 my $nrof = $_->{item}->{nrof} || 1;
2847 $self->{scrolled}->add (1, $i++, new CFClient::UI::Label text => ($_->{item}->{weight} * $nrof) / 1000);
2848 }
2849 2809
2850# $range->{range} = [$self->{pos}, 0, $self->{max_pos}, $page]; 2810 $row++;
2811 }
2851} 2812}
2852 2813
2853sub size_request { 2814sub size_request {
2854 my ($self) = @_; 2815 my ($self) = @_;
2855 ($self->{req_w}, $self->{req_h}); 2816 ($self->{req_w}, $self->{req_h});
2992sub add { 2953sub add {
2993 my ($self, $text, %arg) = @_; 2954 my ($self, $text, %arg) = @_;
2994 2955
2995 $text =~ s/^\s+//; 2956 $text =~ s/^\s+//;
2996 $text =~ s/\s+$//; 2957 $text =~ s/\s+$//;
2958
2959 return unless $text;
2997 2960
2998 my $timeout = time + ((delete $arg{timeout}) || 60); 2961 my $timeout = time + ((delete $arg{timeout}) || 60);
2999 2962
3000 my $group = exists $arg{group} ? $arg{group} : ++$self->{id}; 2963 my $group = exists $arg{group} ? $arg{group} : ++$self->{id};
3001 2964
3045 3008
3046sub new { 3009sub new {
3047 my $class = shift; 3010 my $class = shift;
3048 3011
3049 $class->SUPER::new ( 3012 $class->SUPER::new (
3013 visible => 1,
3050 @_, 3014 @_,
3051 ) 3015 )
3052} 3016}
3053 3017
3054sub configure { 3018sub configure {
3081 if exists $child->{req_x}; 3045 if exists $child->{req_x};
3082 3046
3083 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 3047 $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1
3084 if exists $child->{req_y}; 3048 if exists $child->{req_y};
3085 3049
3050 $X = $self->{user_x} if exists $self->{user_x};
3051 $Y = $self->{user_y} if exists $self->{user_y};
3052
3086 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; 3053 $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5;
3087 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; 3054 $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5;
3088 3055
3089 $child->configure ($X, $Y, $W, $H); 3056 $child->configure ($X, $Y, $W, $H);
3090 } 3057 }
3112sub add { 3079sub add {
3113 my ($self, @children) = @_; 3080 my ($self, @children) = @_;
3114 3081
3115 for (my @widgets = @children; my $w = pop @widgets; ) { 3082 for (my @widgets = @children; my $w = pop @widgets; ) {
3116 push @widgets, $w->children; 3083 push @widgets, $w->children;
3117 $w->{root} = $self; 3084 $w->{root} = $self;
3118 $w->{visible} = 1; 3085 $w->{visible} = $self->{visible} + 1;
3119 } 3086 }
3120 3087
3121 for my $child (@children) { 3088 for my $child (@children) {
3122 $child->{is_toplevel} = 1; 3089 $child->{is_toplevel} = 1;
3123 3090
3160 $_->() 3127 $_->()
3161 for values %{delete $self->{refresh_hook}}; 3128 for values %{delete $self->{refresh_hook}};
3162 } 3129 }
3163 3130
3164 if ($self->{check_size}) { 3131 if ($self->{check_size}) {
3165 my @queue = ([], []); 3132 my @queue;
3166 3133
3167 for (;;) { 3134 for (;;) {
3168 if ($self->{check_size}) { 3135 if ($self->{check_size}) {
3169 # heuristic: check containers last 3136 #TODO use array-of-depth approach
3170 push @{ $queue[ ! ! $_->isa ("CFClient::UI::Container") ] }, $_ 3137
3138 @queue = sort { $a->{visible} <=> $b->{visible} }
3171 for values %{delete $self->{check_size}} 3139 @queue, values %{delete $self->{check_size}};
3172 } 3140 }
3173 3141
3174 my $widget = (pop @{ $queue[0] }) || (pop @{ $queue[1] }) || last; 3142 my $widget = pop @queue || last;
3143
3144 defined $widget->{visible} or last; # do not resize invisible widgets
3175 3145
3176 my ($w, $h) = $widget->{user_w} && $widget->{user_h} 3146 my ($w, $h) = $widget->{user_w} && $widget->{user_h}
3177 ? @$widget{qw(user_w user_h)} 3147 ? @$widget{qw(user_w user_h)}
3178 : $widget->size_request; 3148 : $widget->size_request;
3179 3149

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines