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.458 by root, Fri Dec 28 15:05:33 2007 UTC vs.
Revision 1.459 by root, Sat Dec 29 13:44:30 2007 UTC

368 368
369# traverse the widget chain up to find the maximum "physical" size constraints 369# traverse the widget chain up to find the maximum "physical" size constraints
370sub get_max_wh { 370sub get_max_wh {
371 my ($self) = @_; 371 my ($self) = @_;
372 372
373 my ($w, $h) = @$self{qw(max_w max_h)};
374
375 if ($w <= 0 || $h <= 0) {
376 my ($mw, $mh) = $self->{parent}
373 return $self->{parent}->get_max_wh 377 ? $self->{parent}->get_max_wh
374 if $self->{parent};
375
376 ($::WIDTH, $::HEIGHT) 378 : ($::WIDTH, $::HEIGHT);
379
380 $w = $mw if $w <= 0;
381 $h = $mh if $h <= 0;
382 }
383
384 ($w, $h)
377} 385}
378 386
379sub size_request { 387sub size_request {
380 require Carp; 388 require Carp;
381 Carp::confess "size_request is abstract"; 389 Carp::confess "size_request is abstract";
1241 my ($class, %arg) = @_; 1249 my ($class, %arg) = @_;
1242 1250
1243 if ((exists $arg{label}) && !ref $arg{label}) { 1251 if ((exists $arg{label}) && !ref $arg{label}) {
1244 $arg{label} = new DC::UI::Label 1252 $arg{label} = new DC::UI::Label
1245 align => 1, 1253 align => 1,
1246 valign => 0, 1254 valign => 0.5,
1247 text => $arg{label}, 1255 text => $arg{label},
1248 fontsize => ($arg{border} || 0.8) * 0.75; 1256 fontsize => ($arg{border} || 0.8) * 0.75;
1249 } 1257 }
1250 1258
1251 my $self = $class->SUPER::new ( 1259 my $self = $class->SUPER::new (
1361 min_h => 32, 1369 min_h => 32,
1362 %arg, 1370 %arg,
1363 ); 1371 );
1364 1372
1365 $self->{title_widget} = new DC::UI::Label 1373 $self->{title_widget} = new DC::UI::Label
1366 align => 0, 1374 align => 0.5,
1367 valign => 1, 1375 valign => 1,
1368 text => $self->{title}, 1376 text => $self->{title},
1369 fontsize => $self->{border}, 1377 fontsize => $self->{border},
1370 if exists $self->{title}; 1378 if exists $self->{title};
1371 1379
1889 #max_w => maximum pixel width 1897 #max_w => maximum pixel width
1890 #style => 0, # render flags 1898 #style => 0, # render flags
1891 ellipsise => 3, # end 1899 ellipsise => 3, # end
1892 layout => (new DC::Layout), 1900 layout => (new DC::Layout),
1893 fontsize => 1, 1901 fontsize => 1,
1894 align => -1, 1902 align => 0.5,
1895 valign => -1, 1903 valign => 0.5,
1896 padding_x => 2, 1904 padding_x => 4,
1897 padding_y => 2, 1905 padding_y => 2,
1898 can_events => 0, 1906 can_events => 0,
1899 %arg 1907 %arg
1900 ); 1908 );
1901 1909
1967 1975
1968 $self->{size_req} ||= do { 1976 $self->{size_req} ||= do {
1969 my ($max_w, $max_h) = $self->get_max_wh; 1977 my ($max_w, $max_h) = $self->get_max_wh;
1970 1978
1971 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1979 $self->{layout}->set_font ($self->{font}) if $self->{font};
1972 $self->{layout}->set_width ($self->{max_w} || $max_w || -1); 1980 $self->{layout}->set_width ($max_w);
1973 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1981 $self->{layout}->set_ellipsise ($self->{ellipsise});
1974 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1982 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1975 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1983 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1976 1984
1977 my ($w, $h) = $self->{layout}->size; 1985 my ($w, $h) = $self->{layout}->size;
1978 1986
1979 if (exists $self->{template}) { 1987 if (exists $self->{template}) {
1980 $self->{template}->set_font ($self->{font}) if $self->{font}; 1988 $self->{template}->set_font ($self->{font}) if $self->{font};
1981 $self->{template}->set_width ($self->{max_w} || -1); 1989 $self->{template}->set_width ($max_w);
1982 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE); 1990 $self->{template}->set_height ($self->{fontsize} * $::FONTSIZE);
1983 1991
1984 my ($w2, $h2) = $self->{template}->size; 1992 my ($w2, $h2) = $self->{template}->size;
1985 1993
1986 $w = List::Util::max $w, $w2; 1994 $w = List::Util::max $w, $w2;
2042 2050
2043 [$self->{layout}->size] 2051 [$self->{layout}->size]
2044 }; 2052 };
2045 2053
2046 unless (exists $self->{ox}) { 2054 unless (exists $self->{ox}) {
2047 $self->{ox} = int ($self->{align} < 0 ? $self->{padding_x} 2055 $self->{ox} = $self->{padding_x} + int $self->{align} * ($self->{w} - $size->[0] - $self->{padding_x} * 2);
2048 : $self->{align} > 0 ? $self->{w} - $size->[0] - $self->{padding_x} 2056 $self->{oy} = $self->{padding_y} + int $self->{valign} * ($self->{h} - $size->[1] - $self->{padding_y} * 2);
2049 : ($self->{w} - $size->[0]) * 0.5);
2050
2051 $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y}
2052 : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y}
2053 : ($self->{h} - $size->[1]) * 0.5);
2054 2057
2055 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); 2058 $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style});
2056 }; 2059 };
2057 2060
2058# unless ($self->{list}) { 2061# unless ($self->{list}) {
2093 active_bg => [0, 0, 1, .2], 2096 active_bg => [0, 0, 1, .2],
2094 active_fg => [1, 1, 1], 2097 active_fg => [1, 1, 1],
2095 active_outline => [1, 1, 0], 2098 active_outline => [1, 1, 0],
2096 can_hover => 1, 2099 can_hover => 1,
2097 can_focus => 1, 2100 can_focus => 1,
2101 align => 0,
2098 valign => 0, 2102 valign => 0.5,
2099 can_events => 1, 2103 can_events => 1,
2100 ellipsise => 0, 2104 ellipsise => 0,
2101 padding_x => 4, 2105 padding_x => 4,
2102 padding_y => 2, 2106 padding_y => 2,
2103 #text => ... 2107 #text => ...
2396sub new { 2400sub new {
2397 my $class = shift; 2401 my $class = shift;
2398 2402
2399 $class->SUPER::new ( 2403 $class->SUPER::new (
2400 can_hover => 1, 2404 can_hover => 1,
2401 align => 0, 2405 align => 0.5,
2402 valign => 0, 2406 valign => 0.5,
2403 can_events => 1, 2407 can_events => 1,
2404 @_ 2408 @_
2405 ) 2409 )
2406} 2410}
2407 2411
2449 padding_x => 8, 2453 padding_x => 8,
2450 padding_y => 4, 2454 padding_y => 4,
2451 fg => [1.0, 1.0, 1.0], 2455 fg => [1.0, 1.0, 1.0],
2452 active_fg => [0.8, 0.8, 0.8], 2456 active_fg => [0.8, 0.8, 0.8],
2453 can_hover => 1, 2457 can_hover => 1,
2454 align => 0, 2458 align => 0.5,
2455 valign => 0, 2459 valign => 0.5,
2456 can_events => 1, 2460 can_events => 1,
2457 @_ 2461 @_
2458 ) 2462 )
2459} 2463}
2460 2464
2652 padding_x => 4, 2656 padding_x => 4,
2653 padding_y => 4, 2657 padding_y => 4,
2654 fg => [1, 1, 1], 2658 fg => [1, 1, 1],
2655 active_fg => [0, 0, 1], 2659 active_fg => [0, 0, 1],
2656 can_hover => 1, 2660 can_hover => 1,
2657 align => 0, 2661 align => 0.5,
2658 valign => 0, 2662 valign => 0.5,
2659 can_events => 1, 2663 can_events => 1,
2660 @_ 2664 @_
2661 ); 2665 );
2662} 2666}
2663 2667
2827 fg => [1, 1, 1], 2831 fg => [1, 1, 1],
2828 bg => [0, 0, 1, 0.2], 2832 bg => [0, 0, 1, 0.2],
2829 bar => [0.7, 0.5, 0.1, 0.8], 2833 bar => [0.7, 0.5, 0.1, 0.8],
2830 outline => [0.4, 0.3, 0], 2834 outline => [0.4, 0.3, 0],
2831 fontsize => 0.9, 2835 fontsize => 0.9,
2832 valign => 0, 2836 valign => 0.5,
2833 align => 0, 2837 align => 0.5,
2834 can_events => 1, 2838 can_events => 1,
2835 ellipsise => 1, 2839 ellipsise => 1,
2836 label => "%d%%", 2840 label => "%d%%",
2837 %arg, 2841 %arg,
2838 ); 2842 );
2964 can_hover => 1, 2968 can_hover => 1,
2965 can_events => 1, 2969 can_events => 1,
2966 %arg, 2970 %arg,
2967 ); 2971 );
2968 2972
2969 $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999"); 2973 $self->add ($self->{value} = new DC::UI::Label valign => 1, align => 0.5, template => "999");
2970 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1); 2974 $self->add ($self->{gauge} = new DC::UI::VGauge type => $self->{type}, expand => 1, can_hover => 1);
2971 $self->add ($self->{max} = new DC::UI::Label valign => -1, align => 0, template => "999"); 2975 $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999");
2972 2976
2973 $self 2977 $self
2974} 2978}
2975 2979
2976sub set_fontsize { 2980sub set_fontsize {
3304 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3308 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3305 $layout->set_markup ($para->{markup}); 3309 $layout->set_markup ($para->{markup});
3306 3310
3307 $layout->set_shapes ( 3311 $layout->set_shapes (
3308 map 3312 map
3309 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3313 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3310 @{$para->{widget}} 3314 @{$para->{widget}}
3311 ); 3315 );
3312 3316
3313 $layout 3317 $layout
3314} 3318}
3607 $tip =~ s/\n+$//; 3611 $tip =~ s/\n+$//;
3608 3612
3609 $self->add (new DC::UI::Label 3613 $self->add (new DC::UI::Label
3610 markup => $tip, 3614 markup => $tip,
3611 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3615 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3616 align => 0,
3612 fontsize => 0.8, 3617 fontsize => 0.8,
3613 style => 1, # FLAG_INVERSE 3618 style => 1, # FLAG_INVERSE
3614 ellipsise => 0, 3619 ellipsise => 0,
3615 font => ($widget->{tooltip_font} || $::FONT_PROP), 3620 font => ($widget->{tooltip_font} || $::FONT_PROP),
3616 ); 3621 );
3841 can_hover => 1, 3846 can_hover => 1,
3842 can_events => 1, 3847 can_events => 1,
3843 tooltip => $tooltip, 3848 tooltip => $tooltip,
3844 children => [ 3849 children => [
3845 (new DC::UI::Label markup => $left, expand => 1), 3850 (new DC::UI::Label markup => $left, expand => 1),
3846 (new DC::UI::Label markup => $right, align => +1), 3851 (new DC::UI::Label markup => $right, align => 1),
3847 ], 3852 ],
3848 ; 3853 ;
3849 3854
3850 } else { 3855 } else {
3851 $widget = new DC::UI::Label 3856 $widget = new DC::UI::Label
3852 can_hover => 1, 3857 can_hover => 1,
3853 can_events => 1, 3858 can_events => 1,
3859 align => 0,
3854 markup => $widget, 3860 markup => $widget,
3855 tooltip => $tooltip; 3861 tooltip => $tooltip;
3856 } 3862 }
3857 } 3863 }
3858 3864
4222 tooltip => $item->{tooltip}, 4228 tooltip => $item->{tooltip},
4223 tooltip_font => $::FONT_PROP, 4229 tooltip_font => $::FONT_PROP,
4224 tooltip_width => 0.67, 4230 tooltip_width => 0.67,
4225 fontsize => $item->{fontsize} || $self->{fontsize}, 4231 fontsize => $item->{fontsize} || $self->{fontsize},
4226 max_w => $::WIDTH * 0.44, 4232 max_w => $::WIDTH * 0.44,
4233 align => 0,
4227 fg => [@{ $item->{fg} }], 4234 fg => [@{ $item->{fg} }],
4228 can_events => 1, 4235 can_events => 1,
4229 can_hover => 1 4236 can_hover => 1
4230 }; 4237 };
4231 4238
4455 4462
4456 delete $queue{$widget+0}; 4463 delete $queue{$widget+0};
4457 4464
4458 my ($w, $h) = $widget->size_request; 4465 my ($w, $h) = $widget->size_request;
4459 4466
4460 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4467 $w += $widget->{padding_x} * 2;
4461 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4468 $h += $widget->{padding_y} * 2;
4469
4470 $w = max $widget->{min_w}, $w;
4471 $h = max $widget->{min_h}, $h;
4462 4472
4463 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4473 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4464 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4474 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4465 4475
4466 $w = $widget->{force_w} if exists $widget->{force_w}; 4476 $w = $widget->{force_w} if exists $widget->{force_w};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines