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.335 by root, Sun Jul 23 16:11:56 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 $self->{path}
2202 or die "cannot serialise CFClient::UI::Image on non-loadable images\n";
2203
2204 $self->{path}
2205}
2206
2207sub STORABLE_attach {
2208 my ($self, $cloning, $path) = @_;
2209
2210 $self->new (path => $path)
2211}
2212
2177sub size_request { 2213sub size_request {
2178 my ($self) = @_; 2214 my ($self) = @_;
2179 2215
2180 ($self->{tex}{w}, $self->{tex}{h}) 2216 ($self->{tex}{w}, $self->{tex}{h})
2181} 2217}
2195 } 2231 }
2196 2232
2197 glEnable GL_TEXTURE_2D; 2233 glEnable GL_TEXTURE_2D;
2198 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 2234 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
2199 2235
2200 $tex->draw_quad_alpha (0, 0, $w, $h); 2236 $tex->draw_quad (0, 0, $w, $h);
2201 2237
2202 glDisable GL_TEXTURE_2D; 2238 glDisable GL_TEXTURE_2D;
2203} 2239}
2204 2240
2205############################################################################# 2241#############################################################################
2497sub invoke_mouse_wheel { 2533sub invoke_mouse_wheel {
2498 my ($self, $ev) = @_; 2534 my ($self, $ev) = @_;
2499 2535
2500 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2536 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2501 2537
2502 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.1); 2538 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2);
2503 2539
2504 ! ! $delta 2540 ! ! $delta
2505} 2541}
2506 2542
2507sub update { 2543sub update {
2977 3013
2978 $self->{root}->on_post_alloc ("move_$self" => sub { 3014 $self->{root}->on_post_alloc ("move_$self" => sub {
2979 my $widget = $self->{owner} 3015 my $widget = $self->{owner}
2980 or return; 3016 or return;
2981 3017
3018 if ($widget->{visible}) {
2982 my ($x, $y) = $widget->coord2global ($widget->{w}, 0); 3019 my ($x, $y) = $widget->coord2global ($widget->{w}, 0);
2983 3020
2984 ($x, $y) = $widget->coord2global (-$self->{w}, 0) 3021 ($x, $y) = $widget->coord2global (-$self->{w}, 0)
2985 if $x + $self->{w} > $self->{root}{w}; 3022 if $x + $self->{w} > $self->{root}{w};
2986 3023
2987 $self->move_abs ($x, $y); 3024 $self->move_abs ($x, $y);
3025 } else {
3026 $self->hide;
3027 }
2988 }); 3028 });
2989} 3029}
2990 3030
2991sub _draw { 3031sub _draw {
2992 my ($self) = @_; 3032 my ($self) = @_;
3530sub new { 3570sub new {
3531 my $class = shift; 3571 my $class = shift;
3532 3572
3533 my $self = $class->SUPER::new ( 3573 my $self = $class->SUPER::new (
3534 col_expand => [0, 1, 0], 3574 col_expand => [0, 1, 0],
3575 items => [],
3535 @_, 3576 @_,
3536 ); 3577 );
3537 3578
3579 $self->set_sort_order (undef);
3580
3538 $self 3581 $self
3582}
3583
3584sub update_items {
3585 my ($self) = @_;
3586
3587 $self->clear;
3588
3589 my @item = $self->{sort}->(@{ $self->{items} });
3590
3591 my @adds;
3592 my $row = 0;
3593 for my $item ($self->{sort}->(@{ $self->{items} })) {
3594 CFClient::Item::update_widgets $item;
3595
3596 push @adds, 0, $row, $item->{face_widget};
3597 push @adds, 1, $row, $item->{desc_widget};
3598 push @adds, 2, $row, $item->{weight_widget};
3599
3600 $row++;
3601 }
3602
3603 $self->add (@adds);
3604}
3605
3606sub set_sort_order {
3607 my ($self, $order) = @_;
3608
3609 $self->{sort} = $order ||= sub {
3610 sort {
3611 $a->{type} <=> $b->{type}
3612 or $a->{name} cmp $b->{name}
3613 } @_
3614 };
3615
3616 $self->update_items;
3539} 3617}
3540 3618
3541sub set_items { 3619sub set_items {
3542 my ($self, $items) = @_; 3620 my ($self, $items) = @_;
3543 3621
3544 $self->clear; 3622 $self->{items} = [$items ? values %$items : ()];
3545 return unless $items; 3623 $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} 3624}
3565 3625
3566############################################################################# 3626#############################################################################
3567 3627
3568package CFClient::UI::SpellList; 3628package CFClient::UI::SpellList;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines