… | |
… | |
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}; |
… | |
… | |
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 | { __widget_ref__ => $_[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 | } |
… | |
… | |
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 |
|
|
367 | sub 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 | |
369 | sub size_request { |
376 | sub 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 |
443 | sub coord2local { |
450 | sub 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 |
452 | sub coord2global { |
459 | sub 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 | |
460 | sub invoke_focus_in { |
467 | sub invoke_focus_in { |
… | |
… | |
607 | sub DESTROY { |
614 | sub DESTROY { |
608 | my ($self) = @_; |
615 | my ($self) = @_; |
609 | |
616 | |
610 | return if CFPlus::in_destruct; |
617 | return if CFPlus::in_destruct; |
611 | |
618 | |
|
|
619 | local $@; |
612 | eval { $self->destroy }; |
620 | eval { $self->destroy }; |
613 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
621 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
614 | |
622 | |
615 | delete $WIDGET{$self+0}; |
623 | delete $WIDGET{$self+0}; |
616 | } |
624 | } |
… | |
… | |
624 | use strict; |
632 | use strict; |
625 | use CFPlus::OpenGL; |
633 | use CFPlus::OpenGL; |
626 | |
634 | |
627 | sub new { |
635 | sub new { |
628 | my $class = shift; |
636 | my $class = shift; |
629 | |
|
|
630 | # range [value, low, high, page] |
|
|
631 | |
637 | |
632 | $class->SUPER::new ( |
638 | $class->SUPER::new ( |
633 | #bg => [0, 0, 0, 0.2], |
639 | #bg => [0, 0, 0, 0.2], |
634 | #active_bg => [1, 1, 1, 0.5], |
640 | #active_bg => [1, 1, 1, 0.5], |
635 | @_ |
641 | @_ |
… | |
… | |
647 | my ($w, $h) = @$self{qw(w h)}; |
653 | my ($w, $h) = @$self{qw(w h)}; |
648 | |
654 | |
649 | glEnable GL_BLEND; |
655 | glEnable GL_BLEND; |
650 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
656 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
651 | glColor_premultiply @$color; |
657 | glColor_premultiply @$color; |
652 | |
|
|
653 | glBegin GL_QUADS; |
|
|
654 | glVertex 0 , 0; |
|
|
655 | glVertex 0 , $h; |
|
|
656 | glVertex $w, $h; |
658 | glRect 0, 0, $w, $h; |
657 | glVertex $w, 0; |
|
|
658 | glEnd; |
|
|
659 | |
|
|
660 | glDisable GL_BLEND; |
659 | glDisable GL_BLEND; |
661 | } |
660 | } |
662 | } |
661 | } |
663 | |
662 | |
664 | ############################################################################# |
663 | ############################################################################# |
… | |
… | |
829 | |
828 | |
830 | 1 |
829 | 1 |
831 | } |
830 | } |
832 | |
831 | |
833 | ############################################################################# |
832 | ############################################################################# |
834 | |
|
|
835 | # back-buffered drawing area |
833 | # back-buffered drawing area |
836 | |
834 | |
837 | package CFPlus::UI::Window; |
835 | package CFPlus::UI::Window; |
838 | |
836 | |
839 | our @ISA = CFPlus::UI::Bin::; |
837 | our @ISA = CFPlus::UI::Bin::; |
… | |
… | |
1027 | my $child = delete $arg{child}; |
1025 | my $child = delete $arg{child}; |
1028 | |
1026 | |
1029 | my $self; |
1027 | my $self; |
1030 | |
1028 | |
1031 | my $hslider = new CFPlus::UI::Slider |
1029 | my $hslider = new CFPlus::UI::Slider |
1032 | col => 0, |
1030 | c_col => 0, |
1033 | row => 1, |
1031 | c_row => 1, |
1034 | vertical => 0, |
1032 | vertical => 0, |
1035 | range => [0, 0, 1, 0.01], # HACK fix |
1033 | range => [0, 0, 1, 0.01], # HACK fix |
1036 | on_changed => sub { |
1034 | on_changed => sub { |
1037 | $self->{hpos} = $_[1]; |
1035 | $self->{hpos} = $_[1]; |
1038 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1036 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1039 | }, |
1037 | }, |
1040 | ; |
1038 | ; |
1041 | |
1039 | |
1042 | my $vslider = new CFPlus::UI::Slider |
1040 | my $vslider = new CFPlus::UI::Slider |
1043 | col => 1, |
1041 | c_col => 1, |
1044 | row => 0, |
1042 | c_row => 0, |
1045 | vertical => 1, |
1043 | vertical => 1, |
1046 | range => [0, 0, 1, 0.01], # HACK fix |
1044 | range => [0, 0, 1, 0.01], # HACK fix |
1047 | on_changed => sub { |
1045 | on_changed => sub { |
1048 | $self->{vpos} = $_[1]; |
1046 | $self->{vpos} = $_[1]; |
1049 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1047 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
… | |
… | |
1060 | row_expand => [1, 0], |
1058 | row_expand => [1, 0], |
1061 | %arg, |
1059 | %arg, |
1062 | ); |
1060 | ); |
1063 | |
1061 | |
1064 | $self->{vp} = new CFPlus::UI::ViewPort |
1062 | $self->{vp} = new CFPlus::UI::ViewPort |
1065 | col => 0, |
1063 | c_col => 0, |
1066 | row => 0, |
1064 | c_row => 0, |
1067 | expand => 1, |
1065 | expand => 1, |
1068 | scroll_x => $self->{scroll_x}, |
1066 | scroll_x => $self->{scroll_x}, |
1069 | scroll_y => $self->{scroll_y}, |
1067 | scroll_y => $self->{scroll_y}, |
1070 | on_changed => sub { |
1068 | on_changed => sub { |
1071 | my ($vp, $x, $y) = @_; |
1069 | my ($vp, $x, $y) = @_; |
… | |
… | |
1219 | my ($w, $h) = @$self{qw(w h)}; |
1217 | my ($w, $h) = @$self{qw(w h)}; |
1220 | |
1218 | |
1221 | glEnable GL_BLEND; |
1219 | glEnable GL_BLEND; |
1222 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1220 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1223 | glColor_premultiply @{ $self->{bg} }; |
1221 | glColor_premultiply @{ $self->{bg} }; |
1224 | |
|
|
1225 | glBegin GL_QUADS; |
|
|
1226 | glVertex 0 , 0; |
|
|
1227 | glVertex 0 , $h; |
|
|
1228 | glVertex $w, $h; |
1222 | glRect 0, 0, $w, $h; |
1229 | glVertex $w, 0; |
|
|
1230 | glEnd; |
|
|
1231 | |
|
|
1232 | glDisable GL_BLEND; |
1223 | glDisable GL_BLEND; |
1233 | } |
1224 | } |
1234 | |
1225 | |
1235 | $self->SUPER::_draw; |
1226 | $self->SUPER::_draw; |
1236 | } |
1227 | } |
… | |
… | |
1397 | |
1388 | |
1398 | sub border { |
1389 | sub border { |
1399 | int $_[0]{border} * $::FONTSIZE |
1390 | int $_[0]{border} * $::FONTSIZE |
1400 | } |
1391 | } |
1401 | |
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 |
|
|
1400 | } |
|
|
1401 | |
1402 | sub size_request { |
1402 | sub size_request { |
1403 | my ($self) = @_; |
1403 | my ($self) = @_; |
1404 | |
1404 | |
1405 | $self->{title_widget}->size_request |
1405 | $self->{title_widget}->size_request |
1406 | if $self->{title_widget}; |
1406 | if $self->{title_widget}; |
… | |
… | |
1598 | |
1598 | |
1599 | sub add { |
1599 | sub add { |
1600 | my ($self, @widgets) = @_; |
1600 | my ($self, @widgets) = @_; |
1601 | |
1601 | |
1602 | for my $child (@widgets) { |
1602 | for my $child (@widgets) { |
1603 | $child->{rowspan} ||= 1; |
1603 | $child->{c_rowspan} ||= 1; |
1604 | $child->{colspan} ||= 1; |
1604 | $child->{c_colspan} ||= 1; |
1605 | } |
1605 | } |
1606 | |
1606 | |
1607 | $self->SUPER::add (@widgets); |
1607 | $self->SUPER::add (@widgets); |
1608 | } |
1608 | } |
1609 | |
1609 | |
… | |
… | |
1613 | my @widgets; |
1613 | my @widgets; |
1614 | |
1614 | |
1615 | while (@_) { |
1615 | while (@_) { |
1616 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1616 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1617 | |
1617 | |
1618 | $child->{row} = $row; |
1618 | $child->{c_row} = $row; |
1619 | $child->{col} = $col; |
1619 | $child->{c_col} = $col; |
1620 | |
1620 | |
1621 | push @widgets, $child; |
1621 | push @widgets, $child; |
1622 | } |
1622 | } |
1623 | |
1623 | |
1624 | $self->add (@widgets); |
1624 | $self->add (@widgets); |
… | |
… | |
1630 | my (@w, @h); |
1630 | my (@w, @h); |
1631 | |
1631 | |
1632 | my @children = $self->children; |
1632 | my @children = $self->children; |
1633 | |
1633 | |
1634 | # first pass, columns |
1634 | # first pass, columns |
1635 | for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { |
1635 | for my $widget (sort { $a->{c_colspan} <=> $b->{c_colspan} } @children) { |
1636 | my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; |
1636 | my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; |
1637 | |
1637 | |
1638 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1638 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1639 | |
1639 | |
1640 | if ($w > $sw) { |
1640 | if ($w > $sw) { |
1641 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1641 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1642 | } |
1642 | } |
1643 | } |
1643 | } |
1644 | |
1644 | |
1645 | # second pass, rows |
1645 | # second pass, rows |
1646 | for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { |
1646 | for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { |
1647 | my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; |
1647 | my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; |
1648 | |
1648 | |
1649 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1649 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1650 | |
1650 | |
1651 | if ($h > $sh) { |
1651 | if ($h > $sh) { |
1652 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1652 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
… | |
… | |
1694 | |
1694 | |
1695 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1695 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1696 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1696 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1697 | |
1697 | |
1698 | for my $widget ($self->children) { |
1698 | for my $widget ($self->children) { |
1699 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1699 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(c_row c_col req_w req_h c_rowspan c_colspan)}; |
1700 | |
1700 | |
1701 | $widget->configure ( |
1701 | $widget->configure ( |
1702 | $x[$c], $y[$r], |
1702 | $x[$c], $y[$r], |
1703 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1703 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1704 | ); |
1704 | ); |
… | |
… | |
1923 | |
1923 | |
1924 | delete $self->{ox}; |
1924 | delete $self->{ox}; |
1925 | $self->SUPER::realloc; |
1925 | $self->SUPER::realloc; |
1926 | } |
1926 | } |
1927 | |
1927 | |
|
|
1928 | sub clear { |
|
|
1929 | my ($self) = @_; |
|
|
1930 | |
|
|
1931 | $self->set_text (""); |
|
|
1932 | } |
|
|
1933 | |
1928 | sub set_text { |
1934 | sub set_text { |
1929 | my ($self, $text) = @_; |
1935 | my ($self, $text) = @_; |
1930 | |
1936 | |
1931 | return if $self->{text} eq "T$text"; |
1937 | return if $self->{text} eq "T$text"; |
1932 | $self->{text} = "T$text"; |
1938 | $self->{text} = "T$text"; |
… | |
… | |
1955 | |
1961 | |
1956 | sub size_request { |
1962 | sub size_request { |
1957 | my ($self) = @_; |
1963 | my ($self) = @_; |
1958 | |
1964 | |
1959 | $self->{size_req} ||= do { |
1965 | $self->{size_req} ||= do { |
|
|
1966 | my ($max_w, $max_h) = $self->get_max_wh; |
|
|
1967 | |
1960 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1968 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1961 | $self->{layout}->set_width ($self->{max_w} || -1); |
1969 | $self->{layout}->set_width ($self->{max_w} || $max_w || -1); |
1962 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1970 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1963 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1971 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1964 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1972 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1965 | |
1973 | |
1966 | my ($w, $h) = $self->{layout}->size; |
1974 | my ($w, $h) = $self->{layout}->size; |
… | |
… | |
2038 | : ($self->{w} - $size->[0]) * 0.5); |
2046 | : ($self->{w} - $size->[0]) * 0.5); |
2039 | |
2047 | |
2040 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2048 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2041 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2049 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2042 | : ($self->{h} - $size->[1]) * 0.5); |
2050 | : ($self->{h} - $size->[1]) * 0.5); |
|
|
2051 | |
|
|
2052 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2043 | }; |
2053 | }; |
2044 | |
2054 | |
2045 | # unless ($self->{list}) { |
2055 | # unless ($self->{list}) { |
2046 | # $self->{list} = CFPlus::OpenGL::glGenList; |
2056 | # $self->{list} = CFPlus::OpenGL::glGenList; |
2047 | # CFPlus::OpenGL::glNewList $self->{list}; |
2057 | # CFPlus::OpenGL::glNewList $self->{list}; |
… | |
… | |
2049 | # CFPlus::OpenGL::glEndList; |
2059 | # CFPlus::OpenGL::glEndList; |
2050 | # } |
2060 | # } |
2051 | # |
2061 | # |
2052 | # CFPlus::OpenGL::glCallList $self->{list}; |
2062 | # CFPlus::OpenGL::glCallList $self->{list}; |
2053 | |
2063 | |
2054 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2064 | $self->{layout}->draw; |
2055 | } |
2065 | } |
2056 | |
2066 | |
2057 | #sub destroy { |
2067 | #sub destroy { |
2058 | # my ($self) = @_; |
2068 | # my ($self) = @_; |
2059 | # |
2069 | # |
… | |
… | |
2074 | my $class = shift; |
2084 | my $class = shift; |
2075 | |
2085 | |
2076 | $class->SUPER::new ( |
2086 | $class->SUPER::new ( |
2077 | fg => [1, 1, 1], |
2087 | fg => [1, 1, 1], |
2078 | bg => [0, 0, 0, 0.2], |
2088 | bg => [0, 0, 0, 0.2], |
|
|
2089 | outline => [0.6, 0.3, 0.1], |
2079 | active_bg => [1, 1, 1, 0.5], |
2090 | active_bg => [0, 0, 1, .2], |
2080 | active_fg => [0, 0, 0], |
2091 | active_fg => [1, 1, 1], |
|
|
2092 | active_outline => [1, 1, 0], |
2081 | can_hover => 1, |
2093 | can_hover => 1, |
2082 | can_focus => 1, |
2094 | can_focus => 1, |
2083 | valign => 0, |
2095 | valign => 0, |
2084 | can_events => 1, |
2096 | can_events => 1, |
2085 | ellipsise => 0, |
2097 | ellipsise => 0, |
… | |
… | |
2225 | glColor_premultiply @{$self->{bg}}; |
2237 | glColor_premultiply @{$self->{bg}}; |
2226 | } |
2238 | } |
2227 | |
2239 | |
2228 | glEnable GL_BLEND; |
2240 | glEnable GL_BLEND; |
2229 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2241 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2230 | glBegin GL_QUADS; |
|
|
2231 | glVertex 0 , 0; |
|
|
2232 | glVertex 0 , $self->{h}; |
|
|
2233 | glVertex $self->{w}, $self->{h}; |
2242 | glRect 0, 0, $self->{w}, $self->{h}; |
2234 | glVertex $self->{w}, 0; |
|
|
2235 | glEnd; |
|
|
2236 | glDisable GL_BLEND; |
2243 | glDisable GL_BLEND; |
2237 | |
2244 | |
2238 | $self->SUPER::_draw; |
2245 | $self->SUPER::_draw; |
2239 | |
2246 | |
2240 | #TODO: force update every cursor change :( |
2247 | #TODO: force update every cursor change :( |
… | |
… | |
2242 | |
2249 | |
2243 | unless (exists $self->{cur_h}) { |
2250 | unless (exists $self->{cur_h}) { |
2244 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2251 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2245 | utf8::encode $text; |
2252 | utf8::encode $text; |
2246 | |
2253 | |
2247 | @$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); |
2248 | } |
2255 | } |
2249 | |
2256 | |
|
|
2257 | glColor_premultiply @{$self->{active_fg}}; |
2250 | glBegin GL_LINES; |
2258 | glBegin GL_LINES; |
2251 | 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}; |
2252 | 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}; |
|
|
2261 | glEnd; |
|
|
2262 | |
|
|
2263 | glLineWidth 3; |
|
|
2264 | glColor @{$self->{active_outline}}; |
|
|
2265 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
|
|
2266 | glLineWidth 1; |
|
|
2267 | |
|
|
2268 | } else { |
|
|
2269 | glColor @{$self->{outline}}; |
|
|
2270 | glBegin GL_LINE_STRIP; |
|
|
2271 | glVertex .5, $self->{h} * .5; |
|
|
2272 | glVertex .5, $self->{h} - 2.5; |
|
|
2273 | glVertex $self->{w} - .5, $self->{h} - 2.5; |
|
|
2274 | glVertex $self->{w} - .5, $self->{h} * .5; |
2253 | glEnd; |
2275 | glEnd; |
2254 | } |
2276 | } |
2255 | } |
2277 | } |
2256 | |
2278 | |
2257 | ############################################################################# |
2279 | ############################################################################# |
… | |
… | |
2344 | 1 |
2366 | 1 |
2345 | } |
2367 | } |
2346 | |
2368 | |
2347 | ############################################################################# |
2369 | ############################################################################# |
2348 | |
2370 | |
|
|
2371 | package CFPlus::UI::ButtonBin; |
|
|
2372 | |
|
|
2373 | our @ISA = CFPlus::UI::Bin::; |
|
|
2374 | |
|
|
2375 | use CFPlus::OpenGL; |
|
|
2376 | |
|
|
2377 | my @tex = |
|
|
2378 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
2379 | qw(b1_button_inactive.png b1_button_active.png); |
|
|
2380 | |
|
|
2381 | sub new { |
|
|
2382 | my $class = shift; |
|
|
2383 | |
|
|
2384 | $class->SUPER::new ( |
|
|
2385 | can_hover => 1, |
|
|
2386 | align => 0, |
|
|
2387 | valign => 0, |
|
|
2388 | can_events => 1, |
|
|
2389 | @_ |
|
|
2390 | ) |
|
|
2391 | } |
|
|
2392 | |
|
|
2393 | sub invoke_button_up { |
|
|
2394 | my ($self, $ev, $x, $y) = @_; |
|
|
2395 | |
|
|
2396 | $self->emit ("activate") |
|
|
2397 | if $x >= 0 && $x < $self->{w} |
|
|
2398 | && $y >= 0 && $y < $self->{h}; |
|
|
2399 | |
|
|
2400 | 1 |
|
|
2401 | } |
|
|
2402 | |
|
|
2403 | sub _draw { |
|
|
2404 | my ($self) = @_; |
|
|
2405 | |
|
|
2406 | glEnable GL_TEXTURE_2D; |
|
|
2407 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2408 | glColor 0, 0, 0, 1; |
|
|
2409 | |
|
|
2410 | my $tex = $tex[$GRAB == $self]; |
|
|
2411 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
|
|
2412 | |
|
|
2413 | glDisable GL_TEXTURE_2D; |
|
|
2414 | |
|
|
2415 | $self->SUPER::_draw; |
|
|
2416 | } |
|
|
2417 | |
|
|
2418 | ############################################################################# |
|
|
2419 | |
2349 | package CFPlus::UI::Button; |
2420 | package CFPlus::UI::Button; |
2350 | |
2421 | |
2351 | our @ISA = CFPlus::UI::Label::; |
2422 | our @ISA = CFPlus::UI::Label::; |
2352 | |
2423 | |
2353 | use CFPlus::OpenGL; |
2424 | use CFPlus::OpenGL; |
… | |
… | |
2457 | sub _draw { |
2528 | sub _draw { |
2458 | my ($self) = @_; |
2529 | my ($self) = @_; |
2459 | |
2530 | |
2460 | $self->SUPER::_draw; |
2531 | $self->SUPER::_draw; |
2461 | |
2532 | |
2462 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
2533 | glTranslate $self->{padding_x}, $self->{padding_y}, 0; |
2463 | |
2534 | |
2464 | my ($w, $h) = @$self{qw(w h)}; |
2535 | my ($w, $h) = @$self{qw(w h)}; |
2465 | |
2536 | |
2466 | 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; |
2467 | |
2538 | |
… | |
… | |
2487 | sub new { |
2558 | sub new { |
2488 | my $class = shift; |
2559 | my $class = shift; |
2489 | |
2560 | |
2490 | my $self = $class->SUPER::new ( |
2561 | my $self = $class->SUPER::new ( |
2491 | can_events => 0, |
2562 | can_events => 0, |
|
|
2563 | scale => 1, |
2492 | @_, |
2564 | @_, |
2493 | ); |
2565 | ); |
2494 | |
2566 | |
2495 | $self->{path} || $self->{tex} |
2567 | $self->{path} || $self->{tex} |
2496 | or Carp::croak "'path' or 'tex' attributes required"; |
2568 | or Carp::croak "'path' or 'tex' attributes required"; |
… | |
… | |
2521 | } |
2593 | } |
2522 | |
2594 | |
2523 | sub size_request { |
2595 | sub size_request { |
2524 | my ($self) = @_; |
2596 | my ($self) = @_; |
2525 | |
2597 | |
2526 | ($self->{tex}{w}, $self->{tex}{h}) |
2598 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2527 | } |
2599 | } |
2528 | |
2600 | |
2529 | sub _draw { |
2601 | sub _draw { |
2530 | my ($self) = @_; |
2602 | my ($self) = @_; |
2531 | |
2603 | |
… | |
… | |
2541 | } |
2613 | } |
2542 | |
2614 | |
2543 | glEnable GL_TEXTURE_2D; |
2615 | glEnable GL_TEXTURE_2D; |
2544 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2616 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2545 | |
2617 | |
2546 | $tex->draw_quad (0, 0, $w, $h); |
2618 | $tex->draw_quad_alpha (0, 0, $w, $h); |
2547 | |
2619 | |
2548 | glDisable GL_TEXTURE_2D; |
2620 | glDisable GL_TEXTURE_2D; |
2549 | } |
2621 | } |
2550 | |
2622 | |
2551 | ############################################################################# |
2623 | ############################################################################# |
… | |
… | |
2570 | align => 0, |
2642 | align => 0, |
2571 | valign => 0, |
2643 | valign => 0, |
2572 | can_events => 1, |
2644 | can_events => 1, |
2573 | @_ |
2645 | @_ |
2574 | ); |
2646 | ); |
|
|
2647 | } |
|
|
2648 | |
|
|
2649 | sub invoke_button_down { |
|
|
2650 | my ($self, $ev, $x, $y) = @_; |
|
|
2651 | |
|
|
2652 | 1 |
2575 | } |
2653 | } |
2576 | |
2654 | |
2577 | sub invoke_button_up { |
2655 | sub invoke_button_up { |
2578 | my ($self, $ev, $x, $y) = @_; |
2656 | my ($self, $ev, $x, $y) = @_; |
2579 | |
2657 | |
… | |
… | |
2719 | glDisable GL_TEXTURE_2D; |
2797 | glDisable GL_TEXTURE_2D; |
2720 | } |
2798 | } |
2721 | |
2799 | |
2722 | ############################################################################# |
2800 | ############################################################################# |
2723 | |
2801 | |
|
|
2802 | package CFPlus::UI::Progress; |
|
|
2803 | |
|
|
2804 | our @ISA = CFPlus::UI::Label::; |
|
|
2805 | |
|
|
2806 | use CFPlus::OpenGL; |
|
|
2807 | |
|
|
2808 | sub new { |
|
|
2809 | my ($class, %arg) = @_; |
|
|
2810 | |
|
|
2811 | my $self = $class->SUPER::new ( |
|
|
2812 | fg => [1, 1, 1], |
|
|
2813 | bg => [0, 0, 1, 0.2], |
|
|
2814 | bar => [0.7, 0.5, 0.1, 0.8], |
|
|
2815 | outline => [0.4, 0.3, 0], |
|
|
2816 | fontsize => 0.9, |
|
|
2817 | valign => 0, |
|
|
2818 | align => 0, |
|
|
2819 | can_events => 1, |
|
|
2820 | ellipsise => 1, |
|
|
2821 | label => "%d%%", |
|
|
2822 | %arg, |
|
|
2823 | ); |
|
|
2824 | |
|
|
2825 | $self->set_value ($arg{value} || -1); |
|
|
2826 | |
|
|
2827 | $self |
|
|
2828 | } |
|
|
2829 | |
|
|
2830 | sub set_label { |
|
|
2831 | my ($self, $label) = @_; |
|
|
2832 | |
|
|
2833 | return if $self->{label} eq $label; |
|
|
2834 | $self->{label} = $label; |
|
|
2835 | |
|
|
2836 | $self->CFPlus::UI::Progress::set_value (0 + delete $self->{value}); |
|
|
2837 | } |
|
|
2838 | |
|
|
2839 | sub set_value { |
|
|
2840 | my ($self, $value) = @_; |
|
|
2841 | |
|
|
2842 | if ($self->{value} ne $value) { |
|
|
2843 | $self->{value} = $value; |
|
|
2844 | |
|
|
2845 | if ($value < 0) { |
|
|
2846 | $self->set_text ("-"); |
|
|
2847 | } else { |
|
|
2848 | $self->set_text (sprintf $self->{label}, $value * 100); |
|
|
2849 | } |
|
|
2850 | |
|
|
2851 | $self->update; |
|
|
2852 | } |
|
|
2853 | } |
|
|
2854 | |
|
|
2855 | sub _draw { |
|
|
2856 | my ($self) = @_; |
|
|
2857 | |
|
|
2858 | glEnable GL_BLEND; |
|
|
2859 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
2860 | |
|
|
2861 | if ($self->{value} >= 0) { |
|
|
2862 | my $s = int 2 + ($self->{w} - 4) * $self->{value}; |
|
|
2863 | |
|
|
2864 | glColor_premultiply @{$self->{bar}}; |
|
|
2865 | glRect 2, 2, $s, $self->{h} - 2; |
|
|
2866 | glColor_premultiply @{$self->{bg}}; |
|
|
2867 | glRect $s, 2, $self->{w} - 2, $self->{h} - 2; |
|
|
2868 | } |
|
|
2869 | |
|
|
2870 | glColor_premultiply @{$self->{outline}}; |
|
|
2871 | glRect_lineloop 1.5, 1.5, $self->{w} - 1.5, $self->{h} - 1.5; |
|
|
2872 | |
|
|
2873 | glDisable GL_BLEND; |
|
|
2874 | |
|
|
2875 | { |
|
|
2876 | local $self->{bg}; # do not draw background |
|
|
2877 | $self->SUPER::_draw; |
|
|
2878 | } |
|
|
2879 | } |
|
|
2880 | |
|
|
2881 | ############################################################################# |
|
|
2882 | |
|
|
2883 | package CFPlus::UI::ExperienceProgress; |
|
|
2884 | |
|
|
2885 | our @ISA = CFPlus::UI::Progress::; |
|
|
2886 | |
|
|
2887 | sub new { |
|
|
2888 | my ($class, %arg) = @_; |
|
|
2889 | |
|
|
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 | }, |
|
|
2900 | %arg |
|
|
2901 | ); |
|
|
2902 | |
|
|
2903 | $::CONN->{on_exp_update}{$self+0} = sub { $self->set_value ($self->{value}) } |
|
|
2904 | if $::CONN; |
|
|
2905 | |
|
|
2906 | $self |
|
|
2907 | } |
|
|
2908 | |
|
|
2909 | sub DESTROY { |
|
|
2910 | my ($self) = @_; |
|
|
2911 | |
|
|
2912 | delete $::CONN->{on_exp_update}{$self+0} |
|
|
2913 | if $::CONN; |
|
|
2914 | |
|
|
2915 | $self->SUPER::DESTROY; |
|
|
2916 | } |
|
|
2917 | |
|
|
2918 | sub set_value { |
|
|
2919 | my ($self, $lvl, $exp) = @_; |
|
|
2920 | |
|
|
2921 | $self->{lvl} = $lvl; |
|
|
2922 | $self->{exp} = $exp; |
|
|
2923 | |
|
|
2924 | my $v = -1; |
|
|
2925 | |
|
|
2926 | if ($::CONN && (my $table = $::CONN->{exp_table})) { |
|
|
2927 | my $l0 = $table->[$lvl - 1]; |
|
|
2928 | my $l1 = $table->[$lvl]; |
|
|
2929 | |
|
|
2930 | $self->{nxt} = $l1; |
|
|
2931 | |
|
|
2932 | $v = ($exp - $l0) / ($l1 - $l0); |
|
|
2933 | } |
|
|
2934 | |
|
|
2935 | $self->SUPER::set_value ($v); |
|
|
2936 | } |
|
|
2937 | |
|
|
2938 | ############################################################################# |
|
|
2939 | |
2724 | package CFPlus::UI::Gauge; |
2940 | package CFPlus::UI::Gauge; |
2725 | |
2941 | |
2726 | our @ISA = CFPlus::UI::VBox::; |
2942 | our @ISA = CFPlus::UI::VBox::; |
2727 | |
2943 | |
2728 | sub new { |
2944 | sub new { |
… | |
… | |
3225 | |
3441 | |
3226 | if ($y0 < $y + $h && $y < $y1) { |
3442 | if ($y0 < $y + $h && $y < $y1) { |
3227 | my $layout = $self->get_layout ($para); |
3443 | my $layout = $self->get_layout ($para); |
3228 | |
3444 | |
3229 | $layout->render ($para->{indent}, $y - $y0); |
3445 | $layout->render ($para->{indent}, $y - $y0); |
|
|
3446 | $layout->draw; |
3230 | |
3447 | |
3231 | if (my @w = @{ $para->{widget} }) { |
3448 | if (my @w = @{ $para->{widget} }) { |
3232 | my @s = $layout->get_shapes; |
3449 | my @s = $layout->get_shapes; |
3233 | |
3450 | |
3234 | for (@w) { |
3451 | for (@w) { |
… | |
… | |
3356 | } |
3573 | } |
3357 | |
3574 | |
3358 | sub set_tooltip_from { |
3575 | sub set_tooltip_from { |
3359 | my ($self, $widget) = @_; |
3576 | my ($self, $widget) = @_; |
3360 | |
3577 | |
3361 | $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1 |
|
|
3362 | if $widget->{tooltip} =~ /^#(.*)$/; |
|
|
3363 | |
|
|
3364 | 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 =~ /^#(.*)$/; |
3365 | |
3583 | |
3366 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3584 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3367 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
3585 | $tip .= "\n\n" . (ref $widget) . "\n" |
3368 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3586 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3369 | . "req $widget->{req_w} $widget->{req_h}\n" |
3587 | . "req $widget->{req_w} $widget->{req_h}\n" |
3370 | . "visible $widget->{visible}"; |
3588 | . "visible $widget->{visible}"; |
3371 | } |
3589 | } |
3372 | |
3590 | |
3373 | $tooltip =~ s/^\n+//; |
3591 | $tip =~ s/^\n+//; |
3374 | $tooltip =~ s/\n+$//; |
3592 | $tip =~ s/\n+$//; |
3375 | |
3593 | |
3376 | $self->add (new CFPlus::UI::Label |
3594 | $self->add (new CFPlus::UI::Label |
3377 | markup => $tooltip, |
3595 | markup => $tip, |
3378 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3596 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3379 | fontsize => 0.8, |
3597 | fontsize => 0.8, |
3380 | style => 1, # FLAG_INVERSE |
3598 | style => 1, # FLAG_INVERSE |
3381 | ellipsise => 0, |
3599 | ellipsise => 0, |
3382 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3600 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
… | |
… | |
3420 | } |
3638 | } |
3421 | |
3639 | |
3422 | sub _draw { |
3640 | sub _draw { |
3423 | my ($self) = @_; |
3641 | my ($self) = @_; |
3424 | |
3642 | |
3425 | glTranslate 0.375, 0.375; |
|
|
3426 | |
|
|
3427 | my ($w, $h) = @$self{qw(w h)}; |
3643 | my ($w, $h) = @$self{qw(w h)}; |
3428 | |
3644 | |
3429 | glColor 1, 0.8, 0.4; |
3645 | glColor 1, 0.8, 0.4; |
3430 | glBegin GL_QUADS; |
3646 | glRect 0, 0, $w, $h; |
3431 | glVertex 0 , 0; |
|
|
3432 | glVertex 0 , $h; |
|
|
3433 | glVertex $w, $h; |
|
|
3434 | glVertex $w, 0; |
|
|
3435 | glEnd; |
|
|
3436 | |
3647 | |
3437 | glColor 0, 0, 0; |
3648 | glColor 0, 0, 0; |
3438 | glBegin GL_LINE_LOOP; |
3649 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3439 | glVertex 0 , 0; |
|
|
3440 | glVertex 0 , $h; |
|
|
3441 | glVertex $w, $h; |
|
|
3442 | glVertex $w, 0; |
|
|
3443 | glEnd; |
|
|
3444 | |
3650 | |
3445 | glTranslate 2 - 0.375, 2 - 0.375; |
3651 | glTranslate 2, 2; |
3446 | |
3652 | |
3447 | $self->SUPER::_draw; |
3653 | $self->SUPER::_draw; |
3448 | } |
3654 | } |
3449 | |
3655 | |
3450 | ############################################################################# |
3656 | ############################################################################# |
… | |
… | |
3468 | |
3674 | |
3469 | if ($self->{anim} && $self->{animspeed}) { |
3675 | if ($self->{anim} && $self->{animspeed}) { |
3470 | CFPlus::weaken (my $widget = $self); |
3676 | CFPlus::weaken (my $widget = $self); |
3471 | |
3677 | |
3472 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3678 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3473 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
3679 | $widget->{anim_start} = $self->{animspeed} * int EV::now / $self->{animspeed}; |
3474 | $self->{timer} = Event->timer ( |
3680 | $self->{timer} = EV::timer_ns 0, 0, sub { |
3475 | parked => 1, |
|
|
3476 | cb => sub { |
|
|
3477 | return unless $::CONN && $widget; |
3681 | return unless $::CONN; |
3478 | |
3682 | |
|
|
3683 | my $w = $widget |
|
|
3684 | or return; |
|
|
3685 | |
3479 | ++$widget->{frame}; |
3686 | ++$w->{frame}; |
3480 | $widget->update_face; |
3687 | $w->update_face; |
|
|
3688 | |
|
|
3689 | # somehow, $widget can go away |
3481 | $widget->update; |
3690 | $w->update; |
3482 | |
|
|
3483 | $widget->update_timer; |
3691 | $w->update_timer; |
3484 | }, |
|
|
3485 | ); |
3692 | }; |
3486 | |
3693 | |
3487 | $self->update_face; |
3694 | $self->update_face; |
3488 | $self->update_timer; |
3695 | $self->update_timer; |
3489 | } |
3696 | } |
3490 | |
3697 | |
… | |
… | |
3494 | sub update_timer { |
3701 | sub update_timer { |
3495 | my ($self) = @_; |
3702 | my ($self) = @_; |
3496 | |
3703 | |
3497 | return unless $self->{timer}; |
3704 | return unless $self->{timer}; |
3498 | |
3705 | |
|
|
3706 | $self->{timer}->stop; |
3499 | if ($self->{visible}) { |
3707 | if ($self->{visible}) { |
3500 | $self->{timer}->at ( |
3708 | $self->{timer}->set ( |
3501 | $self->{anim_start} |
3709 | $self->{anim_start} |
3502 | + $self->{animspeed} |
3710 | + $self->{animspeed} |
3503 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
3711 | * int 1.5 + (EV::now - $self->{anim_start}) / $self->{animspeed} |
3504 | ); |
3712 | ); |
3505 | $self->{timer}->start; |
3713 | $self->{timer}->start; |
3506 | } else { |
|
|
3507 | $self->{timer}->stop; |
|
|
3508 | } |
3714 | } |
3509 | } |
3715 | } |
3510 | |
3716 | |
3511 | sub update_face { |
3717 | sub update_face { |
3512 | my ($self) = @_; |
3718 | my ($self) = @_; |
3513 | |
3719 | |
3514 | return unless $::CONN; |
3720 | if ($::CONN) { |
3515 | |
|
|
3516 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3721 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3517 | if ($anim && @$anim) { |
3722 | if ($anim && @$anim) { |
3518 | delete $self->{wait_face}; |
|
|
3519 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
3723 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3724 | delete $self->{face_change_cb}; |
|
|
3725 | |
3520 | $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; |
3726 | if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) { |
|
|
3727 | unless ($tex->{name} || $tex->{loading}) { |
|
|
3728 | $tex->upload (sub { $self->reconfigure }); |
|
|
3729 | } |
|
|
3730 | } |
|
|
3731 | } |
3521 | } |
3732 | } |
3522 | } |
3733 | } |
3523 | } |
3734 | } |
3524 | |
3735 | |
3525 | sub size_request { |
3736 | sub size_request { |
3526 | my ($self) = @_; |
3737 | my ($self) = @_; |
3527 | |
3738 | |
3528 | if ($::CONN) { |
3739 | if ($::CONN) { |
3529 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3740 | if (my $faceid = $::CONN->{face}[$self->{face}]{id}) { |
3530 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3741 | if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) { |
3531 | $self->{tex} = $tex; |
3742 | if ($tex->{name}) { |
3532 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3743 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3533 | } else { |
3744 | } elsif (!$tex->{loading}) { |
3534 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3745 | $tex->upload (sub { $self->reconfigure }); |
3535 | $self->realloc; |
|
|
3536 | }); |
3746 | } |
3537 | } |
3747 | } |
|
|
3748 | |
|
|
3749 | $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure }); |
3538 | } |
3750 | } |
3539 | } |
3751 | } |
3540 | |
3752 | |
3541 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3753 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3542 | } |
3754 | } |
… | |
… | |
3622 | children => [ |
3834 | children => [ |
3623 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3835 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3624 | (new CFPlus::UI::Label markup => $right, align => +1), |
3836 | (new CFPlus::UI::Label markup => $right, align => +1), |
3625 | ], |
3837 | ], |
3626 | ; |
3838 | ; |
3627 | |
3839 | |
3628 | } else { |
3840 | } else { |
3629 | $widget = new CFPlus::UI::Label |
3841 | $widget = new CFPlus::UI::Label |
3630 | can_hover => 1, |
3842 | can_hover => 1, |
3631 | can_events => 1, |
3843 | can_events => 1, |
3632 | markup => $widget, |
3844 | markup => $widget, |
… | |
… | |
3757 | |
3969 | |
3758 | ############################################################################# |
3970 | ############################################################################# |
3759 | |
3971 | |
3760 | package CFPlus::UI::Notebook; |
3972 | package CFPlus::UI::Notebook; |
3761 | |
3973 | |
|
|
3974 | use CFPlus::OpenGL; |
|
|
3975 | |
3762 | our @ISA = CFPlus::UI::VBox::; |
3976 | our @ISA = CFPlus::UI::VBox::; |
3763 | |
3977 | |
3764 | sub new { |
3978 | sub new { |
3765 | my $class = shift; |
3979 | my $class = shift; |
3766 | |
3980 | |
3767 | my $self = $class->SUPER::new ( |
3981 | my $self = $class->SUPER::new ( |
3768 | buttonbar => (new CFPlus::UI::Buttonbar), |
3982 | buttonbar => (new CFPlus::UI::Buttonbar), |
3769 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3983 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
|
|
3984 | active_outline => [.7, .7, 0.2], |
3770 | # filter => # will be put between multiplexer and $self |
3985 | # filter => # will be put between multiplexer and $self |
3771 | @_, |
3986 | @_, |
3772 | ); |
3987 | ); |
3773 | |
3988 | |
3774 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3989 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
… | |
… | |
3848 | |
4063 | |
3849 | $self->{multiplexer}->set_current_page ($page); |
4064 | $self->{multiplexer}->set_current_page ($page); |
3850 | $self->emit (page_changed => $self->{multiplexer}{current}); |
4065 | $self->emit (page_changed => $self->{multiplexer}{current}); |
3851 | } |
4066 | } |
3852 | |
4067 | |
|
|
4068 | sub _draw { |
|
|
4069 | my ($self) = @_; |
|
|
4070 | |
|
|
4071 | $self->SUPER::_draw (); |
|
|
4072 | |
|
|
4073 | if (my $cur = $self->{multiplexer}{current}) { |
|
|
4074 | if ($cur = $cur->{c_tab_}) { |
|
|
4075 | glTranslate $self->{buttonbar}{x} + $cur->{x}, |
|
|
4076 | $self->{buttonbar}{y} + $cur->{y}; |
|
|
4077 | glLineWidth 3; |
|
|
4078 | #glEnable GL_BLEND; |
|
|
4079 | #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
4080 | glColor @{$self->{active_outline}}; |
|
|
4081 | glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5; |
|
|
4082 | glLineWidth 1; |
|
|
4083 | #glDisable GL_BLEND; |
|
|
4084 | } |
|
|
4085 | } |
|
|
4086 | } |
|
|
4087 | |
3853 | ############################################################################# |
4088 | ############################################################################# |
3854 | |
4089 | |
3855 | package CFPlus::UI::Selector; |
4090 | package CFPlus::UI::Selector; |
3856 | |
4091 | |
3857 | use utf8; |
4092 | use utf8; |
… | |
… | |
3887 | } |
4122 | } |
3888 | |
4123 | |
3889 | sub _set_value { |
4124 | sub _set_value { |
3890 | my ($self, $value) = @_; |
4125 | my ($self, $value) = @_; |
3891 | |
4126 | |
3892 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
4127 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} }; |
|
|
4128 | $item ||= $self->{options}[0] |
3893 | or return; |
4129 | or return; |
3894 | |
4130 | |
3895 | $self->{value} = $item->[0]; |
4131 | $self->{value} = $item->[0]; |
3896 | $self->set_markup ("$item->[1] ⇓"); |
4132 | $self->set_markup ("$item->[1] ⇓"); |
3897 | $self->set_tooltip ($item->[2]); |
4133 | # $self->set_tooltip ($item->[2]); |
3898 | } |
4134 | } |
3899 | |
4135 | |
3900 | sub set_value { |
4136 | sub set_value { |
3901 | my ($self, $value) = @_; |
4137 | my ($self, $value) = @_; |
3902 | |
4138 | |
3903 | return unless $self->{value} ne $value; |
4139 | return unless $self->{value} ne $value; |
3904 | |
4140 | |
3905 | $self->_set_value ($value); |
4141 | $self->_set_value ($value); |
3906 | $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}); |
3907 | } |
4150 | } |
3908 | |
4151 | |
3909 | ############################################################################# |
4152 | ############################################################################# |
3910 | |
4153 | |
3911 | package CFPlus::UI::Statusbox; |
4154 | package CFPlus::UI::Statusbox; |
… | |
… | |
3920 | @_, |
4163 | @_, |
3921 | ); |
4164 | ); |
3922 | |
4165 | |
3923 | CFPlus::weaken (my $this = $self); |
4166 | CFPlus::weaken (my $this = $self); |
3924 | |
4167 | |
3925 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
4168 | $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; |
3926 | |
4169 | |
3927 | $self |
4170 | $self |
3928 | } |
4171 | } |
3929 | |
4172 | |
3930 | sub reorder { |
4173 | sub reorder { |
… | |
… | |
3944 | |
4187 | |
3945 | my @items = sort { |
4188 | my @items = sort { |
3946 | $a->{pri} <=> $b->{pri} |
4189 | $a->{pri} <=> $b->{pri} |
3947 | or $b->{id} <=> $a->{id} |
4190 | or $b->{id} <=> $a->{id} |
3948 | } values %{ $self->{item} }; |
4191 | } values %{ $self->{item} }; |
3949 | |
|
|
3950 | $self->{timer}->interval (1); |
|
|
3951 | |
4192 | |
3952 | my $count = 10 + 1; |
4193 | my $count = 10 + 1; |
3953 | for my $item (@items) { |
4194 | for my $item (@items) { |
3954 | last unless --$count; |
4195 | last unless --$count; |
3955 | |
4196 | |
… | |
… | |
3979 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4220 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
3980 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4221 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
3981 | $label->update; |
4222 | $label->update; |
3982 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4223 | $label->set_max_size (undef, $label->{req_h} * $diff) |
3983 | if $diff < 1; |
4224 | if $diff < 1; |
3984 | $self->{timer}->interval (1/30); |
4225 | $self->{timer}->set (1/30, 1/30); |
3985 | } else { |
4226 | } else { |
3986 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4227 | $label->{fg}[3] = $item->{fg}[3] || 1; |
3987 | } |
4228 | } |
3988 | |
4229 | |
3989 | push @widgets, $label; |
4230 | push @widgets, $label; |
… | |
… | |
4125 | } |
4366 | } |
4126 | |
4367 | |
4127 | sub update { |
4368 | sub update { |
4128 | my ($self) = @_; |
4369 | my ($self) = @_; |
4129 | |
4370 | |
4130 | $::WANT_REFRESH++; |
4371 | $::WANT_REFRESH->start; |
4131 | } |
4372 | } |
4132 | |
4373 | |
4133 | sub add { |
4374 | sub add { |
4134 | my ($self, @children) = @_; |
4375 | my ($self, @children) = @_; |
4135 | |
4376 | |