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.334 by root, Sun Jul 23 16:11:12 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) = @_;
1604 } 1635 }
1605 1636
1606 $self 1637 $self
1607} 1638}
1608 1639
1609sub escape($) {
1610 local $_ = $_[0];
1611
1612 s/&/&/g;
1613 s/>/>/g;
1614 s/</&lt;/g;
1615
1616 $_
1617}
1618
1619sub update { 1640sub update {
1620 my ($self) = @_; 1641 my ($self) = @_;
1621 1642
1622 delete $self->{texture}; 1643 delete $self->{texture};
1623 $self->SUPER::update; 1644 $self->SUPER::update;
2172 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2193 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2173 2194
2174 $self 2195 $self
2175} 2196}
2176 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
2177sub size_request { 2216sub size_request {
2178 my ($self) = @_; 2217 my ($self) = @_;
2179 2218
2180 ($self->{tex}{w}, $self->{tex}{h}) 2219 ($self->{tex}{w}, $self->{tex}{h})
2181} 2220}
2195 } 2234 }
2196 2235
2197 glEnable GL_TEXTURE_2D; 2236 glEnable GL_TEXTURE_2D;
2198 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2237 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2199 2238
2200 $tex->draw_quad_alpha (0, 0, $w, $h); 2239 $tex->draw_quad (0, 0, $w, $h);
2201 2240
2202 glDisable GL_TEXTURE_2D; 2241 glDisable GL_TEXTURE_2D;
2203} 2242}
2204 2243
2205############################################################################# 2244#############################################################################
2497sub invoke_mouse_wheel { 2536sub invoke_mouse_wheel {
2498 my ($self, $ev) = @_; 2537 my ($self, $ev) = @_;
2499 2538
2500 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2539 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2501 2540
2502 $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);
2503 2542
2504 ! ! $delta 2543 ! ! $delta
2505} 2544}
2506 2545
2507sub update { 2546sub update {
2977 3016
2978 $self->{root}->on_post_alloc ("move_$self" => sub { 3017 $self->{root}->on_post_alloc ("move_$self" => sub {
2979 my $widget = $self->{owner} 3018 my $widget = $self->{owner}
2980 or return; 3019 or return;
2981 3020
3021 if ($widget->{visible}) {
2982 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 3022 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2983 3023
2984 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 3024 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2985 if $x + $self->{w} > $self->{root}{w}; 3025 if $x + $self->{w} > $self->{root}{w};
2986 3026
2987 $self->move_abs ($x, $y); 3027 $self->move_abs ($x, $y);
3028 } else {
3029 $self->hide;
3030 }
2988 }); 3031 });
2989} 3032}
2990 3033
2991sub _draw { 3034sub _draw {
2992 my ($self) = @_; 3035 my ($self) = @_;
3530sub new { 3573sub new {
3531 my $class = shift; 3574 my $class = shift;
3532 3575
3533 my $self = $class->SUPER::new ( 3576 my $self = $class->SUPER::new (
3534 col_expand => [0, 1, 0], 3577 col_expand => [0, 1, 0],
3578 items => [],
3535 @_, 3579 @_,
3536 ); 3580 );
3537 3581
3582 $self->set_sort_order (undef);
3583
3538 $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;
3539} 3620}
3540 3621
3541sub set_items { 3622sub set_items {
3542 my ($self, $items) = @_; 3623 my ($self, $items) = @_;
3543 3624
3544 $self->clear; 3625 $self->{items} = [$items ? values %$items : ()];
3545 return unless $items; 3626 $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} 3627}
3565 3628
3566############################################################################# 3629#############################################################################
3567 3630
3568package CFClient::UI::SpellList; 3631package CFClient::UI::SpellList;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines