… | |
… | |
144 | |
144 | |
145 | $_->update |
145 | $_->update |
146 | for @widgets; |
146 | for @widgets; |
147 | } |
147 | } |
148 | |
148 | |
|
|
149 | sub 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. |
150 | sub rescale_widgets { |
158 | sub 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 | |
174 | package CFClient::UI::Base; |
179 | package CFClient::UI::Base; |
… | |
… | |
903 | my $class = shift; |
908 | my $class = shift; |
904 | |
909 | |
905 | # TODO: user_x, user_y, overwrite moveto? |
910 | # TODO: user_x, user_y, overwrite moveto? |
906 | |
911 | |
907 | my $self = $class->SUPER::new ( |
912 | my $self = $class->SUPER::new ( |
908 | bg => [1, 1, 1, 1], |
913 | bg => [1, 1, 1, 1], |
909 | border_bg => [1, 1, 1, 1], |
914 | border_bg => [1, 1, 1, 1], |
910 | border => 0.6, |
915 | border => 0.6, |
911 | toplevel => 1, |
916 | is_toplevel => 1, |
912 | can_events => 1, |
917 | can_events => 1, |
913 | @_ |
918 | @_ |
914 | ); |
919 | ); |
915 | |
920 | |
916 | $self->{title} &&= new CFClient::UI::Label |
921 | $self->{title} &&= new CFClient::UI::Label |
917 | align => 0, |
922 | align => 0, |
… | |
… | |
3053 | } |
3058 | } |
3054 | |
3059 | |
3055 | sub size_allocate { |
3060 | sub size_allocate { |
3056 | my ($self, $w, $h) = @_; |
3061 | my ($self, $w, $h) = @_; |
3057 | |
3062 | |
3058 | my $old_w = $self->{old_w}; $self->{old_w} = $w; |
|
|
3059 | my $old_h = $self->{old_h}; $self->{old_h} = $h; |
|
|
3060 | |
|
|
3061 | CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h |
|
|
3062 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
|
|
3063 | |
|
|
3064 | for my $child ($self->children) { |
3063 | for my $child ($self->children) { |
3065 | 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)}; |
3066 | |
3065 | |
3067 | $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 |
3068 | if exists $child->{req_x}; |
3067 | if exists $child->{req_x}; |
… | |
… | |
3104 | $w->{root} = $self; |
3103 | $w->{root} = $self; |
3105 | $w->{visible} = 1; |
3104 | $w->{visible} = 1; |
3106 | } |
3105 | } |
3107 | |
3106 | |
3108 | for my $child (@children) { |
3107 | for my $child (@children) { |
3109 | $child->{toplevel} = 1; |
3108 | $child->{is_toplevel} = 1; |
3110 | |
3109 | |
3111 | # integerise window positions |
3110 | # integerise window positions |
3112 | $child->{x} = int $child->{x}; |
3111 | $child->{x} = int $child->{x}; |
3113 | $child->{y} = int $child->{y}; |
3112 | $child->{y} = int $child->{y}; |
3114 | } |
3113 | } |