unit ZeigerTest;
interface
uses
SysUtils, Classes, Controls, ExtCtrls, Graphics, Messages, Types;
type
TZeigerTest =
class(TPaintBox)
private
FAktZeiger,
FOldZeiger: Real;
FDurchmesser: Integer;
FRadius: Integer;
FFirst: Boolean;
FBackground: TBitmap;
procedure FSetWert(f: Real);
public
constructor Create(AOwner: TComponent);
override;
destructor Destroy;
override;
procedure paint;
override;
procedure Resize;
override;
procedure DrawBG;
procedure ZeichneZeiger;
published
property Wert: Real
read FAktZeiger
write FSetWert;
end;
procedure Register;
implementation
constructor TZeigerTest.Create(AOwner: TComponent);
begin
FBackground := TBitmap.Create;
inherited Create(AOwner);
FFirst := true;
DrawBG;
end;
destructor TZeigerTest.Destroy;
begin
inherited Destroy;
FBackground.Free;
end;
procedure TZeigerTest.Resize;
begin
inherited Resize;
DrawBG;
end;
procedure TZeigerTest.Paint;
begin
// beim ersten paint muss komischerweise einmal Drawbg aufgerufen werden ?????
if FFirst
then begin DrawBg; FFirst:=false;
end;
Canvas.Draw(0,0,FBackground);
ZeichneZeiger;
end;
procedure TZeigerTest.ZeichneZeiger;
var
temp: real;
Zahl:
String;
begin
with Canvas
do
begin
Pen.Color := clBlack;
Pen.Width := 2;
//alten zeiger übermalen
temp := round(FOldZeiger-90)*Pi/180;
Moveto( FRadius, FRadius);
Lineto( Round(Cos(temp)*(FRadius - 15))+FRadius, round(Sin(temp)*(FRadius - 15))+FRadius);
FOldZeiger := FAktZeiger;
Pen.Color := clWhite;
//neuen zeiger malen
temp := round(FAktZeiger-90)*Pi/180;
Moveto( FRadius, FRadius);
lineto( round(Cos(temp)*(FRadius - 15))+FRadius, round(Sin(temp)*(FRadius - 15))+FRadius);
Brush.Color := clBlack;
end;
// with
end;
procedure TZeigerTest.DrawBG;
var i: integer;
begin
// auf quadratische form bringen...
if width < Height
then FDurchmesser := width
else FDurchmesser:= Height;
FRadius:= FDurchmesser
div 2;
FBackground.Width :=width;
FBackground.height :=height;
with FBackground.Canvas
do
begin
brush.Color:=clBtnFace;
pen.Color:=clBtnFace;
// hintergrund grau malen
Rectangle(0,0,width,height);
Brush.Color:= clBlack;
pen.Color := clBlack;
pen.Width:=1;
// schwarzen kreis malen
ellipse(0,0,FDurchmesser,FDurchmesser);
pen.Color := clWhite;
pen.Width:=2;
// Skale an den Rand malen
for i:= 0
to 360
do
begin
if i
mod 30 = 0
then
begin
moveto(round(sin(i/360*2*Pi)*FRadius +FRadius), round(cos(i/360*2*Pi)*FRadius +FRadius));
lineto(round(sin(i/360*2*Pi)*(FRadius - 10)+FRadius), round(cos(i/360*2*Pi)*(FRadius - 10)+FRadius));
end // if
else
if i
mod 10 = 0
then
begin
moveto(round(sin(i/360*2*Pi)*FRadius +FRadius), round(cos(i/360*2*Pi)*FRadius +FRadius));
lineto(round(sin(i/360*2*Pi)*(FRadius - 5)+FRadius), round(cos(i/360*2*Pi)*(FRadius - 5)+FRadius));
end;
// else if
end;
//for
end;
end;
procedure TZeigerTest.FSetWert(f: Real);
begin
FAktZeiger:=f;
ZeichneZeiger;
end;
procedure Register;
begin RegisterComponents('
Beispiele', [TZeigerTest]);
end;
end.