… | |
… | |
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 { |
… | |
… | |
593 | |
600 | |
594 | # using global variables seems a bit hacky, but passing through all drawing |
601 | # using global variables seems a bit hacky, but passing through all drawing |
595 | # functions seems pointless. |
602 | # functions seems pointless. |
596 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
603 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
597 | |
604 | |
598 | sub draw { |
605 | #sub draw { |
599 | my ($self) = @_; |
606 | #CFPlus.xs |
600 | |
|
|
601 | return unless $self->{h} && $self->{w}; |
|
|
602 | |
|
|
603 | # update screen rectangle |
|
|
604 | local $draw_x = $draw_x + $self->{x}; |
|
|
605 | local $draw_y = $draw_y + $self->{y}; |
|
|
606 | |
|
|
607 | # skip widgets that are entirely outside the drawing area |
|
|
608 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
|
|
609 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
|
|
610 | |
|
|
611 | glPushMatrix; |
|
|
612 | glTranslate $self->{x}, $self->{y}, 0; |
|
|
613 | |
|
|
614 | if ($self == $HOVER && $self->{can_hover}) { |
|
|
615 | glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; |
|
|
616 | glEnable GL_BLEND; |
|
|
617 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
618 | glBegin GL_QUADS; |
|
|
619 | glVertex 0 , 0; |
|
|
620 | glVertex $self->{w}, 0; |
|
|
621 | glVertex $self->{w}, $self->{h}; |
|
|
622 | glVertex 0 , $self->{h}; |
|
|
623 | glEnd; |
|
|
624 | glDisable GL_BLEND; |
|
|
625 | } |
|
|
626 | |
|
|
627 | if ($ENV{CFPLUS_DEBUG} & 1) { |
|
|
628 | glPushMatrix; |
|
|
629 | glColor 1, 1, 0, 1; |
|
|
630 | glTranslate 0.375, 0.375; |
|
|
631 | glBegin GL_LINE_LOOP; |
|
|
632 | glVertex 0 , 0; |
|
|
633 | glVertex $self->{w} - 1, 0; |
|
|
634 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
635 | glVertex 0 , $self->{h} - 1; |
|
|
636 | glEnd; |
|
|
637 | glPopMatrix; |
|
|
638 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
639 | } |
|
|
640 | |
|
|
641 | $self->_draw; |
|
|
642 | glPopMatrix; |
|
|
643 | } |
|
|
644 | |
607 | |
645 | sub _draw { |
608 | sub _draw { |
646 | my ($self) = @_; |
609 | my ($self) = @_; |
647 | |
610 | |
648 | warn "no draw defined for $self\n"; |
611 | warn "no draw defined for $self\n"; |
649 | } |
612 | } |
650 | |
613 | |
651 | my $cntx;#d# |
|
|
652 | sub DESTROY { |
614 | sub DESTROY { |
653 | my ($self) = @_; |
615 | my ($self) = @_; |
654 | |
616 | |
655 | return if CFPlus::in_destruct; |
617 | return if CFPlus::in_destruct; |
656 | |
618 | |
|
|
619 | local $@; |
657 | eval { $self->destroy }; |
620 | eval { $self->destroy }; |
658 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
621 | warn "exception during widget destruction: $@" if $@ & $@ != /during global destruction/; |
659 | |
622 | |
660 | delete $WIDGET{$self+0}; |
623 | delete $WIDGET{$self+0}; |
661 | } |
624 | } |
… | |
… | |
669 | use strict; |
632 | use strict; |
670 | use CFPlus::OpenGL; |
633 | use CFPlus::OpenGL; |
671 | |
634 | |
672 | sub new { |
635 | sub new { |
673 | my $class = shift; |
636 | my $class = shift; |
674 | |
|
|
675 | # range [value, low, high, page] |
|
|
676 | |
637 | |
677 | $class->SUPER::new ( |
638 | $class->SUPER::new ( |
678 | #bg => [0, 0, 0, 0.2], |
639 | #bg => [0, 0, 0, 0.2], |
679 | #active_bg => [1, 1, 1, 0.5], |
640 | #active_bg => [1, 1, 1, 0.5], |
680 | @_ |
641 | @_ |
… | |
… | |
692 | my ($w, $h) = @$self{qw(w h)}; |
653 | my ($w, $h) = @$self{qw(w h)}; |
693 | |
654 | |
694 | glEnable GL_BLEND; |
655 | glEnable GL_BLEND; |
695 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
656 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
696 | glColor_premultiply @$color; |
657 | glColor_premultiply @$color; |
697 | |
|
|
698 | glBegin GL_QUADS; |
|
|
699 | glVertex 0 , 0; |
|
|
700 | glVertex 0 , $h; |
|
|
701 | glVertex $w, $h; |
658 | glRect 0, 0, $w, $h; |
702 | glVertex $w, 0; |
|
|
703 | glEnd; |
|
|
704 | |
|
|
705 | glDisable GL_BLEND; |
659 | glDisable GL_BLEND; |
706 | } |
660 | } |
707 | } |
661 | } |
708 | |
662 | |
709 | ############################################################################# |
663 | ############################################################################# |
… | |
… | |
769 | sort { $a->{z} <=> $b->{z} } |
723 | sort { $a->{z} <=> $b->{z} } |
770 | @{$self->{children}}, @widgets |
724 | @{$self->{children}}, @widgets |
771 | ]; |
725 | ]; |
772 | |
726 | |
773 | $self->realloc; |
727 | $self->realloc; |
|
|
728 | |
|
|
729 | $self->emit (c_add => \@widgets); |
|
|
730 | |
|
|
731 | map $_+0, @widgets |
774 | } |
732 | } |
775 | |
733 | |
776 | sub children { |
734 | sub children { |
777 | @{ $_[0]{children} } |
735 | @{ $_[0]{children} } |
778 | } |
736 | } |
779 | |
737 | |
780 | sub remove { |
738 | sub remove { |
781 | my ($self, $child) = @_; |
739 | my ($self, @widgets) = @_; |
782 | |
740 | |
|
|
741 | $self->emit (c_remove => \@widgets); |
|
|
742 | |
|
|
743 | for my $child (@widgets) { |
783 | delete $child->{parent}; |
744 | delete $child->{parent}; |
784 | $child->hide; |
745 | $child->hide; |
785 | |
|
|
786 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
746 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
|
|
747 | } |
787 | |
748 | |
788 | $self->realloc; |
749 | $self->realloc; |
789 | } |
750 | } |
790 | |
751 | |
791 | sub clear { |
752 | sub clear { |
… | |
… | |
819 | } |
780 | } |
820 | |
781 | |
821 | sub _draw { |
782 | sub _draw { |
822 | my ($self) = @_; |
783 | my ($self) = @_; |
823 | |
784 | |
824 | $_->draw for @{$self->{children}}; |
785 | $_->draw for $self->visible_children; |
825 | } |
786 | } |
826 | |
787 | |
827 | ############################################################################# |
788 | ############################################################################# |
828 | |
789 | |
829 | package CFPlus::UI::Bin; |
790 | package CFPlus::UI::Bin; |
… | |
… | |
839 | } |
800 | } |
840 | |
801 | |
841 | sub add { |
802 | sub add { |
842 | my ($self, $child) = @_; |
803 | my ($self, $child) = @_; |
843 | |
804 | |
844 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
805 | $self->clear; |
845 | $self->SUPER::add ($child); |
806 | $self->SUPER::add ($child); |
846 | } |
807 | } |
847 | |
808 | |
848 | sub remove { |
809 | sub remove { |
849 | my ($self, $widget) = @_; |
810 | my ($self, $widget) = @_; |
… | |
… | |
867 | |
828 | |
868 | 1 |
829 | 1 |
869 | } |
830 | } |
870 | |
831 | |
871 | ############################################################################# |
832 | ############################################################################# |
872 | |
|
|
873 | # back-buffered drawing area |
833 | # back-buffered drawing area |
874 | |
834 | |
875 | package CFPlus::UI::Window; |
835 | package CFPlus::UI::Window; |
876 | |
836 | |
877 | our @ISA = CFPlus::UI::Bin::; |
837 | our @ISA = CFPlus::UI::Bin::; |
… | |
… | |
991 | $self->{view_x} = $x; |
951 | $self->{view_x} = $x; |
992 | $self->{view_y} = $y; |
952 | $self->{view_y} = $y; |
993 | |
953 | |
994 | $self->emit (changed => $x, $y); |
954 | $self->emit (changed => $x, $y); |
995 | $self->update; |
955 | $self->update; |
|
|
956 | } |
|
|
957 | } |
|
|
958 | |
|
|
959 | sub set_center { |
|
|
960 | my ($self, $x, $y) = @_; |
|
|
961 | |
|
|
962 | $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5); |
|
|
963 | } |
|
|
964 | |
|
|
965 | sub make_visible { |
|
|
966 | my ($self, $x, $y, $border) = @_; |
|
|
967 | |
|
|
968 | if ( $x < $self->{view_x} + $self->{w} * $border |
|
|
969 | || $x > $self->{view_x} + $self->{w} * (1 - $border) |
|
|
970 | || $y < $self->{view_y} + $self->{h} * $border |
|
|
971 | || $y > $self->{view_y} + $self->{h} * (1 - $border) |
|
|
972 | ) { |
|
|
973 | $self->set_center ($x, $y); |
996 | } |
974 | } |
997 | } |
975 | } |
998 | |
976 | |
999 | # hmm, this does not work for topleft of $self... but we should not ask for that |
977 | # hmm, this does not work for topleft of $self... but we should not ask for that |
1000 | sub coord2local { |
978 | sub coord2local { |
… | |
… | |
1047 | my $child = delete $arg{child}; |
1025 | my $child = delete $arg{child}; |
1048 | |
1026 | |
1049 | my $self; |
1027 | my $self; |
1050 | |
1028 | |
1051 | my $hslider = new CFPlus::UI::Slider |
1029 | my $hslider = new CFPlus::UI::Slider |
1052 | col => 0, |
1030 | c_col => 0, |
1053 | row => 1, |
1031 | c_row => 1, |
1054 | vertical => 0, |
1032 | vertical => 0, |
1055 | range => [0, 0, 1, 0.01], # HACK fix |
1033 | range => [0, 0, 1, 0.01], # HACK fix |
1056 | on_changed => sub { |
1034 | on_changed => sub { |
1057 | $self->{hpos} = $_[1]; |
1035 | $self->{hpos} = $_[1]; |
1058 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1036 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1059 | }, |
1037 | }, |
1060 | ; |
1038 | ; |
1061 | |
1039 | |
1062 | my $vslider = new CFPlus::UI::Slider |
1040 | my $vslider = new CFPlus::UI::Slider |
1063 | col => 1, |
1041 | c_col => 1, |
1064 | row => 0, |
1042 | c_row => 0, |
1065 | vertical => 1, |
1043 | vertical => 1, |
1066 | range => [0, 0, 1, 0.01], # HACK fix |
1044 | range => [0, 0, 1, 0.01], # HACK fix |
1067 | on_changed => sub { |
1045 | on_changed => sub { |
1068 | $self->{vpos} = $_[1]; |
1046 | $self->{vpos} = $_[1]; |
1069 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1047 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
… | |
… | |
1080 | row_expand => [1, 0], |
1058 | row_expand => [1, 0], |
1081 | %arg, |
1059 | %arg, |
1082 | ); |
1060 | ); |
1083 | |
1061 | |
1084 | $self->{vp} = new CFPlus::UI::ViewPort |
1062 | $self->{vp} = new CFPlus::UI::ViewPort |
1085 | col => 0, |
1063 | c_col => 0, |
1086 | row => 0, |
1064 | c_row => 0, |
1087 | expand => 1, |
1065 | expand => 1, |
1088 | scroll_x => $self->{scroll_x}, |
1066 | scroll_x => $self->{scroll_x}, |
1089 | scroll_y => $self->{scroll_y}, |
1067 | scroll_y => $self->{scroll_y}, |
1090 | on_changed => sub { |
1068 | on_changed => sub { |
1091 | my ($vp, $x, $y) = @_; |
1069 | my ($vp, $x, $y) = @_; |
… | |
… | |
1093 | $vp->{parent}{hslider}->set_value ($x); |
1071 | $vp->{parent}{hslider}->set_value ($x); |
1094 | $vp->{parent}{vslider}->set_value ($y); |
1072 | $vp->{parent}{vslider}->set_value ($y); |
1095 | |
1073 | |
1096 | 0 |
1074 | 0 |
1097 | }, |
1075 | }, |
|
|
1076 | on_size_allocate => sub { |
|
|
1077 | my ($vp, $w, $h) = @_; |
|
|
1078 | $vp->{parent}->update_slider; |
|
|
1079 | 0 |
|
|
1080 | }, |
1098 | ; |
1081 | ; |
1099 | |
1082 | |
1100 | $self->SUPER::add ($self->{vp}); |
1083 | $self->SUPER::add ($self->{vp}); |
1101 | |
1084 | |
1102 | $self->add ($child) if $child; |
1085 | $self->add ($child) if $child; |
… | |
… | |
1108 | my ($self, $widget) = @_; |
1091 | my ($self, $widget) = @_; |
1109 | |
1092 | |
1110 | $self->{vp}->add ($self->{child} = $widget); |
1093 | $self->{vp}->add ($self->{child} = $widget); |
1111 | } |
1094 | } |
1112 | |
1095 | |
|
|
1096 | sub set_offset { shift->{vp}->set_offset (@_) } |
|
|
1097 | sub set_center { shift->{vp}->set_center (@_) } |
|
|
1098 | sub make_visible { shift->{vp}->make_visible (@_) } |
|
|
1099 | |
1113 | sub update_slider { |
1100 | sub update_slider { |
1114 | my ($self) = @_; |
1101 | my ($self) = @_; |
1115 | |
1102 | |
1116 | my $child = ($self->{vp} or return)->child; |
1103 | my $child = ($self->{vp} or return)->child; |
1117 | |
1104 | |
|
|
1105 | if ($self->{scroll_x}) { |
1118 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
1106 | my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w}); |
1119 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1107 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1120 | |
1108 | |
1121 | my $visible = $w1 > $w2; |
1109 | my $visible = $w1 > $w2; |
1122 | if ($visible != $self->{hslider_visible}) { |
1110 | if ($visible != $self->{hslider_visible}) { |
1123 | $self->{hslider_visible} = $visible; |
1111 | $self->{hslider_visible} = $visible; |
1124 | $visible ? $self->SUPER::add ($self->{hslider}) |
1112 | $visible ? $self->SUPER::add ($self->{hslider}) |
1125 | : $self->SUPER::remove ($self->{hslider}); |
1113 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1114 | } |
1126 | } |
1115 | } |
1127 | |
1116 | |
|
|
1117 | if ($self->{scroll_y}) { |
1128 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
1118 | my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h}); |
1129 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1119 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1130 | |
1120 | |
1131 | my $visible = $h1 > $h2; |
1121 | my $visible = $h1 > $h2; |
1132 | if ($visible != $self->{vslider_visible}) { |
1122 | if ($visible != $self->{vslider_visible}) { |
1133 | $self->{vslider_visible} = $visible; |
1123 | $self->{vslider_visible} = $visible; |
1134 | $visible ? $self->SUPER::add ($self->{vslider}) |
1124 | $visible ? $self->SUPER::add ($self->{vslider}) |
1135 | : $self->SUPER::remove ($self->{vslider}); |
1125 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1126 | } |
1136 | } |
1127 | } |
1137 | } |
1128 | } |
1138 | |
|
|
1139 | |
1129 | |
1140 | sub start_dragging { |
1130 | sub start_dragging { |
1141 | my ($self, $ev) = @_; |
1131 | my ($self, $ev) = @_; |
1142 | |
1132 | |
1143 | $self->grab_focus; |
1133 | $self->grab_focus; |
… | |
… | |
1156 | } |
1146 | } |
1157 | |
1147 | |
1158 | sub invoke_mouse_wheel { |
1148 | sub invoke_mouse_wheel { |
1159 | my ($self, $ev) = @_; |
1149 | my ($self, $ev) = @_; |
1160 | |
1150 | |
1161 | $self->{vslider}->emit (mouse_wheel => $ev); |
1151 | $self->{vslider}->emit (mouse_wheel => $ev) if $self->{vslider_visible}; |
1162 | $self->{hslider}->emit (mouse_wheel => $ev); |
1152 | $self->{hslider}->emit (mouse_wheel => $ev) if $self->{hslider_visible}; |
1163 | |
1153 | |
1164 | 1 |
1154 | 1 |
1165 | } |
1155 | } |
1166 | |
1156 | |
1167 | sub invoke_button_down { |
1157 | sub invoke_button_down { |
1168 | my ($self, $ev, $x, $y) = @_; |
1158 | my ($self, $ev, $x, $y) = @_; |
1169 | |
1159 | |
|
|
1160 | if ($ev->{button} == 2) { |
1170 | $self->start_dragging ($ev); |
1161 | $self->start_dragging ($ev); |
1171 | |
1162 | return 1; |
1172 | 1 |
1163 | } |
|
|
1164 | |
|
|
1165 | 0 |
1173 | } |
1166 | } |
1174 | |
1167 | |
1175 | sub invoke_button_up { |
1168 | sub invoke_button_up { |
1176 | my ($self, $ev, $x, $y) = @_; |
1169 | my ($self, $ev, $x, $y) = @_; |
1177 | |
1170 | |
… | |
… | |
1224 | my ($w, $h) = @$self{qw(w h)}; |
1217 | my ($w, $h) = @$self{qw(w h)}; |
1225 | |
1218 | |
1226 | glEnable GL_BLEND; |
1219 | glEnable GL_BLEND; |
1227 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1220 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
1228 | glColor_premultiply @{ $self->{bg} }; |
1221 | glColor_premultiply @{ $self->{bg} }; |
1229 | |
|
|
1230 | glBegin GL_QUADS; |
|
|
1231 | glVertex 0 , 0; |
|
|
1232 | glVertex 0 , $h; |
|
|
1233 | glVertex $w, $h; |
1222 | glRect 0, 0, $w, $h; |
1234 | glVertex $w, 0; |
|
|
1235 | glEnd; |
|
|
1236 | |
|
|
1237 | glDisable GL_BLEND; |
1223 | glDisable GL_BLEND; |
1238 | } |
1224 | } |
1239 | |
1225 | |
1240 | $self->SUPER::_draw; |
1226 | $self->SUPER::_draw; |
1241 | } |
1227 | } |
… | |
… | |
1402 | |
1388 | |
1403 | sub border { |
1389 | sub border { |
1404 | int $_[0]{border} * $::FONTSIZE |
1390 | int $_[0]{border} * $::FONTSIZE |
1405 | } |
1391 | } |
1406 | |
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 | |
1407 | sub size_request { |
1402 | sub size_request { |
1408 | my ($self) = @_; |
1403 | my ($self) = @_; |
1409 | |
1404 | |
1410 | $self->{title_widget}->size_request |
1405 | $self->{title_widget}->size_request |
1411 | if $self->{title_widget}; |
1406 | if $self->{title_widget}; |
… | |
… | |
1603 | |
1598 | |
1604 | sub add { |
1599 | sub add { |
1605 | my ($self, @widgets) = @_; |
1600 | my ($self, @widgets) = @_; |
1606 | |
1601 | |
1607 | for my $child (@widgets) { |
1602 | for my $child (@widgets) { |
1608 | $child->{rowspan} ||= 1; |
1603 | $child->{c_rowspan} ||= 1; |
1609 | $child->{colspan} ||= 1; |
1604 | $child->{c_colspan} ||= 1; |
1610 | } |
1605 | } |
1611 | |
1606 | |
1612 | $self->SUPER::add (@widgets); |
1607 | $self->SUPER::add (@widgets); |
1613 | } |
1608 | } |
1614 | |
1609 | |
… | |
… | |
1618 | my @widgets; |
1613 | my @widgets; |
1619 | |
1614 | |
1620 | while (@_) { |
1615 | while (@_) { |
1621 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1616 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1622 | |
1617 | |
1623 | $child->{row} = $row; |
1618 | $child->{c_row} = $row; |
1624 | $child->{col} = $col; |
1619 | $child->{c_col} = $col; |
1625 | |
1620 | |
1626 | push @widgets, $child; |
1621 | push @widgets, $child; |
1627 | } |
1622 | } |
1628 | |
1623 | |
1629 | $self->add (@widgets); |
1624 | $self->add (@widgets); |
… | |
… | |
1635 | my (@w, @h); |
1630 | my (@w, @h); |
1636 | |
1631 | |
1637 | my @children = $self->children; |
1632 | my @children = $self->children; |
1638 | |
1633 | |
1639 | # first pass, columns |
1634 | # first pass, columns |
1640 | for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { |
1635 | for my $widget (sort { $a->{c_colspan} <=> $b->{c_colspan} } @children) { |
1641 | my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; |
1636 | my ($c, $w, $cs) = @$widget{qw(c_col req_w c_colspan)}; |
1642 | |
1637 | |
1643 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1638 | my $sw = sum @w[$c .. $c + $cs - 1]; |
1644 | |
1639 | |
1645 | if ($w > $sw) { |
1640 | if ($w > $sw) { |
1646 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1641 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1647 | } |
1642 | } |
1648 | } |
1643 | } |
1649 | |
1644 | |
1650 | # second pass, rows |
1645 | # second pass, rows |
1651 | for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { |
1646 | for my $widget (sort { $a->{c_rowspan} <=> $b->{c_rowspan} } @children) { |
1652 | my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; |
1647 | my ($r, $h, $rs) = @$widget{qw(c_row req_h c_rowspan)}; |
1653 | |
1648 | |
1654 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1649 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1655 | |
1650 | |
1656 | if ($h > $sh) { |
1651 | if ($h > $sh) { |
1657 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1652 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
… | |
… | |
1699 | |
1694 | |
1700 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1695 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
1701 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1696 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1702 | |
1697 | |
1703 | for my $widget ($self->children) { |
1698 | for my $widget ($self->children) { |
1704 | 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)}; |
1705 | |
1700 | |
1706 | $widget->configure ( |
1701 | $widget->configure ( |
1707 | $x[$c], $y[$r], |
1702 | $x[$c], $y[$r], |
1708 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1703 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1709 | ); |
1704 | ); |
… | |
… | |
1718 | |
1713 | |
1719 | use List::Util qw(min max); |
1714 | use List::Util qw(min max); |
1720 | |
1715 | |
1721 | our @ISA = CFPlus::UI::Container::; |
1716 | our @ISA = CFPlus::UI::Container::; |
1722 | |
1717 | |
1723 | sub add { |
|
|
1724 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1725 | |
|
|
1726 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1727 | $self->SUPER::add ($child); |
|
|
1728 | } |
|
|
1729 | |
|
|
1730 | sub _scale($$$) { |
1718 | sub _scale($$$) { |
1731 | my ($mode, $val, $max) = @_; |
1719 | my ($rel, $val, $max) = @_; |
1732 | |
1720 | |
1733 | $mode eq "abs" ? $val |
1721 | $rel ? $val * $max : $val |
1734 | : $mode eq "rel" ? $val * $max |
|
|
1735 | : 0 |
|
|
1736 | } |
1722 | } |
1737 | |
1723 | |
1738 | sub size_request { |
1724 | sub size_request { |
1739 | my ($self) = @_; |
1725 | my ($self) = @_; |
1740 | |
1726 | |
1741 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1727 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1742 | |
1728 | |
1743 | # determine overall size by querying abs widgets |
1729 | # determine overall size by querying abs widgets |
1744 | for my $child ($self->visible_children) { |
1730 | for my $child ($self->visible_children) { |
1745 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1731 | unless ($child->{c_rel}) { |
|
|
1732 | my $x = $child->{c_x}; |
|
|
1733 | my $y = $child->{c_y}; |
1746 | |
1734 | |
1747 | if ($pos eq "abs") { |
|
|
1748 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1749 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1750 | |
|
|
1751 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1735 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1752 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1736 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1753 | } |
1737 | } |
1754 | } |
1738 | } |
1755 | |
1739 | |
1756 | my $W = $x2 - $x1; |
1740 | my $W = $x2 - $x1; |
1757 | my $H = $y2 - $y1; |
1741 | my $H = $y2 - $y1; |
1758 | |
1742 | |
1759 | # now layout remaining widgets |
1743 | # now layout remaining widgets |
1760 | for my $child ($self->visible_children) { |
1744 | for my $child ($self->visible_children) { |
1761 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1745 | if ($child->{c_rel}) { |
|
|
1746 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1747 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1762 | |
1748 | |
1763 | if ($pos ne "abs") { |
|
|
1764 | $x = _scale $pos, $x, $W; |
|
|
1765 | $y = _scale $pos, $x, $H; |
|
|
1766 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1767 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1768 | |
|
|
1769 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1749 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1770 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1750 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1771 | } |
1751 | } |
1772 | } |
1752 | } |
1773 | |
1753 | |
1774 | my $W = $x2 - $x1; |
1754 | my $W = $x2 - $x1; |
1775 | my $H = $y2 - $y1; |
1755 | my $H = $y2 - $y1; |
… | |
… | |
1779 | |
1759 | |
1780 | sub invoke_size_allocate { |
1760 | sub invoke_size_allocate { |
1781 | my ($self, $W, $H) = @_; |
1761 | my ($self, $W, $H) = @_; |
1782 | |
1762 | |
1783 | for my $child ($self->visible_children) { |
1763 | for my $child ($self->visible_children) { |
1784 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1764 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1765 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1785 | |
1766 | |
1786 | $x = _scale $pos, $x, $W; |
1767 | $x += $child->{c_halign} * $child->{req_w}; |
1787 | $y = _scale $pos, $x, $H; |
1768 | $y += $child->{c_valign} * $child->{req_h}; |
1788 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1789 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1790 | |
1769 | |
1791 | $child->configure ($x, $y, $w, $h); |
1770 | $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h}); |
1792 | } |
1771 | } |
1793 | |
1772 | |
1794 | 1 |
1773 | 1 |
1795 | } |
1774 | } |
1796 | |
1775 | |
… | |
… | |
1800 | |
1779 | |
1801 | our @ISA = CFPlus::UI::Container::; |
1780 | our @ISA = CFPlus::UI::Container::; |
1802 | |
1781 | |
1803 | sub size_request { |
1782 | sub size_request { |
1804 | my ($self) = @_; |
1783 | my ($self) = @_; |
|
|
1784 | |
|
|
1785 | my @children = $self->visible_children; |
1805 | |
1786 | |
1806 | $self->{vertical} |
1787 | $self->{vertical} |
1807 | ? ( |
1788 | ? ( |
1808 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1789 | (List::Util::max map $_->{req_w}, @children), |
1809 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1790 | (List::Util::sum map $_->{req_h}, @children), |
1810 | ) |
1791 | ) |
1811 | : ( |
1792 | : ( |
1812 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
1793 | (List::Util::sum map $_->{req_w}, @children), |
1813 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1794 | (List::Util::max map $_->{req_h}, @children), |
1814 | ) |
1795 | ) |
1815 | } |
1796 | } |
1816 | |
1797 | |
1817 | sub invoke_size_allocate { |
1798 | sub invoke_size_allocate { |
1818 | my ($self, $w, $h) = @_; |
1799 | my ($self, $w, $h) = @_; |
… | |
… | |
1942 | |
1923 | |
1943 | delete $self->{ox}; |
1924 | delete $self->{ox}; |
1944 | $self->SUPER::realloc; |
1925 | $self->SUPER::realloc; |
1945 | } |
1926 | } |
1946 | |
1927 | |
|
|
1928 | sub clear { |
|
|
1929 | my ($self) = @_; |
|
|
1930 | |
|
|
1931 | $self->set_text (""); |
|
|
1932 | } |
|
|
1933 | |
1947 | sub set_text { |
1934 | sub set_text { |
1948 | my ($self, $text) = @_; |
1935 | my ($self, $text) = @_; |
1949 | |
1936 | |
1950 | return if $self->{text} eq "T$text"; |
1937 | return if $self->{text} eq "T$text"; |
1951 | $self->{text} = "T$text"; |
1938 | $self->{text} = "T$text"; |
… | |
… | |
1974 | |
1961 | |
1975 | sub size_request { |
1962 | sub size_request { |
1976 | my ($self) = @_; |
1963 | my ($self) = @_; |
1977 | |
1964 | |
1978 | $self->{size_req} ||= do { |
1965 | $self->{size_req} ||= do { |
|
|
1966 | my ($max_w, $max_h) = $self->get_max_wh; |
|
|
1967 | |
1979 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1968 | $self->{layout}->set_font ($self->{font}) if $self->{font}; |
1980 | $self->{layout}->set_width ($self->{max_w} || -1); |
1969 | $self->{layout}->set_width ($self->{max_w} || $max_w || -1); |
1981 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1970 | $self->{layout}->set_ellipsise ($self->{ellipsise}); |
1982 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1971 | $self->{layout}->set_single_paragraph_mode ($self->{ellipsise}); |
1983 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1972 | $self->{layout}->set_height ($self->{fontsize} * $::FONTSIZE); |
1984 | |
1973 | |
1985 | my ($w, $h) = $self->{layout}->size; |
1974 | my ($w, $h) = $self->{layout}->size; |
… | |
… | |
2057 | : ($self->{w} - $size->[0]) * 0.5); |
2046 | : ($self->{w} - $size->[0]) * 0.5); |
2058 | |
2047 | |
2059 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2048 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2060 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2049 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2061 | : ($self->{h} - $size->[1]) * 0.5); |
2050 | : ($self->{h} - $size->[1]) * 0.5); |
|
|
2051 | |
|
|
2052 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2062 | }; |
2053 | }; |
2063 | |
2054 | |
2064 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2055 | # unless ($self->{list}) { |
2065 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
2056 | # $self->{list} = CFPlus::OpenGL::glGenList; |
2066 | |
2057 | # CFPlus::OpenGL::glNewList $self->{list}; |
2067 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2058 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
|
|
2059 | # CFPlus::OpenGL::glEndList; |
|
|
2060 | # } |
|
|
2061 | # |
|
|
2062 | # CFPlus::OpenGL::glCallList $self->{list}; |
|
|
2063 | |
|
|
2064 | $self->{layout}->draw; |
2068 | } |
2065 | } |
|
|
2066 | |
|
|
2067 | #sub destroy { |
|
|
2068 | # my ($self) = @_; |
|
|
2069 | # |
|
|
2070 | # CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
|
|
2071 | # |
|
|
2072 | # $self->SUPER::destroy; |
|
|
2073 | #} |
2069 | |
2074 | |
2070 | ############################################################################# |
2075 | ############################################################################# |
2071 | |
2076 | |
2072 | package CFPlus::UI::EntryBase; |
2077 | package CFPlus::UI::EntryBase; |
2073 | |
2078 | |
… | |
… | |
2079 | my $class = shift; |
2084 | my $class = shift; |
2080 | |
2085 | |
2081 | $class->SUPER::new ( |
2086 | $class->SUPER::new ( |
2082 | fg => [1, 1, 1], |
2087 | fg => [1, 1, 1], |
2083 | bg => [0, 0, 0, 0.2], |
2088 | bg => [0, 0, 0, 0.2], |
|
|
2089 | outline => [0.6, 0.3, 0.1], |
2084 | active_bg => [1, 1, 1, 0.5], |
2090 | active_bg => [0, 0, 1, .2], |
2085 | active_fg => [0, 0, 0], |
2091 | active_fg => [1, 1, 1], |
|
|
2092 | active_outline => [1, 1, 0], |
2086 | can_hover => 1, |
2093 | can_hover => 1, |
2087 | can_focus => 1, |
2094 | can_focus => 1, |
2088 | valign => 0, |
2095 | valign => 0, |
2089 | can_events => 1, |
2096 | can_events => 1, |
2090 | ellipsise => 0, |
2097 | ellipsise => 0, |
… | |
… | |
2230 | glColor_premultiply @{$self->{bg}}; |
2237 | glColor_premultiply @{$self->{bg}}; |
2231 | } |
2238 | } |
2232 | |
2239 | |
2233 | glEnable GL_BLEND; |
2240 | glEnable GL_BLEND; |
2234 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2241 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
2235 | glBegin GL_QUADS; |
|
|
2236 | glVertex 0 , 0; |
|
|
2237 | glVertex 0 , $self->{h}; |
|
|
2238 | glVertex $self->{w}, $self->{h}; |
2242 | glRect 0, 0, $self->{w}, $self->{h}; |
2239 | glVertex $self->{w}, 0; |
|
|
2240 | glEnd; |
|
|
2241 | glDisable GL_BLEND; |
2243 | glDisable GL_BLEND; |
2242 | |
2244 | |
2243 | $self->SUPER::_draw; |
2245 | $self->SUPER::_draw; |
2244 | |
2246 | |
2245 | #TODO: force update every cursor change :( |
2247 | #TODO: force update every cursor change :( |
… | |
… | |
2247 | |
2249 | |
2248 | unless (exists $self->{cur_h}) { |
2250 | unless (exists $self->{cur_h}) { |
2249 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2251 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2250 | utf8::encode $text; |
2252 | utf8::encode $text; |
2251 | |
2253 | |
2252 | @$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); |
2253 | } |
2255 | } |
2254 | |
2256 | |
|
|
2257 | glColor_premultiply @{$self->{active_fg}}; |
2255 | glBegin GL_LINES; |
2258 | glBegin GL_LINES; |
2256 | 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}; |
2257 | 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; |
2258 | glEnd; |
2275 | glEnd; |
2259 | } |
2276 | } |
2260 | } |
2277 | } |
2261 | |
2278 | |
2262 | ############################################################################# |
2279 | ############################################################################# |
… | |
… | |
2349 | 1 |
2366 | 1 |
2350 | } |
2367 | } |
2351 | |
2368 | |
2352 | ############################################################################# |
2369 | ############################################################################# |
2353 | |
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 | |
2354 | package CFPlus::UI::Button; |
2420 | package CFPlus::UI::Button; |
2355 | |
2421 | |
2356 | our @ISA = CFPlus::UI::Label::; |
2422 | our @ISA = CFPlus::UI::Label::; |
2357 | |
2423 | |
2358 | use CFPlus::OpenGL; |
2424 | use CFPlus::OpenGL; |
… | |
… | |
2462 | sub _draw { |
2528 | sub _draw { |
2463 | my ($self) = @_; |
2529 | my ($self) = @_; |
2464 | |
2530 | |
2465 | $self->SUPER::_draw; |
2531 | $self->SUPER::_draw; |
2466 | |
2532 | |
2467 | glTranslate $self->{padding_x} + 0.375, $self->{padding_y} + 0.375, 0; |
2533 | glTranslate $self->{padding_x}, $self->{padding_y}, 0; |
2468 | |
2534 | |
2469 | my ($w, $h) = @$self{qw(w h)}; |
2535 | my ($w, $h) = @$self{qw(w h)}; |
2470 | |
2536 | |
2471 | 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; |
2472 | |
2538 | |
… | |
… | |
2492 | sub new { |
2558 | sub new { |
2493 | my $class = shift; |
2559 | my $class = shift; |
2494 | |
2560 | |
2495 | my $self = $class->SUPER::new ( |
2561 | my $self = $class->SUPER::new ( |
2496 | can_events => 0, |
2562 | can_events => 0, |
|
|
2563 | scale => 1, |
2497 | @_, |
2564 | @_, |
2498 | ); |
2565 | ); |
2499 | |
2566 | |
2500 | $self->{path} || $self->{tex} |
2567 | $self->{path} || $self->{tex} |
2501 | or Carp::croak "'path' or 'tex' attributes required"; |
2568 | or Carp::croak "'path' or 'tex' attributes required"; |
… | |
… | |
2526 | } |
2593 | } |
2527 | |
2594 | |
2528 | sub size_request { |
2595 | sub size_request { |
2529 | my ($self) = @_; |
2596 | my ($self) = @_; |
2530 | |
2597 | |
2531 | ($self->{tex}{w}, $self->{tex}{h}) |
2598 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2532 | } |
2599 | } |
2533 | |
2600 | |
2534 | sub _draw { |
2601 | sub _draw { |
2535 | my ($self) = @_; |
2602 | my ($self) = @_; |
2536 | |
2603 | |
… | |
… | |
2546 | } |
2613 | } |
2547 | |
2614 | |
2548 | glEnable GL_TEXTURE_2D; |
2615 | glEnable GL_TEXTURE_2D; |
2549 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2616 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2550 | |
2617 | |
2551 | $tex->draw_quad (0, 0, $w, $h); |
2618 | $tex->draw_quad_alpha (0, 0, $w, $h); |
2552 | |
2619 | |
2553 | glDisable GL_TEXTURE_2D; |
2620 | glDisable GL_TEXTURE_2D; |
2554 | } |
2621 | } |
2555 | |
2622 | |
2556 | ############################################################################# |
2623 | ############################################################################# |
… | |
… | |
2575 | align => 0, |
2642 | align => 0, |
2576 | valign => 0, |
2643 | valign => 0, |
2577 | can_events => 1, |
2644 | can_events => 1, |
2578 | @_ |
2645 | @_ |
2579 | ); |
2646 | ); |
|
|
2647 | } |
|
|
2648 | |
|
|
2649 | sub invoke_button_down { |
|
|
2650 | my ($self, $ev, $x, $y) = @_; |
|
|
2651 | |
|
|
2652 | 1 |
2580 | } |
2653 | } |
2581 | |
2654 | |
2582 | sub invoke_button_up { |
2655 | sub invoke_button_up { |
2583 | my ($self, $ev, $x, $y) = @_; |
2656 | my ($self, $ev, $x, $y) = @_; |
2584 | |
2657 | |
… | |
… | |
2724 | glDisable GL_TEXTURE_2D; |
2797 | glDisable GL_TEXTURE_2D; |
2725 | } |
2798 | } |
2726 | |
2799 | |
2727 | ############################################################################# |
2800 | ############################################################################# |
2728 | |
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 | |
2729 | package CFPlus::UI::Gauge; |
2940 | package CFPlus::UI::Gauge; |
2730 | |
2941 | |
2731 | our @ISA = CFPlus::UI::VBox::; |
2942 | our @ISA = CFPlus::UI::VBox::; |
2732 | |
2943 | |
2733 | sub new { |
2944 | sub new { |
… | |
… | |
2858 | |
3069 | |
2859 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
3070 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2860 | |
3071 | |
2861 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
3072 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2862 | |
3073 | |
2863 | $self->invoke_mouse_motion ($ev, $x, $y) |
3074 | $self->invoke_mouse_motion ($ev, $x, $y); |
|
|
3075 | |
|
|
3076 | 1 |
2864 | } |
3077 | } |
2865 | |
3078 | |
2866 | sub invoke_mouse_motion { |
3079 | sub invoke_mouse_motion { |
2867 | my ($self, $ev, $x, $y) = @_; |
3080 | my ($self, $ev, $x, $y) = @_; |
2868 | |
3081 | |
… | |
… | |
2888 | |
3101 | |
2889 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
3102 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2890 | |
3103 | |
2891 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
3104 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2892 | |
3105 | |
2893 | ! ! $delta |
3106 | 1 |
2894 | } |
3107 | } |
2895 | |
3108 | |
2896 | sub update { |
3109 | sub update { |
2897 | my ($self) = @_; |
3110 | my ($self) = @_; |
2898 | |
3111 | |
… | |
… | |
3029 | } |
3242 | } |
3030 | |
3243 | |
3031 | sub size_request { |
3244 | sub size_request { |
3032 | my ($self) = @_; |
3245 | my ($self) = @_; |
3033 | |
3246 | |
3034 | my ($empty, $slider) = @{ $self->{children} }; |
3247 | my ($empty, $slider) = $self->visible_children; |
3035 | |
3248 | |
3036 | local $self->{children} = [$empty, $slider]; |
3249 | local $self->{children} = [$empty, $slider]; |
3037 | $self->SUPER::size_request |
3250 | $self->SUPER::size_request |
3038 | } |
3251 | } |
3039 | |
3252 | |
… | |
… | |
3228 | |
3441 | |
3229 | if ($y0 < $y + $h && $y < $y1) { |
3442 | if ($y0 < $y + $h && $y < $y1) { |
3230 | my $layout = $self->get_layout ($para); |
3443 | my $layout = $self->get_layout ($para); |
3231 | |
3444 | |
3232 | $layout->render ($para->{indent}, $y - $y0); |
3445 | $layout->render ($para->{indent}, $y - $y0); |
|
|
3446 | $layout->draw; |
3233 | |
3447 | |
3234 | if (my @w = @{ $para->{widget} }) { |
3448 | if (my @w = @{ $para->{widget} }) { |
3235 | my @s = $layout->get_shapes; |
3449 | my @s = $layout->get_shapes; |
3236 | |
3450 | |
3237 | for (@w) { |
3451 | for (@w) { |
… | |
… | |
3359 | } |
3573 | } |
3360 | |
3574 | |
3361 | sub set_tooltip_from { |
3575 | sub set_tooltip_from { |
3362 | my ($self, $widget) = @_; |
3576 | my ($self, $widget) = @_; |
3363 | |
3577 | |
3364 | $widget->{tooltip} = CFPlus::Pod::section_label tooltip => $1 |
|
|
3365 | if $widget->{tooltip} =~ /^#(.*)$/; |
|
|
3366 | |
|
|
3367 | 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 =~ /^#(.*)$/; |
3368 | |
3583 | |
3369 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3584 | if ($ENV{CFPLUS_DEBUG} & 2) { |
3370 | $tooltip .= "\n\n" . (ref $widget) . "\n" |
3585 | $tip .= "\n\n" . (ref $widget) . "\n" |
3371 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3586 | . "$widget->{x} $widget->{y} $widget->{w} $widget->{h}\n" |
3372 | . "req $widget->{req_w} $widget->{req_h}\n" |
3587 | . "req $widget->{req_w} $widget->{req_h}\n" |
3373 | . "visible $widget->{visible}"; |
3588 | . "visible $widget->{visible}"; |
3374 | } |
3589 | } |
3375 | |
3590 | |
3376 | $tooltip =~ s/^\n+//; |
3591 | $tip =~ s/^\n+//; |
3377 | $tooltip =~ s/\n+$//; |
3592 | $tip =~ s/\n+$//; |
3378 | |
3593 | |
3379 | $self->add (new CFPlus::UI::Label |
3594 | $self->add (new CFPlus::UI::Label |
3380 | markup => $tooltip, |
3595 | markup => $tip, |
3381 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3596 | max_w => ($widget->{tooltip_width} || 0.25) * $::WIDTH, |
3382 | fontsize => 0.8, |
3597 | fontsize => 0.8, |
3383 | style => 1, # FLAG_INVERSE |
3598 | style => 1, # FLAG_INVERSE |
3384 | ellipsise => 0, |
3599 | ellipsise => 0, |
3385 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
3600 | font => ($widget->{tooltip_font} || $::FONT_PROP), |
… | |
… | |
3423 | } |
3638 | } |
3424 | |
3639 | |
3425 | sub _draw { |
3640 | sub _draw { |
3426 | my ($self) = @_; |
3641 | my ($self) = @_; |
3427 | |
3642 | |
3428 | glTranslate 0.375, 0.375; |
|
|
3429 | |
|
|
3430 | my ($w, $h) = @$self{qw(w h)}; |
3643 | my ($w, $h) = @$self{qw(w h)}; |
3431 | |
3644 | |
3432 | glColor 1, 0.8, 0.4; |
3645 | glColor 1, 0.8, 0.4; |
3433 | glBegin GL_QUADS; |
3646 | glRect 0, 0, $w, $h; |
3434 | glVertex 0 , 0; |
|
|
3435 | glVertex 0 , $h; |
|
|
3436 | glVertex $w, $h; |
|
|
3437 | glVertex $w, 0; |
|
|
3438 | glEnd; |
|
|
3439 | |
3647 | |
3440 | glColor 0, 0, 0; |
3648 | glColor 0, 0, 0; |
3441 | glBegin GL_LINE_LOOP; |
3649 | glRect_lineloop .5, .5, $w + .5, $h + .5; |
3442 | glVertex 0 , 0; |
|
|
3443 | glVertex 0 , $h; |
|
|
3444 | glVertex $w, $h; |
|
|
3445 | glVertex $w, 0; |
|
|
3446 | glEnd; |
|
|
3447 | |
3650 | |
3448 | glTranslate 2 - 0.375, 2 - 0.375; |
3651 | glTranslate 2, 2; |
3449 | |
3652 | |
3450 | $self->SUPER::_draw; |
3653 | $self->SUPER::_draw; |
3451 | } |
3654 | } |
3452 | |
3655 | |
3453 | ############################################################################# |
3656 | ############################################################################# |
… | |
… | |
3471 | |
3674 | |
3472 | if ($self->{anim} && $self->{animspeed}) { |
3675 | if ($self->{anim} && $self->{animspeed}) { |
3473 | CFPlus::weaken (my $widget = $self); |
3676 | CFPlus::weaken (my $widget = $self); |
3474 | |
3677 | |
3475 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3678 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3476 | $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; |
3679 | $widget->{anim_start} = $self->{animspeed} * int EV::now / $self->{animspeed}; |
3477 | $self->{timer} = Event->timer ( |
3680 | $self->{timer} = EV::timer_ns 0, 0, sub { |
3478 | parked => 1, |
|
|
3479 | cb => sub { |
|
|
3480 | return unless $::CONN && $widget; |
3681 | return unless $::CONN; |
3481 | |
3682 | |
|
|
3683 | my $w = $widget |
|
|
3684 | or return; |
|
|
3685 | |
3482 | ++$widget->{frame}; |
3686 | ++$w->{frame}; |
3483 | $widget->update_face; |
3687 | $w->update_face; |
|
|
3688 | |
|
|
3689 | # somehow, $widget can go away |
3484 | $widget->update; |
3690 | $w->update; |
3485 | |
|
|
3486 | $widget->update_timer; |
3691 | $w->update_timer; |
3487 | }, |
|
|
3488 | ); |
3692 | }; |
3489 | |
3693 | |
3490 | $self->update_face; |
3694 | $self->update_face; |
3491 | $self->update_timer; |
3695 | $self->update_timer; |
3492 | } |
3696 | } |
3493 | |
3697 | |
… | |
… | |
3498 | my ($self) = @_; |
3702 | my ($self) = @_; |
3499 | |
3703 | |
3500 | return unless $self->{timer}; |
3704 | return unless $self->{timer}; |
3501 | |
3705 | |
3502 | if ($self->{visible}) { |
3706 | if ($self->{visible}) { |
3503 | $self->{timer}->at ( |
3707 | $self->{timer}->set ( |
3504 | $self->{anim_start} |
3708 | $self->{anim_start} |
3505 | + $self->{animspeed} |
3709 | + $self->{animspeed} |
3506 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
3710 | * int 1.5 + (EV::now - $self->{anim_start}) / $self->{animspeed} |
3507 | ); |
3711 | ); |
3508 | $self->{timer}->start; |
3712 | $self->{timer}->start; |
3509 | } else { |
3713 | } else { |
3510 | $self->{timer}->stop; |
3714 | $self->{timer}->stop; |
3511 | } |
3715 | } |
3512 | } |
3716 | } |
3513 | |
3717 | |
3514 | sub update_face { |
3718 | sub update_face { |
3515 | my ($self) = @_; |
3719 | my ($self) = @_; |
3516 | |
3720 | |
3517 | return unless $::CONN; |
|
|
3518 | |
|
|
3519 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
|
|
3520 | if ($anim && @$anim) { |
|
|
3521 | delete $self->{wait_face}; |
|
|
3522 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3523 | } |
|
|
3524 | } |
|
|
3525 | } |
|
|
3526 | |
|
|
3527 | sub size_request { |
|
|
3528 | my ($self) = @_; |
|
|
3529 | |
|
|
3530 | if ($::CONN) { |
3721 | if ($::CONN) { |
3531 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3722 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3532 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3723 | if ($anim && @$anim) { |
3533 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3724 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
3534 | } else { |
3725 | delete $self->{face_change_cb}; |
3535 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3726 | |
3536 | $self->realloc; |
3727 | if (my $tex = $self->{tex} = $::CONN->{texture}[ $::CONN->{face}[$self->{face}]{id} ]) { |
|
|
3728 | unless ($tex->{name} || $tex->{loading}) { |
|
|
3729 | $tex->upload (sub { $self->reconfigure }); |
|
|
3730 | } |
3537 | }); |
3731 | } |
3538 | } |
3732 | } |
3539 | } |
3733 | } |
3540 | } |
3734 | } |
|
|
3735 | } |
|
|
3736 | |
|
|
3737 | sub size_request { |
|
|
3738 | my ($self) = @_; |
|
|
3739 | |
|
|
3740 | if ($::CONN) { |
|
|
3741 | if (my $faceid = $::CONN->{face}[$self->{face}]{id}) { |
|
|
3742 | if (my $tex = $self->{tex} = $::CONN->{texture}[$faceid]) { |
|
|
3743 | if ($tex->{name}) { |
|
|
3744 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
|
|
3745 | } elsif (!$tex->{loading}) { |
|
|
3746 | $tex->upload (sub { $self->reconfigure }); |
|
|
3747 | } |
|
|
3748 | } |
|
|
3749 | |
|
|
3750 | $self->{face_change_cb} ||= $::CONN->on_face_change ($self->{face}, sub { $self->reconfigure }); |
|
|
3751 | } |
|
|
3752 | } |
3541 | |
3753 | |
3542 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3754 | ($self->{size_w} || 8, $self->{size_h} || 8) |
3543 | } |
3755 | } |
3544 | |
3756 | |
3545 | sub update { |
3757 | sub update { |
… | |
… | |
3559 | } |
3771 | } |
3560 | |
3772 | |
3561 | sub _draw { |
3773 | sub _draw { |
3562 | my ($self) = @_; |
3774 | my ($self) = @_; |
3563 | |
3775 | |
3564 | return unless $::CONN; |
|
|
3565 | |
|
|
3566 | $self->SUPER::_draw; |
3776 | $self->SUPER::_draw; |
3567 | |
3777 | |
3568 | my $faceid = $::CONN->{faceid}[$self->{face}] |
3778 | if (my $tex = $self->{tex}) { |
3569 | or return; |
|
|
3570 | |
|
|
3571 | my $tex = $::CONN->{texture}[$faceid]; |
|
|
3572 | |
|
|
3573 | if ($tex) { |
|
|
3574 | glEnable GL_TEXTURE_2D; |
3779 | glEnable GL_TEXTURE_2D; |
3575 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3780 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3576 | glColor 0, 0, 0, 1; |
3781 | glColor 0, 0, 0, 1; |
3577 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3782 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3578 | glDisable GL_TEXTURE_2D; |
3783 | glDisable GL_TEXTURE_2D; |
… | |
… | |
3630 | children => [ |
3835 | children => [ |
3631 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3836 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3632 | (new CFPlus::UI::Label markup => $right, align => +1), |
3837 | (new CFPlus::UI::Label markup => $right, align => +1), |
3633 | ], |
3838 | ], |
3634 | ; |
3839 | ; |
3635 | |
3840 | |
3636 | } else { |
3841 | } else { |
3637 | $widget = new CFPlus::UI::Label |
3842 | $widget = new CFPlus::UI::Label |
3638 | can_hover => 1, |
3843 | can_hover => 1, |
3639 | can_events => 1, |
3844 | can_events => 1, |
3640 | markup => $widget, |
3845 | markup => $widget, |
… | |
… | |
3765 | |
3970 | |
3766 | ############################################################################# |
3971 | ############################################################################# |
3767 | |
3972 | |
3768 | package CFPlus::UI::Notebook; |
3973 | package CFPlus::UI::Notebook; |
3769 | |
3974 | |
|
|
3975 | use CFPlus::OpenGL; |
|
|
3976 | |
3770 | our @ISA = CFPlus::UI::VBox::; |
3977 | our @ISA = CFPlus::UI::VBox::; |
3771 | |
3978 | |
3772 | sub new { |
3979 | sub new { |
3773 | my $class = shift; |
3980 | my $class = shift; |
3774 | |
3981 | |
3775 | my $self = $class->SUPER::new ( |
3982 | my $self = $class->SUPER::new ( |
3776 | buttonbar => (new CFPlus::UI::Buttonbar), |
3983 | buttonbar => (new CFPlus::UI::Buttonbar), |
3777 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3984 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
|
|
3985 | active_outline => [.7, .7, 0.2], |
3778 | # filter => # will be put between multiplexer and $self |
3986 | # filter => # will be put between multiplexer and $self |
3779 | @_, |
3987 | @_, |
3780 | ); |
3988 | ); |
3781 | |
3989 | |
3782 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3990 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3783 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3991 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3784 | |
3992 | |
|
|
3993 | { |
|
|
3994 | Scalar::Util::weaken (my $wself = $self); |
|
|
3995 | |
|
|
3996 | $self->{multiplexer}->connect (c_add => sub { |
|
|
3997 | my ($mplex, $widgets) = @_; |
|
|
3998 | |
|
|
3999 | for my $child (@$widgets) { |
|
|
4000 | Scalar::Util::weaken $child; |
|
|
4001 | $child->{c_tab_} ||= do { |
|
|
4002 | my $tab = |
|
|
4003 | (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") |
|
|
4004 | ? $child->{c_tab} |
|
|
4005 | : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
|
|
4006 | |
|
|
4007 | $tab->connect (activate => sub { |
|
|
4008 | $wself->set_current_page ($child); |
|
|
4009 | }); |
|
|
4010 | |
|
|
4011 | $tab |
|
|
4012 | }; |
|
|
4013 | |
|
|
4014 | $self->{buttonbar}->add ($child->{c_tab_}); |
|
|
4015 | } |
|
|
4016 | }); |
|
|
4017 | |
|
|
4018 | $self->{multiplexer}->connect (c_remove => sub { |
|
|
4019 | my ($mplex, $widgets) = @_; |
|
|
4020 | |
|
|
4021 | for my $child (@$widgets) { |
|
|
4022 | $wself->{buttonbar}->remove ($child->{c_tab_}); |
|
|
4023 | } |
|
|
4024 | }); |
|
|
4025 | } |
|
|
4026 | |
3785 | $self |
4027 | $self |
3786 | } |
4028 | } |
3787 | |
4029 | |
3788 | sub add { |
4030 | sub add { |
|
|
4031 | my ($self, @widgets) = @_; |
|
|
4032 | |
|
|
4033 | $self->{multiplexer}->add (@widgets) |
|
|
4034 | } |
|
|
4035 | |
|
|
4036 | sub remove { |
|
|
4037 | my ($self, @widgets) = @_; |
|
|
4038 | |
|
|
4039 | $self->{multiplexer}->remove (@widgets) |
|
|
4040 | } |
|
|
4041 | |
|
|
4042 | sub pages { |
|
|
4043 | my ($self) = @_; |
|
|
4044 | $self->{multiplexer}->children |
|
|
4045 | } |
|
|
4046 | |
|
|
4047 | sub add_tab { |
3789 | my ($self, $title, $widget, $tooltip) = @_; |
4048 | my ($self, $title, $widget, $tooltip) = @_; |
3790 | |
4049 | |
3791 | CFPlus::weaken $self; |
4050 | $title = [$title, $tooltip] unless ref $title; |
|
|
4051 | $widget->{c_tab} = $title; |
3792 | |
4052 | |
3793 | $self->{buttonbar}->add (new CFPlus::UI::Button |
|
|
3794 | markup => $title, |
|
|
3795 | tooltip => $tooltip, |
|
|
3796 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3797 | ); |
|
|
3798 | |
|
|
3799 | $self->{multiplexer}->add ($widget); |
4053 | $self->add ($widget); |
3800 | } |
4054 | } |
3801 | |
4055 | |
3802 | sub get_current_page { |
4056 | sub get_current_page { |
3803 | my ($self) = @_; |
4057 | my ($self) = @_; |
3804 | |
4058 | |
… | |
… | |
3808 | sub set_current_page { |
4062 | sub set_current_page { |
3809 | my ($self, $page) = @_; |
4063 | my ($self, $page) = @_; |
3810 | |
4064 | |
3811 | $self->{multiplexer}->set_current_page ($page); |
4065 | $self->{multiplexer}->set_current_page ($page); |
3812 | $self->emit (page_changed => $self->{multiplexer}{current}); |
4066 | $self->emit (page_changed => $self->{multiplexer}{current}); |
|
|
4067 | } |
|
|
4068 | |
|
|
4069 | sub _draw { |
|
|
4070 | my ($self) = @_; |
|
|
4071 | |
|
|
4072 | $self->SUPER::_draw (); |
|
|
4073 | |
|
|
4074 | if (my $cur = $self->{multiplexer}{current}) { |
|
|
4075 | if ($cur = $cur->{c_tab_}) { |
|
|
4076 | glTranslate $self->{buttonbar}{x} + $cur->{x}, |
|
|
4077 | $self->{buttonbar}{y} + $cur->{y}; |
|
|
4078 | glLineWidth 3; |
|
|
4079 | #glEnable GL_BLEND; |
|
|
4080 | #glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
4081 | glColor @{$self->{active_outline}}; |
|
|
4082 | glRect_lineloop 1.5, 1.5, $cur->{w} - 1.5, $cur->{h} - 1.5; |
|
|
4083 | glLineWidth 1; |
|
|
4084 | #glDisable GL_BLEND; |
|
|
4085 | } |
|
|
4086 | } |
3813 | } |
4087 | } |
3814 | |
4088 | |
3815 | ############################################################################# |
4089 | ############################################################################# |
3816 | |
4090 | |
3817 | package CFPlus::UI::Selector; |
4091 | package CFPlus::UI::Selector; |
… | |
… | |
3849 | } |
4123 | } |
3850 | |
4124 | |
3851 | sub _set_value { |
4125 | sub _set_value { |
3852 | my ($self, $value) = @_; |
4126 | my ($self, $value) = @_; |
3853 | |
4127 | |
3854 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} } |
4128 | my ($item) = grep $_->[0] eq $value, @{ $self->{options} }; |
|
|
4129 | $item ||= $self->{options}[0] |
3855 | or return; |
4130 | or return; |
3856 | |
4131 | |
3857 | $self->{value} = $item->[0]; |
4132 | $self->{value} = $item->[0]; |
3858 | $self->set_markup ("$item->[1] ⇓"); |
4133 | $self->set_markup ("$item->[1] ⇓"); |
3859 | $self->set_tooltip ($item->[2]); |
4134 | # $self->set_tooltip ($item->[2]); |
3860 | } |
4135 | } |
3861 | |
4136 | |
3862 | sub set_value { |
4137 | sub set_value { |
3863 | my ($self, $value) = @_; |
4138 | my ($self, $value) = @_; |
3864 | |
4139 | |
3865 | return unless $self->{value} ne $value; |
4140 | return unless $self->{value} ne $value; |
3866 | |
4141 | |
3867 | $self->_set_value ($value); |
4142 | $self->_set_value ($value); |
3868 | $self->emit (changed => $value); |
4143 | $self->emit (changed => $value); |
|
|
4144 | } |
|
|
4145 | |
|
|
4146 | sub set_options { |
|
|
4147 | my ($self, $options) = @_; |
|
|
4148 | |
|
|
4149 | $self->{options} = $options; |
|
|
4150 | $self->_set_value ($self->{value}); |
3869 | } |
4151 | } |
3870 | |
4152 | |
3871 | ############################################################################# |
4153 | ############################################################################# |
3872 | |
4154 | |
3873 | package CFPlus::UI::Statusbox; |
4155 | package CFPlus::UI::Statusbox; |
… | |
… | |
3882 | @_, |
4164 | @_, |
3883 | ); |
4165 | ); |
3884 | |
4166 | |
3885 | CFPlus::weaken (my $this = $self); |
4167 | CFPlus::weaken (my $this = $self); |
3886 | |
4168 | |
3887 | $self->{timer} = Event->timer (after => 1, interval => 1, cb => sub { $this->reorder }); |
4169 | $self->{timer} = EV::timer 1, 1, sub { $this->reorder }; |
3888 | |
4170 | |
3889 | $self |
4171 | $self |
3890 | } |
4172 | } |
3891 | |
4173 | |
3892 | sub reorder { |
4174 | sub reorder { |
… | |
… | |
3900 | |
4182 | |
3901 | while (my ($k, $v) = each %{ $self->{item} }) { |
4183 | while (my ($k, $v) = each %{ $self->{item} }) { |
3902 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
4184 | delete $self->{item}{$k} if $v->{timeout} < $NOW; |
3903 | } |
4185 | } |
3904 | |
4186 | |
|
|
4187 | $self->{timer}->set (1, 1); |
|
|
4188 | |
3905 | my @widgets; |
4189 | my @widgets; |
3906 | |
4190 | |
3907 | my @items = sort { |
4191 | my @items = sort { |
3908 | $a->{pri} <=> $b->{pri} |
4192 | $a->{pri} <=> $b->{pri} |
3909 | or $b->{id} <=> $a->{id} |
4193 | or $b->{id} <=> $a->{id} |
3910 | } values %{ $self->{item} }; |
4194 | } values %{ $self->{item} }; |
3911 | |
|
|
3912 | $self->{timer}->interval (1); |
|
|
3913 | |
4195 | |
3914 | my $count = 10 + 1; |
4196 | my $count = 10 + 1; |
3915 | for my $item (@items) { |
4197 | for my $item (@items) { |
3916 | last unless --$count; |
4198 | last unless --$count; |
3917 | |
4199 | |
… | |
… | |
3941 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
4223 | if ((my $diff = $item->{timeout} - $NOW) < 2) { |
3942 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
4224 | $label->{fg}[3] = ($item->{fg}[3] || 1) * $diff / 2; |
3943 | $label->update; |
4225 | $label->update; |
3944 | $label->set_max_size (undef, $label->{req_h} * $diff) |
4226 | $label->set_max_size (undef, $label->{req_h} * $diff) |
3945 | if $diff < 1; |
4227 | if $diff < 1; |
3946 | $self->{timer}->interval (1/30); |
4228 | $self->{timer}->set (1/30, 1/30); |
3947 | } else { |
4229 | } else { |
3948 | $label->{fg}[3] = $item->{fg}[3] || 1; |
4230 | $label->{fg}[3] = $item->{fg}[3] || 1; |
3949 | } |
4231 | } |
3950 | |
4232 | |
3951 | push @widgets, $label; |
4233 | push @widgets, $label; |
… | |
… | |
4087 | } |
4369 | } |
4088 | |
4370 | |
4089 | sub update { |
4371 | sub update { |
4090 | my ($self) = @_; |
4372 | my ($self) = @_; |
4091 | |
4373 | |
4092 | $::WANT_REFRESH++; |
4374 | $::WANT_REFRESH->start; |
4093 | } |
4375 | } |
4094 | |
4376 | |
4095 | sub add { |
4377 | sub add { |
4096 | my ($self, @children) = @_; |
4378 | my ($self, @children) = @_; |
4097 | |
4379 | |
… | |
… | |
4134 | while ($self->{refresh_hook}) { |
4416 | while ($self->{refresh_hook}) { |
4135 | $_->() |
4417 | $_->() |
4136 | for values %{delete $self->{refresh_hook}}; |
4418 | for values %{delete $self->{refresh_hook}}; |
4137 | } |
4419 | } |
4138 | |
4420 | |
4139 | if ($self->{realloc}) { |
4421 | while ($self->{realloc}) { |
4140 | my %queue; |
4422 | my %queue; |
4141 | my @queue; |
4423 | my @queue; |
4142 | my $widget; |
4424 | my $widget; |
4143 | |
4425 | |
4144 | outer: |
4426 | outer: |
… | |
… | |
4191 | } |
4473 | } |
4192 | } |
4474 | } |
4193 | |
4475 | |
4194 | delete $self->{realloc}{$widget+0}; |
4476 | delete $self->{realloc}{$widget+0}; |
4195 | } |
4477 | } |
4196 | } |
|
|
4197 | |
4478 | |
4198 | while (my $size_alloc = delete $self->{size_alloc}) { |
4479 | while (my $size_alloc = delete $self->{size_alloc}) { |
4199 | my @queue = sort { $b->{visible} <=> $a->{visible} } |
4480 | my @queue = sort { $a->{visible} <=> $b->{visible} } |
4200 | values %$size_alloc; |
4481 | values %$size_alloc; |
4201 | |
4482 | |
4202 | while () { |
4483 | while () { |
4203 | my $widget = pop @queue || last; |
4484 | my $widget = pop @queue || last; |
4204 | |
4485 | |
4205 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4486 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4206 | |
4487 | |
4207 | $w = 0 if $w < 0; |
|
|
4208 | $h = 0 if $h < 0; |
|
|
4209 | |
|
|
4210 | $w = max $widget->{min_w}, $w; |
4488 | $w = max $widget->{min_w}, $w; |
4211 | $h = max $widget->{min_h}, $h; |
4489 | $h = max $widget->{min_h}, $h; |
4212 | |
4490 | |
4213 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4491 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4214 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4492 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4215 | |
4493 | |
4216 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4494 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4217 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4495 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4218 | |
4496 | |
4219 | $w = int $w + 0.5; |
4497 | $w = int $w + 0.5; |
4220 | $h = int $h + 0.5; |
4498 | $h = int $h + 0.5; |
4221 | |
4499 | |
4222 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4500 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4223 | $widget->{old_w} = $widget->{w}; |
4501 | $widget->{old_w} = $widget->{w}; |
4224 | $widget->{old_h} = $widget->{h}; |
4502 | $widget->{old_h} = $widget->{h}; |
4225 | |
4503 | |
4226 | $widget->{w} = $w; |
4504 | $widget->{w} = $w; |
4227 | $widget->{h} = $h; |
4505 | $widget->{h} = $h; |
4228 | |
4506 | |
4229 | $widget->emit (size_allocate => $w, $h); |
4507 | $widget->emit (size_allocate => $w, $h); |
|
|
4508 | } |
4230 | } |
4509 | } |
4231 | } |
4510 | } |
4232 | } |
4511 | } |
4233 | |
4512 | |
4234 | while ($self->{post_alloc_hook}) { |
4513 | while ($self->{post_alloc_hook}) { |