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.342 by root, Sun Aug 13 14:38:35 2006 UTC vs.
Revision 1.345 by root, Sun Aug 13 21:46:10 2006 UTC

909} 909}
910 910
911sub _draw { 911sub _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#############################################################################
1618 #active_bg => none 1616 #active_bg => none
1619 #font => default_font 1617 #font => default_font
1620 #text => initial text 1618 #text => initial text
1621 #markup => initial narkup 1619 #markup => initial narkup
1622 #max_w => maximum pixel width 1620 #max_w => maximum pixel width
1621 #style => 0, # render flags
1623 ellipsise => 3, # end 1622 ellipsise => 3, # end
1624 layout => (new CFPlus::Layout), 1623 layout => (new CFPlus::Layout),
1625 fontsize => 1, 1624 fontsize => 1,
1626 align => -1, 1625 align => -1,
1627 valign => -1, 1626 valign => -1,
1778 }; 1777 };
1779 1778
1780 my $w = List::Util::min $self->{w} + 4, $size->[0]; 1779 my $w = List::Util::min $self->{w} + 4, $size->[0];
1781 my $h = List::Util::min $self->{h} + 2, $size->[1]; 1780 my $h = List::Util::min $self->{h} + 2, $size->[1];
1782 1781
1783 $self->{layout}->render ($self->{ox}, $self->{oy}); 1782 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
1784} 1783}
1785 1784
1786############################################################################# 1785#############################################################################
1787 1786
1788package CFPlus::UI::EntryBase; 1787package CFPlus::UI::EntryBase;
1949 utf8::encode $text; 1948 utf8::encode $text;
1950 1949
1951 @$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)
1952 } 1951 }
1953 1952
1954 glColor @{$self->{fg}};
1955 glBegin GL_LINES; 1953 glBegin GL_LINES;
1956 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};
1957 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};
1958 glEnd; 1956 glEnd;
1959 } 1957 }
1960} 1958}
1961 1959
1962package CFPlus::UI::Entry; 1960package CFPlus::UI::Entry;
2752 2750
2753 # todo: base offset on lines or so, not on pixels 2751 # todo: base offset on lines or so, not on pixels
2754 $self->{children}[1]->set_value ($offset); 2752 $self->{children}[1]->set_value ($offset);
2755} 2753}
2756 2754
2755sub current_paragraph {
2756 my ($self) = @_;
2757
2758 $self->force_uptodate;
2759 $self->{top_paragraph} - 1
2760}
2761
2762sub 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
2757sub clear { 2772sub clear {
2758 my ($self) = @_; 2773 my ($self) = @_;
2759 2774
2760 my (undef, undef, @other) = @{ $self->{children} }; 2775 my (undef, undef, @other) = @{ $self->{children} };
2761 $self->remove ($_) for @other; 2776 $self->remove ($_) for @other;
2792 2807
2793 $self->{scroll_to_bottom} = 1; 2808 $self->{scroll_to_bottom} = 1;
2794 $self->update; 2809 $self->update;
2795} 2810}
2796 2811
2812sub 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
2797sub update { 2854sub update {
2798 my ($self) = @_; 2855 my ($self) = @_;
2799 2856
2800 $self->SUPER::update; 2857 $self->SUPER::update;
2801 2858
2802 return unless $self->{h} > 0; 2859 return unless $self->{h} > 0;
2803 2860
2804 delete $self->{texture}; 2861 delete $self->{texture};
2805 2862
2806 $ROOT->on_post_alloc ($self => sub { 2863 $ROOT->on_post_alloc ($self => sub {
2864 $self->force_uptodate;
2865
2807 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 2866 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2808
2809 if (delete $self->{need_reflow}) {
2810 my $height = 0;
2811
2812 for my $para (@{$self->{par}}) {
2813 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) {
2814 my $layout = $self->get_layout ($para);
2815 my ($w, $h) = $layout->size;
2816
2817 $para->{w} = $w + $para->{indent};
2818 $para->{h} = $h;
2819 $para->{wrapped} = $layout->has_wrapped;
2820 }
2821
2822 $height += $para->{h};
2823 }
2824
2825 $self->{height} = $height;
2826
2827 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]);
2828
2829 delete $self->{texture};
2830 }
2831
2832 if (delete $self->{scroll_to_bottom}) {
2833 $self->{children}[1]->set_value (1e10);
2834 }
2835 2867
2836 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 2868 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2837 glClearColor 0, 0, 0, 0; 2869 glClearColor 0, 0, 0, 0;
2838 glClear GL_COLOR_BUFFER_BIT; 2870 glClear GL_COLOR_BUFFER_BIT;
2839 2871
2840 my $top = int $self->{children}[1]{range}[0]; 2872 my $top = int $self->{children}[1]{range}[0];
2841 2873
2842 my $y0 = $top; 2874 my $y0 = $top;
2843 my $y1 = $top + $H; 2875 my $y1 = $top + $H;
2844 2876
2845 my $y = 0;
2846
2847 for my $para (@{$self->{par}}) { 2877 for my $para (@{$self->{par}}) {
2848 my $h = $para->{h}; 2878 my $h = $para->{h};
2879 my $y = $para->{y};
2849 2880
2850 if ($y0 < $y + $h && $y < $y1) { 2881 if ($y0 < $y + $h && $y < $y1) {
2851
2852 my $layout = $self->get_layout ($para); 2882 my $layout = $self->get_layout ($para);
2853 2883
2854 $layout->render ($para->{indent}, $y - $y0); 2884 $layout->render ($para->{indent}, $y - $y0);
2855 2885
2856 if (my @w = @{ $para->{widget} }) { 2886 if (my @w = @{ $para->{widget} }) {
2864 2894
2865 $_->draw; 2895 $_->draw;
2866 } 2896 }
2867 } 2897 }
2868 } 2898 }
2869
2870 $y += $h;
2871 } 2899 }
2872 }; 2900 };
2873 }); 2901 });
2874} 2902}
2875 2903
2997 3025
2998 $self->add (new CFPlus::UI::Label 3026 $self->add (new CFPlus::UI::Label
2999 markup => $tooltip, 3027 markup => $tooltip,
3000 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3028 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3001 fontsize => 0.8, 3029 fontsize => 0.8,
3002 fg => [0, 0, 0, 1], 3030 style => 1, # FLAG_INVERSE
3003 ellipsise => 0, 3031 ellipsise => 0,
3004 font => ($widget->{tooltip_font} || $::FONT_PROP), 3032 font => ($widget->{tooltip_font} || $::FONT_PROP),
3005 ); 3033 );
3006} 3034}
3007 3035

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines