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.456 by root, Fri Dec 28 11:44:02 2007 UTC vs.
Revision 1.462 by root, Thu Mar 20 22:28:33 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
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 => ...
2287 2291
2288our @ISA = DC::UI::EntryBase::; 2292our @ISA = DC::UI::EntryBase::;
2289 2293
2290use DC::OpenGL; 2294use DC::OpenGL;
2291 2295
2296sub new {
2297 my $class = shift;
2298
2299 $class->SUPER::new (
2300 history_pointer => -1,
2301 @_
2302 )
2303}
2304
2305
2292sub invoke_key_down { 2306sub invoke_key_down {
2293 my ($self, $ev) = @_; 2307 my ($self, $ev) = @_;
2294 2308
2295 my $sym = $ev->{sym}; 2309 my $sym = $ev->{sym};
2296 2310
2320 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2334 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2321 2335
2322 if ($self->{history_pointer} >= 0) { 2336 if ($self->{history_pointer} >= 0) {
2323 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2337 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2324 } else { 2338 } else {
2339 if (defined $self->{history_saveback}) {
2325 $self->set_text ($self->{history_saveback}); 2340 $self->set_text ($self->{history_saveback});
2341 $self->{history_saveback} = undef;
2342 }
2326 } 2343 }
2327 2344
2328 } else { 2345 } else {
2329 return $self->SUPER::invoke_key_down ($ev) 2346 return $self->SUPER::invoke_key_down ($ev)
2330 } 2347 }
2351} 2368}
2352 2369
2353sub move_cursor_ver { 2370sub move_cursor_ver {
2354 my ($self, $dy) = @_; 2371 my ($self, $dy) = @_;
2355 2372
2356 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2373 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2357 2374
2358 $y += $dy; 2375 $line += $dy;
2359 2376
2360 if (defined (my $index = $self->{layout}->line_x_to_index ($y, $x))) { 2377 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2361 $self->{cursor} = $index; 2378 $self->{cursor} = $index;
2362 delete $self->{cur_h}; 2379 delete $self->{cur_h};
2363 $self->update; 2380 $self->update;
2364 return; 2381 return;
2365 } 2382 }
2396sub new { 2413sub new {
2397 my $class = shift; 2414 my $class = shift;
2398 2415
2399 $class->SUPER::new ( 2416 $class->SUPER::new (
2400 can_hover => 1, 2417 can_hover => 1,
2401 align => 0, 2418 align => 0.5,
2402 valign => 0, 2419 valign => 0.5,
2403 can_events => 1, 2420 can_events => 1,
2404 @_ 2421 @_
2405 ) 2422 )
2406} 2423}
2407 2424
2449 padding_x => 8, 2466 padding_x => 8,
2450 padding_y => 4, 2467 padding_y => 4,
2451 fg => [1.0, 1.0, 1.0], 2468 fg => [1.0, 1.0, 1.0],
2452 active_fg => [0.8, 0.8, 0.8], 2469 active_fg => [0.8, 0.8, 0.8],
2453 can_hover => 1, 2470 can_hover => 1,
2454 align => 0, 2471 align => 0.5,
2455 valign => 0, 2472 valign => 0.5,
2456 can_events => 1, 2473 can_events => 1,
2457 @_ 2474 @_
2458 ) 2475 )
2459} 2476}
2460 2477
2652 padding_x => 4, 2669 padding_x => 4,
2653 padding_y => 4, 2670 padding_y => 4,
2654 fg => [1, 1, 1], 2671 fg => [1, 1, 1],
2655 active_fg => [0, 0, 1], 2672 active_fg => [0, 0, 1],
2656 can_hover => 1, 2673 can_hover => 1,
2657 align => 0, 2674 align => 0.5,
2658 valign => 0, 2675 valign => 0.5,
2659 can_events => 1, 2676 can_events => 1,
2660 @_ 2677 @_
2661 ); 2678 );
2662} 2679}
2663 2680
2827 fg => [1, 1, 1], 2844 fg => [1, 1, 1],
2828 bg => [0, 0, 1, 0.2], 2845 bg => [0, 0, 1, 0.2],
2829 bar => [0.7, 0.5, 0.1, 0.8], 2846 bar => [0.7, 0.5, 0.1, 0.8],
2830 outline => [0.4, 0.3, 0], 2847 outline => [0.4, 0.3, 0],
2831 fontsize => 0.9, 2848 fontsize => 0.9,
2832 valign => 0, 2849 valign => 0.5,
2833 align => 0, 2850 align => 0.5,
2834 can_events => 1, 2851 can_events => 1,
2835 ellipsise => 1, 2852 ellipsise => 1,
2836 label => "%d%%", 2853 label => "%d%%",
2837 %arg, 2854 %arg,
2838 ); 2855 );
2964 can_hover => 1, 2981 can_hover => 1,
2965 can_events => 1, 2982 can_events => 1,
2966 %arg, 2983 %arg,
2967 ); 2984 );
2968 2985
2969 $self->add ($self->{value} = new DC::UI::Label valign => +1, align => 0, template => "999"); 2986 $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); 2987 $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"); 2988 $self->add ($self->{max} = new DC::UI::Label valign => 0, align => 0.5, template => "999");
2972 2989
2973 $self 2990 $self
2974} 2991}
2975 2992
2976sub set_fontsize { 2993sub set_fontsize {
3304 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3321 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3305 $layout->set_markup ($para->{markup}); 3322 $layout->set_markup ($para->{markup});
3306 3323
3307 $layout->set_shapes ( 3324 $layout->set_shapes (
3308 map 3325 map
3309 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3326 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3310 @{$para->{widget}} 3327 @{$para->{widget}}
3311 ); 3328 );
3312 3329
3313 $layout 3330 $layout
3314} 3331}
3607 $tip =~ s/\n+$//; 3624 $tip =~ s/\n+$//;
3608 3625
3609 $self->add (new DC::UI::Label 3626 $self->add (new DC::UI::Label
3610 markup => $tip, 3627 markup => $tip,
3611 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3628 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3629 align => 0,
3612 fontsize => 0.8, 3630 fontsize => 0.8,
3613 style => 1, # FLAG_INVERSE 3631 style => 1, # FLAG_INVERSE
3614 ellipsise => 0, 3632 ellipsise => 0,
3615 font => ($widget->{tooltip_font} || $::FONT_PROP), 3633 font => ($widget->{tooltip_font} || $::FONT_PROP),
3616 ); 3634 );
3841 can_hover => 1, 3859 can_hover => 1,
3842 can_events => 1, 3860 can_events => 1,
3843 tooltip => $tooltip, 3861 tooltip => $tooltip,
3844 children => [ 3862 children => [
3845 (new DC::UI::Label markup => $left, expand => 1), 3863 (new DC::UI::Label markup => $left, expand => 1),
3846 (new DC::UI::Label markup => $right, align => +1), 3864 (new DC::UI::Label markup => $right, align => 1),
3847 ], 3865 ],
3848 ; 3866 ;
3849 3867
3850 } else { 3868 } else {
3851 $widget = new DC::UI::Label 3869 $widget = new DC::UI::Label
3852 can_hover => 1, 3870 can_hover => 1,
3853 can_events => 1, 3871 can_events => 1,
3872 align => 0,
3854 markup => $widget, 3873 markup => $widget,
3855 tooltip => $tooltip; 3874 tooltip => $tooltip;
3856 } 3875 }
3857 } 3876 }
3858 3877
4049} 4068}
4050 4069
4051sub pages { 4070sub pages {
4052 my ($self) = @_; 4071 my ($self) = @_;
4053 $self->{multiplexer}->children 4072 $self->{multiplexer}->children
4073}
4074
4075sub page_index {
4076 my ($self, $widget) = @_;
4077
4078 my $i = 0;
4079 for ($self->pages) {
4080 if ($_ eq $widget) { return $i };
4081 $i++;
4082 }
4083
4084 undef
4054} 4085}
4055 4086
4056sub add_tab { 4087sub add_tab {
4057 my ($self, $title, $widget, $tooltip) = @_; 4088 my ($self, $title, $widget, $tooltip) = @_;
4058 4089
4222 tooltip => $item->{tooltip}, 4253 tooltip => $item->{tooltip},
4223 tooltip_font => $::FONT_PROP, 4254 tooltip_font => $::FONT_PROP,
4224 tooltip_width => 0.67, 4255 tooltip_width => 0.67,
4225 fontsize => $item->{fontsize} || $self->{fontsize}, 4256 fontsize => $item->{fontsize} || $self->{fontsize},
4226 max_w => $::WIDTH * 0.44, 4257 max_w => $::WIDTH * 0.44,
4258 align => 0,
4227 fg => [@{ $item->{fg} }], 4259 fg => [@{ $item->{fg} }],
4228 can_events => 1, 4260 can_events => 1,
4229 can_hover => 1 4261 can_hover => 1
4230 }; 4262 };
4231 4263
4455 4487
4456 delete $queue{$widget+0}; 4488 delete $queue{$widget+0};
4457 4489
4458 my ($w, $h) = $widget->size_request; 4490 my ($w, $h) = $widget->size_request;
4459 4491
4460 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4492 $w += $widget->{padding_x} * 2;
4461 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4493 $h += $widget->{padding_y} * 2;
4494
4495 $w = max $widget->{min_w}, $w;
4496 $h = max $widget->{min_h}, $h;
4462 4497
4463 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4498 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4464 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4499 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4465 4500
4466 $w = $widget->{force_w} if exists $widget->{force_w}; 4501 $w = $widget->{force_w} if exists $widget->{force_w};
4546 4581
4547############################################################################# 4582#############################################################################
4548 4583
4549package DC::UI; 4584package DC::UI;
4550 4585
4551$ROOT = new DC::UI::Root; 4586$ROOT = new DC::UI::Root;
4552$TOOLTIP = new DC::UI::Tooltip z => 900; 4587$TOOLTIP = new DC::UI::Tooltip z => 900;
4553 4588
45541 45891
4555 4590

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines