… | |
… | |
2 | |
2 | |
3 | use utf8; |
3 | use utf8; |
4 | use strict; |
4 | use strict; |
5 | |
5 | |
6 | use List::Util (); |
6 | use List::Util (); |
|
|
7 | |
|
|
8 | use Guard (); |
7 | |
9 | |
8 | use DC; |
10 | use DC; |
9 | use DC::Pod; |
11 | use DC::Pod; |
10 | use DC::Texture; |
12 | use DC::Texture; |
11 | |
13 | |
… | |
… | |
189 | # call when resolution changes etc. |
191 | # call when resolution changes etc. |
190 | sub rescale_widgets { |
192 | sub rescale_widgets { |
191 | my ($sx, $sy) = @_; |
193 | my ($sx, $sy) = @_; |
192 | |
194 | |
193 | for my $widget (values %WIDGET) { |
195 | for my $widget (values %WIDGET) { |
194 | if ($widget->{is_toplevel}) { |
196 | if ($widget->{is_toplevel} || $widget->{c_rescale}) { |
195 | $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
197 | $widget->{x} += int $widget->{w} * 0.5 if $widget->{x} =~ /^[0-9.]+$/; |
196 | $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
198 | $widget->{y} += int $widget->{h} * 0.5 if $widget->{y} =~ /^[0-9.]+$/; |
197 | |
199 | |
198 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
200 | $widget->{x} = int 0.5 + $widget->{x} * $sx if $widget->{x} =~ /^[0-9.]+$/; |
199 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
201 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
… | |
… | |
286 | sub set_visible { |
288 | sub set_visible { |
287 | my ($self) = @_; |
289 | my ($self) = @_; |
288 | |
290 | |
289 | return if $self->{visible}; |
291 | return if $self->{visible}; |
290 | |
292 | |
|
|
293 | $self->{parent} && $self->{parent}{root}#d# |
|
|
294 | or return ::clienterror ("set_visible called without parent ($self->{parent}) or root\n" => 1); |
|
|
295 | |
291 | $self->{root} = $self->{parent}{root}; |
296 | $self->{root} = $self->{parent}{root}; |
292 | $self->{visible} = $self->{parent}{visible} + 1; |
297 | $self->{visible} = $self->{parent}{visible} + 1; |
293 | |
298 | |
294 | $self->emit (visibility_change => 1); |
299 | $self->emit (visibility_change => 1); |
295 | |
300 | |
296 | $self->realloc if !exists $self->{req_w}; |
301 | $self->realloc if !exists $self->{req_w}; |
297 | |
302 | |
298 | $_->set_visible for $self->children; |
303 | $_->set_visible for $self->visible_children; |
299 | } |
304 | } |
300 | |
305 | |
301 | sub set_invisible { |
306 | sub set_invisible { |
302 | my ($self) = @_; |
307 | my ($self) = @_; |
303 | |
308 | |
… | |
… | |
527 | sub connect { |
532 | sub connect { |
528 | my ($self, $signal, $cb) = @_; |
533 | my ($self, $signal, $cb) = @_; |
529 | |
534 | |
530 | push @{ $self->{signal_cb}{$signal} }, $cb; |
535 | push @{ $self->{signal_cb}{$signal} }, $cb; |
531 | |
536 | |
532 | defined wantarray and DC::guard { |
537 | defined wantarray and Guard::guard { |
533 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
538 | @{ $self->{signal_cb}{$signal} } = grep $_ != $cb, |
534 | @{ $self->{signal_cb}{$signal} }; |
539 | @{ $self->{signal_cb}{$signal} }; |
535 | } |
540 | } |
536 | } |
541 | } |
537 | |
542 | |
… | |
… | |
1256 | fontsize => ($arg{border} || 0.8) * 0.75; |
1261 | fontsize => ($arg{border} || 0.8) * 0.75; |
1257 | } |
1262 | } |
1258 | |
1263 | |
1259 | my $self = $class->SUPER::new ( |
1264 | my $self = $class->SUPER::new ( |
1260 | # label => "", |
1265 | # label => "", |
1261 | fg => [0.6, 0.3, 0.1], |
1266 | fg => undef, |
1262 | border => 0.8, |
1267 | border => 0.8, |
1263 | style => 'single', |
1268 | style => 'single', |
1264 | %arg, |
1269 | %arg, |
1265 | ); |
1270 | ); |
1266 | |
1271 | |
… | |
… | |
1319 | my $border = $self->border; |
1324 | my $border = $self->border; |
1320 | my ($w, $h) = ($self->{w}, $self->{h}); |
1325 | my ($w, $h) = ($self->{w}, $self->{h}); |
1321 | |
1326 | |
1322 | $child->draw; |
1327 | $child->draw; |
1323 | |
1328 | |
1324 | glColor @{$self->{fg}}; |
1329 | glColor @{$self->{fg} || $DC::THEME{fancyframe}}; |
1325 | glBegin GL_LINE_STRIP; |
1330 | glBegin GL_LINE_STRIP; |
1326 | glVertex $border * 1.5 , $border * 0.5 + 0.5; |
1331 | glVertex $border * 1.5 , $border * 0.5 + 0.5; |
1327 | glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
1332 | glVertex $border * 0.5 + 0.5, $border * 0.5 + 0.5; |
1328 | glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
1333 | glVertex $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
1329 | glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
1334 | glVertex $w - $border * 0.5 + 0.5, $h - $border * 0.5 + 0.5; |
… | |
… | |
1361 | my ($class, %arg) = @_; |
1366 | my ($class, %arg) = @_; |
1362 | |
1367 | |
1363 | my $self = $class->SUPER::new ( |
1368 | my $self = $class->SUPER::new ( |
1364 | bg => [1, 1, 1, 1], |
1369 | bg => [1, 1, 1, 1], |
1365 | border_bg => [1, 1, 1, 1], |
1370 | border_bg => [1, 1, 1, 1], |
1366 | border => 1, |
1371 | border => 0.8, |
1367 | can_events => 1, |
1372 | can_events => 1, |
1368 | min_w => 64, |
1373 | min_w => 64, |
1369 | min_h => 32, |
1374 | min_h => 32, |
1370 | %arg, |
1375 | %arg, |
1371 | ); |
1376 | ); |
… | |
… | |
1540 | glEnable GL_TEXTURE_2D; |
1545 | glEnable GL_TEXTURE_2D; |
1541 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1546 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1542 | |
1547 | |
1543 | my $border = $self->border; |
1548 | my $border = $self->border; |
1544 | |
1549 | |
|
|
1550 | if ($border) { |
1545 | glColor @{ $self->{border_bg} }; |
1551 | glColor @{ $self->{border_bg} }; |
1546 | $border[0]->draw_quad_alpha ( 0, 0, $w, $border); |
1552 | $border[0]->draw_quad_alpha ( 0, 0, $w, $border); |
1547 | $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); |
1553 | $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); |
1548 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1554 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1549 | $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); |
1555 | $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); |
1550 | |
1556 | |
1551 | # move |
1557 | # move |
1552 | my $w2 = ($w - $border) * .5; |
1558 | my $w2 = ($w - $border) * .5; |
1553 | my $h2 = ($h - $border) * .5; |
1559 | my $h2 = ($h - $border) * .5; |
1554 | $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); |
1560 | $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); |
1555 | $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); |
1561 | $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); |
1556 | $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); |
1562 | $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); |
1557 | |
1563 | |
1558 | # resize |
1564 | # resize |
1559 | $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); |
1565 | $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); |
1560 | $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) |
1566 | $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) |
1561 | unless $self->{has_close_button}; |
1567 | unless $self->{has_close_button}; |
1562 | $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); |
1568 | $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); |
1563 | $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); |
1569 | $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); |
|
|
1570 | } |
1564 | |
1571 | |
1565 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1572 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1566 | glColor @{ $self->{bg} }; |
1573 | glColor @{ $self->{bg} }; |
1567 | |
1574 | |
1568 | # TODO: repeat texture not scale |
1575 | # TODO: repeat texture not scale |
… | |
… | |
2090 | my $class = shift; |
2097 | my $class = shift; |
2091 | |
2098 | |
2092 | $class->SUPER::new ( |
2099 | $class->SUPER::new ( |
2093 | fg => [1, 1, 1], |
2100 | fg => [1, 1, 1], |
2094 | bg => [0, 0, 0, 0.2], |
2101 | bg => [0, 0, 0, 0.2], |
2095 | outline => [0.6, 0.3, 0.1], |
2102 | outline => undef, |
2096 | active_bg => [0, 0, 1, .2], |
2103 | active_bg => [0, 0, 1, .2], |
2097 | active_fg => [1, 1, 1], |
2104 | active_fg => [1, 1, 1], |
2098 | active_outline => [1, 1, 0], |
2105 | active_outline => [1, 1, 0], |
2099 | can_hover => 1, |
2106 | can_hover => 1, |
2100 | can_focus => 1, |
2107 | can_focus => 1, |
… | |
… | |
2273 | glColor @{$self->{active_outline}}; |
2280 | glColor @{$self->{active_outline}}; |
2274 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2281 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2275 | glLineWidth 1; |
2282 | glLineWidth 1; |
2276 | |
2283 | |
2277 | } else { |
2284 | } else { |
2278 | glColor @{$self->{outline}}; |
2285 | glColor @{$self->{outline} || $DC::THEME{entry_outline}}; |
2279 | glBegin GL_LINE_STRIP; |
2286 | glBegin GL_LINE_STRIP; |
2280 | glVertex .5, $self->{h} * .5; |
2287 | glVertex .5, $self->{h} * .5; |
2281 | glVertex .5, $self->{h} - 2.5; |
2288 | glVertex .5, $self->{h} - 2.5; |
2282 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
2289 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
2283 | glVertex $self->{w} - .5, $self->{h} * .5; |
2290 | glVertex $self->{w} - .5, $self->{h} * .5; |
… | |
… | |
2516 | |
2523 | |
2517 | sub new { |
2524 | sub new { |
2518 | my $class = shift; |
2525 | my $class = shift; |
2519 | |
2526 | |
2520 | $class->SUPER::new ( |
2527 | $class->SUPER::new ( |
|
|
2528 | fontsize => 1, |
2521 | padding_x => 2, |
2529 | padding_x => 2, |
2522 | padding_y => 2, |
2530 | padding_y => 2, |
2523 | fg => [1, 1, 1], |
2531 | fg => [1, 1, 1], |
2524 | active_fg => [1, 1, 0], |
2532 | active_fg => [1, 1, 0], |
2525 | bg => [0, 0, 0, 0.2], |
2533 | bg => [0, 0, 0, 0.2], |
… | |
… | |
2531 | } |
2539 | } |
2532 | |
2540 | |
2533 | sub size_request { |
2541 | sub size_request { |
2534 | my ($self) = @_; |
2542 | my ($self) = @_; |
2535 | |
2543 | |
2536 | (6) x 2 |
2544 | ($self->{fontsize} * $::FONTSIZE) x 2 |
2537 | } |
2545 | } |
2538 | |
2546 | |
2539 | sub toggle { |
2547 | sub toggle { |
2540 | my ($self) = @_; |
2548 | my ($self) = @_; |
2541 | |
2549 | |
… | |
… | |
2839 | |
2847 | |
2840 | sub new { |
2848 | sub new { |
2841 | my ($class, %arg) = @_; |
2849 | my ($class, %arg) = @_; |
2842 | |
2850 | |
2843 | my $self = $class->SUPER::new ( |
2851 | my $self = $class->SUPER::new ( |
|
|
2852 | padding_x => 2, |
|
|
2853 | padding_y => 2, |
2844 | fg => [1, 1, 1], |
2854 | fg => [1, 1, 1], |
2845 | bg => [0, 0, 1, 0.2], |
2855 | bg => [0, 0, 1, 0.2], |
2846 | bar => [0.7, 0.5, 0.1, 0.8], |
2856 | bar => [0.7, 0.5, 0.1, 0.8], |
2847 | outline => [0.4, 0.3, 0], |
2857 | outline => [0.4, 0.3, 0], |
2848 | fontsize => 0.9, |
2858 | fontsize => 0.9, |
… | |
… | |
2888 | my ($self) = @_; |
2898 | my ($self) = @_; |
2889 | |
2899 | |
2890 | glEnable GL_BLEND; |
2900 | glEnable GL_BLEND; |
2891 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2901 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2892 | |
2902 | |
|
|
2903 | my $px = $self->{padding_x}; |
|
|
2904 | my $py = $self->{padding_y}; |
|
|
2905 | |
2893 | if ($self->{value} >= 0) { |
2906 | if ($self->{value} >= 0) { |
2894 | my $s = int 2 + ($self->{w} - 4) * $self->{value}; |
2907 | my $s = int $px + ($self->{w} - $px * 2) * $self->{value}; |
2895 | |
2908 | |
2896 | glColor_premultiply @{$self->{bar}}; |
2909 | glColor_premultiply @{$self->{bar}}; |
2897 | glRect 2, 2, $s, $self->{h} - 2; |
2910 | glRect $px, $py, $s, $self->{h} - $py; |
2898 | glColor_premultiply @{$self->{bg}}; |
2911 | glColor_premultiply @{$self->{bg}}; |
2899 | glRect $s, 2, $self->{w} - 2, $self->{h} - 2; |
2912 | glRect $s , $py, $self->{w} - $px, $self->{h} - $py; |
2900 | } |
2913 | } |
2901 | |
2914 | |
2902 | glColor_premultiply @{$self->{outline}}; |
2915 | glColor_premultiply @{$self->{outline}}; |
|
|
2916 | |
|
|
2917 | $px -= .5; |
|
|
2918 | $py -= .5; |
|
|
2919 | |
2903 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2920 | glRect_lineloop $px, $py, $self->{w} - $px, $self->{h} - $py; |
2904 | |
2921 | |
2905 | glDisable GL_BLEND; |
2922 | glDisable GL_BLEND; |
2906 | |
2923 | |
2907 | { |
2924 | { |
2908 | local $self->{bg}; # do not draw background |
2925 | local $self->{bg}; # do not draw background |
… | |
… | |
2917 | our @ISA = DC::UI::Progress::; |
2934 | our @ISA = DC::UI::Progress::; |
2918 | |
2935 | |
2919 | sub new { |
2936 | sub new { |
2920 | my ($class, %arg) = @_; |
2937 | my ($class, %arg) = @_; |
2921 | |
2938 | |
|
|
2939 | my $tt = exists $arg{tooltip} ? "$arg{tooltip}\n\n" : ""; |
|
|
2940 | |
2922 | my $self = $class->SUPER::new ( |
2941 | my $self = $class->SUPER::new ( |
|
|
2942 | %arg, |
2923 | tooltip => sub { |
2943 | tooltip => sub { |
2924 | my ($self) = @_; |
2944 | my ($self) = @_; |
2925 | |
2945 | |
2926 | sprintf "level %d\n%s points\n%s next level\n%s to go", |
2946 | sprintf "%slevel %d\n%s points\n%s next level\n%s to go / %d%%", |
|
|
2947 | $tt, |
2927 | $self->{lvl}, |
2948 | $self->{lvl}, |
2928 | ::formsep ($self->{exp}), |
2949 | ::formsep ($self->{exp}), |
2929 | ::formsep ($self->{nxt}), |
2950 | ::formsep ($self->{nxt}), |
2930 | ::formsep ($self->{nxt} - $self->{exp}), |
2951 | ::formsep ($self->{nxt} - $self->{exp}), |
|
|
2952 | $self->_percent * 100, |
2931 | }, |
2953 | }, |
2932 | %arg |
|
|
2933 | ); |
2954 | ); |
2934 | |
2955 | |
2935 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
2956 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
2936 | if $::CONN; |
2957 | if $::CONN; |
2937 | |
2958 | |
… | |
… | |
2945 | if $::CONN; |
2966 | if $::CONN; |
2946 | |
2967 | |
2947 | $self->SUPER::DESTROY; |
2968 | $self->SUPER::DESTROY; |
2948 | } |
2969 | } |
2949 | |
2970 | |
|
|
2971 | sub _percent { |
|
|
2972 | my ($self) = @_; |
|
|
2973 | |
|
|
2974 | my $table = $::CONN && $::CONN->{exp_table} |
|
|
2975 | or return -1; |
|
|
2976 | |
|
|
2977 | my $l0 = $table->[$self->{lvl} - 1]; |
|
|
2978 | my $l1 = $table->[$self->{lvl}]; |
|
|
2979 | |
|
|
2980 | $self->{nxt} = $l1; |
|
|
2981 | |
|
|
2982 | ($self->{exp} - $l0) / ($l1 - $l0) |
|
|
2983 | } |
|
|
2984 | |
2950 | sub set_value { |
2985 | sub set_value { |
2951 | my ($self, $lvl, $exp) = @_; |
2986 | my ($self, $lvl, $exp) = @_; |
2952 | |
2987 | |
2953 | $self->{lvl} = $lvl; |
2988 | $self->{lvl} = $lvl; |
2954 | $self->{exp} = $exp; |
2989 | $self->{exp} = $exp; |
2955 | |
2990 | |
2956 | my $v = -1; |
|
|
2957 | |
|
|
2958 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
|
|
2959 | my $l0 = $table->[$lvl - 1]; |
|
|
2960 | my $l1 = $table->[$lvl]; |
|
|
2961 | |
|
|
2962 | $self->{nxt} = $l1; |
|
|
2963 | |
|
|
2964 | $v = ($exp - $l0) / ($l1 - $l0); |
|
|
2965 | } |
|
|
2966 | |
|
|
2967 | $self->SUPER::set_value ($v); |
2991 | $self->SUPER::set_value ($self->_percent); |
2968 | } |
2992 | } |
2969 | |
2993 | |
2970 | ############################################################################# |
2994 | ############################################################################# |
2971 | |
2995 | |
2972 | package DC::UI::Gauge; |
2996 | package DC::UI::Gauge; |
… | |
… | |
3620 | |
3644 | |
3621 | $tip =~ s/^\n+//; |
3645 | $tip =~ s/^\n+//; |
3622 | $tip =~ s/\n+$//; |
3646 | $tip =~ s/\n+$//; |
3623 | |
3647 | |
3624 | $self->add (new DC::UI::Label |
3648 | $self->add (new DC::UI::Label |
|
|
3649 | fg => $DC::THEME{tooltip_fg}, |
3625 | markup => $tip, |
3650 | markup => $tip, |
3626 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3651 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3627 | align => 0, |
3652 | align => 0, |
3628 | fontsize => 0.8, |
3653 | fontsize => 0.8, |
3629 | style => 1, # FLAG_INVERSE |
3654 | style => $DC::THEME{tooltip_style}, # FLAG_INVERSE |
3630 | ellipsise => 0, |
3655 | ellipsise => 0, |
3631 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3656 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3632 | ); |
3657 | ); |
3633 | } |
3658 | } |
3634 | |
3659 | |
… | |
… | |
3671 | sub _draw { |
3696 | sub _draw { |
3672 | my ($self) = @_; |
3697 | my ($self) = @_; |
3673 | |
3698 | |
3674 | my ($w, $h) = @$self{qw(w h)}; |
3699 | my ($w, $h) = @$self{qw(w h)}; |
3675 | |
3700 | |
3676 | glColor 1, 0.8, 0.4; |
3701 | glColor @{ $DC::THEME{tooltip_bg} }; |
3677 | glRect 0, 0, $w, $h; |
3702 | glRect 0, 0, $w, $h; |
3678 | |
3703 | |
3679 | glColor 0, 0, 0; |
3704 | glColor @{ $DC::THEME{tooltip_border} }; |
3680 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3705 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3681 | |
3706 | |
3682 | glTranslate 2, 2; |
3707 | glTranslate 2, 2; |
3683 | |
3708 | |
3684 | $self->SUPER::_draw; |
3709 | $self->SUPER::_draw; |
… | |
… | |
3890 | # maybe save $GRAB? must be careful about events... |
3915 | # maybe save $GRAB? must be careful about events... |
3891 | $GRAB = $self; |
3916 | $GRAB = $self; |
3892 | $self->{button} = $ev->{button}; |
3917 | $self->{button} = $ev->{button}; |
3893 | |
3918 | |
3894 | $self->show; |
3919 | $self->show; |
3895 | $self->move_abs ($ev->{x} - $self->{w} * 0.5, $ev->{y} - $self->{h} * 0.5); |
3920 | |
|
|
3921 | my $x = $ev->{x}; |
|
|
3922 | my $y = $ev->{y}; |
|
|
3923 | |
|
|
3924 | $self->{root}->on_post_alloc ($self => sub { |
|
|
3925 | $self->move_abs ($x - $self->{w} * 0.25, $y - $self->{border} * $::FONTSIZE * .5); |
|
|
3926 | }); |
|
|
3927 | |
|
|
3928 | 1 # so it can be used inside event handlers |
3896 | } |
3929 | } |
3897 | |
3930 | |
3898 | sub invoke_mouse_motion { |
3931 | sub invoke_mouse_motion { |
3899 | my ($self, $ev, $x, $y) = @_; |
3932 | my ($self, $ev, $x, $y) = @_; |
3900 | |
3933 | |
… | |
… | |
3932 | |
3965 | |
3933 | my $self = $class->SUPER::new ( |
3966 | my $self = $class->SUPER::new ( |
3934 | @_, |
3967 | @_, |
3935 | ); |
3968 | ); |
3936 | |
3969 | |
3937 | $self->{current} = $self->{children}[0] |
3970 | $self->set_current_page (0); |
3938 | if @{ $self->{children} }; |
|
|
3939 | |
3971 | |
3940 | $self |
3972 | $self |
3941 | } |
3973 | } |
3942 | |
3974 | |
3943 | sub add { |
3975 | sub add { |
3944 | my ($self, @widgets) = @_; |
3976 | my ($self, @widgets) = @_; |
3945 | |
3977 | |
3946 | $self->SUPER::add (@widgets); |
3978 | $self->SUPER::add (@widgets); |
3947 | |
3979 | |
3948 | $self->{current} = $self->{children}[0] |
3980 | $self->set_current_page (0) |
3949 | if @{ $self->{children} }; |
3981 | if @widgets == @{ $self->{children} }; |
3950 | } |
3982 | } |
3951 | |
3983 | |
3952 | sub get_current_page { |
3984 | sub get_current_page { |
3953 | my ($self) = @_; |
3985 | my ($self) = @_; |
3954 | |
3986 | |
… | |
… | |
3960 | |
3992 | |
3961 | my $widget = ref $page_or_widget |
3993 | my $widget = ref $page_or_widget |
3962 | ? $page_or_widget |
3994 | ? $page_or_widget |
3963 | : $self->{children}[$page_or_widget]; |
3995 | : $self->{children}[$page_or_widget]; |
3964 | |
3996 | |
|
|
3997 | $self->{current}->set_invisible if $self->{current} && $self->{visible}; |
|
|
3998 | |
3965 | $self->{current} = $widget; |
3999 | if (($self->{current} = $widget)) { |
|
|
4000 | $self->{current}->set_visible if $self->{current} && $self->{visible}; |
3966 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
4001 | $self->{current}->configure (0, 0, $self->{w}, $self->{h}); |
3967 | |
4002 | |
3968 | $self->emit (page_changed => $self->{current}); |
4003 | $self->emit (page_changed => $self->{current}); |
|
|
4004 | } |
3969 | |
4005 | |
3970 | $self->realloc; |
4006 | $self->realloc; |
3971 | } |
4007 | } |
3972 | |
4008 | |
3973 | sub visible_children { |
4009 | sub visible_children { |
3974 | $_[0]{current} |
4010 | $_[0]{current} || () |
3975 | } |
4011 | } |
3976 | |
4012 | |
3977 | sub size_request { |
4013 | sub size_request { |
3978 | my ($self) = @_; |
4014 | my ($self) = @_; |
3979 | |
4015 | |
|
|
4016 | $self->{current} |
3980 | $self->{current}->size_request |
4017 | ? $self->{current}->size_request |
|
|
4018 | : (0, 0) |
3981 | } |
4019 | } |
3982 | |
4020 | |
3983 | sub invoke_size_allocate { |
4021 | sub invoke_size_allocate { |
3984 | my ($self, $w, $h) = @_; |
4022 | my ($self, $w, $h) = @_; |
3985 | |
4023 | |
3986 | $self->{current}->configure (0, 0, $w, $h); |
4024 | $self->{current}->configure (0, 0, $w, $h) |
|
|
4025 | if $self->{current}; |
3987 | |
4026 | |
3988 | 1 |
4027 | 1 |
3989 | } |
4028 | } |
3990 | |
4029 | |
3991 | sub _draw { |
4030 | sub _draw { |
3992 | my ($self) = @_; |
4031 | my ($self) = @_; |
3993 | |
4032 | |
3994 | $self->{current}->draw; |
4033 | $self->{current}->draw |
|
|
4034 | if $self->{current}; |
3995 | } |
4035 | } |
3996 | |
4036 | |
3997 | ############################################################################# |
4037 | ############################################################################# |
3998 | |
4038 | |
3999 | package DC::UI::Notebook; |
4039 | package DC::UI::Notebook; |
… | |
… | |
4209 | $self |
4249 | $self |
4210 | } |
4250 | } |
4211 | |
4251 | |
4212 | sub reorder { |
4252 | sub reorder { |
4213 | my ($self) = @_; |
4253 | my ($self) = @_; |
4214 | my $NOW = Time::HiRes::time; |
4254 | my $NOW = EV::time; |
4215 | |
4255 | |
4216 | # freeze display when hovering over any label |
4256 | # freeze display when hovering over any label |
4217 | return if $DC::UI::TOOLTIP->{owner} |
4257 | return if $DC::UI::TOOLTIP->{owner} |
4218 | && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, |
4258 | && grep $DC::UI::TOOLTIP->{owner} == $_->{label}, |
4219 | values %{ $self->{item} }; |
4259 | values %{ $self->{item} }; |
… | |
… | |
4269 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4309 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4270 | } |
4310 | } |
4271 | |
4311 | |
4272 | push @widgets, $label; |
4312 | push @widgets, $label; |
4273 | } |
4313 | } |
|
|
4314 | |
|
|
4315 | my $hash = join ",", @widgets; |
|
|
4316 | return if $hash eq $self->{last_widget_hash}; |
|
|
4317 | $self->{last_widget_hash} = $hash; |
4274 | |
4318 | |
4275 | $self->clear; |
4319 | $self->clear; |
4276 | $self->SUPER::add (reverse @widgets); |
4320 | $self->SUPER::add (reverse @widgets); |
4277 | } |
4321 | } |
4278 | |
4322 | |
… | |
… | |
4583 | |
4627 | |
4584 | $ROOT = new DC::UI::Root; |
4628 | $ROOT = new DC::UI::Root; |
4585 | $TOOLTIP = new DC::UI::Tooltip z => 900; |
4629 | $TOOLTIP = new DC::UI::Tooltip z => 900; |
4586 | |
4630 | |
4587 | 1 |
4631 | 1 |
4588 | |
|
|