Back

{ Surface Test )
author: Nikolai Shokhirev  )
created: (January 01, 2001)
last modified: May 05, 2003)
ŠNikolai V. Shokhirev, 2001-2003 }
unit fSurface;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, ComCtrls, Buttons, StdCtrls, Spin, uMatTypes, uSurface;

type
  TFormSurface = class(TForm)
    TrackBarAngle: TTrackBar;
    TrackBarView: TTrackBar;
    PanelGraph: TPanel;
    PanelTop: TPanel;
    SpinEditNIntervals: TSpinEdit;
    Label1: TLabel;
    SpeedButtonColor: TSpeedButton;
    ColorDialog1: TColorDialog;
    procedure SpeedButtonColorClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpinEditNIntervalsChange(Sender: TObject);
    procedure TrackBarViewChange(Sender: TObject);
    procedure TrackBarAngleChange(Sender: TObject);
  private
    { Private declarations }
    fxMin, fxMax, fyMin, fyMax, fzMin, fzMax: TFloat;
    fAngle, fView: TFloat;
    Surface: TSurface;
    fSurfaceColor: TColor;
    fMargin: TInt;
    fZFunc: TZofXY;
    fNInterval: TInt;
    procedure PaintSurface(Sender: TObject);
    function GetNInterval: TInt;
    procedure SetNInterval(const Value: TInt);
  public
    { Public declarations }
    procedure Init;
    property Xmin: TFloat read fXmin write fXmin;
    property Xmax: TFloat read fXmax write fXmax;
    property Ymin: TFloat read fYmin write fYmin;
    property Ymax: TFloat read fYmax write fYmax;
    property Zmin: TFloat read fZmin write fZmin;
    property Zmax: TFloat read fZmax write fZmax;
    property Margin: TInt read fMargin write fMargin;
    property SurfaceColor: TColor read fSurfaceColor write fSurfaceColor;
    property ZFunc: TZofXY read fZFunc write fZFunc;
    property NInterval: TInt read GetNInterval write SetNInterval;
  end;

const
 MaxLine = 128;
 MinLine =  8;
var
  FormSurface: TFormSurface;

implementation

uses
  math;

{$R *.DFM}

procedure TFormSurface.FormCreate(Sender: TObject);
begin
  fxMin := -1.0;
  fxMax :=  1.0;
  fyMin := -1.0;
  fyMax :=  1.0;
  fzMin := -1.0;
  fzMax :=  1.0;
  fMargin := 16;
  fSurfaceColor := clRed;
  fAngle := 20.0;
  fView := 20.0;
  fNInterval := 16;
end;

procedure TFormSurface.Init;
begin
  Surface := TSurface.Create(self, PanelGraph);
  Surface.SetMinMax(xMin, xMax, yMin, yMax, zMin, zMax);
  Surface.SetDimensions(Margin, fView);
  Surface.Angle := fAngle;
  Surface.NInterval := fNInterval;
  Surface.SetFramePoints;
  Surface.GetOrder;
  Surface.LineColor := fSurfaceColor;
  Surface.FillColor := clWhite;
  if Assigned(fZFunc) then
    Surface.SetFunction(fZFunc);
  Surface.OnPaint := PaintSurface;
  PaintSurface(self);
//  FormResize(Sender: TObject);
end;

procedure TFormSurface.PaintSurface(Sender: TObject);
begin
  if Assigned(Surface) then
  begin
    Surface.Angle := fAngle;
    Surface.SetDimensions(Margin, fView);
    Surface.SetFramePoints;
    Surface.GetOrder;
    Surface.Clear;
    Surface.DrawFrame;
  end;
end;

procedure TFormSurface.SpeedButtonColorClick(Sender: TObject);
begin
  ColorDialog1.Color := fSurfaceColor;
  if ColorDialog1.Execute then
    fSurfaceColor := ColorDialog1.Color;
  if Assigned(Surface) then
  begin
    Surface.LineColor := fSurfaceColor;
    PaintSurface(self);
  end;
end;

function TFormSurface.GetNInterval: TInt;
begin
  result := fNInterval;
end;

procedure TFormSurface.SetNInterval(const Value: TInt);
begin
  fNInterval := Value;
  SpinEditNIntervals.Value := fNInterval;
  if Assigned(Surface) then
  begin
    Surface.NInterval := fNInterval;
    PaintSurface(self);
  end;
end;

procedure TFormSurface.SpinEditNIntervalsChange(Sender: TObject);
begin
  fNinterval := StrToIntDef(SpinEditNIntervals.Text, 16);
  if Assigned(Surface) then
  begin
    if fNInterval > MaxLine then fNInterval := MaxLine;
    if fNInterval < MinLine then fNInterval := MinLine;
    Surface.NInterval := fNInterval;
//    SpinEditNIntervals.Value := fNInterval;
    PaintSurface(self);
  end;
end;

procedure TFormSurface.TrackBarViewChange(Sender: TObject);
begin
  fView := -TrackBarView.Position-0.5;
  if Assigned(Surface) then
  begin
    Surface.SetDimensions(Margin, fView);
    PaintSurface(self);
  end;
end;

procedure TFormSurface.TrackBarAngleChange(Sender: TObject);
begin
  fAngle := TrackBarAngle.Position+0.5;
  if Assigned(Surface) then
  begin
    Surface.Angle := fAngle;
    PaintSurface(self);
  end;
end;

end.

Top

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