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.455 by root, Thu Dec 27 19:12:19 2007 UTC vs.
Revision 1.460 by elmex, Sun Jan 6 16:28:49 2008 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
1639 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; 1647 my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)};
1640 1648
1641 my $sw = sum @w[$c .. $c + $cs - 1]; 1649 my $sw = sum @w[$c .. $c + $cs - 1];
1642 1650
1643 if ($w > $sw) { 1651 if ($w > $sw) {
1644 $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; 1652 $_ += ($w - $sw) / ($_ ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1];
1645 } 1653 }
1646 } 1654 }
1647 1655
1648 # second pass, rows 1656 # second pass, rows
1649 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { 1657 for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) {
1650 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; 1658 my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)};
1651 1659
1652 my $sh = sum @h[$r .. $r + $rs - 1]; 1660 my $sh = sum @h[$r .. $r + $rs - 1];
1653 1661
1654 if ($h > $sh) { 1662 if ($h > $sh) {
1655 $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; 1663 $_ += ($h - $sh) / ($_ ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1];
1656 } 1664 }
1657 } 1665 }
1658 1666
1659 (\@w, \@h) 1667 (\@w, \@h)
1660} 1668}
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,
2105 padding_x => 4,
2106 padding_y => 2,
2101 #text => ... 2107 #text => ...
2102 #hidden => "*", 2108 #hidden => "*",
2103 @_ 2109 @_
2104 ) 2110 )
2105} 2111}
2336 2342
2337our @ISA = DC::UI::EntryBase::; 2343our @ISA = DC::UI::EntryBase::;
2338 2344
2339use DC::OpenGL; 2345use DC::OpenGL;
2340 2346
2347sub new {
2348 my $class = shift;
2349
2350 $class->SUPER::new (
2351 padding_y => 4,
2352
2353 @_
2354 )
2355}
2356
2341sub move_cursor_ver { 2357sub move_cursor_ver {
2342 my ($self, $dy) = @_; 2358 my ($self, $dy) = @_;
2343 2359
2344 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2360 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2345 2361
2346 $y += $dy; 2362 $line += $dy;
2347 2363
2348 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { 2364 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2349 $self->{cursor} = $index; 2365 $self->{cursor} = $index;
2350 delete $self->{cur_h}; 2366 delete $self->{cur_h};
2351 $self->update; 2367 $self->update;
2352 return; 2368 return;
2353 } 2369 }
2384sub new { 2400sub new {
2385 my $class = shift; 2401 my $class = shift;
2386 2402
2387 $class->SUPER::new ( 2403 $class->SUPER::new (
2388 can_hover => 1, 2404 can_hover => 1,
2389 align => 0, 2405 align => 0.5,
2390 valign => 0, 2406 valign => 0.5,
2391 can_events => 1, 2407 can_events => 1,
2392 @_ 2408 @_
2393 ) 2409 )
2394} 2410}
2395 2411
2437 padding_x => 8, 2453 padding_x => 8,
2438 padding_y => 4, 2454 padding_y => 4,
2439 fg => [1.0, 1.0, 1.0], 2455 fg => [1.0, 1.0, 1.0],
2440 active_fg => [0.8, 0.8, 0.8], 2456 active_fg => [0.8, 0.8, 0.8],
2441 can_hover => 1, 2457 can_hover => 1,
2442 align => 0, 2458 align => 0.5,
2443 valign => 0, 2459 valign => 0.5,
2444 can_events => 1, 2460 can_events => 1,
2445 @_ 2461 @_
2446 ) 2462 )
2447} 2463}
2448 2464
2640 padding_x => 4, 2656 padding_x => 4,
2641 padding_y => 4, 2657 padding_y => 4,
2642 fg => [1, 1, 1], 2658 fg => [1, 1, 1],
2643 active_fg => [0, 0, 1], 2659 active_fg => [0, 0, 1],
2644 can_hover => 1, 2660 can_hover => 1,
2645 align => 0, 2661 align => 0.5,
2646 valign => 0, 2662 valign => 0.5,
2647 can_events => 1, 2663 can_events => 1,
2648 @_ 2664 @_
2649 ); 2665 );
2650} 2666}
2651 2667
2815 fg => [1, 1, 1], 2831 fg => [1, 1, 1],
2816 bg => [0, 0, 1, 0.2], 2832 bg => [0, 0, 1, 0.2],
2817 bar => [0.7, 0.5, 0.1, 0.8], 2833 bar => [0.7, 0.5, 0.1, 0.8],
2818 outline => [0.4, 0.3, 0], 2834 outline => [0.4, 0.3, 0],
2819 fontsize => 0.9, 2835 fontsize => 0.9,
2820 valign => 0, 2836 valign => 0.5,
2821 align => 0, 2837 align => 0.5,
2822 can_events => 1, 2838 can_events => 1,
2823 ellipsise => 1, 2839 ellipsise => 1,
2824 label => "%d%%", 2840 label => "%d%%",
2825 %arg, 2841 %arg,
2826 ); 2842 );
2952 can_hover => 1, 2968 can_hover => 1,
2953 can_events => 1, 2969 can_events => 1,
2954 %arg, 2970 %arg,
2955 ); 2971 );
2956 2972
2957 $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");
2958 $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);
2959 $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");
2960 2976
2961 $self 2977 $self
2962} 2978}
2963 2979
2964sub set_fontsize { 2980sub set_fontsize {
3292 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3308 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3293 $layout->set_markup ($para->{markup}); 3309 $layout->set_markup ($para->{markup});
3294 3310
3295 $layout->set_shapes ( 3311 $layout->set_shapes (
3296 map 3312 map
3297 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3313 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3298 @{$para->{widget}} 3314 @{$para->{widget}}
3299 ); 3315 );
3300 3316
3301 $layout 3317 $layout
3302} 3318}
3595 $tip =~ s/\n+$//; 3611 $tip =~ s/\n+$//;
3596 3612
3597 $self->add (new DC::UI::Label 3613 $self->add (new DC::UI::Label
3598 markup => $tip, 3614 markup => $tip,
3599 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3615 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3616 align => 0,
3600 fontsize => 0.8, 3617 fontsize => 0.8,
3601 style => 1, # FLAG_INVERSE 3618 style => 1, # FLAG_INVERSE
3602 ellipsise => 0, 3619 ellipsise => 0,
3603 font => ($widget->{tooltip_font} || $::FONT_PROP), 3620 font => ($widget->{tooltip_font} || $::FONT_PROP),
3604 ); 3621 );
3829 can_hover => 1, 3846 can_hover => 1,
3830 can_events => 1, 3847 can_events => 1,
3831 tooltip => $tooltip, 3848 tooltip => $tooltip,
3832 children => [ 3849 children => [
3833 (new DC::UI::Label markup => $left, expand => 1), 3850 (new DC::UI::Label markup => $left, expand => 1),
3834 (new DC::UI::Label markup => $right, align => +1), 3851 (new DC::UI::Label markup => $right, align => 1),
3835 ], 3852 ],
3836 ; 3853 ;
3837 3854
3838 } else { 3855 } else {
3839 $widget = new DC::UI::Label 3856 $widget = new DC::UI::Label
3840 can_hover => 1, 3857 can_hover => 1,
3841 can_events => 1, 3858 can_events => 1,
3859 align => 0,
3842 markup => $widget, 3860 markup => $widget,
3843 tooltip => $tooltip; 3861 tooltip => $tooltip;
3844 } 3862 }
3845 } 3863 }
3846 3864
4037} 4055}
4038 4056
4039sub pages { 4057sub pages {
4040 my ($self) = @_; 4058 my ($self) = @_;
4041 $self->{multiplexer}->children 4059 $self->{multiplexer}->children
4060}
4061
4062sub page_index {
4063 my ($self, $widget) = @_;
4064
4065 my $i = 0;
4066 for ($self->pages) {
4067 if ($_ eq $widget) { return $i };
4068 $i++;
4069 }
4070
4071 undef
4042} 4072}
4043 4073
4044sub add_tab { 4074sub add_tab {
4045 my ($self, $title, $widget, $tooltip) = @_; 4075 my ($self, $title, $widget, $tooltip) = @_;
4046 4076
4210 tooltip => $item->{tooltip}, 4240 tooltip => $item->{tooltip},
4211 tooltip_font => $::FONT_PROP, 4241 tooltip_font => $::FONT_PROP,
4212 tooltip_width => 0.67, 4242 tooltip_width => 0.67,
4213 fontsize => $item->{fontsize} || $self->{fontsize}, 4243 fontsize => $item->{fontsize} || $self->{fontsize},
4214 max_w => $::WIDTH * 0.44, 4244 max_w => $::WIDTH * 0.44,
4245 align => 0,
4215 fg => [@{ $item->{fg} }], 4246 fg => [@{ $item->{fg} }],
4216 can_events => 1, 4247 can_events => 1,
4217 can_hover => 1 4248 can_hover => 1
4218 }; 4249 };
4219 4250
4443 4474
4444 delete $queue{$widget+0}; 4475 delete $queue{$widget+0};
4445 4476
4446 my ($w, $h) = $widget->size_request; 4477 my ($w, $h) = $widget->size_request;
4447 4478
4448 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4479 $w += $widget->{padding_x} * 2;
4449 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4480 $h += $widget->{padding_y} * 2;
4481
4482 $w = max $widget->{min_w}, $w;
4483 $h = max $widget->{min_h}, $h;
4450 4484
4451 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4485 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4452 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4486 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4453 4487
4454 $w = $widget->{force_w} if exists $widget->{force_w}; 4488 $w = $widget->{force_w} if exists $widget->{force_w};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines