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.345 by root, Sun Aug 13 21:46:10 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) = @_;
1127} 1140}
1128 1141
1129############################################################################# 1142#############################################################################
1130 1143
1131package CFPlus::UI::FancyFrame; 1144package CFPlus::UI::FancyFrame;
1145
1146our @ISA = CFPlus::UI::Bin::;
1147
1148use CFPlus::OpenGL;
1149
1150sub new {
1151 my ($class, %arg) = @_;
1152
1153 if ((exists $arg{label}) && !ref $arg{label}) {
1154 $arg{label} = new CFPlus::UI::Label
1155 align => 1,
1156 valign => 0,
1157 text => $arg{label},
1158 fontsize => ($arg{border} || 0.8) * 0.75;
1159 }
1160
1161 my $self = $class->SUPER::new (
1162 # label => "",
1163 fg => [0.6, 0.3, 0.1],
1164 border => 0.8,
1165 style => 'single',
1166 %arg,
1167 );
1168
1169 $self
1170}
1171
1172sub add {
1173 my ($self, @widgets) = @_;
1174
1175 $self->SUPER::add (@widgets);
1176 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label};
1177}
1178
1179sub border {
1180 int $_[0]{border} * $::FONTSIZE
1181}
1182
1183sub size_request {
1184 my ($self) = @_;
1185
1186 ($self->{label_w}, undef) = $self->{label}->size_request
1187 if $self->{label};
1188
1189 my ($w, $h) = $self->SUPER::size_request;
1190
1191 (
1192 $w + $self->border * 2,
1193 $h + $self->border * 2,
1194 )
1195}
1196
1197sub invoke_size_allocate {
1198 my ($self, $w, $h) = @_;
1199
1200 my $border = $self->border;
1201
1202 $w -= List::Util::max 0, $border * 2;
1203 $h -= List::Util::max 0, $border * 2;
1204
1205 if (my $label = $self->{label}) {
1206 $label->{w} = List::Util::max 0, List::Util::min $self->{label_w}, $w - $border * 2;
1207 $label->{h} = List::Util::min $h, $border;
1208 $label->invoke_size_allocate ($label->{w}, $label->{h});
1209 }
1210
1211 $self->child->configure ($border, $border, $w, $h);
1212
1213 1
1214}
1215
1216sub _draw {
1217 my ($self) = @_;
1218
1219 my $child = $self->{children}[0];
1220
1221 my $border = $self->border;
1222 my ($w, $h) = ($self->{w}, $self->{h});
1223
1224 $child->draw;
1225
1226 glColor @{$self->{fg}};
1227 glBegin GL_LINE_STRIP;
1228 glVertex $border * 1.5 , $border * 0.5 + 0.5;
1229 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1230 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1231 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1232 glVertex $w - $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1233 glVertex $self->{label} ? $border * 2 + $self->{label}{w} : $border * 1.5, $border * 0.5 + 0.5;
1234 glEnd;
1235
1236 if ($self->{label}) {
1237 glTranslate $border * 2, 0;
1238 $self->{label}->_draw;
1239 }
1240}
1241
1242#############################################################################
1243
1244package CFPlus::UI::Toplevel;
1132 1245
1133our @ISA = CFPlus::UI::Bin::; 1246our @ISA = CFPlus::UI::Bin::;
1134 1247
1135use CFPlus::OpenGL; 1248use CFPlus::OpenGL;
1136 1249
1866 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1979 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1867 } elsif ($sym == CFPlus::SDLK_HOME) { 1980 } elsif ($sym == CFPlus::SDLK_HOME) {
1868 $self->{cursor} = 0; 1981 $self->{cursor} = 0;
1869 } elsif ($sym == CFPlus::SDLK_END) { 1982 } elsif ($sym == CFPlus::SDLK_END) {
1870 $self->{cursor} = length $text; 1983 $self->{cursor} = length $text;
1984 } elsif ($uni == 21) { # ctrl-u
1985 $text = "";
1986 $self->{cursor} = 0;
1871 } elsif ($uni == 27) { 1987 } elsif ($uni == 27) {
1872 $self->emit ('escape'); 1988 $self->emit ('escape');
1873 } elsif ($uni) { 1989 } elsif ($uni) {
1874 substr $text, $self->{cursor}++, 0, chr $uni; 1990 substr $text, $self->{cursor}++, 0, chr $uni;
1875 } else { 1991 } else {
2753} 2869}
2754 2870
2755sub current_paragraph { 2871sub current_paragraph {
2756 my ($self) = @_; 2872 my ($self) = @_;
2757 2873
2758 $self->force_uptodate;
2759 $self->{top_paragraph} - 1 2874 $self->{top_paragraph} - 1
2760} 2875}
2761 2876
2762sub scroll_to { 2877sub scroll_to {
2763 my ($self, $para) = @_; 2878 my ($self, $para) = @_;
2764 2879
2765 $self->force_uptodate;
2766
2767 $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; 2880 $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para;
2768 2881
2769 $self->{children}[1]->set_value ($self->{par}[$para]{y}); 2882 $self->{scroll_to} = $para;
2883 $self->update;
2770} 2884}
2771 2885
2772sub clear { 2886sub clear {
2773 my ($self) = @_; 2887 my ($self) = @_;
2774 2888
2803} 2917}
2804 2918
2805sub scroll_to_bottom { 2919sub scroll_to_bottom {
2806 my ($self) = @_; 2920 my ($self) = @_;
2807 2921
2808 $self->{scroll_to_bottom} = 1; 2922 $self->{scroll_to} = $#{$self->{par}};
2809 $self->update; 2923 $self->update;
2810} 2924}
2811 2925
2812sub force_uptodate { 2926sub force_uptodate {
2813 my ($self) = @_; 2927 my ($self) = @_;
2814 2928
2815 if (delete $self->{need_reflow}) { 2929 if (delete $self->{need_reflow}) {
2816 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 2930 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2817 2931
2818 my $height = 0; 2932 my $height = 0;
2819 my $paridx;
2820 my $top_paragraph;
2821 my $top = int $self->{children}[1]{range}[0];
2822 2933
2823 for my $para (@{$self->{par}}) { 2934 for my $para (@{$self->{par}}) {
2824 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { 2935 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) {
2825 my $layout = $self->get_layout ($para); 2936 my $layout = $self->get_layout ($para);
2826 my ($w, $h) = $layout->size; 2937 my ($w, $h) = $layout->size;
2829 $para->{h} = $h; 2940 $para->{h} = $h;
2830 $para->{wrapped} = $layout->has_wrapped; 2941 $para->{wrapped} = $layout->has_wrapped;
2831 } 2942 }
2832 2943
2833 $para->{y} = $height; 2944 $para->{y} = $height;
2834
2835 $paridx++;
2836 $top_paragraph ||= $paridx if $height >= $top;
2837
2838 $height += $para->{h}; 2945 $height += $para->{h};
2839 } 2946 }
2840 2947
2841 $self->{top_paragraph} = $top_paragraph;
2842 $self->{height} = $height; 2948 $self->{height} = $height;
2843
2844 $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]);
2845 2950
2846 delete $self->{texture}; 2951 delete $self->{texture};
2847 } 2952 }
2848 2953
2849 if (delete $self->{scroll_to_bottom}) { 2954 if (my $paridx = delete $self->{scroll_to}) {
2850 $self->{children}[1]->set_value (1e10); 2955 $self->{children}[1]->set_value ($self->{par}[$paridx]{y});
2851 } 2956 }
2852} 2957}
2853 2958
2854sub update { 2959sub update {
2855 my ($self) = @_; 2960 my ($self) = @_;
2867 2972
2868 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 2973 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2869 glClearColor 0, 0, 0, 0; 2974 glClearColor 0, 0, 0, 0;
2870 glClear GL_COLOR_BUFFER_BIT; 2975 glClear GL_COLOR_BUFFER_BIT;
2871 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;
2872 my $top = int $self->{children}[1]{range}[0]; 2985 my $top = int $self->{children}[1]{range}[0];
2873 2986
2874 my $y0 = $top; 2987 my $y0 = $top;
2875 my $y1 = $top + $H; 2988 my $y1 = $top + $H;
2876 2989
2894 3007
2895 $_->draw; 3008 $_->draw;
2896 } 3009 }
2897 } 3010 }
2898 } 3011 }
3012
3013 $paridx++;
3014 $top_paragraph ||= $paridx if $y >= $top;
2899 } 3015 }
3016
3017 $self->{top_paragraph} = $top_paragraph;
2900 }; 3018 };
2901 }); 3019 });
2902} 3020}
2903 3021
2904sub reconfigure { 3022sub reconfigure {
3183 3301
3184package CFPlus::UI::Buttonbar; 3302package CFPlus::UI::Buttonbar;
3185 3303
3186our @ISA = CFPlus::UI::HBox::; 3304our @ISA = CFPlus::UI::HBox::;
3187 3305
3188# TODO: should actualyl wrap buttons and other goodies. 3306# TODO: should actually wrap buttons and other goodies.
3189 3307
3190############################################################################# 3308#############################################################################
3191 3309
3192package CFPlus::UI::Menu; 3310package CFPlus::UI::Menu;
3193 3311
3194our @ISA = CFPlus::UI::FancyFrame::; 3312our @ISA = CFPlus::UI::Toplevel::;
3195 3313
3196use CFPlus::OpenGL; 3314use CFPlus::OpenGL;
3197 3315
3198sub new { 3316sub new {
3199 my $class = shift; 3317 my $class = shift;
3735 } 3853 }
3736 3854
3737 1 3855 1
3738 }; 3856 };
3739 3857
3740 my $tooltip = "$spell->{message}$TOOLTIP_ALL"; 3858 my $tooltip = (CFPlus::asxml $spell->{message}) . $TOOLTIP_ALL;
3741 3859
3742 #TODO: add path info to tooltip 3860 #TODO: add path info to tooltip
3743 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); 3861 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path});
3744 3862
3745 $self->add (0, $row, new CFPlus::UI::Face 3863 $self->add (0, $row, new CFPlus::UI::Face
4023 glLoadIdentity; 4141 glLoadIdentity;
4024 4142
4025 { 4143 {
4026 package CFPlus::UI::Base; 4144 package CFPlus::UI::Base;
4027 4145
4028 ($draw_x, $draw_y, $draw_w, $draw_h) = 4146 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4029 (0, 0, $self->{w}, $self->{h}); 4147 (0, 0, $self->{w}, $self->{h});
4030 }
4031 4148
4032 $self->_draw; 4149 $self->_draw;
4150 }
4033} 4151}
4034 4152
4035############################################################################# 4153#############################################################################
4036 4154
4037package CFPlus::UI; 4155package CFPlus::UI;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines