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.434 by root, Wed Aug 22 21:32:09 2007 UTC vs.
Revision 1.448 by root, Tue Dec 25 07:39:18 2007 UTC

2 2
3use utf8; 3use utf8;
4use strict; 4use strict;
5 5
6use List::Util (); 6use List::Util ();
7use Event;
8 7
9use CFPlus; 8use CFPlus;
10use CFPlus::Pod; 9use CFPlus::Pod;
11use CFPlus::Texture; 10use CFPlus::Texture;
12 11
17our $TOOLTIP; 16our $TOOLTIP;
18our $BUTTON_STATE; 17our $BUTTON_STATE;
19 18
20our %WIDGET; # all widgets, weak-referenced 19our %WIDGET; # all widgets, weak-referenced
21 20
22our $TOOLTIP_WATCHER = Event->idle (min => 1/60, cb => sub { 21our $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};
30 $TOOLTIP->{owner} = $widget; 31 $TOOLTIP->{owner} = $widget;
31 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner}; 32 $TOOLTIP->{owner}->emit ("tooltip_show") if $TOOLTIP->{owner};
32 33
33 return if $ENV{CFPLUS_DEBUG} & 8; 34 return if $ENV{CFPLUS_DEBUG} & 8;
34 35
35 my $tip = $widget->{tooltip};
36
37 $tip = $tip->($widget) if CODE:: eq ref $tip;
38
39 $TOOLTIP->set_tooltip_from ($widget); 36 $TOOLTIP->set_tooltip_from ($widget);
40 $TOOLTIP->show; 37 $TOOLTIP->show;
41 } 38 }
42 39
43 return; 40 return;
46 } 43 }
47 44
48 $TOOLTIP->hide; 45 $TOOLTIP->hide;
49 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner}; 46 $TOOLTIP->{owner}->emit ("tooltip_hide") if $TOOLTIP->{owner};
50 delete $TOOLTIP->{owner}; 47 delete $TOOLTIP->{owner};
51}); 48};
52 49
53sub get_layout { 50sub get_layout {
54 my $layout; 51 my $layout;
55 52
56 for (grep { $_->{name} } values %WIDGET) { 53 for (grep { $_->{name} } values %WIDGET) {
91 my $hover = $HOVER; $HOVER = $widget; 88 my $hover = $HOVER; $HOVER = $widget;
92 89
93 $hover->update if $hover && $hover->{can_hover}; 90 $hover->update if $hover && $hover->{can_hover};
94 $HOVER->update if $HOVER && $HOVER->{can_hover}; 91 $HOVER->update if $HOVER && $HOVER->{can_hover};
95 92
96 $TOOLTIP_WATCHER->start; 93 $TOOLTIP_WATCHER->again;
97 } 94 }
98} 95}
99 96
100sub feed_sdl_button_down_event { 97sub feed_sdl_button_down_event {
101 my ($ev) = @_; 98 my ($ev) = @_;
107 my $widget = $ROOT->find_widget ($x, $y); 104 my $widget = $ROOT->find_widget ($x, $y);
108 105
109 $GRAB = $widget; 106 $GRAB = $widget;
110 $GRAB->update if $GRAB; 107 $GRAB->update if $GRAB;
111 108
112 $TOOLTIP_WATCHER->cb->(); 109 $TOOLTIP_WATCHER->invoke;
113 } 110 }
114 111
115 if ($GRAB) { 112 if ($GRAB) {
116 if ($ev->{button} == 4 || $ev->{button} == 5) { 113 if ($ev->{button} == 4 || $ev->{button} == 5) {
117 # mousewheel 114 # mousewheel
142 my $grab = $GRAB; undef $GRAB; 139 my $grab = $GRAB; undef $GRAB;
143 $grab->update if $grab; 140 $grab->update if $grab;
144 $GRAB->update if $GRAB; 141 $GRAB->update if $GRAB;
145 142
146 check_hover $widget; 143 check_hover $widget;
147 $TOOLTIP_WATCHER->cb->(); 144 $TOOLTIP_WATCHER->invoke;
148 } 145 }
149} 146}
150 147
151sub feed_sdl_motion_event { 148sub feed_sdl_motion_event {
152 my ($ev) = @_; 149 my ($ev) = @_;
273 $self->emit ("destroy"); 270 $self->emit ("destroy");
274 %$self = (); 271 %$self = ();
275} 272}
276 273
277sub TO_JSON { 274sub TO_JSON {
278 { __w_ => $_[0]{s_id} } 275 { "\fw" => $_[0]{s_id} }
279} 276}
280 277
281sub show { 278sub show {
282 my ($self) = @_; 279 my ($self) = @_;
283 280
312 delete $self->{root}; 309 delete $self->{root};
313 310
314 undef $GRAB if $GRAB == $self; 311 undef $GRAB if $GRAB == $self;
315 undef $HOVER if $HOVER == $self; 312 undef $HOVER if $HOVER == $self;
316 313
317 $CFPlus::UI::TOOLTIP_WATCHER->cb->() 314 $CFPlus::UI::TOOLTIP_WATCHER->invoke
318 if $TOOLTIP->{owner} == $self; 315 if $TOOLTIP->{owner} == $self;
319 316
320 $self->emit ("focus_out"); 317 $self->emit ("focus_out");
321 $self->emit (visibility_change => 0); 318 $self->emit (visibility_change => 0);
322} 319}
362 359
363 $self->{force_w} = $w; 360 $self->{force_w} = $w;
364 $self->{force_h} = $h; 361 $self->{force_h} = $h;
365 362
366 $self->realloc; 363 $self->realloc;
364}
365
366# traverse the widget chain up to find the maximum "physical" size constraints
367sub get_max_wh {
368 my ($self) = @_;
369
370 return $self->{parent}->get_max_wh
371 if $self->{parent};
372
373 ($::WIDTH, $::HEIGHT)
367} 374}
368 375
369sub size_request { 376sub size_request {
370 require Carp; 377 require Carp;
371 Carp::confess "size_request is abstract"; 378 Carp::confess "size_request is abstract";
433 440
434 $self->{tooltip} = $tooltip; 441 $self->{tooltip} = $tooltip;
435 442
436 if ($CFPlus::UI::TOOLTIP->{owner} == $self) { 443 if ($CFPlus::UI::TOOLTIP->{owner} == $self) {
437 delete $CFPlus::UI::TOOLTIP->{owner}; 444 delete $CFPlus::UI::TOOLTIP->{owner};
438 $CFPlus::UI::TOOLTIP_WATCHER->cb->(); 445 $CFPlus::UI::TOOLTIP_WATCHER->invoke;
439 } 446 }
440} 447}
441 448
442# translate global coordinates to local coordinate system 449# translate global coordinates to local coordinate system
443sub coord2local { 450sub coord2local {
444 my ($self, $x, $y) = @_; 451 my ($self, $x, $y) = @_;
445 452
446 Carp::confess unless $self->{parent};#d# 453 return (undef, undef) unless $self->{parent};
447 454
448 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) 455 $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y})
449} 456}
450 457
451# translate local coordinates to global coordinate system 458# translate local coordinates to global coordinate system
452sub coord2global { 459sub coord2global {
453 my ($self, $x, $y) = @_; 460 my ($self, $x, $y) = @_;
454 461
455 Carp::confess unless $self->{parent};#d# 462 return (undef, undef) unless $self->{parent};
456 463
457 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) 464 $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y})
458} 465}
459 466
460sub invoke_focus_in { 467sub invoke_focus_in {
821 828
822 1 829 1
823} 830}
824 831
825############################################################################# 832#############################################################################
826
827# back-buffered drawing area 833# back-buffered drawing area
828 834
829package CFPlus::UI::Window; 835package CFPlus::UI::Window;
830 836
831our @ISA = CFPlus::UI::Bin::; 837our @ISA = CFPlus::UI::Bin::;
1380 $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};
1381} 1387}
1382 1388
1383sub border { 1389sub border {
1384 int $_[0]{border} * $::FONTSIZE 1390 int $_[0]{border} * $::FONTSIZE
1391}
1392
1393sub 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
1385} 1400}
1386 1401
1387sub size_request { 1402sub size_request {
1388 my ($self) = @_; 1403 my ($self) = @_;
1389 1404
1946 1961
1947sub size_request { 1962sub size_request {
1948 my ($self) = @_; 1963 my ($self) = @_;
1949 1964
1950 $self->{size_req} ||= do { 1965 $self->{size_req} ||= do {
1966 my ($max_w, $max_h) = $self->get_max_wh;
1967
1951 $self->{layout}->set_font ($self->{font}) if $self->{font}; 1968 $self->{layout}->set_font ($self->{font}) if $self->{font};
1952 $self->{layout}->set_width ($self->{max_w} || -1); 1969 $self->{layout}->set_width ($self->{max_w} || $max_w || -1);
1953 $self->{layout}->set_ellipsise ($self->{ellipsise}); 1970 $self->{layout}->set_ellipsise ($self->{ellipsise});
1954 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); 1971 $self->{layout}->set_single_paragraph_mode ($self->{ellipsise});
1955 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); 1972 $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE);
1956 1973
1957 my ($w, $h) = $self->{layout}->size; 1974 my ($w, $h) = $self->{layout}->size;
2237 @$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);
2238 } 2255 }
2239 2256
2240 glColor_premultiply @{$self->{active_fg}}; 2257 glColor_premultiply @{$self->{active_fg}};
2241 glBegin GL_LINES; 2258 glBegin GL_LINES;
2242 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};
2243 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};
2244 glEnd; 2261 glEnd;
2245 2262
2246 glLineWidth 3; 2263 glLineWidth 3;
2247 glColor @{$self->{active_outline}}; 2264 glColor @{$self->{active_outline}};
2248 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;
2249 glLineWidth 1; 2266 glLineWidth 1;
2250 2267
2251 } else { 2268 } else {
2252 glColor @{$self->{outline}}; 2269 glColor @{$self->{outline}};
2253 glTranslate .375, .375;
2254 glBegin GL_LINE_STRIP; 2270 glBegin GL_LINE_STRIP;
2255 glVertex 0, $self->{h} * .5; 2271 glVertex .5, $self->{h} * .5;
2256 glVertex 0, $self->{h} - 3; 2272 glVertex .5, $self->{h} - 2.5;
2257 glVertex $self->{w} - 1, $self->{h} - 3; 2273 glVertex $self->{w} - .5, $self->{h} - 2.5;
2258 glVertex $self->{w} - 1, $self->{h} * .5; 2274 glVertex $self->{w} - .5, $self->{h} * .5;
2259 glEnd; 2275 glEnd;
2260 } 2276 }
2261} 2277}
2262 2278
2263############################################################################# 2279#############################################################################
2512sub _draw { 2528sub _draw {
2513 my ($self) = @_; 2529 my ($self) = @_;
2514 2530
2515 $self->SUPER::_draw; 2531 $self->SUPER::_draw;
2516 2532
2517 glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; 2533 glTranslate $self->{padding_x}, $self->{padding_y}, 0;
2518 2534
2519 my ($w, $h) = @$self{qw(w h)}; 2535 my ($w, $h) = @$self{qw(w h)};
2520 2536
2521 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;
2522 2538
2841 2857
2842 glEnable GL_BLEND; 2858 glEnable GL_BLEND;
2843 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; 2859 glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
2844 2860
2845 if ($self->{value} >= 0) { 2861 if ($self->{value} >= 0) {
2846 my $s = 3 + ($self->{w} - 6) * $self->{value}; 2862 my $s = int 2 + ($self->{w} - 4) * $self->{value};
2847 2863
2848 glColor_premultiply @{$self->{bar}}; 2864 glColor_premultiply @{$self->{bar}};
2849 glRect 2, 2, $s, $self->{h} - 2; 2865 glRect 2, 2, $s, $self->{h} - 2;
2850 glColor_premultiply @{$self->{bg}}; 2866 glColor_premultiply @{$self->{bg}};
2851 glRect $s + 1, 0, $self->{w} - 2, $self->{h} - 2; 2867 glRect $s, 2, $self->{w} - 2, $self->{h} - 2;
2852 } 2868 }
2853 2869
2854 glColor_premultiply @{$self->{outline}}; 2870 glColor_premultiply @{$self->{outline}};
2855 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;
2856 2872
2857 glDisable GL_BLEND; 2873 glDisable GL_BLEND;
2858 2874
2859 { 2875 {
2860 local $self->{bg}; # do not draw background 2876 local $self->{bg}; # do not draw background
2873 2889
2874 my $self = $class->SUPER::new ( 2890 my $self = $class->SUPER::new (
2875 tooltip => sub { 2891 tooltip => sub {
2876 my ($self) = @_; 2892 my ($self) = @_;
2877 2893
2878 sprintf "%s points experience (level %d).\n%s points to next level %s.", 2894 sprintf "level %d\n%s points\n%s next level\n%s to go",
2879 ::formsep $self->{exp},
2880 $self->{lvl}, 2895 $self->{lvl},
2896 ::formsep ($self->{exp}),
2881 ::formsep $self->{nxt} 2897 ::formsep ($self->{nxt}),
2898 ::formsep ($self->{nxt} - $self->{exp}),
2882 }, 2899 },
2883 %arg 2900 %arg
2884 ); 2901 );
2885 2902
2886 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } 2903 $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) }
2899} 2916}
2900 2917
2901sub set_value { 2918sub set_value {
2902 my ($self, $lvl, $exp) = @_; 2919 my ($self, $lvl, $exp) = @_;
2903 2920
2904 $self->{lvl} = $exp; 2921 $self->{lvl} = $lvl;
2905 $self->{exp} = $exp; 2922 $self->{exp} = $exp;
2906 2923
2907 my $v = -1; 2924 my $v = -1;
2908 2925
2909 if ($::CONN && (my $table = $::CONN->{exp_table})) { 2926 if ($::CONN && (my $table = $::CONN->{exp_table})) {
3556} 3573}
3557 3574
3558sub set_tooltip_from { 3575sub set_tooltip_from {
3559 my ($self, $widget) = @_; 3576 my ($self, $widget) = @_;
3560 3577
3561 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3562 if $widget->{tooltip} =~ /^#(.*)$/;
3563
3564 my $tooltip = $widget->{tooltip}; 3578 my $tip = $widget->{tooltip};
3579 $tip = $tip->($widget) if "CODE" eq ref $tip;
3580
3581 $tip = CFPlus::Pod::section_label tooltip => $1
3582 if $tip =~ /^#(.*)$/;
3565 3583
3566 if ($ENV{CFPLUS_DEBUG} & 2) { 3584 if ($ENV{CFPLUS_DEBUG} & 2) {
3567 $tooltip .= "\n\n" . (ref $widget) . "\n" 3585 $tip .= "\n\n" . (ref $widget) . "\n"
3568 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3586 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3569 . "req $widget->{req_w} $widget->{req_h}\n" 3587 . "req $widget->{req_w} $widget->{req_h}\n"
3570 . "visible $widget->{visible}"; 3588 . "visible $widget->{visible}";
3571 } 3589 }
3572 3590
3573 $tooltip =~ s/^\n+//; 3591 $tip =~ s/^\n+//;
3574 $tooltip =~ s/\n+$//; 3592 $tip =~ s/\n+$//;
3575 3593
3576 $self->add (new CFPlus::UI::Label 3594 $self->add (new CFPlus::UI::Label
3577 markup => $tooltip, 3595 markup => $tip,
3578 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3596 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3579 fontsize => 0.8, 3597 fontsize => 0.8,
3580 style => 1, # FLAG_INVERSE 3598 style => 1, # FLAG_INVERSE
3581 ellipsise => 0, 3599 ellipsise => 0,
3582 font => ($widget->{tooltip_font} || $::FONT_PROP), 3600 font => ($widget->{tooltip_font} || $::FONT_PROP),
3620} 3638}
3621 3639
3622sub _draw { 3640sub _draw {
3623 my ($self) = @_; 3641 my ($self) = @_;
3624 3642
3625 glTranslate 0.375, 0.375;
3626
3627 my ($w, $h) = @$self{qw(w h)}; 3643 my ($w, $h) = @$self{qw(w h)};
3628 3644
3629 glColor 1, 0.8, 0.4; 3645 glColor 1, 0.8, 0.4;
3630 glRect 0, 0, $w, $h; 3646 glRect 0, 0, $w, $h;
3631 3647
3632 glColor 0, 0, 0; 3648 glColor 0, 0, 0;
3633 glRect_lineloop 0, 0, $w, $h; 3649 glRect_lineloop .5, .5, $w + .5, $h + .5;
3634 3650
3635 glTranslate 2 - 0.375, 2 - 0.375; 3651 glTranslate 2, 2;
3636 3652
3637 $self->SUPER::_draw; 3653 $self->SUPER::_draw;
3638} 3654}
3639 3655
3640############################################################################# 3656#############################################################################
3657 ); 3673 );
3658 3674
3659 if ($self->{anim} && $self->{animspeed}) { 3675 if ($self->{anim} && $self->{animspeed}) {
3660 CFPlus::weaken (my $widget = $self); 3676 CFPlus::weaken (my $widget = $self);
3661 3677
3662 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3678 $self->{animspeed} = List::Util::max 0.05, $self->{animspeed};
3663 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; 3679 $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub {
3664 $self->{timer} = Event->timer (
3665 parked => 1,
3666 cb => sub {
3667 return unless $::CONN; 3680 return unless $::CONN;
3668 3681
3669 my $w = $widget 3682 my $w = $widget
3670 or return; 3683 or return;
3671 3684
3672 ++$w->{frame}; 3685 ++$w->{frame};
3673 $w->update_face; 3686 $w->update_face;
3674 3687
3675 # somehow, $widget can go away 3688 # somehow, $widget can go away
3676 $w->update; 3689 $w->update;
3677 $w->update_timer; 3690 $w->update_timer;
3678 },
3679 ); 3691 };
3680 3692
3681 $self->update_face; 3693 $self->update_face;
3682 $self->update_timer; 3694 $self->update_timer;
3683 } 3695 }
3684 3696
3689 my ($self) = @_; 3701 my ($self) = @_;
3690 3702
3691 return unless $self->{timer}; 3703 return unless $self->{timer};
3692 3704
3693 if ($self->{visible}) { 3705 if ($self->{visible}) {
3694 $self->{timer}->at (
3695 $self->{anim_start}
3696 + $self->{animspeed}
3697 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed}
3698 );
3699 $self->{timer}->start; 3706 $self->{timer}->start;
3700 } else { 3707 } else {
3701 $self->{timer}->stop; 3708 $self->{timer}->stop;
3702 } 3709 }
3703} 3710}
3967 my $class = shift; 3974 my $class = shift;
3968 3975
3969 my $self = $class->SUPER::new ( 3976 my $self = $class->SUPER::new (
3970 buttonbar => (new CFPlus::UI::Buttonbar), 3977 buttonbar => (new CFPlus::UI::Buttonbar),
3971 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3978 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3972 active_outline => [1, 1, 0], 3979 active_outline => [.7, .7, 0.2],
3973 # filter => # will be put between multiplexer and $self 3980 # filter => # will be put between multiplexer and $self
3974 @_, 3981 @_,
3975 ); 3982 );
3976 3983
3977 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3984 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
4058 4065
4059 $self->SUPER::_draw (); 4066 $self->SUPER::_draw ();
4060 4067
4061 if (my $cur = $self->{multiplexer}{current}) { 4068 if (my $cur = $self->{multiplexer}{current}) {
4062 if ($cur = $cur->{c_tab_}) { 4069 if ($cur = $cur->{c_tab_}) {
4063 glTranslate $cur->{x}, $cur->{y}; 4070 glTranslate $self->{buttonbar}{x} + $cur->{x},
4071 $self->{buttonbar}{y} + $cur->{y};
4064 glLineWidth 3; 4072 glLineWidth 3;
4073 #glEnable GL_BLEND;
4074 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4065 glColor @{$self->{active_outline}}; 4075 glColor @{$self->{active_outline}};
4066 glRect_lineloop 1, 1, $cur->{w} - 2, $cur->{h} - 2; 4076 glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5;
4067 glLineWidth 1; 4077 glLineWidth 1;
4078 #glDisable GL_BLEND;
4068 } 4079 }
4069 } 4080 }
4070} 4081}
4071 4082
4072############################################################################# 4083#############################################################################
4106} 4117}
4107 4118
4108sub _set_value { 4119sub _set_value {
4109 my ($self, $value) = @_; 4120 my ($self, $value) = @_;
4110 4121
4111 my ($item) = grep $_->[0] eq $value, @{ $self->{options} } 4122 my ($item) = grep $_->[0] eq $value, @{ $self->{options} };
4123 $item ||= $self->{options}[0]
4112 or return; 4124 or return;
4113 4125
4114 $self->{value} = $item->[0]; 4126 $self->{value} = $item->[0];
4115 $self->set_markup ("$item->[1] ⇓"); 4127 $self->set_markup ("$item->[1] ⇓");
4116 $self->set_tooltip ($item->[2]); 4128# $self->set_tooltip ($item->[2]);
4117} 4129}
4118 4130
4119sub set_value { 4131sub set_value {
4120 my ($self, $value) = @_; 4132 my ($self, $value) = @_;
4121 4133
4122 return unless $self->{value} ne $value; 4134 return unless $self->{value} ne $value;
4123 4135
4124 $self->_set_value ($value); 4136 $self->_set_value ($value);
4125 $self->emit (changed => $value); 4137 $self->emit (changed => $value);
4138}
4139
4140sub set_options {
4141 my ($self, $options) = @_;
4142
4143 $self->{options} = $options;
4144 $self->_set_value ($self->{value});
4126} 4145}
4127 4146
4128############################################################################# 4147#############################################################################
4129 4148
4130package CFPlus::UI::Statusbox; 4149package CFPlus::UI::Statusbox;
4139 @_, 4158 @_,
4140 ); 4159 );
4141 4160
4142 CFPlus::weaken (my $this = $self); 4161 CFPlus::weaken (my $this = $self);
4143 4162
4144 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 4163 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
4145 4164
4146 $self 4165 $self
4147} 4166}
4148 4167
4149sub reorder { 4168sub reorder {
4163 4182
4164 my @items = sort { 4183 my @items = sort {
4165 $a->{pri} <=> $b->{pri} 4184 $a->{pri} <=> $b->{pri}
4166 or $b->{id} <=> $a->{id} 4185 or $b->{id} <=> $a->{id}
4167 } values %{ $self->{item} }; 4186 } values %{ $self->{item} };
4168
4169 $self->{timer}->interval (1);
4170 4187
4171 my $count = 10 + 1; 4188 my $count = 10 + 1;
4172 for my $item (@items) { 4189 for my $item (@items) {
4173 last unless --$count; 4190 last unless --$count;
4174 4191
4198 if ((my $diff = $item->{timeout} - $NOW) < 2) { 4215 if ((my $diff = $item->{timeout} - $NOW) < 2) {
4199 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; 4216 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
4200 $label->update; 4217 $label->update;
4201 $label->set_max_size (undef, $label->{req_h} * $diff) 4218 $label->set_max_size (undef, $label->{req_h} * $diff)
4202 if $diff < 1; 4219 if $diff < 1;
4203 $self->{timer}->interval (1/30); 4220 $self->{timer}->set (1/30, 1/30);
4204 } else { 4221 } else {
4205 $label->{fg}[3] = $item->{fg}[3] || 1; 4222 $label->{fg}[3] = $item->{fg}[3] || 1;
4206 } 4223 }
4207 4224
4208 push @widgets, $label; 4225 push @widgets, $label;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines