chemtext: Add demo for usage of painting routine in custom-drawn grid.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5962 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2017-06-25 21:28:36 +00:00
parent 63fa370c20
commit 0202c3c2af
6 changed files with 256 additions and 2 deletions

View File

@ -117,7 +117,7 @@ object Form1: TForm1
object Edit1: TEdit
Left = 32
Height = 26
Top = 168
Top = 184
Width = 329
OnChange = Edit1Change
TabOrder = 0
@ -126,7 +126,7 @@ object Form1: TForm1
object ChemLabel4: TChemLabel
Left = 32
Height = 36
Top = 208
Top = 224
Width = 131
Arrow = caUTF8Single
Caption = '(CH3)3COH'
@ -136,4 +136,12 @@ object Form1: TForm1
ParentColor = False
ParentFont = False
end
object Label4: TLabel
Left = 32
Height = 18
Top = 162
Width = 140
Caption = 'Type a formula here:'
ParentColor = False
end
end

View File

@ -11,6 +11,7 @@ type
{ TForm1 }
TForm1 = class(TForm)
Label4: TLabel;
Spacer: TBevel;
ChemLabel1: TChemLabel;
ChemLabel2: TChemLabel;

View File

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="10"/>
<PathDelim Value="\"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="project1"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<Icon Value="0"/>
</General>
<VersionInfo>
<StringTable ProductVersion=""/>
</VersionInfo>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
</PublishOptions>
<RunParams>
<local>
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="2">
<Item1>
<PackageName Value="laz_chemtext"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="project1"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<UseExternalDbgSyms Value="True"/>
</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>

View File

@ -0,0 +1,21 @@
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, Unit1
{ you can add units after this };
{$R *.res}
begin
RequireDerivedFormResource := True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@ -0,0 +1,78 @@
object Form1: TForm1
Left = 280
Height = 240
Top = 130
Width = 687
Caption = 'ChemText in StringGrid'
ClientHeight = 240
ClientWidth = 687
OnCreate = FormCreate
LCLVersion = '1.9.0.0'
object StringGrid1: TStringGrid
Left = 8
Height = 224
Top = 8
Width = 671
Align = alClient
AutoFillColumns = True
BorderSpacing.Around = 8
ColCount = 4
DefaultDrawing = False
TabOrder = 0
OnDrawCell = StringGrid1DrawCell
ColWidths = (
32
211
211
213
)
Cells = (
15
1
0
'Substance'
1
1
'Water (H2O)'
1
2
'Ferric chloride (Fe3Cl)'
1
3
'Ammonium nitrate (NH4NO3)'
1
4
'Copper sulfate (CuSO4)'
2
0
'Density (g/cm³)'
2
1
'1.0'
2
2
'2.9'
2
3
'1.72'
2
4
'3.6'
3
0
'Molar mass (g/mole)'
3
1
'18.01528'
3
2
'162.2'
3
3
'80.043'
3
4
'159.609'
)
end
end

View File

@ -0,0 +1,62 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids, Types;
type
{ TForm1 }
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
uses
chemtext;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.DefaultRowHeight := ChemTextHeight(StringGrid1.Canvas, 'H2') + 2*constCellpadding;
end;
procedure TForm1.StringGrid1DrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
var
X, Y: Integer;
txt: String;
begin
X := ARect.Left + constCellpadding;
Y := ARect.Top + constCellpadding;
txt := StringGrid1.Cells[ACol, ARow];
StringGrid1.Canvas.FillRect(ARect);
case ACol of
0 : if ARow > 0 then StringGrid1.Canvas.TextOut(X, Y, IntToStr(ARow));
1 : ChemTextOut(StringGrid1.Canvas, X, Y, txt)
else StringGrid1.Canvas.TextOut(X, Y, txt);
end;
end;
end.