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.228 by root, Wed May 24 03:52:54 2006 UTC vs.
Revision 1.230 by root, Wed May 24 21:59:54 2006 UTC

144 144
145 $_->update 145 $_->update
146 for @widgets; 146 for @widgets;
147} 147}
148 148
149sub reconfigure_widgets {
150 # make a copy, otherwise C<for> complains about freed values.
151 my @widgets = values %WIDGET;
152
153 $_->reconfigure
154 for @widgets;
155}
156
149# call when resolution changes etc. 157# call when resolution changes etc.
150sub rescale_widgets { 158sub rescale_widgets {
151 my ($sx, $sy) = @_; 159 my ($sx, $sy) = @_;
152 160
153 # make a copy, otherwise for complains about freed values.
154 my @widgets = values %WIDGET; 161 for my $widget (values %WIDGET) {
155
156 for my $widget (@widgets) {
157 if ($widget->{toplevel}) { 162 if ($widget->{is_toplevel}) {
158 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; 163 $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x};
159 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; 164 $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w};
160 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; 165 $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w};
161 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; 166 $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w};
162 $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; 167 $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y};
163 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; 168 $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h};
164 $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; 169 $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h};
165 $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; 170 $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h};
166 } 171 }
167
168 $widget->reconfigure;
169 } 172 }
173
174 reconfigure_widgets;
170} 175}
171 176
172############################################################################# 177#############################################################################
173 178
174package CFClient::UI::Base; 179package CFClient::UI::Base;
816 821
817 my $slider = new CFClient::UI::Slider 822 my $slider = new CFClient::UI::Slider
818 vertical => 1, 823 vertical => 1,
819 range => [0, 0, 1, 0.01], # HACK fix 824 range => [0, 0, 1, 0.01], # HACK fix
820 connect_changed => sub { 825 connect_changed => sub {
821 $self->{vp}->set_offset (0, $_[1] * ($self->{vp}{child_h} - $self->{vp}{h})); 826 $self->{vp}->set_offset (0, $_[1]);
822 }, 827 },
823 ; 828 ;
824 829
825 $self = $class->SUPER::new ( 830 $self = $class->SUPER::new (
826 vp => (new CFClient::UI::ViewPort expand => 1), 831 vp => (new CFClient::UI::ViewPort expand => 1),
831 $self->{vp}->add ($self->{scrolled}); 836 $self->{vp}->add ($self->{scrolled});
832 $self->add ($self->{vp}); 837 $self->add ($self->{vp});
833 $self->add ($self->{slider}); 838 $self->add ($self->{slider});
834 839
835 $self 840 $self
841}
842
843sub size_allocate {
844 my ($self, $w, $h) = @_;
845
846 $self->SUPER::size_allocate ($w, $h);
847
848 my $child = $self->{vp}->child;
849 $self->{slider}->set_range ([$self->{slider}{range}[0], 0, $child->{h}, $self->{vp}{h}, 1]);
836} 850}
837 851
838#TODO# update range on size_allocate depending on child 852#TODO# update range on size_allocate depending on child
839# update viewport offset on scroll 853# update viewport offset on scroll
840 854
894 my $class = shift; 908 my $class = shift;
895 909
896 # TODO: user_x, user_y, overwrite moveto? 910 # TODO: user_x, user_y, overwrite moveto?
897 911
898 my $self = $class->SUPER::new ( 912 my $self = $class->SUPER::new (
899 bg => [1, 1, 1, 1], 913 bg => [1, 1, 1, 1],
900 border_bg => [1, 1, 1, 1], 914 border_bg => [1, 1, 1, 1],
901 border => 0.6, 915 border => 0.6,
902 toplevel => 1, 916 is_toplevel => 1,
903 can_events => 1, 917 can_events => 1,
904 @_ 918 @_
905 ); 919 );
906 920
907 $self->{title} &&= new CFClient::UI::Label 921 $self->{title} &&= new CFClient::UI::Label
908 align => 0, 922 align => 0,
3044} 3058}
3045 3059
3046sub size_allocate { 3060sub size_allocate {
3047 my ($self, $w, $h) = @_; 3061 my ($self, $w, $h) = @_;
3048 3062
3049 my $old_w = $self->{old_w}; $self->{old_w} = $w;
3050 my $old_h = $self->{old_h}; $self->{old_h} = $h;
3051
3052 CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h
3053 if $old_w && $old_h && ($old_w != $w || $old_h != $h);
3054
3055 for my $child ($self->children) { 3063 for my $child ($self->children) {
3056 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; 3064 my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)};
3057 3065
3058 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 3066 $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1
3059 if exists $child->{req_x}; 3067 if exists $child->{req_x};
3088} 3096}
3089 3097
3090sub add { 3098sub add {
3091 my ($self, @children) = @_; 3099 my ($self, @children) = @_;
3092 3100
3101 for (my @widgets = @children; my $w = pop @widgets; ) {
3102 push @widgets, $w->children;
3103 $w->{root} = $self;
3104 $w->{visible} = 1;
3105 }
3106
3093 for my $child (@children) { 3107 for my $child (@children) {
3094 $child->{toplevel} = 1; 3108 $child->{is_toplevel} = 1;
3095 3109
3096 # integerise window positions 3110 # integerise window positions
3097 $child->{x} = int $child->{x}; 3111 $child->{x} = int $child->{x};
3098 $child->{y} = int $child->{y}; 3112 $child->{y} = int $child->{y};
3099 } 3113 }
3100 3114
3101 $self->SUPER::add (@children); 3115 $self->SUPER::add (@children);
3102
3103 while (@children) {
3104 my $w = pop @children;
3105 push @children, $w->children;
3106 $w->{visible} = 1;
3107 }
3108} 3116}
3109 3117
3110sub remove { 3118sub remove {
3111 my ($self, @children) = @_; 3119 my ($self, @children) = @_;
3112 3120

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines