vectorgraphclassunit.pas

来自「在delphi7 下开发医学图象浏览器,对医学图象进行编辑,分析的」· PAS 代码 · 共 116 行

PAS
116
字号
unit VectorGraphClassUnit;

interface

uses
  Windows, SysUtils, Classes, Graphics, GraphicsClassUnit;

Type
  TVectorGraph = class
  private
    FGraphicsList: TList;
    function GetGraphics(Index: Integer): TGraphics;
    procedure SetGraphics(Index: Integer; AGraphics: TGraphics);
    function GetCount: Integer;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Paint(ACanvas: TCanvas);
    procedure Add(AGraphics: TGraphics);
    procedure Delete(AGraphics: TGraphics);
    procedure DeleteSelection;
    function GetGraphicsFromPoint(APoint: TPoint): TGraphics;
    property Count: Integer read GetCount;
    property Graphicses[Index: Integer]: TGraphics read GetGraphics write SetGraphics; default;
  end;

implementation

{ TVectorGraph }

////////////////////////////// Public //////////////////////////////

constructor TVectorGraph.Create;
begin
  FGraphicsList := TList.Create;
end;

destructor TVectorGraph.Destroy;
begin
  while FGraphicsList.Count > 0 do
  begin
    TGraphics(FGraphicsList[0]).Free;
    FGraphicsList.Delete(0);
  end;
  FGraphicsList.Free;
  
  inherited;
end;

{ 画出所有图形 }
procedure TVectorGraph.Paint(ACanvas: TCanvas);
var
  i: Integer;
begin
  for i := 0 to FGraphicsList.Count - 1 do
    TGraphics(FGraphicsList[i]).Paint(ACanvas);
end;

{ 增加图形 }
procedure TVectorGraph.Add(AGraphics: TGraphics);
begin
  FGraphicsList.Add(AGraphics);
end;

{ 删除一个图形 }
procedure TVectorGraph.Delete(AGraphics: TGraphics);
begin
  FGraphicsList.Delete(FGraphicsList.IndexOf(AGraphics));
end;

procedure TVectorGraph.DeleteSelection();
var
  i: Integer;
begin
  for i := FGraphicsList.Count - 1 downto 0 do
    if TGraphics(FGraphicsList[i]).Selected then
    begin
      TGraphics(FGraphicsList[i]).Free;
      FGraphicsList.Delete(i);
    end;
end;

{ 获取当前坐标上的图形 }
function TVectorGraph.GetGraphicsFromPoint(APoint: TPoint): TGraphics;
var
  i: Integer;
begin
  Result := nil;

  for i := FGraphicsList.Count - 1 downto 0 do
    if TGraphics(FGraphicsList[i]).PointInside(APoint) then
    begin
      Result := GetGraphics(i);
      Break;
    end;
end;

////////////////////////////// Private //////////////////////////////

function TVectorGraph.GetGraphics(Index: Integer): TGraphics;
begin
  Result := TGraphics(FGraphicsList[Index]);
end;

procedure TVectorGraph.SetGraphics(Index: Integer; AGraphics: TGraphics);
begin
  FGraphicsList[Index] := AGraphics;
end;

function TVectorGraph.GetCount(): Integer;
begin
  Result := FGraphicsList.Count;
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?