… | |
… | |
986 | } |
986 | } |
987 | |
987 | |
988 | sub set_offset { |
988 | sub set_offset { |
989 | my ($self, $x, $y) = @_; |
989 | my ($self, $x, $y) = @_; |
990 | |
990 | |
991 | $self->{view_x} = max 0, min $self->child->{w} - $self->{w}, int $x; |
991 | my $x = max 0, min $self->child->{w} - $self->{w}, int $x; |
992 | $self->{view_y} = max 0, min $self->child->{h} - $self->{h}, int $y; |
992 | my $y = max 0, min $self->child->{h} - $self->{h}, int $y; |
993 | |
993 | |
|
|
994 | if ($x != $self->{view_x} or $y != $self->{view_y}) { |
|
|
995 | $self->{view_x} = $x; |
|
|
996 | $self->{view_y} = $y; |
|
|
997 | |
|
|
998 | $self->emit (changed => $x, $y); |
994 | $self->update; |
999 | $self->update; |
|
|
1000 | } |
995 | } |
1001 | } |
996 | |
1002 | |
997 | # hmm, this does not work for topleft of $self... but we should not ask for that |
1003 | # hmm, this does not work for topleft of $self... but we should not ask for that |
998 | sub coord2local { |
1004 | sub coord2local { |
999 | my ($self, $x, $y) = @_; |
1005 | my ($self, $x, $y) = @_; |
… | |
… | |
1074 | row_expand => [1, 0], |
1080 | row_expand => [1, 0], |
1075 | %arg, |
1081 | %arg, |
1076 | ); |
1082 | ); |
1077 | |
1083 | |
1078 | $self->{vp} = new CFPlus::UI::ViewPort |
1084 | $self->{vp} = new CFPlus::UI::ViewPort |
1079 | expand => 1, |
1085 | expand => 1, |
1080 | scroll_x => $self->{scroll_x}, |
1086 | scroll_x => $self->{scroll_x}, |
1081 | scroll_y => $self->{scroll_y}, |
1087 | scroll_y => $self->{scroll_y}, |
|
|
1088 | on_changed => sub { |
|
|
1089 | my ($vp, $x, $y) = @_; |
|
|
1090 | |
|
|
1091 | $vp->{parent}{hslider}->set_value ($x); |
|
|
1092 | $vp->{parent}{vslider}->set_value ($y); |
|
|
1093 | |
|
|
1094 | 0 |
|
|
1095 | }, |
1082 | ; |
1096 | ; |
1083 | |
1097 | |
1084 | $self->SUPER::add (0, 0, $self->{vp}); |
1098 | $self->SUPER::add (0, 0, $self->{vp}); |
1085 | |
1099 | |
1086 | $self->add ($child) if $child; |
1100 | $self->add ($child) if $child; |
… | |
… | |
1140 | sub invoke_button_down { |
1154 | sub invoke_button_down { |
1141 | my ($self, $ev, $x, $y) = @_; |
1155 | my ($self, $ev, $x, $y) = @_; |
1142 | |
1156 | |
1143 | if ($ev->{button} == 2) { |
1157 | if ($ev->{button} == 2) { |
1144 | $self->grab_focus; |
1158 | $self->grab_focus; |
|
|
1159 | |
|
|
1160 | my $ox = $self->{vp}{view_x} + $ev->{x}; |
|
|
1161 | my $oy = $self->{vp}{view_y} + $ev->{y}; |
1145 | |
1162 | |
1146 | $self->{motion} = sub { |
1163 | $self->{motion} = sub { |
1147 | my ($ev, $x, $y) = @_; |
1164 | my ($ev, $x, $y) = @_; |
1148 | |
1165 | |
1149 | $self->{vp}->set_offset ( |
1166 | $self->{vp}->set_offset ($ox - $ev->{x}, $oy - $ev->{y}); |
1150 | $self->{vp}{view_x} - $ev->{xrel}, |
1167 | $self->update; |
1151 | $self->{vp}{view_y} - $ev->{yrel}, |
|
|
1152 | ); |
|
|
1153 | }; |
1168 | }; |
1154 | |
1169 | |
1155 | return 1; |
1170 | return 1; |
1156 | } |
1171 | } |
1157 | |
1172 | |
… | |
… | |
3478 | ); |
3493 | ); |
3479 | |
3494 | |
3480 | if ($self->{anim} && $self->{animspeed}) { |
3495 | if ($self->{anim} && $self->{animspeed}) { |
3481 | CFPlus::weaken (my $widget = $self); |
3496 | CFPlus::weaken (my $widget = $self); |
3482 | |
3497 | |
|
|
3498 | $widget->{animspeed} = List::Util::max 0.05, $widget->{animspeed}; |
|
|
3499 | $widget->{anim_start} = $self->{animspeed} * Event::time / $self->{animspeed}; |
3483 | $self->{timer} = Event->timer ( |
3500 | $self->{timer} = Event->timer ( |
3484 | at => $self->{animspeed} * int $::NOW / $self->{animspeed}, |
|
|
3485 | hard => 1, |
3501 | parked => 1, |
3486 | interval => $self->{animspeed}, |
|
|
3487 | cb => sub { |
3502 | cb => sub { |
3488 | return unless $::CONN; |
3503 | return unless $::CONN; |
3489 | |
3504 | |
|
|
3505 | if (!$widget) {#d# |
|
|
3506 | warn "animation widget timer active but widgetd estroyed\n";#d# |
|
|
3507 | warn $_[0]->w->active;#d# |
|
|
3508 | }#d# |
|
|
3509 | |
3490 | ++$widget->{frame}; |
3510 | ++$widget->{frame}; |
3491 | $self->update_face; |
3511 | $widget->update_face; |
3492 | $self->update; |
3512 | $widget->update; |
|
|
3513 | |
|
|
3514 | $widget->update_timer; |
3493 | }, |
3515 | }, |
3494 | ); |
3516 | ); |
3495 | |
3517 | |
3496 | $self->update_face; |
3518 | $self->update_face; |
|
|
3519 | $self->update_timer; |
3497 | } |
3520 | } |
3498 | |
3521 | |
3499 | $self |
3522 | $self |
|
|
3523 | } |
|
|
3524 | |
|
|
3525 | sub update_timer { |
|
|
3526 | my ($self) = @_; |
|
|
3527 | |
|
|
3528 | return unless $self->{timer}; |
|
|
3529 | |
|
|
3530 | if ($self->{visible}) { |
|
|
3531 | $self->{timer}->at ( |
|
|
3532 | $self->{anim_start} |
|
|
3533 | + $self->{animspeed} |
|
|
3534 | * int 1.5 + (Event::time - $self->{anim_start}) / $self->{animspeed} |
|
|
3535 | ); |
|
|
3536 | $self->{timer}->start; |
|
|
3537 | } else { |
|
|
3538 | $self->{timer}->stop; |
|
|
3539 | } |
3500 | } |
3540 | } |
3501 | |
3541 | |
3502 | sub update_face { |
3542 | sub update_face { |
3503 | my ($self) = @_; |
3543 | my ($self) = @_; |
3504 | |
3544 | |
… | |
… | |
3536 | return unless $self->{visible}; |
3576 | return unless $self->{visible}; |
3537 | |
3577 | |
3538 | $self->SUPER::update; |
3578 | $self->SUPER::update; |
3539 | } |
3579 | } |
3540 | |
3580 | |
|
|
3581 | sub invoke_visibility_change { |
|
|
3582 | my ($self) = @_; |
|
|
3583 | |
|
|
3584 | $self->update_timer; |
|
|
3585 | |
|
|
3586 | 0 |
|
|
3587 | } |
|
|
3588 | |
3541 | sub _draw { |
3589 | sub _draw { |
3542 | my ($self) = @_; |
3590 | my ($self) = @_; |
3543 | |
3591 | |
3544 | return unless $::CONN; |
3592 | return unless $::CONN; |
3545 | |
3593 | |
… | |
… | |
3560 | } |
3608 | } |
3561 | |
3609 | |
3562 | sub destroy { |
3610 | sub destroy { |
3563 | my ($self) = @_; |
3611 | my ($self) = @_; |
3564 | |
3612 | |
3565 | $self->{timer}->cancel |
3613 | (delete $self->{timer})->cancel |
3566 | if $self->{timer}; |
3614 | if $self->{timer}; |
3567 | |
3615 | |
3568 | $self->SUPER::destroy; |
3616 | $self->SUPER::destroy; |
3569 | } |
3617 | } |
3570 | |
3618 | |