unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TImage =
Class(ExtCtrls.TImage)
private
FAngle: Double;
FPoint: TPoint;
FZoom: Double;
procedure SetAngle(
const Value: Double);
procedure SetPoint(
const Value: TPoint);
procedure SetZoom(
const Value: Double);
public
Constructor Create(AOwner:TComponent);
override;
published
procedure Paint;
override;
property CenterPoint:TPoint
read FPoint
write SetPoint;
property Angle:Double
read FAngle
write SetAngle;
Property Zoom:Double
read FZoom
write SetZoom;
End;
TGraphicControl =
Class(Controls.TGraphicControl)
public
Property Canvas;
End;
TForm3 =
class(TForm)
Image1: TImage;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form3: TForm3;
implementation
uses math;
{$R *.dfm}
Procedure SetCanvasZoomAndRotation(ACanvas: TCanvas; Zoom: Double; Angle: Double; CenterpointX, CenterpointY: Double);
var
form: tagXFORM;
Winkel: Double;
begin
Winkel := DegToRad(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;
procedure TForm3.Button1Click(Sender: TObject);
begin
Image1.Invalidate;
end;
{ TImage }
constructor TImage.Create(AOwner:TComponent);
begin
inherited;
FZoom := 1;
end;
procedure TImage.Paint;
begin
SetCanvasZoomAndRotation(TGraphicControl(self).Canvas, FZoom, FAngle, FPoint.x, FPoint.y);
inherited;
end;
procedure TImage.SetAngle(
const Value: Double);
begin
FAngle := Value;
invalidate;
end;
procedure TImage.SetPoint(
const Value: TPoint);
begin
FPoint := Value;
invalidate;
end;
procedure TImage.SetZoom(
const Value: Double);
begin
FZoom := Value;
invalidate;
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
KeyPreview := true;
end;
procedure TForm3.FormKeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
var
p:TPoint;
begin
if key
in [37..40,187,189,76,82]
then
begin
p := Image1.CenterPoint;
case Key
of
38: p.Y := p.Y - 1;
40: p.Y := p.Y + 1;
37: p.X := p.X - 1;
39: p.X := p.X + 1;
187:Image1.zoom := Image1.Zoom + 0.1;
// +
189:Image1.zoom := Image1.Zoom - 0.1;
// -
82 :Image1.Angle := Image1.Angle + 1;
// R
76 :Image1.Angle := Image1.Angle - 1;
// L
end;
Image1.CenterPoint := p;
end;
Caption := IntToStr(Ord(key))
end;
end.