Forráskód Böngészése

fix Transform for pixel centered coords

Johann 6 éve
szülő
commit
142d30705a

+ 4 - 4
lazpaintcontrols/lcvectororiginal.pas

@@ -219,9 +219,9 @@ type
     procedure Remove;
     function Duplicate: TVectorShape;
     class function StorageClassName: RawByteString; virtual; abstract;
-    function GetIsSlow({%H-}AMatrix: TAffineMatrix): boolean; virtual;
+    function GetIsSlow(const {%H-}AMatrix: TAffineMatrix): boolean; virtual;
     function GetUsedTextures: ArrayOfBGRABitmap; virtual;
-    procedure Transform(AMatrix: TAffineMatrix); virtual;
+    procedure Transform(const AMatrix: TAffineMatrix); virtual;
     class function Fields: TVectorShapeFields; virtual;
     class function Usermodes: TVectorShapeUsermodes; virtual;
     class function PreferPixelCentered: boolean; virtual;
@@ -1117,7 +1117,7 @@ end;
 
 { TVectorShape }
 
-function TVectorShape.GetIsSlow(AMatrix: TAffineMatrix): boolean;
+function TVectorShape.GetIsSlow(const AMatrix: TAffineMatrix): boolean;
 begin
   result := false;
 end;
@@ -1148,7 +1148,7 @@ begin
   setlength(result, nb);
 end;
 
-procedure TVectorShape.Transform(AMatrix: TAffineMatrix);
+procedure TVectorShape.Transform(const AMatrix: TAffineMatrix);
 var
   zoom: Single;
 begin

+ 7 - 5
lazpaintcontrols/lcvectorpolyshapes.pas

@@ -107,7 +107,7 @@ type
     procedure LoadFromStorage(AStorage: TBGRACustomOriginalStorage); override;
     procedure SaveToStorage(AStorage: TBGRACustomOriginalStorage); override;
     procedure ConfigureCustomEditor(AEditor: TBGRAOriginalEditor); override;
-    procedure Transform(AMatrix: TAffineMatrix); override;
+    procedure Transform(const AMatrix: TAffineMatrix); override;
     class function Usermodes: TVectorShapeUsermodes; override;
     class function DefaultArrowSize: TPointF;
     property Points[AIndex:integer]: TPointF read GetPoint write SetPoint;
@@ -131,7 +131,7 @@ type
     procedure Render(ADest: TBGRABitmap; AMatrix: TAffineMatrix; ADraft: boolean); override;
     function GetRenderBounds({%H-}ADestRect: TRect; AMatrix: TAffineMatrix; AOptions: TRenderBoundsOptions = []): TRectF; override;
     function PointInShape(APoint: TPointF): boolean; override;
-    function GetIsSlow({%H-}AMatrix: TAffineMatrix): boolean; override;
+    function GetIsSlow(const {%H-}AMatrix: TAffineMatrix): boolean; override;
     class function StorageClassName: RawByteString; override;
   end;
 
@@ -915,13 +915,15 @@ begin
   end;
 end;
 
-procedure TCustomPolypointShape.Transform(AMatrix: TAffineMatrix);
+procedure TCustomPolypointShape.Transform(const AMatrix: TAffineMatrix);
 var
   i: Integer;
+  m: TAffineMatrix;
 begin
   BeginUpdate(TCustomPolypointShapeDiff);
+  m := MatrixForPixelCentered(AMatrix);
   for i := 0 to PointCount-1 do
-    FPoints[i].coord := AMatrix*FPoints[i].coord;
+    FPoints[i].coord := m*FPoints[i].coord;
   inherited Transform(AMatrix);
   EndUpdate;
 end;
@@ -1044,7 +1046,7 @@ begin
   result := false;
 end;
 
-function TPolylineShape.GetIsSlow(AMatrix: TAffineMatrix): boolean;
+function TPolylineShape.GetIsSlow(const AMatrix: TAffineMatrix): boolean;
 begin
   Result:= PointCount > 40;
 end;

+ 18 - 15
lazpaintcontrols/lcvectorrectshapes.pas

