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.186 by root, Mon May 8 20:39:34 2006 UTC vs.
Revision 1.190 by root, Mon May 8 22:17:38 2006 UTC

403} 403}
404 404
405sub check_size { 405sub check_size {
406 my ($self) = @_; 406 my ($self) = @_;
407 407
408 $self->_check_size;
409 return;
410 #TODO: but needs a vastly more difficult algorithm
411 my $check_size = $CFClient::UI::ROOT->{_check_size} ||= {};
412
413 $check_size->{$self} = $self;
414
415 $CFClient::UI::ROOT->on_refresh (_check_size => sub {
416 while (%$check_size) {
417 my @widgets = values %$check_size;
418 $_->_check_size
419 for @widgets;
420 }
421 });
422}
423
424sub _check_size {
425 my ($self) = @_;
426
427 delete $CFClient::UI::ROOT->{_check_size}{$self};
428
408 $self->{parent} 429 $self->{parent}
409 or return 1; 430 or return 1;
410 431
411 my ($w, $h) = $self->{user_w} && $self->{user_h} 432 my ($w, $h) = $self->{user_w} && $self->{user_h}
412 ? @$self{qw(user_w user_h)} 433 ? @$self{qw(user_w user_h)}
414 435
415 if ($w != $self->{req_w} || $h != $self->{req_h}) { 436 if ($w != $self->{req_w} || $h != $self->{req_h}) {
416 $self->{req_w} = $w; 437 $self->{req_w} = $w;
417 $self->{req_h} = $h; 438 $self->{req_h} = $h;
418 439
419 $self->{parent}->check_size 440 $self->{parent}->_check_size
420 or $self->size_allocate ( 441 or $self->size_allocate (
421 (List::Util::max $self->{w}, $w), 442 (List::Util::max $self->{w}, $w),
422 (List::Util::max $self->{h}, $h), 443 (List::Util::max $self->{h}, $h),
423 ); 444 );
424 445
429} 450}
430 451
431sub update { 452sub update {
432 my ($self) = @_; 453 my ($self) = @_;
433 454
434 $self->{parent}->update 455 my $update = $CFClient::UI::ROOT->{_update} ||= {};
435 if $self->{parent}; 456
457 $update->{$self} = $self;
458
459 $CFClient::UI::ROOT->on_refresh (_update => sub {
460 while (%$update) {
461 my @widgets = values %$update;
462 %$update = ();
463
464 $_->{parent} && $_->{parent}->update
465 for @widgets;
466 }
467 });
436} 468}
437 469
438sub connect { 470sub connect {
439 my ($self, $signal, $cb) = @_; 471 my ($self, $signal, $cb) = @_;
440 472
530 562
531 $self 563 $self
532} 564}
533 565
534sub add { 566sub add {
535 my ($self, $child) = @_; 567 my ($self, @widgets) = @_;
536 568
537 $child->set_parent ($self); 569 $_->set_parent ($self)
570 for @widgets;
538 571
539 use sort 'stable'; 572 use sort 'stable';
540 573
541 $self->{children} = [ 574 $self->{children} = [
542 sort { $a->{z} <=> $b->{z} } 575 sort { $a->{z} <=> $b->{z} }
543 @{$self->{children}}, $child 576 @{$self->{children}}, @widgets
544 ]; 577 ];
545 578
546 $child->check_size; 579 $_->check_size
580 for @widgets;
581
547 $self->update; 582 $self->update;
548} 583}
549 584
550sub children { 585sub children {
551 @{ $_[0]{children} } 586 @{ $_[0]{children} }
2702 my $old_h = $self->{old_h}; 2737 my $old_h = $self->{old_h};
2703 2738
2704 if ($old_w && $old_h) { 2739 if ($old_w && $old_h) {
2705 for my $child ($self->children) { 2740 for my $child ($self->children) {
2706 $child->{x} = int 0.5 + $child->{x} * $w / $old_w; 2741 $child->{x} = int 0.5 + $child->{x} * $w / $old_w;
2707 $child->{w} = int 0.5 + $child->{req_w} * $w / $old_w; 2742 $child->{w} = int 0.5 + $child->{w} * $w / $old_w;
2708 $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; 2743 $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w};
2709 $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; 2744 $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w};
2710 $child->{y} = int 0.5 + $child->{y} * $h / $old_h; 2745 $child->{y} = int 0.5 + $child->{y} * $h / $old_h;
2711 $child->{h} = int 0.5 + $child->{h} * $h / $old_h; 2746 $child->{h} = int 0.5 + $child->{h} * $h / $old_h;
2712 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; 2747 $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines