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.346 by root, Mon Aug 14 01:21:02 2006 UTC vs.
Revision 1.354 by root, Sat Nov 18 23:31:23 2006 UTC

514); 514);
515 515
516sub emit { 516sub emit {
517 my ($self, $signal, @args) = @_; 517 my ($self, $signal, @args) = @_;
518 518
519 # I do not really like this solution, but I dislike duplication 519 # I do not really like this solution, but I do not like duplication
520 # and needlessly verbose code, too. 520 # and needlessly verbose code, either.
521 my @append 521 my @append
522 = $has_coords{$signal} 522 = $has_coords{$signal}
523 ? $args[0]->xy ($self) 523 ? $args[0]->xy ($self)
524 : (); 524 : ();
525 525
526 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d# 526 #warn +(caller(1))[3] . "emit $signal on $self (parent $self->{parent})\n";#d#
527 527
528 if ($self->{tooltip} =~ /Apply.*audio/) {
529 warn "2 ", join ":", @{ $self->{signal_cb}{$signal} || []}, "\n";#d#
530 warn "3 $self->{parent}\n";#d#
531 }
532
528 #d##TODO# stop propagating at first true, do not use sum 533 #d##TODO# stop propagating at first true, do not use sum
534 my $res =
529 (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before 535 (List::Util::sum map $_->($self, @args, @append), @{$self->{signal_cb}{$signal} || []}) # before
530 || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure 536 || ($self->can ("invoke_$signal") || sub { 1 })->($self, @args, @append) # closure
531 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent 537 || ($self->{parent} && $self->{parent}->emit ($signal, @args)) # parent
538 ;
539 if ($self->{tooltip} =~ /Apply.*audio/) {
540 warn "4 ", join ":", @{ $self->{signal_cb}{$signal} || []}, "\n";#d#
541 warn "5 $self->{parent}\n";#d#
542 }
543
544 $res
532} 545}
533 546
534sub find_widget { 547sub find_widget {
535 my ($self, $x, $y) = @_; 548 my ($self, $x, $y) = @_;
536 549
898 glClear GL_COLOR_BUFFER_BIT; 911 glClear GL_COLOR_BUFFER_BIT;
899 912
900 { 913 {
901 package CFPlus::UI::Base; 914 package CFPlus::UI::Base;
902 915
903 ($draw_x, $draw_y, $draw_w, $draw_h) = 916 local ($draw_x, $draw_y, $draw_w, $draw_h) =
904 (0, 0, $self->{w}, $self->{h}); 917 (0, 0, $self->{w}, $self->{h});
918
919 $self->_render;
905 } 920 }
906
907 $self->_render;
908 }; 921 };
909} 922}
910 923
911sub _draw { 924sub _draw {
912 my ($self) = @_; 925 my ($self) = @_;
1138 my ($class, %arg) = @_; 1151 my ($class, %arg) = @_;
1139 1152
1140 if ((exists $arg{label}) && !ref $arg{label}) { 1153 if ((exists $arg{label}) && !ref $arg{label}) {
1141 $arg{label} = new CFPlus::UI::Label 1154 $arg{label} = new CFPlus::UI::Label
1142 align => 1, 1155 align => 1,
1143 valign => 1, 1156 valign => 0,
1144 text => $arg{label}, 1157 text => $arg{label},
1145 fontsize => ($arg{border} || 0.8) * 0.75; 1158 fontsize => ($arg{border} || 0.8) * 0.75;
1146 } 1159 }
1147 1160
1148 my $self = $class->SUPER::new ( 1161 my $self = $class->SUPER::new (
1966 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1979 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1967 } elsif ($sym == CFPlus::SDLK_HOME) { 1980 } elsif ($sym == CFPlus::SDLK_HOME) {
1968 $self->{cursor} = 0; 1981 $self->{cursor} = 0;
1969 } elsif ($sym == CFPlus::SDLK_END) { 1982 } elsif ($sym == CFPlus::SDLK_END) {
1970 $self->{cursor} = length $text; 1983 $self->{cursor} = length $text;
1984 } elsif ($uni == 21) { # ctrl-u
1985 $text = "";
1986 $self->{cursor} = 0;
1971 } elsif ($uni == 27) { 1987 } elsif ($uni == 27) {
1972 $self->emit ('escape'); 1988 $self->emit ('escape');
1973 } elsif ($uni) { 1989 } elsif ($uni) {
1974 substr $text, $self->{cursor}++, 0, chr $uni; 1990 substr $text, $self->{cursor}++, 0, chr $uni;
1975 } else { 1991 } else {
2853} 2869}
2854 2870
2855sub current_paragraph { 2871sub current_paragraph {
2856 my ($self) = @_; 2872 my ($self) = @_;
2857 2873
2858 $self->force_uptodate;
2859 $self->{top_paragraph} - 1 2874 $self->{top_paragraph} - 1
2860} 2875}
2861 2876
2862sub scroll_to { 2877sub scroll_to {
2863 my ($self, $para) = @_; 2878 my ($self, $para) = @_;
2864 2879
2865 $self->force_uptodate;
2866
2867 $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; 2880 $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para;
2868 2881
2869 $self->{children}[1]->set_value ($self->{par}[$para]{y}); 2882 $self->{scroll_to} = $para;
2883 $self->update;
2870} 2884}
2871 2885
2872sub clear { 2886sub clear {
2873 my ($self) = @_; 2887 my ($self) = @_;
2874 2888
2903} 2917}
2904 2918
2905sub scroll_to_bottom { 2919sub scroll_to_bottom {
2906 my ($self) = @_; 2920 my ($self) = @_;
2907 2921
2908 $self->{scroll_to_bottom} = 1; 2922 $self->{scroll_to} = $#{$self->{par}};
2909 $self->update; 2923 $self->update;
2910} 2924}
2911 2925
2912sub force_uptodate { 2926sub force_uptodate {
2913 my ($self) = @_; 2927 my ($self) = @_;
2914 2928
2915 if (delete $self->{need_reflow}) { 2929 if (delete $self->{need_reflow}) {
2916 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 2930 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2917 2931
2918 my $height = 0; 2932 my $height = 0;
2919 my $paridx;
2920 my $top_paragraph;
2921 my $top = int $self->{children}[1]{range}[0];
2922 2933
2923 for my $para (@{$self->{par}}) { 2934 for my $para (@{$self->{par}}) {
2924 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { 2935 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) {
2925 my $layout = $self->get_layout ($para); 2936 my $layout = $self->get_layout ($para);
2926 my ($w, $h) = $layout->size; 2937 my ($w, $h) = $layout->size;
2929 $para->{h} = $h; 2940 $para->{h} = $h;
2930 $para->{wrapped} = $layout->has_wrapped; 2941 $para->{wrapped} = $layout->has_wrapped;
2931 } 2942 }
2932 2943
2933 $para->{y} = $height; 2944 $para->{y} = $height;
2934
2935 $paridx++;
2936 $top_paragraph ||= $paridx if $height >= $top;
2937
2938 $height += $para->{h}; 2945 $height += $para->{h};
2939 } 2946 }
2940 2947
2941 $self->{top_paragraph} = $top_paragraph;
2942 $self->{height} = $height; 2948 $self->{height} = $height;
2943
2944 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); 2949 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]);
2945 2950
2946 delete $self->{texture}; 2951 delete $self->{texture};
2947 } 2952 }
2948 2953
2949 if (delete $self->{scroll_to_bottom}) { 2954 if (my $paridx = delete $self->{scroll_to}) {
2950 $self->{children}[1]->set_value (1e10); 2955 $self->{children}[1]->set_value ($self->{par}[$paridx]{y});
2951 } 2956 }
2952} 2957}
2953 2958
2954sub update { 2959sub update {
2955 my ($self) = @_; 2960 my ($self) = @_;
2967 2972
2968 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 2973 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2969 glClearColor 0, 0, 0, 0; 2974 glClearColor 0, 0, 0, 0;
2970 glClear GL_COLOR_BUFFER_BIT; 2975 glClear GL_COLOR_BUFFER_BIT;
2971 2976
2977 package CFPlus::UI::Base;
2978 local ($draw_x, $draw_y, $draw_w, $draw_h) =
2979 (0, 0, $self->{w}, $self->{h});
2980
2981 my $top = int $self->{children}[1]{range}[0];
2982
2983 my $paridx = 0;
2984 my $top_paragraph;
2972 my $top = int $self->{children}[1]{range}[0]; 2985 my $top = int $self->{children}[1]{range}[0];
2973 2986
2974 my $y0 = $top; 2987 my $y0 = $top;
2975 my $y1 = $top + $H; 2988 my $y1 = $top + $H;
2976 2989
2994 3007
2995 $_->draw; 3008 $_->draw;
2996 } 3009 }
2997 } 3010 }
2998 } 3011 }
3012
3013 $paridx++;
3014 $top_paragraph ||= $paridx if $y >= $top;
2999 } 3015 }
3016
3017 $self->{top_paragraph} = $top_paragraph;
3000 }; 3018 };
3001 }); 3019 });
3002} 3020}
3003 3021
3004sub reconfigure { 3022sub reconfigure {
3283 3301
3284package CFPlus::UI::Buttonbar; 3302package CFPlus::UI::Buttonbar;
3285 3303
3286our @ISA = CFPlus::UI::HBox::; 3304our @ISA = CFPlus::UI::HBox::;
3287 3305
3288# TODO: should actualyl wrap buttons and other goodies. 3306# TODO: should actually wrap buttons and other goodies.
3289 3307
3290############################################################################# 3308#############################################################################
3291 3309
3292package CFPlus::UI::Menu; 3310package CFPlus::UI::Menu;
3293 3311
3835 } 3853 }
3836 3854
3837 1 3855 1
3838 }; 3856 };
3839 3857
3840 my $tooltip = "$spell->{message}$TOOLTIP_ALL"; 3858 my $tooltip = (CFPlus::asxml $spell->{message}) . $TOOLTIP_ALL;
3841 3859
3842 #TODO: add path info to tooltip 3860 #TODO: add path info to tooltip
3843 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); 3861 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path});
3844 3862
3845 $self->add (0, $row, new CFPlus::UI::Face 3863 $self->add (0, $row, new CFPlus::UI::Face
4123 glLoadIdentity; 4141 glLoadIdentity;
4124 4142
4125 { 4143 {
4126 package CFPlus::UI::Base; 4144 package CFPlus::UI::Base;
4127 4145
4128 ($draw_x, $draw_y, $draw_w, $draw_h) = 4146 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4129 (0, 0, $self->{w}, $self->{h}); 4147 (0, 0, $self->{w}, $self->{h});
4130 }
4131 4148
4132 $self->_draw; 4149 $self->_draw;
4150 }
4133} 4151}
4134 4152
4135############################################################################# 4153#############################################################################
4136 4154
4137package CFPlus::UI; 4155package CFPlus::UI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines