Correct movement of a rotating figure with the mouse

  

The following example, places a Timage in a form; it creates a drawing inside it and then through 2 mouse events (MouseDown and MouseMove) on the image, we move the drawing correctly on screen with the mouse;

Now, if we remove the comment { MyImage.RotationAngle := 120;} from the code and activate the rotation of the figure previously plus 90 degrees, the movement is incorrect. I don’t see what the problem is. [It is necessary to be able to rotate the figure in screen several times while we can move the result in screen through the mouse.]

Video example: https://1drv.ms/v/s!AqdWVn6k-HLbgqRvDhSeWACUsf4okQ

unit UMoveShape;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
FMX.Objects, FMX.StdCtrls, FMX.Controls.Presentation,
FireDAC.UI.Intf, FireDAC.FMXUI.Async, FireDAC.Stan.Intf,
FMX.DialogService.Async,System.UIConsts,System.Math.Vectors, FireDAC.Comp.UI;

type
TForm16 = class(TForm)
MyImage: TImage;
procedure FormCreate(Sender: TObject);
procedure MyImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
procedure MyImageMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
private
{ Private declarations }
public
Xdiff,Ydiff: single;
{ Public declarations }
end;

var
Form16: TForm16;

implementation

{$R *.fmx}

procedure TForm16.FormCreate(Sender: TObject);
Var
MyRect1, MyRect2: TRectF;
Path: TPathData;
begin
MyImage.Width := 500;
MyImage.Height := 500;
MyImage.Bitmap.SetSize(Round(MyImage.Width), Round(MyImage.Height));
MyRect1 := TRectF.Create(98, 100, 200, 200);
MyRect2 := TRectF.Create(70, 90, 225, 210);
Path := TPathData.Create;
Path.AddEllipse(MyRect1);
Path.AddRectangle(MyRect2, 0, 0, AllCorners);
MyImage.Bitmap.Canvas.BeginScene;
MyImage.Bitmap.Canvas.DrawPath(path, 200);
MyImage.Bitmap.Canvas.EndScene;

{If we rotate the image more than 90 degrees for example, the movement of the
image with the cursor is erratic using the mouseDown and MouseMove routines.
On the other way, if we don’t rotate the movement is perfect.}

// MyImage.RotationAngle := 120;
end;

procedure TForm16.MyImageMouseDown (Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
Y: Single);
begin
if (ssleft in shift) then
begin
Xdiff := X;
Ydiff := y;
end;
end;

procedure TForm16.MyImageMouseMove (Sender: TObject; Shift: TShiftState; X, Y: Single);
begin
if (ssleft in shift) then
begin
MyImage.Position.X := MyImage.Position.X + X – Xdiff;
MyImage.Position.y := MyImage.Position.Y + Y – YDiff;
end;

end;

end.

Comments are closed.