… | |
… | |
113 | } |
113 | } |
114 | |
114 | |
115 | if ($GRAB) { |
115 | if ($GRAB) { |
116 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
116 | if ($ev->{button} == 4 || $ev->{button} == 5) { |
117 | # mousewheel |
117 | # mousewheel |
118 | $ev->{dx} = 0; |
|
|
119 | $ev->{dy} = $ev->{button} * 2 - 9; |
118 | my $delta = $ev->{button} * 2 - 9; |
|
|
119 | my $shift = $ev->{mod} & CFPlus::KMOD_SHIFT; |
|
|
120 | |
|
|
121 | $ev->{dx} = $shift ? $delta : 0; |
|
|
122 | $ev->{dy} = $shift ? 0 : $delta; |
|
|
123 | |
120 | $GRAB->emit (mouse_wheel => $ev); |
124 | $GRAB->emit (mouse_wheel => $ev); |
121 | } else { |
125 | } else { |
122 | $GRAB->emit (button_down => $ev) |
126 | $GRAB->emit (button_down => $ev) |
123 | } |
127 | } |
124 | } |
128 | } |
… | |
… | |
269 | $self->emit ("destroy"); |
273 | $self->emit ("destroy"); |
270 | %$self = (); |
274 | %$self = (); |
271 | } |
275 | } |
272 | |
276 | |
273 | sub TO_JSON { |
277 | sub TO_JSON { |
274 | { __widget_ref__ => $_[0]{s_id} } |
278 | { __w_ => $_[0]{s_id} } |
275 | } |
279 | } |
276 | |
280 | |
277 | sub show { |
281 | sub show { |
278 | my ($self) = @_; |
282 | my ($self) = @_; |
279 | |
283 | |
… | |
… | |
547 | |
551 | |
548 | # parent |
552 | # parent |
549 | $self->{parent} && $self->{parent}->emit ($signal, @args) |
553 | $self->{parent} && $self->{parent}->emit ($signal, @args) |
550 | } |
554 | } |
551 | |
555 | |
552 | sub find_widget { |
556 | #sub find_widget { |
553 | my ($self, $x, $y) = @_; |
557 | # in .xs |
554 | |
|
|
555 | return () unless $self->{can_events}; |
|
|
556 | |
|
|
557 | return $self |
|
|
558 | if $x >= $self->{x} && $x < $self->{x} + $self->{w} |
|
|
559 | && $y >= $self->{y} && $y < $self->{y} + $self->{h}; |
|
|
560 | |
|
|
561 | () |
|
|
562 | } |
|
|
563 | |
558 | |
564 | sub set_parent { |
559 | sub set_parent { |
565 | my ($self, $parent) = @_; |
560 | my ($self, $parent) = @_; |
566 | |
561 | |
567 | CFPlus::weaken ($self->{parent} = $parent); |
562 | CFPlus::weaken ($self->{parent} = $parent); |
… | |
… | |
598 | |
593 | |
599 | # using global variables seems a bit hacky, but passing through all drawing |
594 | # using global variables seems a bit hacky, but passing through all drawing |
600 | # functions seems pointless. |
595 | # functions seems pointless. |
601 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
596 | our ($draw_x, $draw_y, $draw_w, $draw_h); # screen rectangle being drawn |
602 | |
597 | |
603 | sub draw { |
598 | #sub draw { |
604 | my ($self) = @_; |
599 | #CFPlus.xs |
605 | |
|
|
606 | return unless $self->{h} && $self->{w}; |
|
|
607 | |
|
|
608 | # update screen rectangle |
|
|
609 | local $draw_x = $draw_x + $self->{x}; |
|
|
610 | local $draw_y = $draw_y + $self->{y}; |
|
|
611 | |
|
|
612 | # skip widgets that are entirely outside the drawing area |
|
|
613 | return if ($draw_x + $self->{w} < 0) || ($draw_x >= $draw_w) |
|
|
614 | || ($draw_y + $self->{h} < 0) || ($draw_y >= $draw_h); |
|
|
615 | |
|
|
616 | glPushMatrix; |
|
|
617 | glTranslate $self->{x}, $self->{y}, 0; |
|
|
618 | |
|
|
619 | if ($self == $HOVER && $self->{can_hover}) { |
|
|
620 | glColor 1*0.2, 0.8*0.2, 0.5*0.2, 0.2; |
|
|
621 | glEnable GL_BLEND; |
|
|
622 | glBlendFunc GL_ONE, GL_ONE_MINUS_SRC_ALPHA; |
|
|
623 | glBegin GL_QUADS; |
|
|
624 | glVertex 0 , 0; |
|
|
625 | glVertex $self->{w}, 0; |
|
|
626 | glVertex $self->{w}, $self->{h}; |
|
|
627 | glVertex 0 , $self->{h}; |
|
|
628 | glEnd; |
|
|
629 | glDisable GL_BLEND; |
|
|
630 | } |
|
|
631 | |
|
|
632 | if ($ENV{CFPLUS_DEBUG} & 1) { |
|
|
633 | glPushMatrix; |
|
|
634 | glColor 1, 1, 0, 1; |
|
|
635 | glTranslate 0.375, 0.375; |
|
|
636 | glBegin GL_LINE_LOOP; |
|
|
637 | glVertex 0 , 0; |
|
|
638 | glVertex $self->{w} - 1, 0; |
|
|
639 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
640 | glVertex 0 , $self->{h} - 1; |
|
|
641 | glEnd; |
|
|
642 | glPopMatrix; |
|
|
643 | #CFPlus::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
|
|
644 | } |
|
|
645 | |
|
|
646 | $self->_draw; |
|
|
647 | glPopMatrix; |
|
|
648 | } |
|
|
649 | |
600 | |
650 | sub _draw { |
601 | sub _draw { |
651 | my ($self) = @_; |
602 | my ($self) = @_; |
652 | |
603 | |
653 | warn "no draw defined for $self\n"; |
604 | warn "no draw defined for $self\n"; |
654 | } |
605 | } |
655 | |
606 | |
656 | my $cntx;#d# |
|
|
657 | sub DESTROY { |
607 | sub DESTROY { |
658 | my ($self) = @_; |
608 | my ($self) = @_; |
659 | |
609 | |
660 | return if CFPlus::in_destruct; |
610 | return if CFPlus::in_destruct; |
661 | |
611 | |
… | |
… | |
746 | can_events => 0, |
696 | can_events => 0, |
747 | %arg, |
697 | %arg, |
748 | ); |
698 | ); |
749 | |
699 | |
750 | $self->add (@$children) |
700 | $self->add (@$children) |
751 | if $children; |
701 | if $children && @$children; |
752 | |
702 | |
753 | $self |
703 | $self |
754 | } |
704 | } |
755 | |
705 | |
756 | sub realloc { |
706 | sub realloc { |
… | |
… | |
765 | my ($self, @widgets) = @_; |
715 | my ($self, @widgets) = @_; |
766 | |
716 | |
767 | $_->set_parent ($self) |
717 | $_->set_parent ($self) |
768 | for @widgets; |
718 | for @widgets; |
769 | |
719 | |
|
|
720 | # TODO: only do this in widgets that need it, e.g. root, fixed |
770 | use sort 'stable'; |
721 | use sort 'stable'; |
771 | |
722 | |
772 | $self->{children} = [ |
723 | $self->{children} = [ |
773 | sort { $a->{z} <=> $b->{z} } |
724 | sort { $a->{z} <=> $b->{z} } |
774 | @{$self->{children}}, @widgets |
725 | @{$self->{children}}, @widgets |
775 | ]; |
726 | ]; |
776 | |
727 | |
777 | $self->realloc; |
728 | $self->realloc; |
|
|
729 | |
|
|
730 | $self->emit (c_add => \@widgets); |
|
|
731 | |
|
|
732 | map $_+0, @widgets |
778 | } |
733 | } |
779 | |
734 | |
780 | sub children { |
735 | sub children { |
781 | @{ $_[0]{children} } |
736 | @{ $_[0]{children} } |
782 | } |
737 | } |
783 | |
738 | |
784 | sub remove { |
739 | sub remove { |
785 | my ($self, $child) = @_; |
740 | my ($self, @widgets) = @_; |
786 | |
741 | |
|
|
742 | $self->emit (c_remove => \@widgets); |
|
|
743 | |
|
|
744 | for my $child (@widgets) { |
787 | delete $child->{parent}; |
745 | delete $child->{parent}; |
788 | $child->hide; |
746 | $child->hide; |
789 | |
|
|
790 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
747 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
|
|
748 | } |
791 | |
749 | |
792 | $self->realloc; |
750 | $self->realloc; |
793 | } |
751 | } |
794 | |
752 | |
795 | sub clear { |
753 | sub clear { |
796 | my ($self) = @_; |
754 | my ($self) = @_; |
797 | |
755 | |
798 | my $children = delete $self->{children}; |
756 | my $children = $self->{children}; |
799 | $self->{children} = []; |
757 | $self->{children} = []; |
800 | |
758 | |
801 | for (@$children) { |
759 | for (@$children) { |
802 | delete $_->{parent}; |
760 | delete $_->{parent}; |
803 | $_->hide; |
761 | $_->hide; |
… | |
… | |
823 | } |
781 | } |
824 | |
782 | |
825 | sub _draw { |
783 | sub _draw { |
826 | my ($self) = @_; |
784 | my ($self) = @_; |
827 | |
785 | |
828 | $_->draw for @{$self->{children}}; |
786 | $_->draw for $self->visible_children; |
829 | } |
787 | } |
830 | |
788 | |
831 | ############################################################################# |
789 | ############################################################################# |
832 | |
790 | |
833 | package CFPlus::UI::Bin; |
791 | package CFPlus::UI::Bin; |
… | |
… | |
843 | } |
801 | } |
844 | |
802 | |
845 | sub add { |
803 | sub add { |
846 | my ($self, $child) = @_; |
804 | my ($self, $child) = @_; |
847 | |
805 | |
848 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
806 | $self->clear; |
849 | $self->SUPER::add ($child); |
807 | $self->SUPER::add ($child); |
850 | } |
808 | } |
851 | |
809 | |
852 | sub remove { |
810 | sub remove { |
853 | my ($self, $widget) = @_; |
811 | my ($self, $widget) = @_; |
… | |
… | |
963 | sub size_request { |
921 | sub size_request { |
964 | my ($self) = @_; |
922 | my ($self) = @_; |
965 | |
923 | |
966 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
924 | my ($w, $h) = @{$self->child}{qw(req_w req_h)}; |
967 | |
925 | |
968 | $w = 10 if $self->{scroll_x}; |
926 | $w = 1 if $self->{scroll_x}; |
969 | $h = 10 if $self->{scroll_y}; |
927 | $h = 1 if $self->{scroll_y}; |
970 | |
928 | |
971 | ($w, $h) |
929 | ($w, $h) |
972 | } |
930 | } |
973 | |
931 | |
974 | sub invoke_size_allocate { |
932 | sub invoke_size_allocate { |
… | |
… | |
986 | } |
944 | } |
987 | |
945 | |
988 | sub set_offset { |
946 | sub set_offset { |
989 | my ($self, $x, $y) = @_; |
947 | my ($self, $x, $y) = @_; |
990 | |
948 | |
991 | $self->{view_x} = max 0, min $self->child->{w} - $self->{w}, int $x; |
949 | my $x = max 0, min $self->child->{w} - $self->{w}, int $x; |
992 | $self->{view_y} = max 0, min $self->child->{h} - $self->{h}, int $y; |
950 | my $y = max 0, min $self->child->{h} - $self->{h}, int $y; |
993 | |
951 | |
994 | $self->emit (changed => $self->{view_x}, $self->{view_y}); |
952 | if ($x != $self->{view_x} or $y != $self->{view_y}) { |
|
|
953 | $self->{view_x} = $x; |
|
|
954 | $self->{view_y} = $y; |
|
|
955 | |
|
|
956 | $self->emit (changed => $x, $y); |
995 | $self->update; |
957 | $self->update; |
|
|
958 | } |
|
|
959 | } |
|
|
960 | |
|
|
961 | sub set_center { |
|
|
962 | my ($self, $x, $y) = @_; |
|
|
963 | |
|
|
964 | $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5); |
|
|
965 | } |
|
|
966 | |
|
|
967 | sub make_visible { |
|
|
968 | my ($self, $x, $y, $border) = @_; |
|
|
969 | |
|
|
970 | if ( $x < $self->{view_x} + $self->{w} * $border |
|
|
971 | || $x > $self->{view_x} + $self->{w} * (1 - $border) |
|
|
972 | || $y < $self->{view_y} + $self->{h} * $border |
|
|
973 | || $y > $self->{view_y} + $self->{h} * (1 - $border) |
|
|
974 | ) { |
|
|
975 | $self->set_center ($x, $y); |
|
|
976 | } |
996 | } |
977 | } |
997 | |
978 | |
998 | # hmm, this does not work for topleft of $self... but we should not ask for that |
979 | # hmm, this does not work for topleft of $self... but we should not ask for that |
999 | sub coord2local { |
980 | sub coord2local { |
1000 | my ($self, $x, $y) = @_; |
981 | my ($self, $x, $y) = @_; |
… | |
… | |
1015 | my ($self, $x, $y) = @_; |
996 | my ($self, $x, $y) = @_; |
1016 | |
997 | |
1017 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
998 | if ( $x >= $self->{x} && $x < $self->{x} + $self->{w} |
1018 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
999 | && $y >= $self->{y} && $y < $self->{y} + $self->{h} |
1019 | ) { |
1000 | ) { |
1020 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1001 | $self->child->find_widget ($x + $self->{view_x}, $y + $self->{view_y}) |
1021 | } else { |
1002 | } else { |
1022 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
1003 | $self->CFPlus::UI::Base::find_widget ($x, $y) |
1023 | } |
1004 | } |
1024 | } |
1005 | } |
1025 | |
1006 | |
… | |
… | |
1046 | my $child = delete $arg{child}; |
1027 | my $child = delete $arg{child}; |
1047 | |
1028 | |
1048 | my $self; |
1029 | my $self; |
1049 | |
1030 | |
1050 | my $hslider = new CFPlus::UI::Slider |
1031 | my $hslider = new CFPlus::UI::Slider |
|
|
1032 | col => 0, |
|
|
1033 | row => 1, |
1051 | vertical => 0, |
1034 | vertical => 0, |
1052 | range => [0, 0, 1, 0.01], # HACK fix |
1035 | range => [0, 0, 1, 0.01], # HACK fix |
1053 | on_changed => sub { |
1036 | on_changed => sub { |
1054 | $self->{hpos} = $_[1]; |
1037 | $self->{hpos} = $_[1]; |
1055 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1038 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1056 | }, |
1039 | }, |
1057 | ; |
1040 | ; |
1058 | |
1041 | |
1059 | my $vslider = new CFPlus::UI::Slider |
1042 | my $vslider = new CFPlus::UI::Slider |
|
|
1043 | col => 1, |
|
|
1044 | row => 0, |
1060 | vertical => 1, |
1045 | vertical => 1, |
1061 | range => [0, 0, 1, 0.01], # HACK fix |
1046 | range => [0, 0, 1, 0.01], # HACK fix |
1062 | on_changed => sub { |
1047 | on_changed => sub { |
1063 | $self->{vpos} = $_[1]; |
1048 | $self->{vpos} = $_[1]; |
1064 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
1049 | $self->{vp}->set_offset ($self->{hpos}, $self->{vpos}); |
… | |
… | |
1075 | row_expand => [1, 0], |
1060 | row_expand => [1, 0], |
1076 | %arg, |
1061 | %arg, |
1077 | ); |
1062 | ); |
1078 | |
1063 | |
1079 | $self->{vp} = new CFPlus::UI::ViewPort |
1064 | $self->{vp} = new CFPlus::UI::ViewPort |
|
|
1065 | col => 0, |
|
|
1066 | row => 0, |
1080 | expand => 1, |
1067 | expand => 1, |
1081 | scroll_x => $self->{scroll_x}, |
1068 | scroll_x => $self->{scroll_x}, |
1082 | scroll_y => $self->{scroll_y}, |
1069 | scroll_y => $self->{scroll_y}, |
1083 | on_changed => sub { |
1070 | on_changed => sub { |
1084 | my ($vp, $x, $y) = @_; |
1071 | my ($vp, $x, $y) = @_; |
… | |
… | |
1086 | $vp->{parent}{hslider}->set_value ($x); |
1073 | $vp->{parent}{hslider}->set_value ($x); |
1087 | $vp->{parent}{vslider}->set_value ($y); |
1074 | $vp->{parent}{vslider}->set_value ($y); |
1088 | |
1075 | |
1089 | 0 |
1076 | 0 |
1090 | }, |
1077 | }, |
|
|
1078 | on_size_allocate => sub { |
|
|
1079 | my ($vp, $w, $h) = @_; |
|
|
1080 | $vp->{parent}->update_slider; |
|
|
1081 | 0 |
|
|
1082 | }, |
1091 | ; |
1083 | ; |
1092 | |
1084 | |
1093 | $self->SUPER::add (0, 0, $self->{vp}); |
1085 | $self->SUPER::add ($self->{vp}); |
1094 | |
1086 | |
1095 | $self->add ($child) if $child; |
1087 | $self->add ($child) if $child; |
1096 | |
1088 | |
1097 | $self |
1089 | $self |
1098 | } |
1090 | } |
1099 | |
|
|
1100 | #TODO# update range on size_allocate depending on child |
|
|
1101 | |
1091 | |
1102 | sub add { |
1092 | sub add { |
1103 | my ($self, $widget) = @_; |
1093 | my ($self, $widget) = @_; |
1104 | |
1094 | |
1105 | $self->{vp}->add ($self->{child} = $widget); |
1095 | $self->{vp}->add ($self->{child} = $widget); |
1106 | } |
1096 | } |
1107 | |
1097 | |
|
|
1098 | sub set_offset { shift->{vp}->set_offset (@_) } |
|
|
1099 | sub set_center { shift->{vp}->set_center (@_) } |
|
|
1100 | sub make_visible { shift->{vp}->make_visible (@_) } |
|
|
1101 | |
1108 | sub update_slider { |
1102 | sub update_slider { |
1109 | my ($self) = @_; |
1103 | my ($self) = @_; |
1110 | |
1104 | |
1111 | my $child = ($self->{vp} or return)->child; |
1105 | my $child = ($self->{vp} or return)->child; |
1112 | |
1106 | |
|
|
1107 | if ($self->{scroll_x}) { |
1113 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
1108 | my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w}); |
1114 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1109 | $self->{hslider}->set_range ([$self->{hslider}{range}[0], 0, $w1, $w2, 1]); |
1115 | |
1110 | |
1116 | my $visible = $w1 > $w2; |
1111 | my $visible = $w1 > $w2; |
1117 | if ($visible != $self->{hslider}{visible}) { |
1112 | if ($visible != $self->{hslider_visible}) { |
|
|
1113 | $self->{hslider_visible} = $visible; |
1118 | $visible ? $self->SUPER::add (0, 1, $self->{hslider}) |
1114 | $visible ? $self->SUPER::add ($self->{hslider}) |
1119 | : $self->{hslider}->hide; |
1115 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1116 | } |
1120 | } |
1117 | } |
1121 | |
1118 | |
|
|
1119 | if ($self->{scroll_y}) { |
1122 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
1120 | my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h}); |
1123 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1121 | $self->{vslider}->set_range ([$self->{vslider}{range}[0], 0, $h1, $h2, 1]); |
1124 | |
1122 | |
1125 | my $visible = $h1 > $h2; |
1123 | my $visible = $h1 > $h2; |
1126 | if ($visible != $self->{vslider}{visible}) { |
1124 | if ($visible != $self->{vslider_visible}) { |
|
|
1125 | $self->{vslider_visible} = $visible; |
1127 | $visible ? $self->SUPER::add (1, 0, $self->{vslider}) |
1126 | $visible ? $self->SUPER::add ($self->{vslider}) |
1128 | : $self->{vslider}->hide; |
1127 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1128 | } |
|
|
1129 | } |
|
|
1130 | } |
|
|
1131 | |
|
|
1132 | sub start_dragging { |
|
|
1133 | my ($self, $ev) = @_; |
|
|
1134 | |
|
|
1135 | $self->grab_focus; |
|
|
1136 | |
|
|
1137 | my $ox = $self->{vp}{view_x}; |
|
|
1138 | my $oy = $self->{vp}{view_y}; |
|
|
1139 | |
|
|
1140 | $self->{motion} = sub { |
|
|
1141 | my ($ev, $x, $y) = @_; |
|
|
1142 | |
|
|
1143 | $ox -= $ev->{xrel}; |
|
|
1144 | $oy -= $ev->{yrel}; |
|
|
1145 | |
|
|
1146 | $self->{vp}->set_offset ($ox, $oy); |
1129 | } |
1147 | }; |
1130 | } |
|
|
1131 | |
|
|
1132 | sub update { |
|
|
1133 | my ($self) = @_; |
|
|
1134 | |
|
|
1135 | $self->SUPER::update; |
|
|
1136 | $self->update_slider; |
|
|
1137 | } |
1148 | } |
1138 | |
1149 | |
1139 | sub invoke_mouse_wheel { |
1150 | sub invoke_mouse_wheel { |
1140 | my ($self, $ev) = @_; |
1151 | my ($self, $ev) = @_; |
1141 | |
1152 | |
1142 | return 0 unless $ev->{dy}; # only vertical movements for now |
|
|
1143 | |
|
|
1144 | $self->{vslider}->emit (mouse_wheel => $ev); |
1153 | $self->{vslider}->emit (mouse_wheel => $ev) if $self->{vslider_visible}; |
|
|
1154 | $self->{hslider}->emit (mouse_wheel => $ev) if $self->{hslider_visible}; |
1145 | |
1155 | |
1146 | 1 |
1156 | 1 |
1147 | } |
1157 | } |
1148 | |
1158 | |
1149 | sub invoke_button_down { |
1159 | sub invoke_button_down { |
1150 | my ($self, $ev, $x, $y) = @_; |
1160 | my ($self, $ev, $x, $y) = @_; |
1151 | |
1161 | |
1152 | if ($ev->{button} == 2) { |
1162 | if ($ev->{button} == 2) { |
1153 | $self->grab_focus; |
1163 | $self->start_dragging ($ev); |
1154 | |
|
|
1155 | my $ox = $self->{vp}{view_x} + $ev->{x}; |
|
|
1156 | my $oy = $self->{vp}{view_y} + $ev->{y}; |
|
|
1157 | |
|
|
1158 | $self->{motion} = sub { |
|
|
1159 | my ($ev, $x, $y) = @_; |
|
|
1160 | |
|
|
1161 | $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y}); |
|
|
1162 | $self->update; |
|
|
1163 | }; |
|
|
1164 | |
|
|
1165 | return 1; |
1164 | return 1; |
1166 | } |
1165 | } |
1167 | |
1166 | |
1168 | 0 |
1167 | 0 |
1169 | } |
1168 | } |
… | |
… | |
1350 | |
1349 | |
1351 | my @border = |
1350 | my @border = |
1352 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1351 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
1353 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1352 | qw(d1_border_top.png d1_border_right.png d1_border_left.png d1_border_bottom.png); |
1354 | |
1353 | |
|
|
1354 | my @icon = |
|
|
1355 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
1356 | qw(x1_move.png x1_resize.png); |
|
|
1357 | |
1355 | sub new { |
1358 | sub new { |
1356 | my ($class, %arg) = @_; |
1359 | my ($class, %arg) = @_; |
1357 | |
1360 | |
1358 | my $self = $class->SUPER::new ( |
1361 | my $self = $class->SUPER::new ( |
1359 | bg => [1, 1, 1, 1], |
1362 | bg => [1, 1, 1, 1], |
… | |
… | |
1527 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1530 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
1528 | |
1531 | |
1529 | my $border = $self->border; |
1532 | my $border = $self->border; |
1530 | |
1533 | |
1531 | glColor @{ $self->{border_bg} }; |
1534 | glColor @{ $self->{border_bg} }; |
1532 | $border[0]->draw_quad_alpha (0, 0, $w, $border); |
1535 | $border[0]->draw_quad_alpha ( 0, 0, $w, $border); |
1533 | $border[1]->draw_quad_alpha (0, $border, $border, $ch); |
1536 | $border[1]->draw_quad_alpha ( 0, $border, $border, $ch); |
1534 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1537 | $border[2]->draw_quad_alpha ($w - $border, $border, $border, $ch); |
1535 | $border[3]->draw_quad_alpha (0, $h - $border, $w, $border); |
1538 | $border[3]->draw_quad_alpha ( 0, $h - $border, $w, $border); |
|
|
1539 | |
|
|
1540 | # move |
|
|
1541 | my $w2 = ($w - $border) * .5; |
|
|
1542 | my $h2 = ($h - $border) * .5; |
|
|
1543 | $icon[0]->draw_quad_alpha ( 0, $h2, $border, $border); |
|
|
1544 | $icon[0]->draw_quad_alpha ($w - $border, $h2, $border, $border); |
|
|
1545 | $icon[0]->draw_quad_alpha ($w2 , $h - $border, $border, $border); |
|
|
1546 | |
|
|
1547 | # resize |
|
|
1548 | $icon[1]->draw_quad_alpha ( 0, 0, $border, $border); |
|
|
1549 | $icon[1]->draw_quad_alpha ($w - $border, 0, $border, $border) |
|
|
1550 | unless $self->{has_close_button}; |
|
|
1551 | $icon[1]->draw_quad_alpha ( 0, $h - $border, $border, $border); |
|
|
1552 | $icon[1]->draw_quad_alpha ($w - $border, $h - $border, $border, $border); |
1536 | |
1553 | |
1537 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1554 | if (@{$self->{bg}} < 4 || $self->{bg}[3]) { |
1538 | glColor @{ $self->{bg} }; |
1555 | glColor @{ $self->{bg} }; |
1539 | |
1556 | |
1540 | # TODO: repeat texture not scale |
1557 | # TODO: repeat texture not scale |
… | |
… | |
1561 | |
1578 | |
1562 | ############################################################################# |
1579 | ############################################################################# |
1563 | |
1580 | |
1564 | package CFPlus::UI::Table; |
1581 | package CFPlus::UI::Table; |
1565 | |
1582 | |
1566 | our @ISA = CFPlus::UI::Base::; |
1583 | our @ISA = CFPlus::UI::Container::; |
1567 | |
1584 | |
1568 | use List::Util qw(max sum); |
1585 | use List::Util qw(max sum); |
1569 | |
1586 | |
1570 | use CFPlus::OpenGL; |
1587 | use CFPlus::OpenGL; |
1571 | |
1588 | |
1572 | sub new { |
1589 | sub new { |
1573 | my $class = shift; |
1590 | my $class = shift; |
1574 | |
1591 | |
1575 | $class->SUPER::new ( |
1592 | $class->SUPER::new ( |
1576 | children => [], |
|
|
1577 | col_expand => [], |
1593 | col_expand => [], |
1578 | row_expand => [], |
1594 | row_expand => [], |
1579 | @_, |
1595 | @_, |
1580 | ) |
1596 | ) |
1581 | } |
1597 | } |
1582 | |
1598 | |
1583 | sub children { |
|
|
1584 | grep $_, map @$_, grep $_, @{ $_[0]{children} } |
|
|
1585 | } |
|
|
1586 | |
|
|
1587 | # TODO: store row/col info in child widget and use standard add/del |
|
|
1588 | sub add { |
1599 | sub add { |
|
|
1600 | my ($self, @widgets) = @_; |
|
|
1601 | |
|
|
1602 | for my $child (@widgets) { |
|
|
1603 | $child->{rowspan} ||= 1; |
|
|
1604 | $child->{colspan} ||= 1; |
|
|
1605 | } |
|
|
1606 | |
|
|
1607 | $self->SUPER::add (@widgets); |
|
|
1608 | } |
|
|
1609 | |
|
|
1610 | sub add_at { |
1589 | my ($self) = shift; |
1611 | my $self = shift; |
|
|
1612 | |
|
|
1613 | my @widgets; |
1590 | |
1614 | |
1591 | while (@_) { |
1615 | while (@_) { |
1592 | my ($x, $y, $child) = splice @_, 0, 3, (); |
1616 | my ($col, $row, $child) = splice @_, 0, 3, (); |
1593 | $child->set_parent ($self); |
|
|
1594 | $self->{children}[$y][$x] = $child; |
|
|
1595 | } |
|
|
1596 | |
1617 | |
1597 | $self->{force_realloc} = 1; |
1618 | $child->{row} = $row; |
1598 | $self->{force_size_alloc} = 1; |
1619 | $child->{col} = $col; |
1599 | $self->realloc; |
|
|
1600 | } |
|
|
1601 | |
1620 | |
1602 | sub remove { |
1621 | push @widgets, $child; |
|
|
1622 | } |
|
|
1623 | |
|
|
1624 | $self->add (@widgets); |
|
|
1625 | } |
|
|
1626 | |
|
|
1627 | sub get_wh { |
1603 | my ($self, $child) = @_; |
1628 | my ($self) = @_; |
1604 | |
1629 | |
1605 | for (@{ $self->{children} }) { |
1630 | my (@w, @h); |
1606 | for (@{ $_ || [] }) { |
1631 | |
1607 | $_ = undef if $_ == $child; |
1632 | my @children = $self->children; |
|
|
1633 | |
|
|
1634 | # first pass, columns |
|
|
1635 | for my $widget (sort { $a->{colspan} <=> $b->{colspan} } @children) { |
|
|
1636 | my ($c, $w, $cs) = @$widget{qw(col req_w colspan)}; |
|
|
1637 | |
|
|
1638 | my $sw = sum @w[$c .. $c + $cs - 1]; |
|
|
1639 | |
|
|
1640 | if ($w > $sw) { |
|
|
1641 | $_ += ($w - $sw) / ($sw ? $sw / $_ : $cs) for @w[$c .. $c + $cs - 1]; |
1608 | } |
1642 | } |
1609 | } |
1643 | } |
1610 | } |
|
|
1611 | |
1644 | |
1612 | # TODO: move to container class maybe? send children a signal on removal? |
1645 | # second pass, rows |
1613 | sub clear { |
1646 | for my $widget (sort { $a->{rowspan} <=> $b->{rowspan} } @children) { |
1614 | my ($self) = @_; |
|
|
1615 | |
|
|
1616 | my @children = $self->children; |
|
|
1617 | delete $self->{children}; |
|
|
1618 | |
|
|
1619 | for (@children) { |
|
|
1620 | delete $_->{parent}; |
|
|
1621 | $_->hide; |
|
|
1622 | } |
|
|
1623 | |
|
|
1624 | $self->realloc; |
|
|
1625 | } |
|
|
1626 | |
|
|
1627 | sub get_wh { |
|
|
1628 | my ($self) = @_; |
|
|
1629 | |
|
|
1630 | my (@w, @h); |
|
|
1631 | |
|
|
1632 | for my $y (0 .. $#{$self->{children}}) { |
|
|
1633 | my $row = $self->{children}[$y] |
|
|
1634 | or next; |
|
|
1635 | |
|
|
1636 | for my $x (0 .. $#$row) { |
|
|
1637 | my $widget = $row->[$x] |
|
|
1638 | or next; |
|
|
1639 | my ($w, $h) = @$widget{qw(req_w req_h)}; |
1647 | my ($r, $h, $rs) = @$widget{qw(row req_h rowspan)}; |
1640 | |
1648 | |
1641 | $w[$x] = max $w[$x], $w; |
1649 | my $sh = sum @h[$r .. $r + $rs - 1]; |
1642 | $h[$y] = max $h[$y], $h; |
1650 | |
|
|
1651 | if ($h > $sh) { |
|
|
1652 | $_ += ($h - $sh) / ($sh ? $sh / $_ : $rs) for @h[$r .. $r + $rs - 1]; |
1643 | } |
1653 | } |
1644 | } |
1654 | } |
1645 | |
1655 | |
1646 | (\@w, \@h) |
1656 | (\@w, \@h) |
1647 | } |
1657 | } |
… | |
… | |
1663 | my ($ws, $hs) = $self->get_wh; |
1673 | my ($ws, $hs) = $self->get_wh; |
1664 | |
1674 | |
1665 | my $req_w = (sum @$ws) || 1; |
1675 | my $req_w = (sum @$ws) || 1; |
1666 | my $req_h = (sum @$hs) || 1; |
1676 | my $req_h = (sum @$hs) || 1; |
1667 | |
1677 | |
1668 | # TODO: nicer code |
1678 | # now linearly scale the rows/columns to the allocated size |
1669 | my @col_expand = @{$self->{col_expand}}; |
1679 | my @col_expand = @{$self->{col_expand}}; |
1670 | @col_expand = (1) x @$ws unless @col_expand; |
1680 | @col_expand = (1) x @$ws unless @col_expand; |
1671 | my $col_expand = (sum @col_expand) || 1; |
1681 | my $col_expand = (sum @col_expand) || 1; |
1672 | |
1682 | |
1673 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
1683 | $ws->[$_] += $col_expand[$_] / $col_expand * ($w - $req_w) for 0 .. $#$ws; |
… | |
… | |
1680 | |
1690 | |
1681 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1691 | $hs->[$_] += $row_expand[$_] / $row_expand * ($h - $req_h) for 0 .. $#$hs; |
1682 | |
1692 | |
1683 | CFPlus::UI::harmonize $hs; |
1693 | CFPlus::UI::harmonize $hs; |
1684 | |
1694 | |
1685 | my $y; |
1695 | my @x; for (0 .. $#$ws) { $x[$_ + 1] = $x[$_] + $ws->[$_] } |
|
|
1696 | my @y; for (0 .. $#$hs) { $y[$_ + 1] = $y[$_] + $hs->[$_] } |
1686 | |
1697 | |
1687 | for my $r (0 .. $#{$self->{children}}) { |
1698 | for my $widget ($self->children) { |
1688 | my $row = $self->{children}[$r] |
1699 | my ($r, $c, $w, $h, $rs, $cs) = @$widget{qw(row col req_w req_h rowspan colspan)}; |
1689 | or next; |
|
|
1690 | |
1700 | |
1691 | my $x = 0; |
1701 | $widget->configure ( |
1692 | my $row_h = $hs->[$r]; |
1702 | $x[$c], $y[$r], |
|
|
1703 | $x[$c + $cs] - $x[$c], $y[$r + $rs] - $y[$r], |
1693 | |
1704 | ); |
1694 | for my $c (0 .. $#$row) { |
|
|
1695 | my $col_w = $ws->[$c]; |
|
|
1696 | |
|
|
1697 | if (my $widget = $row->[$c]) { |
|
|
1698 | $widget->configure ($x, $y, $col_w, $row_h); |
|
|
1699 | } |
|
|
1700 | |
|
|
1701 | $x += $col_w; |
|
|
1702 | } |
|
|
1703 | |
|
|
1704 | $y += $row_h; |
|
|
1705 | } |
1705 | } |
1706 | |
1706 | |
1707 | 1 |
1707 | 1 |
1708 | } |
1708 | } |
1709 | |
1709 | |
1710 | sub find_widget { |
|
|
1711 | my ($self, $x, $y) = @_; |
|
|
1712 | |
|
|
1713 | $x -= $self->{x}; |
|
|
1714 | $y -= $self->{y}; |
|
|
1715 | |
|
|
1716 | my $res; |
|
|
1717 | |
|
|
1718 | for (grep $_, map @$_, grep $_, @{ $self->{children} }) { |
|
|
1719 | $res = $_->find_widget ($x, $y) |
|
|
1720 | and return $res; |
|
|
1721 | } |
|
|
1722 | |
|
|
1723 | $self->SUPER::find_widget ($x + $self->{x}, $y + $self->{y}) |
|
|
1724 | } |
|
|
1725 | |
|
|
1726 | sub _draw { |
|
|
1727 | my ($self) = @_; |
|
|
1728 | |
|
|
1729 | for (grep $_, @{$self->{children}}) { |
|
|
1730 | $_->draw for grep $_, @$_; |
|
|
1731 | } |
|
|
1732 | } |
|
|
1733 | |
|
|
1734 | ############################################################################# |
1710 | ############################################################################# |
1735 | |
1711 | |
1736 | package CFPlus::UI::Fixed; |
1712 | package CFPlus::UI::Fixed; |
1737 | |
1713 | |
1738 | use List::Util qw(min max); |
1714 | use List::Util qw(min max); |
1739 | |
1715 | |
1740 | our @ISA = CFPlus::UI::Container::; |
1716 | our @ISA = CFPlus::UI::Container::; |
1741 | |
1717 | |
1742 | sub add { |
|
|
1743 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1744 | |
|
|
1745 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1746 | $self->SUPER::add ($child); |
|
|
1747 | } |
|
|
1748 | |
|
|
1749 | sub _scale($$$) { |
1718 | sub _scale($$$) { |
1750 | my ($mode, $val, $max) = @_; |
1719 | my ($rel, $val, $max) = @_; |
1751 | |
1720 | |
1752 | $mode eq "abs" ? $val |
1721 | $rel ? $val * $max : $val |
1753 | : $mode eq "rel" ? $val * $max |
|
|
1754 | : 0 |
|
|
1755 | } |
1722 | } |
1756 | |
1723 | |
1757 | sub size_request { |
1724 | sub size_request { |
1758 | my ($self) = @_; |
1725 | my ($self) = @_; |
1759 | |
1726 | |
1760 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1727 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1761 | |
1728 | |
1762 | # determine overall size by querying abs widgets |
1729 | # determine overall size by querying abs widgets |
1763 | for my $child ($self->visible_children) { |
1730 | for my $child ($self->visible_children) { |
1764 | 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}; |
1765 | |
1734 | |
1766 | if ($pos eq "abs") { |
|
|
1767 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1768 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1769 | |
|
|
1770 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1735 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1771 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1736 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1772 | } |
1737 | } |
1773 | } |
1738 | } |
1774 | |
1739 | |
1775 | my $W = $x2 - $x1; |
1740 | my $W = $x2 - $x1; |
1776 | my $H = $y2 - $y1; |
1741 | my $H = $y2 - $y1; |
1777 | |
1742 | |
1778 | # now layout remaining widgets |
1743 | # now layout remaining widgets |
1779 | for my $child ($self->visible_children) { |
1744 | for my $child ($self->visible_children) { |
1780 | 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; |
1781 | |
1748 | |
1782 | if ($pos ne "abs") { |
|
|
1783 | $x = _scale $pos, $x, $W; |
|
|
1784 | $y = _scale $pos, $x, $H; |
|
|
1785 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1786 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1787 | |
|
|
1788 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1749 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1789 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1750 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1790 | } |
1751 | } |
1791 | } |
1752 | } |
1792 | |
1753 | |
1793 | my $W = $x2 - $x1; |
1754 | my $W = $x2 - $x1; |
1794 | my $H = $y2 - $y1; |
1755 | my $H = $y2 - $y1; |
… | |
… | |
1798 | |
1759 | |
1799 | sub invoke_size_allocate { |
1760 | sub invoke_size_allocate { |
1800 | my ($self, $W, $H) = @_; |
1761 | my ($self, $W, $H) = @_; |
1801 | |
1762 | |
1802 | for my $child ($self->visible_children) { |
1763 | for my $child ($self->visible_children) { |
1803 | 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; |
1804 | |
1766 | |
1805 | $x = _scale $pos, $x, $W; |
1767 | $x += $child->{c_halign} * $child->{req_w}; |
1806 | $y = _scale $pos, $x, $H; |
1768 | $y += $child->{c_valign} * $child->{req_h}; |
1807 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1808 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1809 | |
1769 | |
1810 | $child->configure ($x, $y, $w, $h); |
1770 | $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h}); |
1811 | } |
1771 | } |
1812 | |
1772 | |
1813 | 1 |
1773 | 1 |
1814 | } |
1774 | } |
1815 | |
1775 | |
… | |
… | |
1819 | |
1779 | |
1820 | our @ISA = CFPlus::UI::Container::; |
1780 | our @ISA = CFPlus::UI::Container::; |
1821 | |
1781 | |
1822 | sub size_request { |
1782 | sub size_request { |
1823 | my ($self) = @_; |
1783 | my ($self) = @_; |
|
|
1784 | |
|
|
1785 | my @children = $self->visible_children; |
1824 | |
1786 | |
1825 | $self->{vertical} |
1787 | $self->{vertical} |
1826 | ? ( |
1788 | ? ( |
1827 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1789 | (List::Util::max map $_->{req_w}, @children), |
1828 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1790 | (List::Util::sum map $_->{req_h}, @children), |
1829 | ) |
1791 | ) |
1830 | : ( |
1792 | : ( |
1831 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
1793 | (List::Util::sum map $_->{req_w}, @children), |
1832 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1794 | (List::Util::max map $_->{req_h}, @children), |
1833 | ) |
1795 | ) |
1834 | } |
1796 | } |
1835 | |
1797 | |
1836 | sub invoke_size_allocate { |
1798 | sub invoke_size_allocate { |
1837 | my ($self, $w, $h) = @_; |
1799 | my ($self, $w, $h) = @_; |
… | |
… | |
2078 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2040 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2079 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2041 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2080 | : ($self->{h} - $size->[1]) * 0.5); |
2042 | : ($self->{h} - $size->[1]) * 0.5); |
2081 | }; |
2043 | }; |
2082 | |
2044 | |
2083 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2045 | # unless ($self->{list}) { |
2084 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
2046 | # $self->{list} = CFPlus::OpenGL::glGenList; |
|
|
2047 | # CFPlus::OpenGL::glNewList $self->{list}; |
|
|
2048 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
|
|
2049 | # CFPlus::OpenGL::glEndList; |
|
|
2050 | # } |
|
|
2051 | # |
|
|
2052 | # CFPlus::OpenGL::glCallList $self->{list}; |
2085 | |
2053 | |
2086 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2054 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2087 | } |
2055 | } |
|
|
2056 | |
|
|
2057 | #sub destroy { |
|
|
2058 | # my ($self) = @_; |
|
|
2059 | # |
|
|
2060 | # CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
|
|
2061 | # |
|
|
2062 | # $self->SUPER::destroy; |
|
|
2063 | #} |
2088 | |
2064 | |
2089 | ############################################################################# |
2065 | ############################################################################# |
2090 | |
2066 | |
2091 | package CFPlus::UI::EntryBase; |
2067 | package CFPlus::UI::EntryBase; |
2092 | |
2068 | |
… | |
… | |
2098 | my $class = shift; |
2074 | my $class = shift; |
2099 | |
2075 | |
2100 | $class->SUPER::new ( |
2076 | $class->SUPER::new ( |
2101 | fg => [1, 1, 1], |
2077 | fg => [1, 1, 1], |
2102 | bg => [0, 0, 0, 0.2], |
2078 | bg => [0, 0, 0, 0.2], |
|
|
2079 | outline => [0.6, 0.3, 0.1], |
2103 | active_bg => [1, 1, 1, 0.5], |
2080 | active_bg => [0, 0, 1, .2], |
2104 | active_fg => [0, 0, 0], |
2081 | active_fg => [1, 1, 1], |
|
|
2082 | active_outline => [1, 1, 0], |
2105 | can_hover => 1, |
2083 | can_hover => 1, |
2106 | can_focus => 1, |
2084 | can_focus => 1, |
2107 | valign => 0, |
2085 | valign => 0, |
2108 | can_events => 1, |
2086 | can_events => 1, |
2109 | ellipsise => 0, |
2087 | ellipsise => 0, |
… | |
… | |
2266 | |
2244 | |
2267 | unless (exists $self->{cur_h}) { |
2245 | unless (exists $self->{cur_h}) { |
2268 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2246 | my $text = substr $self->{text}, 0, $self->{cursor}; |
2269 | utf8::encode $text; |
2247 | utf8::encode $text; |
2270 | |
2248 | |
2271 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) |
2249 | @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text); |
2272 | } |
2250 | } |
2273 | |
2251 | |
|
|
2252 | glColor_premultiply @{$self->{active_fg}}; |
2274 | glBegin GL_LINES; |
2253 | glBegin GL_LINES; |
2275 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2254 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; |
2276 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
2255 | glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; |
|
|
2256 | glEnd; |
|
|
2257 | |
|
|
2258 | glLineWidth 3; |
|
|
2259 | glColor @{$self->{active_outline}}; |
|
|
2260 | glBegin GL_LINE_LOOP; |
|
|
2261 | glVertex 0, 0; |
|
|
2262 | glVertex $self->{w} - 1, 0; |
|
|
2263 | glVertex $self->{w} - 1, $self->{h} - 1; |
|
|
2264 | glVertex 0, $self->{h} - 1; |
|
|
2265 | glEnd; |
|
|
2266 | glLineWidth 1; |
|
|
2267 | |
|
|
2268 | } else { |
|
|
2269 | glColor @{$self->{outline}}; |
|
|
2270 | glTranslate .375, .375; |
|
|
2271 | glBegin GL_LINE_STRIP; |
|
|
2272 | glVertex 0, $self->{h} * .5; |
|
|
2273 | glVertex 0, $self->{h} - 3; |
|
|
2274 | glVertex $self->{w} - 1, $self->{h} - 3; |
|
|
2275 | glVertex $self->{w} - 1, $self->{h} * .5; |
2277 | glEnd; |
2276 | glEnd; |
2278 | } |
2277 | } |
2279 | } |
2278 | } |
2280 | |
2279 | |
2281 | ############################################################################# |
2280 | ############################################################################# |
… | |
… | |
2368 | 1 |
2367 | 1 |
2369 | } |
2368 | } |
2370 | |
2369 | |
2371 | ############################################################################# |
2370 | ############################################################################# |
2372 | |
2371 | |
2373 | package CFPlus::UI::Button; |
2372 | package CFPlus::UI::ButtonBin; |
2374 | |
2373 | |
2375 | our @ISA = CFPlus::UI::Label::; |
2374 | our @ISA = CFPlus::UI::Bin::; |
2376 | |
2375 | |
2377 | use CFPlus::OpenGL; |
2376 | use CFPlus::OpenGL; |
2378 | |
2377 | |
2379 | my @tex = |
2378 | my @tex = |
2380 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2379 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
2381 | qw(b1_button_active.png); |
2380 | qw(b1_button_inactive.png b1_button_active.png); |
2382 | |
2381 | |
2383 | sub new { |
2382 | sub new { |
2384 | my $class = shift; |
2383 | my $class = shift; |
2385 | |
2384 | |
2386 | $class->SUPER::new ( |
2385 | $class->SUPER::new ( |
2387 | padding_x => 4, |
|
|
2388 | padding_y => 4, |
|
|
2389 | fg => [1, 1, 1], |
|
|
2390 | active_fg => [0, 0, 1], |
|
|
2391 | can_hover => 1, |
2386 | can_hover => 1, |
2392 | align => 0, |
2387 | align => 0, |
2393 | valign => 0, |
2388 | valign => 0, |
2394 | can_events => 1, |
2389 | can_events => 1, |
2395 | @_ |
2390 | @_ |
… | |
… | |
2407 | } |
2402 | } |
2408 | |
2403 | |
2409 | sub _draw { |
2404 | sub _draw { |
2410 | my ($self) = @_; |
2405 | my ($self) = @_; |
2411 | |
2406 | |
2412 | local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg}; |
|
|
2413 | |
|
|
2414 | glEnable GL_TEXTURE_2D; |
2407 | glEnable GL_TEXTURE_2D; |
2415 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2408 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2416 | glColor 0, 0, 0, 1; |
2409 | glColor 0, 0, 0, 1; |
2417 | |
2410 | |
|
|
2411 | my $tex = $tex[$GRAB == $self]; |
2418 | $tex[0]->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2412 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
|
|
2413 | |
|
|
2414 | glDisable GL_TEXTURE_2D; |
|
|
2415 | |
|
|
2416 | $self->SUPER::_draw; |
|
|
2417 | } |
|
|
2418 | |
|
|
2419 | ############################################################################# |
|
|
2420 | |
|
|
2421 | package CFPlus::UI::Button; |
|
|
2422 | |
|
|
2423 | our @ISA = CFPlus::UI::Label::; |
|
|
2424 | |
|
|
2425 | use CFPlus::OpenGL; |
|
|
2426 | |
|
|
2427 | my @tex = |
|
|
2428 | map { new_from_file CFPlus::Texture CFPlus::find_rcfile $_, mipmap => 1 } |
|
|
2429 | qw(b1_button_inactive.png b1_button_active.png); |
|
|
2430 | |
|
|
2431 | sub new { |
|
|
2432 | my $class = shift; |
|
|
2433 | |
|
|
2434 | $class->SUPER::new ( |
|
|
2435 | padding_x => 4, |
|
|
2436 | padding_y => 4, |
|
|
2437 | fg => [1.0, 1.0, 1.0], |
|
|
2438 | active_fg => [0.8, 0.8, 0.8], |
|
|
2439 | can_hover => 1, |
|
|
2440 | align => 0, |
|
|
2441 | valign => 0, |
|
|
2442 | can_events => 1, |
|
|
2443 | @_ |
|
|
2444 | ) |
|
|
2445 | } |
|
|
2446 | |
|
|
2447 | sub invoke_button_up { |
|
|
2448 | my ($self, $ev, $x, $y) = @_; |
|
|
2449 | |
|
|
2450 | $self->emit ("activate") |
|
|
2451 | if $x >= 0 && $x < $self->{w} |
|
|
2452 | && $y >= 0 && $y < $self->{h}; |
|
|
2453 | |
|
|
2454 | 1 |
|
|
2455 | } |
|
|
2456 | |
|
|
2457 | sub _draw { |
|
|
2458 | my ($self) = @_; |
|
|
2459 | |
|
|
2460 | local $self->{fg} = $GRAB == $self ? $self->{active_fg} : $self->{fg}; |
|
|
2461 | |
|
|
2462 | glEnable GL_TEXTURE_2D; |
|
|
2463 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
|
|
2464 | glColor 0, 0, 0, 1; |
|
|
2465 | |
|
|
2466 | my $tex = $tex[$GRAB == $self]; |
|
|
2467 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
2419 | |
2468 | |
2420 | glDisable GL_TEXTURE_2D; |
2469 | glDisable GL_TEXTURE_2D; |
2421 | |
2470 | |
2422 | $self->SUPER::_draw; |
2471 | $self->SUPER::_draw; |
2423 | } |
2472 | } |
… | |
… | |
2510 | sub new { |
2559 | sub new { |
2511 | my $class = shift; |
2560 | my $class = shift; |
2512 | |
2561 | |
2513 | my $self = $class->SUPER::new ( |
2562 | my $self = $class->SUPER::new ( |
2514 | can_events => 0, |
2563 | can_events => 0, |
|
|
2564 | scale => 1, |
2515 | @_, |
2565 | @_, |
2516 | ); |
2566 | ); |
2517 | |
2567 | |
2518 | $self->{path} || $self->{tex} |
2568 | $self->{path} || $self->{tex} |
2519 | or Carp::croak "'path' or 'tex' attributes required"; |
2569 | or Carp::croak "'path' or 'tex' attributes required"; |
… | |
… | |
2544 | } |
2594 | } |
2545 | |
2595 | |
2546 | sub size_request { |
2596 | sub size_request { |
2547 | my ($self) = @_; |
2597 | my ($self) = @_; |
2548 | |
2598 | |
2549 | ($self->{tex}{w}, $self->{tex}{h}) |
2599 | (int $self->{tex}{w} * $self->{scale}, int $self->{tex}{h} * $self->{scale}) |
2550 | } |
2600 | } |
2551 | |
2601 | |
2552 | sub _draw { |
2602 | sub _draw { |
2553 | my ($self) = @_; |
2603 | my ($self) = @_; |
2554 | |
2604 | |
… | |
… | |
2564 | } |
2614 | } |
2565 | |
2615 | |
2566 | glEnable GL_TEXTURE_2D; |
2616 | glEnable GL_TEXTURE_2D; |
2567 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2617 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
2568 | |
2618 | |
2569 | $tex->draw_quad (0, 0, $w, $h); |
2619 | $tex->draw_quad_alpha (0, 0, $w, $h); |
2570 | |
2620 | |
2571 | glDisable GL_TEXTURE_2D; |
2621 | glDisable GL_TEXTURE_2D; |
2572 | } |
2622 | } |
2573 | |
2623 | |
2574 | ############################################################################# |
2624 | ############################################################################# |
… | |
… | |
2876 | |
2926 | |
2877 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2927 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2878 | |
2928 | |
2879 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2929 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2880 | |
2930 | |
2881 | $self->invoke_mouse_motion ($ev, $x, $y) |
2931 | $self->invoke_mouse_motion ($ev, $x, $y); |
|
|
2932 | |
|
|
2933 | 1 |
2882 | } |
2934 | } |
2883 | |
2935 | |
2884 | sub invoke_mouse_motion { |
2936 | sub invoke_mouse_motion { |
2885 | my ($self, $ev, $x, $y) = @_; |
2937 | my ($self, $ev, $x, $y) = @_; |
2886 | |
2938 | |
… | |
… | |
2906 | |
2958 | |
2907 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2959 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2908 | |
2960 | |
2909 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2961 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2910 | |
2962 | |
2911 | ! ! $delta |
2963 | 1 |
2912 | } |
2964 | } |
2913 | |
2965 | |
2914 | sub update { |
2966 | sub update { |
2915 | my ($self) = @_; |
2967 | my ($self) = @_; |
2916 | |
2968 | |
… | |
… | |
3047 | } |
3099 | } |
3048 | |
3100 | |
3049 | sub size_request { |
3101 | sub size_request { |
3050 | my ($self) = @_; |
3102 | my ($self) = @_; |
3051 | |
3103 | |
3052 | my ($empty, $slider) = @{ $self->{children} }; |
3104 | my ($empty, $slider) = $self->visible_children; |
3053 | |
3105 | |
3054 | local $self->{children} = [$empty, $slider]; |
3106 | local $self->{children} = [$empty, $slider]; |
3055 | $self->SUPER::size_request |
3107 | $self->SUPER::size_request |
3056 | } |
3108 | } |
3057 | |
3109 | |
… | |
… | |
3446 | glTranslate 0.375, 0.375; |
3498 | glTranslate 0.375, 0.375; |
3447 | |
3499 | |
3448 | my ($w, $h) = @$self{qw(w h)}; |
3500 | my ($w, $h) = @$self{qw(w h)}; |
3449 | |
3501 | |
3450 | glColor 1, 0.8, 0.4; |
3502 | glColor 1, 0.8, 0.4; |
3451 | glBegin GL_QUADS; |
3503 | glRect 0, 0, $w, $h; |
3452 | glVertex 0 , 0; |
|
|
3453 | glVertex 0 , $h; |
|
|
3454 | glVertex $w, $h; |
|
|
3455 | glVertex $w, 0; |
|
|
3456 | glEnd; |
|
|
3457 | |
3504 | |
3458 | glColor 0, 0, 0; |
3505 | glColor 0, 0, 0; |
3459 | glBegin GL_LINE_LOOP; |
3506 | glBegin GL_LINE_LOOP; |
3460 | glVertex 0 , 0; |
3507 | glVertex 0 , 0; |
3461 | glVertex 0 , $h; |
3508 | glVertex 0 , $h; |
… | |
… | |
3488 | ); |
3535 | ); |
3489 | |
3536 | |
3490 | if ($self->{anim} && $self->{animspeed}) { |
3537 | if ($self->{anim} && $self->{animspeed}) { |
3491 | CFPlus::weaken (my $widget = $self); |
3538 | CFPlus::weaken (my $widget = $self); |
3492 | |
3539 | |
|
|
3540 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
|
|
3541 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
3493 | $self->{timer} = Event->timer ( |
3542 | $self->{timer} = Event->timer ( |
3494 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
|
|
3495 | hard => 1, |
3543 | parked => 1, |
3496 | interval => $self->{animspeed}, |
|
|
3497 | cb => sub { |
3544 | cb => sub { |
3498 | return unless $::CONN; |
3545 | return unless $::CONN && $widget; |
3499 | |
3546 | |
3500 | ++$widget->{frame}; |
3547 | ++$widget->{frame}; |
3501 | $self->update_face; |
3548 | $widget->update_face; |
3502 | $self->update; |
3549 | $widget->update; |
|
|
3550 | |
|
|
3551 | $widget->update_timer; |
3503 | }, |
3552 | }, |
3504 | ); |
3553 | ); |
3505 | |
3554 | |
3506 | $self->update_face; |
3555 | $self->update_face; |
|
|
3556 | $self->update_timer; |
3507 | } |
3557 | } |
3508 | |
3558 | |
3509 | $self |
3559 | $self |
|
|
3560 | } |
|
|
3561 | |
|
|
3562 | sub update_timer { |
|
|
3563 | my ($self) = @_; |
|
|
3564 | |
|
|
3565 | return unless $self->{timer}; |
|
|
3566 | |
|
|
3567 | if ($self->{visible}) { |
|
|
3568 | $self->{timer}->at ( |
|
|
3569 | $self->{anim_start} |
|
|
3570 | + $self->{animspeed} |
|
|
3571 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
|
|
3572 | ); |
|
|
3573 | $self->{timer}->start; |
|
|
3574 | } else { |
|
|
3575 | $self->{timer}->stop; |
|
|
3576 | } |
3510 | } |
3577 | } |
3511 | |
3578 | |
3512 | sub update_face { |
3579 | sub update_face { |
3513 | my ($self) = @_; |
3580 | my ($self) = @_; |
3514 | |
3581 | |
… | |
… | |
3516 | |
3583 | |
3517 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3584 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3518 | if ($anim && @$anim) { |
3585 | if ($anim && @$anim) { |
3519 | delete $self->{wait_face}; |
3586 | delete $self->{wait_face}; |
3520 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
3587 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3588 | $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; |
3521 | } |
3589 | } |
3522 | } |
3590 | } |
3523 | } |
3591 | } |
3524 | |
3592 | |
3525 | sub size_request { |
3593 | sub size_request { |
3526 | my ($self) = @_; |
3594 | my ($self) = @_; |
3527 | |
3595 | |
3528 | if ($::CONN) { |
3596 | if ($::CONN) { |
3529 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3597 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3530 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3598 | if (my $tex = $::CONN->{texture}[$faceid]) { |
|
|
3599 | $self->{tex} = $tex; |
3531 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3600 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3532 | } else { |
3601 | } else { |
3533 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3602 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3534 | $self->realloc; |
3603 | $self->realloc; |
3535 | }); |
3604 | }); |
… | |
… | |
3546 | return unless $self->{visible}; |
3615 | return unless $self->{visible}; |
3547 | |
3616 | |
3548 | $self->SUPER::update; |
3617 | $self->SUPER::update; |
3549 | } |
3618 | } |
3550 | |
3619 | |
|
|
3620 | sub invoke_visibility_change { |
|
|
3621 | my ($self) = @_; |
|
|
3622 | |
|
|
3623 | $self->update_timer; |
|
|
3624 | |
|
|
3625 | 0 |
|
|
3626 | } |
|
|
3627 | |
3551 | sub _draw { |
3628 | sub _draw { |
3552 | my ($self) = @_; |
3629 | my ($self) = @_; |
3553 | |
3630 | |
3554 | return unless $::CONN; |
|
|
3555 | |
|
|
3556 | $self->SUPER::_draw; |
3631 | $self->SUPER::_draw; |
3557 | |
3632 | |
3558 | my $faceid = $::CONN->{faceid}[$self->{face}] |
3633 | if (my $tex = $self->{tex}) { |
3559 | or return; |
|
|
3560 | |
|
|
3561 | my $tex = $::CONN->{texture}[$faceid]; |
|
|
3562 | |
|
|
3563 | if ($tex) { |
|
|
3564 | glEnable GL_TEXTURE_2D; |
3634 | glEnable GL_TEXTURE_2D; |
3565 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3635 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3566 | glColor 0, 0, 0, 1; |
3636 | glColor 0, 0, 0, 1; |
3567 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3637 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3568 | glDisable GL_TEXTURE_2D; |
3638 | glDisable GL_TEXTURE_2D; |
… | |
… | |
3570 | } |
3640 | } |
3571 | |
3641 | |
3572 | sub destroy { |
3642 | sub destroy { |
3573 | my ($self) = @_; |
3643 | my ($self) = @_; |
3574 | |
3644 | |
3575 | $self->{timer}->cancel |
3645 | (delete $self->{timer})->cancel |
3576 | if $self->{timer}; |
3646 | if $self->{timer}; |
3577 | |
3647 | |
3578 | $self->SUPER::destroy; |
3648 | $self->SUPER::destroy; |
3579 | } |
3649 | } |
3580 | |
3650 | |
… | |
… | |
3620 | children => [ |
3690 | children => [ |
3621 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3691 | (new CFPlus::UI::Label markup => $left, expand => 1), |
3622 | (new CFPlus::UI::Label markup => $right, align => +1), |
3692 | (new CFPlus::UI::Label markup => $right, align => +1), |
3623 | ], |
3693 | ], |
3624 | ; |
3694 | ; |
3625 | |
3695 | |
3626 | } else { |
3696 | } else { |
3627 | $widget = new CFPlus::UI::Label |
3697 | $widget = new CFPlus::UI::Label |
3628 | can_hover => 1, |
3698 | can_hover => 1, |
3629 | can_events => 1, |
3699 | can_events => 1, |
3630 | markup => $widget, |
3700 | markup => $widget, |
… | |
… | |
3766 | buttonbar => (new CFPlus::UI::Buttonbar), |
3836 | buttonbar => (new CFPlus::UI::Buttonbar), |
3767 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3837 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3768 | # filter => # will be put between multiplexer and $self |
3838 | # filter => # will be put between multiplexer and $self |
3769 | @_, |
3839 | @_, |
3770 | ); |
3840 | ); |
3771 | |
3841 | |
3772 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3842 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3773 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3843 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3774 | |
3844 | |
|
|
3845 | { |
|
|
3846 | Scalar::Util::weaken (my $wself = $self); |
|
|
3847 | |
|
|
3848 | $self->{multiplexer}->connect (c_add => sub { |
|
|
3849 | my ($mplex, $widgets) = @_; |
|
|
3850 | |
|
|
3851 | for my $child (@$widgets) { |
|
|
3852 | Scalar::Util::weaken $child; |
|
|
3853 | $child->{c_tab_} ||= do { |
|
|
3854 | my $tab = |
|
|
3855 | (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") |
|
|
3856 | ? $child->{c_tab} |
|
|
3857 | : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
|
|
3858 | |
|
|
3859 | $tab->connect (activate => sub { |
|
|
3860 | $wself->set_current_page ($child); |
|
|
3861 | }); |
|
|
3862 | |
|
|
3863 | $tab |
|
|
3864 | }; |
|
|
3865 | |
|
|
3866 | $self->{buttonbar}->add ($child->{c_tab_}); |
|
|
3867 | } |
|
|
3868 | }); |
|
|
3869 | |
|
|
3870 | $self->{multiplexer}->connect (c_remove => sub { |
|
|
3871 | my ($mplex, $widgets) = @_; |
|
|
3872 | |
|
|
3873 | for my $child (@$widgets) { |
|
|
3874 | $wself->{buttonbar}->remove ($child->{c_tab_}); |
|
|
3875 | } |
|
|
3876 | }); |
|
|
3877 | } |
|
|
3878 | |
3775 | $self |
3879 | $self |
3776 | } |
3880 | } |
3777 | |
3881 | |
3778 | sub add { |
3882 | sub add { |
|
|
3883 | my ($self, @widgets) = @_; |
|
|
3884 | |
|
|
3885 | $self->{multiplexer}->add (@widgets) |
|
|
3886 | } |
|
|
3887 | |
|
|
3888 | sub remove { |
|
|
3889 | my ($self, @widgets) = @_; |
|
|
3890 | |
|
|
3891 | $self->{multiplexer}->remove (@widgets) |
|
|
3892 | } |
|
|
3893 | |
|
|
3894 | sub pages { |
|
|
3895 | my ($self) = @_; |
|
|
3896 | $self->{multiplexer}->children |
|
|
3897 | } |
|
|
3898 | |
|
|
3899 | sub add_tab { |
3779 | my ($self, $title, $widget, $tooltip) = @_; |
3900 | my ($self, $title, $widget, $tooltip) = @_; |
3780 | |
3901 | |
3781 | CFPlus::weaken $self; |
3902 | $title = [$title, $tooltip] unless ref $title; |
|
|
3903 | $widget->{c_tab} = $title; |
3782 | |
3904 | |
3783 | $self->{buttonbar}->add (new CFPlus::UI::Button |
|
|
3784 | markup => $title, |
|
|
3785 | tooltip => $tooltip, |
|
|
3786 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3787 | ); |
|
|
3788 | |
|
|
3789 | $self->{multiplexer}->add ($widget); |
3905 | $self->add ($widget); |
3790 | } |
3906 | } |
3791 | |
3907 | |
3792 | sub get_current_page { |
3908 | sub get_current_page { |
3793 | my ($self) = @_; |
3909 | my ($self) = @_; |
3794 | |
3910 | |
… | |
… | |
4124 | while ($self->{refresh_hook}) { |
4240 | while ($self->{refresh_hook}) { |
4125 | $_->() |
4241 | $_->() |
4126 | for values %{delete $self->{refresh_hook}}; |
4242 | for values %{delete $self->{refresh_hook}}; |
4127 | } |
4243 | } |
4128 | |
4244 | |
4129 | if ($self->{realloc}) { |
4245 | while ($self->{realloc}) { |
4130 | my %queue; |
4246 | my %queue; |
4131 | my @queue; |
4247 | my @queue; |
4132 | my $widget; |
4248 | my $widget; |
4133 | |
4249 | |
4134 | outer: |
4250 | outer: |
… | |
… | |
4181 | } |
4297 | } |
4182 | } |
4298 | } |
4183 | |
4299 | |
4184 | delete $self->{realloc}{$widget+0}; |
4300 | delete $self->{realloc}{$widget+0}; |
4185 | } |
4301 | } |
4186 | } |
|
|
4187 | |
4302 | |
4188 | while (my $size_alloc = delete $self->{size_alloc}) { |
4303 | while (my $size_alloc = delete $self->{size_alloc}) { |
4189 | my @queue = sort { $b->{visible} <=> $a->{visible} } |
4304 | my @queue = sort { $a->{visible} <=> $b->{visible} } |
4190 | values %$size_alloc; |
4305 | values %$size_alloc; |
4191 | |
4306 | |
4192 | while () { |
4307 | while () { |
4193 | my $widget = pop @queue || last; |
4308 | my $widget = pop @queue || last; |
4194 | |
4309 | |
4195 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4310 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4196 | |
4311 | |
4197 | $w = 0 if $w < 0; |
|
|
4198 | $h = 0 if $h < 0; |
|
|
4199 | |
|
|
4200 | $w = max $widget->{min_w}, $w; |
4312 | $w = max $widget->{min_w}, $w; |
4201 | $h = max $widget->{min_h}, $h; |
4313 | $h = max $widget->{min_h}, $h; |
4202 | |
4314 | |
4203 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4315 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4204 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4316 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4205 | |
4317 | |
4206 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4318 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4207 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4319 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4208 | |
4320 | |
4209 | $w = int $w + 0.5; |
4321 | $w = int $w + 0.5; |
4210 | $h = int $h + 0.5; |
4322 | $h = int $h + 0.5; |
4211 | |
4323 | |
4212 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4324 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4213 | $widget->{old_w} = $widget->{w}; |
4325 | $widget->{old_w} = $widget->{w}; |
4214 | $widget->{old_h} = $widget->{h}; |
4326 | $widget->{old_h} = $widget->{h}; |
4215 | |
4327 | |
4216 | $widget->{w} = $w; |
4328 | $widget->{w} = $w; |
4217 | $widget->{h} = $h; |
4329 | $widget->{h} = $h; |
4218 | |
4330 | |
4219 | $widget->emit (size_allocate => $w, $h); |
4331 | $widget->emit (size_allocate => $w, $h); |
|
|
4332 | } |
4220 | } |
4333 | } |
4221 | } |
4334 | } |
4222 | } |
4335 | } |
4223 | |
4336 | |
4224 | while ($self->{post_alloc_hook}) { |
4337 | while ($self->{post_alloc_hook}) { |
4225 | $_->() |
4338 | $_->() |
4226 | for values %{delete $self->{post_alloc_hook}}; |
4339 | for values %{delete $self->{post_alloc_hook}}; |
4227 | } |
4340 | } |
4228 | |
|
|
4229 | |
4341 | |
4230 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
4342 | glViewport 0, 0, $::WIDTH, $::HEIGHT; |
4231 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
4343 | glClearColor +($::CFG->{fow_intensity}) x 3, 1; |
4232 | glClear GL_COLOR_BUFFER_BIT; |
4344 | glClear GL_COLOR_BUFFER_BIT; |
4233 | |
4345 | |