… | |
… | |
206 | can_events => 1, |
206 | can_events => 1, |
207 | @_ |
207 | @_ |
208 | }, $class; |
208 | }, $class; |
209 | |
209 | |
210 | for (keys %$self) { |
210 | for (keys %$self) { |
211 | if (/^connect_(.*)$/) { |
211 | if (/^on_(.*)$/) { |
212 | $self->connect ($1 => delete $self->{$_}); |
212 | $self->connect ($1 => delete $self->{$_}); |
213 | } |
213 | } |
214 | } |
214 | } |
215 | |
215 | |
216 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
216 | Scalar::Util::weaken ($CFClient::UI::WIDGET{$self+0} = $self); |
… | |
… | |
223 | } |
223 | } |
224 | |
224 | |
225 | $self |
225 | $self |
226 | } |
226 | } |
227 | |
227 | |
|
|
228 | sub toggle_visibility { |
|
|
229 | my ($self) = @_; |
|
|
230 | |
|
|
231 | if ($self->{visible}) { |
|
|
232 | $self->hide; |
|
|
233 | } else { |
|
|
234 | $self->show; |
|
|
235 | } |
|
|
236 | } |
|
|
237 | |
228 | sub destroy { |
238 | sub destroy { |
229 | my ($self) = @_; |
239 | my ($self) = @_; |
230 | |
240 | |
231 | $self->hide; |
241 | $self->hide; |
232 | %$self = (); |
242 | %$self = (); |
… | |
… | |
253 | } |
263 | } |
254 | |
264 | |
255 | sub set_invisible { |
265 | sub set_invisible { |
256 | my ($self) = @_; |
266 | my ($self) = @_; |
257 | |
267 | |
|
|
268 | return unless $self->{visible}; |
|
|
269 | |
258 | # broken show/hide model |
270 | # broken show/hide model |
259 | |
271 | |
260 | delete $self->{root}; |
272 | delete $self->{root}; |
261 | delete $self->{visible}; |
273 | delete $self->{visible}; |
262 | |
274 | |
… | |
… | |
265 | |
277 | |
266 | CFClient::UI::check_tooltip |
278 | CFClient::UI::check_tooltip |
267 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
279 | if $CFClient::UI::TOOLTIP->{owner} == $self; |
268 | |
280 | |
269 | $self->focus_out; |
281 | $self->focus_out; |
|
|
282 | |
|
|
283 | $self->emit (visibility_change => 0); |
270 | } |
284 | } |
271 | |
285 | |
272 | sub hide { |
286 | sub hide { |
273 | my ($self) = @_; |
287 | my ($self) = @_; |
274 | |
288 | |
… | |
… | |
486 | sub set_parent { |
500 | sub set_parent { |
487 | my ($self, $parent) = @_; |
501 | my ($self, $parent) = @_; |
488 | |
502 | |
489 | Scalar::Util::weaken ($self->{parent} = $parent); |
503 | Scalar::Util::weaken ($self->{parent} = $parent); |
490 | |
504 | |
|
|
505 | if ($parent->{visible} || 1) { |
491 | $self->{root} = $parent->{root}; |
506 | $self->{root} = $parent->{root}; |
492 | $self->{visible} = $parent->{visible} + 1; |
507 | $self->{visible} = $parent->{visible} + 1; |
|
|
508 | |
|
|
509 | $self->emit (visibility_change => 1) |
|
|
510 | unless $self->{parent}{visible}; |
|
|
511 | } |
493 | |
512 | |
494 | # TODO: req_w _does_change after ->reconfigure |
513 | # TODO: req_w _does_change after ->reconfigure |
495 | $self->check_size |
514 | $self->check_size |
496 | unless exists $self->{req_w}; |
515 | unless exists $self->{req_w}; |
497 | |
516 | |
… | |
… | |
527 | sub emit { |
546 | sub emit { |
528 | my ($self, $signal, @args) = @_; |
547 | my ($self, $signal, @args) = @_; |
529 | |
548 | |
530 | $self->_emit ($signal, @args) |
549 | $self->_emit ($signal, @args) |
531 | || $self->$signal (@args); |
550 | || $self->$signal (@args); |
|
|
551 | } |
|
|
552 | |
|
|
553 | sub visibility_change { |
|
|
554 | #my ($self, $visible) = @_; |
532 | } |
555 | } |
533 | |
556 | |
534 | sub DESTROY { |
557 | sub DESTROY { |
535 | my ($self) = @_; |
558 | my ($self) = @_; |
536 | |
559 | |
… | |
… | |
884 | my $class = shift; |
907 | my $class = shift; |
885 | |
908 | |
886 | my $self; |
909 | my $self; |
887 | |
910 | |
888 | my $slider = new CFClient::UI::Slider |
911 | my $slider = new CFClient::UI::Slider |
889 | vertical => 1, |
912 | vertical => 1, |
890 | range => [0, 0, 1, 0.01], # HACK fix |
913 | range => [0, 0, 1, 0.01], # HACK fix |
891 | connect_changed => sub { |
914 | on_changed => sub { |
892 | $self->{vp}->set_offset (0, $_[1]); |
915 | $self->{vp}->set_offset (0, $_[1]); |
893 | }, |
916 | }, |
894 | ; |
917 | ; |
895 | |
918 | |
896 | $self = $class->SUPER::new ( |
919 | $self = $class->SUPER::new ( |
… | |
… | |
1051 | my ($ev, $x, $y) = @_; |
1074 | my ($ev, $x, $y) = @_; |
1052 | |
1075 | |
1053 | my $dx = $ev->{x} - $ox; |
1076 | my $dx = $ev->{x} - $ox; |
1054 | my $dy = $ev->{y} - $oy; |
1077 | my $dy = $ev->{y} - $oy; |
1055 | |
1078 | |
|
|
1079 | $self->{user_x} = $wx + $dx * $mx; |
|
|
1080 | $self->{user_y} = $wy + $dy * $my; |
1056 | $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); |
1081 | $self->{user_w} = $bw + $dx * ($mx ? -1 : 1); |
1057 | $self->{user_h} = $bh + $dy * ($my ? -1 : 1); |
1082 | $self->{user_h} = $bh + $dy * ($my ? -1 : 1); |
1058 | $self->move ($wx + $dx * $mx, $wy + $dy * $my); |
1083 | $self->move ($self->{user_x}, $self->{user_y}); |
1059 | $self->check_size; |
1084 | $self->check_size; |
1060 | }; |
1085 | }; |
1061 | |
1086 | |
1062 | } elsif ($lr ^ $td) { |
1087 | } elsif ($lr ^ $td) { |
1063 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
1088 | my ($ox, $oy) = ($ev->{x}, $ev->{y}); |
… | |
… | |
1066 | $self->{motion} = sub { |
1091 | $self->{motion} = sub { |
1067 | my ($ev, $x, $y) = @_; |
1092 | my ($ev, $x, $y) = @_; |
1068 | |
1093 | |
1069 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1094 | ($x, $y) = ($ev->{x}, $ev->{y}); |
1070 | |
1095 | |
1071 | $self->move ($bx + $x - $ox, $by + $y - $oy); |
1096 | $self->{user_x} = $bx + $x - $ox; |
|
|
1097 | $self->{user_y} = $by + $y - $oy; |
|
|
1098 | $self->move ($self->{user_x}, $self->{user_y}); |
1072 | $self->update; |
1099 | $self->update; |
1073 | }; |
1100 | }; |
1074 | } |
1101 | } |
1075 | } |
1102 | } |
1076 | |
1103 | |
… | |
… | |
2570 | |
2597 | |
2571 | sub new { |
2598 | sub new { |
2572 | my $class = shift; |
2599 | my $class = shift; |
2573 | |
2600 | |
2574 | my $self = $class->SUPER::new ( |
2601 | my $self = $class->SUPER::new ( |
2575 | state => 0, |
2602 | state => 0, |
2576 | connect_activate => \&toggle_flopper, |
2603 | on_activate => \&toggle_flopper, |
2577 | @_ |
2604 | @_ |
2578 | ); |
2605 | ); |
2579 | |
2606 | |
2580 | if ($self->{state}) { |
|
|
2581 | $self->{state} = 0; |
|
|
2582 | $self->toggle_flopper; |
|
|
2583 | } |
|
|
2584 | |
|
|
2585 | $self |
2607 | $self |
2586 | } |
2608 | } |
2587 | |
2609 | |
2588 | sub toggle_flopper { |
2610 | sub toggle_flopper { |
2589 | my ($self) = @_; |
2611 | my ($self) = @_; |
2590 | |
2612 | |
2591 | # TODO: use animation |
2613 | $self->{other}->toggle_visibility; |
2592 | if ($self->{state} = !$self->{state}) { |
|
|
2593 | $CFClient::UI::ROOT->add ($self->{other}); |
|
|
2594 | $self->{other}->move ($self->coord2global (0, $self->{h})); |
|
|
2595 | $self->_emit ("open"); |
|
|
2596 | } else { |
|
|
2597 | $CFClient::UI::ROOT->remove ($self->{other}); |
|
|
2598 | $self->_emit ("close"); |
|
|
2599 | } |
|
|
2600 | |
|
|
2601 | $self->_emit (changed => $self->{state}); |
|
|
2602 | } |
2614 | } |
2603 | |
2615 | |
2604 | ############################################################################# |
2616 | ############################################################################# |
2605 | |
2617 | |
2606 | package CFClient::UI::Tooltip; |
2618 | package CFClient::UI::Tooltip; |
… | |
… | |
3028 | if exists $child->{req_x}; |
3040 | if exists $child->{req_x}; |
3029 | |
3041 | |
3030 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3042 | $Y = $child->{req_y} > 0 ? $child->{req_y} : $h - $H - $child->{req_y} + 1 |
3031 | if exists $child->{req_y}; |
3043 | if exists $child->{req_y}; |
3032 | |
3044 | |
|
|
3045 | $X = $self->{user_x} if exists $self->{user_x}; |
|
|
3046 | $Y = $self->{user_y} if exists $self->{user_y}; |
|
|
3047 | |
3033 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3048 | $X = List::Util::max 0, List::Util::min $w - $W, int $X + 0.5; |
3034 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3049 | $Y = List::Util::max 0, List::Util::min $h - $H, int $Y + 0.5; |
3035 | |
3050 | |
3036 | $child->configure ($X, $Y, $W, $H); |
3051 | $child->configure ($X, $Y, $W, $H); |
3037 | } |
3052 | } |
… | |
… | |
3107 | $_->() |
3122 | $_->() |
3108 | for values %{delete $self->{refresh_hook}}; |
3123 | for values %{delete $self->{refresh_hook}}; |
3109 | } |
3124 | } |
3110 | |
3125 | |
3111 | if ($self->{check_size}) { |
3126 | if ($self->{check_size}) { |
3112 | my @queue = ([], []); |
3127 | my @queue; |
3113 | |
3128 | |
3114 | for (;;) { |
3129 | for (;;) { |
3115 | if ($self->{check_size}) { |
3130 | if ($self->{check_size}) { |
3116 | # heuristic: check containers last |
3131 | #TODO use array-of-depth approach |
3117 | push @{ $queue[ ! ! $_->isa ("CFClient::UI::Container") ] }, $_ |
3132 | |
|
|
3133 | @queue = sort { $a->{visible} <=> $b->{visible} } |
3118 | for values %{delete $self->{check_size}} |
3134 | @queue, values %{delete $self->{check_size}}; |
3119 | } |
3135 | } |
3120 | |
3136 | |
3121 | my $widget = (pop @{ $queue[0] }) || (pop @{ $queue[1] }) || last; |
3137 | my $widget = pop @queue || last; |
|
|
3138 | |
|
|
3139 | defined $widget->{visible} or last; # do not resize invisible widgets |
3122 | |
3140 | |
3123 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
3141 | my ($w, $h) = $widget->{user_w} && $widget->{user_h} |
3124 | ? @$widget{qw(user_w user_h)} |
3142 | ? @$widget{qw(user_w user_h)} |
3125 | : $widget->size_request; |
3143 | : $widget->size_request; |
3126 | |
3144 | |