… | |
… | |
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}) { |
… | |
… | |
29 | $TOOLTIP->set_tooltip_from ($widget); |
31 | $TOOLTIP->set_tooltip_from ($widget); |
30 | $TOOLTIP->show; |
32 | $TOOLTIP->show; |
31 | |
33 | |
32 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
34 | my ($x, $y) = $widget->coord2global ($widget->{w}, 0); |
33 | |
35 | |
34 | if ($x + $TOOLTIP->{w} > $::WIDTH) { |
|
|
35 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0); |
36 | ($x, $y) = $widget->coord2global (-$TOOLTIP->{w}, 0) |
36 | } |
37 | if $x + $TOOLTIP->{w} > $::WIDTH; |
37 | |
38 | |
38 | $TOOLTIP->move ($x, $y); |
39 | $TOOLTIP->move ($x, $y); |
39 | $TOOLTIP->check_size; |
40 | $TOOLTIP->check_size; |
40 | $TOOLTIP->update; |
41 | $TOOLTIP->update; |
41 | } |
42 | } |
… | |
… | |
132 | |
133 | |
133 | for (@$vals) { |
134 | for (@$vals) { |
134 | my $i = int $_ + $rem; |
135 | my $i = int $_ + $rem; |
135 | $rem += $_ - $i; |
136 | $rem += $_ - $i; |
136 | $_ = $i; |
137 | $_ = $i; |
|
|
138 | } |
|
|
139 | } |
|
|
140 | |
|
|
141 | # call when resolution changes etc. |
|
|
142 | sub rescale_widgets { |
|
|
143 | my ($sx, $sy) = @_; |
|
|
144 | |
|
|
145 | for my $widget (values %WIDGET) { |
|
|
146 | if ($widget->{toplevel}) { |
|
|
147 | $widget->{x} = int 0.5 + $widget->{x} * $sx if exists $widget->{x}; |
|
|
148 | $widget->{w} = int 0.5 + $widget->{w} * $sx if exists $widget->{w}; |
|
|
149 | $widget->{req_w} = int 0.5 + $widget->{req_w} * $sx if exists $widget->{req_w}; |
|
|
150 | $widget->{user_w} = int 0.5 + $widget->{user_w} * $sx if exists $widget->{user_w}; |
|
|
151 | $widget->{y} = int 0.5 + $widget->{y} * $sy if exists $widget->{y}; |
|
|
152 | $widget->{h} = int 0.5 + $widget->{h} * $sy if exists $widget->{h}; |
|
|
153 | $widget->{req_h} = int 0.5 + $widget->{req_h} * $sy if exists $widget->{req_h}; |
|
|
154 | $widget->{user_h} = int 0.5 + $widget->{user_h} * $sy if exists $widget->{user_h}; |
|
|
155 | } |
|
|
156 | |
|
|
157 | $widget->reconfigure; |
137 | } |
158 | } |
138 | } |
159 | } |
139 | |
160 | |
140 | ############################################################################# |
161 | ############################################################################# |
141 | |
162 | |
… | |
… | |
160 | if (/^connect_(.*)$/) { |
181 | if (/^connect_(.*)$/) { |
161 | $self->connect ($1 => delete $self->{$_}); |
182 | $self->connect ($1 => delete $self->{$_}); |
162 | } |
183 | } |
163 | } |
184 | } |
164 | |
185 | |
|
|
186 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
|
|
187 | |
165 | $self |
188 | $self |
166 | } |
189 | } |
167 | |
190 | |
168 | sub destroy { |
191 | sub destroy { |
169 | my ($self) = @_; |
192 | my ($self) = @_; |
… | |
… | |
242 | |
265 | |
243 | sub size_allocate { |
266 | sub size_allocate { |
244 | # nothing to be done |
267 | # nothing to be done |
245 | } |
268 | } |
246 | |
269 | |
247 | sub children { |
|
|
248 | } |
|
|
249 | |
|
|
250 | # call when resolution changes etc. |
|
|
251 | sub reconfigure { |
270 | sub reconfigure { |
252 | my ($self) = @_; |
271 | my ($self) = @_; |
253 | |
|
|
254 | $_->reconfigure |
|
|
255 | for $self->children; |
|
|
256 | |
272 | |
257 | $self->check_size (1); |
273 | $self->check_size (1); |
258 | $self->update; |
274 | $self->update; |
|
|
275 | } |
|
|
276 | |
|
|
277 | sub children { |
259 | } |
278 | } |
260 | |
279 | |
261 | sub set_max_size { |
280 | sub set_max_size { |
262 | my ($self, $w, $h) = @_; |
281 | my ($self, $w, $h) = @_; |
263 | |
282 | |
… | |
… | |
356 | glVertex $self->{w}, 0; |
375 | glVertex $self->{w}, 0; |
357 | glVertex $self->{w}, $self->{h}; |
376 | glVertex $self->{w}, $self->{h}; |
358 | glVertex 0 , $self->{h}; |
377 | glVertex 0 , $self->{h}; |
359 | glEnd; |
378 | glEnd; |
360 | glPopMatrix; |
379 | glPopMatrix; |
361 | CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
380 | #CFClient::UI::Label->new (w => $self->{w}, h => $self->{h}, text => $self, fontsize => 0)->_draw; |
362 | } |
381 | } |
363 | } |
382 | } |
364 | |
383 | |
365 | sub _draw { |
384 | sub _draw { |
366 | my ($self) = @_; |
385 | my ($self) = @_; |
… | |
… | |
417 | } |
436 | } |
418 | |
437 | |
419 | sub DESTROY { |
438 | sub DESTROY { |
420 | my ($self) = @_; |
439 | my ($self) = @_; |
421 | |
440 | |
|
|
441 | delete $WIDGET{$self+0}; |
422 | #$self->deactivate; |
442 | #$self->deactivate; |
423 | } |
443 | } |
424 | |
444 | |
425 | ############################################################################# |
445 | ############################################################################# |
426 | |
446 | |
… | |
… | |
840 | |
860 | |
841 | my $self = $class->SUPER::new ( |
861 | my $self = $class->SUPER::new ( |
842 | bg => [1, 1, 1, 1], |
862 | bg => [1, 1, 1, 1], |
843 | border_bg => [1, 1, 1, 1], |
863 | border_bg => [1, 1, 1, 1], |
844 | border => 0.6, |
864 | border => 0.6, |
|
|
865 | toplevel => 1, |
845 | can_events => 1, |
866 | can_events => 1, |
846 | @_ |
867 | @_ |
847 | ); |
868 | ); |
848 | |
869 | |
849 | $self->{title} &&= new CFClient::UI::Label |
870 | $self->{title} &&= new CFClient::UI::Label |
… | |
… | |
2668 | ? "<b>$item->{count} ×</b> $item->{text}" |
2689 | ? "<b>$item->{count} ×</b> $item->{text}" |
2669 | : $item->{text}; |
2690 | : $item->{text}; |
2670 | |
2691 | |
2671 | for ($short) { |
2692 | for ($short) { |
2672 | s/^\s+//; |
2693 | s/^\s+//; |
2673 | s/\012.*/…/s; |
2694 | s/\s+/ /g; |
2674 | my $len = int 40 / $item->{fontsize}; |
2695 | my $len = int 40 / $item->{fontsize}; |
2675 | substr $_, $len, length, "…" if $len < length; |
2696 | substr $_, $len, length, "…" if $len < length; |
2676 | } |
2697 | } |
2677 | |
2698 | |
2678 | new CFClient::UI::Label |
2699 | new CFClient::UI::Label |
2679 | markup => $short, |
2700 | markup => $short, |
2680 | tooltip => $item->{tooltip}, |
2701 | tooltip => $item->{tooltip}, |
2681 | tooltip_font => $::FONT_PROP, |
2702 | tooltip_font => $::FONT_PROP, |
2682 | tooltip_width => 0.67, |
2703 | tooltip_width => 0.67, |
2683 | fontsize => $item->{fontsize}, |
2704 | fontsize => $item->{fontsize}, |
2684 | color => $item->{color}, |
2705 | fg => $item->{fg}, |
2685 | can_events => 1, |
2706 | can_events => 1, |
2686 | can_hover => 1 |
2707 | can_hover => 1 |
2687 | }; |
2708 | }; |
2688 | } |
2709 | } |
2689 | |
2710 | |
… | |
… | |
2716 | id => ++$self->{id}, |
2737 | id => ++$self->{id}, |
2717 | text => $text, |
2738 | text => $text, |
2718 | timeout => $timeout, |
2739 | timeout => $timeout, |
2719 | tooltip => $text, |
2740 | tooltip => $text, |
2720 | fontsize => 0.8, |
2741 | fontsize => 0.8, |
2721 | color => [0.8, 0.8, 0.8, 0.8], |
2742 | fg => [0.8, 0.8, 0.8, 0.8], |
2722 | pri => 0, |
2743 | pri => 0, |
2723 | count => 1, |
2744 | count => 1, |
2724 | %arg, |
2745 | %arg, |
2725 | }; |
2746 | }; |
2726 | } |
2747 | } |
… | |
… | |
2765 | } |
2786 | } |
2766 | |
2787 | |
2767 | sub size_allocate { |
2788 | sub size_allocate { |
2768 | my ($self, $w, $h) = @_; |
2789 | my ($self, $w, $h) = @_; |
2769 | |
2790 | |
2770 | my $old_w = $self->{old_w}; |
2791 | my $old_w = $self->{old_w}; $self->{old_w} = $w; |
2771 | my $old_h = $self->{old_h}; |
2792 | my $old_h = $self->{old_h}; $self->{old_h} = $h; |
2772 | |
2793 | |
2773 | if ($old_w && $old_h) { |
2794 | CFClient::UI::rescale_widgets $w / $old_w, $h / $old_h |
2774 | for my $child ($self->children) { |
2795 | 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 | |
2796 | |
2786 | for my $child ($self->children) { |
2797 | for my $child ($self->children) { |
2787 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2798 | my ($X, $Y, $W, $H) = @$child{qw(x y req_w req_h)}; |
2788 | |
2799 | |
|
|
2800 | $X = $child->{req_x} > 0 ? $child->{req_x} : $w - $W - $child->{req_x} + 1 |
|
|
2801 | if exists $child->{req_x}; |
|
|
2802 | |
|
|
2803 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
|
|
2804 | if exists $child->{req_y}; |
|
|
2805 | |
2789 | $X = List::Util::max 0, List::Util::min $w - $W, $X; |
2806 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
2790 | $Y = List::Util::max 0, List::Util::min $h - $H, $Y; |
2807 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
|
|
2808 | |
2791 | $child->configure ($X, $Y, $W, $H); |
2809 | $child->configure ($X, $Y, $W, $H); |
2792 | } |
2810 | } |
2793 | |
|
|
2794 | $self->{old_w} = $w; |
|
|
2795 | $self->{old_h} = $h; |
|
|
2796 | } |
2811 | } |
2797 | |
2812 | |
2798 | sub coord2local { |
2813 | sub coord2local { |
2799 | my ($self, $x, $y) = @_; |
2814 | my ($self, $x, $y) = @_; |
2800 | |
2815 | |
… | |
… | |
2813 | $self->check_size; |
2828 | $self->check_size; |
2814 | $::WANT_REFRESH++; |
2829 | $::WANT_REFRESH++; |
2815 | } |
2830 | } |
2816 | |
2831 | |
2817 | sub add { |
2832 | sub add { |
2818 | my ($self, $child) = @_; |
2833 | my ($self, @children) = @_; |
2819 | |
2834 | |
|
|
2835 | for my $child (@children) { |
|
|
2836 | $child->{toplevel} = 1; |
|
|
2837 | |
2820 | # integerise window positions |
2838 | # integerise window positions |
2821 | $child->{x} = int $child->{x}; |
2839 | $child->{x} = int $child->{x}; |
2822 | $child->{y} = int $child->{y}; |
2840 | $child->{y} = int $child->{y}; |
|
|
2841 | } |
2823 | |
2842 | |
2824 | $self->SUPER::add ($child); |
2843 | $self->SUPER::add (@children); |
2825 | } |
2844 | } |
2826 | |
2845 | |
2827 | sub on_refresh { |
2846 | sub on_refresh { |
2828 | my ($self, $id, $cb) = @_; |
2847 | my ($self, $id, $cb) = @_; |
2829 | |
2848 | |