// print Unit, was Du vorschlägt
unit ExCanvasTools;
// 20100915 by Thomas Wassermann
// www.explido-software.de
interface
uses
Windows, SysUtils, Classes, Graphics;
Function Grad2Rad(w:Double):Double;
Procedure PaintGraphic(ACanvas:TCanvas;x,y:Integer;AGraphic:TGraphic;Faktor,Winkel:Double;PosIsCenter:Boolean=false);
Procedure PaintText(ACanvas:TCanvas;
Const s:
String;x,y:Integer;Faktor,Winkel:Double;PosIsCenter:Boolean=false);
Procedure ResetCanvas(ACanvas:TCanvas);
procedure SetCanvasZoomAndRotation(ACanvas: TCanvas;Zoom:Double;Angle:Double;CenterpointX,CenterpointY:Double);
implementation
Function Grad2Rad(w:Double):Double;
begin
Result := w / 360 * PI *2;
end;
Procedure PaintText(ACanvas:TCanvas;
Const s:
String;x,y:Integer;Faktor,Winkel:Double;PosIsCenter:Boolean=false);
var
px,py:Integer;
begin
SetCanvasZoomAndRotation(ACanvas , Faktor, Winkel, x,y);
if PosIsCenter
then
begin
px := Round( ACanvas.TextWidth(s) / 2 );
py := Round( ACanvas.TextHeight(s) / 2 );
end
else
begin
px := 0;
py := 0;
end;
ACanvas.TextOut(-px ,-py ,s);
ResetCanvas(ACanvas);
end;
Procedure PaintGraphic(ACanvas:TCanvas;x,y:Integer;AGraphic:TGraphic;Faktor,Winkel:Double;PosIsCenter:Boolean=false);
var
px,py:Integer;
begin
if PosIsCenter
then
begin
px := Round( AGraphic.Width / 2 );
py := Round( AGraphic.Height / 2 );
end
else
begin
px := 0;
py := 0;
end;
SetCanvasZoomAndRotation(ACanvas , Faktor, Winkel, x , y );
ACanvas.Draw(-px ,-py ,AGraphic);
ResetCanvas(ACanvas);
end;
Procedure ResetCanvas(ACanvas:TCanvas);
begin
SetCanvasZoomAndRotation(ACanvas , 1, 0, 0,0);
end;
Procedure SetCanvasZoomAndRotation(ACanvas:TCanvas;Zoom:Double;Angle:Double;CenterpointX,CenterpointY:Double);
var
form : tagXFORM;
Winkel:Double;
begin
Winkel := Grad2Rad(Angle);
SetGraphicsMode(ACanvas.Handle, GM_ADVANCED);
SetMapMode(ACanvas.Handle,MM_ANISOTROPIC);
form.eM11 := Zoom * cos( Winkel);
form.eM12 := Zoom *Sin( Winkel) ;
form.eM21 := Zoom * (-sin( Winkel));
form.eM22 := Zoom * cos( Winkel) ;
form.eDx := CenterpointX;
form.eDy := CenterpointY;
SetWorldTransform(ACanvas.Handle,form);
end;
end.