… | |
… | |
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 | }; |
… | |
… | |
1138 | my ($class, %arg) = @_; |
1138 | my ($class, %arg) = @_; |
1139 | |
1139 | |
1140 | if ((exists $arg{label}) && !ref $arg{label}) { |
1140 | if ((exists $arg{label}) && !ref $arg{label}) { |
1141 | $arg{label} = new CFPlus::UI::Label |
1141 | $arg{label} = new CFPlus::UI::Label |
1142 | align => 1, |
1142 | align => 1, |
1143 | valign => 1, |
1143 | valign => 0, |
1144 | text => $arg{label}, |
1144 | text => $arg{label}, |
1145 | fontsize => ($arg{border} || 0.8) * 0.75; |
1145 | fontsize => ($arg{border} || 0.8) * 0.75; |
1146 | } |
1146 | } |
1147 | |
1147 | |
1148 | my $self = $class->SUPER::new ( |
1148 | my $self = $class->SUPER::new ( |
… | |
… | |
1966 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1966 | ++$self->{cursor} if $self->{cursor} < length $self->{text}; |
1967 | } elsif ($sym == CFPlus::SDLK_HOME) { |
1967 | } elsif ($sym == CFPlus::SDLK_HOME) { |
1968 | $self->{cursor} = 0; |
1968 | $self->{cursor} = 0; |
1969 | } elsif ($sym == CFPlus::SDLK_END) { |
1969 | } elsif ($sym == CFPlus::SDLK_END) { |
1970 | $self->{cursor} = length $text; |
1970 | $self->{cursor} = length $text; |
|
|
1971 | } elsif ($uni == 21) { # ctrl-u |
|
|
1972 | $text = ""; |
|
|
1973 | $self->{cursor} = 0; |
1971 | } elsif ($uni == 27) { |
1974 | } elsif ($uni == 27) { |
1972 | $self->emit ('escape'); |
1975 | $self->emit ('escape'); |
1973 | } elsif ($uni) { |
1976 | } elsif ($uni) { |
1974 | substr $text, $self->{cursor}++, 0, chr $uni; |
1977 | substr $text, $self->{cursor}++, 0, chr $uni; |
1975 | } else { |
1978 | } else { |
… | |
… | |
2853 | } |
2856 | } |
2854 | |
2857 | |
2855 | sub current_paragraph { |
2858 | sub current_paragraph { |
2856 | my ($self) = @_; |
2859 | my ($self) = @_; |
2857 | |
2860 | |
2858 | $self->force_uptodate; |
|
|
2859 | $self->{top_paragraph} - 1 |
2861 | $self->{top_paragraph} - 1 |
2860 | } |
2862 | } |
2861 | |
2863 | |
2862 | sub scroll_to { |
2864 | sub scroll_to { |
2863 | my ($self, $para) = @_; |
2865 | my ($self, $para) = @_; |
2864 | |
2866 | |
2865 | $self->force_uptodate; |
|
|
2866 | |
|
|
2867 | $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; |
2867 | $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; |
2868 | |
2868 | |
2869 | $self->{children}[1]->set_value ($self->{par}[$para]{y}); |
2869 | $self->{scroll_to} = $para; |
|
|
2870 | $self->update; |
2870 | } |
2871 | } |
2871 | |
2872 | |
2872 | sub clear { |
2873 | sub clear { |
2873 | my ($self) = @_; |
2874 | my ($self) = @_; |
2874 | |
2875 | |
… | |
… | |
2903 | } |
2904 | } |
2904 | |
2905 | |
2905 | sub scroll_to_bottom { |
2906 | sub scroll_to_bottom { |
2906 | my ($self) = @_; |
2907 | my ($self) = @_; |
2907 | |
2908 | |
2908 | $self->{scroll_to_bottom} = 1; |
2909 | $self->{scroll_to} = $#{$self->{par}}; |
2909 | $self->update; |
2910 | $self->update; |
2910 | } |
2911 | } |
2911 | |
2912 | |
2912 | sub force_uptodate { |
2913 | sub force_uptodate { |
2913 | my ($self) = @_; |
2914 | my ($self) = @_; |
2914 | |
2915 | |
2915 | if (delete $self->{need_reflow}) { |
2916 | if (delete $self->{need_reflow}) { |
2916 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2917 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2917 | |
2918 | |
2918 | my $height = 0; |
2919 | my $height = 0; |
2919 | my $paridx; |
|
|
2920 | my $top_paragraph; |
|
|
2921 | my $top = int $self->{children}[1]{range}[0]; |
|
|
2922 | |
2920 | |
2923 | for my $para (@{$self->{par}}) { |
2921 | for my $para (@{$self->{par}}) { |
2924 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
2922 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
2925 | my $layout = $self->get_layout ($para); |
2923 | my $layout = $self->get_layout ($para); |
2926 | my ($w, $h) = $layout->size; |
2924 | my ($w, $h) = $layout->size; |
… | |
… | |
2929 | $para->{h} = $h; |
2927 | $para->{h} = $h; |
2930 | $para->{wrapped} = $layout->has_wrapped; |
2928 | $para->{wrapped} = $layout->has_wrapped; |
2931 | } |
2929 | } |
2932 | |
2930 | |
2933 | $para->{y} = $height; |
2931 | $para->{y} = $height; |
2934 | |
|
|
2935 | $paridx++; |
|
|
2936 | $top_paragraph ||= $paridx if $height >= $top; |
|
|
2937 | |
|
|
2938 | $height += $para->{h}; |
2932 | $height += $para->{h}; |
2939 | } |
2933 | } |
2940 | |
2934 | |
2941 | $self->{top_paragraph} = $top_paragraph; |
|
|
2942 | $self->{height} = $height; |
2935 | $self->{height} = $height; |
2943 | |
|
|
2944 | $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]); |
2945 | |
2937 | |
2946 | delete $self->{texture}; |
2938 | delete $self->{texture}; |
2947 | } |
2939 | } |
2948 | |
2940 | |
2949 | if (delete $self->{scroll_to_bottom}) { |
2941 | if (my $paridx = delete $self->{scroll_to}) { |
2950 | $self->{children}[1]->set_value (1e10); |
2942 | $self->{children}[1]->set_value ($self->{par}[$paridx]{y}); |
2951 | } |
2943 | } |
2952 | } |
2944 | } |
2953 | |
2945 | |
2954 | sub update { |
2946 | sub update { |
2955 | my ($self) = @_; |
2947 | my ($self) = @_; |
… | |
… | |
2967 | |
2959 | |
2968 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
2960 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
2969 | glClearColor 0, 0, 0, 0; |
2961 | glClearColor 0, 0, 0, 0; |
2970 | glClear GL_COLOR_BUFFER_BIT; |
2962 | glClear GL_COLOR_BUFFER_BIT; |
2971 | |
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; |
2972 | my $top = int $self->{children}[1]{range}[0]; |
2975 | my $top = int $self->{children}[1]{range}[0]; |
2973 | |
2976 | |
2974 | my $y0 = $top; |
2977 | my $y0 = $top; |
2975 | my $y1 = $top + $H; |
2978 | my $y1 = $top + $H; |
2976 | |
2979 | |
… | |
… | |
2994 | |
2997 | |
2995 | $_->draw; |
2998 | $_->draw; |
2996 | } |
2999 | } |
2997 | } |
3000 | } |
2998 | } |
3001 | } |
|
|
3002 | |
|
|
3003 | $paridx++; |
|
|
3004 | $top_paragraph ||= $paridx if $y >= $top; |
2999 | } |
3005 | } |
|
|
3006 | |
|
|
3007 | $self->{top_paragraph} = $top_paragraph; |
3000 | }; |
3008 | }; |
3001 | }); |
3009 | }); |
3002 | } |
3010 | } |
3003 | |
3011 | |
3004 | sub reconfigure { |
3012 | sub reconfigure { |
… | |
… | |
3835 | } |
3843 | } |
3836 | |
3844 | |
3837 | 1 |
3845 | 1 |
3838 | }; |
3846 | }; |
3839 | |
3847 | |
3840 | my $tooltip = "$spell->{message}$TOOLTIP_ALL"; |
3848 | my $tooltip = (CFPlus::asxml $spell->{message}) . $TOOLTIP_ALL; |
3841 | |
3849 | |
3842 | #TODO: add path info to tooltip |
3850 | #TODO: add path info to tooltip |
3843 | #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); |
3851 | #$self->add (6, $row, new CFPlus::UI::Label text => $spell->{path}); |
3844 | |
3852 | |
3845 | $self->add (0, $row, new CFPlus::UI::Face |
3853 | $self->add (0, $row, new CFPlus::UI::Face |
… | |
… | |
4123 | glLoadIdentity; |
4131 | glLoadIdentity; |
4124 | |
4132 | |
4125 | { |
4133 | { |
4126 | package CFPlus::UI::Base; |
4134 | package CFPlus::UI::Base; |
4127 | |
4135 | |
4128 | ($draw_x, $draw_y, $draw_w, $draw_h) = |
4136 | local ($draw_x, $draw_y, $draw_w, $draw_h) = |
4129 | (0, 0, $self->{w}, $self->{h}); |
4137 | (0, 0, $self->{w}, $self->{h}); |
4130 | } |
4138 | } |
4131 | |
4139 | |
4132 | $self->_draw; |
4140 | $self->_draw; |
4133 | } |
4141 | } |