Back

{TPainterLight and TPainter classes)
author: Nikolai Shokhirev )
created: (June 6, 2002)
last modified: November 2, 2002)
ŠNikolai V. Shokhirev, 2002-2003 }
unit uPainter;

interface

uses
  classes, extctrls, uMatTypes, controls, Graphics, Windows;

type

  TPainterLight = class(TPaintBox)
  private
    fXmin: TFloat;
    fXmax: TFloat;
    fYmin: TFloat;
    fYmax: TFloat;
    fNXmin: TInt;
    fNXmax: TInt;
    fNYmin: TInt;
    fNYmax: TInt;
    fIWidth: TFloat;
    fIHeight: TFloat;
    fRWidth: TFloat;
    fRHeight: TFloat;
    fXYRatio: TFloat;
    fPPUX, fPPUY: TFloat;
    fBgColor: TColor; // used in Clear
    function GetXmin: TFloat;
    function GetXmax: TFloat;
    function GetYmin: TFloat;
    function GetYmax: TFloat;
    procedure SetXmin(const Value: TFloat);
    procedure SetXmax(const Value: TFloat);
    procedure SetYmin(const Value: TFloat);
    procedure SetYmax(const Value: TFloat);
    function GetXYRatio: TFloat;
    procedure SetXYRatio(const Value: TFloat);
    function GetPPUX: TFloat;
    function GetPPUY: TFloat;
    function GetBgColor: TColor;
    procedure SetBgColor(const Value: TColor);
    function GetBrushColor: TColor;
    function GetPenColor: TColor;
    procedure SetBrushColor(const Value: TColor);
    procedure SetPenColor(const Value: TColor);
    function GetPenWidth: integer;
    procedure SetPenWidth(const Value: integer);
  public
    constructor Create(aOwner: TComponent; aParent: TWinControl);  reintroduce;
    destructor Destroy; override;
    procedure SetRanges(aXmin, aXmax, aYmin, aYmax, aXYRatio: TFloat);
    procedure SetPPU;
    procedure Clear;
    function rRect2iRect(x1, x2, y1, y2: TFloat): TRect;
    function rx2ix(x: TFloat): TInt;
    function ry2iy(y: TFloat): TInt;
    function ix2rx(ix: TInt): TFloat;
    function iy2ry(iy: TInt): TFloat;
    procedure MoveTo(x, y: TFloat);
    procedure LineTo(x, y: TFloat);
    procedure Line(x1, y1, x2, y2: TFloat);
    procedure Circle(x, y, r: TFloat);
    property Xmin: TFloat read GetXmin write SetXmin;
    property Xmax: TFloat read GetXmax write SetXmax;
    property Ymin: TFloat read GetYmin write SetYmin;
    property Ymax: TFloat read GetYmax write SetYmax;
    property PPUX: TFloat read GetPPUX;
    property PPUY: TFloat read GetPPUY;
    property XYRatio: TFloat read GetXYRatio write SetXYRatio;
    property BgColor: TColor read GetBgColor write SetBgColor;
    property PenColor: TColor read GetPenColor write SetPenColor;
    property PenWidth: integer read GetPenWidth write SetPenWidth;
    property BrushColor: TColor read GetBrushColor write SetBrushColor;
  end;

  TPainter = class(TPainterLight)
  private
    fDelta: TFloat;
    fXOrigin: TFloat;  // Origin
    fYOrigin: TFloat;  // Origin
    fInitialAngle: TFloat;
    fCurrentAngle: TFloat;
    fMouseIsDown: boolean;
    function GetXOrigin: TFloat;
    function GetYOrigin: TFloat;
    procedure SetXOrigin(const Value: TFloat);
    procedure SetYOrigin(const Value: TFloat);
    function GetDelta: TFloat;
    procedure SetDelta(const Value: TFloat);
    function GetMouseIsDown: boolean;
    procedure SetMouseIsDown(const Value: boolean);
    function GetCurrentAngle: TFloat;
    function GetInitialAngle: TFloat;
    procedure SetCurrentAngle(const Value: TFloat);
    procedure SetInitialAngle(const Value: TFloat);
  public
    constructor Create(aOwner: TComponent; aParent: TWinControl); //override;
//    destructor Destroy; override;
    procedure SetRanges(aXmin, aXmax, aYmin, aYmax, aXYRatio: TFloat);
    procedure LineC(x1, y1, x2, y2: TFloat; c: TColor);
    procedure CircleC(x, y, r: TFloat; c: TColor);
    function Angle(x, y: TFloat): TFloat;
    function RelAngle(x2, y2, x1, y1: TFloat): TFloat;
    function HitLine(x1, y1, x2, y2: TFloat; ix, iy: TInt): boolean;
    function HitDot(rx, ry: TFloat; ix, iy: TInt): boolean;
    property Delta: TFloat read GetDelta write SetDelta;
    property XOrigin: TFloat read GetXOrigin write SetXOrigin;
    property YOrigin: TFloat read GetYOrigin write SetYOrigin;
    property InitialAngle: TFloat read GetInitialAngle write SetInitialAngle;
    property CurrentAngle: TFloat read GetCurrentAngle write SetCurrentAngle;
    property MouseIsDown: boolean read GetMouseIsDown write SetMouseIsDown;
  end;

implementation

uses
  Math;

end.

Top

Back

Generated by Lore's Source to HTML Converter(http://www.newty.de/lsc/index.html)