… | |
… | |
593 | |
593 | |
594 | # 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 |
595 | # functions seems pointless. |
595 | # functions seems pointless. |
596 | 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 |
597 | |
597 | |
598 | sub draw { |
598 | #sub draw { |
599 | my ($self) = @_; |
599 | #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 | |
600 | |
645 | sub _draw { |
601 | sub _draw { |
646 | my ($self) = @_; |
602 | my ($self) = @_; |
647 | |
603 | |
648 | warn "no draw defined for $self\n"; |
604 | warn "no draw defined for $self\n"; |
… | |
… | |
769 | @{$self->{children}}, @widgets |
725 | @{$self->{children}}, @widgets |
770 | ]; |
726 | ]; |
771 | |
727 | |
772 | $self->realloc; |
728 | $self->realloc; |
773 | |
729 | |
|
|
730 | $self->emit (c_add => \@widgets); |
|
|
731 | |
774 | map $_+0, @widgets |
732 | map $_+0, @widgets |
775 | } |
733 | } |
776 | |
734 | |
777 | sub children { |
735 | sub children { |
778 | @{ $_[0]{children} } |
736 | @{ $_[0]{children} } |
779 | } |
737 | } |
780 | |
738 | |
781 | sub remove { |
739 | sub remove { |
782 | my ($self, $child) = @_; |
740 | my ($self, @widgets) = @_; |
783 | |
741 | |
|
|
742 | $self->emit (c_remove => \@widgets); |
|
|
743 | |
|
|
744 | for my $child (@widgets) { |
784 | delete $child->{parent}; |
745 | delete $child->{parent}; |
785 | $child->hide; |
746 | $child->hide; |
786 | |
|
|
787 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
747 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
|
|
748 | } |
788 | |
749 | |
789 | $self->realloc; |
750 | $self->realloc; |
790 | } |
751 | } |
791 | |
752 | |
792 | sub clear { |
753 | sub clear { |
… | |
… | |
820 | } |
781 | } |
821 | |
782 | |
822 | sub _draw { |
783 | sub _draw { |
823 | my ($self) = @_; |
784 | my ($self) = @_; |
824 | |
785 | |
825 | $_->draw for @{$self->{children}}; |
786 | $_->draw for $self->visible_children; |
826 | } |
787 | } |
827 | |
788 | |
828 | ############################################################################# |
789 | ############################################################################# |
829 | |
790 | |
830 | package CFPlus::UI::Bin; |
791 | package CFPlus::UI::Bin; |
… | |
… | |
840 | } |
801 | } |
841 | |
802 | |
842 | sub add { |
803 | sub add { |
843 | my ($self, $child) = @_; |
804 | my ($self, $child) = @_; |
844 | |
805 | |
845 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
806 | $self->clear; |
846 | $self->SUPER::add ($child); |
807 | $self->SUPER::add ($child); |
847 | } |
808 | } |
848 | |
809 | |
849 | sub remove { |
810 | sub remove { |
850 | my ($self, $widget) = @_; |
811 | my ($self, $widget) = @_; |
… | |
… | |
992 | $self->{view_x} = $x; |
953 | $self->{view_x} = $x; |
993 | $self->{view_y} = $y; |
954 | $self->{view_y} = $y; |
994 | |
955 | |
995 | $self->emit (changed => $x, $y); |
956 | $self->emit (changed => $x, $y); |
996 | $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); |
997 | } |
976 | } |
998 | } |
977 | } |
999 | |
978 | |
1000 | # 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 |
1001 | sub coord2local { |
980 | sub coord2local { |
… | |
… | |
1094 | $vp->{parent}{hslider}->set_value ($x); |
1073 | $vp->{parent}{hslider}->set_value ($x); |
1095 | $vp->{parent}{vslider}->set_value ($y); |
1074 | $vp->{parent}{vslider}->set_value ($y); |
1096 | |
1075 | |
1097 | 0 |
1076 | 0 |
1098 | }, |
1077 | }, |
|
|
1078 | on_size_allocate => sub { |
|
|
1079 | my ($vp, $w, $h) = @_; |
|
|
1080 | $vp->{parent}->update_slider; |
|
|
1081 | 0 |
|
|
1082 | }, |
1099 | ; |
1083 | ; |
1100 | |
1084 | |
1101 | $self->SUPER::add ($self->{vp}); |
1085 | $self->SUPER::add ($self->{vp}); |
1102 | |
1086 | |
1103 | $self->add ($child) if $child; |
1087 | $self->add ($child) if $child; |
… | |
… | |
1109 | my ($self, $widget) = @_; |
1093 | my ($self, $widget) = @_; |
1110 | |
1094 | |
1111 | $self->{vp}->add ($self->{child} = $widget); |
1095 | $self->{vp}->add ($self->{child} = $widget); |
1112 | } |
1096 | } |
1113 | |
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 | |
1114 | sub update_slider { |
1102 | sub update_slider { |
1115 | my ($self) = @_; |
1103 | my ($self) = @_; |
1116 | |
1104 | |
1117 | my $child = ($self->{vp} or return)->child; |
1105 | my $child = ($self->{vp} or return)->child; |
1118 | |
1106 | |
|
|
1107 | if ($self->{scroll_x}) { |
1119 | my ($w1, $w2) = ($child->{w}, $self->{vp}{w}); |
1108 | my ($w1, $w2) = ($child->{req_w}, $self->{vp}{w}); |
1120 | $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]); |
1121 | |
1110 | |
1122 | my $visible = $w1 > $w2; |
1111 | my $visible = $w1 > $w2; |
1123 | if ($visible != $self->{hslider_visible}) { |
1112 | if ($visible != $self->{hslider_visible}) { |
1124 | $self->{hslider_visible} = $visible; |
1113 | $self->{hslider_visible} = $visible; |
1125 | $visible ? $self->SUPER::add ($self->{hslider}) |
1114 | $visible ? $self->SUPER::add ($self->{hslider}) |
1126 | : $self->SUPER::remove ($self->{hslider}); |
1115 | : $self->SUPER::remove ($self->{hslider}); |
|
|
1116 | } |
1127 | } |
1117 | } |
1128 | |
1118 | |
|
|
1119 | if ($self->{scroll_y}) { |
1129 | my ($h1, $h2) = ($child->{h}, $self->{vp}{h}); |
1120 | my ($h1, $h2) = ($child->{req_h}, $self->{vp}{h}); |
1130 | $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]); |
1131 | |
1122 | |
1132 | my $visible = $h1 > $h2; |
1123 | my $visible = $h1 > $h2; |
1133 | if ($visible != $self->{vslider_visible}) { |
1124 | if ($visible != $self->{vslider_visible}) { |
1134 | $self->{vslider_visible} = $visible; |
1125 | $self->{vslider_visible} = $visible; |
1135 | $visible ? $self->SUPER::add ($self->{vslider}) |
1126 | $visible ? $self->SUPER::add ($self->{vslider}) |
1136 | : $self->SUPER::remove ($self->{vslider}); |
1127 | : $self->SUPER::remove ($self->{vslider}); |
|
|
1128 | } |
1137 | } |
1129 | } |
1138 | } |
1130 | } |
1139 | |
1131 | |
1140 | sub start_dragging { |
1132 | sub start_dragging { |
1141 | my ($self, $ev) = @_; |
1133 | my ($self, $ev) = @_; |
… | |
… | |
1721 | |
1713 | |
1722 | use List::Util qw(min max); |
1714 | use List::Util qw(min max); |
1723 | |
1715 | |
1724 | our @ISA = CFPlus::UI::Container::; |
1716 | our @ISA = CFPlus::UI::Container::; |
1725 | |
1717 | |
1726 | sub add { |
|
|
1727 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1728 | |
|
|
1729 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1730 | $self->SUPER::add ($child); |
|
|
1731 | } |
|
|
1732 | |
|
|
1733 | sub _scale($$$) { |
1718 | sub _scale($$$) { |
1734 | my ($mode, $val, $max) = @_; |
1719 | my ($rel, $val, $max) = @_; |
1735 | |
1720 | |
1736 | $mode eq "abs" ? $val |
1721 | $rel ? $val * $max : $val |
1737 | : $mode eq "rel" ? $val * $max |
|
|
1738 | : 0 |
|
|
1739 | } |
1722 | } |
1740 | |
1723 | |
1741 | sub size_request { |
1724 | sub size_request { |
1742 | my ($self) = @_; |
1725 | my ($self) = @_; |
1743 | |
1726 | |
1744 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1727 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1745 | |
1728 | |
1746 | # determine overall size by querying abs widgets |
1729 | # determine overall size by querying abs widgets |
1747 | for my $child ($self->visible_children) { |
1730 | for my $child ($self->visible_children) { |
1748 | 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}; |
1749 | |
1734 | |
1750 | if ($pos eq "abs") { |
|
|
1751 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1752 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1753 | |
|
|
1754 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1735 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1755 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1736 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1756 | } |
1737 | } |
1757 | } |
1738 | } |
1758 | |
1739 | |
1759 | my $W = $x2 - $x1; |
1740 | my $W = $x2 - $x1; |
1760 | my $H = $y2 - $y1; |
1741 | my $H = $y2 - $y1; |
1761 | |
1742 | |
1762 | # now layout remaining widgets |
1743 | # now layout remaining widgets |
1763 | for my $child ($self->visible_children) { |
1744 | for my $child ($self->visible_children) { |
1764 | 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; |
1765 | |
1748 | |
1766 | if ($pos ne "abs") { |
|
|
1767 | $x = _scale $pos, $x, $W; |
|
|
1768 | $y = _scale $pos, $x, $H; |
|
|
1769 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1770 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1771 | |
|
|
1772 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1749 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1773 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1750 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1774 | } |
1751 | } |
1775 | } |
1752 | } |
1776 | |
1753 | |
1777 | my $W = $x2 - $x1; |
1754 | my $W = $x2 - $x1; |
1778 | my $H = $y2 - $y1; |
1755 | my $H = $y2 - $y1; |
… | |
… | |
1782 | |
1759 | |
1783 | sub invoke_size_allocate { |
1760 | sub invoke_size_allocate { |
1784 | my ($self, $W, $H) = @_; |
1761 | my ($self, $W, $H) = @_; |
1785 | |
1762 | |
1786 | for my $child ($self->visible_children) { |
1763 | for my $child ($self->visible_children) { |
1787 | 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; |
1788 | |
1766 | |
1789 | $x = _scale $pos, $x, $W; |
1767 | $x += $child->{c_halign} * $child->{req_w}; |
1790 | $y = _scale $pos, $x, $H; |
1768 | $y += $child->{c_valign} * $child->{req_h}; |
1791 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1792 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1793 | |
1769 | |
1794 | $child->configure ($x, $y, $w, $h); |
1770 | $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h}); |
1795 | } |
1771 | } |
1796 | |
1772 | |
1797 | 1 |
1773 | 1 |
1798 | } |
1774 | } |
1799 | |
1775 | |
… | |
… | |
1803 | |
1779 | |
1804 | our @ISA = CFPlus::UI::Container::; |
1780 | our @ISA = CFPlus::UI::Container::; |
1805 | |
1781 | |
1806 | sub size_request { |
1782 | sub size_request { |
1807 | my ($self) = @_; |
1783 | my ($self) = @_; |
|
|
1784 | |
|
|
1785 | my @children = $self->visible_children; |
1808 | |
1786 | |
1809 | $self->{vertical} |
1787 | $self->{vertical} |
1810 | ? ( |
1788 | ? ( |
1811 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1789 | (List::Util::max map $_->{req_w}, @children), |
1812 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1790 | (List::Util::sum map $_->{req_h}, @children), |
1813 | ) |
1791 | ) |
1814 | : ( |
1792 | : ( |
1815 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
1793 | (List::Util::sum map $_->{req_w}, @children), |
1816 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1794 | (List::Util::max map $_->{req_h}, @children), |
1817 | ) |
1795 | ) |
1818 | } |
1796 | } |
1819 | |
1797 | |
1820 | sub invoke_size_allocate { |
1798 | sub invoke_size_allocate { |
1821 | my ($self, $w, $h) = @_; |
1799 | my ($self, $w, $h) = @_; |
… | |
… | |
2062 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2040 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2063 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2041 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2064 | : ($self->{h} - $size->[1]) * 0.5); |
2042 | : ($self->{h} - $size->[1]) * 0.5); |
2065 | }; |
2043 | }; |
2066 | |
2044 | |
2067 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2045 | # unless ($self->{list}) { |
2068 | 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}; |
2069 | |
2053 | |
2070 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2054 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2071 | } |
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 | #} |
2072 | |
2064 | |
2073 | ############################################################################# |
2065 | ############################################################################# |
2074 | |
2066 | |
2075 | package CFPlus::UI::EntryBase; |
2067 | package CFPlus::UI::EntryBase; |
2076 | |
2068 | |
… | |
… | |
2861 | |
2853 | |
2862 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2854 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2863 | |
2855 | |
2864 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2856 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2865 | |
2857 | |
2866 | $self->invoke_mouse_motion ($ev, $x, $y) |
2858 | $self->invoke_mouse_motion ($ev, $x, $y); |
|
|
2859 | |
|
|
2860 | 1 |
2867 | } |
2861 | } |
2868 | |
2862 | |
2869 | sub invoke_mouse_motion { |
2863 | sub invoke_mouse_motion { |
2870 | my ($self, $ev, $x, $y) = @_; |
2864 | my ($self, $ev, $x, $y) = @_; |
2871 | |
2865 | |
… | |
… | |
2891 | |
2885 | |
2892 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2886 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2893 | |
2887 | |
2894 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2888 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2895 | |
2889 | |
2896 | ! ! $delta |
2890 | 1 |
2897 | } |
2891 | } |
2898 | |
2892 | |
2899 | sub update { |
2893 | sub update { |
2900 | my ($self) = @_; |
2894 | my ($self) = @_; |
2901 | |
2895 | |
… | |
… | |
3032 | } |
3026 | } |
3033 | |
3027 | |
3034 | sub size_request { |
3028 | sub size_request { |
3035 | my ($self) = @_; |
3029 | my ($self) = @_; |
3036 | |
3030 | |
3037 | my ($empty, $slider) = @{ $self->{children} }; |
3031 | my ($empty, $slider) = $self->visible_children; |
3038 | |
3032 | |
3039 | local $self->{children} = [$empty, $slider]; |
3033 | local $self->{children} = [$empty, $slider]; |
3040 | $self->SUPER::size_request |
3034 | $self->SUPER::size_request |
3041 | } |
3035 | } |
3042 | |
3036 | |
… | |
… | |
3474 | |
3468 | |
3475 | if ($self->{anim} && $self->{animspeed}) { |
3469 | if ($self->{anim} && $self->{animspeed}) { |
3476 | CFPlus::weaken (my $widget = $self); |
3470 | CFPlus::weaken (my $widget = $self); |
3477 | |
3471 | |
3478 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3472 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
3479 | $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; |
3473 | $widget->{anim_start} = $self->{animspeed} * int Event::time / $self->{animspeed}; |
3480 | $self->{timer} = Event->timer ( |
3474 | $self->{timer} = Event->timer ( |
3481 | parked => 1, |
3475 | parked => 1, |
3482 | cb => sub { |
3476 | cb => sub { |
3483 | return unless $::CONN && $widget; |
3477 | return unless $::CONN && $widget; |
3484 | |
3478 | |
… | |
… | |
3521 | |
3515 | |
3522 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3516 | if (my $anim = $::CONN->{anim}[$self->{anim}]) { |
3523 | if ($anim && @$anim) { |
3517 | if ($anim && @$anim) { |
3524 | delete $self->{wait_face}; |
3518 | delete $self->{wait_face}; |
3525 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
3519 | $self->{face} = $anim->[ $self->{frame} % @$anim ]; |
|
|
3520 | $self->{tex} = $::CONN->{texture}[ $::CONN->{faceid}[$self->{face}] ]; |
3526 | } |
3521 | } |
3527 | } |
3522 | } |
3528 | } |
3523 | } |
3529 | |
3524 | |
3530 | sub size_request { |
3525 | sub size_request { |
3531 | my ($self) = @_; |
3526 | my ($self) = @_; |
3532 | |
3527 | |
3533 | if ($::CONN) { |
3528 | if ($::CONN) { |
3534 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3529 | if (my $faceid = $::CONN->{faceid}[$self->{face}]) { |
3535 | if (my $tex = $::CONN->{texture}[$faceid]) { |
3530 | if (my $tex = $::CONN->{texture}[$faceid]) { |
|
|
3531 | $self->{tex} = $tex; |
3536 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3532 | return ($self->{size_w} || $tex->{w}, $self->{size_h} || $tex->{h}); |
3537 | } else { |
3533 | } else { |
3538 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3534 | $self->{wait_face} ||= $::CONN->connect_face_update ($faceid, sub { |
3539 | $self->realloc; |
3535 | $self->realloc; |
3540 | }); |
3536 | }); |
… | |
… | |
3562 | } |
3558 | } |
3563 | |
3559 | |
3564 | sub _draw { |
3560 | sub _draw { |
3565 | my ($self) = @_; |
3561 | my ($self) = @_; |
3566 | |
3562 | |
3567 | return unless $::CONN; |
|
|
3568 | |
|
|
3569 | $self->SUPER::_draw; |
3563 | $self->SUPER::_draw; |
3570 | |
3564 | |
3571 | my $faceid = $::CONN->{faceid}[$self->{face}] |
3565 | if (my $tex = $self->{tex}) { |
3572 | or return; |
|
|
3573 | |
|
|
3574 | my $tex = $::CONN->{texture}[$faceid]; |
|
|
3575 | |
|
|
3576 | if ($tex) { |
|
|
3577 | glEnable GL_TEXTURE_2D; |
3566 | glEnable GL_TEXTURE_2D; |
3578 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3567 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE; |
3579 | glColor 0, 0, 0, 1; |
3568 | glColor 0, 0, 0, 1; |
3580 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3569 | $tex->draw_quad_alpha (0, 0, $self->{w}, $self->{h}); |
3581 | glDisable GL_TEXTURE_2D; |
3570 | glDisable GL_TEXTURE_2D; |
… | |
… | |
3779 | buttonbar => (new CFPlus::UI::Buttonbar), |
3768 | buttonbar => (new CFPlus::UI::Buttonbar), |
3780 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3769 | multiplexer => (new CFPlus::UI::Multiplexer expand => 1), |
3781 | # filter => # will be put between multiplexer and $self |
3770 | # filter => # will be put between multiplexer and $self |
3782 | @_, |
3771 | @_, |
3783 | ); |
3772 | ); |
3784 | |
3773 | |
3785 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3774 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3786 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3775 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3787 | |
3776 | |
|
|
3777 | { |
|
|
3778 | Scalar::Util::weaken (my $wself = $self); |
|
|
3779 | |
|
|
3780 | $self->{multiplexer}->connect (c_add => sub { |
|
|
3781 | my ($mplex, $widgets) = @_; |
|
|
3782 | |
|
|
3783 | for my $child (@$widgets) { |
|
|
3784 | Scalar::Util::weaken $child; |
|
|
3785 | $child->{c_tab_} ||= do { |
|
|
3786 | my $tab = |
|
|
3787 | (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") |
|
|
3788 | ? $child->{c_tab} |
|
|
3789 | : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
|
|
3790 | |
|
|
3791 | $tab->connect (activate => sub { |
|
|
3792 | $wself->set_current_page ($child); |
|
|
3793 | }); |
|
|
3794 | |
|
|
3795 | $tab |
|
|
3796 | }; |
|
|
3797 | |
|
|
3798 | $self->{buttonbar}->add ($child->{c_tab_}); |
|
|
3799 | } |
|
|
3800 | }); |
|
|
3801 | |
|
|
3802 | $self->{multiplexer}->connect (c_remove => sub { |
|
|
3803 | my ($mplex, $widgets) = @_; |
|
|
3804 | |
|
|
3805 | for my $child (@$widgets) { |
|
|
3806 | $wself->{buttonbar}->remove ($child->{c_tab_}); |
|
|
3807 | } |
|
|
3808 | }); |
|
|
3809 | } |
|
|
3810 | |
3788 | $self |
3811 | $self |
3789 | } |
3812 | } |
3790 | |
3813 | |
3791 | sub add { |
3814 | sub add { |
|
|
3815 | my ($self, @widgets) = @_; |
|
|
3816 | |
|
|
3817 | $self->{multiplexer}->add (@widgets) |
|
|
3818 | } |
|
|
3819 | |
|
|
3820 | sub remove { |
|
|
3821 | my ($self, @widgets) = @_; |
|
|
3822 | |
|
|
3823 | $self->{multiplexer}->remove (@widgets) |
|
|
3824 | } |
|
|
3825 | |
|
|
3826 | sub pages { |
|
|
3827 | my ($self) = @_; |
|
|
3828 | $self->{multiplexer}->children |
|
|
3829 | } |
|
|
3830 | |
|
|
3831 | sub add_tab { |
3792 | my ($self, $title, $widget, $tooltip) = @_; |
3832 | my ($self, $title, $widget, $tooltip) = @_; |
3793 | |
3833 | |
3794 | CFPlus::weaken $self; |
3834 | $title = [$title, $tooltip] unless ref $title; |
|
|
3835 | $widget->{c_tab} = $title; |
3795 | |
3836 | |
3796 | $self->{buttonbar}->add (new CFPlus::UI::Button |
|
|
3797 | markup => $title, |
|
|
3798 | tooltip => $tooltip, |
|
|
3799 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3800 | ); |
|
|
3801 | |
|
|
3802 | $self->{multiplexer}->add ($widget); |
3837 | $self->add ($widget); |
3803 | } |
3838 | } |
3804 | |
3839 | |
3805 | sub get_current_page { |
3840 | sub get_current_page { |
3806 | my ($self) = @_; |
3841 | my ($self) = @_; |
3807 | |
3842 | |
… | |
… | |
4137 | while ($self->{refresh_hook}) { |
4172 | while ($self->{refresh_hook}) { |
4138 | $_->() |
4173 | $_->() |
4139 | for values %{delete $self->{refresh_hook}}; |
4174 | for values %{delete $self->{refresh_hook}}; |
4140 | } |
4175 | } |
4141 | |
4176 | |
4142 | if ($self->{realloc}) { |
4177 | while ($self->{realloc}) { |
4143 | my %queue; |
4178 | my %queue; |
4144 | my @queue; |
4179 | my @queue; |
4145 | my $widget; |
4180 | my $widget; |
4146 | |
4181 | |
4147 | outer: |
4182 | outer: |
… | |
… | |
4194 | } |
4229 | } |
4195 | } |
4230 | } |
4196 | |
4231 | |
4197 | delete $self->{realloc}{$widget+0}; |
4232 | delete $self->{realloc}{$widget+0}; |
4198 | } |
4233 | } |
4199 | } |
|
|
4200 | |
4234 | |
4201 | while (my $size_alloc = delete $self->{size_alloc}) { |
4235 | while (my $size_alloc = delete $self->{size_alloc}) { |
4202 | my @queue = sort { $b->{visible} <=> $a->{visible} } |
4236 | my @queue = sort { $a->{visible} <=> $b->{visible} } |
4203 | values %$size_alloc; |
4237 | values %$size_alloc; |
4204 | |
4238 | |
4205 | while () { |
4239 | while () { |
4206 | my $widget = pop @queue || last; |
4240 | my $widget = pop @queue || last; |
4207 | |
4241 | |
4208 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4242 | my ($w, $h) = @$widget{qw(alloc_w alloc_h)}; |
4209 | |
4243 | |
4210 | $w = 0 if $w < 0; |
|
|
4211 | $h = 0 if $h < 0; |
|
|
4212 | |
|
|
4213 | $w = max $widget->{min_w}, $w; |
4244 | $w = max $widget->{min_w}, $w; |
4214 | $h = max $widget->{min_h}, $h; |
4245 | $h = max $widget->{min_h}, $h; |
4215 | |
4246 | |
4216 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4247 | # $w = min $self->{w} - $widget->{x}, $w if $self->{w}; |
4217 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4248 | # $h = min $self->{h} - $widget->{y}, $h if $self->{h}; |
4218 | |
4249 | |
4219 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4250 | $w = min $widget->{max_w}, $w if exists $widget->{max_w}; |
4220 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4251 | $h = min $widget->{max_h}, $h if exists $widget->{max_h}; |
4221 | |
4252 | |
4222 | $w = int $w + 0.5; |
4253 | $w = int $w + 0.5; |
4223 | $h = int $h + 0.5; |
4254 | $h = int $h + 0.5; |
4224 | |
4255 | |
4225 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4256 | if ($widget->{w} != $w || $widget->{h} != $h || delete $widget->{force_size_alloc}) { |
4226 | $widget->{old_w} = $widget->{w}; |
4257 | $widget->{old_w} = $widget->{w}; |
4227 | $widget->{old_h} = $widget->{h}; |
4258 | $widget->{old_h} = $widget->{h}; |
4228 | |
4259 | |
4229 | $widget->{w} = $w; |
4260 | $widget->{w} = $w; |
4230 | $widget->{h} = $h; |
4261 | $widget->{h} = $h; |
4231 | |
4262 | |
4232 | $widget->emit (size_allocate => $w, $h); |
4263 | $widget->emit (size_allocate => $w, $h); |
|
|
4264 | } |
4233 | } |
4265 | } |
4234 | } |
4266 | } |
4235 | } |
4267 | } |
4236 | |
4268 | |
4237 | while ($self->{post_alloc_hook}) { |
4269 | while ($self->{post_alloc_hook}) { |