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.334 by root, Sun Jul 23 16:11:12 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) = @_;
1613 } 1635 }
1614 1636
1615 $self 1637 $self
1616} 1638}
1617 1639
1618sub escape($) {
1619 local $_ = $_[0];
1620
1621 s/&/&/g;
1622 s/>/>/g;
1623 s/</&lt;/g;
1624
1625 $_
1626}
1627
1628sub update { 1640sub update {
1629 my ($self) = @_; 1641 my ($self) = @_;
1630 1642
1631 delete $self->{texture}; 1643 delete $self->{texture};
1632 $self->SUPER::update; 1644 $self->SUPER::update;
2181 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2193 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2182 2194
2183 $self 2195 $self
2184} 2196}
2185 2197
2198sub STORABLE_freeze {
2199 my ($self, $cloning) = @_;
2200
2201 warn "freeze<$self>\n";#d#
2202
2203 $self->{path}
2204 or die "cannot serialise CFClient::UI::Image on non-loadable images\n";
2205
2206 $self->{path}
2207}
2208
2209sub STORABLE_attach {
2210 my ($self, $cloning, $path) = @_;
2211 warn "attach<@_>\n";#d#
2212
2213 $self->new (path => $path)
2214}
2215
2186sub size_request { 2216sub size_request {
2187 my ($self) = @_; 2217 my ($self) = @_;
2188 2218
2189 ($self->{tex}{w}, $self->{tex}{h}) 2219 ($self->{tex}{w}, $self->{tex}{h})
2190} 2220}
2204 } 2234 }
2205 2235
2206 glEnable GL_TEXTURE_2D; 2236 glEnable GL_TEXTURE_2D;
2207 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2237 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2208 2238
2209 $tex->draw_quad_alpha (0, 0, $w, $h); 2239 $tex->draw_quad (0, 0, $w, $h);
2210 2240
2211 glDisable GL_TEXTURE_2D; 2241 glDisable GL_TEXTURE_2D;
2212} 2242}
2213 2243
2214############################################################################# 2244#############################################################################
2506sub invoke_mouse_wheel { 2536sub invoke_mouse_wheel {
2507 my ($self, $ev) = @_; 2537 my ($self, $ev) = @_;
2508 2538
2509 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2539 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2510 2540
2511 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1); 2541 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2);
2512 2542
2513 ! ! $delta 2543 ! ! $delta
2514} 2544}
2515 2545
2516sub update { 2546sub update {
2986 3016
2987 $self->{root}->on_post_alloc ("move_$self" => sub { 3017 $self->{root}->on_post_alloc ("move_$self" => sub {
2988 my $widget = $self->{owner} 3018 my $widget = $self->{owner}
2989 or return; 3019 or return;
2990 3020
3021 if ($widget->{visible}) {
2991 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 3022 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2992 3023
2993 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 3024 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2994 if $x + $self->{w} > $self->{root}{w}; 3025 if $x + $self->{w} > $self->{root}{w};
2995 3026
2996 $self->move_abs ($x, $y); 3027 $self->move_abs ($x, $y);
3028 } else {
3029 $self->hide;
3030 }
2997 }); 3031 });
2998} 3032}
2999 3033
3000sub _draw { 3034sub _draw {
3001 my ($self) = @_; 3035 my ($self) = @_;
3539sub new { 3573sub new {
3540 my $class = shift; 3574 my $class = shift;
3541 3575
3542 my $self = $class->SUPER::new ( 3576 my $self = $class->SUPER::new (
3543 col_expand => [0, 1, 0], 3577 col_expand => [0, 1, 0],
3578 items => [],
3544 @_, 3579 @_,
3545 ); 3580 );
3546 3581
3582 $self->set_sort_order (undef);
3583
3547 $self 3584 $self
3585}
3586
3587sub update_items {
3588 my ($self) = @_;
3589
3590 $self->clear;
3591
3592 my @item = $self->{sort}->(@{ $self->{items} });
3593
3594 my @adds;
3595 my $row = 0;
3596 for my $item ($self->{sort}->(@{ $self->{items} })) {
3597 CFClient::Item::update_widgets $item;
3598
3599 push @adds, 0, $row, $item->{face_widget};
3600 push @adds, 1, $row, $item->{desc_widget};
3601 push @adds, 2, $row, $item->{weight_widget};
3602
3603 $row++;
3604 }
3605
3606 $self->add (@adds);
3607}
3608
3609sub set_sort_order {
3610 my ($self, $order) = @_;
3611
3612 $self->{sort} = $order ||= sub {
3613 sort {
3614 $a->{type} <=> $b->{type}
3615 or $a->{name} cmp $b->{name}
3616 } @_
3617 };
3618
3619 $self->update_items;
3548} 3620}
3549 3621
3550sub set_items { 3622sub set_items {
3551 my ($self, $items) = @_; 3623 my ($self, $items) = @_;
3552 3624
3553 $self->clear; 3625 $self->{items} = [$items ? values %$items : ()];
3554 return unless $items; 3626 $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} 3627}
3574 3628
3575############################################################################# 3629#############################################################################
3576 3630
3577package CFClient::UI::SpellList; 3631package CFClient::UI::SpellList;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines