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.331 by root, Sun Jul 23 04:46:02 2006 UTC vs.
Revision 1.332 by root, Sun Jul 23 08:58:44 2006 UTC

438 438
439# translate local coordinates to global coordinate system 439# translate local coordinates to global coordinate system
440sub coord2global { 440sub coord2global {
441 my ($self, $x, $y) = @_; 441 my ($self, $x, $y) = @_;
442 442
443 Carp::confess unless $self->{parent};#d#
444
443 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 445 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
444} 446}
445 447
446sub invoke_focus_in { 448sub invoke_focus_in {
447 my ($self) = @_; 449 my ($self) = @_;
494 496
495sub connect { 497sub connect {
496 my ($self, $signal, $cb) = @_; 498 my ($self, $signal, $cb) = @_;
497 499
498 push @{ $self->{signal_cb}{$signal} }, $cb; 500 push @{ $self->{signal_cb}{$signal} }, $cb;
501
502 defined wantarray and CFClient::guard {
503 @{ $self->{signal_cb}{$signal} } = grep $_ != $cb,
504 @{ $self->{signal_cb}{$signal} };
505 }
499} 506}
500 507
501my %has_coords = ( 508my %has_coords = (
502 button_down => 1, 509 button_down => 1,
503 button_up => 1, 510 button_up => 1,
506); 513);
507 514
508sub emit { 515sub emit {
509 my ($self, $signal, @args) = @_; 516 my ($self, $signal, @args) = @_;
510 517
518 # I do not really like this solution, but I dislike duplication
519 # and needlessly verbose code, too.
511 my @append 520 my @append
512 = $has_coords{$signal} 521 = $has_coords{$signal}
513 ? $args[0]->xy ($self) 522 ? $args[0]->xy ($self)
514 : (); 523 : ();
515 524
722 if $children; 731 if $children;
723 732
724 $self 733 $self
725} 734}
726 735
736sub realloc {
737 my ($self) = @_;
738
739 $self->{force_realloc} = 1;
740 $self->{force_size_alloc} = 1;
741 $self->SUPER::realloc;
742}
743
727sub add { 744sub add {
728 my ($self, @widgets) = @_; 745 my ($self, @widgets) = @_;
729 746
730 $_->set_parent ($self) 747 $_->set_parent ($self)
731 for @widgets; 748 for @widgets;
1347sub children { 1364sub children {
1348 grep $_, map @$_, grep $_, @{ $_[0]{children} } 1365 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1349} 1366}
1350 1367
1351sub add { 1368sub add {
1352 my ($self, $x, $y, $child) = @_; 1369 my ($self) = shift;
1353 1370
1371 while (@_) {
1372 my ($x, $y, $child) = splice @_, 0, 3, ();
1354 $child->set_parent ($self); 1373 $child->set_parent ($self);
1355 $self->{children}[$y][$x] = $child; 1374 $self->{children}[$y][$x] = $child;
1375 }
1356 1376
1377 $self->{force_realloc} = 1;
1378 $self->{force_size_alloc} = 1;
1357 $self->realloc; 1379 $self->realloc;
1358} 1380}
1359 1381
1360sub remove { 1382sub remove {
1361 my ($self, $child) = @_; 1383 my ($self, $child) = @_;
2986 3008
2987 $self->{root}->on_post_alloc ("move_$self" => sub { 3009 $self->{root}->on_post_alloc ("move_$self" => sub {
2988 my $widget = $self->{owner} 3010 my $widget = $self->{owner}
2989 or return; 3011 or return;
2990 3012
3013 if ($widget->{visible}) {
2991 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 3014 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2992 3015
2993 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 3016 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2994 if $x + $self->{w} > $self->{root}{w}; 3017 if $x + $self->{w} > $self->{root}{w};
2995 3018
2996 $self->move_abs ($x, $y); 3019 $self->move_abs ($x, $y);
3020 } else {
3021 $self->hide;
3022 }
2997 }); 3023 });
2998} 3024}
2999 3025
3000sub _draw { 3026sub _draw {
3001 my ($self) = @_; 3027 my ($self) = @_;
3539sub new { 3565sub new {
3540 my $class = shift; 3566 my $class = shift;
3541 3567
3542 my $self = $class->SUPER::new ( 3568 my $self = $class->SUPER::new (
3543 col_expand => [0, 1, 0], 3569 col_expand => [0, 1, 0],
3570 items => [],
3544 @_, 3571 @_,
3545 ); 3572 );
3546 3573
3574 $self->set_sort_order (undef);
3575
3547 $self 3576 $self
3577}
3578
3579sub update_items {
3580 my ($self) = @_;
3581
3582 $self->clear;
3583
3584 my @item = $self->{sort}->(@{ $self->{items} });
3585
3586 my @adds;
3587 my $row = 0;
3588 for my $item ($self->{sort}->(@{ $self->{items} })) {
3589 CFClient::Item::update_widgets $item;
3590
3591 push @adds, 0, $row, $item->{face_widget};
3592 push @adds, 1, $row, $item->{desc_widget};
3593 push @adds, 2, $row, $item->{weight_widget};
3594
3595 $row++;
3596 }
3597
3598 $self->add (@adds);
3599}
3600
3601sub set_sort_order {
3602 my ($self, $order) = @_;
3603
3604 $self->{sort} = $order ||= sub {
3605 sort {
3606 $a->{type} <=> $b->{type}
3607 or $a->{name} cmp $b->{name}
3608 } @_
3609 };
3610
3611 $self->update_items;
3548} 3612}
3549 3613
3550sub set_items { 3614sub set_items {
3551 my ($self, $items) = @_; 3615 my ($self, $items) = @_;
3552 3616
3553 $self->clear; 3617 $self->{items} = [$items ? values %$items : ()];
3554 return unless $items; 3618 $self->update_items;
3555
3556 my @items = sort {
3557 ($a->{type} <=> $b->{type})
3558 or ($a->{name} cmp $b->{name})
3559 } values %$items;
3560
3561 $self->{real_items} = \@items;
3562
3563 my $row = 0;
3564 for my $item (@items) {
3565 CFClient::Item::update_widgets $item;
3566
3567 $self->add (0, $row, $item->{face_widget});
3568 $self->add (1, $row, $item->{desc_widget});
3569 $self->add (2, $row, $item->{weight_widget});
3570
3571 $row++;
3572 }
3573} 3619}
3574 3620
3575############################################################################# 3621#############################################################################
3576 3622
3577package CFClient::UI::SpellList; 3623package CFClient::UI::SpellList;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines