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

429 429
430# translate global coordinates to local coordinate system 430# translate global coordinates to local coordinate system
431sub coord2local { 431sub coord2local {
432 my ($self, $x, $y) = @_; 432 my ($self, $x, $y) = @_;
433 433
434 Carp::confess unless $self->{parent};#d#
435
434 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 436 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
435} 437}
436 438
437# translate local coordinates to global coordinate system 439# translate local coordinates to global coordinate system
438sub coord2global { 440sub coord2global {
439 my ($self, $x, $y) = @_; 441 my ($self, $x, $y) = @_;
442
443 Carp::confess unless $self->{parent};#d#
440 444
441 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 445 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
442} 446}
443 447
444sub invoke_focus_in { 448sub invoke_focus_in {
492 496
493sub connect { 497sub connect {
494 my ($self, $signal, $cb) = @_; 498 my ($self, $signal, $cb) = @_;
495 499
496 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 }
497} 506}
507
508my %has_coords = (
509 button_down => 1,
510 button_up => 1,
511 mouse_motion => 1,
512 mouse_wheel => 1,
513);
498 514
499sub emit { 515sub emit {
500 my ($self, $signal, @args) = @_; 516 my ($self, $signal, @args) = @_;
501 517
518 # I do not really like this solution, but I dislike duplication
519 # and needlessly verbose code, too.
502 my @append 520 my @append
503 = ref $args[0] && $args[0]->isa ("CFClient::UI::Event") 521 = $has_coords{$signal}
504 ? $args[0]->xy ($self) 522 ? $args[0]->xy ($self)
505 : (); 523 : ();
506 524
507 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# 525 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d#
508 526
713 if $children; 731 if $children;
714 732
715 $self 733 $self
716} 734}
717 735
736sub realloc {
737 my ($self) = @_;
738
739 $self->{force_realloc} = 1;
740 $self->{force_size_alloc} = 1;
741 $self->SUPER::realloc;
742}
743
718sub add { 744sub add {
719 my ($self, @widgets) = @_; 745 my ($self, @widgets) = @_;
720 746
721 $_->set_parent ($self) 747 $_->set_parent ($self)
722 for @widgets; 748 for @widgets;
1338sub children { 1364sub children {
1339 grep $_, map @$_, grep $_, @{ $_[0]{children} } 1365 grep $_, map @$_, grep $_, @{ $_[0]{children} }
1340} 1366}
1341 1367
1342sub add { 1368sub add {
1343 my ($self, $x, $y, $child) = @_; 1369 my ($self) = shift;
1344 1370
1371 while (@_) {
1372 my ($x, $y, $child) = splice @_, 0, 3, ();
1345 $child->set_parent ($self); 1373 $child->set_parent ($self);
1346 $self->{children}[$y][$x] = $child; 1374 $self->{children}[$y][$x] = $child;
1375 }
1347 1376
1377 $self->{force_realloc} = 1;
1378 $self->{force_size_alloc} = 1;
1348 $self->realloc; 1379 $self->realloc;
1349} 1380}
1350 1381
1351sub remove { 1382sub remove {
1352 my ($self, $child) = @_; 1383 my ($self, $child) = @_;
2977 3008
2978 $self->{root}->on_post_alloc ("move_$self" => sub { 3009 $self->{root}->on_post_alloc ("move_$self" => sub {
2979 my $widget = $self->{owner} 3010 my $widget = $self->{owner}
2980 or return; 3011 or return;
2981 3012
3013 if ($widget->{visible}) {
2982 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 3014 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2983 3015
2984 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 3016 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2985 if $x + $self->{w} > $self->{root}{w}; 3017 if $x + $self->{w} > $self->{root}{w};
2986 3018
2987 $self->move_abs ($x, $y); 3019 $self->move_abs ($x, $y);
3020 } else {
3021 $self->hide;
3022 }
2988 }); 3023 });
2989} 3024}
2990 3025
2991sub _draw { 3026sub _draw {
2992 my ($self) = @_; 3027 my ($self) = @_;
3530sub new { 3565sub new {
3531 my $class = shift; 3566 my $class = shift;
3532 3567
3533 my $self = $class->SUPER::new ( 3568 my $self = $class->SUPER::new (
3534 col_expand => [0, 1, 0], 3569 col_expand => [0, 1, 0],
3570 items => [],
3535 @_, 3571 @_,
3536 ); 3572 );
3537 3573
3574 $self->set_sort_order (undef);
3575
3538 $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;
3539} 3612}
3540 3613
3541sub set_items { 3614sub set_items {
3542 my ($self, $items) = @_; 3615 my ($self, $items) = @_;
3543 3616
3544 $self->clear; 3617 $self->{items} = [$items ? values %$items : ()];
3545 return unless $items; 3618 $self->update_items;
3546
3547 my @items = sort {
3548 ($a->{type} <=> $b->{type})
3549 or ($a->{name} cmp $b->{name})
3550 } values %$items;
3551
3552 $self->{real_items} = \@items;
3553
3554 my $row = 0;
3555 for my $item (@items) {
3556 CFClient::Item::update_widgets $item;
3557
3558 $self->add (0, $row, $item->{face_widget});
3559 $self->add (1, $row, $item->{desc_widget});
3560 $self->add (2, $row, $item->{weight_widget});
3561
3562 $row++;
3563 }
3564} 3619}
3565 3620
3566############################################################################# 3621#############################################################################
3567 3622
3568package CFClient::UI::SpellList; 3623package CFClient::UI::SpellList;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines