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.351 by root, Sun Oct 1 12:08:58 2006 UTC

898 glClear GL_COLOR_BUFFER_BIT; 898 glClear GL_COLOR_BUFFER_BIT;
899 899
900 { 900 {
901 package CFPlus::UI::Base; 901 package CFPlus::UI::Base;
902 902
903 ($draw_x, $draw_y, $draw_w, $draw_h) = 903 local ($draw_x, $draw_y, $draw_w, $draw_h) =
904 (0, 0, $self->{w}, $self->{h}); 904 (0, 0, $self->{w}, $self->{h});
905 } 905 }
906 906
907 $self->_render; 907 $self->_render;
908 }; 908 };
1127} 1127}
1128 1128
1129############################################################################# 1129#############################################################################
1130 1130
1131package CFPlus::UI::FancyFrame; 1131package CFPlus::UI::FancyFrame;
1132
1133our @ISA = CFPlus::UI::Bin::;
1134
1135use CFPlus::OpenGL;
1136
1137sub new {
1138 my ($class, %arg) = @_;
1139
1140 if ((exists $arg{label}) && !ref $arg{label}) {
1141 $arg{label} = new CFPlus::UI::Label
1142 align => 1,
1143 valign => 0,
1144 text => $arg{label},
1145 fontsize => ($arg{border} || 0.8) * 0.75;
1146 }
1147
1148 my $self = $class->SUPER::new (
1149 # label => "",
1150 fg => [0.6, 0.3, 0.1],
1151 border => 0.8,
1152 style => 'single',
1153 %arg,
1154 );
1155
1156 $self
1157}
1158
1159sub add {
1160 my ($self, @widgets) = @_;
1161
1162 $self->SUPER::add (@widgets);
1163 $self->CFPlus::UI::Container::add ($self->{label}) if $self->{label};
1164}
1165
1166sub border {
1167 int $_[0]{border} * $::FONTSIZE
1168}
1169
1170sub size_request {
1171 my ($self) = @_;
1172
1173 ($self->{label_w}, undef) = $self->{label}->size_request
1174 if $self->{label};
1175
1176 my ($w, $h) = $self->SUPER::size_request;
1177
1178 (
1179 $w + $self->border * 2,
1180 $h + $self->border * 2,
1181 )
1182}
1183
1184sub invoke_size_allocate {
1185 my ($self, $w, $h) = @_;
1186
1187 my $border = $self->border;
1188
1189 $w -= List::Util::max 0, $border * 2;
1190 $h -= List::Util::max 0, $border * 2;
1191
1192 if (my $label = $self->{label}) {
1193 $label->{w} = List::Util::max 0, List::Util::min $self->{label_w}, $w - $border * 2;
1194 $label->{h} = List::Util::min $h, $border;
1195 $label->invoke_size_allocate ($label->{w}, $label->{h});
1196 }
1197
1198 $self->child->configure ($border, $border, $w, $h);
1199
1200 1
1201}
1202
1203sub _draw {
1204 my ($self) = @_;
1205
1206 my $child = $self->{children}[0];
1207
1208 my $border = $self->border;
1209 my ($w, $h) = ($self->{w}, $self->{h});
1210
1211 $child->draw;
1212
1213 glColor @{$self->{fg}};
1214 glBegin GL_LINE_STRIP;
1215 glVertex $border * 1.5 , $border * 0.5 + 0.5;
1216 glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1217 glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1218 glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5;
1219 glVertex $w - $border * 0.5 + 0.5, $border * 0.5 + 0.5;
1220 glVertex $self->{label} ? $border * 2 + $self->{label}{w} : $border * 1.5, $border * 0.5 + 0.5;
1221 glEnd;
1222
1223 if ($self->{label}) {
1224 glTranslate $border * 2, 0;
1225 $self->{label}->_draw;
1226 }
1227}
1228
1229#############################################################################
1230
1231package CFPlus::UI::Toplevel;
1132 1232
1133our @ISA = CFPlus::UI::Bin::; 1233our @ISA = CFPlus::UI::Bin::;
1134 1234
1135use CFPlus::OpenGL; 1235use CFPlus::OpenGL;
1136 1236
1866 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 1966 ++$self->{cursor} if $self->{cursor} < length $self->{text};
1867 } elsif ($sym == CFPlus::SDLK_HOME) { 1967 } elsif ($sym == CFPlus::SDLK_HOME) {
1868 $self->{cursor} = 0; 1968 $self->{cursor} = 0;
1869 } elsif ($sym == CFPlus::SDLK_END) { 1969 } elsif ($sym == CFPlus::SDLK_END) {
1870 $self->{cursor} = length $text; 1970 $self->{cursor} = length $text;
1971 } elsif ($uni == 21) { # ctrl-u
1972 $text = "";
1973 $self->{cursor} = 0;
1871 } elsif ($uni == 27) { 1974 } elsif ($uni == 27) {
1872 $self->emit ('escape'); 1975 $self->emit ('escape');
1873 } elsif ($uni) { 1976 } elsif ($uni) {
1874 substr $text, $self->{cursor}++, 0, chr $uni; 1977 substr $text, $self->{cursor}++, 0, chr $uni;
1875 } else { 1978 } else {
2753} 2856}
2754 2857
2755sub current_paragraph { 2858sub current_paragraph {
2756 my ($self) = @_; 2859 my ($self) = @_;
2757 2860
2758 $self->force_uptodate;
2759 $self->{top_paragraph} - 1 2861 $self->{top_paragraph} - 1
2760} 2862}
2761 2863
2762sub scroll_to { 2864sub scroll_to {
2763 my ($self, $para) = @_; 2865 my ($self, $para) = @_;
2764 2866
2765 $self->force_uptodate;
2766
2767 $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; 2867 $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para;
2768 2868
2769 $self->{children}[1]->set_value ($self->{par}[$para]{y}); 2869 $self->{scroll_to} = $para;
2870 $self->update;
2770} 2871}
2771 2872
2772sub clear { 2873sub clear {
2773 my ($self) = @_; 2874 my ($self) = @_;
2774 2875
2803} 2904}
2804 2905
2805sub scroll_to_bottom { 2906sub scroll_to_bottom {
2806 my ($self) = @_; 2907 my ($self) = @_;
2807 2908
2808 $self->{scroll_to_bottom} = 1; 2909 $self->{scroll_to} = $#{$self->{par}};
2809 $self->update; 2910 $self->update;
2810} 2911}
2811 2912
2812sub force_uptodate { 2913sub force_uptodate {
2813 my ($self) = @_; 2914 my ($self) = @_;
2814 2915
2815 if (delete $self->{need_reflow}) { 2916 if (delete $self->{need_reflow}) {
2816 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 2917 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2817 2918
2818 my $height = 0; 2919 my $height = 0;
2819 my $paridx;
2820 my $top_paragraph;
2821 my $top = int $self->{children}[1]{range}[0];
2822 2920
2823 for my $para (@{$self->{par}}) { 2921 for my $para (@{$self->{par}}) {
2824 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { 2922 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) {
2825 my $layout = $self->get_layout ($para); 2923 my $layout = $self->get_layout ($para);
2826 my ($w, $h) = $layout->size; 2924 my ($w, $h) = $layout->size;
2829 $para->{h} = $h; 2927 $para->{h} = $h;
2830 $para->{wrapped} = $layout->has_wrapped; 2928 $para->{wrapped} = $layout->has_wrapped;
2831 } 2929 }
2832 2930
2833 $para->{y} = $height; 2931 $para->{y} = $height;
2834
2835 $paridx++;
2836 $top_paragraph ||= $paridx if $height >= $top;
2837
2838 $height += $para->{h}; 2932 $height += $para->{h};
2839 } 2933 }
2840 2934
2841 $self->{top_paragraph} = $top_paragraph;
2842 $self->{height} = $height; 2935 $self->{height} = $height;
2843
2844 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); 2936 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]);
2845 2937
2846 delete $self->{texture}; 2938 delete $self->{texture};
2847 } 2939 }
2848 2940
2849 if (delete $self->{scroll_to_bottom}) { 2941 if (my $paridx = delete $self->{scroll_to}) {
2850 $self->{children}[1]->set_value (1e10); 2942 $self->{children}[1]->set_value ($self->{par}[$paridx]{y});
2851 } 2943 }
2852} 2944}
2853 2945
2854sub update { 2946sub update {
2855 my ($self) = @_; 2947 my ($self) = @_;
2867 2959
2868 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 2960 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2869 glClearColor 0, 0, 0, 0; 2961 glClearColor 0, 0, 0, 0;
2870 glClear GL_COLOR_BUFFER_BIT; 2962 glClear GL_COLOR_BUFFER_BIT;
2871 2963
2964 {
2965 package CFPlus::UI::Base;
2966
2967 local ($draw_x, $draw_y, $draw_w, $draw_h) =
2968 (0, 0, $self->{w}, $self->{h});
2969 }
2970
2971 my $top = int $self->{children}[1]{range}[0];
2972
2973 my $paridx = 0;
2974 my $top_paragraph;
2872 my $top = int $self->{children}[1]{range}[0]; 2975 my $top = int $self->{children}[1]{range}[0];
2873 2976
2874 my $y0 = $top; 2977 my $y0 = $top;
2875 my $y1 = $top + $H; 2978 my $y1 = $top + $H;
2876 2979
2894 2997
2895 $_->draw; 2998 $_->draw;
2896 } 2999 }
2897 } 3000 }
2898 } 3001 }
3002
3003 $paridx++;
3004 $top_paragraph ||= $paridx if $y >= $top;
2899 } 3005 }
3006
3007 $self->{top_paragraph} = $top_paragraph;
2900 }; 3008 };
2901 }); 3009 });
2902} 3010}
2903 3011
2904sub reconfigure { 3012sub reconfigure {
3189 3297
3190############################################################################# 3298#############################################################################
3191 3299
3192package CFPlus::UI::Menu; 3300package CFPlus::UI::Menu;
3193 3301
3194our @ISA = CFPlus::UI::FancyFrame::; 3302our @ISA = CFPlus::UI::Toplevel::;
3195 3303
3196use CFPlus::OpenGL; 3304use CFPlus::OpenGL;
3197 3305
3198sub new { 3306sub new {
3199 my $class = shift; 3307 my $class = shift;
3735 } 3843 }
3736 3844
3737 1 3845 1
3738 }; 3846 };
3739 3847
3740 my $tooltip = "$spell->{message}$TOOLTIP_ALL"; 3848 my $tooltip = (CFPlus::asxml $spell->{message}) . $TOOLTIP_ALL;
3741 3849
3742 #TODO: add path info to tooltip 3850 #TODO: add path info to tooltip
3743 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); 3851 #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path});
3744 3852
3745 $self->add (0, $row, new CFPlus::UI::Face 3853 $self->add (0, $row, new CFPlus::UI::Face
4023 glLoadIdentity; 4131 glLoadIdentity;
4024 4132
4025 { 4133 {
4026 package CFPlus::UI::Base; 4134 package CFPlus::UI::Base;
4027 4135
4028 ($draw_x, $draw_y, $draw_w, $draw_h) = 4136 local ($draw_x, $draw_y, $draw_w, $draw_h) =
4029 (0, 0, $self->{w}, $self->{h}); 4137 (0, 0, $self->{w}, $self->{h});
4030 } 4138 }
4031 4139
4032 $self->_draw; 4140 $self->_draw;
4033} 4141}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines