トップへ(mam-mam.net/)

ジェスチャーイベント発生時に、ジェスチャーをキャンセルしたい

検索:

「ジェスチャーイベント発生時に、ジェスチャーをキャンセルしたい」

ジェスチャーイベント発生時に、ジェスチャーをキャンセルしたい。
.netには
  ManipulationStartingEventArgs.Cancel
でキャンセルできる。
Delphi(VCL、又はFMX)で余計なイナーシア等が発生した場合に
例えば、パンで画像を移動させる場合にはるか彼方へ画像が移動してしまう為、
ジェスチャーをキャンセルして、EventInfo.FlagsにTInteractiveGestureFlag.gfEndが届くようにしたい。
どうすればよいか。

回答

Delphiジェスチャーのキャンセルは、右クリックを強引に行えば可能。
(他に方法が有るかもしれませんが・・・。)

//イナーシアのキャンセル(とりあえず右クリックでキャンセルさせる・・・)
mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);

ソース

uses ....,winapi.windows;

var fxy:TPointF;
    fflag:Boolean;


procedure TForm1.ScaledLayout1Gesture(Sender: TObject;
  const EventInfo: TGestureEventInfo; var Handled: Boolean);
begin
  if EventInfo.GestureID=igiPan then
  begin
    if  TInteractiveGestureFlag.gfBegin in EventInfo.Flags then
    begin
      fxy:=EventInfo.Location;
      fflag:=True;
    end
    else if  TInteractiveGestureFlag.gfEnd in EventInfo.Flags then
    begin
      Image1.AnimateFloat('Position.X',100,0.1,TAnimationType.atOut,TInterpolationType.itCubic);
      Image1.AnimateFloat('Opacity',1,0.1,TAnimationType.atOut,TInterpolationType.itCubic);
    end
    else if  TInteractiveGestureFlag.gfInertia in EventInfo.Flags then
    begin
      Image1.Position.X:=Image1.Position.X+(EventInfo.InertiaVector.X)/(ScaledLayout1.Width/4);
      Image1.Opacity:=(400-abs(Image1.Position.X-100))/400;
      fxy:=EventInfo.Location;
      if (Image1.Position.X<=-100) or (Image1.Position.X>=200) then
      begin
        //ジェスチャー(イナーシア)のキャンセル(右クリックしてるだけですが・・・)
        mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);
        mouse_event(MOUSEEVENTF_RIGHTUP,0,0,0,0);
      end;
    end
    else
    begin
      Image1.Position.X:=Image1.Position.X-(fxy.X-EventInfo.Location.X);
      Image1.Opacity:=(400-abs(Image1.Position.X-100))/400;
      fxy:=EventInfo.Location;
    end;
    Handled:=True;
  end;
end;