📄 vectorgraphclassunit.pas
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -