… | |
… | |
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 | use Event; |
|
|
8 | |
7 | |
9 | use CFPlus; |
8 | use CFPlus; |
10 | use CFPlus::Pod; |
9 | use CFPlus::Pod; |
11 | use CFPlus::Texture; |
10 | use CFPlus::Texture; |
12 | |
11 | |
… | |
… | |
17 | our $TOOLTIP; |
16 | our $TOOLTIP; |
18 | our $BUTTON_STATE; |
17 | our $BUTTON_STATE; |
19 | |
18 | |
20 | our %WIDGET; # all widgets, weak-referenced |
19 | our %WIDGET; # all widgets, weak-referenced |
21 | |
20 | |
22 | our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { |
21 | our $TOOLTIP_WATCHER = EV::timer_ns 0, 1/60, sub { |
|
|
22 | $_[0]->stop; |
|
|
23 | |
23 | if (!$GRAB) { |
24 | if (!$GRAB) { |
24 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
25 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
25 | if (length $widget->{tooltip}) { |
26 | if (length $widget->{tooltip}) { |
26 | if ($TOOLTIP->{owner} != $widget) { |
27 | if ($TOOLTIP->{owner} != $widget) { |
27 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
28 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
… | |
… | |
42 | } |
43 | } |
43 | |
44 | |
44 | $TOOLTIP->hide; |
45 | $TOOLTIP->hide; |
45 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
46 | $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; |
46 | delete $TOOLTIP->{owner}; |
47 | delete $TOOLTIP->{owner}; |
47 | }); |
48 | }; |
48 | |
49 | |
49 | sub get_layout { |
50 | sub get_layout { |
50 | my $layout; |
51 | my $layout; |
51 | |
52 | |
52 | for (grep { $_->{name} } values %WIDGET) { |
53 | for (grep { $_->{name} } values %WIDGET) { |
… | |
… | |
87 | my $hover = $HOVER; $HOVER = $widget; |
88 | my $hover = $HOVER; $HOVER = $widget; |
88 | |
89 | |
89 | $hover->update if $hover && $hover->{can_hover}; |
90 | $hover->update if $hover && $hover->{can_hover}; |
90 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
91 | $HOVER->update if $HOVER && $HOVER->{can_hover}; |
91 | |
92 | |
92 | $TOOLTIP_WATCHER->start; |
93 | $TOOLTIP_WATCHER->again; |
93 | } |
94 | } |
94 | } |
95 | } |
95 | |
96 | |
96 | sub feed_sdl_button_down_event { |
97 | sub feed_sdl_button_down_event { |
97 | my ($ev) = @_; |
98 | my ($ev) = @_; |
… | |
… | |
103 | my $widget = $ROOT->find_widget ($x, $y); |
104 | my $widget = $ROOT->find_widget ($x, $y); |
104 | |
105 | |
105 | $GRAB = $widget; |
106 | $GRAB = $widget; |
106 | $GRAB->update if $GRAB; |
107 | $GRAB->update if $GRAB; |
107 | |
108 | |
108 | $TOOLTIP_WATCHER->cb->(); |
109 | $TOOLTIP_WATCHER->invoke; |
109 | } |
110 | } |
110 | |
111 | |
111 | if ($GRAB) { |
112 | if ($GRAB) { |
112 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
113 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
113 | # mousewheel |
114 | # mousewheel |
… | |
… | |
138 | my $grab = $GRAB; undef $GRAB; |
139 | my $grab = $GRAB; undef $GRAB; |
139 | $grab->update if $grab; |
140 | $grab->update if $grab; |
140 | $GRAB->update if $GRAB; |
141 | $GRAB->update if $GRAB; |
141 | |
142 | |
142 | check_hover $widget; |
143 | check_hover $widget; |
143 | $TOOLTIP_WATCHER->cb->(); |
144 | $TOOLTIP_WATCHER->invoke; |
144 | } |
145 | } |
145 | } |
146 | } |
146 | |
147 | |
147 | sub feed_sdl_motion_event { |
148 | sub feed_sdl_motion_event { |
148 | my ($ev) = @_; |
149 | my ($ev) = @_; |
… | |
… | |
269 | $self->emit ("destroy"); |
270 | $self->emit ("destroy"); |
270 | %$self = (); |
271 | %$self = (); |
271 | } |
272 | } |
272 | |
273 | |
273 | sub TO_JSON { |
274 | sub TO_JSON { |
274 | { __w_ => $_[0]{s_id} } |
275 | { "\fw" => $_[0]{s_id} } |
275 | } |
276 | } |
276 | |
277 | |
277 | sub show { |
278 | sub show { |
278 | my ($self) = @_; |
279 | my ($self) = @_; |
279 | |
280 | |
… | |
… | |
308 | delete $self->{root}; |
309 | delete $self->{root}; |
309 | |
310 | |
310 | undef $GRAB if $GRAB == $self; |
311 | undef $GRAB if $GRAB == $self; |
311 | undef $HOVER if $HOVER == $self; |
312 | undef $HOVER if $HOVER == $self; |
312 | |
313 | |
313 | $CFPlus::UI::TOOLTIP_WATCHER->cb->() |
314 | $CFPlus::UI::TOOLTIP_WATCHER->invoke |
314 | if $TOOLTIP->{owner} == $self; |
315 | if $TOOLTIP->{owner} == $self; |
315 | |
316 | |
316 | $self->emit ("focus_out"); |
317 | $self->emit ("focus_out"); |
317 | $self->emit (visibility_change => 0); |
318 | $self->emit (visibility_change => 0); |
318 | } |
319 | } |
… | |
… | |
358 | |
359 | |
359 | $self->{force_w} = $w; |
360 | $self->{force_w} = $w; |
360 | $self->{force_h} = $h; |
361 | $self->{force_h} = $h; |
361 | |
362 | |
362 | $self->realloc; |
363 | $self->realloc; |
|
|
364 | } |
|
|
365 | |
|
|
366 | # traverse the widget chain up to find the maximum "physical" size constraints |
|
|
367 | sub get_max_wh { |
|
|
368 | my ($self) = @_; |
|
|
369 | |
|
|
370 | return $self->{parent}->get_max_wh |
|
|
371 | if $self->{parent}; |
|
|
372 | |
|
|
373 | ($::WIDTH, $::HEIGHT) |
363 | } |
374 | } |
364 | |
375 | |
365 | sub size_request { |
376 | sub size_request { |
366 | require Carp; |
377 | require Carp; |
367 | Carp::confess "size_request is abstract"; |
378 | Carp::confess "size_request is abstract"; |
… | |
… | |
429 | |
440 | |
430 | $self->{tooltip} = $tooltip; |
441 | $self->{tooltip} = $tooltip; |
431 | |
442 | |
432 | if ($CFPlus::UI::TOOLTIP->{owner} == $self) { |
443 | if ($CFPlus::UI::TOOLTIP->{owner} == $self) { |
433 | delete $CFPlus::UI::TOOLTIP->{owner}; |
444 | delete $CFPlus::UI::TOOLTIP->{owner}; |
434 | $CFPlus::UI::TOOLTIP_WATCHER->cb->(); |
445 | $CFPlus::UI::TOOLTIP_WATCHER->invoke; |
435 | } |
446 | } |
436 | } |
447 | } |
437 | |
448 | |
438 | # translate global coordinates to local coordinate system |
449 | # translate global coordinates to local coordinate system |
439 | sub coord2local { |
450 | sub coord2local { |
440 | my ($self, $x, $y) = @_; |
451 | my ($self, $x, $y) = @_; |
441 | |
452 | |
442 | Carp::confess unless $self->{parent};#d# |
453 | return (undef, undef) unless $self->{parent}; |
443 | |
454 | |
444 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
455 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
445 | } |
456 | } |
446 | |
457 | |
447 | # translate local coordinates to global coordinate system |
458 | # translate local coordinates to global coordinate system |
448 | sub coord2global { |
459 | sub coord2global { |
449 | my ($self, $x, $y) = @_; |
460 | my ($self, $x, $y) = @_; |
450 | |
461 | |
451 | Carp::confess unless $self->{parent};#d# |
462 | return (undef, undef) unless $self->{parent}; |
452 | |
463 | |
453 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
464 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
454 | } |
465 | } |
455 | |
466 | |
456 | sub invoke_focus_in { |
467 | sub invoke_focus_in { |
… | |
… | |
817 | |
828 | |
818 | 1 |
829 | 1 |
819 | } |
830 | } |
820 | |
831 | |
821 | ############################################################################# |
832 | ############################################################################# |
822 | |
|
|
823 | # back-buffered drawing area |
833 | # back-buffered drawing area |
824 | |
834 | |
825 | package CFPlus::UI::Window; |
835 | package CFPlus::UI::Window; |
826 | |
836 | |
827 | our @ISA = CFPlus::UI::Bin::; |
837 | our @ISA = CFPlus::UI::Bin::; |
… | |
… | |
1376 | $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1386 | $self->CFPlus::UI::Container::add ($self->{title_widget}) if $self->{title_widget}; |
1377 | } |
1387 | } |
1378 | |
1388 | |
1379 | sub border { |
1389 | sub border { |
1380 | int $_[0]{border} * $::FONTSIZE |
1390 | int $_[0]{border} * $::FONTSIZE |
|
|
1391 | } |
|
|
1392 | |
|
|
1393 | sub get_max_wh { |
|
|
1394 | my ($self) = @_; |
|
|
1395 | |
|
|
1396 | return ($self->{w}, $self->{h}) |
|
|
1397 | if $self->{visible} && $self->{w}; |
|
|
1398 | |
|
|
1399 | $self->SUPER::get_max_wh |
1381 | } |
1400 | } |
1382 | |
1401 | |
1383 | sub size_request { |
1402 | sub size_request { |
1384 | my ($self) = @_; |
1403 | my ($self) = @_; |
1385 | |
1404 | |
… | |
… | |
1942 | |
1961 | |
1943 | sub size_request { |
1962 | sub size_request { |
1944 | my ($self) = @_; |
1963 | my ($self) = @_; |
1945 | |
1964 | |
1946 | $self->{size_req} ||= do { |
1965 | $self->{size_req} ||= do { |
|
|
1966 | my ($max_w, $max_h) = $self->get_max_wh; |
|
|
1967 | |
1947 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1968 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1948 | $self->{layout}->set_width ($self->{max_w} || -1); |
1969 | $self->{layout}->set_width ($self->{max_w} || $max_w || -1); |
1949 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1970 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1950 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1971 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1951 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1972 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1952 | |
1973 | |
1953 | my ($w, $h) = $self->{layout}->size; |
1974 | my ($w, $h) = $self->{layout}->size; |
… | |
… | |
2233 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2254 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2234 | } |
2255 | } |
2235 | |
2256 | |
2236 | glColor_premultiply @{$self->{active_fg}}; |
2257 | glColor_premultiply @{$self->{active_fg}}; |
2237 | glBegin GL_LINES; |
2258 | glBegin GL_LINES; |
2238 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2259 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy}; |
2239 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2260 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2240 | glEnd; |
2261 | glEnd; |
2241 | |
2262 | |
2242 | glLineWidth 3; |
2263 | glLineWidth 3; |
2243 | glColor @{$self->{active_outline}}; |
2264 | glColor @{$self->{active_outline}}; |
2244 | glRect_lineloop 0, 0, $self->{w} - 1, $self->{h} - 1; |
2265 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2245 | glLineWidth 1; |
2266 | glLineWidth 1; |
2246 | |
2267 | |
2247 | } else { |
2268 | } else { |
2248 | glColor @{$self->{outline}}; |
2269 | glColor @{$self->{outline}}; |
2249 | glTranslate .375, .375; |
|
|
2250 | glBegin GL_LINE_STRIP; |
2270 | glBegin GL_LINE_STRIP; |
2251 | glVertex 0, $self->{h} * .5; |
2271 | glVertex .5, $self->{h} * .5; |
2252 | glVertex 0, $self->{h} - 3; |
2272 | glVertex .5, $self->{h} - 2.5; |
2253 | glVertex $self->{w} - 1, $self->{h} - 3; |
2273 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
2254 | glVertex $self->{w} - 1, $self->{h} * .5; |
2274 | glVertex $self->{w} - .5, $self->{h} * .5; |
2255 | glEnd; |
2275 | glEnd; |
2256 | } |
2276 | } |
2257 | } |
2277 | } |
2258 | |
2278 | |
2259 | ############################################################################# |
2279 | ############################################################################# |
… | |
… | |
2508 | sub _draw { |
2528 | sub _draw { |
2509 | my ($self) = @_; |
2529 | my ($self) = @_; |
2510 | |
2530 | |
2511 | $self->SUPER::_draw; |
2531 | $self->SUPER::_draw; |
2512 | |
2532 | |
2513 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
2533 | glTranslate $self->{padding_x}, $self->{padding_y}, 0; |
2514 | |
2534 | |
2515 | my ($w, $h) = @$self{qw(w h)}; |
2535 | my ($w, $h) = @$self{qw(w h)}; |
2516 | |
2536 | |
2517 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2537 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2518 | |
2538 | |
… | |
… | |
2837 | |
2857 | |
2838 | glEnable GL_BLEND; |
2858 | glEnable GL_BLEND; |
2839 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2859 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2840 | |
2860 | |
2841 | if ($self->{value} >= 0) { |
2861 | if ($self->{value} >= 0) { |
2842 | my $s = 3 + ($self->{w} - 6) * $self->{value}; |
2862 | my $s = int 2 + ($self->{w} - 4) * $self->{value}; |
2843 | |
2863 | |
2844 | glColor_premultiply @{$self->{bar}}; |
2864 | glColor_premultiply @{$self->{bar}}; |
2845 | glRect 2, 2, $s, $self->{h} - 2; |
2865 | glRect 2, 2, $s, $self->{h} - 2; |
2846 | glColor_premultiply @{$self->{bg}}; |
2866 | glColor_premultiply @{$self->{bg}}; |
2847 | glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; |
2867 | glRect $s, 2, $self->{w} - 2, $self->{h} - 2; |
2848 | } |
2868 | } |
2849 | |
2869 | |
2850 | glColor_premultiply @{$self->{outline}}; |
2870 | glColor_premultiply @{$self->{outline}}; |
2851 | glRect_lineloop 1, 1, $self->{w} - 2, $self->{h} - 2; |
2871 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
2852 | |
2872 | |
2853 | glDisable GL_BLEND; |
2873 | glDisable GL_BLEND; |
2854 | |
2874 | |
2855 | { |
2875 | { |
2856 | local $self->{bg}; # do not draw background |
2876 | local $self->{bg}; # do not draw background |
… | |
… | |
3618 | } |
3638 | } |
3619 | |
3639 | |
3620 | sub _draw { |
3640 | sub _draw { |
3621 | my ($self) = @_; |
3641 | my ($self) = @_; |
3622 | |
3642 | |
3623 | glTranslate 0.375, 0.375; |
|
|
3624 | |
|
|
3625 | my ($w, $h) = @$self{qw(w h)}; |
3643 | my ($w, $h) = @$self{qw(w h)}; |
3626 | |
3644 | |
3627 | glColor 1, 0.8, 0.4; |
3645 | glColor 1, 0.8, 0.4; |
3628 | glRect 0, 0, $w, $h; |
3646 | glRect 0, 0, $w, $h; |
3629 | |
3647 | |
3630 | glColor 0, 0, 0; |
3648 | glColor 0, 0, 0; |
3631 | glRect_lineloop 0, 0, $w, $h; |
3649 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3632 | |
3650 | |
3633 | glTranslate 2 - 0.375, 2 - 0.375; |
3651 | glTranslate 2, 2; |
3634 | |
3652 | |
3635 | $self->SUPER::_draw; |
3653 | $self->SUPER::_draw; |
3636 | } |
3654 | } |
3637 | |
3655 | |
3638 | ############################################################################# |
3656 | ############################################################################# |
… | |
… | |
3656 | |
3674 | |
3657 | if ($self->{anim} && $self->{animspeed}) { |
3675 | if ($self->{anim} && $self->{animspeed}) { |
3658 | CFPlus::weaken (my $widget = $self); |
3676 | CFPlus::weaken (my $widget = $self); |
3659 | |
3677 | |
3660 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3678 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3661 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
3679 | $widget->{anim_start} = $self->{animspeed} * int EV::now / $self->{animspeed}; |
3662 | $self->{timer} = Event->timer ( |
3680 | $self->{timer} = EV::timer_ns 0, 0, sub { |
3663 | parked => 1, |
|
|
3664 | cb => sub { |
|
|
3665 | return unless $::CONN; |
3681 | return unless $::CONN; |
3666 | |
3682 | |
3667 | my $w = $widget |
3683 | my $w = $widget |
3668 | or return; |
3684 | or return; |
3669 | |
3685 | |
3670 | ++$w->{frame}; |
3686 | ++$w->{frame}; |
3671 | $w->update_face; |
3687 | $w->update_face; |
3672 | |
3688 | |
3673 | # somehow, $widget can go away |
3689 | # somehow, $widget can go away |
3674 | $w->update; |
3690 | $w->update; |
3675 | $w->update_timer; |
3691 | $w->update_timer; |
3676 | }, |
|
|
3677 | ); |
3692 | }; |
3678 | |
3693 | |
3679 | $self->update_face; |
3694 | $self->update_face; |
3680 | $self->update_timer; |
3695 | $self->update_timer; |
3681 | } |
3696 | } |
3682 | |
3697 | |
… | |
… | |
3686 | sub update_timer { |
3701 | sub update_timer { |
3687 | my ($self) = @_; |
3702 | my ($self) = @_; |
3688 | |
3703 | |
3689 | return unless $self->{timer}; |
3704 | return unless $self->{timer}; |
3690 | |
3705 | |
|
|
3706 | $self->{timer}->stop; |
3691 | if ($self->{visible}) { |
3707 | if ($self->{visible}) { |
3692 | $self->{timer}->at ( |
3708 | $self->{timer}->set ( |
3693 | $self->{anim_start} |
3709 | $self->{anim_start} |
3694 | + $self->{animspeed} |
3710 | + $self->{animspeed} |
3695 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
3711 | * int 1.5 + (EV::now - $self->{anim_start}) / $self->{animspeed} |
3696 | ); |
3712 | ); |
3697 | $self->{timer}->start; |
3713 | $self->{timer}->start; |
3698 | } else { |
|
|
3699 | $self->{timer}->stop; |
|
|
3700 | } |
3714 | } |
3701 | } |
3715 | } |
3702 | |
3716 | |
3703 | sub update_face { |
3717 | sub update_face { |
3704 | my ($self) = @_; |
3718 | my ($self) = @_; |
… | |
… | |
3965 | my $class = shift; |
3979 | my $class = shift; |
3966 | |
3980 | |
3967 | my $self = $class->SUPER::new ( |
3981 | my $self = $class->SUPER::new ( |
3968 | buttonbar => (new CFPlus::UI::Buttonbar), |
3982 | buttonbar => (new CFPlus::UI::Buttonbar), |
3969 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3983 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3970 | active_outline => [1, 1, 0], |
3984 | active_outline => [.7, .7, 0.2], |
3971 | # filter => # will be put between multiplexer and $self |
3985 | # filter => # will be put between multiplexer and $self |
3972 | @_, |
3986 | @_, |
3973 | ); |
3987 | ); |
3974 | |
3988 | |
3975 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3989 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
… | |
… | |
4056 | |
4070 | |
4057 | $self->SUPER::_draw (); |
4071 | $self->SUPER::_draw (); |
4058 | |
4072 | |
4059 | if (my $cur = $self->{multiplexer}{current}) { |
4073 | if (my $cur = $self->{multiplexer}{current}) { |
4060 | if ($cur = $cur->{c_tab_}) { |
4074 | if ($cur = $cur->{c_tab_}) { |
4061 | glTranslate $cur->{x}, $cur->{y}; |
4075 | glTranslate $self->{buttonbar}{x} + $cur->{x}, |
|
|
4076 | $self->{buttonbar}{y} + $cur->{y}; |
4062 | glLineWidth 3; |
4077 | glLineWidth 3; |
|
|
4078 | #glEnable GL_BLEND; |
|
|
4079 | #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
4063 | glColor @{$self->{active_outline}}; |
4080 | glColor @{$self->{active_outline}}; |
4064 | glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2; |
4081 | glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5; |
4065 | glLineWidth 1; |
4082 | glLineWidth 1; |
|
|
4083 | #glDisable GL_BLEND; |
4066 | } |
4084 | } |
4067 | } |
4085 | } |
4068 | } |
4086 | } |
4069 | |
4087 | |
4070 | ############################################################################# |
4088 | ############################################################################# |
… | |
… | |
4104 | } |
4122 | } |
4105 | |
4123 | |
4106 | sub _set_value { |
4124 | sub _set_value { |
4107 | my ($self, $value) = @_; |
4125 | my ($self, $value) = @_; |
4108 | |
4126 | |
4109 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
4127 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} }; |
|
|
4128 | $item ||= $self->{options}[0] |
4110 | or return; |
4129 | or return; |
4111 | |
4130 | |
4112 | $self->{value} = $item->[0]; |
4131 | $self->{value} = $item->[0]; |
4113 | $self->set_markup ("$item->[1] ⇓"); |
4132 | $self->set_markup ("$item->[1] ⇓"); |
4114 | $self->set_tooltip ($item->[2]); |
4133 | # $self->set_tooltip ($item->[2]); |
4115 | } |
4134 | } |
4116 | |
4135 | |
4117 | sub set_value { |
4136 | sub set_value { |
4118 | my ($self, $value) = @_; |
4137 | my ($self, $value) = @_; |
4119 | |
4138 | |
4120 | return unless $self->{value} ne $value; |
4139 | return unless $self->{value} ne $value; |
4121 | |
4140 | |
4122 | $self->_set_value ($value); |
4141 | $self->_set_value ($value); |
4123 | $self->emit (changed => $value); |
4142 | $self->emit (changed => $value); |
|
|
4143 | } |
|
|
4144 | |
|
|
4145 | sub set_options { |
|
|
4146 | my ($self, $options) = @_; |
|
|
4147 | |
|
|
4148 | $self->{options} = $options; |
|
|
4149 | $self->_set_value ($self->{value}); |
4124 | } |
4150 | } |
4125 | |
4151 | |
4126 | ############################################################################# |
4152 | ############################################################################# |
4127 | |
4153 | |
4128 | package CFPlus::UI::Statusbox; |
4154 | package CFPlus::UI::Statusbox; |
… | |
… | |
4137 | @_, |
4163 | @_, |
4138 | ); |
4164 | ); |
4139 | |
4165 | |
4140 | CFPlus::weaken (my $this = $self); |
4166 | CFPlus::weaken (my $this = $self); |
4141 | |
4167 | |
4142 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
4168 | $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; |
4143 | |
4169 | |
4144 | $self |
4170 | $self |
4145 | } |
4171 | } |
4146 | |
4172 | |
4147 | sub reorder { |
4173 | sub reorder { |
… | |
… | |
4161 | |
4187 | |
4162 | my @items = sort { |
4188 | my @items = sort { |
4163 | $a->{pri} <=> $b->{pri} |
4189 | $a->{pri} <=> $b->{pri} |
4164 | or $b->{id} <=> $a->{id} |
4190 | or $b->{id} <=> $a->{id} |
4165 | } values %{ $self->{item} }; |
4191 | } values %{ $self->{item} }; |
4166 | |
|
|
4167 | $self->{timer}->interval (1); |
|
|
4168 | |
4192 | |
4169 | my $count = 10 + 1; |
4193 | my $count = 10 + 1; |
4170 | for my $item (@items) { |
4194 | for my $item (@items) { |
4171 | last unless --$count; |
4195 | last unless --$count; |
4172 | |
4196 | |
… | |
… | |
4196 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4220 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4197 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4221 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4198 | $label->update; |
4222 | $label->update; |
4199 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4223 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4200 | if $diff < 1; |
4224 | if $diff < 1; |
4201 | $self->{timer}->interval (1/30); |
4225 | $self->{timer}->set (1/30, 1/30); |
4202 | } else { |
4226 | } else { |
4203 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4227 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4204 | } |
4228 | } |
4205 | |
4229 | |
4206 | push @widgets, $label; |
4230 | push @widgets, $label; |