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.433 by root, Wed Aug 22 21:27:13 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
2841 2836
2842 glEnable GL_BLEND; 2837 glEnable GL_BLEND;
2843 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2838 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2844 2839
2845 if ($self->{value} >= 0) { 2840 if ($self->{value} >= 0) {
2846 my $s = 3 + ($self->{w} - 6) * $self->{value}; 2841 my $s = int 2 + ($self->{w} - 4) * $self->{value};
2847 2842
2848 glColor_premultiply @{$self->{bar}}; 2843 glColor_premultiply @{$self->{bar}};
2849 glRect 2, 2, $s, $self->{h} - 2; 2844 glRect 2, 2, $s, $self->{h} - 2;
2850 glColor_premultiply @{$self->{bg}}; 2845 glColor_premultiply @{$self->{bg}};
2851 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; 2846 glRect $s, 2, $self->{w} - 2, $self->{h} - 2;
2852 } 2847 }
2853 2848
2854 glColor_premultiply @{$self->{outline}}; 2849 glColor_premultiply @{$self->{outline}};
2855 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;
2856 2851
2857 glDisable GL_BLEND; 2852 glDisable GL_BLEND;
2858 2853
2859 { 2854 {
2860 local $self->{bg}; # do not draw background 2855 local $self->{bg}; # do not draw background
2870 2865
2871sub new { 2866sub new {
2872 my ($class, %arg) = @_; 2867 my ($class, %arg) = @_;
2873 2868
2874 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 },
2875 %arg 2879 %arg
2876 ); 2880 );
2877 2881
2878 $::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}) }
2879 if $::CONN; 2883 if $::CONN;
2890 $self->SUPER::DESTROY; 2894 $self->SUPER::DESTROY;
2891} 2895}
2892 2896
2893sub set_value { 2897sub set_value {
2894 my ($self, $lvl, $exp) = @_; 2898 my ($self, $lvl, $exp) = @_;
2899
2900 $self->{lvl} = $lvl;
2901 $self->{exp} = $exp;
2895 2902
2896 my $v = -1; 2903 my $v = -1;
2897 2904
2898 if ($::CONN && (my $table = $::CONN->{exp_table})) { 2905 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2899 my $l0 = $table->[$lvl - 1]; 2906 my $l0 = $table->[$lvl - 1];
2900 my $l1 = $table->[$lvl]; 2907 my $l1 = $table->[$lvl];
2908
2909 $self->{nxt} = $l1;
2901 2910
2902 $v = ($exp - $l0) / ($l1 - $l0); 2911 $v = ($exp - $l0) / ($l1 - $l0);
2903 } 2912 }
2904 2913
2905 $self->SUPER::set_value ($v); 2914 $self->SUPER::set_value ($v);
3543} 3552}
3544 3553
3545sub set_tooltip_from { 3554sub set_tooltip_from {
3546 my ($self, $widget) = @_; 3555 my ($self, $widget) = @_;
3547 3556
3548 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3549 if $widget->{tooltip} =~ /^#(.*)$/;
3550
3551 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 =~ /^#(.*)$/;
3552 3562
3553 if ($ENV{CFPLUS_DEBUG} & 2) { 3563 if ($ENV{CFPLUS_DEBUG} & 2) {
3554 $tooltip .= "\n\n" . (ref $widget) . "\n" 3564 $tip .= "\n\n" . (ref $widget) . "\n"
3555 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3565 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3556 . "req $widget->{req_w} $widget->{req_h}\n" 3566 . "req $widget->{req_w} $widget->{req_h}\n"
3557 . "visible $widget->{visible}"; 3567 . "visible $widget->{visible}";
3558 } 3568 }
3559 3569
3560 $tooltip =~ s/^\n+//; 3570 $tip =~ s/^\n+//;
3561 $tooltip =~ s/\n+$//; 3571 $tip =~ s/\n+$//;
3562 3572
3563 $self->add (new CFPlus::UI::Label 3573 $self->add (new CFPlus::UI::Label
3564 markup => $tooltip, 3574 markup => $tip,
3565 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3575 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3566 fontsize => 0.8, 3576 fontsize => 0.8,
3567 style => 1, # FLAG_INVERSE 3577 style => 1, # FLAG_INVERSE
3568 ellipsise => 0, 3578 ellipsise => 0,
3569 font => ($widget->{tooltip_font} || $::FONT_PROP), 3579 font => ($widget->{tooltip_font} || $::FONT_PROP),
3607} 3617}
3608 3618
3609sub _draw { 3619sub _draw {
3610 my ($self) = @_; 3620 my ($self) = @_;
3611 3621
3612 glTranslate 0.375, 0.375;
3613
3614 my ($w, $h) = @$self{qw(w h)}; 3622 my ($w, $h) = @$self{qw(w h)};
3615 3623
3616 glColor 1, 0.8, 0.4; 3624 glColor 1, 0.8, 0.4;
3617 glRect 0, 0, $w, $h; 3625 glRect 0, 0, $w, $h;
3618 3626
3619 glColor 0, 0, 0; 3627 glColor 0, 0, 0;
3620 glRect_lineloop 0, 0, $w, $h; 3628 glRect_lineloop .5, .5, $w + .5, $h + .5;
3621 3629
3622 glTranslate 2 - 0.375, 2 - 0.375; 3630 glTranslate 2, 2;
3623 3631
3624 $self->SUPER::_draw; 3632 $self->SUPER::_draw;
3625} 3633}
3626 3634
3627############################################################################# 3635#############################################################################
3954 my $class = shift; 3962 my $class = shift;
3955 3963
3956 my $self = $class->SUPER::new ( 3964 my $self = $class->SUPER::new (
3957 buttonbar => (new CFPlus::UI::Buttonbar), 3965 buttonbar => (new CFPlus::UI::Buttonbar),
3958 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3966 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3959 active_outline => [1, 1, 0], 3967 active_outline => [.7, .7, 0.2],
3960 # filter => # will be put between multiplexer and $self 3968 # filter => # will be put between multiplexer and $self
3961 @_, 3969 @_,
3962 ); 3970 );
3963 3971
3964 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3972 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
4045 4053
4046 $self->SUPER::_draw (); 4054 $self->SUPER::_draw ();
4047 4055
4048 if (my $cur = $self->{multiplexer}{current}) { 4056 if (my $cur = $self->{multiplexer}{current}) {
4049 if ($cur = $cur->{c_tab_}) { 4057 if ($cur = $cur->{c_tab_}) {
4050 glTranslate $cur->{x}, $cur->{y}; 4058 glTranslate $self->{buttonbar}{x} + $cur->{x},
4059 $self->{buttonbar}{y} + $cur->{y};
4051 glLineWidth 3; 4060 glLineWidth 3;
4061 #glEnable GL_BLEND;
4062 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4052 glColor @{$self->{active_outline}}; 4063 glColor @{$self->{active_outline}};
4053 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;
4054 glLineWidth 1; 4065 glLineWidth 1;
4066 #glDisable GL_BLEND;
4055 } 4067 }
4056 } 4068 }
4057} 4069}
4058 4070
4059############################################################################# 4071#############################################################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines