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.439 by root, Sun Sep 16 13:04:36 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;
273 $self->emit ("destroy"); 269 $self->emit ("destroy");
274 %$self = (); 270 %$self = ();
275} 271}
276 272
277sub TO_JSON { 273sub TO_JSON {
278 { __w_ => $_[0]{s_id} } 274 { "\fw" => $_[0]{s_id} }
279} 275}
280 276
281sub show { 277sub show {
282 my ($self) = @_; 278 my ($self) = @_;
283 279
362 358
363 $self->{force_w} = $w; 359 $self->{force_w} = $w;
364 $self->{force_h} = $h; 360 $self->{force_h} = $h;
365 361
366 $self->realloc; 362 $self->realloc;
363}
364
365# travsle the widget chain up to find the maximum "physical" size constraints
366sub get_max_wh {
367 my ($self) = @_;
368
369 return ($self->{alloc_w}, $self->{alloc_h})
370 if $self->{alloc_w} && !$self->{root}{realloc}{$self+0};
371
372 return $self->{parent}->get_max_wh
373 if $self->{parent};
374
375 ($::WIDTH, $::HEIGHT)
367} 376}
368 377
369sub size_request { 378sub size_request {
370 require Carp; 379 require Carp;
371 Carp::confess "size_request is abstract"; 380 Carp::confess "size_request is abstract";
821 830
822 1 831 1
823} 832}
824 833
825############################################################################# 834#############################################################################
826
827# back-buffered drawing area 835# back-buffered drawing area
828 836
829package CFPlus::UI::Window; 837package CFPlus::UI::Window;
830 838
831our @ISA = CFPlus::UI::Bin::; 839our @ISA = CFPlus::UI::Bin::;
1946 1954
1947sub size_request { 1955sub size_request {
1948 my ($self) = @_; 1956 my ($self) = @_;
1949 1957
1950 $self->{size_req} ||= do { 1958 $self->{size_req} ||= do {
1959 my ($max_w, $max_h) = $self->get_max_wh;
1960
1951 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1961 $self->{layout}->set_font ($self->{font}) if $self->{font};
1952 $self->{layout}->set_width ($self->{max_w} || -1); 1962 $self->{layout}->set_width ($self->{max_w} || $max_w || -1);
1953 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1963 $self->{layout}->set_ellipsise ($self->{ellipsise});
1954 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1964 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1955 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1965 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1956 1966
1957 my ($w, $h) = $self->{layout}->size; 1967 my ($w, $h) = $self->{layout}->size;
2237 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 2247 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2238 } 2248 }
2239 2249
2240 glColor_premultiply @{$self->{active_fg}}; 2250 glColor_premultiply @{$self->{active_fg}};
2241 glBegin GL_LINES; 2251 glBegin GL_LINES;
2242 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2252 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}; 2253 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2244 glEnd; 2254 glEnd;
2245 2255
2246 glLineWidth 3; 2256 glLineWidth 3;
2247 glColor @{$self->{active_outline}}; 2257 glColor @{$self->{active_outline}};
2248 glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; 2258 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2249 glLineWidth 1; 2259 glLineWidth 1;
2250 2260
2251 } else { 2261 } else {
2252 glColor @{$self->{outline}}; 2262 glColor @{$self->{outline}};
2253 glTranslate .375, .375;
2254 glBegin GL_LINE_STRIP; 2263 glBegin GL_LINE_STRIP;
2255 glVertex 0, $self->{h} * .5; 2264 glVertex .5, $self->{h} * .5;
2256 glVertex 0, $self->{h} - 3; 2265 glVertex .5, $self->{h} - 2.5;
2257 glVertex $self->{w} - 1, $self->{h} - 3; 2266 glVertex $self->{w} - .5, $self->{h} - 2.5;
2258 glVertex $self->{w} - 1, $self->{h} * .5; 2267 glVertex $self->{w} - .5, $self->{h} * .5;
2259 glEnd; 2268 glEnd;
2260 } 2269 }
2261} 2270}
2262 2271
2263############################################################################# 2272#############################################################################
2512sub _draw { 2521sub _draw {
2513 my ($self) = @_; 2522 my ($self) = @_;
2514 2523
2515 $self->SUPER::_draw; 2524 $self->SUPER::_draw;
2516 2525
2517 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; 2526 glTranslate $self->{padding_x}, $self->{padding_y}, 0;
2518 2527
2519 my ($w, $h) = @$self{qw(w h)}; 2528 my ($w, $h) = @$self{qw(w h)};
2520 2529
2521 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; 2530 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2522 2531
2800 fontsize => 0.9, 2809 fontsize => 0.9,
2801 valign => 0, 2810 valign => 0,
2802 align => 0, 2811 align => 0,
2803 can_events => 1, 2812 can_events => 1,
2804 ellipsise => 1, 2813 ellipsise => 1,
2814 label => "%d%%",
2805 %arg, 2815 %arg,
2806 ); 2816 );
2807 2817
2808 $self->set_value ($arg{value} || -1); 2818 $self->set_value ($arg{value} || -1);
2809 2819
2810 $self 2820 $self
2811} 2821}
2812 2822
2823sub set_label {
2824 my ($self, $label) = @_;
2825
2826 return if $self->{label} eq $label;
2827 $self->{label} = $label;
2828
2829 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value});
2830}
2831
2813sub set_value { 2832sub set_value {
2814 my ($self, $value) = @_; 2833 my ($self, $value) = @_;
2815 2834
2816 if ($self->{value} != $value) { 2835 if ($self->{value} ne $value) {
2817 $self->{value} = $value; 2836 $self->{value} = $value;
2818 2837
2819 if ($value < 0) { 2838 if ($value < 0) {
2820 $self->set_text ("-"); 2839 $self->set_text ("-");
2821 } else { 2840 } else {
2822 $self->set_text (sprintf "%d%%", $value * 100); 2841 $self->set_text (sprintf $self->{label}, $value * 100);
2823 } 2842 }
2843
2824 $self->update; 2844 $self->update;
2825 } 2845 }
2826} 2846}
2827 2847
2828sub _draw { 2848sub _draw {
2830 2850
2831 glEnable GL_BLEND; 2851 glEnable GL_BLEND;
2832 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2852 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2833 2853
2834 if ($self->{value} >= 0) { 2854 if ($self->{value} >= 0) {
2835 my $s = 3 + ($self->{w} - 6) * $self->{value}; 2855 my $s = int 2 + ($self->{w} - 4) * $self->{value};
2836 2856
2837 glColor_premultiply @{$self->{bar}}; 2857 glColor_premultiply @{$self->{bar}};
2838 glRect 2, 2, $s, $self->{h} - 2; 2858 glRect 2, 2, $s, $self->{h} - 2;
2839 glColor_premultiply @{$self->{bg}}; 2859 glColor_premultiply @{$self->{bg}};
2840 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; 2860 glRect $s, 2, $self->{w} - 2, $self->{h} - 2;
2841 } 2861 }
2842 2862
2843 glColor_premultiply @{$self->{outline}}; 2863 glColor_premultiply @{$self->{outline}};
2844 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; 2864 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2845 2865
2846 glDisable GL_BLEND; 2866 glDisable GL_BLEND;
2847 2867
2848 { 2868 {
2849 local $self->{bg}; # do not draw background 2869 local $self->{bg}; # do not draw background
2859 2879
2860sub new { 2880sub new {
2861 my ($class, %arg) = @_; 2881 my ($class, %arg) = @_;
2862 2882
2863 my $self = $class->SUPER::new ( 2883 my $self = $class->SUPER::new (
2884 tooltip => sub {
2885 my ($self) = @_;
2886
2887 sprintf "level %d\n%s points\n%s next level\n%s to go",
2888 $self->{lvl},
2889 ::formsep ($self->{exp}),
2890 ::formsep ($self->{nxt}),
2891 ::formsep ($self->{nxt} - $self->{exp}),
2892 },
2864 %arg 2893 %arg
2865 ); 2894 );
2866 2895
2867 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2896 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2868 if $::CONN; 2897 if $::CONN;
2879 $self->SUPER::DESTROY; 2908 $self->SUPER::DESTROY;
2880} 2909}
2881 2910
2882sub set_value { 2911sub set_value {
2883 my ($self, $lvl, $exp) = @_; 2912 my ($self, $lvl, $exp) = @_;
2913
2914 $self->{lvl} = $lvl;
2915 $self->{exp} = $exp;
2884 2916
2885 my $v = -1; 2917 my $v = -1;
2886 2918
2887 if ($::CONN && (my $table = $::CONN->{exp_table})) { 2919 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2888 my $l0 = $table->[$lvl - 1]; 2920 my $l0 = $table->[$lvl - 1];
2889 my $l1 = $table->[$lvl]; 2921 my $l1 = $table->[$lvl];
2922
2923 $self->{nxt} = $l1;
2890 2924
2891 $v = ($exp - $l0) / ($l1 - $l0); 2925 $v = ($exp - $l0) / ($l1 - $l0);
2892 } 2926 }
2893 2927
2894 $self->SUPER::set_value ($v); 2928 $self->SUPER::set_value ($v);
3532} 3566}
3533 3567
3534sub set_tooltip_from { 3568sub set_tooltip_from {
3535 my ($self, $widget) = @_; 3569 my ($self, $widget) = @_;
3536 3570
3537 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3538 if $widget->{tooltip} =~ /^#(.*)$/;
3539
3540 my $tooltip = $widget->{tooltip}; 3571 my $tip = $widget->{tooltip};
3572 $tip = $tip->($widget) if "CODE" eq ref $tip;
3573
3574 $tip = CFPlus::Pod::section_label tooltip => $1
3575 if $tip =~ /^#(.*)$/;
3541 3576
3542 if ($ENV{CFPLUS_DEBUG} & 2) { 3577 if ($ENV{CFPLUS_DEBUG} & 2) {
3543 $tooltip .= "\n\n" . (ref $widget) . "\n" 3578 $tip .= "\n\n" . (ref $widget) . "\n"
3544 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3579 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3545 . "req $widget->{req_w} $widget->{req_h}\n" 3580 . "req $widget->{req_w} $widget->{req_h}\n"
3546 . "visible $widget->{visible}"; 3581 . "visible $widget->{visible}";
3547 } 3582 }
3548 3583
3549 $tooltip =~ s/^\n+//; 3584 $tip =~ s/^\n+//;
3550 $tooltip =~ s/\n+$//; 3585 $tip =~ s/\n+$//;
3551 3586
3552 $self->add (new CFPlus::UI::Label 3587 $self->add (new CFPlus::UI::Label
3553 markup => $tooltip, 3588 markup => $tip,
3554 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3589 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3555 fontsize => 0.8, 3590 fontsize => 0.8,
3556 style => 1, # FLAG_INVERSE 3591 style => 1, # FLAG_INVERSE
3557 ellipsise => 0, 3592 ellipsise => 0,
3558 font => ($widget->{tooltip_font} || $::FONT_PROP), 3593 font => ($widget->{tooltip_font} || $::FONT_PROP),
3596} 3631}
3597 3632
3598sub _draw { 3633sub _draw {
3599 my ($self) = @_; 3634 my ($self) = @_;
3600 3635
3601 glTranslate 0.375, 0.375;
3602
3603 my ($w, $h) = @$self{qw(w h)}; 3636 my ($w, $h) = @$self{qw(w h)};
3604 3637
3605 glColor 1, 0.8, 0.4; 3638 glColor 1, 0.8, 0.4;
3606 glRect 0, 0, $w, $h; 3639 glRect 0, 0, $w, $h;
3607 3640
3608 glColor 0, 0, 0; 3641 glColor 0, 0, 0;
3609 glRect_lineloop 0, 0, $w, $h; 3642 glRect_lineloop .5, .5, $w + .5, $h + .5;
3610 3643
3611 glTranslate 2 - 0.375, 2 - 0.375; 3644 glTranslate 2, 2;
3612 3645
3613 $self->SUPER::_draw; 3646 $self->SUPER::_draw;
3614} 3647}
3615 3648
3616############################################################################# 3649#############################################################################
3943 my $class = shift; 3976 my $class = shift;
3944 3977
3945 my $self = $class->SUPER::new ( 3978 my $self = $class->SUPER::new (
3946 buttonbar => (new CFPlus::UI::Buttonbar), 3979 buttonbar => (new CFPlus::UI::Buttonbar),
3947 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3980 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3948 active_outline => [1, 1, 0], 3981 active_outline => [.7, .7, 0.2],
3949 # filter => # will be put between multiplexer and $self 3982 # filter => # will be put between multiplexer and $self
3950 @_, 3983 @_,
3951 ); 3984 );
3952 3985
3953 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3986 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
4034 4067
4035 $self->SUPER::_draw (); 4068 $self->SUPER::_draw ();
4036 4069
4037 if (my $cur = $self->{multiplexer}{current}) { 4070 if (my $cur = $self->{multiplexer}{current}) {
4038 if ($cur = $cur->{c_tab_}) { 4071 if ($cur = $cur->{c_tab_}) {
4039 glTranslate $cur->{x}, $cur->{y}; 4072 glTranslate $self->{buttonbar}{x} + $cur->{x},
4073 $self->{buttonbar}{y} + $cur->{y};
4040 glLineWidth 3; 4074 glLineWidth 3;
4075 #glEnable GL_BLEND;
4076 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4041 glColor @{$self->{active_outline}}; 4077 glColor @{$self->{active_outline}};
4042 glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2; 4078 glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5;
4043 glLineWidth 1; 4079 glLineWidth 1;
4080 #glDisable GL_BLEND;
4044 } 4081 }
4045 } 4082 }
4046} 4083}
4047 4084
4048############################################################################# 4085#############################################################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines