unit AchsenKreuz;
interface
uses
SysUtils, Classes, Controls, ExtCtrls,Dialogs,Graphics;
type TEPoint=record
x,y:extended;
end;
type TEPixel=record
x,y:integer;
col:TColor;
end;
type
TAchsenKreuz =
class(TPaintBox)
private
{ Private-Deklarationen }
Ffrom_x: extended;
Fto_y: extended;
Fto_x: extended;
Ffrom_y: extended;
t_width,t_height:extended;
Fdraw_axes: boolean;
td_pixels:
array of TEPixel;
Faxes_color: TColor;
procedure Setfrom_x(
const Value: extended);
procedure Setfrom_y(
const Value: extended);
procedure Setto_x(
const Value: extended);
procedure Setto_y(
const Value: extended);
procedure init_values();
procedure Setdraw_axes(
const Value: boolean);
procedure Setaxes_color(
const Value: TColor);
protected
{ Protected-Deklarationen }
public
{ Public-Deklarationen }
//Public zu Debug-Zwecken
x_scale,y_scale:extended;
org:TEPoint;
constructor Create(AOwner: TComponent);
override;
procedure Paint;
override;
procedure draw_point(x,y:extended;col:TColor);
function pix2point(px,py:integer):TEPoint;
procedure loschen;
published
{ Published-Deklarationen }
property from_x:extended
read Ffrom_x
write Setfrom_x;
property to_x:extended
read Fto_x
write Setto_x;
property from_y:extended
read Ffrom_y
write Setfrom_y;
property to_y:extended
read Fto_y
write Setto_y;
property draw_axes:boolean
read Fdraw_axes
write Setdraw_axes;
property axes_color:TColor
read Faxes_color
write Setaxes_color;
end;
procedure Register;
implementation
constructor TAchsenKreuz.Create(AOwner: TComponent);
begin;
//Bis jetzt noch unütz
setlength(td_pixels,0);
inherited Create(AOwner);
end;
procedure TAchsenKreuz.Paint;
var i:integer;
begin;
init_values;
//Bis jetz noch unütz
for i:= low(td_pixels)
to high(td_pixels)
do begin;
canvas.Pixels[td_pixels[i].x,td_pixels[i].y] := td_pixels[i].col;
end;
if (Fdraw_axes)
then begin;
Canvas.Pen.Color := Faxes_color;
canvas.Pen.Style := psSolid;
Canvas.MoveTo(round(org.X),0);
Canvas.LineTo(round(org.X),height);
Canvas.MoveTo(0,round(org.y));
Canvas.LineTo(width,round(org.y));
end;
end;
procedure TAchsenKreuz.draw_point(x,y:extended;col:TColor);
begin;
//Bis jetzt noch unütz
{setlength(td_pixels,length(td_pixels)+1);
td_pixels[high(td_pixels)].x := round(org.x + x*x_scale);
td_pixels[high(td_pixels)].y := round(org.y - y*y_scale);
td_pixels[high(td_pixels)].col := col;
}
canvas.Pixels[round(org.x + x*x_scale),round(org.y - y*y_scale)] := col;
paint;
end;
//Wandelt Delphi Pixel in Achsenkreu Koordinaten um
function TAchsenKreuz.pix2point(px,py:integer):TEPoint;
begin;
if ((x_scale>0)
AND (y_scale>0))
then begin;
result.x := (px-org.x)/x_scale;
result.y := (-py+org.y)/y_scale;
end
else begin;
result.x := 99999;
result.y := 99999;
end
end;
//löscht die paintbox
procedure TAchsenKreuz.loschen;
begin;
canvas.Brush.Color := color;
canvas.Pen.Style := psClear;
canvas.Rectangle(0,0,width,height);
end;
procedure Register;
begin
RegisterComponents('
Beispiele', [TAchsenKreuz]);
end;
//Berechnungen
procedure TAchsenKreuz.init_values;
begin
t_width := abs(ffrom_x)+abs(fto_x);
t_height:= abs(ffrom_y)+abs(fto_y);
if ((t_width>0)
AND (t_height>0))
then begin;
try
x_scale:=Width / t_width;
except
on E:
Exception do
messagedlg('
XScale '+floattostr(x_scale)+'
/'+floattostr(t_width)+'
'+ E.
Message,mterror,[mbok],0);
end;
try
y_scale:=self.Height / t_height;
except
on E:
Exception do
messagedlg('
YScale '+floattostr(Y_scale)+'
/'+floattostr(t_height)+'
'+ E.
Message,mterror,[mbok],0);
end;
org.X := ffrom_x*(-1)*x_scale;
org.y := fto_y*y_scale;
end;
end;
procedure TAchsenKreuz.Setdraw_axes(
const Value: boolean);
begin
Fdraw_axes := Value;
init_values;
end;
procedure TAchsenKreuz.Setfrom_x(
const Value: extended);
begin
Ffrom_x := Value;
init_values;
end;
procedure TAchsenKreuz.Setfrom_y(
const Value: extended);
begin
Ffrom_y := Value;
init_values;
end;
procedure TAchsenKreuz.Setto_x(
const Value: extended);
begin
Fto_x := Value;
init_values;
end;
procedure TAchsenKreuz.Setto_y(
const Value: extended);
begin
Fto_y := Value;
init_values;
end;
procedure TAchsenKreuz.Setaxes_color(
const Value: TColor);
begin
Faxes_color := Value;
end;
end.