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.432 by root, Tue Aug 21 23:42:02 2007 UTC vs.
Revision 1.437 by root, Wed Aug 22 22:36:26 2007 UTC

30 $TOOLTIP->{owner} = $widget; 30 $TOOLTIP->{owner} = $widget;
31 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; 31 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner};
32 32
33 return if $ENV{CFPLUS_DEBUG} & 8; 33 return if $ENV{CFPLUS_DEBUG} & 8;
34 34
35 my $tip = $widget->{tooltip};
36
37 $tip = $tip->($widget) if CODE:: eq ref $tip;
38
39 $TOOLTIP->set_tooltip_from ($widget); 35 $TOOLTIP->set_tooltip_from ($widget);
40 $TOOLTIP->show; 36 $TOOLTIP->show;
41 } 37 }
42 38
43 return; 39 return;
2237 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 2233 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2238 } 2234 }
2239 2235
2240 glColor_premultiply @{$self->{active_fg}}; 2236 glColor_premultiply @{$self->{active_fg}};
2241 glBegin GL_LINES; 2237 glBegin GL_LINES;
2242 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2238 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy};
2243 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 2239 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2244 glEnd; 2240 glEnd;
2245 2241
2246 glLineWidth 3; 2242 glLineWidth 3;
2247 glColor @{$self->{active_outline}}; 2243 glColor @{$self->{active_outline}};
2248 glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; 2244 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2249 glLineWidth 1; 2245 glLineWidth 1;
2250 2246
2251 } else { 2247 } else {
2252 glColor @{$self->{outline}}; 2248 glColor @{$self->{outline}};
2253 glTranslate .375, .375;
2254 glBegin GL_LINE_STRIP; 2249 glBegin GL_LINE_STRIP;
2255 glVertex 0, $self->{h} * .5; 2250 glVertex .5, $self->{h} * .5;
2256 glVertex 0, $self->{h} - 3; 2251 glVertex .5, $self->{h} - 2.5;
2257 glVertex $self->{w} - 1, $self->{h} - 3; 2252 glVertex $self->{w} - .5, $self->{h} - 2.5;
2258 glVertex $self->{w} - 1, $self->{h} * .5; 2253 glVertex $self->{w} - .5, $self->{h} * .5;
2259 glEnd; 2254 glEnd;
2260 } 2255 }
2261} 2256}
2262 2257
2263############################################################################# 2258#############################################################################
2512sub _draw { 2507sub _draw {
2513 my ($self) = @_; 2508 my ($self) = @_;
2514 2509
2515 $self->SUPER::_draw; 2510 $self->SUPER::_draw;
2516 2511
2517 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; 2512 glTranslate $self->{padding_x}, $self->{padding_y}, 0;
2518 2513
2519 my ($w, $h) = @$self{qw(w h)}; 2514 my ($w, $h) = @$self{qw(w h)};
2520 2515
2521 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; 2516 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2522 2517
2800 fontsize => 0.9, 2795 fontsize => 0.9,
2801 valign => 0, 2796 valign => 0,
2802 align => 0, 2797 align => 0,
2803 can_events => 1, 2798 can_events => 1,
2804 ellipsise => 1, 2799 ellipsise => 1,
2800 label => "%d%%",
2805 %arg, 2801 %arg,
2806 ); 2802 );
2807 2803
2808 $self->set_value ($arg{value} || -1); 2804 $self->set_value ($arg{value} || -1);
2809 2805
2810 $self 2806 $self
2811} 2807}
2812 2808
2809sub set_label {
2810 my ($self, $label) = @_;
2811
2812 return if $self->{label} eq $label;
2813 $self->{label} = $label;
2814
2815 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value});
2816}
2817
2813sub set_value { 2818sub set_value {
2814 my ($self, $value) = @_; 2819 my ($self, $value) = @_;
2815 2820
2816 if ($self->{value} != $value) { 2821 if ($self->{value} ne $value) {
2817 $self->{value} = $value; 2822 $self->{value} = $value;
2818 2823
2819 if ($value < 0) { 2824 if ($value < 0) {
2820 $self->set_text ("-"); 2825 $self->set_text ("-");
2821 } else { 2826 } else {
2822 $self->set_text (sprintf "%d%%", $value * 100); 2827 $self->set_text (sprintf $self->{label}, $value * 100);
2823 } 2828 }
2829
2824 $self->update; 2830 $self->update;
2825 } 2831 }
2826} 2832}
2827 2833
2828sub _draw { 2834sub _draw {
2830 2836
2831 glEnable GL_BLEND; 2837 glEnable GL_BLEND;
2832 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2838 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2833 2839
2834 if ($self->{value} >= 0) { 2840 if ($self->{value} >= 0) {
2835 my $s = 3 + ($self->{w} - 6) * $self->{value}; 2841 my $s = int 2 + ($self->{w} - 4) * $self->{value};
2836 2842
2837 glColor_premultiply @{$self->{bar}}; 2843 glColor_premultiply @{$self->{bar}};
2838 glRect 2, 2, $s, $self->{h} - 2; 2844 glRect 2, 2, $s, $self->{h} - 2;
2839 glColor_premultiply @{$self->{bg}}; 2845 glColor_premultiply @{$self->{bg}};
2840 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; 2846 glRect $s, 2, $self->{w} - 2, $self->{h} - 2;
2841 } 2847 }
2842 2848
2843 glColor_premultiply @{$self->{outline}}; 2849 glColor_premultiply @{$self->{outline}};
2844 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; 2850 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2845 2851
2846 glDisable GL_BLEND; 2852 glDisable GL_BLEND;
2847 2853
2848 { 2854 {
2849 local $self->{bg}; # do not draw background 2855 local $self->{bg}; # do not draw background
2859 2865
2860sub new { 2866sub new {
2861 my ($class, %arg) = @_; 2867 my ($class, %arg) = @_;
2862 2868
2863 my $self = $class->SUPER::new ( 2869 my $self = $class->SUPER::new (
2870 tooltip => sub {
2871 my ($self) = @_;
2872
2873 sprintf "level %d\n%s points\n%s next level\n%s to go",
2874 $self->{lvl},
2875 ::formsep ($self->{exp}),
2876 ::formsep ($self->{nxt}),
2877 ::formsep ($self->{nxt} - $self->{exp}),
2878 },
2864 %arg 2879 %arg
2865 ); 2880 );
2866 2881
2867 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2882 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2868 if $::CONN; 2883 if $::CONN;
2879 $self->SUPER::DESTROY; 2894 $self->SUPER::DESTROY;
2880} 2895}
2881 2896
2882sub set_value { 2897sub set_value {
2883 my ($self, $lvl, $exp) = @_; 2898 my ($self, $lvl, $exp) = @_;
2899
2900 $self->{lvl} = $lvl;
2901 $self->{exp} = $exp;
2884 2902
2885 my $v = -1; 2903 my $v = -1;
2886 2904
2887 if ($::CONN && (my $table = $::CONN->{exp_table})) { 2905 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2888 my $l0 = $table->[$lvl - 1]; 2906 my $l0 = $table->[$lvl - 1];
2889 my $l1 = $table->[$lvl]; 2907 my $l1 = $table->[$lvl];
2908
2909 $self->{nxt} = $l1;
2890 2910
2891 $v = ($exp - $l0) / ($l1 - $l0); 2911 $v = ($exp - $l0) / ($l1 - $l0);
2892 } 2912 }
2893 2913
2894 $self->SUPER::set_value ($v); 2914 $self->SUPER::set_value ($v);
3532} 3552}
3533 3553
3534sub set_tooltip_from { 3554sub set_tooltip_from {
3535 my ($self, $widget) = @_; 3555 my ($self, $widget) = @_;
3536 3556
3537 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3538 if $widget->{tooltip} =~ /^#(.*)$/;
3539
3540 my $tooltip = $widget->{tooltip}; 3557 my $tip = $widget->{tooltip};
3558 $tip = $tip->($widget) if "CODE" eq ref $tip;
3559
3560 $tip = CFPlus::Pod::section_label tooltip => $1
3561 if $tip =~ /^#(.*)$/;
3541 3562
3542 if ($ENV{CFPLUS_DEBUG} & 2) { 3563 if ($ENV{CFPLUS_DEBUG} & 2) {
3543 $tooltip .= "\n\n" . (ref $widget) . "\n" 3564 $tip .= "\n\n" . (ref $widget) . "\n"
3544 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3565 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3545 . "req $widget->{req_w} $widget->{req_h}\n" 3566 . "req $widget->{req_w} $widget->{req_h}\n"
3546 . "visible $widget->{visible}"; 3567 . "visible $widget->{visible}";
3547 } 3568 }
3548 3569
3549 $tooltip =~ s/^\n+//; 3570 $tip =~ s/^\n+//;
3550 $tooltip =~ s/\n+$//; 3571 $tip =~ s/\n+$//;
3551 3572
3552 $self->add (new CFPlus::UI::Label 3573 $self->add (new CFPlus::UI::Label
3553 markup => $tooltip, 3574 markup => $tip,
3554 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3575 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3555 fontsize => 0.8, 3576 fontsize => 0.8,
3556 style => 1, # FLAG_INVERSE 3577 style => 1, # FLAG_INVERSE
3557 ellipsise => 0, 3578 ellipsise => 0,
3558 font => ($widget->{tooltip_font} || $::FONT_PROP), 3579 font => ($widget->{tooltip_font} || $::FONT_PROP),
3596} 3617}
3597 3618
3598sub _draw { 3619sub _draw {
3599 my ($self) = @_; 3620 my ($self) = @_;
3600 3621
3601 glTranslate 0.375, 0.375;
3602
3603 my ($w, $h) = @$self{qw(w h)}; 3622 my ($w, $h) = @$self{qw(w h)};
3604 3623
3605 glColor 1, 0.8, 0.4; 3624 glColor 1, 0.8, 0.4;
3606 glRect 0, 0, $w, $h; 3625 glRect 0, 0, $w, $h;
3607 3626
3608 glColor 0, 0, 0; 3627 glColor 0, 0, 0;
3609 glRect_lineloop 0, 0, $w, $h; 3628 glRect_lineloop .5, .5, $w + .5, $h + .5;
3610 3629
3611 glTranslate 2 - 0.375, 2 - 0.375; 3630 glTranslate 2, 2;
3612 3631
3613 $self->SUPER::_draw; 3632 $self->SUPER::_draw;
3614} 3633}
3615 3634
3616############################################################################# 3635#############################################################################
3943 my $class = shift; 3962 my $class = shift;
3944 3963
3945 my $self = $class->SUPER::new ( 3964 my $self = $class->SUPER::new (
3946 buttonbar => (new CFPlus::UI::Buttonbar), 3965 buttonbar => (new CFPlus::UI::Buttonbar),
3947 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3966 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3948 active_outline => [1, 1, 0], 3967 active_outline => [.7, .7, 0.2],
3949 # filter => # will be put between multiplexer and $self 3968 # filter => # will be put between multiplexer and $self
3950 @_, 3969 @_,
3951 ); 3970 );
3952 3971
3953 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3972 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
4034 4053
4035 $self->SUPER::_draw (); 4054 $self->SUPER::_draw ();
4036 4055
4037 if (my $cur = $self->{multiplexer}{current}) { 4056 if (my $cur = $self->{multiplexer}{current}) {
4038 if ($cur = $cur->{c_tab_}) { 4057 if ($cur = $cur->{c_tab_}) {
4039 glTranslate $cur->{x}, $cur->{y}; 4058 glTranslate $self->{buttonbar}{x} + $cur->{x},
4059 $self->{buttonbar}{y} + $cur->{y};
4040 glLineWidth 3; 4060 glLineWidth 3;
4061 #glEnable GL_BLEND;
4062 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4041 glColor @{$self->{active_outline}}; 4063 glColor @{$self->{active_outline}};
4042 glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2; 4064 glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5;
4043 glLineWidth 1; 4065 glLineWidth 1;
4066 #glDisable GL_BLEND;
4044 } 4067 }
4045 } 4068 }
4046} 4069}
4047 4070
4048############################################################################# 4071#############################################################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines