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.365 by root, Thu Apr 12 07:53:31 2007 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 {
2813 #font => default_font 2830 #font => default_font
2814 @_, 2831 @_,
2815 2832
2816 layout => (new CFPlus::Layout), 2833 layout => (new CFPlus::Layout),
2817 par => [], 2834 par => [],
2835 max_par => 0,
2818 height => 0, 2836 height => 0,
2819 children => [ 2837 children => [
2820 (new CFPlus::UI::Empty expand => 1), 2838 (new CFPlus::UI::Empty expand => 1),
2821 (new CFPlus::UI::Slider vertical => 1), 2839 (new CFPlus::UI::Slider vertical => 1),
2822 ], 2840 ],
2945 wrapped => 1, 2963 wrapped => 1,
2946 }; 2964 };
2947 2965
2948 $self->add (@{ $para->{widget} }) if @{ $para->{widget} }; 2966 $self->add (@{ $para->{widget} }) if @{ $para->{widget} };
2949 push @{$self->{par}}, $para; 2967 push @{$self->{par}}, $para;
2968 }
2969
2970 if (my $max = $self->{max_par}) {
2971 shift @{$self->{par}} while @{$self->{par}} > $max;
2950 } 2972 }
2951 2973
2952 $self->{need_reflow}++; 2974 $self->{need_reflow}++;
2953 $self->update; 2975 $self->update;
2954} 2976}
3268 can_events => 0, 3290 can_events => 0,
3269 @_, 3291 @_,
3270 ); 3292 );
3271 3293
3272 if ($self->{anim} && $self->{animspeed}) { 3294 if ($self->{anim} && $self->{animspeed}) {
3273 Scalar::Util::weaken (my $widget = $self); 3295 CFPlus::weaken (my $widget = $self);
3274 3296
3275 $self->{timer} = Event->timer ( 3297 $self->{timer} = Event->timer (
3276 at => $self->{animspeed} * int $::NOW / $self->{animspeed}, 3298 at => $self->{animspeed} * int $::NOW / $self->{animspeed},
3277 hard => 1, 3299 hard => 1,
3278 interval => $self->{animspeed}, 3300 interval => $self->{animspeed},
3532} 3554}
3533 3555
3534sub add { 3556sub add {
3535 my ($self, $title, $widget, $tooltip) = @_; 3557 my ($self, $title, $widget, $tooltip) = @_;
3536 3558
3537 Scalar::Util::weaken $self; 3559 CFPlus::weaken $self;
3538 3560
3539 $self->{buttonbar}->add (new CFPlus::UI::Button 3561 $self->{buttonbar}->add (new CFPlus::UI::Button
3540 markup => $title, 3562 markup => $title,
3541 tooltip => $tooltip, 3563 tooltip => $tooltip,
3542 on_activate => sub { $self->set_current_page ($widget) }, 3564 on_activate => sub { $self->set_current_page ($widget) },
3626 my $self = $class->SUPER::new ( 3648 my $self = $class->SUPER::new (
3627 fontsize => 0.8, 3649 fontsize => 0.8,
3628 @_, 3650 @_,
3629 ); 3651 );
3630 3652
3631 Scalar::Util::weaken (my $this = $self); 3653 CFPlus::weaken (my $this = $self);
3632 3654
3633 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 3655 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder });
3634 3656
3635 $self 3657 $self
3636} 3658}
3775 my $self = $class->SUPER::new ( 3797 my $self = $class->SUPER::new (
3776 visible => 1, 3798 visible => 1,
3777 @_, 3799 @_,
3778 ); 3800 );
3779 3801
3780 Scalar::Util::weaken ($self->{root} = $self); 3802 CFPlus::weaken ($self->{root} = $self);
3781 3803
3782 $self 3804 $self
3783} 3805}
3784 3806
3785sub size_request { 3807sub size_request {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines