Add not-quite-working graphics polymophism demo
This commit is contained in:
parent
1169375c4e
commit
010d124826
56
drawing demo/drawing.pas
Normal file
56
drawing demo/drawing.pas
Normal file
@ -0,0 +1,56 @@
|
||||
unit drawing;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Controls, ExtCtrls, Graphics;
|
||||
|
||||
type TDrawing = class(TGraphicControl)
|
||||
private
|
||||
FExtent: integer;
|
||||
public
|
||||
constructor Create(theOwner: TComponent; anExtent: integer);
|
||||
property Extent: integer read FExtent write FExtent;
|
||||
end;
|
||||
|
||||
TSquare = class(TDrawing)
|
||||
public
|
||||
procedure Paint; override;
|
||||
end;
|
||||
|
||||
TCircle = class(TDrawing)
|
||||
public
|
||||
procedure Paint; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
constructor TDrawing.Create(theOwner: TComponent; anExtent: integer);
|
||||
begin
|
||||
inherited Create(theOwner);
|
||||
FExtent := anExtent;
|
||||
Width := FExtent;
|
||||
Height := FExtent;
|
||||
end;
|
||||
|
||||
{TCircle}
|
||||
procedure TCircle.Paint;
|
||||
begin
|
||||
Canvas.Brush.Color := clBtnFace;
|
||||
Canvas.FillRect(0, 0, FExtent, FExtent);
|
||||
Canvas.Brush.Color := clYellow;
|
||||
Canvas.Ellipse(0, 0, FExtent, FExtent);
|
||||
end;
|
||||
|
||||
{TSquare}
|
||||
procedure TSquare.Paint;
|
||||
begin
|
||||
Canvas.Brush.Color := clSilver;
|
||||
Canvas.FillRect(0, 0, FExtent, FExtent);
|
||||
Canvas.Rectangle(0, 0, FExtent, FExtent);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
BIN
drawing demo/drawingdemo.ico
Normal file
BIN
drawing demo/drawingdemo.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
83
drawing demo/drawingdemo.lpi
Normal file
83
drawing demo/drawingdemo.lpi
Normal file
@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="11"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<Title Value="drawingdemo"/>
|
||||
<Scaled Value="True"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<XPManifest>
|
||||
<DpiAware Value="True"/>
|
||||
</XPManifest>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<BuildModes Count="1">
|
||||
<Item1 Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
<Modes Count="0"/>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="1">
|
||||
<Item1>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item1>
|
||||
</RequiredPackages>
|
||||
<Units Count="3">
|
||||
<Unit0>
|
||||
<Filename Value="drawingdemo.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="drawingdisplay.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="drawing.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit2>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target>
|
||||
<Filename Value="drawingdemo"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<DebugInfoType Value="dsDwarf2Set"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
26
drawing demo/drawingdemo.lpr
Normal file
26
drawing demo/drawingdemo.lpr
Normal file
@ -0,0 +1,26 @@
|
||||
program drawingdemo;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms,
|
||||
Controls,
|
||||
Graphics,
|
||||
ExtCtrls,
|
||||
drawing,
|
||||
drawingdisplay;
|
||||
|
||||
{$R *.res}
|
||||
|
||||
begin
|
||||
RequireDerivedFormResource:=True;
|
||||
// Application.Scaled:=True;
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm1, Form1);
|
||||
Application.Run;
|
||||
end.
|
||||
|
34
drawing demo/drawingdisplay.lfm
Normal file
34
drawing demo/drawingdisplay.lfm
Normal file
@ -0,0 +1,34 @@
|
||||
object Form1: TForm1
|
||||
Left = 627
|
||||
Height = 240
|
||||
Top = 322
|
||||
Width = 320
|
||||
Caption = 'Polymorphic drawing example'
|
||||
ClientHeight = 240
|
||||
ClientWidth = 320
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '2.0.12.0'
|
||||
object rgShape: TRadioGroup
|
||||
Left = 41
|
||||
Height = 68
|
||||
Top = 141
|
||||
Width = 239
|
||||
AutoFill = True
|
||||
Caption = 'Type of FDrawing'
|
||||
ChildSizing.LeftRightSpacing = 6
|
||||
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
|
||||
ChildSizing.EnlargeVertical = crsHomogenousChildResize
|
||||
ChildSizing.ShrinkHorizontal = crsScaleChilds
|
||||
ChildSizing.ShrinkVertical = crsScaleChilds
|
||||
ChildSizing.Layout = cclLeftToRightThenTopToBottom
|
||||
ChildSizing.ControlsPerLine = 1
|
||||
ClientHeight = 49
|
||||
ClientWidth = 229
|
||||
Items.Strings = (
|
||||
'TSquare'
|
||||
'TCircle'
|
||||
)
|
||||
OnClick = rgShapeClick
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
62
drawing demo/drawingdisplay.pas
Normal file
62
drawing demo/drawingdisplay.pas
Normal file
@ -0,0 +1,62 @@
|
||||
unit drawingdisplay;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, drawing;
|
||||
type
|
||||
{ TForm1 }
|
||||
TForm1 = class(TForm)
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure rgShapeClick(Sender: TObject);
|
||||
private
|
||||
rgShape: TRadioGroup;
|
||||
FDrawing: TDrawing;
|
||||
procedure CreateANewDrawing;
|
||||
public
|
||||
end;
|
||||
|
||||
const extent = 50;
|
||||
|
||||
var
|
||||
Form1: TForm1;
|
||||
|
||||
implementation
|
||||
|
||||
procedure TForm1.CreateANewDrawing;
|
||||
begin
|
||||
if (rgShape.ItemIndex < 0) then Exit;
|
||||
|
||||
FDrawing.Free;
|
||||
|
||||
case rgShape.ItemIndex of
|
||||
0: begin
|
||||
FDrawing := TSquare.Create(Self, extent);
|
||||
FDrawing.Left := 10;
|
||||
end;
|
||||
1: begin
|
||||
FDrawing := TCircle.Create(Self, extent);
|
||||
FDrawing.Left := 60;
|
||||
end;
|
||||
end;
|
||||
|
||||
FDrawing.Top := 10;
|
||||
FDrawing.Parent := Self;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
begin
|
||||
CreateANewDrawing;
|
||||
end;
|
||||
|
||||
procedure TForm1.rgShapeClick(Sender: TObject);
|
||||
begin
|
||||
CreateANewDrawing;
|
||||
end;
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user