… | |
… | |
11 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
11 | our ($FOCUS, $HOVER, $GRAB); # various widgets |
12 | |
12 | |
13 | our $ROOT; |
13 | our $ROOT; |
14 | our $TOOLTIP; |
14 | our $TOOLTIP; |
15 | our $BUTTON_STATE; |
15 | our $BUTTON_STATE; |
|
|
16 | |
|
|
17 | our %WIDGET; # all widgets, weak-referenced |
16 | |
18 | |
17 | sub check_tooltip { |
19 | sub check_tooltip { |
18 | if (!$GRAB) { |
20 | if (!$GRAB) { |
19 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
21 | for (my $widget = $HOVER; $widget; $widget = $widget->{parent}) { |
20 | if (length $widget->{tooltip}) { |
22 | if (length $widget->{tooltip}) { |
… | |
… | |
132 | |
134 | |
133 | for (@$vals) { |
135 | for (@$vals) { |
134 | my $i = int $_ + $rem; |
136 | my $i = int $_ + $rem; |
135 | $rem += $_ - $i; |
137 | $rem += $_ - $i; |
136 | $_ = $i; |
138 | $_ = $i; |
|
|
139 | } |
|
|
140 | } |
|
|
141 | |
|
|
142 | # call when resolution changes etc. |
|
|
143 | sub rescale_widgets { |
|
|
144 | my ($sx, $sy) = @_; |
|
|
145 | |
|
|
146 | for my $widget (values %WIDGET) { |
|
|
147 | if ($widget->{toplevel}) { |
|
|
148 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
|
|
149 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
|
|
150 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
|
|
151 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
|
|
152 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
|
|
153 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
|
|
154 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
|
|
155 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
|
|
156 | } |
|
|
157 | |
|
|
158 | $widget->reconfigure; |
137 | } |
159 | } |
138 | } |
160 | } |
139 | |
161 | |
140 | ############################################################################# |
162 | ############################################################################# |
141 | |
163 | |
… | |
… | |
160 | if (/^connect_(.*)$/) { |
182 | if (/^connect_(.*)$/) { |
161 | $self->connect ($1 => delete $self->{$_}); |
183 | $self->connect ($1 => delete $self->{$_}); |
162 | } |
184 | } |
163 | } |
185 | } |
164 | |
186 | |
|
|
187 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
|
|
188 | |
165 | $self |
189 | $self |
166 | } |
190 | } |
167 | |
191 | |
168 | sub destroy { |
192 | sub destroy { |
169 | my ($self) = @_; |
193 | my ($self) = @_; |
… | |
… | |
242 | |
266 | |
243 | sub size_allocate { |
267 | sub size_allocate { |
244 | # nothing to be done |
268 | # nothing to be done |
245 | } |
269 | } |
246 | |
270 | |
247 | sub children { |
|
|
248 | } |
|
|
249 | |
|
|
250 | # call when resolution changes etc. |
|
|
251 | sub reconfigure { |
271 | sub reconfigure { |
252 | my ($self) = @_; |
272 | my ($self) = @_; |
253 | |
|
|
254 | $_->reconfigure |
|
|
255 | for $self->children; |
|
|
256 | |
273 | |
257 | $self->check_size (1); |
274 | $self->check_size (1); |
258 | $self->update; |
275 | $self->update; |
|
|
276 | } |
|
|
277 | |
|
|
278 | sub children { |
259 | } |
279 | } |
260 | |
280 | |
261 | sub set_max_size { |
281 | sub set_max_size { |
262 | my ($self, $w, $h) = @_; |
282 | my ($self, $w, $h) = @_; |
263 | |
283 | |
… | |
… | |
417 | } |
437 | } |
418 | |
438 | |
419 | sub DESTROY { |
439 | sub DESTROY { |
420 | my ($self) = @_; |
440 | my ($self) = @_; |
421 | |
441 | |
|
|
442 | delete $WIDGET{$self+0}; |
422 | #$self->deactivate; |
443 | #$self->deactivate; |
423 | } |
444 | } |
424 | |
445 | |
425 | ############################################################################# |
446 | ############################################################################# |
426 | |
447 | |
… | |
… | |
840 | |
861 | |
841 | my $self = $class->SUPER::new ( |
862 | my $self = $class->SUPER::new ( |
842 | bg => [1, 1, 1, 1], |
863 | bg => [1, 1, 1, 1], |
843 | border_bg => [1, 1, 1, 1], |
864 | border_bg => [1, 1, 1, 1], |
844 | border => 0.6, |
865 | border => 0.6, |
|
|
866 | toplevel => 1, |
845 | can_events => 1, |
867 | can_events => 1, |
846 | @_ |
868 | @_ |
847 | ); |
869 | ); |
848 | |
870 | |
849 | $self->{title} &&= new CFClient::UI::Label |
871 | $self->{title} &&= new CFClient::UI::Label |
… | |
… | |
2765 | } |
2787 | } |
2766 | |
2788 | |
2767 | sub size_allocate { |
2789 | sub size_allocate { |
2768 | my ($self, $w, $h) = @_; |
2790 | my ($self, $w, $h) = @_; |
2769 | |
2791 | |
2770 | my $old_w = $self->{old_w}; |
2792 | my $old_w = $self->{old_w}; $self->{old_w} = $w; |
2771 | my $old_h = $self->{old_h}; |
2793 | my $old_h = $self->{old_h}; $self->{old_h} = $h; |
2772 | |
2794 | |
2773 | if ($old_w && $old_h) { |
2795 | CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h |
2774 | for my $child ($self->children) { |
2796 | if $old_w && $old_h && ($old_w != $w || $old_h != $h); |
2775 | $child->{x} = int 0.5 + $child->{x} * $w / $old_w; |
|
|
2776 | $child->{w} = int 0.5 + $child->{w} * $w / $old_w; |
|
|
2777 | $child->{req_w} = int 0.5 + $child->{req_w} * $w / $old_w if exists $child->{req_w}; |
|
|
2778 | $child->{user_w} = int 0.5 + $child->{user_w} * $w / $old_w if exists $child->{user_w}; |
|
|
2779 | $child->{y} = int 0.5 + $child->{y} * $h / $old_h; |
|
|
2780 | $child->{h} = int 0.5 + $child->{h} * $h / $old_h; |
|
|
2781 | $child->{req_h} = int 0.5 + $child->{req_h} * $h / $old_h if exists $child->{req_h}; |
|
|
2782 | $child->{user_h} = int 0.5 + $child->{user_h} * $h / $old_h if exists $child->{user_h}; |
|
|
2783 | } |
|
|
2784 | } |
|
|
2785 | |
2797 | |
2786 | for my $child ($self->children) { |
2798 | for my $child ($self->children) { |
2787 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2799 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2788 | |
2800 | |
2789 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2801 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2790 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2802 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2791 | $child->configure ($X, $Y, $W, $H); |
2803 | $child->configure ($X, $Y, $W, $H); |
2792 | } |
2804 | } |
2793 | |
|
|
2794 | $self->{old_w} = $w; |
|
|
2795 | $self->{old_h} = $h; |
|
|
2796 | } |
2805 | } |
2797 | |
2806 | |
2798 | sub coord2local { |
2807 | sub coord2local { |
2799 | my ($self, $x, $y) = @_; |
2808 | my ($self, $x, $y) = @_; |
2800 | |
2809 | |
… | |
… | |
2813 | $self->check_size; |
2822 | $self->check_size; |
2814 | $::WANT_REFRESH++; |
2823 | $::WANT_REFRESH++; |
2815 | } |
2824 | } |
2816 | |
2825 | |
2817 | sub add { |
2826 | sub add { |
2818 | my ($self, $child) = @_; |
2827 | my ($self, @children) = @_; |
2819 | |
2828 | |
|
|
2829 | for my $child (@children) { |
|
|
2830 | $child->{toplevel} = 1; |
|
|
2831 | |
2820 | # integerise window positions |
2832 | # integerise window positions |
2821 | $child->{x} = int $child->{x}; |
2833 | $child->{x} = int $child->{x}; |
2822 | $child->{y} = int $child->{y}; |
2834 | $child->{y} = int $child->{y}; |
|
|
2835 | } |
2823 | |
2836 | |
2824 | $self->SUPER::add ($child); |
2837 | $self->SUPER::add (@children); |
2825 | } |
2838 | } |
2826 | |
2839 | |
2827 | sub on_refresh { |
2840 | sub on_refresh { |
2828 | my ($self, $id, $cb) = @_; |
2841 | my ($self, $id, $cb) = @_; |
2829 | |
2842 | |