@@ -71,8 +71,8 @@ type
     procedure SaveToStorage(AStorage: TBGRACustomOriginalStorage); override;
     function GetRenderBounds({%H-}ADestRect: TRect; AMatrix: TAffineMatrix; {%H-}AOptions: TRenderBoundsOptions = []): TRectF; override;
     procedure ConfigureCustomEditor(AEditor: TBGRAOriginalEditor); override;
-    function GetAffineBox(AMatrix: TAffineMatrix; APixelCentered: boolean): TAffineBox;
-    procedure Transform(AMatrix: TAffineMatrix); override;
+    function GetAffineBox(const AMatrix: TAffineMatrix; APixelCentered: boolean): TAffineBox;
+    procedure Transform(const AMatrix: TAffineMatrix); override;
     property Origin: TPointF read FOrigin write SetOrigin;
     property XAxis: TPointF read FXAxis write SetXAxis;
     property YAxis: TPointF read FYAxis write SetYAxis;
@@ -93,7 +93,7 @@ type
     procedure Render(ADest: TBGRABitmap; AMatrix: TAffineMatrix; ADraft: boolean); override;
     function GetRenderBounds({%H-}ADestRect: TRect; AMatrix: TAffineMatrix; AOptions: TRenderBoundsOptions = []): TRectF; override;
     function PointInShape(APoint: TPointF): boolean; override;
-    function GetIsSlow(AMatrix: TAffineMatrix): boolean; override;
+    function GetIsSlow(const AMatrix: TAffineMatrix): boolean; override;
     class function StorageClassName: RawByteString; override;
   end;
 
@@ -110,7 +110,7 @@ type
     procedure Render(ADest: TBGRABitmap; AMatrix: TAffineMatrix; ADraft: boolean); override;
     function GetRenderBounds({%H-}ADestRect: TRect; AMatrix: TAffineMatrix; AOptions: TRenderBoundsOptions = []): TRectF; override;
     function PointInShape(APoint: TPointF): boolean; override;
-    function GetIsSlow(AMatrix: TAffineMatrix): boolean; override;
+    function GetIsSlow(const AMatrix: TAffineMatrix): boolean; override;
     class function StorageClassName: RawByteString; override;
   end;
 
@@ -173,8 +173,8 @@ type
     procedure Render(ADest: TBGRABitmap; AMatrix: TAffineMatrix; ADraft: boolean); override;
     function GetRenderBounds({%H-}ADestRect: TRect; AMatrix: TAffineMatrix; AOptions: TRenderBoundsOptions = []): TRectF; override;
     function PointInShape(APoint: TPointF): boolean; override;
-    function GetIsSlow(AMatrix: TAffineMatrix): boolean; override;
-    procedure Transform(AMatrix: TAffineMatrix); override;
+    function GetIsSlow(const AMatrix: TAffineMatrix): boolean; override;
+    procedure Transform(const AMatrix: TAffineMatrix); override;
     class function StorageClassName: RawByteString; override;
     property ShapeKind: TPhongShapeKind read FShapeKind write SetShapeKind;
     property LightPosition: TPointF read FLightPosition write SetLightPosition;
@@ -649,7 +649,7 @@ begin
   if FYSizeBackup <> 0 then FYUnitBackup := (1/FYSizeBackup)*FYUnitBackup;
 end;
 
-function TCustomRectShape.GetAffineBox(AMatrix: TAffineMatrix; APixelCentered: boolean): TAffineBox;
+function TCustomRectShape.GetAffineBox(const AMatrix: TAffineMatrix; APixelCentered: boolean): TAffineBox;
 var
   m: TAffineMatrix;
 begin
@@ -661,12 +661,15 @@ begin
       FXAxis - (FYAxis - FOrigin), FYAxis - (FXAxis - FOrigin));
 end;
 
-procedure TCustomRectShape.Transform(AMatrix: TAffineMatrix);
+procedure TCustomRectShape.Transform(const AMatrix: TAffineMatrix);
+var
+  m: TAffineMatrix;
 begin
   BeginUpdate(TCustomRectShapeDiff);
