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.467 by root, Wed Sep 3 06:07:39 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 (
1336our @ISA = DC::UI::Bin::; 1344our @ISA = DC::UI::Bin::;
1337 1345
1338use DC::OpenGL; 1346use DC::OpenGL;
1339 1347
1340my $bg = 1348my $bg =
1341 new_from_file DC::Texture DC::find_rcfile "d1_bg.png", 1349 new_from_resource DC::Texture "d1_bg.png",
1342 mipmap => 1, wrap => 1; 1350 mipmap => 1, wrap => 1;
1343 1351
1344my @border = 1352my @border =
1345 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 1353 map { new_from_resource DC::Texture $_, mipmap => 1 }
1346 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); 1354 qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png);
1347 1355
1348my @icon = 1356my @icon =
1349 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 1357 map { new_from_resource DC::Texture $_, mipmap => 1 }
1350 qw(x1_move.png x1_resize.png); 1358 qw(x1_move.png x1_resize.png);
1351 1359
1352sub new { 1360sub new {
1353 my ($class, %arg) = @_; 1361 my ($class, %arg) = @_;
1354 1362
1355 my $self = $class->SUPER::new ( 1363 my $self = $class->SUPER::new (
1356 bg => [1, 1, 1, 1], 1364 bg => [1, 1, 1, 1],
1357 border_bg => [1, 1, 1, 1], 1365 border_bg => [1, 1, 1, 1],
1358 border => 0.6, 1366 border => 1,
1359 can_events => 1, 1367 can_events => 1,
1360 min_w => 64, 1368 min_w => 64,
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}
2152 2158
2153 my $text = $self->get_text; 2159 my $text = $self->get_text;
2154 2160
2155 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text; 2161 $self->{cursor} = List::Util::max 0, List::Util::min $self->{cursor}, length $text;
2156 2162
2157 if ($uni == 8) { 2163 if ($sym == DC::SDLK_BACKSPACE) {
2158 substr $text, --$self->{cursor}, 1, "" if $self->{cursor}; 2164 substr $text, --$self->{cursor}, 1, "" if $self->{cursor};
2159 } elsif ($uni == 127) { 2165 } elsif ($sym == DC::SDLK_DELETE) {
2160 substr $text, $self->{cursor}, 1, ""; 2166 substr $text, $self->{cursor}, 1, "";
2161 } elsif ($sym == DC::SDLK_LEFT) { 2167 } elsif ($sym == DC::SDLK_LEFT) {
2162 --$self->{cursor} if $self->{cursor}; 2168 --$self->{cursor} if $self->{cursor};
2163 } elsif ($sym == DC::SDLK_RIGHT) { 2169 } elsif ($sym == DC::SDLK_RIGHT) {
2164 ++$self->{cursor} if $self->{cursor} < length $self->{text}; 2170 ++$self->{cursor} if $self->{cursor} < length $self->{text};
2285 2291
2286our @ISA = DC::UI::EntryBase::; 2292our @ISA = DC::UI::EntryBase::;
2287 2293
2288use DC::OpenGL; 2294use DC::OpenGL;
2289 2295
2296sub new {
2297 my $class = shift;
2298
2299 $class->SUPER::new (
2300 history_pointer => -1,
2301 @_
2302 )
2303}
2304
2305
2290sub invoke_key_down { 2306sub invoke_key_down {
2291 my ($self, $ev) = @_; 2307 my ($self, $ev) = @_;
2292 2308
2293 my $sym = $ev->{sym}; 2309 my $sym = $ev->{sym};
2294 2310
2318 $self->{history_pointer} = -1 if $self->{history_pointer} < 0; 2334 $self->{history_pointer} = -1 if $self->{history_pointer} < 0;
2319 2335
2320 if ($self->{history_pointer} >= 0) { 2336 if ($self->{history_pointer} >= 0) {
2321 $self->set_text ($self->{history}->[$self->{history_pointer}]); 2337 $self->set_text ($self->{history}->[$self->{history_pointer}]);
2322 } else { 2338 } else {
2339 if (defined $self->{history_saveback}) {
2323 $self->set_text ($self->{history_saveback}); 2340 $self->set_text ($self->{history_saveback});
2341 $self->{history_saveback} = undef;
2342 }
2324 } 2343 }
2325 2344
2326 } else { 2345 } else {
2327 return $self->SUPER::invoke_key_down ($ev) 2346 return $self->SUPER::invoke_key_down ($ev)
2328 } 2347 }
2336 2355
2337our @ISA = DC::UI::EntryBase::; 2356our @ISA = DC::UI::EntryBase::;
2338 2357
2339use DC::OpenGL; 2358use DC::OpenGL;
2340 2359
2360sub new {
2361 my $class = shift;
2362
2363 $class->SUPER::new (
2364 padding_y => 4,
2365
2366 @_
2367 )
2368}
2369
2341sub move_cursor_ver { 2370sub move_cursor_ver {
2342 my ($self, $dy) = @_; 2371 my ($self, $dy) = @_;
2343 2372
2344 my ($y, $x) = $self->{layout}->index_to_line_x ($self->{cursor}); 2373 my ($line, $x) = $self->{layout}->index_to_line_x ($self->{cursor});
2345 2374
2346 $y += $dy; 2375 $line += $dy;
2347 2376
2348 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))) {
2349 $self->{cursor} = $index; 2378 $self->{cursor} = $index;
2350 delete $self->{cur_h}; 2379 delete $self->{cur_h};
2351 $self->update; 2380 $self->update;
2352 return; 2381 return;
2353 } 2382 }
2376our @ISA = DC::UI::Bin::; 2405our @ISA = DC::UI::Bin::;
2377 2406
2378use DC::OpenGL; 2407use DC::OpenGL;
2379 2408
2380my @tex = 2409my @tex =
2381 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2410 map { new_from_resource DC::Texture $_, mipmap => 1 }
2382 qw(b1_button_inactive.png b1_button_active.png); 2411 qw(b1_button_inactive.png b1_button_active.png);
2383 2412
2384sub new { 2413sub new {
2385 my $class = shift; 2414 my $class = shift;
2386 2415
2387 $class->SUPER::new ( 2416 $class->SUPER::new (
2388 can_hover => 1, 2417 can_hover => 1,
2389 align => 0, 2418 align => 0.5,
2390 valign => 0, 2419 valign => 0.5,
2391 can_events => 1, 2420 can_events => 1,
2392 @_ 2421 @_
2393 ) 2422 )
2394} 2423}
2395 2424
2425our @ISA = DC::UI::Label::; 2454our @ISA = DC::UI::Label::;
2426 2455
2427use DC::OpenGL; 2456use DC::OpenGL;
2428 2457
2429my @tex = 2458my @tex =
2430 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2459 map { new_from_resource DC::Texture $_, mipmap => 1 }
2431 qw(b1_button_inactive.png b1_button_active.png); 2460 qw(b1_button_inactive.png b1_button_active.png);
2432 2461
2433sub new { 2462sub new {
2434 my $class = shift; 2463 my $class = shift;
2435 2464
2437 padding_x => 8, 2466 padding_x => 8,
2438 padding_y => 4, 2467 padding_y => 4,
2439 fg => [1.0, 1.0, 1.0], 2468 fg => [1.0, 1.0, 1.0],
2440 active_fg => [0.8, 0.8, 0.8], 2469 active_fg => [0.8, 0.8, 0.8],
2441 can_hover => 1, 2470 can_hover => 1,
2442 align => 0, 2471 align => 0.5,
2443 valign => 0, 2472 valign => 0.5,
2444 can_events => 1, 2473 can_events => 1,
2445 @_ 2474 @_
2446 ) 2475 )
2447} 2476}
2448 2477
2478package DC::UI::CheckBox; 2507package DC::UI::CheckBox;
2479 2508
2480our @ISA = DC::UI::DrawBG::; 2509our @ISA = DC::UI::DrawBG::;
2481 2510
2482my @tex = 2511my @tex =
2483 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2512 map { new_from_resource DC::Texture $_, mipmap => 1 }
2484 qw(c1_checkbox_bg.png c1_checkbox_active.png); 2513 qw(c1_checkbox_bg.png c1_checkbox_active.png);
2485 2514
2486use DC::OpenGL; 2515use DC::OpenGL;
2487 2516
2488sub new { 2517sub new {
2569 2598
2570 $self->{path} || $self->{tex} 2599 $self->{path} || $self->{tex}
2571 or Carp::croak "'path' or 'tex' attributes required"; 2600 or Carp::croak "'path' or 'tex' attributes required";
2572 2601
2573 $self->{tex} ||= $texture_cache{$self->{path}} ||= 2602 $self->{tex} ||= $texture_cache{$self->{path}} ||=
2574 new_from_file DC::Texture DC::find_rcfile $self->{path}, mipmap => 1; 2603 new_from_resource DC::Texture $self->{path}, mipmap => 1;
2575 2604
2576 DC::weaken $texture_cache{$self->{path}}; 2605 DC::weaken $texture_cache{$self->{path}};
2577 2606
2578 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h}; 2607 $self->{aspect} ||= $self->{tex}{w} / $self->{tex}{h};
2579 2608
2640 padding_x => 4, 2669 padding_x => 4,
2641 padding_y => 4, 2670 padding_y => 4,
2642 fg => [1, 1, 1], 2671 fg => [1, 1, 1],
2643 active_fg => [0, 0, 1], 2672 active_fg => [0, 0, 1],
2644 can_hover => 1, 2673 can_hover => 1,
2645 align => 0, 2674 align => 0.5,
2646 valign => 0, 2675 valign => 0.5,
2647 can_events => 1, 2676 can_events => 1,
2648 @_ 2677 @_
2649 ); 2678 );
2650} 2679}
2651 2680
2675 2704
2676use DC::OpenGL; 2705use DC::OpenGL;
2677 2706
2678my %tex = ( 2707my %tex = (
2679 food => [ 2708 food => [
2680 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2709 map { new_from_resource DC::Texture $_, mipmap => 1 }
2681 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/ 2710 qw/g1_food_gauge_empty.png g1_food_gauge_full.png/
2682 ], 2711 ],
2683 grace => [ 2712 grace => [
2684 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2713 map { new_from_resource DC::Texture $_, mipmap => 1 }
2685 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/ 2714 qw/g1_grace_gauge_empty.png g1_grace_gauge_full.png g1_grace_gauge_overflow.png/
2686 ], 2715 ],
2687 hp => [ 2716 hp => [
2688 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2717 map { new_from_resource DC::Texture $_, mipmap => 1 }
2689 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/ 2718 qw/g1_hp_gauge_empty.png g1_hp_gauge_full.png/
2690 ], 2719 ],
2691 mana => [ 2720 mana => [
2692 map { new_from_file DC::Texture DC::find_rcfile $_, mipmap => 1 } 2721 map { new_from_resource DC::Texture $_, mipmap => 1 }
2693 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/ 2722 qw/g1_mana_gauge_empty.png g1_mana_gauge_full.png g1_mana_gauge_overflow.png/
2694 ], 2723 ],
2695); 2724);
2696 2725
2697# eg. VGauge->new (gauge => 'food'), default gauge: food 2726# eg. VGauge->new (gauge => 'food'), default gauge: food
2815 fg => [1, 1, 1], 2844 fg => [1, 1, 1],
2816 bg => [0, 0, 1, 0.2], 2845 bg => [0, 0, 1, 0.2],
2817 bar => [0.7, 0.5, 0.1, 0.8], 2846 bar => [0.7, 0.5, 0.1, 0.8],
2818 outline => [0.4, 0.3, 0], 2847 outline => [0.4, 0.3, 0],
2819 fontsize => 0.9, 2848 fontsize => 0.9,
2820 valign => 0, 2849 valign => 0.5,
2821 align => 0, 2850 align => 0.5,
2822 can_events => 1, 2851 can_events => 1,
2823 ellipsise => 1, 2852 ellipsise => 1,
2824 label => "%d%%", 2853 label => "%d%%",
2825 %arg, 2854 %arg,
2826 ); 2855 );
2952 can_hover => 1, 2981 can_hover => 1,
2953 can_events => 1, 2982 can_events => 1,
2954 %arg, 2983 %arg,
2955 ); 2984 );
2956 2985
2957 $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");
2958 $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);
2959 $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");
2960 2989
2961 $self 2990 $self
2962} 2991}
2963 2992
2964sub set_fontsize { 2993sub set_fontsize {
2994use DC::OpenGL; 3023use DC::OpenGL;
2995 3024
2996our @ISA = DC::UI::DrawBG::; 3025our @ISA = DC::UI::DrawBG::;
2997 3026
2998my @tex = 3027my @tex =
2999 map { new_from_file DC::Texture DC::find_rcfile $_ } 3028 map { new_from_resource DC::Texture $_ }
3000 qw(s1_slider.png s1_slider_bg.png); 3029 qw(s1_slider.png s1_slider_bg.png);
3001 3030
3002sub new { 3031sub new {
3003 my $class = shift; 3032 my $class = shift;
3004 3033
3041sub set_value { 3070sub set_value {
3042 my ($self, $value) = @_; 3071 my ($self, $value) = @_;
3043 3072
3044 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}}; 3073 my ($old_value, $lo, $hi, $page, $unit) = @{$self->{range}};
3045 3074
3046 $hi = $lo + 1 if $hi <= $lo; 3075 $hi = $lo if $hi < $lo;
3047 3076
3048 $page = $hi - $lo if $page > $hi - $lo; 3077 $value = $hi - $page if $value > $hi - $page;
3049
3050 $value = $lo if $value < $lo; 3078 $value = $lo if $value < $lo;
3051 $value = $hi - $page if $value > $hi - $page;
3052 3079
3053 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit 3080 $value = $lo + $unit * int +($value - $lo + $unit * 0.5) / $unit
3054 if $unit; 3081 if $unit;
3055 3082
3056 @{$self->{range}} = ($value, $lo, $hi, $page, $unit); 3083 @{$self->{range}} = ($value, $lo, $hi, $page, $unit);
3120 my ($self) = @_; 3147 my ($self) = @_;
3121 3148
3122 unless ($self->{knob_w}) { 3149 unless ($self->{knob_w}) {
3123 $self->set_value ($self->{range}[0]); 3150 $self->set_value ($self->{range}[0]);
3124 3151
3125 my ($value, $lo, $hi, $page) = @{$self->{range}}; 3152 my ($value, $lo, $hi, $page, $unit) = @{$self->{range}};
3126 my $range = ($hi - $page - $lo) || 1e-100; 3153 my $range = ($hi - $page - $lo) || 1e-10;
3127 3154
3128 my $knob_w = List::Util::min 1, $page / ($hi - $lo) || 0.1; 3155 my $knob_w = List::Util::min 1, $page / (($hi - $lo) || 1e-10) || 24 / $self->{w};
3129 3156
3130 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5; 3157 $self->{offset} = List::Util::max $self->{inner_pad}, $knob_w * 0.5;
3131 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100; 3158 $self->{scale} = 1 - 2 * $self->{offset} || 1e-100;
3132 3159
3133 $value = ($value - $lo) / $range; 3160 $value = ($value - $lo) / $range;
3292 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent}); 3319 $layout->set_indent ($self->{fontsize} * $::FONTSIZE * $self->{indent});
3293 $layout->set_markup ($para->{markup}); 3320 $layout->set_markup ($para->{markup});
3294 3321
3295 $layout->set_shapes ( 3322 $layout->set_shapes (
3296 map 3323 map
3297 +(0, $_->baseline_shift +$_->{padding_y} - $_->{h}, $_->{w}, $_->{h}), 3324 +(0, $_->baseline_shift + $_->{padding_y} - $_->{h}, $_->{w}, $_->{h}),
3298 @{$para->{widget}} 3325 @{$para->{widget}}
3299 ); 3326 );
3300 3327
3301 $layout 3328 $layout
3302} 3329}
3595 $tip =~ s/\n+$//; 3622 $tip =~ s/\n+$//;
3596 3623
3597 $self->add (new DC::UI::Label 3624 $self->add (new DC::UI::Label
3598 markup => $tip, 3625 markup => $tip,
3599 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3626 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3627 align => 0,
3600 fontsize => 0.8, 3628 fontsize => 0.8,
3601 style => 1, # FLAG_INVERSE 3629 style => 1, # FLAG_INVERSE
3602 ellipsise => 0, 3630 ellipsise => 0,
3603 font => ($widget->{tooltip_font} || $::FONT_PROP), 3631 font => ($widget->{tooltip_font} || $::FONT_PROP),
3604 ); 3632 );
3828 $widget = new DC::UI::HBox 3856 $widget = new DC::UI::HBox
3829 can_hover => 1, 3857 can_hover => 1,
3830 can_events => 1, 3858 can_events => 1,
3831 tooltip => $tooltip, 3859 tooltip => $tooltip,
3832 children => [ 3860 children => [
3833 (new DC::UI::Label markup => $left, expand => 1), 3861 (new DC::UI::Label markup => $left , align => 0, expand => 1),
3834 (new DC::UI::Label markup => $right, align => +1), 3862 (new DC::UI::Label markup => $right, align => 1),
3835 ], 3863 ],
3836 ; 3864 ;
3837 3865
3838 } else { 3866 } else {
3839 $widget = new DC::UI::Label 3867 $widget = new DC::UI::Label
3840 can_hover => 1, 3868 can_hover => 1,
3841 can_events => 1, 3869 can_events => 1,
3870 align => 0,
3842 markup => $widget, 3871 markup => $widget,
3843 tooltip => $tooltip; 3872 tooltip => $tooltip;
3844 } 3873 }
3845 } 3874 }
3846 3875
4037} 4066}
4038 4067
4039sub pages { 4068sub pages {
4040 my ($self) = @_; 4069 my ($self) = @_;
4041 $self->{multiplexer}->children 4070 $self->{multiplexer}->children
4071}
4072
4073sub page_index {
4074 my ($self, $widget) = @_;
4075
4076 my $i = 0;
4077 for ($self->pages) {
4078 if ($_ eq $widget) { return $i };
4079 $i++;
4080 }
4081
4082 undef
4042} 4083}
4043 4084
4044sub add_tab { 4085sub add_tab {
4045 my ($self, $title, $widget, $tooltip) = @_; 4086 my ($self, $title, $widget, $tooltip) = @_;
4046 4087
4210 tooltip => $item->{tooltip}, 4251 tooltip => $item->{tooltip},
4211 tooltip_font => $::FONT_PROP, 4252 tooltip_font => $::FONT_PROP,
4212 tooltip_width => 0.67, 4253 tooltip_width => 0.67,
4213 fontsize => $item->{fontsize} || $self->{fontsize}, 4254 fontsize => $item->{fontsize} || $self->{fontsize},
4214 max_w => $::WIDTH * 0.44, 4255 max_w => $::WIDTH * 0.44,
4256 align => 0,
4215 fg => [@{ $item->{fg} }], 4257 fg => [@{ $item->{fg} }],
4216 can_events => 1, 4258 can_events => 1,
4217 can_hover => 1 4259 can_hover => 1
4218 }; 4260 };
4219 4261
4443 4485
4444 delete $queue{$widget+0}; 4486 delete $queue{$widget+0};
4445 4487
4446 my ($w, $h) = $widget->size_request; 4488 my ($w, $h) = $widget->size_request;
4447 4489
4448 $w = max $widget->{min_w}, $w + $widget->{padding_x} * 2; 4490 $w += $widget->{padding_x} * 2;
4449 $h = max $widget->{min_h}, $h + $widget->{padding_y} * 2; 4491 $h += $widget->{padding_y} * 2;
4492
4493 $w = max $widget->{min_w}, $w;
4494 $h = max $widget->{min_h}, $h;
4450 4495
4451 $w = min $widget->{max_w}, $w if exists $widget->{max_w}; 4496 $w = min $widget->{max_w}, $w if exists $widget->{max_w};
4452 $h = min $widget->{max_h}, $h if exists $widget->{max_h}; 4497 $h = min $widget->{max_h}, $h if exists $widget->{max_h};
4453 4498
4454 $w = $widget->{force_w} if exists $widget->{force_w}; 4499 $w = $widget->{force_w} if exists $widget->{force_w};
4534 4579
4535############################################################################# 4580#############################################################################
4536 4581
4537package DC::UI; 4582package DC::UI;
4538 4583
4539$ROOT = new DC::UI::Root; 4584$ROOT = new DC::UI::Root;
4540$TOOLTIP = new DC::UI::Tooltip z => 900; 4585$TOOLTIP = new DC::UI::Tooltip z => 900;
4541 4586
45421 45871
4543 4588

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines