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.430 by root, Tue Aug 21 02:39:17 2007 UTC vs.
Revision 1.442 by root, Mon Oct 8 17:01:03 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# traverse the widget chain up to find the maximum "physical" size constraints
366sub get_max_wh {
367 my ($self) = @_;
368
369 return $self->{parent}->get_max_wh
370 if $self->{parent};
371
372 ($::WIDTH, $::HEIGHT)
367} 373}
368 374
369sub size_request { 375sub size_request {
370 require Carp; 376 require Carp;
371 Carp::confess "size_request is abstract"; 377 Carp::confess "size_request is abstract";
821 827
822 1 828 1
823} 829}
824 830
825############################################################################# 831#############################################################################
826
827# back-buffered drawing area 832# back-buffered drawing area
828 833
829package CFPlus::UI::Window; 834package CFPlus::UI::Window;
830 835
831our @ISA = CFPlus::UI::Bin::; 836our @ISA = CFPlus::UI::Bin::;
1380 $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; 1385 $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget};
1381} 1386}
1382 1387
1383sub border { 1388sub border {
1384 int $_[0]{border} * $::FONTSIZE 1389 int $_[0]{border} * $::FONTSIZE
1390}
1391
1392sub get_max_wh {
1393 my ($self) = @_;
1394
1395 return ($self->{w}, $self->{h})
1396 if $self->{visible} && $self->{w};
1397
1398 $self->SUPER::get_max_wh
1385} 1399}
1386 1400
1387sub size_request { 1401sub size_request {
1388 my ($self) = @_; 1402 my ($self) = @_;
1389 1403
1946 1960
1947sub size_request { 1961sub size_request {
1948 my ($self) = @_; 1962 my ($self) = @_;
1949 1963
1950 $self->{size_req} ||= do { 1964 $self->{size_req} ||= do {
1965 my ($max_w, $max_h) = $self->get_max_wh;
1966
1951 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1967 $self->{layout}->set_font ($self->{font}) if $self->{font};
1952 $self->{layout}->set_width ($self->{max_w} || -1); 1968 $self->{layout}->set_width ($self->{max_w} || $max_w || -1);
1953 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1969 $self->{layout}->set_ellipsise ($self->{ellipsise});
1954 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1970 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1955 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1971 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1956 1972
1957 my ($w, $h) = $self->{layout}->size; 1973 my ($w, $h) = $self->{layout}->size;
2237 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); 2253 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2238 } 2254 }
2239 2255
2240 glColor_premultiply @{$self->{active_fg}}; 2256 glColor_premultiply @{$self->{active_fg}};
2241 glBegin GL_LINES; 2257 glBegin GL_LINES;
2242 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2258 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}; 2259 glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2244 glEnd; 2260 glEnd;
2245 2261
2246 glLineWidth 3; 2262 glLineWidth 3;
2247 glColor @{$self->{active_outline}}; 2263 glColor @{$self->{active_outline}};
2248 glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; 2264 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2249 glLineWidth 1; 2265 glLineWidth 1;
2250 2266
2251 } else { 2267 } else {
2252 glColor @{$self->{outline}}; 2268 glColor @{$self->{outline}};
2253 glTranslate .375, .375;
2254 glBegin GL_LINE_STRIP; 2269 glBegin GL_LINE_STRIP;
2255 glVertex 0, $self->{h} * .5; 2270 glVertex .5, $self->{h} * .5;
2256 glVertex 0, $self->{h} - 3; 2271 glVertex .5, $self->{h} - 2.5;
2257 glVertex $self->{w} - 1, $self->{h} - 3; 2272 glVertex $self->{w} - .5, $self->{h} - 2.5;
2258 glVertex $self->{w} - 1, $self->{h} * .5; 2273 glVertex $self->{w} - .5, $self->{h} * .5;
2259 glEnd; 2274 glEnd;
2260 } 2275 }
2261} 2276}
2262 2277
2263############################################################################# 2278#############################################################################
2512sub _draw { 2527sub _draw {
2513 my ($self) = @_; 2528 my ($self) = @_;
2514 2529
2515 $self->SUPER::_draw; 2530 $self->SUPER::_draw;
2516 2531
2517 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; 2532 glTranslate $self->{padding_x}, $self->{padding_y}, 0;
2518 2533
2519 my ($w, $h) = @$self{qw(w h)}; 2534 my ($w, $h) = @$self{qw(w h)};
2520 2535
2521 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; 2536 my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2;
2522 2537
2800 fontsize => 0.9, 2815 fontsize => 0.9,
2801 valign => 0, 2816 valign => 0,
2802 align => 0, 2817 align => 0,
2803 can_events => 1, 2818 can_events => 1,
2804 ellipsise => 1, 2819 ellipsise => 1,
2820 label => "%d%%",
2805 %arg, 2821 %arg,
2806 text => "-",
2807 value => -1,
2808 ); 2822 );
2809 2823
2810 $self->set_value ($arg{value}) if exists $arg{value}; 2824 $self->set_value ($arg{value} || -1);
2811 2825
2812 $self 2826 $self
2827}
2828
2829sub set_label {
2830 my ($self, $label) = @_;
2831
2832 return if $self->{label} eq $label;
2833 $self->{label} = $label;
2834
2835 $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value});
2813} 2836}
2814 2837
2815sub set_value { 2838sub set_value {
2816 my ($self, $value) = @_; 2839 my ($self, $value) = @_;
2817 2840
2818 if ($self->{value} != $value) { 2841 if ($self->{value} ne $value) {
2819 $self->{value} = $value; 2842 $self->{value} = $value;
2843
2844 if ($value < 0) {
2845 $self->set_text ("-");
2846 } else {
2820 $self->set_text (sprintf "%d%%", $value * 100); 2847 $self->set_text (sprintf $self->{label}, $value * 100);
2848 }
2849
2821 $self->update; 2850 $self->update;
2822 } 2851 }
2823} 2852}
2824 2853
2825sub _draw { 2854sub _draw {
2827 2856
2828 glEnable GL_BLEND; 2857 glEnable GL_BLEND;
2829 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2858 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2830 2859
2831 if ($self->{value} >= 0) { 2860 if ($self->{value} >= 0) {
2832 my $s = 3 + ($self->{w} - 6) * $self->{value}; 2861 my $s = int 2 + ($self->{w} - 4) * $self->{value};
2833 2862
2834 glColor_premultiply @{$self->{bar}}; 2863 glColor_premultiply @{$self->{bar}};
2835 glRect 2, 2, $s, $self->{h} - 2; 2864 glRect 2, 2, $s, $self->{h} - 2;
2836 glColor_premultiply @{$self->{bg}}; 2865 glColor_premultiply @{$self->{bg}};
2837 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; 2866 glRect $s, 2, $self->{w} - 2, $self->{h} - 2;
2838 } 2867 }
2839 2868
2840 glColor_premultiply @{$self->{outline}}; 2869 glColor_premultiply @{$self->{outline}};
2841 glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; 2870 glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5;
2842 2871
2843 glDisable GL_BLEND; 2872 glDisable GL_BLEND;
2844 2873
2845 { 2874 {
2846 local $self->{bg}; # do not draw background 2875 local $self->{bg}; # do not draw background
2856 2885
2857sub new { 2886sub new {
2858 my ($class, %arg) = @_; 2887 my ($class, %arg) = @_;
2859 2888
2860 my $self = $class->SUPER::new ( 2889 my $self = $class->SUPER::new (
2890 tooltip => sub {
2891 my ($self) = @_;
2892
2893 sprintf "level %d\n%s points\n%s next level\n%s to go",
2894 $self->{lvl},
2895 ::formsep ($self->{exp}),
2896 ::formsep ($self->{nxt}),
2897 ::formsep ($self->{nxt} - $self->{exp}),
2898 },
2861 %arg 2899 %arg
2862 ); 2900 );
2863 2901
2864 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2902 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2865 if $::CONN; 2903 if $::CONN;
2877} 2915}
2878 2916
2879sub set_value { 2917sub set_value {
2880 my ($self, $lvl, $exp) = @_; 2918 my ($self, $lvl, $exp) = @_;
2881 2919
2920 $self->{lvl} = $lvl;
2921 $self->{exp} = $exp;
2922
2882 my $v = 0; 2923 my $v = -1;
2883 2924
2884 if ($::CONN && (my $table = $::CONN->{exp_table})) { 2925 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2885 my $l0 = $table->[$lvl - 1]; 2926 my $l0 = $table->[$lvl - 1];
2886 my $l1 = $table->[$lvl]; 2927 my $l1 = $table->[$lvl];
2928
2929 $self->{nxt} = $l1;
2887 2930
2888 $v = ($exp - $l0) / ($l1 - $l0); 2931 $v = ($exp - $l0) / ($l1 - $l0);
2889 } 2932 }
2890 2933
2891 $self->SUPER::set_value ($v); 2934 $self->SUPER::set_value ($v);
3529} 3572}
3530 3573
3531sub set_tooltip_from { 3574sub set_tooltip_from {
3532 my ($self, $widget) = @_; 3575 my ($self, $widget) = @_;
3533 3576
3534 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3535 if $widget->{tooltip} =~ /^#(.*)$/;
3536
3537 my $tooltip = $widget->{tooltip}; 3577 my $tip = $widget->{tooltip};
3578 $tip = $tip->($widget) if "CODE" eq ref $tip;
3579
3580 $tip = CFPlus::Pod::section_label tooltip => $1
3581 if $tip =~ /^#(.*)$/;
3538 3582
3539 if ($ENV{CFPLUS_DEBUG} & 2) { 3583 if ($ENV{CFPLUS_DEBUG} & 2) {
3540 $tooltip .= "\n\n" . (ref $widget) . "\n" 3584 $tip .= "\n\n" . (ref $widget) . "\n"
3541 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3585 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3542 . "req $widget->{req_w} $widget->{req_h}\n" 3586 . "req $widget->{req_w} $widget->{req_h}\n"
3543 . "visible $widget->{visible}"; 3587 . "visible $widget->{visible}";
3544 } 3588 }
3545 3589
3546 $tooltip =~ s/^\n+//; 3590 $tip =~ s/^\n+//;
3547 $tooltip =~ s/\n+$//; 3591 $tip =~ s/\n+$//;
3548 3592
3549 $self->add (new CFPlus::UI::Label 3593 $self->add (new CFPlus::UI::Label
3550 markup => $tooltip, 3594 markup => $tip,
3551 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3595 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3552 fontsize => 0.8, 3596 fontsize => 0.8,
3553 style => 1, # FLAG_INVERSE 3597 style => 1, # FLAG_INVERSE
3554 ellipsise => 0, 3598 ellipsise => 0,
3555 font => ($widget->{tooltip_font} || $::FONT_PROP), 3599 font => ($widget->{tooltip_font} || $::FONT_PROP),
3593} 3637}
3594 3638
3595sub _draw { 3639sub _draw {
3596 my ($self) = @_; 3640 my ($self) = @_;
3597 3641
3598 glTranslate 0.375, 0.375;
3599
3600 my ($w, $h) = @$self{qw(w h)}; 3642 my ($w, $h) = @$self{qw(w h)};
3601 3643
3602 glColor 1, 0.8, 0.4; 3644 glColor 1, 0.8, 0.4;
3603 glRect 0, 0, $w, $h; 3645 glRect 0, 0, $w, $h;
3604 3646
3605 glColor 0, 0, 0; 3647 glColor 0, 0, 0;
3606 glRect_lineloop 0, 0, $w, $h; 3648 glRect_lineloop .5, .5, $w + .5, $h + .5;
3607 3649
3608 glTranslate 2 - 0.375, 2 - 0.375; 3650 glTranslate 2, 2;
3609 3651
3610 $self->SUPER::_draw; 3652 $self->SUPER::_draw;
3611} 3653}
3612 3654
3613############################################################################# 3655#############################################################################
3930 3972
3931############################################################################# 3973#############################################################################
3932 3974
3933package CFPlus::UI::Notebook; 3975package CFPlus::UI::Notebook;
3934 3976
3977use CFPlus::OpenGL;
3978
3935our @ISA = CFPlus::UI::VBox::; 3979our @ISA = CFPlus::UI::VBox::;
3936 3980
3937sub new { 3981sub new {
3938 my $class = shift; 3982 my $class = shift;
3939 3983
3940 my $self = $class->SUPER::new ( 3984 my $self = $class->SUPER::new (
3941 buttonbar => (new CFPlus::UI::Buttonbar), 3985 buttonbar => (new CFPlus::UI::Buttonbar),
3942 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3986 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3987 active_outline => [.7, .7, 0.2],
3943 # filter => # will be put between multiplexer and $self 3988 # filter => # will be put between multiplexer and $self
3944 @_, 3989 @_,
3945 ); 3990 );
3946 3991
3947 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3992 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
4021 4066
4022 $self->{multiplexer}->set_current_page ($page); 4067 $self->{multiplexer}->set_current_page ($page);
4023 $self->emit (page_changed => $self->{multiplexer}{current}); 4068 $self->emit (page_changed => $self->{multiplexer}{current});
4024} 4069}
4025 4070
4071sub _draw {
4072 my ($self) = @_;
4073
4074 $self->SUPER::_draw ();
4075
4076 if (my $cur = $self->{multiplexer}{current}) {
4077 if ($cur = $cur->{c_tab_}) {
4078 glTranslate $self->{buttonbar}{x} + $cur->{x},
4079 $self->{buttonbar}{y} + $cur->{y};
4080 glLineWidth 3;
4081 #glEnable GL_BLEND;
4082 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4083 glColor @{$self->{active_outline}};
4084 glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5;
4085 glLineWidth 1;
4086 #glDisable GL_BLEND;
4087 }
4088 }
4089}
4090
4026############################################################################# 4091#############################################################################
4027 4092
4028package CFPlus::UI::Selector; 4093package CFPlus::UI::Selector;
4029 4094
4030use utf8; 4095use utf8;
4060} 4125}
4061 4126
4062sub _set_value { 4127sub _set_value {
4063 my ($self, $value) = @_; 4128 my ($self, $value) = @_;
4064 4129
4065 my ($item) = grep $_->[0] eq $value, @{ $self->{options} } 4130 my ($item) = grep $_->[0] eq $value, @{ $self->{options} };
4131 $item ||= $self->{options}[0]
4066 or return; 4132 or return;
4067 4133
4068 $self->{value} = $item->[0]; 4134 $self->{value} = $item->[0];
4069 $self->set_markup ("$item->[1] ⇓"); 4135 $self->set_markup ("$item->[1] ⇓");
4070 $self->set_tooltip ($item->[2]); 4136# $self->set_tooltip ($item->[2]);
4071} 4137}
4072 4138
4073sub set_value { 4139sub set_value {
4074 my ($self, $value) = @_; 4140 my ($self, $value) = @_;
4075 4141
4076 return unless $self->{value} ne $value; 4142 return unless $self->{value} ne $value;
4077 4143
4078 $self->_set_value ($value); 4144 $self->_set_value ($value);
4079 $self->emit (changed => $value); 4145 $self->emit (changed => $value);
4146}
4147
4148sub set_options {
4149 my ($self, $options) = @_;
4150
4151 $self->{options} = $options;
4152 $self->_set_value ($self->{value});
4080} 4153}
4081 4154
4082############################################################################# 4155#############################################################################
4083 4156
4084package CFPlus::UI::Statusbox; 4157package CFPlus::UI::Statusbox;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines