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.361 by root, Sat Dec 9 02:21:25 2006 UTC vs.
Revision 1.364 by root, Sat Dec 23 10:18:27 2006 UTC

1package CFPlus::UI; 1package CFPlus::UI;
2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use Scalar::Util ();
7use List::Util (); 6use List::Util ();
8use Event; 7use Event;
9 8
10use CFPlus; 9use CFPlus;
11use CFPlus::Pod; 10use CFPlus::Pod;
235 h => undef, 234 h => undef,
236 can_events => 1, 235 can_events => 1,
237 @_ 236 @_
238 }, $class; 237 }, $class;
239 238
240 Scalar::Util::weaken ($CFPlus::UI::WIDGET{$self+0} = $self); 239 CFPlus::weaken ($CFPlus::UI::WIDGET{$self+0} = $self);
241 240
242 for (keys %$self) { 241 for (keys %$self) {
243 if (/^on_(.*)$/) { 242 if (/^on_(.*)$/) {
244 $self->connect ($1 => delete $self->{$_}); 243 $self->connect ($1 => delete $self->{$_});
245 } 244 }
530 ? $args[0]->xy ($self) 529 ? $args[0]->xy ($self)
531 : (); 530 : ();
532 531
533 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# 532 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d#
534 533
535 #d##TODO# stop propagating at first true, do not use sum 534 for my $cb (
536 (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before 535 @{$self->{signal_cb}{$signal} || []}, # before
537 || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure 536 ($self->can ("invoke_$signal") || sub { 1 }), # closure
537 ) {
538 return $cb->($self, @args, @append) || next;
539 }
540
541 # parent
538 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent 542 $self->{parent} && $self->{parent}->emit ($signal, @args)
539} 543}
540 544
541sub find_widget { 545sub find_widget {
542 my ($self, $x, $y) = @_; 546 my ($self, $x, $y) = @_;
543 547
551} 555}
552 556
553sub set_parent { 557sub set_parent {
554 my ($self, $parent) = @_; 558 my ($self, $parent) = @_;
555 559
556 Scalar::Util::weaken ($self->{parent} = $parent); 560 CFPlus::weaken ($self->{parent} = $parent);
557 $self->set_visible if $parent->{visible}; 561 $self->set_visible if $parent->{visible};
558} 562}
559 563
560sub realloc { 564sub realloc {
561 my ($self) = @_; 565 my ($self) = @_;
640 my ($self) = @_; 644 my ($self) = @_;
641 645
642 warn "no draw defined for $self\n"; 646 warn "no draw defined for $self\n";
643} 647}
644 648
649my $cntx;#d#
645sub DESTROY { 650sub DESTROY {
646 my ($self) = @_; 651 my ($self) = @_;
647 652
648 return if CFPlus::in_destruct; 653 return if CFPlus::in_destruct;
649 654
1971 } elsif ($sym == CFPlus::SDLK_LEFT) { 1976 } elsif ($sym == CFPlus::SDLK_LEFT) {
1972 --$self->{cursor} if $self->{cursor}; 1977 --$self->{cursor} if $self->{cursor};
1973 } elsif ($sym == CFPlus::SDLK_RIGHT) { 1978 } elsif ($sym == CFPlus::SDLK_RIGHT) {
1974 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1979 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1975 } elsif ($sym == CFPlus::SDLK_HOME) { 1980 } elsif ($sym == CFPlus::SDLK_HOME) {
1981 # what a hack
1976 $self->{cursor} = 0; 1982 $self->{cursor} =
1983 (substr $self->{text}, 0, $self->{cursor}) =~ /^(.*\012)/
1984 ? length $1
1985 : 0;
1977 } elsif ($sym == CFPlus::SDLK_END) { 1986 } elsif ($sym == CFPlus::SDLK_END) {
1987 # uh, again
1988 $self->{cursor} =
1989 (substr $self->{text}, $self->{cursor}) =~ /^([^\012]*)\012/
1978 $self->{cursor} = length $text; 1990 ? $self->{cursor} + length $1
1991 : length $self->{text};
1979 } elsif ($uni == 21) { # ctrl-u 1992 } elsif ($uni == 21) { # ctrl-u
1980 $text = ""; 1993 $text = "";
1981 $self->{cursor} = 0; 1994 $self->{cursor} = 0;
1982 } elsif ($uni == 27) { 1995 } elsif ($uni == 27) {
1983 $self->emit ('escape'); 1996 $self->emit ('escape');
1984 } elsif ($uni >= 0x20 || $uni == 0x0d) { 1997 } elsif ($uni == 0x0d) {
1998 substr $text, $self->{cursor}++, 0, "\012";
1999 } elsif ($uni >= 0x20) {
1985 substr $text, $self->{cursor}++, 0, chr $uni; 2000 substr $text, $self->{cursor}++, 0, chr $uni;
1986 } else { 2001 } else {
1987 return 0; 2002 return 0;
1988 } 2003 }
1989 2004
2310 or Carp::croak "'path' or 'tex' attributes required"; 2325 or Carp::croak "'path' or 'tex' attributes required";
2311 2326
2312 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2327 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2313 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1; 2328 new_from_file CFPlus::Texture CFPlus::find_rcfile $self->{path}, mipmap => 1;
2314 2329
2315 Scalar::Util::weaken $texture_cache{$self->{path}}; 2330 CFPlus::weaken $texture_cache{$self->{path}};
2316 2331
2317 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2332 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2318 2333
2319 $self 2334 $self
2320} 2335}
2693sub invoke_mouse_wheel { 2708sub invoke_mouse_wheel {
2694 my ($self, $ev) = @_; 2709 my ($self, $ev) = @_;
2695 2710
2696 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx}; 2711 my $delta = $self->{vertical} ? $ev->{dy} : $ev->{dx};
2697 2712
2713 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2;
2714
2698 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * 0.2); 2715 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2699 2716
2700 ! ! $delta 2717 ! ! $delta
2701} 2718}
2702 2719
2703sub update { 2720sub update {
3268 can_events => 0, 3285 can_events => 0,
3269 @_, 3286 @_,
3270 ); 3287 );
3271 3288
3272 if ($self->{anim} && $self->{animspeed}) { 3289 if ($self->{anim} && $self->{animspeed}) {
3273 Scalar::Util::weaken (my $widget = $self); 3290 CFPlus::weaken (my $widget = $self);
3274 3291
3275 $self->{timer} = Event->timer ( 3292 $self->{timer} = Event->timer (
3276 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3293 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3277 hard => 1, 3294 hard => 1,
3278 interval => $self->{animspeed}, 3295 interval => $self->{animspeed},
3532} 3549}
3533 3550
3534sub add { 3551sub add {
3535 my ($self, $title, $widget, $tooltip) = @_; 3552 my ($self, $title, $widget, $tooltip) = @_;
3536 3553
3537 Scalar::Util::weaken $self; 3554 CFPlus::weaken $self;
3538 3555
3539 $self->{buttonbar}->add (new CFPlus::UI::Button 3556 $self->{buttonbar}->add (new CFPlus::UI::Button
3540 markup => $title, 3557 markup => $title,
3541 tooltip => $tooltip, 3558 tooltip => $tooltip,
3542 on_activate => sub { $self->set_current_page ($widget) }, 3559 on_activate => sub { $self->set_current_page ($widget) },
3626 my $self = $class->SUPER::new ( 3643 my $self = $class->SUPER::new (
3627 fontsize => 0.8, 3644 fontsize => 0.8,
3628 @_, 3645 @_,
3629 ); 3646 );
3630 3647
3631 Scalar::Util::weaken (my $this = $self); 3648 CFPlus::weaken (my $this = $self);
3632 3649
3633 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 3650 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder });
3634 3651
3635 $self 3652 $self
3636} 3653}
3775 my $self = $class->SUPER::new ( 3792 my $self = $class->SUPER::new (
3776 visible => 1, 3793 visible => 1,
3777 @_, 3794 @_,
3778 ); 3795 );
3779 3796
3780 Scalar::Util::weaken ($self->{root} = $self); 3797 CFPlus::weaken ($self->{root} = $self);
3781 3798
3782 $self 3799 $self
3783} 3800}
3784 3801
3785sub size_request { 3802sub size_request {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines