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.250 by root, Sun May 28 02:31:03 2006 UTC vs.
Revision 1.252 by root, Sun May 28 23:21:28 2006 UTC

47 my $tip = $widget->{tooltip}; 47 my $tip = $widget->{tooltip};
48 48
49 $tip = $tip->($widget) if CODE:: eq ref $tip; 49 $tip = $tip->($widget) if CODE:: eq ref $tip;
50 50
51 $TOOLTIP->set_tooltip_from ($widget); 51 $TOOLTIP->set_tooltip_from ($widget);
52 $TOOLTIP->show;
53 52
54 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 53 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
55 54
56 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) 55 ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0)
57 if $x + $TOOLTIP->{w} > $::WIDTH; 56 if $x + $TOOLTIP->{w} > $::WIDTH;
58 57
59 $TOOLTIP->move ($x, $y); 58 $TOOLTIP->move ($x, $y);
60 $TOOLTIP->check_size;
61 $TOOLTIP->update; 59 $TOOLTIP->show;
62 } 60 }
63 61
64 return; 62 return;
65 } 63 }
66 } 64 }
257 255
258 $self->{root} = $self->{parent}{root}; 256 $self->{root} = $self->{parent}{root};
259 $self->{visible} = $self->{parent}{visible} + 1; 257 $self->{visible} = $self->{parent}{visible} + 1;
260 258
261 $self->emit (visibility_change => 1); 259 $self->emit (visibility_change => 1);
260
261 $self->realloc if !exists $self->{req_w};
262
263 $_->set_visible for $self->children;
262} 264}
263 265
264sub set_invisible { 266sub set_invisible {
265 my ($self) = @_; 267 my ($self) = @_;
266 268
267 return unless $self->{visible}; 269 return unless $self->{visible};
268 270
269 # broken show/hide model 271 $_->set_invisible for $self->children;
270 272
271 delete $self->{root}; 273 delete $self->{root};
272 delete $self->{visible}; 274 delete $self->{visible};
273 275
274 undef $GRAB if $GRAB == $self; 276 undef $GRAB if $GRAB == $self;
275 undef $HOVER if $HOVER == $self; 277 undef $HOVER if $HOVER == $self;
276 278
277 CFClient::UI::check_tooltip 279 CFClient::UI::check_tooltip
278 if $CFClient::UI::TOOLTIP->{owner} == $self; 280 if $TOOLTIP->{owner} == $self;
279 281
280 $self->focus_out; 282 $self->focus_out;
281 283
282 $self->emit (visibility_change => 0); 284 $self->emit (visibility_change => 0);
283} 285}
322 my ($self, $w, $h) = @_; 324 my ($self, $w, $h) = @_;
323 325
324 $self->{def_w} = $w; 326 $self->{def_w} = $w;
325 $self->{def_h} = $h; 327 $self->{def_h} = $h;
326 328
327 $self->check_size; 329 $self->realloc;
328} 330}
329 331
330sub size_request { 332sub size_request {
331 require Carp; 333 require Carp;
332 Carp::confess "size_request is abstract"; 334 Carp::confess "size_request is abstract";
352 $self->{y} = $y; 354 $self->{y} = $y;
353 $self->update; 355 $self->update;
354 } 356 }
355 357
356 if ($self->{w} != $w || $self->{h} != $h) { 358 if ($self->{w} != $w || $self->{h} != $h) {
359 return unless $self->{visible};
360
357 $CFClient::UI::ROOT->{size_alloc}{$self+0} = [$self, $w, $h]; 361 $self->{root}->{size_alloc}{$self+0} = [$self, $w, $h];
358 } 362 }
359} 363}
360 364
361sub size_allocate { 365sub size_allocate {
362 # nothing to be done 366 # nothing to be done
363}
364
365sub reconfigure {
366 my ($self) = @_;
367
368 $self->check_size (1);
369 $self->update;
370} 367}
371 368
372sub children { 369sub children {
373} 370}
374 371
452sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} } 449sub w { $_[0]{w} = $_[1] if @_ > 1; $_[0]{w} }
453sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} } 450sub h { $_[0]{h} = $_[1] if @_ > 1; $_[0]{h} }
454sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} } 451sub x { $_[0]{x} = $_[1] if @_ > 1; $_[0]{x} }
455sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} } 452sub y { $_[0]{y} = $_[1] if @_ > 1; $_[0]{y} }
456sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} } 453sub z { $_[0]{z} = $_[1] if @_ > 1; $_[0]{z} }
454
455sub find_widget {
456 my ($self, $x, $y) = @_;
457
458 return () unless $self->{can_events};
459
460 return $self
461 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
462 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
463
464 ()
465}
466
467sub set_parent {
468 my ($self, $parent) = @_;
469
470 Scalar::Util::weaken ($self->{parent} = $parent);
471
472 $self->set_visible if $parent->{visible};
473}
474
475sub connect {
476 my ($self, $signal, $cb) = @_;
477
478 push @{ $self->{signal_cb}{$signal} }, $cb;
479}
480
481sub _emit {
482 my ($self, $signal, @args) = @_;
483
484 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}
485}
486
487sub emit {
488 my ($self, $signal, @args) = @_;
489
490 $self->_emit ($signal, @args)
491 || $self->$signal (@args);
492}
493
494sub visibility_change {
495 #my ($self, $visible) = @_;
496}
497
498sub realloc {
499 my ($self) = @_;
500
501 if ($self->{visible}) {
502 return if $self->{root}{realloc}{$self};
503
504 $self->{root}{realloc}{$self} = $self;
505 $self->{root}->update;
506 } else {
507 delete $self->{req_w};
508 }
509}
510
511sub update {
512 my ($self) = @_;
513
514 $self->{parent}->update
515 if $self->{parent};
516}
457 517
458sub draw { 518sub draw {
459 my ($self) = @_; 519 my ($self) = @_;
460 520
461 return unless $self->{h} && $self->{w}; 521 return unless $self->{h} && $self->{w};
499 my ($self) = @_; 559 my ($self) = @_;
500 560
501 warn "no draw defined for $self\n"; 561 warn "no draw defined for $self\n";
502} 562}
503 563
504sub find_widget {
505 my ($self, $x, $y) = @_;
506
507 return () unless $self->{can_events};
508
509 return $self
510 if $x >= $self->{x} && $x < $self->{x} + $self->{w}
511 && $y >= $self->{y} && $y < $self->{y} + $self->{h};
512
513 ()
514}
515
516sub set_parent {
517 my ($self, $parent) = @_;
518
519 Scalar::Util::weaken ($self->{parent} = $parent);
520
521 $self->set_visible; #TODO why breakssssss borked damn if $parent->{visible};
522
523 $self->check_size;
524}
525
526sub check_size {
527 my ($self, $forced) = @_;
528
529 $self->{force_alloc} = 1 if $forced;
530 $CFClient::UI::ROOT->{check_size}{$self} = $self;
531}
532
533sub update {
534 my ($self) = @_;
535
536 $self->{parent}->update
537 if $self->{parent};
538}
539
540sub connect {
541 my ($self, $signal, $cb) = @_;
542
543 push @{ $self->{signal_cb}{$signal} }, $cb;
544}
545
546sub _emit {
547 my ($self, $signal, @args) = @_;
548
549 List::Util::sum map $_->($self, @args), @{$self->{signal_cb}{$signal} || []}
550}
551
552sub emit {
553 my ($self, $signal, @args) = @_;
554
555 $self->_emit ($signal, @args)
556 || $self->$signal (@args);
557}
558
559sub visibility_change {
560 #my ($self, $visible) = @_;
561}
562
563sub DESTROY { 564sub DESTROY {
564 my ($self) = @_; 565 my ($self) = @_;
565 566
566 delete $WIDGET{$self+0}; 567 delete $WIDGET{$self+0};
567 #$self->deactivate; 568 #$self->deactivate;
662 $self->{children} = [ 663 $self->{children} = [
663 sort { $a->{z} <=> $b->{z} } 664 sort { $a->{z} <=> $b->{z} }
664 @{$self->{children}}, @widgets 665 @{$self->{children}}, @widgets
665 ]; 666 ];
666 667
667 $self->check_size (1); 668 $self->realloc;
668 $self->update;
669} 669}
670 670
671sub children { 671sub children {
672 @{ $_[0]{children} } 672 @{ $_[0]{children} }
673} 673}
678 delete $child->{parent}; 678 delete $child->{parent};
679 $child->hide; 679 $child->hide;
680 680
681 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; 681 $self->{children} = [ grep $_ != $child, @{ $self->{children} } ];
682 682
683 $self->check_size (1); 683 $self->realloc;
684 $self->update;
685} 684}
686 685
687sub clear { 686sub clear {
688 my ($self) = @_; 687 my ($self) = @_;
689 688
693 for (@$children) { 692 for (@$children) {
694 delete $_->{parent}; 693 delete $_->{parent};
695 $_->hide; 694 $_->hide;
696 } 695 }
697 696
698 $self->check_size; 697 $self->realloc;
699 $self->update;
700} 698}
701 699
702sub find_widget { 700sub find_widget {
703 my ($self, $x, $y) = @_; 701 my ($self, $x, $y) = @_;
704 702
757sub size_request { 755sub size_request {
758 $_[0]{children}[0]->size_request 756 $_[0]{children}[0]->size_request
759} 757}
760 758
761sub size_allocate { 759sub size_allocate {
762 my ($self, $w, $h) = @_; 760 my ($self, $w, $h, $changed) = @_;
763 761
764 $self->{children}[0]->configure (0, 0, $w, $h); 762 $self->{children}[0]->configure (0, 0, $w, $h);
765} 763}
766 764
767############################################################################# 765#############################################################################
784 $ROOT->on_post_alloc ($self => sub { $self->render_child }); 782 $ROOT->on_post_alloc ($self => sub { $self->render_child });
785 $self->SUPER::update; 783 $self->SUPER::update;
786} 784}
787 785
788sub size_allocate { 786sub size_allocate {
789 my ($self, $w, $h) = @_; 787 my ($self, $w, $h, $changed) = @_;
790 788
791 $self->SUPER::size_allocate ($w, $h); 789 $self->SUPER::size_allocate ($w, $h, $changed);
792 $self->update; 790 $self->update
791 if $changed;
793} 792}
794 793
795sub _render { 794sub _render {
796 $_[0]{children}[0]->draw; 795 $_[0]{children}[0]->draw;
797} 796}
850 849
851 ($w, $h) 850 ($w, $h)
852} 851}
853 852
854sub size_allocate { 853sub size_allocate {
855 my ($self, $w, $h) = @_; 854 my ($self, $w, $h, $changed) = @_;
856 855
857 $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w}; 856 $w = $self->{child_w} if $self->{scroll_x} && $self->{child_w};
858 $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h}; 857 $h = $self->{child_h} if $self->{scroll_y} && $self->{child_h};
859 858
860 $self->child->configure (0, 0, $w, $h); 859 $self->child->configure (0, 0, $w, $h);
947 my $child = $self->{vp}->child; 946 my $child = $self->{vp}->child;
948 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); 947 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
949} 948}
950 949
951sub size_allocate { 950sub size_allocate {
952 my ($self, $w, $h) = @_; 951 my ($self, $w, $h, $changed) = @_;
953 952
954 $self->SUPER::size_allocate ($w, $h); 953 $self->SUPER::size_allocate ($w, $h, $changed);
955 954
956 my $child = $self->{vp}->child; 955 my $child = $self->{vp}->child;
957 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]); 956 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
958} 957}
959 958
1047 $h + $self->border * 2, 1046 $h + $self->border * 2,
1048 ) 1047 )
1049} 1048}
1050 1049
1051sub size_allocate { 1050sub size_allocate {
1052 my ($self, $w, $h) = @_; 1051 my ($self, $w, $h, $changed) = @_;
1052
1053 return unless $changed;
1053 1054
1054 $h -= List::Util::max 0, $self->border * 2; 1055 $h -= List::Util::max 0, $self->border * 2;
1055 $w -= List::Util::max 0, $self->border * 2; 1056 $w -= List::Util::max 0, $self->border * 2;
1056 1057
1057 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2) 1058 $self->{title}->configure ($self->border, int $self->border - $::FONTSIZE * 2, $w, int $::FONTSIZE * 2)
1086 $self->{user_x} = $wx + $dx * $mx; 1087 $self->{user_x} = $wx + $dx * $mx;
1087 $self->{user_y} = $wy + $dy * $my; 1088 $self->{user_y} = $wy + $dy * $my;
1088 $self->{def_w} = $bw + $dx * ($mx ? -1 : 1); 1089 $self->{def_w} = $bw + $dx * ($mx ? -1 : 1);
1089 $self->{def_h} = $bh + $dy * ($my ? -1 : 1); 1090 $self->{def_h} = $bh + $dy * ($my ? -1 : 1);
1090 $self->move ($self->{user_x}, $self->{user_y}); 1091 $self->move ($self->{user_x}, $self->{user_y});
1091 $self->check_size; 1092 $self->realloc;
1092 }; 1093 };
1093 1094
1094 } elsif ($lr ^ $td) { 1095 } elsif ($lr ^ $td) {
1095 my ($ox, $oy) = ($ev->{x}, $ev->{y}); 1096 my ($ox, $oy) = ($ev->{x}, $ev->{y});
1096 my ($bx, $by) = ($self->{x}, $self->{y}); 1097 my ($bx, $by) = ($self->{x}, $self->{y});
1102 1103
1103 $self->{user_x} = $bx + $x - $ox; 1104 $self->{user_x} = $bx + $x - $ox;
1104 $self->{user_y} = $by + $y - $oy; 1105 $self->{user_y} = $by + $y - $oy;
1105 1106
1106 $self->move ($self->{user_x}, $self->{user_y}); 1107 $self->move ($self->{user_x}, $self->{user_y});
1107 $self->update; 1108 $self->realloc;
1108 }; 1109 };
1109 } 1110 }
1110} 1111}
1111 1112
1112sub button_up { 1113sub button_up {
1187 my ($self, $x, $y, $child) = @_; 1188 my ($self, $x, $y, $child) = @_;
1188 1189
1189 $child->set_parent ($self); 1190 $child->set_parent ($self);
1190 $self->{children}[$y][$x] = $child; 1191 $self->{children}[$y][$x] = $child;
1191 1192
1192 $self->check_size (1); 1193 $self->realloc;
1193} 1194}
1194 1195
1195# TODO: move to container class maybe? send children a signal on removal? 1196# TODO: move to container class maybe? send children a signal on removal?
1196sub clear { 1197sub clear {
1197 my ($self) = @_; 1198 my ($self) = @_;
1202 for (@children) { 1203 for (@children) {
1203 delete $_->{parent}; 1204 delete $_->{parent};
1204 $_->hide; 1205 $_->hide;
1205 } 1206 }
1206 1207
1207 $self->check_size (1); 1208 $self->realloc;
1208 $self->update;
1209} 1209}
1210 1210
1211sub get_wh { 1211sub get_wh {
1212 my ($self) = @_; 1212 my ($self) = @_;
1213 1213
1240 (sum @$hs), 1240 (sum @$hs),
1241 ) 1241 )
1242} 1242}
1243 1243
1244sub size_allocate { 1244sub size_allocate {
1245 my ($self, $w, $h) = @_; 1245 my ($self, $w, $h, $changed) = @_;
1246 1246
1247 my ($ws, $hs) = $self->get_wh; 1247 my ($ws, $hs) = $self->get_wh;
1248 1248
1249 my $req_w = (sum @$ws) || 1; 1249 my $req_w = (sum @$ws) || 1;
1250 my $req_h = (sum @$hs) || 1; 1250 my $req_h = (sum @$hs) || 1;
1328 (List::Util::max map $_->{req_h}, @{$self->{children}}), 1328 (List::Util::max map $_->{req_h}, @{$self->{children}}),
1329 ) 1329 )
1330} 1330}
1331 1331
1332sub size_allocate { 1332sub size_allocate {
1333 my ($self, $w, $h) = @_; 1333 my ($self, $w, $h, $changed) = @_;
1334 1334
1335 my $space = $self->{vertical} ? $h : $w; 1335 my $space = $self->{vertical} ? $h : $w;
1336 my $children = $self->{children}; 1336 my $children = $self->{children};
1337 1337
1338 my @req; 1338 my @req;
1467 $self->{text} = "T$text"; 1467 $self->{text} = "T$text";
1468 1468
1469 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba; 1469 $self->{layout} = new CFClient::Layout if $self->{layout}->is_rgba;
1470 $self->{layout}->set_text ($text); 1470 $self->{layout}->set_text ($text);
1471 1471
1472 $self->realloc;
1472 $self->update; 1473 $self->update;
1473 $self->check_size;
1474} 1474}
1475 1475
1476sub set_markup { 1476sub set_markup {
1477 my ($self, $markup) = @_; 1477 my ($self, $markup) = @_;
1478 1478
1482 my $rgba = $markup =~ /span.*(?:foreground|background)/; 1482 my $rgba = $markup =~ /span.*(?:foreground|background)/;
1483 1483
1484 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba; 1484 $self->{layout} = new CFClient::Layout $rgba if $self->{layout}->is_rgba != $rgba;
1485 $self->{layout}->set_markup ($markup); 1485 $self->{layout}->set_markup ($markup);
1486 1486
1487 $self->realloc;
1487 $self->update; 1488 $self->update;
1488 $self->check_size;
1489} 1489}
1490 1490
1491sub size_request { 1491sub size_request {
1492 my ($self) = @_; 1492 my ($self) = @_;
1493 1493
1514 $h + $self->{padding} * 2, 1514 $h + $self->{padding} * 2,
1515 ) 1515 )
1516} 1516}
1517 1517
1518sub size_allocate { 1518sub size_allocate {
1519 my ($self, $w, $h) = @_; 1519 my ($self, $w, $h, $changed) = @_;
1520 1520
1521 delete $self->{texture}; 1521 delete $self->{texture}
1522 if $changed;
1522} 1523}
1523 1524
1524sub set_fontsize { 1525sub set_fontsize {
1525 my ($self, $fontsize) = @_; 1526 my ($self, $fontsize) = @_;
1526 1527
1527 $self->{fontsize} = $fontsize; 1528 $self->{fontsize} = $fontsize;
1528 delete $self->{texture}; 1529 delete $self->{texture};
1529 1530
1530 $self->update; 1531 $self->realloc;
1531 $self->check_size;
1532} 1532}
1533 1533
1534sub _draw { 1534sub _draw {
1535 my ($self) = @_; 1535 my ($self) = @_;
1536 1536
1616sub set_text { 1616sub set_text {
1617 my ($self, $text) = @_; 1617 my ($self, $text) = @_;
1618 1618
1619 $self->{cursor} = length $text; 1619 $self->{cursor} = length $text;
1620 $self->_set_text ($text); 1620 $self->_set_text ($text);
1621 $self->update; 1621
1622 $self->check_size; 1622 $self->realloc;
1623} 1623}
1624 1624
1625sub get_text { 1625sub get_text {
1626 $_[0]{text} 1626 $_[0]{text}
1627} 1627}
1660 } elsif ($uni) { 1660 } elsif ($uni) {
1661 substr $text, $self->{cursor}++, 0, chr $uni; 1661 substr $text, $self->{cursor}++, 0, chr $uni;
1662 } 1662 }
1663 1663
1664 $self->_set_text ($text); 1664 $self->_set_text ($text);
1665 $self->update; 1665
1666 $self->check_size; 1666 $self->realloc;
1667} 1667}
1668 1668
1669sub focus_in { 1669sub focus_in {
1670 my ($self) = @_; 1670 my ($self) = @_;
1671 1671
2178 $self->update; 2178 $self->update;
2179 2179
2180 $self 2180 $self
2181} 2181}
2182 2182
2183sub changed { }
2184
2183sub set_range { 2185sub set_range {
2184 my ($self, $range) = @_; 2186 my ($self, $range) = @_;
2185 2187
2186 ($range, $self->{range}) = ($self->{range}, $range); 2188 ($range, $self->{range}) = ($self->{range}, $range);
2187 2189
2376 $self->{fontsize} = $fontsize; 2378 $self->{fontsize} = $fontsize;
2377 $self->reflow; 2379 $self->reflow;
2378} 2380}
2379 2381
2380sub size_allocate { 2382sub size_allocate {
2381 my ($self, $w, $h) = @_; 2383 my ($self, $w, $h, $changed) = @_;
2382 2384
2383 $self->SUPER::size_allocate ($w, $h); 2385 $self->SUPER::size_allocate ($w, $h, $changed);
2386
2387 return unless $changed;
2384 2388
2385 $self->{layout}->set_font ($self->{font}) if $self->{font}; 2389 $self->{layout}->set_font ($self->{font}) if $self->{font};
2386 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 2390 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
2387 $self->{layout}->set_width ($self->{children}[0]{w}); 2391 $self->{layout}->set_width ($self->{children}[0]{w});
2388 2392
2630 2634
2631 ($w + 4, $h + 4) 2635 ($w + 4, $h + 4)
2632} 2636}
2633 2637
2634sub size_allocate { 2638sub size_allocate {
2635 my ($self, $w, $h) = @_; 2639 my ($self, $w, $h, $changed) = @_;
2636 2640
2641 return unless $changed;
2642
2637 $self->SUPER::size_allocate ($w - 4, $h - 4); 2643 $self->SUPER::size_allocate ($w - 4, $h - 4, $changed);
2638} 2644}
2639 2645
2640sub _draw { 2646sub _draw {
2641 my ($self) = @_; 2647 my ($self) = @_;
2642 2648
2659 glVertex $w, $h; 2665 glVertex $w, $h;
2660 glVertex $w, 0; 2666 glVertex $w, 0;
2661 glEnd; 2667 glEnd;
2662 2668
2663 glTranslate 2 - 0.375, 2 - 0.375; 2669 glTranslate 2 - 0.375, 2 - 0.375;
2670
2664 $self->SUPER::_draw; 2671 $self->SUPER::_draw;
2665} 2672}
2666 2673
2667############################################################################# 2674#############################################################################
2668 2675
2977use CFClient::OpenGL; 2984use CFClient::OpenGL;
2978 2985
2979sub new { 2986sub new {
2980 my $class = shift; 2987 my $class = shift;
2981 2988
2982 $class->SUPER::new ( 2989 my $self = $class->SUPER::new (
2983 visible => 1, 2990 visible => 1,
2984 @_, 2991 @_,
2985 ) 2992 );
2993
2994 Scalar::Util::weaken ($self->{root} = $self);
2995
2996 $self
2986} 2997}
2987 2998
2988sub configure { 2999sub configure {
2989 my ($self, $x, $y, $w, $h) = @_; 3000 my ($self, $x, $y, $w, $h) = @_;
2990 3001
2991 $self->{w} = $w; 3002 $self->{w} = $w;
2992 $self->{h} = $h; 3003 $self->{h} = $h;
2993} 3004}
2994 3005
2995sub check_size { 3006sub reconfigure {
2996 my ($self) = @_; 3007 my ($self) = @_;
2997 3008
3009 $self->SUPER::reconfigure;
3010
2998 $self->size_allocate ($self->{w}, $self->{h}) 3011 $self->size_allocate ($self->{w}, $self->{h}, 1)
2999 if $self->{w}; 3012 if $self->{w};
3000} 3013}
3001 3014
3002sub size_request { 3015sub size_request {
3003 my ($self) = @_; 3016 my ($self) = @_;
3004 3017
3005 ($self->{w}, $self->{h}) 3018 ($self->{w}, $self->{h})
3006} 3019}
3007 3020
3008sub size_allocate { 3021sub size_allocate {
3009 my ($self, $w, $h) = @_; 3022 my ($self, $w, $h, $changed) = @_;
3010 3023
3011 for my $child ($self->children) { 3024 for my $child ($self->children) {
3012 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 3025 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
3013 3026
3014 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 3027 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
3039} 3052}
3040 3053
3041sub update { 3054sub update {
3042 my ($self) = @_; 3055 my ($self) = @_;
3043 3056
3044 $self->check_size;
3045 $::WANT_REFRESH++; 3057 $::WANT_REFRESH++;
3046} 3058}
3047 3059
3048sub add { 3060sub add {
3049 my ($self, @children) = @_; 3061 my ($self, @children) = @_;
3055 $child->{x} = int $child->{x}; 3067 $child->{x} = int $child->{x};
3056 $child->{y} = int $child->{y}; 3068 $child->{y} = int $child->{y};
3057 } 3069 }
3058 3070
3059 $self->SUPER::add (@children); 3071 $self->SUPER::add (@children);
3060
3061 for (my @widgets = @children; my $w = pop @widgets; ) {
3062 push @widgets, $w->children;
3063 $w->set_visible;
3064 }
3065
3066} 3072}
3067 3073
3068sub remove { 3074sub remove {
3069 my ($self, @children) = @_; 3075 my ($self, @children) = @_;
3070 3076
3095 while ($self->{refresh_hook}) { 3101 while ($self->{refresh_hook}) {
3096 $_->() 3102 $_->()
3097 for values %{delete $self->{refresh_hook}}; 3103 for values %{delete $self->{refresh_hook}};
3098 } 3104 }
3099 3105
3100 if ($self->{check_size}) { 3106 if ($self->{realloc}) {
3101 my @queue; 3107 my @queue;
3102 3108
3103 while () { 3109 while () {
3104 if ($self->{check_size}) { 3110 if ($self->{realloc}) {
3105 #TODO use array-of-depth approach 3111 #TODO use array-of-depth approach
3106 3112
3107 @queue = sort { $a->{visible} <=> $b->{visible} } 3113 @queue = sort { $a->{visible} <=> $b->{visible} }
3108 @queue, values %{delete $self->{check_size}}; 3114 @queue, values %{delete $self->{realloc}};
3109 } 3115 }
3110 3116
3111 my $widget = pop @queue || last; 3117 my $widget = pop @queue || last;
3112 3118
3113 defined $widget->{visible} or last; # do not resize invisible widgets 3119 $widget->{visible} or last; # do not resize invisible widgets
3114 3120
3115 my ($w, $h) = $widget->{def_w} && $widget->{def_h} 3121 my ($w, $h) = $widget->{def_w} && $widget->{def_h}
3116 ? @$widget{qw(def_w def_h)} 3122 ? @$widget{qw(def_w def_h)}
3117 : $widget->size_request; 3123 : $widget->size_request;
3118 3124
3119 if (delete $widget->{force_alloc}
3120 or $w != $widget->{req_w} or $h != $widget->{req_h}) {
3121 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d# 3125 Carp::confess "$widget: size_request is negative" if $w < 0 || $h < 0;#d#
3122 3126
3123 $widget->{req_w} = $w; 3127 $widget->{req_w} = $w;
3124 $widget->{req_h} = $h; 3128 $widget->{req_h} = $h;
3125 3129
3126 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h]; 3130 $self->{size_alloc}{$widget} = [$widget, $widget->{w} || $w, $widget->{h} || $h];
3127 3131
3128 $widget->{parent}->check_size 3132 push @queue, $widget->{parent}
3129 if $widget->{parent}; 3133 if $widget->{parent};
3130 }
3131 } 3134 }
3132 } 3135 }
3133 3136
3134 while (my $size_alloc = delete $self->{size_alloc}) { 3137 while (my $size_alloc = delete $self->{size_alloc}) {
3135 my @queue = sort $b->[0]{visible} <=> $a->[0]{visible}, 3138 my @queue = sort $b->[0]{visible} <=> $a->[0]{visible},
3139 my ($widget, $w, $h) = @{ pop @queue or last }; 3142 my ($widget, $w, $h) = @{ pop @queue or last };
3140 3143
3141 $w = 0 if $w < 0; 3144 $w = 0 if $w < 0;
3142 $h = 0 if $h < 0; 3145 $h = 0 if $h < 0;
3143 3146
3147 my $changed = $widget->{w} != $w || $widget->{h} != $h;
3148
3144 $widget->{w} = $w; 3149 $widget->{w} = $w;
3145 $widget->{h} = $h; 3150 $widget->{h} = $h;
3151
3146 $widget->emit (size_allocate => $w, $h); 3152 $widget->emit (size_allocate => $w, $h, $changed);
3147 } 3153 }
3148 } 3154 }
3149 3155
3150 while ($self->{post_alloc_hook}) { 3156 while ($self->{post_alloc_hook}) {
3151 $_->() 3157 $_->()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines