Refactoring

This commit is contained in:
Michael Schimmel
2025-09-08 11:53:10 +02:00
parent 6b77391e91
commit 7e4ecb2ff9
3 changed files with 159 additions and 28 deletions
+33 -28
View File
@@ -131,10 +131,12 @@ type
procedure MouseMove(Shift: TShiftState; X, Y: Single); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Single); override;
procedure MouseWheel(Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean); override;
procedure DblClick; override;
public
constructor Create(AOwner: TComponent); override;
procedure BuildTree(const Root: IAstNode; const Position: TPointF; AMode: TVisualizationMode);
function GetChildrenMatrix(var Matrix: TMatrix; var Simple: Boolean): Boolean; override;
function Zoom(Factor: Single): Boolean;
published
// Standard control properties
@@ -752,37 +754,15 @@ begin
end;
procedure TAuraWorkspace.MouseWheel(Shift: TShiftState; WheelDelta: Integer; var Handled: Boolean);
var
oldZoom: Single;
MouseService: IFMXMouseService;
begin
inherited;
Handled := Zoom(IfThen(WheelDelta > 0, FZoom * 1.1, FZoom / 1.1));
end;
if TPlatformServices.Current.SupportsPlatformService(IFMXMouseService, MouseService) then
begin
var MousePos := ScreenToLocal(MouseService.GetMousePos);
oldZoom := FZoom;
// Calculate new zoom
if WheelDelta > 0 then
FZoom := FZoom * 1.1
else
FZoom := FZoom / 1.1;
// Clamp zoom level to a reasonable range
FZoom := Max(0.2, Min(3.0, FZoom));
// Adjust panning to keep the point under the cursor stationary
FPanning.cx := MousePos.X * (1 - FZoom / oldZoom) + FPanning.cx * (FZoom / oldZoom);
FPanning.cy := MousePos.Y * (1 - FZoom / oldZoom) + FPanning.cy * (FZoom / oldZoom);
// Trigger repaint to apply the new transformation matrix
RecalcAbsolute;
RecalcUpdateRect;
Repaint;
Handled := True;
end;
procedure TAuraWorkspace.DblClick;
begin
inherited;
Zoom(1.0);
end;
procedure TAuraWorkspace.Paint;
@@ -836,6 +816,31 @@ begin
end;
end;
function TAuraWorkspace.Zoom(Factor: Single): Boolean;
var
MouseService: IFMXMouseService;
begin
Result := TPlatformServices.Current.SupportsPlatformService(IFMXMouseService, MouseService);
if Result then
begin
var MousePos := ScreenToLocal(MouseService.GetMousePos);
// Clamp zoom level to a reasonable range
Factor := Max(0.2, Min(3.0, Factor));
// Adjust panning to keep the point under the cursor stationary
FPanning.cx := MousePos.X * (1 - Factor / FZoom) + FPanning.cx * (Factor / FZoom);
FPanning.cy := MousePos.Y * (1 - Factor / FZoom) + FPanning.cy * (Factor / FZoom);
FZoom := Factor;
// Trigger repaint to apply the new transformation matrix
RecalcAbsolute;
RecalcUpdateRect;
Repaint;
end;
end;
{ TAstToAuraNodeVisitor }
constructor TAstToAuraNodeVisitor.Create(