… | |
… | |
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, 0.03, 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 | |
53 | sub get_layout { |
50 | sub 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 | |
100 | sub feed_sdl_button_down_event { |
97 | sub 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 | |
151 | sub feed_sdl_motion_event { |
148 | sub 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 | |
277 | sub TO_JSON { |
274 | sub TO_JSON { |
278 | { __w_ => $_[0]{s_id} } |
275 | { "\fw" => $_[0]{s_id} } |
279 | } |
276 | } |
280 | |
277 | |
281 | sub show { |
278 | sub 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 | } |
… | |
… | |
341 | sub hide { |
338 | sub hide { |
342 | my ($self) = @_; |
339 | my ($self) = @_; |
343 | |
340 | |
344 | $self->set_invisible; |
341 | $self->set_invisible; |
345 | |
342 | |
|
|
343 | # extra $parent copy for 5.8.8+ bug workaround |
|
|
344 | # (otherwise $_[0] in remove gets freed |
|
|
345 | if (my $parent = $self->{parent}) { |
346 | $self->{parent}->remove ($self) |
346 | $parent->remove ($self); |
347 | if $self->{parent}; |
347 | } |
348 | } |
348 | } |
349 | |
349 | |
350 | sub move_abs { |
350 | sub move_abs { |
351 | my ($self, $x, $y, $z) = @_; |
351 | my ($self, $x, $y, $z) = @_; |
352 | |
352 | |
… | |
… | |
362 | |
362 | |
363 | $self->{force_w} = $w; |
363 | $self->{force_w} = $w; |
364 | $self->{force_h} = $h; |
364 | $self->{force_h} = $h; |
365 | |
365 | |
366 | $self->realloc; |
366 | $self->realloc; |
|
|
367 | } |
|
|
368 | |
|
|
369 | # traverse the widget chain up to find the maximum "physical" size constraints |
|
|
370 | sub get_max_wh { |
|
|
371 | my ($self) = @_; |
|
|
372 | |
|
|
373 | return $self->{parent}->get_max_wh |
|
|
374 | if $self->{parent}; |
|
|
375 | |
|
|
376 | ($::WIDTH, $::HEIGHT) |
367 | } |
377 | } |
368 | |
378 | |
369 | sub size_request { |
379 | sub size_request { |
370 | require Carp; |
380 | require Carp; |
371 | Carp::confess "size_request is abstract"; |
381 | Carp::confess "size_request is abstract"; |
… | |
… | |
433 | |
443 | |
434 | $self->{tooltip} = $tooltip; |
444 | $self->{tooltip} = $tooltip; |
435 | |
445 | |
436 | if ($CFPlus::UI::TOOLTIP->{owner} == $self) { |
446 | if ($CFPlus::UI::TOOLTIP->{owner} == $self) { |
437 | delete $CFPlus::UI::TOOLTIP->{owner}; |
447 | delete $CFPlus::UI::TOOLTIP->{owner}; |
438 | $CFPlus::UI::TOOLTIP_WATCHER->cb->(); |
448 | $CFPlus::UI::TOOLTIP_WATCHER->invoke; |
439 | } |
449 | } |
440 | } |
450 | } |
441 | |
451 | |
442 | # translate global coordinates to local coordinate system |
452 | # translate global coordinates to local coordinate system |
443 | sub coord2local { |
453 | sub coord2local { |
444 | my ($self, $x, $y) = @_; |
454 | my ($self, $x, $y) = @_; |
445 | |
455 | |
446 | Carp::confess unless $self->{parent};#d# |
456 | return (undef, undef) unless $self->{parent}; |
447 | |
457 | |
448 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
458 | $self->{parent}->coord2local ($x - $self->{x}, $y - $self->{y}) |
449 | } |
459 | } |
450 | |
460 | |
451 | # translate local coordinates to global coordinate system |
461 | # translate local coordinates to global coordinate system |
452 | sub coord2global { |
462 | sub coord2global { |
453 | my ($self, $x, $y) = @_; |
463 | my ($self, $x, $y) = @_; |
454 | |
464 | |
455 | Carp::confess unless $self->{parent};#d# |
465 | return (undef, undef) unless $self->{parent}; |
456 | |
466 | |
457 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
467 | $self->{parent}->coord2global ($x + $self->{x}, $y + $self->{y}) |
458 | } |
468 | } |
459 | |
469 | |
460 | sub invoke_focus_in { |
470 | sub invoke_focus_in { |
… | |
… | |
607 | sub DESTROY { |
617 | sub DESTROY { |
608 | my ($self) = @_; |
618 | my ($self) = @_; |
609 | |
619 | |
610 | return if CFPlus::in_destruct; |
620 | return if CFPlus::in_destruct; |
611 | |
621 | |
|
|
622 | local $@; |
612 | eval { $self->destroy }; |
623 | eval { $self->destroy }; |
613 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
624 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
614 | |
625 | |
615 | delete $WIDGET{$self+0}; |
626 | delete $WIDGET{$self+0}; |
616 | } |
627 | } |
… | |
… | |
624 | use strict; |
635 | use strict; |
625 | use CFPlus::OpenGL; |
636 | use CFPlus::OpenGL; |
626 | |
637 | |
627 | sub new { |
638 | sub new { |
628 | my $class = shift; |
639 | my $class = shift; |
629 | |
|
|
630 | # range [value, low, high, page] |
|
|
631 | |
640 | |
632 | $class->SUPER::new ( |
641 | $class->SUPER::new ( |
633 | #bg => [0, 0, 0, 0.2], |
642 | #bg => [0, 0, 0, 0.2], |
634 | #active_bg => [1, 1, 1, 0.5], |
643 | #active_bg => [1, 1, 1, 0.5], |
635 | @_ |
644 | @_ |
… | |
… | |
647 | my ($w, $h) = @$self{qw(w h)}; |
656 | my ($w, $h) = @$self{qw(w h)}; |
648 | |
657 | |
649 | glEnable GL_BLEND; |
658 | glEnable GL_BLEND; |
650 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
659 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
651 | glColor_premultiply @$color; |
660 | glColor_premultiply @$color; |
652 | |
|
|
653 | glBegin GL_QUADS; |
|
|
654 | glVertex 0 , 0; |
|
|
655 | glVertex 0 , $h; |
|
|
656 | glVertex $w, $h; |
661 | glRect 0, 0, $w, $h; |
657 | glVertex $w, 0; |
|
|
658 | glEnd; |
|
|
659 | |
|
|
660 | glDisable GL_BLEND; |
662 | glDisable GL_BLEND; |
661 | } |
663 | } |
662 | } |
664 | } |
663 | |
665 | |
664 | ############################################################################# |
666 | ############################################################################# |
… | |
… | |
829 | |
831 | |
830 | 1 |
832 | 1 |
831 | } |
833 | } |
832 | |
834 | |
833 | ############################################################################# |
835 | ############################################################################# |
834 | |
|
|
835 | # back-buffered drawing area |
836 | # back-buffered drawing area |
836 | |
837 | |
837 | package CFPlus::UI::Window; |
838 | package CFPlus::UI::Window; |
838 | |
839 | |
839 | our @ISA = CFPlus::UI::Bin::; |
840 | our @ISA = CFPlus::UI::Bin::; |
… | |
… | |
1027 | my $child = delete $arg{child}; |
1028 | my $child = delete $arg{child}; |
1028 | |
1029 | |
1029 | my $self; |
1030 | my $self; |
1030 | |
1031 | |
1031 | my $hslider = new CFPlus::UI::Slider |
1032 | my $hslider = new CFPlus::UI::Slider |
1032 | col => 0, |
1033 | c_col => 0, |
1033 | row => 1, |
1034 | c_row => 1, |
1034 | vertical => 0, |
1035 | vertical => 0, |
1035 | range => [0, 0, 1, 0.01], # HACK fix |
1036 | range => [0, 0, 1, 0.01], # HACK fix |
1036 | on_changed => sub { |
1037 | on_changed => sub { |
1037 | $self->{hpos} = $_[1]; |
1038 | $self->{hpos} = $_[1]; |
1038 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1039 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1039 | }, |
1040 | }, |
1040 | ; |
1041 | ; |
1041 | |
1042 | |
1042 | my $vslider = new CFPlus::UI::Slider |
1043 | my $vslider = new CFPlus::UI::Slider |
1043 | col => 1, |
1044 | c_col => 1, |
1044 | row => 0, |
1045 | c_row => 0, |
1045 | vertical => 1, |
1046 | vertical => 1, |
1046 | range => [0, 0, 1, 0.01], # HACK fix |
1047 | range => [0, 0, 1, 0.01], # HACK fix |
1047 | on_changed => sub { |
1048 | on_changed => sub { |
1048 | $self->{vpos} = $_[1]; |
1049 | $self->{vpos} = $_[1]; |
1049 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1050 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
… | |
… | |
1060 | row_expand => [1, 0], |
1061 | row_expand => [1, 0], |
1061 | %arg, |
1062 | %arg, |
1062 | ); |
1063 | ); |
1063 | |
1064 | |
1064 | $self->{vp} = new CFPlus::UI::ViewPort |
1065 | $self->{vp} = new CFPlus::UI::ViewPort |
1065 | col => 0, |
1066 | c_col => 0, |
1066 | row => 0, |
1067 | c_row => 0, |
1067 | expand => 1, |
1068 | expand => 1, |
1068 | scroll_x => $self->{scroll_x}, |
1069 | scroll_x => $self->{scroll_x}, |
1069 | scroll_y => $self->{scroll_y}, |
1070 | scroll_y => $self->{scroll_y}, |
1070 | on_changed => sub { |
1071 | on_changed => sub { |
1071 | my ($vp, $x, $y) = @_; |
1072 | my ($vp, $x, $y) = @_; |
… | |
… | |
1219 | my ($w, $h) = @$self{qw(w h)}; |
1220 | my ($w, $h) = @$self{qw(w h)}; |
1220 | |
1221 | |
1221 | glEnable GL_BLEND; |
1222 | glEnable GL_BLEND; |
1222 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1223 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1223 | glColor_premultiply @{ $self->{bg} }; |
1224 | glColor_premultiply @{ $self->{bg} }; |
1224 | |
|
|
1225 | glBegin GL_QUADS; |
|
|
1226 | glVertex 0 , 0; |
|
|
1227 | glVertex 0 , $h; |
|
|
1228 | glVertex $w, $h; |
1225 | glRect 0, 0, $w, $h; |
1229 | glVertex $w, 0; |
|
|
1230 | glEnd; |
|
|
1231 | |
|
|
1232 | glDisable GL_BLEND; |
1226 | glDisable GL_BLEND; |
1233 | } |
1227 | } |
1234 | |
1228 | |
1235 | $self->SUPER::_draw; |
1229 | $self->SUPER::_draw; |
1236 | } |
1230 | } |
… | |
… | |
1397 | |
1391 | |
1398 | sub border { |
1392 | sub border { |
1399 | int $_[0]{border} * $::FONTSIZE |
1393 | int $_[0]{border} * $::FONTSIZE |
1400 | } |
1394 | } |
1401 | |
1395 | |
|
|
1396 | sub get_max_wh { |
|
|
1397 | my ($self) = @_; |
|
|
1398 | |
|
|
1399 | return ($self->{w}, $self->{h}) |
|
|
1400 | if $self->{visible} && $self->{w}; |
|
|
1401 | |
|
|
1402 | $self->SUPER::get_max_wh |
|
|
1403 | } |
|
|
1404 | |
1402 | sub size_request { |
1405 | sub size_request { |
1403 | my ($self) = @_; |
1406 | my ($self) = @_; |
1404 | |
1407 | |
1405 | $self->{title_widget}->size_request |
1408 | $self->{title_widget}->size_request |
1406 | if $self->{title_widget}; |
1409 | if $self->{title_widget}; |
… | |
… | |
1598 | |
1601 | |
1599 | sub add { |
1602 | sub add { |
1600 | my ($self, @widgets) = @_; |
1603 | my ($self, @widgets) = @_; |
1601 | |
1604 | |
1602 | for my $child (@widgets) { |
1605 | for my $child (@widgets) { |
1603 | $child->{rowspan} ||= 1; |
1606 | $child->{c_rowspan} ||= 1; |
1604 | $child->{colspan} ||= 1; |
1607 | $child->{c_colspan} ||= 1; |
1605 | } |
1608 | } |
1606 | |
1609 | |
1607 | $self->SUPER::add (@widgets); |
1610 | $self->SUPER::add (@widgets); |
1608 | } |
1611 | } |
1609 | |
1612 | |
… | |
… | |
1613 | my @widgets; |
1616 | my @widgets; |
1614 | |
1617 | |
1615 | while (@_) { |
1618 | while (@_) { |
1616 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1619 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1617 | |
1620 | |
1618 | $child->{row} = $row; |
1621 | $child->{c_row} = $row; |
1619 | $child->{col} = $col; |
1622 | $child->{c_col} = $col; |
1620 | |
1623 | |
1621 | push @widgets, $child; |
1624 | push @widgets, $child; |
1622 | } |
1625 | } |
1623 | |
1626 | |
1624 | $self->add (@widgets); |
1627 | $self->add (@widgets); |
… | |
… | |
1630 | my (@w, @h); |
1633 | my (@w, @h); |
1631 | |
1634 | |
1632 | my @children = $self->children; |
1635 | my @children = $self->children; |
1633 | |
1636 | |
1634 | # first pass, columns |
1637 | # first pass, columns |
1635 | for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { |
1638 | for my $widget (sort { $a->{c_colspan} <=> $b->{c_colspan} } @children) { |
1636 | my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; |
1639 | my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; |
1637 | |
1640 | |
1638 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1641 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1639 | |
1642 | |
1640 | if ($w > $sw) { |
1643 | if ($w > $sw) { |
1641 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1644 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1642 | } |
1645 | } |
1643 | } |
1646 | } |
1644 | |
1647 | |
1645 | # second pass, rows |
1648 | # second pass, rows |
1646 | for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { |
1649 | for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { |
1647 | my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; |
1650 | my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; |
1648 | |
1651 | |
1649 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1652 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1650 | |
1653 | |
1651 | if ($h > $sh) { |
1654 | if ($h > $sh) { |
1652 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1655 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
… | |
… | |
1694 | |
1697 | |
1695 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1698 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1696 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1699 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1697 | |
1700 | |
1698 | for my $widget ($self->children) { |
1701 | for my $widget ($self->children) { |
1699 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1702 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(c_row c_col req_w req_h c_rowspan c_colspan)}; |
1700 | |
1703 | |
1701 | $widget->configure ( |
1704 | $widget->configure ( |
1702 | $x[$c], $y[$r], |
1705 | $x[$c], $y[$r], |
1703 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1706 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1704 | ); |
1707 | ); |
… | |
… | |
1923 | |
1926 | |
1924 | delete $self->{ox}; |
1927 | delete $self->{ox}; |
1925 | $self->SUPER::realloc; |
1928 | $self->SUPER::realloc; |
1926 | } |
1929 | } |
1927 | |
1930 | |
|
|
1931 | sub clear { |
|
|
1932 | my ($self) = @_; |
|
|
1933 | |
|
|
1934 | $self->set_text (""); |
|
|
1935 | } |
|
|
1936 | |
1928 | sub set_text { |
1937 | sub set_text { |
1929 | my ($self, $text) = @_; |
1938 | my ($self, $text) = @_; |
1930 | |
1939 | |
1931 | return if $self->{text} eq "T$text"; |
1940 | return if $self->{text} eq "T$text"; |
1932 | $self->{text} = "T$text"; |
1941 | $self->{text} = "T$text"; |
… | |
… | |
1955 | |
1964 | |
1956 | sub size_request { |
1965 | sub size_request { |
1957 | my ($self) = @_; |
1966 | my ($self) = @_; |
1958 | |
1967 | |
1959 | $self->{size_req} ||= do { |
1968 | $self->{size_req} ||= do { |
|
|
1969 | my ($max_w, $max_h) = $self->get_max_wh; |
|
|
1970 | |
1960 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1971 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1961 | $self->{layout}->set_width ($self->{max_w} || -1); |
1972 | $self->{layout}->set_width ($self->{max_w} || $max_w || -1); |
1962 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1973 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1963 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1974 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1964 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1975 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1965 | |
1976 | |
1966 | my ($w, $h) = $self->{layout}->size; |
1977 | my ($w, $h) = $self->{layout}->size; |
… | |
… | |
2038 | : ($self->{w} - $size->[0]) * 0.5); |
2049 | : ($self->{w} - $size->[0]) * 0.5); |
2039 | |
2050 | |
2040 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2051 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2041 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2052 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2042 | : ($self->{h} - $size->[1]) * 0.5); |
2053 | : ($self->{h} - $size->[1]) * 0.5); |
|
|
2054 | |
|
|
2055 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2043 | }; |
2056 | }; |
2044 | |
2057 | |
2045 | # unless ($self->{list}) { |
2058 | # unless ($self->{list}) { |
2046 | # $self->{list} = CFPlus::OpenGL::glGenList; |
2059 | # $self->{list} = CFPlus::OpenGL::glGenList; |
2047 | # CFPlus::OpenGL::glNewList $self->{list}; |
2060 | # CFPlus::OpenGL::glNewList $self->{list}; |
… | |
… | |
2049 | # CFPlus::OpenGL::glEndList; |
2062 | # CFPlus::OpenGL::glEndList; |
2050 | # } |
2063 | # } |
2051 | # |
2064 | # |
2052 | # CFPlus::OpenGL::glCallList $self->{list}; |
2065 | # CFPlus::OpenGL::glCallList $self->{list}; |
2053 | |
2066 | |
2054 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2067 | $self->{layout}->draw; |
2055 | } |
2068 | } |
2056 | |
2069 | |
2057 | #sub destroy { |
2070 | #sub destroy { |
2058 | # my ($self) = @_; |
2071 | # my ($self) = @_; |
2059 | # |
2072 | # |
… | |
… | |
2074 | my $class = shift; |
2087 | my $class = shift; |
2075 | |
2088 | |
2076 | $class->SUPER::new ( |
2089 | $class->SUPER::new ( |
2077 | fg => [1, 1, 1], |
2090 | fg => [1, 1, 1], |
2078 | bg => [0, 0, 0, 0.2], |
2091 | bg => [0, 0, 0, 0.2], |
|
|
2092 | outline => [0.6, 0.3, 0.1], |
2079 | active_bg => [0, 0, 1, .2], |
2093 | active_bg => [0, 0, 1, .2], |
2080 | active_fg => [1, 1, 1], |
2094 | active_fg => [1, 1, 1], |
2081 | active_outline => [1, 1, 0], |
2095 | active_outline => [1, 1, 0], |
2082 | can_hover => 1, |
2096 | can_hover => 1, |
2083 | can_focus => 1, |
2097 | can_focus => 1, |
… | |
… | |
2226 | glColor_premultiply @{$self->{bg}}; |
2240 | glColor_premultiply @{$self->{bg}}; |
2227 | } |
2241 | } |
2228 | |
2242 | |
2229 | glEnable GL_BLEND; |
2243 | glEnable GL_BLEND; |
2230 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2244 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2231 | glBegin GL_QUADS; |
|
|
2232 | glVertex 0 , 0; |
|
|
2233 | glVertex 0 , $self->{h}; |
|
|
2234 | glVertex $self->{w}, $self->{h}; |
2245 | glRect 0, 0, $self->{w}, $self->{h}; |
2235 | glVertex $self->{w}, 0; |
|
|
2236 | glEnd; |
|
|
2237 | glDisable GL_BLEND; |
2246 | glDisable GL_BLEND; |
2238 | |
2247 | |
2239 | $self->SUPER::_draw; |
2248 | $self->SUPER::_draw; |
2240 | |
2249 | |
2241 | #TODO: force update every cursor change :( |
2250 | #TODO: force update every cursor change :( |
… | |
… | |
2248 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2257 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2249 | } |
2258 | } |
2250 | |
2259 | |
2251 | glColor_premultiply @{$self->{active_fg}}; |
2260 | glColor_premultiply @{$self->{active_fg}}; |
2252 | glBegin GL_LINES; |
2261 | glBegin GL_LINES; |
2253 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2262 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy}; |
2254 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2263 | glVertex $self->{cur_x} + $self->{ox} + .5, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2255 | glEnd; |
2264 | glEnd; |
2256 | |
2265 | |
2257 | glLineWidth 3; |
2266 | glLineWidth 3; |
2258 | glColor @{$self->{active_outline}}; |
2267 | glColor @{$self->{active_outline}}; |
2259 | glTranslate -.375, -.375; |
2268 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
|
|
2269 | glLineWidth 1; |
|
|
2270 | |
|
|
2271 | } else { |
|
|
2272 | glColor @{$self->{outline}}; |
2260 | glBegin GL_LINE_LOOP; |
2273 | glBegin GL_LINE_STRIP; |
2261 | glVertex 0, 0; |
2274 | glVertex .5, $self->{h} * .5; |
2262 | glVertex $self->{w}, 0; |
2275 | glVertex .5, $self->{h} - 2.5; |
2263 | glVertex $self->{w}, $self->{h}; |
2276 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
2264 | glVertex 0, $self->{h}; |
2277 | glVertex $self->{w} - .5, $self->{h} * .5; |
2265 | glEnd; |
2278 | glEnd; |
2266 | glLineWidth 1; |
|
|
2267 | } |
2279 | } |
2268 | } |
2280 | } |
2269 | |
2281 | |
2270 | ############################################################################# |
2282 | ############################################################################# |
2271 | |
2283 | |
… | |
… | |
2519 | sub _draw { |
2531 | sub _draw { |
2520 | my ($self) = @_; |
2532 | my ($self) = @_; |
2521 | |
2533 | |
2522 | $self->SUPER::_draw; |
2534 | $self->SUPER::_draw; |
2523 | |
2535 | |
2524 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
2536 | glTranslate $self->{padding_x}, $self->{padding_y}, 0; |
2525 | |
2537 | |
2526 | my ($w, $h) = @$self{qw(w h)}; |
2538 | my ($w, $h) = @$self{qw(w h)}; |
2527 | |
2539 | |
2528 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2540 | my $s = List::Util::min $w - $self->{padding_x} * 2, $h - $self->{padding_y} * 2; |
2529 | |
2541 | |
… | |
… | |
2633 | align => 0, |
2645 | align => 0, |
2634 | valign => 0, |
2646 | valign => 0, |
2635 | can_events => 1, |
2647 | can_events => 1, |
2636 | @_ |
2648 | @_ |
2637 | ); |
2649 | ); |
|
|
2650 | } |
|
|
2651 | |
|
|
2652 | sub invoke_button_down { |
|
|
2653 | my ($self, $ev, $x, $y) = @_; |
|
|
2654 | |
|
|
2655 | 1 |
2638 | } |
2656 | } |
2639 | |
2657 | |
2640 | sub invoke_button_up { |
2658 | sub invoke_button_up { |
2641 | my ($self, $ev, $x, $y) = @_; |
2659 | my ($self, $ev, $x, $y) = @_; |
2642 | |
2660 | |
… | |
… | |
2782 | glDisable GL_TEXTURE_2D; |
2800 | glDisable GL_TEXTURE_2D; |
2783 | } |
2801 | } |
2784 | |
2802 | |
2785 | ############################################################################# |
2803 | ############################################################################# |
2786 | |
2804 | |
|
|
2805 | package CFPlus::UI::Progress; |
|
|
2806 | |
|
|
2807 | our @ISA = CFPlus::UI::Label::; |
|
|
2808 | |
|
|
2809 | use CFPlus::OpenGL; |
|
|
2810 | |
|
|
2811 | sub new { |
|
|
2812 | my ($class, %arg) = @_; |
|
|
2813 | |
|
|
2814 | my $self = $class->SUPER::new ( |
|
|
2815 | fg => [1, 1, 1], |
|
|
2816 | bg => [0, 0, 1, 0.2], |
|
|
2817 | bar => [0.7, 0.5, 0.1, 0.8], |
|
|
2818 | outline => [0.4, 0.3, 0], |
|
|
2819 | fontsize => 0.9, |
|
|
2820 | valign => 0, |
|
|
2821 | align => 0, |
|
|
2822 | can_events => 1, |
|
|
2823 | ellipsise => 1, |
|
|
2824 | label => "%d%%", |
|
|
2825 | %arg, |
|
|
2826 | ); |
|
|
2827 | |
|
|
2828 | $self->set_value ($arg{value} || -1); |
|
|
2829 | |
|
|
2830 | $self |
|
|
2831 | } |
|
|
2832 | |
|
|
2833 | sub set_label { |
|
|
2834 | my ($self, $label) = @_; |
|
|
2835 | |
|
|
2836 | return if $self->{label} eq $label; |
|
|
2837 | $self->{label} = $label; |
|
|
2838 | |
|
|
2839 | $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value}); |
|
|
2840 | } |
|
|
2841 | |
|
|
2842 | sub set_value { |
|
|
2843 | my ($self, $value) = @_; |
|
|
2844 | |
|
|
2845 | if ($self->{value} ne $value) { |
|
|
2846 | $self->{value} = $value; |
|
|
2847 | |
|
|
2848 | if ($value < 0) { |
|
|
2849 | $self->set_text ("-"); |
|
|
2850 | } else { |
|
|
2851 | $self->set_text (sprintf $self->{label}, $value * 100); |
|
|
2852 | } |
|
|
2853 | |
|
|
2854 | $self->update; |
|
|
2855 | } |
|
|
2856 | } |
|
|
2857 | |
|
|
2858 | sub _draw { |
|
|
2859 | my ($self) = @_; |
|
|
2860 | |
|
|
2861 | glEnable GL_BLEND; |
|
|
2862 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2863 | |
|
|
2864 | if ($self->{value} >= 0) { |
|
|
2865 | my $s = int 2 + ($self->{w} - 4) * $self->{value}; |
|
|
2866 | |
|
|
2867 | glColor_premultiply @{$self->{bar}}; |
|
|
2868 | glRect 2, 2, $s, $self->{h} - 2; |
|
|
2869 | glColor_premultiply @{$self->{bg}}; |
|
|
2870 | glRect $s, 2, $self->{w} - 2, $self->{h} - 2; |
|
|
2871 | } |
|
|
2872 | |
|
|
2873 | glColor_premultiply @{$self->{outline}}; |
|
|
2874 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
|
|
2875 | |
|
|
2876 | glDisable GL_BLEND; |
|
|
2877 | |
|
|
2878 | { |
|
|
2879 | local $self->{bg}; # do not draw background |
|
|
2880 | $self->SUPER::_draw; |
|
|
2881 | } |
|
|
2882 | } |
|
|
2883 | |
|
|
2884 | ############################################################################# |
|
|
2885 | |
|
|
2886 | package CFPlus::UI::ExperienceProgress; |
|
|
2887 | |
|
|
2888 | our @ISA = CFPlus::UI::Progress::; |
|
|
2889 | |
|
|
2890 | sub new { |
|
|
2891 | my ($class, %arg) = @_; |
|
|
2892 | |
|
|
2893 | my $self = $class->SUPER::new ( |
|
|
2894 | tooltip => sub { |
|
|
2895 | my ($self) = @_; |
|
|
2896 | |
|
|
2897 | sprintf "level %d\n%s points\n%s next level\n%s to go", |
|
|
2898 | $self->{lvl}, |
|
|
2899 | ::formsep ($self->{exp}), |
|
|
2900 | ::formsep ($self->{nxt}), |
|
|
2901 | ::formsep ($self->{nxt} - $self->{exp}), |
|
|
2902 | }, |
|
|
2903 | %arg |
|
|
2904 | ); |
|
|
2905 | |
|
|
2906 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
|
|
2907 | if $::CONN; |
|
|
2908 | |
|
|
2909 | $self |
|
|
2910 | } |
|
|
2911 | |
|
|
2912 | sub DESTROY { |
|
|
2913 | my ($self) = @_; |
|
|
2914 | |
|
|
2915 | delete $::CONN->{on_exp_update}{$self+0} |
|
|
2916 | if $::CONN; |
|
|
2917 | |
|
|
2918 | $self->SUPER::DESTROY; |
|
|
2919 | } |
|
|
2920 | |
|
|
2921 | sub set_value { |
|
|
2922 | my ($self, $lvl, $exp) = @_; |
|
|
2923 | |
|
|
2924 | $self->{lvl} = $lvl; |
|
|
2925 | $self->{exp} = $exp; |
|
|
2926 | |
|
|
2927 | my $v = -1; |
|
|
2928 | |
|
|
2929 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
|
|
2930 | my $l0 = $table->[$lvl - 1]; |
|
|
2931 | my $l1 = $table->[$lvl]; |
|
|
2932 | |
|
|
2933 | $self->{nxt} = $l1; |
|
|
2934 | |
|
|
2935 | $v = ($exp - $l0) / ($l1 - $l0); |
|
|
2936 | } |
|
|
2937 | |
|
|
2938 | $self->SUPER::set_value ($v); |
|
|
2939 | } |
|
|
2940 | |
|
|
2941 | ############################################################################# |
|
|
2942 | |
2787 | package CFPlus::UI::Gauge; |
2943 | package CFPlus::UI::Gauge; |
2788 | |
2944 | |
2789 | our @ISA = CFPlus::UI::VBox::; |
2945 | our @ISA = CFPlus::UI::VBox::; |
2790 | |
2946 | |
2791 | sub new { |
2947 | sub new { |
… | |
… | |
3288 | |
3444 | |
3289 | if ($y0 < $y + $h && $y < $y1) { |
3445 | if ($y0 < $y + $h && $y < $y1) { |
3290 | my $layout = $self->get_layout ($para); |
3446 | my $layout = $self->get_layout ($para); |
3291 | |
3447 | |
3292 | $layout->render ($para->{indent}, $y - $y0); |
3448 | $layout->render ($para->{indent}, $y - $y0); |
|
|
3449 | $layout->draw; |
3293 | |
3450 | |
3294 | if (my @w = @{ $para->{widget} }) { |
3451 | if (my @w = @{ $para->{widget} }) { |
3295 | my @s = $layout->get_shapes; |
3452 | my @s = $layout->get_shapes; |
3296 | |
3453 | |
3297 | for (@w) { |
3454 | for (@w) { |
… | |
… | |
3419 | } |
3576 | } |
3420 | |
3577 | |
3421 | sub set_tooltip_from { |
3578 | sub set_tooltip_from { |
3422 | my ($self, $widget) = @_; |
3579 | my ($self, $widget) = @_; |
3423 | |
3580 | |
3424 | $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1 |
|
|
3425 | if $widget->{tooltip} =~ /^#(.*)$/; |
|
|
3426 | |
|
|
3427 | my $tooltip = $widget->{tooltip}; |
3581 | my $tip = $widget->{tooltip}; |
|
|
3582 | $tip = $tip->($widget) if "CODE" eq ref $tip; |
|
|
3583 | |
|
|
3584 | $tip = CFPlus::Pod::section_label tooltip => $1 |
|
|
3585 | if $tip =~ /^#(.*)$/; |
3428 | |
3586 | |
3429 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3587 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3430 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
3588 | $tip .= "\n\n" . (ref $widget) . "\n" |
3431 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3589 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3432 | . "req $widget->{req_w} $widget->{req_h}\n" |
3590 | . "req $widget->{req_w} $widget->{req_h}\n" |
3433 | . "visible $widget->{visible}"; |
3591 | . "visible $widget->{visible}"; |
3434 | } |
3592 | } |
3435 | |
3593 | |
3436 | $tooltip =~ s/^\n+//; |
3594 | $tip =~ s/^\n+//; |
3437 | $tooltip =~ s/\n+$//; |
3595 | $tip =~ s/\n+$//; |
3438 | |
3596 | |
3439 | $self->add (new CFPlus::UI::Label |
3597 | $self->add (new CFPlus::UI::Label |
3440 | markup => $tooltip, |
3598 | markup => $tip, |
3441 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3599 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3442 | fontsize => 0.8, |
3600 | fontsize => 0.8, |
3443 | style => 1, # FLAG_INVERSE |
3601 | style => 1, # FLAG_INVERSE |
3444 | ellipsise => 0, |
3602 | ellipsise => 0, |
3445 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3603 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
… | |
… | |
3483 | } |
3641 | } |
3484 | |
3642 | |
3485 | sub _draw { |
3643 | sub _draw { |
3486 | my ($self) = @_; |
3644 | my ($self) = @_; |
3487 | |
3645 | |
3488 | glTranslate 0.375, 0.375; |
|
|
3489 | |
|
|
3490 | my ($w, $h) = @$self{qw(w h)}; |
3646 | my ($w, $h) = @$self{qw(w h)}; |
3491 | |
3647 | |
3492 | glColor 1, 0.8, 0.4; |
3648 | glColor 1, 0.8, 0.4; |
3493 | glBegin GL_QUADS; |
3649 | glRect 0, 0, $w, $h; |
3494 | glVertex 0 , 0; |
|
|
3495 | glVertex 0 , $h; |
|
|
3496 | glVertex $w, $h; |
|
|
3497 | glVertex $w, 0; |
|
|
3498 | glEnd; |
|
|
3499 | |
3650 | |
3500 | glColor 0, 0, 0; |
3651 | glColor 0, 0, 0; |
3501 | glBegin GL_LINE_LOOP; |
3652 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3502 | glVertex 0 , 0; |
|
|
3503 | glVertex 0 , $h; |
|
|
3504 | glVertex $w, $h; |
|
|
3505 | glVertex $w, 0; |
|
|
3506 | glEnd; |
|
|
3507 | |
3653 | |
3508 | glTranslate 2 - 0.375, 2 - 0.375; |
3654 | glTranslate 2, 2; |
3509 | |
3655 | |
3510 | $self->SUPER::_draw; |
3656 | $self->SUPER::_draw; |
3511 | } |
3657 | } |
3512 | |
3658 | |
3513 | ############################################################################# |
3659 | ############################################################################# |
… | |
… | |
3530 | ); |
3676 | ); |
3531 | |
3677 | |
3532 | if ($self->{anim} && $self->{animspeed}) { |
3678 | if ($self->{anim} && $self->{animspeed}) { |
3533 | CFPlus::weaken (my $widget = $self); |
3679 | CFPlus::weaken (my $widget = $self); |
3534 | |
3680 | |
3535 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3681 | $self->{animspeed} = List::Util::max 0.05, $self->{animspeed}; |
3536 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
3682 | $self->{timer} = EV::periodic_ns 0, $self->{animspeed}, undef, sub { |
3537 | $self->{timer} = Event->timer ( |
|
|
3538 | parked => 1, |
|
|
3539 | cb => sub { |
|
|
3540 | return unless $::CONN && $widget; |
3683 | return unless $::CONN; |
3541 | |
3684 | |
|
|
3685 | my $w = $widget |
|
|
3686 | or return; |
|
|
3687 | |
3542 | ++$widget->{frame}; |
3688 | ++$w->{frame}; |
3543 | $widget->update_face; |
3689 | $w->update_face; |
|
|
3690 | |
|
|
3691 | # somehow, $widget can go away |
3544 | $widget->update; |
3692 | $w->update; |
3545 | |
|
|
3546 | $widget->update_timer; |
3693 | $w->update_timer; |
3547 | }, |
|
|
3548 | ); |
3694 | }; |
3549 | |
3695 | |
3550 | $self->update_face; |
3696 | $self->update_face; |
3551 | $self->update_timer; |
3697 | $self->update_timer; |
3552 | } |
3698 | } |
3553 | |
3699 | |
… | |
… | |
3558 | my ($self) = @_; |
3704 | my ($self) = @_; |
3559 | |
3705 | |
3560 | return unless $self->{timer}; |
3706 | return unless $self->{timer}; |
3561 | |
3707 | |
3562 | if ($self->{visible}) { |
3708 | if ($self->{visible}) { |
3563 | $self->{timer}->at ( |
|
|
3564 | $self->{anim_start} |
|
|
3565 | + $self->{animspeed} |
|
|
3566 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
|
|
3567 | ); |
|
|
3568 | $self->{timer}->start; |
3709 | $self->{timer}->start; |
3569 | } else { |
3710 | } else { |
3570 | $self->{timer}->stop; |
3711 | $self->{timer}->stop; |
3571 | } |
3712 | } |
3572 | } |
3713 | } |
3573 | |
3714 | |
3574 | sub update_face { |
3715 | sub update_face { |
3575 | my ($self) = @_; |
3716 | my ($self) = @_; |
3576 | |
3717 | |
3577 | return unless $::CONN; |
3718 | if ($::CONN) { |
3578 | |
|
|
3579 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3719 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3580 | if ($anim && @$anim) { |
3720 | if ($anim && @$anim) { |
3581 | delete $self->{wait_face}; |
|
|
3582 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
3721 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3722 | delete $self->{face_change_cb}; |
|
|
3723 | |
3583 | $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; |
3724 | if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) { |
|
|
3725 | unless ($tex->{name} || $tex->{loading}) { |
|
|
3726 | $tex->upload (sub { $self->reconfigure }); |
|
|
3727 | } |
|
|
3728 | } |
|
|
3729 | } |
3584 | } |
3730 | } |
3585 | } |
3731 | } |
3586 | } |
3732 | } |
3587 | |
3733 | |
3588 | sub size_request { |
3734 | sub size_request { |
3589 | my ($self) = @_; |
3735 | my ($self) = @_; |
3590 | |
3736 | |
3591 | if ($::CONN) { |
3737 | if ($::CONN) { |
3592 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3738 | if (my $faceid = $::CONN->{face}[$self->{face}]{id}) { |
3593 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3739 | if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) { |
3594 | $self->{tex} = $tex; |
3740 | if ($tex->{name}) { |
3595 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3741 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3596 | } else { |
3742 | } elsif (!$tex->{loading}) { |
3597 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3743 | $tex->upload (sub { $self->reconfigure }); |
3598 | $self->realloc; |
|
|
3599 | }); |
3744 | } |
3600 | } |
3745 | } |
|
|
3746 | |
|
|
3747 | $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure }); |
3601 | } |
3748 | } |
3602 | } |
3749 | } |
3603 | |
3750 | |
3604 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3751 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3605 | } |
3752 | } |
… | |
… | |
3820 | |
3967 | |
3821 | ############################################################################# |
3968 | ############################################################################# |
3822 | |
3969 | |
3823 | package CFPlus::UI::Notebook; |
3970 | package CFPlus::UI::Notebook; |
3824 | |
3971 | |
|
|
3972 | use CFPlus::OpenGL; |
|
|
3973 | |
3825 | our @ISA = CFPlus::UI::VBox::; |
3974 | our @ISA = CFPlus::UI::VBox::; |
3826 | |
3975 | |
3827 | sub new { |
3976 | sub new { |
3828 | my $class = shift; |
3977 | my $class = shift; |
3829 | |
3978 | |
3830 | my $self = $class->SUPER::new ( |
3979 | my $self = $class->SUPER::new ( |
3831 | buttonbar => (new CFPlus::UI::Buttonbar), |
3980 | buttonbar => (new CFPlus::UI::Buttonbar), |
3832 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3981 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
|
|
3982 | active_outline => [.7, .7, 0.2], |
3833 | # filter => # will be put between multiplexer and $self |
3983 | # filter => # will be put between multiplexer and $self |
3834 | @_, |
3984 | @_, |
3835 | ); |
3985 | ); |
3836 | |
3986 | |
3837 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3987 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
… | |
… | |
3911 | |
4061 | |
3912 | $self->{multiplexer}->set_current_page ($page); |
4062 | $self->{multiplexer}->set_current_page ($page); |
3913 | $self->emit (page_changed => $self->{multiplexer}{current}); |
4063 | $self->emit (page_changed => $self->{multiplexer}{current}); |
3914 | } |
4064 | } |
3915 | |
4065 | |
|
|
4066 | sub _draw { |
|
|
4067 | my ($self) = @_; |
|
|
4068 | |
|
|
4069 | $self->SUPER::_draw (); |
|
|
4070 | |
|
|
4071 | if (my $cur = $self->{multiplexer}{current}) { |
|
|
4072 | if ($cur = $cur->{c_tab_}) { |
|
|
4073 | glTranslate $self->{buttonbar}{x} + $cur->{x}, |
|
|
4074 | $self->{buttonbar}{y} + $cur->{y}; |
|
|
4075 | glLineWidth 3; |
|
|
4076 | #glEnable GL_BLEND; |
|
|
4077 | #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
4078 | glColor @{$self->{active_outline}}; |
|
|
4079 | glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5; |
|
|
4080 | glLineWidth 1; |
|
|
4081 | #glDisable GL_BLEND; |
|
|
4082 | } |
|
|
4083 | } |
|
|
4084 | } |
|
|
4085 | |
3916 | ############################################################################# |
4086 | ############################################################################# |
3917 | |
4087 | |
3918 | package CFPlus::UI::Selector; |
4088 | package CFPlus::UI::Selector; |
3919 | |
4089 | |
3920 | use utf8; |
4090 | use utf8; |
… | |
… | |
3950 | } |
4120 | } |
3951 | |
4121 | |
3952 | sub _set_value { |
4122 | sub _set_value { |
3953 | my ($self, $value) = @_; |
4123 | my ($self, $value) = @_; |
3954 | |
4124 | |
3955 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
4125 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} }; |
|
|
4126 | $item ||= $self->{options}[0] |
3956 | or return; |
4127 | or return; |
3957 | |
4128 | |
3958 | $self->{value} = $item->[0]; |
4129 | $self->{value} = $item->[0]; |
3959 | $self->set_markup ("$item->[1] ⇓"); |
4130 | $self->set_markup ("$item->[1] ⇓"); |
3960 | $self->set_tooltip ($item->[2]); |
4131 | # $self->set_tooltip ($item->[2]); |
3961 | } |
4132 | } |
3962 | |
4133 | |
3963 | sub set_value { |
4134 | sub set_value { |
3964 | my ($self, $value) = @_; |
4135 | my ($self, $value) = @_; |
3965 | |
4136 | |
3966 | return unless $self->{value} ne $value; |
4137 | return unless $self->{value} ne $value; |
3967 | |
4138 | |
3968 | $self->_set_value ($value); |
4139 | $self->_set_value ($value); |
3969 | $self->emit (changed => $value); |
4140 | $self->emit (changed => $value); |
|
|
4141 | } |
|
|
4142 | |
|
|
4143 | sub set_options { |
|
|
4144 | my ($self, $options) = @_; |
|
|
4145 | |
|
|
4146 | $self->{options} = $options; |
|
|
4147 | $self->_set_value ($self->{value}); |
3970 | } |
4148 | } |
3971 | |
4149 | |
3972 | ############################################################################# |
4150 | ############################################################################# |
3973 | |
4151 | |
3974 | package CFPlus::UI::Statusbox; |
4152 | package CFPlus::UI::Statusbox; |
… | |
… | |
3983 | @_, |
4161 | @_, |
3984 | ); |
4162 | ); |
3985 | |
4163 | |
3986 | CFPlus::weaken (my $this = $self); |
4164 | CFPlus::weaken (my $this = $self); |
3987 | |
4165 | |
3988 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
4166 | $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; |
3989 | |
4167 | |
3990 | $self |
4168 | $self |
3991 | } |
4169 | } |
3992 | |
4170 | |
3993 | sub reorder { |
4171 | sub reorder { |
… | |
… | |
4001 | |
4179 | |
4002 | while (my ($k, $v) = each %{ $self->{item} }) { |
4180 | while (my ($k, $v) = each %{ $self->{item} }) { |
4003 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
4181 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
4004 | } |
4182 | } |
4005 | |
4183 | |
|
|
4184 | $self->{timer}->set (1, 1); |
|
|
4185 | |
4006 | my @widgets; |
4186 | my @widgets; |
4007 | |
4187 | |
4008 | my @items = sort { |
4188 | my @items = sort { |
4009 | $a->{pri} <=> $b->{pri} |
4189 | $a->{pri} <=> $b->{pri} |
4010 | or $b->{id} <=> $a->{id} |
4190 | or $b->{id} <=> $a->{id} |
4011 | } values %{ $self->{item} }; |
4191 | } values %{ $self->{item} }; |
4012 | |
|
|
4013 | $self->{timer}->interval (1); |
|
|
4014 | |
4192 | |
4015 | my $count = 10 + 1; |
4193 | my $count = 10 + 1; |
4016 | for my $item (@items) { |
4194 | for my $item (@items) { |
4017 | last unless --$count; |
4195 | last unless --$count; |
4018 | |
4196 | |
… | |
… | |
4042 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4220 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4043 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4221 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4044 | $label->update; |
4222 | $label->update; |
4045 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4223 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4046 | if $diff < 1; |
4224 | if $diff < 1; |
4047 | $self->{timer}->interval (1/30); |
4225 | $self->{timer}->set (1/30, 1/30); |
4048 | } else { |
4226 | } else { |
4049 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4227 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4050 | } |
4228 | } |
4051 | |
4229 | |
4052 | push @widgets, $label; |
4230 | push @widgets, $label; |
… | |
… | |
4188 | } |
4366 | } |
4189 | |
4367 | |
4190 | sub update { |
4368 | sub update { |
4191 | my ($self) = @_; |
4369 | my ($self) = @_; |
4192 | |
4370 | |
4193 | $::WANT_REFRESH++; |
4371 | $::WANT_REFRESH = 1; |
4194 | } |
4372 | } |
4195 | |
4373 | |
4196 | sub add { |
4374 | sub add { |
4197 | my ($self, @children) = @_; |
4375 | my ($self, @children) = @_; |
4198 | |
4376 | |