-  FOrigin := AMatrix*FOrigin;
-  FXAxis := AMatrix*FXAxis;
-  FYAxis := AMatrix*FYAxis;
+  m := MatrixForPixelCentered(AMatrix);
+  FOrigin := m*FOrigin;
+  FXAxis := m*FXAxis;
+  FYAxis := m*FYAxis;
   inherited Transform(AMatrix);
   EndUpdate;
 end;
@@ -812,7 +815,7 @@ begin
   result := 1;
 end;
 
-function TRectShape.GetIsSlow(AMatrix: TAffineMatrix): boolean;
+function TRectShape.GetIsSlow(const AMatrix: TAffineMatrix): boolean;
 var
   ab: TAffineBox;
   backSurface, totalSurface, penSurface: Single;
@@ -1188,7 +1191,7 @@ begin
     result := false;
 end;
 
-function TEllipseShape.GetIsSlow(AMatrix: TAffineMatrix): boolean;
+function TEllipseShape.GetIsSlow(const AMatrix: TAffineMatrix): boolean;
 var
   ab: TAffineBox;
   backSurface, totalSurface, penSurface: Single;
@@ -1536,7 +1539,7 @@ begin
   end;
 end;
 
-function TPhongShape.GetIsSlow(AMatrix: TAffineMatrix): boolean;
+function TPhongShape.GetIsSlow(const AMatrix: TAffineMatrix): boolean;
 var
   ab: TAffineBox;
 begin
@@ -1545,7 +1548,7 @@ begin
   result := ab.Surface > 320*240;
 end;
 
-procedure TPhongShape.Transform(AMatrix: TAffineMatrix);
+procedure TPhongShape.Transform(const AMatrix: TAffineMatrix);
 begin
   BeginUpdate(TPhongShapeDiff);
   LightPosition := AMatrix*LightPosition;

+ 4 - 4
lazpaintcontrols/lcvectortextshapes.pas

@@ -153,7 +153,7 @@ type
     procedure Render(ADest: TBGRABitmap; ARenderOffset: TPoint; AMatrix: TAffineMatrix; ADraft: boolean); override;
     function GetRenderBounds({%H-}ADestRect: TRect; AMatrix: TAffineMatrix; AOptions: TRenderBoundsOptions = []): TRectF; override;
     function PointInShape(APoint: TPointF): boolean; override;
-    function GetIsSlow({%H-}AMatrix: TAffineMatrix): boolean; override;
+    function GetIsSlow(const {%H-}AMatrix: TAffineMatrix): boolean; override;
     procedure MouseMove({%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; var {%H-}ACursor: TOriginalEditorCursor; var {%H-}AHandled: boolean); override;
     procedure MouseDown({%H-}RightButton: boolean; {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; var {%H-}ACursor: TOriginalEditorCursor; var {%H-}AHandled: boolean); override;
     procedure MouseUp({%H-}RightButton: boolean; {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; var {%H-}ACursor: TOriginalEditorCursor; var {%H-}AHandled: boolean); override;
@@ -164,7 +164,7 @@ type
     function CopySelection: boolean;
     function CutSelection: boolean;
     function PasteSelection: boolean;
-    procedure Transform(AMatrix: TAffineMatrix); override;
+    procedure Transform(const AMatrix: TAffineMatrix); override;
     property HasSelection: boolean read GetHasSelection;
     property CanPasteSelection: boolean read GetCanPasteSelection;
     property Text: string read FText write SetText;
@@ -1456,7 +1456,7 @@ begin
   result := GetAffineBox(AffineMatrixIdentity,true).Contains(APoint);
 end;
 
-function TTextShape.GetIsSlow(AMatrix: TAffineMatrix): boolean;
+function TTextShape.GetIsSlow(const AMatrix: TAffineMatrix): boolean;
 begin
   Result:= true;
 end;
@@ -1728,7 +1728,7 @@ begin
     result := false;
 end;
 
-procedure TTextShape.Transform(AMatrix: TAffineMatrix);
+procedure TTextShape.Transform(const AMatrix: TAffineMatrix);
 var
   zoom: Single;
 begin