… | |
… | |
909 | } |
909 | } |
910 | |
910 | |
911 | sub _draw { |
911 | sub _draw { |
912 | my ($self) = @_; |
912 | my ($self) = @_; |
913 | |
913 | |
914 | my ($w, $h) = @$self{qw(w h)}; |
|
|
915 | |
|
|
916 | my $tex = $self->{texture} |
914 | my $tex = $self->{texture} |
917 | or return; |
915 | or return; |
918 | |
916 | |
919 | glEnable GL_TEXTURE_2D; |
917 | glEnable GL_TEXTURE_2D; |
920 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
918 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
921 | glColor 0, 0, 0, 1; |
919 | glColor 0, 0, 0, 1; |
922 | |
920 | |
923 | $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); |
921 | $tex->draw_quad_alpha_premultiplied (0, 0); |
924 | |
922 | |
925 | glDisable GL_TEXTURE_2D; |
923 | glDisable GL_TEXTURE_2D; |
926 | } |
924 | } |
927 | |
925 | |
928 | ############################################################################# |
926 | ############################################################################# |
… | |
… | |
1950 | utf8::encode $text; |
1948 | utf8::encode $text; |
1951 | |
1949 | |
1952 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
1950 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
1953 | } |
1951 | } |
1954 | |
1952 | |
1955 | glColor @{$self->{fg}}; |
|
|
1956 | glBegin GL_LINES; |
1953 | glBegin GL_LINES; |
1957 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
1954 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
1958 | glVertex $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1955 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
1959 | glEnd; |
1956 | glEnd; |
1960 | } |
1957 | } |
1961 | } |
1958 | } |
1962 | |
1959 | |
1963 | package CFPlus::UI::Entry; |
1960 | package CFPlus::UI::Entry; |
… | |
… | |
2753 | |
2750 | |
2754 | # todo: base offset on lines or so, not on pixels |
2751 | # todo: base offset on lines or so, not on pixels |
2755 | $self->{children}[1]->set_value ($offset); |
2752 | $self->{children}[1]->set_value ($offset); |
2756 | } |
2753 | } |
2757 | |
2754 | |
|
|
2755 | sub current_paragraph { |
|
|
2756 | my ($self) = @_; |
|
|
2757 | |
|
|
2758 | $self->force_uptodate; |
|
|
2759 | $self->{top_paragraph} - 1 |
|
|
2760 | } |
|
|
2761 | |
|
|
2762 | sub scroll_to { |
|
|
2763 | my ($self, $para) = @_; |
|
|
2764 | |
|
|
2765 | $self->force_uptodate; |
|
|
2766 | |
|
|
2767 | $para = List::Util::max 0, List::Util::min $#{$self->{par}}, $para; |
|
|
2768 | |
|
|
2769 | $self->{children}[1]->set_value ($self->{par}[$para]{y}); |
|
|
2770 | } |
|
|
2771 | |
2758 | sub clear { |
2772 | sub clear { |
2759 | my ($self) = @_; |
2773 | my ($self) = @_; |
2760 | |
2774 | |
2761 | my (undef, undef, @other) = @{ $self->{children} }; |
2775 | my (undef, undef, @other) = @{ $self->{children} }; |
2762 | $self->remove ($_) for @other; |
2776 | $self->remove ($_) for @other; |
… | |
… | |
2793 | |
2807 | |
2794 | $self->{scroll_to_bottom} = 1; |
2808 | $self->{scroll_to_bottom} = 1; |
2795 | $self->update; |
2809 | $self->update; |
2796 | } |
2810 | } |
2797 | |
2811 | |
|
|
2812 | sub force_uptodate { |
|
|
2813 | my ($self) = @_; |
|
|
2814 | |
|
|
2815 | if (delete $self->{need_reflow}) { |
|
|
2816 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
|
|
2817 | |
|
|
2818 | my $height = 0; |
|
|
2819 | my $paridx; |
|
|
2820 | my $top_paragraph; |
|
|
2821 | my $top = int $self->{children}[1]{range}[0]; |
|
|
2822 | |
|
|
2823 | for my $para (@{$self->{par}}) { |
|
|
2824 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
|
|
2825 | my $layout = $self->get_layout ($para); |
|
|
2826 | my ($w, $h) = $layout->size; |
|
|
2827 | |
|
|
2828 | $para->{w} = $w + $para->{indent}; |
|
|
2829 | $para->{h} = $h; |
|
|
2830 | $para->{wrapped} = $layout->has_wrapped; |
|
|
2831 | } |
|
|
2832 | |
|
|
2833 | $para->{y} = $height; |
|
|
2834 | |
|
|
2835 | $paridx++; |
|
|
2836 | $top_paragraph ||= $paridx if $height >= $top; |
|
|
2837 | |
|
|
2838 | $height += $para->{h}; |
|
|
2839 | } |
|
|
2840 | |
|
|
2841 | $self->{top_paragraph} = $top_paragraph; |
|
|
2842 | $self->{height} = $height; |
|
|
2843 | |
|
|
2844 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
|
|
2845 | |
|
|
2846 | delete $self->{texture}; |
|
|
2847 | } |
|
|
2848 | |
|
|
2849 | if (delete $self->{scroll_to_bottom}) { |
|
|
2850 | $self->{children}[1]->set_value (1e10); |
|
|
2851 | } |
|
|
2852 | } |
|
|
2853 | |
2798 | sub update { |
2854 | sub update { |
2799 | my ($self) = @_; |
2855 | my ($self) = @_; |
2800 | |
2856 | |
2801 | $self->SUPER::update; |
2857 | $self->SUPER::update; |
2802 | |
2858 | |
2803 | return unless $self->{h} > 0; |
2859 | return unless $self->{h} > 0; |
2804 | |
2860 | |
2805 | delete $self->{texture}; |
2861 | delete $self->{texture}; |
2806 | |
2862 | |
2807 | $ROOT->on_post_alloc ($self => sub { |
2863 | $ROOT->on_post_alloc ($self => sub { |
|
|
2864 | $self->force_uptodate; |
|
|
2865 | |
2808 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2866 | my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; |
2809 | |
|
|
2810 | if (delete $self->{need_reflow}) { |
|
|
2811 | my $height = 0; |
|
|
2812 | |
|
|
2813 | for my $para (@{$self->{par}}) { |
|
|
2814 | if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) { |
|
|
2815 | my $layout = $self->get_layout ($para); |
|
|
2816 | my ($w, $h) = $layout->size; |
|
|
2817 | |
|
|
2818 | $para->{w} = $w + $para->{indent}; |
|
|
2819 | $para->{h} = $h; |
|
|
2820 | $para->{wrapped} = $layout->has_wrapped; |
|
|
2821 | } |
|
|
2822 | |
|
|
2823 | $height += $para->{h}; |
|
|
2824 | } |
|
|
2825 | |
|
|
2826 | $self->{height} = $height; |
|
|
2827 | |
|
|
2828 | $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]); |
|
|
2829 | |
|
|
2830 | delete $self->{texture}; |
|
|
2831 | } |
|
|
2832 | |
|
|
2833 | if (delete $self->{scroll_to_bottom}) { |
|
|
2834 | $self->{children}[1]->set_value (1e10); |
|
|
2835 | } |
|
|
2836 | |
2867 | |
2837 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
2868 | $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { |
2838 | glClearColor 0, 0, 0, 0; |
2869 | glClearColor 0, 0, 0, 0; |
2839 | glClear GL_COLOR_BUFFER_BIT; |
2870 | glClear GL_COLOR_BUFFER_BIT; |
2840 | |
2871 | |
2841 | my $top = int $self->{children}[1]{range}[0]; |
2872 | my $top = int $self->{children}[1]{range}[0]; |
2842 | |
2873 | |
2843 | my $y0 = $top; |
2874 | my $y0 = $top; |
2844 | my $y1 = $top + $H; |
2875 | my $y1 = $top + $H; |
2845 | |
2876 | |
2846 | my $y = 0; |
|
|
2847 | |
|
|
2848 | for my $para (@{$self->{par}}) { |
2877 | for my $para (@{$self->{par}}) { |
2849 | my $h = $para->{h}; |
2878 | my $h = $para->{h}; |
|
|
2879 | my $y = $para->{y}; |
2850 | |
2880 | |
2851 | if ($y0 < $y + $h && $y < $y1) { |
2881 | if ($y0 < $y + $h && $y < $y1) { |
2852 | |
|
|
2853 | my $layout = $self->get_layout ($para); |
2882 | my $layout = $self->get_layout ($para); |
2854 | |
2883 | |
2855 | $layout->render ($para->{indent}, $y - $y0); |
2884 | $layout->render ($para->{indent}, $y - $y0); |
2856 | |
2885 | |
2857 | if (my @w = @{ $para->{widget} }) { |
2886 | if (my @w = @{ $para->{widget} }) { |
… | |
… | |
2865 | |
2894 | |
2866 | $_->draw; |
2895 | $_->draw; |
2867 | } |
2896 | } |
2868 | } |
2897 | } |
2869 | } |
2898 | } |
2870 | |
|
|
2871 | $y += $h; |
|
|
2872 | } |
2899 | } |
2873 | }; |
2900 | }; |
2874 | }); |
2901 | }); |
2875 | } |
2902 | } |
2876 | |
2903 | |