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.457 by root, Fri Dec 28 15:05:20 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 }
2352 2369
2353sub move_cursor_ver { 2370sub move_cursor_ver {
2354 my ($self, $dy) = @_; 2371 my ($self, $dy) = @_;
2355 2372
2356 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2373 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2357 warn "cursor $self->{cursor} => $x $line\n";#d#
2358 2374
2359 $line += $dy; 2375 $line += $dy;
2360 2376
2361 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) { 2377 if (defined (my $index = $self->{layout}->line_x_to_index ($line, $x))) {
2362 warn "index $x $line => $index\n";#d#
2363 $self->{cursor} = $index; 2378 $self->{cursor} = $index;
2364 delete $self->{cur_h}; 2379 delete $self->{cur_h};
2365 $self->update; 2380 $self->update;
2366 return; 2381 return;
2367 } 2382 }
2398sub new { 2413sub new {
2399 my $class = shift; 2414 my $class = shift;
2400 2415
2401 $class->SUPER::new ( 2416 $class->SUPER::new (
2402 can_hover => 1, 2417 can_hover => 1,
2403 align => 0, 2418 align => 0.5,
2404 valign => 0, 2419 valign => 0.5,
2405 can_events => 1, 2420 can_events => 1,
2406 @_ 2421 @_
2407 ) 2422 )
2408} 2423}
2409 2424
2451 padding_x => 8, 2466 padding_x => 8,
2452 padding_y => 4, 2467 padding_y => 4,
2453 fg => [1.0, 1.0, 1.0], 2468 fg => [1.0, 1.0, 1.0],
2454 active_fg => [0.8, 0.8, 0.8], 2469 active_fg => [0.8, 0.8, 0.8],
2455 can_hover => 1, 2470 can_hover => 1,
2456 align => 0, 2471 align => 0.5,
2457 valign => 0, 2472 valign => 0.5,
2458 can_events => 1, 2473 can_events => 1,
2459 @_ 2474 @_
2460 ) 2475 )
2461} 2476}
2462 2477
2654 padding_x => 4, 2669 padding_x => 4,
2655 padding_y => 4, 2670 padding_y => 4,
2656 fg => [1, 1, 1], 2671 fg => [1, 1, 1],
2657 active_fg => [0, 0, 1], 2672 active_fg => [0, 0, 1],
2658 can_hover => 1, 2673 can_hover => 1,
2659 align => 0, 2674 align => 0.5,
2660 valign => 0, 2675 valign => 0.5,
2661 can_events => 1, 2676 can_events => 1,
2662 @_ 2677 @_
2663 ); 2678 );
2664} 2679}
2665 2680
2829 fg => [1, 1, 1], 2844 fg => [1, 1, 1],
2830 bg => [0, 0, 1, 0.2], 2845 bg => [0, 0, 1, 0.2],
2831 bar => [0.7, 0.5, 0.1, 0.8], 2846 bar => [0.7, 0.5, 0.1, 0.8],
2832 outline => [0.4, 0.3, 0], 2847 outline => [0.4, 0.3, 0],
2833 fontsize => 0.9, 2848 fontsize => 0.9,
2834 valign => 0, 2849 valign => 0.5,
2835 align => 0, 2850 align => 0.5,
2836 can_events => 1, 2851 can_events => 1,
2837 ellipsise => 1, 2852 ellipsise => 1,
2838 label => "%d%%", 2853 label => "%d%%",
2839 %arg, 2854 %arg,
2840 ); 2855 );
2966 can_hover => 1, 2981 can_hover => 1,
2967 can_events => 1, 2982 can_events => 1,
2968 %arg, 2983 %arg,
2969 ); 2984 );
2970 2985
2971 $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");
2972 $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);
2973 $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");
2974 2989
2975 $self 2990 $self
2976} 2991}
2977 2992
2978sub set_fontsize { 2993sub set_fontsize {
3306 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3321 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3307 $layout->set_markup ($para->{markup}); 3322 $layout->set_markup ($para->{markup});
3308 3323
3309 $layout->set_shapes ( 3324 $layout->set_shapes (
3310 map 3325 map
3311 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3326 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3312 @{$para->{widget}} 3327 @{$para->{widget}}
3313 ); 3328 );
3314 3329
3315 $layout 3330 $layout
3316} 3331}
3609 $tip =~ s/\n+$//; 3624 $tip =~ s/\n+$//;
3610 3625
3611 $self->add (new DC::UI::Label 3626 $self->add (new DC::UI::Label
3612 markup => $tip, 3627 markup => $tip,
3613 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3628 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3629 align => 0,
3614 fontsize => 0.8, 3630 fontsize => 0.8,
3615 style => 1, # FLAG_INVERSE 3631 style => 1, # FLAG_INVERSE
3616 ellipsise => 0, 3632 ellipsise => 0,
3617 font => ($widget->{tooltip_font} || $::FONT_PROP), 3633 font => ($widget->{tooltip_font} || $::FONT_PROP),
3618 ); 3634 );
3843 can_hover => 1, 3859 can_hover => 1,
3844 can_events => 1, 3860 can_events => 1,
3845 tooltip => $tooltip, 3861 tooltip => $tooltip,
3846 children => [ 3862 children => [
3847 (new DC::UI::Label markup => $left, expand => 1), 3863 (new DC::UI::Label markup => $left, expand => 1),
3848 (new DC::UI::Label markup => $right, align => +1), 3864 (new DC::UI::Label markup => $right, align => 1),
3849 ], 3865 ],
3850 ; 3866 ;
3851 3867
3852 } else { 3868 } else {
3853 $widget = new DC::UI::Label 3869 $widget = new DC::UI::Label
3854 can_hover => 1, 3870 can_hover => 1,
3855 can_events => 1, 3871 can_events => 1,
3872 align => 0,
3856 markup => $widget, 3873 markup => $widget,
3857 tooltip => $tooltip; 3874 tooltip => $tooltip;
3858 } 3875 }
3859 } 3876 }
3860 3877
4051} 4068}
4052 4069
4053sub pages { 4070sub pages {
4054 my ($self) = @_; 4071 my ($self) = @_;
4055 $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
4056} 4085}
4057 4086
4058sub add_tab { 4087sub add_tab {
4059 my ($self, $title, $widget, $tooltip) = @_; 4088 my ($self, $title, $widget, $tooltip) = @_;
4060 4089
4224 tooltip => $item->{tooltip}, 4253 tooltip => $item->{tooltip},
4225 tooltip_font => $::FONT_PROP, 4254 tooltip_font => $::FONT_PROP,
4226 tooltip_width => 0.67, 4255 tooltip_width => 0.67,
4227 fontsize => $item->{fontsize} || $self->{fontsize}, 4256 fontsize => $item->{fontsize} || $self->{fontsize},
4228 max_w => $::WIDTH * 0.44, 4257 max_w => $::WIDTH * 0.44,
4258 align => 0,
4229 fg => [@{ $item->{fg} }], 4259 fg => [@{ $item->{fg} }],
4230 can_events => 1, 4260 can_events => 1,
4231 can_hover => 1 4261 can_hover => 1
4232 }; 4262 };
4233 4263
4457 4487
4458 delete $queue{$widget+0}; 4488 delete $queue{$widget+0};
4459 4489
4460 my ($w, $h) = $widget->size_request; 4490 my ($w, $h) = $widget->size_request;
4461 4491
4462 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4492 $w += $widget->{padding_x} * 2;
4463 $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;
4464 4497
4465 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4498 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4466 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4499 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4467 4500
4468 $w = $widget->{force_w} if exists $widget->{force_w}; 4501 $w = $widget->{force_w} if exists $widget->{force_w};
4548 4581
4549############################################################################# 4582#############################################################################
4550 4583
4551package DC::UI; 4584package DC::UI;
4552 4585
4553$ROOT = new DC::UI::Root; 4586$ROOT = new DC::UI::Root;
4554$TOOLTIP = new DC::UI::Tooltip z => 900; 4587$TOOLTIP = new DC::UI::Tooltip z => 900;
4555 4588
45561 45891
4557 4590

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines