… | |
… | |
725 | @{$self->{children}}, @widgets |
725 | @{$self->{children}}, @widgets |
726 | ]; |
726 | ]; |
727 | |
727 | |
728 | $self->realloc; |
728 | $self->realloc; |
729 | |
729 | |
|
|
730 | $self->emit (c_add => \@widgets); |
|
|
731 | |
730 | map $_+0, @widgets |
732 | map $_+0, @widgets |
731 | } |
733 | } |
732 | |
734 | |
733 | sub children { |
735 | sub children { |
734 | @{ $_[0]{children} } |
736 | @{ $_[0]{children} } |
735 | } |
737 | } |
736 | |
738 | |
737 | sub remove { |
739 | sub remove { |
738 | my ($self, $child) = @_; |
740 | my ($self, @widgets) = @_; |
739 | |
741 | |
|
|
742 | $self->emit (c_remove => \@widgets); |
|
|
743 | |
|
|
744 | for my $child (@widgets) { |
740 | delete $child->{parent}; |
745 | delete $child->{parent}; |
741 | $child->hide; |
746 | $child->hide; |
742 | |
|
|
743 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
747 | $self->{children} = [ grep $_ != $child, @{ $self->{children} } ]; |
|
|
748 | } |
744 | |
749 | |
745 | $self->realloc; |
750 | $self->realloc; |
746 | } |
751 | } |
747 | |
752 | |
748 | sub clear { |
753 | sub clear { |
… | |
… | |
776 | } |
781 | } |
777 | |
782 | |
778 | sub _draw { |
783 | sub _draw { |
779 | my ($self) = @_; |
784 | my ($self) = @_; |
780 | |
785 | |
781 | $_->draw for @{$self->{children}}; |
786 | $_->draw for $self->visible_children; |
782 | } |
787 | } |
783 | |
788 | |
784 | ############################################################################# |
789 | ############################################################################# |
785 | |
790 | |
786 | package CFPlus::UI::Bin; |
791 | package CFPlus::UI::Bin; |
… | |
… | |
796 | } |
801 | } |
797 | |
802 | |
798 | sub add { |
803 | sub add { |
799 | my ($self, $child) = @_; |
804 | my ($self, $child) = @_; |
800 | |
805 | |
801 | $self->SUPER::remove ($_) for @{ $self->{children} }; |
806 | $self->clear; |
802 | $self->SUPER::add ($child); |
807 | $self->SUPER::add ($child); |
803 | } |
808 | } |
804 | |
809 | |
805 | sub remove { |
810 | sub remove { |
806 | my ($self, $widget) = @_; |
811 | my ($self, $widget) = @_; |
… | |
… | |
1686 | |
1691 | |
1687 | use List::Util qw(min max); |
1692 | use List::Util qw(min max); |
1688 | |
1693 | |
1689 | our @ISA = CFPlus::UI::Container::; |
1694 | our @ISA = CFPlus::UI::Container::; |
1690 | |
1695 | |
1691 | sub add_fixed { |
|
|
1692 | my ($self, $child, $posmode, $x, $y, $sizemode, $w, $h) = @_; |
|
|
1693 | |
|
|
1694 | $child->{_fixed} = [$posmode, $x, $y, $sizemode, $w, $h]; |
|
|
1695 | $self->SUPER::add ($child); |
|
|
1696 | } |
|
|
1697 | |
|
|
1698 | sub _scale($$$) { |
1696 | sub _scale($$$) { |
1699 | my ($mode, $val, $max) = @_; |
1697 | my ($rel, $val, $max) = @_; |
1700 | |
1698 | |
1701 | $mode eq "abs" ? $val |
1699 | $rel ? $val * $max : $val |
1702 | : $mode eq "rel" ? $val * $max |
|
|
1703 | : 0 |
|
|
1704 | } |
1700 | } |
1705 | |
1701 | |
1706 | sub size_request { |
1702 | sub size_request { |
1707 | my ($self) = @_; |
1703 | my ($self) = @_; |
1708 | |
1704 | |
1709 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1705 | my ($x1, $y1, $x2, $y2) = (0, 0, 0, 0); |
1710 | |
1706 | |
1711 | # determine overall size by querying abs widgets |
1707 | # determine overall size by querying abs widgets |
1712 | for my $child ($self->visible_children) { |
1708 | for my $child ($self->visible_children) { |
1713 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1709 | unless ($child->{c_rel}) { |
|
|
1710 | my $x = $child->{c_x}; |
|
|
1711 | my $y = $child->{c_y}; |
1714 | |
1712 | |
1715 | if ($pos eq "abs") { |
|
|
1716 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1717 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1718 | |
|
|
1719 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1713 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1720 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1714 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1721 | } |
1715 | } |
1722 | } |
1716 | } |
1723 | |
1717 | |
1724 | my $W = $x2 - $x1; |
1718 | my $W = $x2 - $x1; |
1725 | my $H = $y2 - $y1; |
1719 | my $H = $y2 - $y1; |
1726 | |
1720 | |
1727 | # now layout remaining widgets |
1721 | # now layout remaining widgets |
1728 | for my $child ($self->visible_children) { |
1722 | for my $child ($self->visible_children) { |
1729 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1723 | if ($child->{c_rel}) { |
|
|
1724 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1725 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1730 | |
1726 | |
1731 | if ($pos ne "abs") { |
|
|
1732 | $x = _scale $pos, $x, $W; |
|
|
1733 | $y = _scale $pos, $x, $H; |
|
|
1734 | $w = _scale $size, $w, $child->{req_w}; |
|
|
1735 | $h = _scale $size, $h, $child->{req_h}; |
|
|
1736 | |
|
|
1737 | $x1 = min $x1, $x; $x2 = max $x2, $x + $w; |
1727 | $x1 = min $x1, $x; $x2 = max $x2, $x + $child->{req_w}; |
1738 | $y1 = min $y1, $y; $y2 = max $y2, $y + $h; |
1728 | $y1 = min $y1, $y; $y2 = max $y2, $y + $child->{req_h}; |
1739 | } |
1729 | } |
1740 | } |
1730 | } |
1741 | |
1731 | |
1742 | my $W = $x2 - $x1; |
1732 | my $W = $x2 - $x1; |
1743 | my $H = $y2 - $y1; |
1733 | my $H = $y2 - $y1; |
… | |
… | |
1747 | |
1737 | |
1748 | sub invoke_size_allocate { |
1738 | sub invoke_size_allocate { |
1749 | my ($self, $W, $H) = @_; |
1739 | my ($self, $W, $H) = @_; |
1750 | |
1740 | |
1751 | for my $child ($self->visible_children) { |
1741 | for my $child ($self->visible_children) { |
1752 | my ($pos, $x, $y, $size, $w, $h) = @{ $child->{_fixed} }; |
1742 | my $x = _scale $child->{c_rel}, $child->{c_x}, $W; |
|
|
1743 | my $y = _scale $child->{c_rel}, $child->{c_y}, $H; |
1753 | |
1744 | |
1754 | $x = _scale $pos, $x, $W; |
1745 | $x += $child->{c_halign} * $child->{req_w}; |
1755 | $y = _scale $pos, $x, $H; |
1746 | $y += $child->{c_valign} * $child->{req_h}; |
1756 | $w = _scale $size, $w, $W; |
|
|
1757 | $h = _scale $size, $h, $H; |
|
|
1758 | |
1747 | |
1759 | $child->configure ($x, $y, $w, $h); |
1748 | $child->configure (int $x, int $y, $child->{req_w}, $child->{req_h}); |
1760 | } |
1749 | } |
1761 | |
1750 | |
1762 | 1 |
1751 | 1 |
1763 | } |
1752 | } |
1764 | |
1753 | |
… | |
… | |
1768 | |
1757 | |
1769 | our @ISA = CFPlus::UI::Container::; |
1758 | our @ISA = CFPlus::UI::Container::; |
1770 | |
1759 | |
1771 | sub size_request { |
1760 | sub size_request { |
1772 | my ($self) = @_; |
1761 | my ($self) = @_; |
|
|
1762 | |
|
|
1763 | my @children = $self->visible_children; |
1773 | |
1764 | |
1774 | $self->{vertical} |
1765 | $self->{vertical} |
1775 | ? ( |
1766 | ? ( |
1776 | (List::Util::max map $_->{req_w}, @{$self->{children}}), |
1767 | (List::Util::max map $_->{req_w}, @children), |
1777 | (List::Util::sum map $_->{req_h}, @{$self->{children}}), |
1768 | (List::Util::sum map $_->{req_h}, @children), |
1778 | ) |
1769 | ) |
1779 | : ( |
1770 | : ( |
1780 | (List::Util::sum map $_->{req_w}, @{$self->{children}}), |
1771 | (List::Util::sum map $_->{req_w}, @children), |
1781 | (List::Util::max map $_->{req_h}, @{$self->{children}}), |
1772 | (List::Util::max map $_->{req_h}, @children), |
1782 | ) |
1773 | ) |
1783 | } |
1774 | } |
1784 | |
1775 | |
1785 | sub invoke_size_allocate { |
1776 | sub invoke_size_allocate { |
1786 | my ($self, $w, $h) = @_; |
1777 | my ($self, $w, $h) = @_; |
… | |
… | |
2027 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2018 | $self->{oy} = int ($self->{valign} < 0 ? $self->{padding_y} |
2028 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2019 | : $self->{valign} > 0 ? $self->{h} - $size->[1] - $self->{padding_y} |
2029 | : ($self->{h} - $size->[1]) * 0.5); |
2020 | : ($self->{h} - $size->[1]) * 0.5); |
2030 | }; |
2021 | }; |
2031 | |
2022 | |
2032 | my $w = List::Util::min $self->{w} + 4, $size->[0]; |
2023 | # unless ($self->{list}) { |
2033 | my $h = List::Util::min $self->{h} + 2, $size->[1]; |
2024 | # $self->{list} = CFPlus::OpenGL::glGenList; |
|
|
2025 | # CFPlus::OpenGL::glNewList $self->{list}; |
|
|
2026 | # $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
|
|
2027 | # CFPlus::OpenGL::glEndList; |
|
|
2028 | # } |
|
|
2029 | # |
|
|
2030 | # CFPlus::OpenGL::glCallList $self->{list}; |
2034 | |
2031 | |
2035 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2032 | $self->{layout}->render ($self->{ox}, $self->{oy}, $self->{style}); |
2036 | } |
2033 | } |
|
|
2034 | |
|
|
2035 | #sub destroy { |
|
|
2036 | # my ($self) = @_; |
|
|
2037 | # |
|
|
2038 | # CFPlus::OpenGL::glDeleteList delete $self->{list} if $self->{list}; |
|
|
2039 | # |
|
|
2040 | # $self->SUPER::destroy; |
|
|
2041 | #} |
2037 | |
2042 | |
2038 | ############################################################################# |
2043 | ############################################################################# |
2039 | |
2044 | |
2040 | package CFPlus::UI::EntryBase; |
2045 | package CFPlus::UI::EntryBase; |
2041 | |
2046 | |
… | |
… | |
2826 | |
2831 | |
2827 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2832 | $self->SUPER::invoke_button_down ($ev, $x, $y); |
2828 | |
2833 | |
2829 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2834 | $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; |
2830 | |
2835 | |
2831 | $self->invoke_mouse_motion ($ev, $x, $y) |
2836 | $self->invoke_mouse_motion ($ev, $x, $y); |
|
|
2837 | |
|
|
2838 | 1 |
2832 | } |
2839 | } |
2833 | |
2840 | |
2834 | sub invoke_mouse_motion { |
2841 | sub invoke_mouse_motion { |
2835 | my ($self, $ev, $x, $y) = @_; |
2842 | my ($self, $ev, $x, $y) = @_; |
2836 | |
2843 | |
… | |
… | |
2856 | |
2863 | |
2857 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2864 | my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; |
2858 | |
2865 | |
2859 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2866 | $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); |
2860 | |
2867 | |
2861 | ! ! $delta |
2868 | 1 |
2862 | } |
2869 | } |
2863 | |
2870 | |
2864 | sub update { |
2871 | sub update { |
2865 | my ($self) = @_; |
2872 | my ($self) = @_; |
2866 | |
2873 | |
… | |
… | |
2997 | } |
3004 | } |
2998 | |
3005 | |
2999 | sub size_request { |
3006 | sub size_request { |
3000 | my ($self) = @_; |
3007 | my ($self) = @_; |
3001 | |
3008 | |
3002 | my ($empty, $slider) = @{ $self->{children} }; |
3009 | my ($empty, $slider) = $self->visible_children; |
3003 | |
3010 | |
3004 | local $self->{children} = [$empty, $slider]; |
3011 | local $self->{children} = [$empty, $slider]; |
3005 | $self->SUPER::size_request |
3012 | $self->SUPER::size_request |
3006 | } |
3013 | } |
3007 | |
3014 | |
… | |
… | |
3743 | ); |
3750 | ); |
3744 | |
3751 | |
3745 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3752 | $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; |
3746 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3753 | $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); |
3747 | |
3754 | |
|
|
3755 | { |
|
|
3756 | Scalar::Util::weaken (my $wself = $self); |
|
|
3757 | |
|
|
3758 | $self->{multiplexer}->connect (c_add => sub { |
|
|
3759 | my ($mplex, $widgets) = @_; |
|
|
3760 | |
|
|
3761 | for my $child (@$widgets) { |
|
|
3762 | Scalar::Util::weaken $child; |
|
|
3763 | $child->{c_tab_} ||= do { |
|
|
3764 | my $tab = |
|
|
3765 | (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base") |
|
|
3766 | ? $child->{c_tab} |
|
|
3767 | : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1]; |
|
|
3768 | |
|
|
3769 | $tab->connect (activate => sub { |
|
|
3770 | $wself->set_current_page ($child); |
|
|
3771 | }); |
|
|
3772 | |
|
|
3773 | $tab |
|
|
3774 | }; |
|
|
3775 | |
|
|
3776 | $self->{buttonbar}->add ($child->{c_tab_}); |
|
|
3777 | } |
|
|
3778 | }); |
|
|
3779 | |
|
|
3780 | $self->{multiplexer}->connect (c_remove => sub { |
|
|
3781 | my ($mplex, $widgets) = @_; |
|
|
3782 | |
|
|
3783 | for my $child (@$widgets) { |
|
|
3784 | $wself->{buttonbar}->remove ($child->{c_tab_}); |
|
|
3785 | } |
|
|
3786 | }); |
|
|
3787 | } |
|
|
3788 | |
3748 | $self |
3789 | $self |
3749 | } |
3790 | } |
3750 | |
3791 | |
3751 | sub add { |
3792 | sub add { |
|
|
3793 | my ($self, @widgets) = @_; |
|
|
3794 | |
|
|
3795 | $self->{multiplexer}->add (@widgets) |
|
|
3796 | } |
|
|
3797 | |
|
|
3798 | sub remove { |
|
|
3799 | my ($self, @widgets) = @_; |
|
|
3800 | |
|
|
3801 | $self->{multiplexer}->remove (@widgets) |
|
|
3802 | } |
|
|
3803 | |
|
|
3804 | sub add_tab { |
3752 | my ($self, $title, $widget, $tooltip) = @_; |
3805 | my ($self, $title, $widget, $tooltip) = @_; |
3753 | |
3806 | |
3754 | CFPlus::weaken $self; |
3807 | $title = [$title, $tooltip] unless ref $title; |
|
|
3808 | $widget->{c_tab} = $title; |
3755 | |
3809 | |
3756 | $self->{buttonbar}->add (new CFPlus::UI::Button |
|
|
3757 | markup => $title, |
|
|
3758 | tooltip => $tooltip, |
|
|
3759 | on_activate => sub { $self->set_current_page ($widget) }, |
|
|
3760 | ); |
|
|
3761 | |
|
|
3762 | $self->{multiplexer}->add ($widget); |
3810 | $self->add ($widget); |
3763 | } |
3811 | } |
3764 | |
3812 | |
3765 | sub get_current_page { |
3813 | sub get_current_page { |
3766 | my ($self) = @_; |
3814 | my ($self) = @_; |
3767 | |
3815 | |