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.433 by root, Wed Aug 22 21:27:13 2007 UTC vs.
Revision 1.447 by root, Sat Dec 22 06:50:45 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
2870 2886
2871sub new { 2887sub new {
2872 my ($class, %arg) = @_; 2888 my ($class, %arg) = @_;
2873 2889
2874 my $self = $class->SUPER::new ( 2890 my $self = $class->SUPER::new (
2891 tooltip => sub {
2892 my ($self) = @_;
2893
2894 sprintf "level %d\n%s points\n%s next level\n%s to go",
2895 $self->{lvl},
2896 ::formsep ($self->{exp}),
2897 ::formsep ($self->{nxt}),
2898 ::formsep ($self->{nxt} - $self->{exp}),
2899 },
2875 %arg 2900 %arg
2876 ); 2901 );
2877 2902
2878 $::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}) }
2879 if $::CONN; 2904 if $::CONN;
2890 $self->SUPER::DESTROY; 2915 $self->SUPER::DESTROY;
2891} 2916}
2892 2917
2893sub set_value { 2918sub set_value {
2894 my ($self, $lvl, $exp) = @_; 2919 my ($self, $lvl, $exp) = @_;
2920
2921 $self->{lvl} = $lvl;
2922 $self->{exp} = $exp;
2895 2923
2896 my $v = -1; 2924 my $v = -1;
2897 2925
2898 if ($::CONN && (my $table = $::CONN->{exp_table})) { 2926 if ($::CONN && (my $table = $::CONN->{exp_table})) {
2899 my $l0 = $table->[$lvl - 1]; 2927 my $l0 = $table->[$lvl - 1];
2900 my $l1 = $table->[$lvl]; 2928 my $l1 = $table->[$lvl];
2929
2930 $self->{nxt} = $l1;
2901 2931
2902 $v = ($exp - $l0) / ($l1 - $l0); 2932 $v = ($exp - $l0) / ($l1 - $l0);
2903 } 2933 }
2904 2934
2905 $self->SUPER::set_value ($v); 2935 $self->SUPER::set_value ($v);
3543} 3573}
3544 3574
3545sub set_tooltip_from { 3575sub set_tooltip_from {
3546 my ($self, $widget) = @_; 3576 my ($self, $widget) = @_;
3547 3577
3548 $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1
3549 if $widget->{tooltip} =~ /^#(.*)$/;
3550
3551 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 =~ /^#(.*)$/;
3552 3583
3553 if ($ENV{CFPLUS_DEBUG} & 2) { 3584 if ($ENV{CFPLUS_DEBUG} & 2) {
3554 $tooltip .= "\n\n" . (ref $widget) . "\n" 3585 $tip .= "\n\n" . (ref $widget) . "\n"
3555 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" 3586 . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n"
3556 . "req $widget->{req_w} $widget->{req_h}\n" 3587 . "req $widget->{req_w} $widget->{req_h}\n"
3557 . "visible $widget->{visible}"; 3588 . "visible $widget->{visible}";
3558 } 3589 }
3559 3590
3560 $tooltip =~ s/^\n+//; 3591 $tip =~ s/^\n+//;
3561 $tooltip =~ s/\n+$//; 3592 $tip =~ s/\n+$//;
3562 3593
3563 $self->add (new CFPlus::UI::Label 3594 $self->add (new CFPlus::UI::Label
3564 markup => $tooltip, 3595 markup => $tip,
3565 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, 3596 max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH,
3566 fontsize => 0.8, 3597 fontsize => 0.8,
3567 style => 1, # FLAG_INVERSE 3598 style => 1, # FLAG_INVERSE
3568 ellipsise => 0, 3599 ellipsise => 0,
3569 font => ($widget->{tooltip_font} || $::FONT_PROP), 3600 font => ($widget->{tooltip_font} || $::FONT_PROP),
3607} 3638}
3608 3639
3609sub _draw { 3640sub _draw {
3610 my ($self) = @_; 3641 my ($self) = @_;
3611 3642
3612 glTranslate 0.375, 0.375;
3613
3614 my ($w, $h) = @$self{qw(w h)}; 3643 my ($w, $h) = @$self{qw(w h)};
3615 3644
3616 glColor 1, 0.8, 0.4; 3645 glColor 1, 0.8, 0.4;
3617 glRect 0, 0, $w, $h; 3646 glRect 0, 0, $w, $h;
3618 3647
3619 glColor 0, 0, 0; 3648 glColor 0, 0, 0;
3620 glRect_lineloop 0, 0, $w, $h; 3649 glRect_lineloop .5, .5, $w + .5, $h + .5;
3621 3650
3622 glTranslate 2 - 0.375, 2 - 0.375; 3651 glTranslate 2, 2;
3623 3652
3624 $self->SUPER::_draw; 3653 $self->SUPER::_draw;
3625} 3654}
3626 3655
3627############################################################################# 3656#############################################################################
3645 3674
3646 if ($self->{anim} && $self->{animspeed}) { 3675 if ($self->{anim} && $self->{animspeed}) {
3647 CFPlus::weaken (my $widget = $self); 3676 CFPlus::weaken (my $widget = $self);
3648 3677
3649 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; 3678 $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed};
3650 $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; 3679 $widget->{anim_start} = $self->{animspeed} * int EV::now / $self->{animspeed};
3651 $self->{timer} = Event->timer ( 3680 $self->{timer} = EV::timer_ns 0, 0, sub {
3652 parked => 1,
3653 cb => sub {
3654 return unless $::CONN; 3681 return unless $::CONN;
3655 3682
3656 my $w = $widget 3683 my $w = $widget
3657 or return; 3684 or return;
3658 3685
3659 ++$w->{frame}; 3686 ++$w->{frame};
3660 $w->update_face; 3687 $w->update_face;
3661 3688
3662 # somehow, $widget can go away 3689 # somehow, $widget can go away
3663 $w->update; 3690 $w->update;
3664 $w->update_timer; 3691 $w->update_timer;
3665 },
3666 ); 3692 };
3667 3693
3668 $self->update_face; 3694 $self->update_face;
3669 $self->update_timer; 3695 $self->update_timer;
3670 } 3696 }
3671 3697
3675sub update_timer { 3701sub update_timer {
3676 my ($self) = @_; 3702 my ($self) = @_;
3677 3703
3678 return unless $self->{timer}; 3704 return unless $self->{timer};
3679 3705
3706 $self->{timer}->stop;
3680 if ($self->{visible}) { 3707 if ($self->{visible}) {
3681 $self->{timer}->at ( 3708 $self->{timer}->set (
3682 $self->{anim_start} 3709 $self->{anim_start}
3683 + $self->{animspeed} 3710 + $self->{animspeed}
3684 * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} 3711 * int 1.5 + (EV::now - $self->{anim_start}) / $self->{animspeed}
3685 ); 3712 );
3686 $self->{timer}->start; 3713 $self->{timer}->start;
3687 } else {
3688 $self->{timer}->stop;
3689 } 3714 }
3690} 3715}
3691 3716
3692sub update_face { 3717sub update_face {
3693 my ($self) = @_; 3718 my ($self) = @_;
3954 my $class = shift; 3979 my $class = shift;
3955 3980
3956 my $self = $class->SUPER::new ( 3981 my $self = $class->SUPER::new (
3957 buttonbar => (new CFPlus::UI::Buttonbar), 3982 buttonbar => (new CFPlus::UI::Buttonbar),
3958 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3983 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3959 active_outline => [1, 1, 0], 3984 active_outline => [.7, .7, 0.2],
3960 # filter => # will be put between multiplexer and $self 3985 # filter => # will be put between multiplexer and $self
3961 @_, 3986 @_,
3962 ); 3987 );
3963 3988
3964 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3989 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
4045 4070
4046 $self->SUPER::_draw (); 4071 $self->SUPER::_draw ();
4047 4072
4048 if (my $cur = $self->{multiplexer}{current}) { 4073 if (my $cur = $self->{multiplexer}{current}) {
4049 if ($cur = $cur->{c_tab_}) { 4074 if ($cur = $cur->{c_tab_}) {
4050 glTranslate $cur->{x}, $cur->{y}; 4075 glTranslate $self->{buttonbar}{x} + $cur->{x},
4076 $self->{buttonbar}{y} + $cur->{y};
4051 glLineWidth 3; 4077 glLineWidth 3;
4078 #glEnable GL_BLEND;
4079 #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA;
4052 glColor @{$self->{active_outline}}; 4080 glColor @{$self->{active_outline}};
4053 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;
4054 glLineWidth 1; 4082 glLineWidth 1;
4083 #glDisable GL_BLEND;
4055 } 4084 }
4056 } 4085 }
4057} 4086}
4058 4087
4059############################################################################# 4088#############################################################################
4093} 4122}
4094 4123
4095sub _set_value { 4124sub _set_value {
4096 my ($self, $value) = @_; 4125 my ($self, $value) = @_;
4097 4126
4098 my ($item) = grep $_->[0] eq $value, @{ $self->{options} } 4127 my ($item) = grep $_->[0] eq $value, @{ $self->{options} };
4128 $item ||= $self->{options}[0]
4099 or return; 4129 or return;
4100 4130
4101 $self->{value} = $item->[0]; 4131 $self->{value} = $item->[0];
4102 $self->set_markup ("$item->[1] ⇓"); 4132 $self->set_markup ("$item->[1] ⇓");
4103 $self->set_tooltip ($item->[2]); 4133# $self->set_tooltip ($item->[2]);
4104} 4134}
4105 4135
4106sub set_value { 4136sub set_value {
4107 my ($self, $value) = @_; 4137 my ($self, $value) = @_;
4108 4138
4109 return unless $self->{value} ne $value; 4139 return unless $self->{value} ne $value;
4110 4140
4111 $self->_set_value ($value); 4141 $self->_set_value ($value);
4112 $self->emit (changed => $value); 4142 $self->emit (changed => $value);
4143}
4144
4145sub set_options {
4146 my ($self, $options) = @_;
4147
4148 $self->{options} = $options;
4149 $self->_set_value ($self->{value});
4113} 4150}
4114 4151
4115############################################################################# 4152#############################################################################
4116 4153
4117package CFPlus::UI::Statusbox; 4154package CFPlus::UI::Statusbox;
4126 @_, 4163 @_,
4127 ); 4164 );
4128 4165
4129 CFPlus::weaken (my $this = $self); 4166 CFPlus::weaken (my $this = $self);
4130 4167
4131 $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); 4168 $self->{timer} = EV::timer 1, 1, sub { $this->reorder };
4132 4169
4133 $self 4170 $self
4134} 4171}
4135 4172
4136sub reorder { 4173sub reorder {
4150 4187
4151 my @items = sort { 4188 my @items = sort {
4152 $a->{pri} <=> $b->{pri} 4189 $a->{pri} <=> $b->{pri}
4153 or $b->{id} <=> $a->{id} 4190 or $b->{id} <=> $a->{id}
4154 } values %{ $self->{item} }; 4191 } values %{ $self->{item} };
4155
4156 $self->{timer}->interval (1);
4157 4192
4158 my $count = 10 + 1; 4193 my $count = 10 + 1;
4159 for my $item (@items) { 4194 for my $item (@items) {
4160 last unless --$count; 4195 last unless --$count;
4161 4196
4185 if ((my $diff = $item->{timeout} - $NOW) < 2) { 4220 if ((my $diff = $item->{timeout} - $NOW) < 2) {
4186 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; 4221 $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2;
4187 $label->update; 4222 $label->update;
4188 $label->set_max_size (undef, $label->{req_h} * $diff) 4223 $label->set_max_size (undef, $label->{req_h} * $diff)
4189 if $diff < 1; 4224 if $diff < 1;
4190 $self->{timer}->interval (1/30); 4225 $self->{timer}->set (1/30, 1/30);
4191 } else { 4226 } else {
4192 $label->{fg}[3] = $item->{fg}[3] || 1; 4227 $label->{fg}[3] = $item->{fg}[3] || 1;
4193 } 4228 }
4194 4229
4195 push @widgets, $label; 4230 push @widgets, $label;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines