ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/UI.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/UI.pm (file contents):
Revision 1.407 by root, Sat Jul 21 23:31:31 2007 UTC vs.
Revision 1.413 by root, Mon Jul 23 15:30:45 2007 UTC

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
733sub children { 735sub children {
734 @{ $_[0]{children} } 736 @{ $_[0]{children} }
735} 737}
736 738
737sub remove { 739sub 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
748sub clear { 753sub clear {
776} 781}
777 782
778sub _draw { 783sub _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
786package CFPlus::UI::Bin; 791package CFPlus::UI::Bin;
796} 801}
797 802
798sub add { 803sub 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
805sub remove { 810sub remove {
806 my ($self, $widget) = @_; 811 my ($self, $widget) = @_;
1686 1691
1687use List::Util qw(min max); 1692use List::Util qw(min max);
1688 1693
1689our @ISA = CFPlus::UI::Container::; 1694our @ISA = CFPlus::UI::Container::;
1690 1695
1691sub 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
1698sub _scale($$$) { 1696sub _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
1706sub size_request { 1702sub 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
1748sub invoke_size_allocate { 1738sub 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
1769our @ISA = CFPlus::UI::Container::; 1758our @ISA = CFPlus::UI::Container::;
1770 1759
1771sub size_request { 1760sub 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
1785sub invoke_size_allocate { 1776sub invoke_size_allocate {
1786 my ($self, $w, $h) = @_; 1777 my ($self, $w, $h) = @_;
2840 2831
2841 $self->SUPER::invoke_button_down ($ev, $x, $y); 2832 $self->SUPER::invoke_button_down ($ev, $x, $y);
2842 2833
2843 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x]; 2834 $self->{click} = [$self->{range}[0], $self->{vertical} ? $y : $x];
2844 2835
2845 $self->invoke_mouse_motion ($ev, $x, $y) 2836 $self->invoke_mouse_motion ($ev, $x, $y);
2837
2838 1
2846} 2839}
2847 2840
2848sub invoke_mouse_motion { 2841sub invoke_mouse_motion {
2849 my ($self, $ev, $x, $y) = @_; 2842 my ($self, $ev, $x, $y) = @_;
2850 2843
2870 2863
2871 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2; 2864 my $pagepart = $ev->{mod} & CFPlus::KMOD_SHIFT ? 1 : 0.2;
2872 2865
2873 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart); 2866 $self->set_value ($self->{range}[0] + $delta * $self->{range}[3] * $pagepart);
2874 2867
2875 ! ! $delta 2868 1
2876} 2869}
2877 2870
2878sub update { 2871sub update {
2879 my ($self) = @_; 2872 my ($self) = @_;
2880 2873
3011} 3004}
3012 3005
3013sub size_request { 3006sub size_request {
3014 my ($self) = @_; 3007 my ($self) = @_;
3015 3008
3016 my ($empty, $slider) = @{ $self->{children} }; 3009 my ($empty, $slider) = $self->visible_children;
3017 3010
3018 local $self->{children} = [$empty, $slider]; 3011 local $self->{children} = [$empty, $slider];
3019 $self->SUPER::size_request 3012 $self->SUPER::size_request
3020} 3013}
3021 3014
3757 ); 3750 );
3758 3751
3759 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3752 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3760 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 3753 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3761 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
3762 $self 3789 $self
3763} 3790}
3764 3791
3765sub add { 3792sub add {
3793 my ($self, @widgets) = @_;
3794
3795 $self->{multiplexer}->add (@widgets)
3796}
3797
3798sub remove {
3799 my ($self, @widgets) = @_;
3800
3801 $self->{multiplexer}->remove (@widgets)
3802}
3803
3804sub add_tab {
3766 my ($self, $title, $widget, $tooltip) = @_; 3805 my ($self, $title, $widget, $tooltip) = @_;
3767 3806
3768 CFPlus::weaken $self; 3807 $title = [$title, $tooltip] unless ref $title;
3808 $widget->{c_tab} = $title;
3769 3809
3770 $self->{buttonbar}->add (new CFPlus::UI::Button
3771 markup => $title,
3772 tooltip => $tooltip,
3773 on_activate => sub { $self->set_current_page ($widget) },
3774 );
3775
3776 $self->{multiplexer}->add ($widget); 3810 $self->add ($widget);
3777} 3811}
3778 3812
3779sub get_current_page { 3813sub get_current_page {
3780 my ($self) = @_; 3814 my ($self) = @_;
3781 3815

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines