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.412 by root, Sun Jul 22 20:08:17 2007 UTC vs.
Revision 1.417 by root, Tue Jul 24 18:24:04 2007 UTC

273 $self->emit ("destroy"); 273 $self->emit ("destroy");
274 %$self = (); 274 %$self = ();
275} 275}
276 276
277sub TO_JSON { 277sub TO_JSON {
278 { __widget_ref__ => $_[0]{s_id} } 278 { __w_ => $_[0]{s_id} }
279} 279}
280 280
281sub show { 281sub show {
282 my ($self) = @_; 282 my ($self) = @_;
283 283
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) = @_;
948 $self->{view_x} = $x; 953 $self->{view_x} = $x;
949 $self->{view_y} = $y; 954 $self->{view_y} = $y;
950 955
951 $self->emit (changed => $x, $y); 956 $self->emit (changed => $x, $y);
952 $self->update; 957 $self->update;
958 }
959}
960
961sub set_center {
962 my ($self, $x, $y) = @_;
963
964 $self->set_offset ($x - $self->{w} * .5, $y - $self->{h} * .5);
965}
966
967sub 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);
953 } 976 }
954} 977}
955 978
956# 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
957sub coord2local { 980sub coord2local {
1070 my ($self, $widget) = @_; 1093 my ($self, $widget) = @_;
1071 1094
1072 $self->{vp}->add ($self->{child} = $widget); 1095 $self->{vp}->add ($self->{child} = $widget);
1073} 1096}
1074 1097
1098sub set_offset { shift->{vp}->set_offset (@_) }
1099sub set_center { shift->{vp}->set_center (@_) }
1100sub make_visible { shift->{vp}->make_visible (@_) }
1101
1075sub update_slider { 1102sub update_slider {
1076 my ($self) = @_; 1103 my ($self) = @_;
1077 1104
1078 my $child = ($self->{vp} or return)->child; 1105 my $child = ($self->{vp} or return)->child;
1079 1106
1753our @ISA = CFPlus::UI::Container::; 1780our @ISA = CFPlus::UI::Container::;
1754 1781
1755sub size_request { 1782sub size_request {
1756 my ($self) = @_; 1783 my ($self) = @_;
1757 1784
1785 my @children = $self->visible_children;
1786
1758 $self->{vertical} 1787 $self->{vertical}
1759 ? ( 1788 ? (
1760 (List::Util::max map $_->{req_w}, @{$self->{children}}), 1789 (List::Util::max map $_->{req_w}, @children),
1761 (List::Util::sum map $_->{req_h}, @{$self->{children}}), 1790 (List::Util::sum map $_->{req_h}, @children),
1762 ) 1791 )
1763 : ( 1792 : (
1764 (List::Util::sum map $_->{req_w}, @{$self->{children}}), 1793 (List::Util::sum map $_->{req_w}, @children),
1765 (List::Util::max map $_->{req_h}, @{$self->{children}}), 1794 (List::Util::max map $_->{req_h}, @children),
1766 ) 1795 )
1767} 1796}
1768 1797
1769sub invoke_size_allocate { 1798sub invoke_size_allocate {
1770 my ($self, $w, $h) = @_; 1799 my ($self, $w, $h) = @_;
2045 my $class = shift; 2074 my $class = shift;
2046 2075
2047 $class->SUPER::new ( 2076 $class->SUPER::new (
2048 fg => [1, 1, 1], 2077 fg => [1, 1, 1],
2049 bg => [0, 0, 0, 0.2], 2078 bg => [0, 0, 0, 0.2],
2050 active_bg => [1, 1, 1, 0.5], 2079 active_bg => [0, 0, 1, .2],
2051 active_fg => [0, 0, 0], 2080 active_fg => [1, 1, 1],
2081 active_outline => [1, 1, 0],
2052 can_hover => 1, 2082 can_hover => 1,
2053 can_focus => 1, 2083 can_focus => 1,
2054 valign => 0, 2084 valign => 0,
2055 can_events => 1, 2085 can_events => 1,
2056 ellipsise => 0, 2086 ellipsise => 0,
2213 2243
2214 unless (exists $self->{cur_h}) { 2244 unless (exists $self->{cur_h}) {
2215 my $text = substr $self->{text}, 0, $self->{cursor}; 2245 my $text = substr $self->{text}, 0, $self->{cursor};
2216 utf8::encode $text; 2246 utf8::encode $text;
2217 2247
2218 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text) 2248 @$self{qw(cur_x cur_y cur_h)} = $self->{layout}->cursor_pos (length $text);
2219 } 2249 }
2220 2250
2251 glColor_premultiply @{$self->{active_fg}};
2221 glBegin GL_LINES; 2252 glBegin GL_LINES;
2222 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy}; 2253 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy};
2223 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h}; 2254 glVertex 0.5 + $self->{cur_x} + $self->{ox}, $self->{cur_y} + $self->{oy} + $self->{cur_h};
2224 glEnd; 2255 glEnd;
2256
2257 glLineWidth 3;
2258 glColor @{$self->{active_outline}};
2259 glTranslate -.375, -.375;
2260 glBegin GL_LINE_LOOP;
2261 glVertex 0, 0;
2262 glVertex $self->{w}, 0;
2263 glVertex $self->{w}, $self->{h};
2264 glVertex 0, $self->{h};
2265 glEnd;
2266 glLineWidth 1;
2225 } 2267 }
2226} 2268}
2227 2269
2228############################################################################# 2270#############################################################################
2229 2271
2997} 3039}
2998 3040
2999sub size_request { 3041sub size_request {
3000 my ($self) = @_; 3042 my ($self) = @_;
3001 3043
3002 my ($empty, $slider) = @{ $self->{children} }; 3044 my ($empty, $slider) = $self->visible_children;
3003 3045
3004 local $self->{children} = [$empty, $slider]; 3046 local $self->{children} = [$empty, $slider];
3005 $self->SUPER::size_request 3047 $self->SUPER::size_request
3006} 3048}
3007 3049
3739 buttonbar => (new CFPlus::UI::Buttonbar), 3781 buttonbar => (new CFPlus::UI::Buttonbar),
3740 multiplexer => (new CFPlus::UI::Multiplexer expand => 1), 3782 multiplexer => (new CFPlus::UI::Multiplexer expand => 1),
3741 # filter => # will be put between multiplexer and $self 3783 # filter => # will be put between multiplexer and $self
3742 @_, 3784 @_,
3743 ); 3785 );
3744 3786
3745 $self->{filter}->add ($self->{multiplexer}) if $self->{filter}; 3787 $self->{filter}->add ($self->{multiplexer}) if $self->{filter};
3746 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer}); 3788 $self->SUPER::add ($self->{buttonbar}, $self->{filter} || $self->{multiplexer});
3747 3789
3790 {
3791 Scalar::Util::weaken (my $wself = $self);
3792
3793 $self->{multiplexer}->connect (c_add => sub {
3794 my ($mplex, $widgets) = @_;
3795
3796 for my $child (@$widgets) {
3797 Scalar::Util::weaken $child;
3798 $child->{c_tab_} ||= do {
3799 my $tab =
3800 (UNIVERSAL::isa $child->{c_tab}, "CFPlus::UI::Base")
3801 ? $child->{c_tab}
3802 : new CFPlus::UI::Button markup => $child->{c_tab}[0], tooltip => $child->{c_tab}[1];
3803
3804 $tab->connect (activate => sub {
3805 $wself->set_current_page ($child);
3806 });
3807
3808 $tab
3809 };
3810
3811 $self->{buttonbar}->add ($child->{c_tab_});
3812 }
3813 });
3814
3815 $self->{multiplexer}->connect (c_remove => sub {
3816 my ($mplex, $widgets) = @_;
3817
3818 for my $child (@$widgets) {
3819 $wself->{buttonbar}->remove ($child->{c_tab_});
3820 }
3821 });
3822 }
3823
3748 $self 3824 $self
3749} 3825}
3750 3826
3751sub add { 3827sub add {
3828 my ($self, @widgets) = @_;
3829
3830 $self->{multiplexer}->add (@widgets)
3831}
3832
3833sub remove {
3834 my ($self, @widgets) = @_;
3835
3836 $self->{multiplexer}->remove (@widgets)
3837}
3838
3839sub pages {
3840 my ($self) = @_;
3841 $self->{multiplexer}->children
3842}
3843
3844sub add_tab {
3752 my ($self, $title, $widget, $tooltip) = @_; 3845 my ($self, $title, $widget, $tooltip) = @_;
3753 3846
3754 CFPlus::weaken $self; 3847 $title = [$title, $tooltip] unless ref $title;
3848 $widget->{c_tab} = $title;
3755 3849
3756 unless (ref $title) {
3757 $title = new CFPlus::UI::Button
3758 markup => $title,
3759 tooltip => $tooltip,
3760 ;
3761 }
3762
3763 $title->connect (activate => sub { $self->set_current_page ($widget) });
3764 $self->{buttonbar}->add ($title);
3765
3766 $self->{multiplexer}->add ($widget); 3850 $self->add ($widget);
3767} 3851}
3768 3852
3769sub get_current_page { 3853sub get_current_page {
3770 my ($self) = @_; 3854 my ($self) = @_;
3771 3855

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines