diff --git a/drawing demo/drawing.pas b/drawing demo/drawing.pas new file mode 100644 index 0000000..3c48512 --- /dev/null +++ b/drawing demo/drawing.pas @@ -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. + diff --git a/drawing demo/drawingdemo.ico b/drawing demo/drawingdemo.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/drawing demo/drawingdemo.ico differ diff --git a/drawing demo/drawingdemo.lpi b/drawing demo/drawingdemo.lpi new file mode 100644 index 0000000..1cc60d9 --- /dev/null +++ b/drawing demo/drawingdemo.lpi @@ -0,0 +1,83 @@ + + + + + + + + + <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> diff --git a/drawing demo/drawingdemo.lpr b/drawing demo/drawingdemo.lpr new file mode 100644 index 0000000..eb487a3 --- /dev/null +++ b/drawing demo/drawingdemo.lpr @@ -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. + diff --git a/drawing demo/drawingdisplay.lfm b/drawing demo/drawingdisplay.lfm new file mode 100644 index 0000000..65bc55c --- /dev/null +++ b/drawing demo/drawingdisplay.lfm @@ -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 diff --git a/drawing demo/drawingdisplay.pas b/drawing demo/drawingdisplay.pas new file mode 100644 index 0000000..151edad --- /dev/null +++ b/drawing demo/drawingdisplay.pas @@ -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. +