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.340 by root, Sun Jul 30 13:16:44 2006 UTC vs.
Revision 1.345 by root, Sun Aug 13 21:46:10 2006 UTC

6use Scalar::Util (); 6use Scalar::Util ();
7use List::Util (); 7use List::Util ();
8use Event; 8use Event;
9 9
10use CFPlus; 10use CFPlus;
11use CFPlus::Pod;
11use CFPlus::Texture; 12use CFPlus::Texture;
12 13
13our ($FOCUS, $HOVER, $GRAB); # various widgets 14our ($FOCUS, $HOVER, $GRAB); # various widgets
14 15
15our $LAYOUT; 16our $LAYOUT;
908} 909}
909 910
910sub _draw { 911sub _draw {
911 my ($self) = @_; 912 my ($self) = @_;
912 913
913 my ($w, $h) = @$self{qw(w h)};
914
915 my $tex = $self->{texture} 914 my $tex = $self->{texture}
916 or return; 915 or return;
917 916
918 glEnable GL_TEXTURE_2D; 917 glEnable GL_TEXTURE_2D;
919 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; 918 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE;
920 glColor 0, 0, 0, 1; 919 glColor 0, 0, 0, 1;
921 920
922 $tex->draw_quad_alpha_premultiplied (0, 0, $w, $h); 921 $tex->draw_quad_alpha_premultiplied (0, 0);
923 922
924 glDisable GL_TEXTURE_2D; 923 glDisable GL_TEXTURE_2D;
925} 924}
926 925
927############################################################################# 926#############################################################################
1617 #active_bg => none 1616 #active_bg => none
1618 #font => default_font 1617 #font => default_font
1619 #text => initial text 1618 #text => initial text
1620 #markup => initial narkup 1619 #markup => initial narkup
1621 #max_w => maximum pixel width 1620 #max_w => maximum pixel width
1621 #style => 0, # render flags
1622 ellipsise => 3, # end 1622 ellipsise => 3, # end
1623 layout => (new CFPlus::Layout), 1623 layout => (new CFPlus::Layout),
1624 fontsize => 1, 1624 fontsize => 1,
1625 align => -1, 1625 align => -1,
1626 valign => -1, 1626 valign => -1,
1777 }; 1777 };
1778 1778
1779 my $w = List::Util::min $self->{w} + 4, $size->[0]; 1779 my $w = List::Util::min $self->{w} + 4, $size->[0];
1780 my $h = List::Util::min $self->{h} + 2, $size->[1]; 1780 my $h = List::Util::min $self->{h} + 2, $size->[1];
1781 1781
1782 $self->{layout}->render ($self->{ox}, $self->{oy}); 1782 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
1783} 1783}
1784 1784
1785############################################################################# 1785#############################################################################
1786 1786
1787package CFPlus::UI::EntryBase; 1787package CFPlus::UI::EntryBase;
1948 utf8::encode $text; 1948 utf8::encode $text;
1949 1949
1950 @$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)
1951 } 1951 }
1952 1952
1953 glColor @{$self->{fg}};
1954 glBegin GL_LINES; 1953 glBegin GL_LINES;
1955 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};
1956 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};
1957 glEnd; 1956 glEnd;
1958 } 1957 }
1959} 1958}
1960 1959
1961package CFPlus::UI::Entry; 1960package CFPlus::UI::Entry;
2751 2750
2752 # todo: base offset on lines or so, not on pixels 2751 # todo: base offset on lines or so, not on pixels
2753 $self->{children}[1]->set_value ($offset); 2752 $self->{children}[1]->set_value ($offset);
2754} 2753}
2755 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
2756sub clear { 2772sub clear {
2757 my ($self) = @_; 2773 my ($self) = @_;
2758 2774
2759 my (undef, undef, @other) = @{ $self->{children} }; 2775 my (undef, undef, @other) = @{ $self->{children} };
2760 $self->remove ($_) for @other; 2776 $self->remove ($_) for @other;
2791 2807
2792 $self->{scroll_to_bottom} = 1; 2808 $self->{scroll_to_bottom} = 1;
2793 $self->update; 2809 $self->update;
2794} 2810}
2795 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
2796sub update { 2854sub update {
2797 my ($self) = @_; 2855 my ($self) = @_;
2798 2856
2799 $self->SUPER::update; 2857 $self->SUPER::update;
2800 2858
2801 return unless $self->{h} > 0; 2859 return unless $self->{h} > 0;
2802 2860
2803 delete $self->{texture}; 2861 delete $self->{texture};
2804 2862
2805 $ROOT->on_post_alloc ($self => sub { 2863 $ROOT->on_post_alloc ($self => sub {
2864 $self->force_uptodate;
2865
2806 my ($W, $H) = @{$self->{children}[0]}{qw(w h)}; 2866 my ($W, $H) = @{$self->{children}[0]}{qw(w h)};
2807
2808 if (delete $self->{need_reflow}) {
2809 my $height = 0;
2810
2811 for my $para (@{$self->{par}}) {
2812 if ($para->{w} != $W && ($para->{wrapped} || $para->{w} > $W)) {
2813 my $layout = $self->get_layout ($para);
2814 my ($w, $h) = $layout->size;
2815
2816 $para->{w} = $w + $para->{indent};
2817 $para->{h} = $h;
2818 $para->{wrapped} = $layout->has_wrapped;
2819 }
2820
2821 $height += $para->{h};
2822 }
2823
2824 $self->{height} = $height;
2825
2826 $self->{children}[1]->set_range ([$self->{children}[1]{range}[0], 0, $height, $H, 1]);
2827
2828 delete $self->{texture};
2829 }
2830
2831 if (delete $self->{scroll_to_bottom}) {
2832 $self->{children}[1]->set_value (1e10);
2833 }
2834 2867
2835 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub { 2868 $self->{texture} ||= new_from_opengl CFPlus::Texture $W, $H, sub {
2836 glClearColor 0, 0, 0, 0; 2869 glClearColor 0, 0, 0, 0;
2837 glClear GL_COLOR_BUFFER_BIT; 2870 glClear GL_COLOR_BUFFER_BIT;
2838 2871
2839 my $top = int $self->{children}[1]{range}[0]; 2872 my $top = int $self->{children}[1]{range}[0];
2840 2873
2841 my $y0 = $top; 2874 my $y0 = $top;
2842 my $y1 = $top + $H; 2875 my $y1 = $top + $H;
2843 2876
2844 my $y = 0;
2845
2846 for my $para (@{$self->{par}}) { 2877 for my $para (@{$self->{par}}) {
2847 my $h = $para->{h}; 2878 my $h = $para->{h};
2879 my $y = $para->{y};
2848 2880
2849 if ($y0 < $y + $h && $y < $y1) { 2881 if ($y0 < $y + $h && $y < $y1) {
2850
2851 my $layout = $self->get_layout ($para); 2882 my $layout = $self->get_layout ($para);
2852 2883
2853 $layout->render ($para->{indent}, $y - $y0); 2884 $layout->render ($para->{indent}, $y - $y0);
2854 2885
2855 if (my @w = @{ $para->{widget} }) { 2886 if (my @w = @{ $para->{widget} }) {
2863 2894
2864 $_->draw; 2895 $_->draw;
2865 } 2896 }
2866 } 2897 }
2867 } 2898 }
2868
2869 $y += $h;
2870 } 2899 }
2871 }; 2900 };
2872 }); 2901 });
2873} 2902}
2874 2903
2977} 3006}
2978 3007
2979sub set_tooltip_from { 3008sub set_tooltip_from {
2980 my ($self, $widget) = @_; 3009 my ($self, $widget) = @_;
2981 3010
3011 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3012 if $widget->{tooltip} =~ /^#(.*)$/;
3013
2982 my $tooltip = $widget->{tooltip}; 3014 my $tooltip = $widget->{tooltip};
2983 3015
2984 if ($ENV{CFPLUS_DEBUG} & 2) { 3016 if ($ENV{CFPLUS_DEBUG} & 2) {
2985 $tooltip .= "\n\n" . (ref $widget) . "\n" 3017 $tooltip .= "\n\n" . (ref $widget) . "\n"
2986 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3018 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
2993 3025
2994 $self->add (new CFPlus::UI::Label 3026 $self->add (new CFPlus::UI::Label
2995 markup => $tooltip, 3027 markup => $tooltip,
2996 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3028 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
2997 fontsize => 0.8, 3029 fontsize => 0.8,
2998 fg => [0, 0, 0, 1], 3030 style => 1, # FLAG_INVERSE
2999 ellipsise => 0, 3031 ellipsise => 0,
3000 font => ($widget->{tooltip_font} || $::FONT_PROP), 3032 font => ($widget->{tooltip_font} || $::FONT_PROP),
3001 ); 3033 );
3002} 3034}
3003 3035

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines