examples: add bitmap pattern brush to pen and brush example

git-svn-id: trunk@16780 -
This commit is contained in:
paul 2008-09-29 05:15:17 +00:00
parent e3a48da832
commit 34fcc43209
4 changed files with 66 additions and 31 deletions

View File

@ -45,13 +45,23 @@
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<ResourceFilename Value="unit1.lrs"/> <ResourceFilename Value="unit1.lrs"/>
<UnitName Value="Unit1"/> <UnitName Value="Unit1"/>
<CursorPos X="19" Y="46"/> <CursorPos X="43" Y="79"/>
<TopLine Value="42"/> <TopLine Value="49"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<UsageCount Value="23"/> <UsageCount Value="23"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit1> </Unit1>
</Units> </Units>
<JumpHistory Count="2" HistoryIndex="1">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="23" Column="43" TopLine="21"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="24" Column="44" TopLine="22"/>
</Position2>
</JumpHistory>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>
<Version Value="8"/> <Version Value="8"/>

View File

@ -6,6 +6,8 @@ object Form1: TForm1
Caption = 'Pen & Brush' Caption = 'Pen & Brush'
ClientHeight = 425 ClientHeight = 425
ClientWidth = 400 ClientWidth = 400
OnCreate = FormCreate
OnDestroy = FormDestroy
ParentFont = False ParentFont = False
Position = poScreenCenter Position = poScreenCenter
LCLVersion = '0.9.27' LCLVersion = '0.9.27'

View File

@ -3,31 +3,32 @@
LazarusResources.Add('TForm1','FORMDATA',[ LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'^'#1#6'Height'#3#169#1#3'Top'#3#215#0#5'W' 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3'^'#1#6'Height'#3#169#1#3'Top'#3#215#0#5'W'
+'idth'#3#144#1#7'Caption'#6#11'Pen & Brush'#12'ClientHeight'#3#169#1#11'Clie' +'idth'#3#144#1#7'Caption'#6#11'Pen & Brush'#12'ClientHeight'#3#169#1#11'Clie'
+'ntWidth'#3#144#1#10'ParentFont'#8#8'Position'#7#14'poScreenCenter'#10'LCLVe' +'ntWidth'#3#144#1#8'OnCreate'#7#10'FormCreate'#9'OnDestroy'#7#11'FormDestroy'
+'rsion'#6#6'0.9.27'#0#6'TLabel'#6'Label1'#22'AnchorSideLeft.Control'#7#5'Own' +#10'ParentFont'#8#8'Position'#7#14'poScreenCenter'#10'LCLVersion'#6#6'0.9.27'
+'er'#21'AnchorSideTop.Control'#7#5'Owner'#4'Left'#2#11#6'Height'#2#14#3'Top' +#0#6'TLabel'#6'Label1'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTo'
+#2#11#5'Width'#2#28#18'BorderSpacing.Left'#2#11#17'BorderSpacing.Top'#2#11#7 +'p.Control'#7#5'Owner'#4'Left'#2#11#6'Height'#2#14#3'Top'#2#11#5'Width'#2#28
+'Caption'#6#5'Pens:'#11'ParentColor'#8#0#0#9'TPaintBox'#6'PenBox'#22'AnchorS' +#18'BorderSpacing.Left'#2#11#17'BorderSpacing.Top'#2#11#7'Caption'#6#5'Pens:'
+'ideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Control'#7#6'Label1'#18'Anchor' +#11'ParentColor'#8#0#0#9'TPaintBox'#6'PenBox'#22'AnchorSideLeft.Control'#7#5
+'SideTop.Side'#7#9'asrBottom'#23'AnchorSideRight.Control'#7#5'Owner'#20'Anch' +'Owner'#21'AnchorSideTop.Control'#7#6'Label1'#18'AnchorSideTop.Side'#7#9'asr'
+'orSideRight.Side'#7#9'asrBottom'#4'Left'#2#11#6'Height'#2'i'#3'Top'#2' '#5 +'Bottom'#23'AnchorSideRight.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7#9
+'Width'#3'z'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#18'BorderSpacin' +'asrBottom'#4'Left'#2#11#6'Height'#2'i'#3'Top'#2' '#5'Width'#3'z'#1#7'Anchor'
+'g.Left'#2#11#17'BorderSpacing.Top'#2#7#19'BorderSpacing.Right'#2#11#7'OnPai' +'s'#11#5'akTop'#6'akLeft'#7'akRight'#0#18'BorderSpacing.Left'#2#11#17'Border'
+'nt'#7#11'PenBoxPaint'#0#0#6'TLabel'#6'Label2'#22'AnchorSideLeft.Control'#7#5 +'Spacing.Top'#2#7#19'BorderSpacing.Right'#2#11#7'OnPaint'#7#11'PenBoxPaint'#0
+'Owner'#21'AnchorSideTop.Control'#7#6'PenBox'#18'AnchorSideTop.Side'#7#9'asr' +#0#6'TLabel'#6'Label2'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTo'
+'Bottom'#4'Left'#2#11#6'Height'#2#14#3'Top'#3#148#0#5'Width'#2'+'#18'BorderS' +'p.Control'#7#6'PenBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2#11#6
+'pacing.Left'#2#11#17'BorderSpacing.Top'#2#11#7'Caption'#6#8'Brushes:'#11'Pa' +'Height'#2#14#3'Top'#3#148#0#5'Width'#2'+'#18'BorderSpacing.Left'#2#11#17'Bo'
+'rentColor'#8#0#0#9'TPaintBox'#8'BrushBox'#22'AnchorSideLeft.Control'#7#5'Ow' +'rderSpacing.Top'#2#11#7'Caption'#6#8'Brushes:'#11'ParentColor'#8#0#0#9'TPai'
+'ner'#21'AnchorSideTop.Control'#7#6'Label2'#18'AnchorSideTop.Side'#7#9'asrBo' +'ntBox'#8'BrushBox'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTop.C'
+'ttom'#23'AnchorSideRight.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7#9'a' +'ontrol'#7#6'Label2'#18'AnchorSideTop.Side'#7#9'asrBottom'#23'AnchorSideRigh'
+'srBottom'#4'Left'#2#11#6'Height'#3#207#0#3'Top'#3#169#0#5'Width'#3'z'#1#7'A' +'t.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7#9'asrBottom'#4'Left'#2#11#6
+'nchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#18'BorderSpacing.Left'#2#11#17'B' +'Height'#3#207#0#3'Top'#3#169#0#5'Width'#3'z'#1#7'Anchors'#11#5'akTop'#6'akL'
+'orderSpacing.Top'#2#7#19'BorderSpacing.Right'#2#11#7'OnPaint'#7#13'BrushBox' +'eft'#7'akRight'#0#18'BorderSpacing.Left'#2#11#17'BorderSpacing.Top'#2#7#19
+'Paint'#0#0#7'TBitBtn'#7'Button1'#21'AnchorSideTop.Control'#7#8'BrushBox'#18 +'BorderSpacing.Right'#2#11#7'OnPaint'#7#13'BrushBoxPaint'#0#0#7'TBitBtn'#7'B'
+'AnchorSideTop.Side'#7#9'asrBottom'#23'AnchorSideRight.Control'#7#5'Owner'#20 +'utton1'#21'AnchorSideTop.Control'#7#8'BrushBox'#18'AnchorSideTop.Side'#7#9
+'AnchorSideRight.Side'#7#9'asrBottom'#4'Left'#3'3'#1#6'Height'#2#26#3'Top'#3 +'asrBottom'#23'AnchorSideRight.Control'#7#5'Owner'#20'AnchorSideRight.Side'#7
+#131#1#5'Width'#2'R'#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'AutoSiz' +#9'asrBottom'#4'Left'#3'3'#1#6'Height'#2#26#3'Top'#3#131#1#5'Width'#2'R'#7'A'
+'e'#9#17'BorderSpacing.Top'#2#11#19'BorderSpacing.Right'#2#11#7'Caption'#6#15 +'nchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'AutoSize'#9#17'BorderSpacing.T'
+'&'#208#151#208#176#208#186#209#128#209#139#209#130#209#140#4'Kind'#7#7'bkCl' +'op'#2#11#19'BorderSpacing.Right'#2#11#7'Caption'#6#15'&'#208#151#208#176#208
+'ose'#9'NumGlyphs'#2#0#7'OnClick'#7#12'Button1Click'#8'TabOrder'#2#0#0#0#0 +#186#209#128#209#139#209#130#209#140#4'Kind'#7#7'bkClose'#9'NumGlyphs'#2#0#7
+'OnClick'#7#12'Button1Click'#8'TabOrder'#2#0#0#0#0
]); ]);

View File

@ -20,9 +20,11 @@ type
BrushBox: TPaintBox; BrushBox: TPaintBox;
procedure BrushBoxPaint(Sender: TObject); procedure BrushBoxPaint(Sender: TObject);
procedure Button1Click(Sender: TObject); procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PenBoxPaint(Sender: TObject); procedure PenBoxPaint(Sender: TObject);
private private
{ private declarations } FPattern: TBitmap;
public public
{ public declarations } { public declarations }
end; end;
@ -42,20 +44,40 @@ begin
Close; Close;
end; end;
procedure TForm1.FormCreate(Sender: TObject);
const
LineBitsDotted: array[0..7] of Word = ($55, $AA, $55, $AA, $55, $AA, $55, $AA);
begin
FPattern := TBitmap.Create;
FPattern.SetHandles(CreateBitmap(8, 8, 1, 1, @LineBitsDotted), 0);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FPattern.Free;
end;
procedure TForm1.BrushBoxPaint(Sender: TObject); procedure TForm1.BrushBoxPaint(Sender: TObject);
var var
bs: TBrushStyle; bs: TBrushStyle;
y: integer; y: integer;
begin begin
y := 15;
for bs := bsSolid to bsDiagCross do for bs := bsSolid to bsDiagCross do
begin begin
y := 15 * (Ord(bs) + 1);
BrushBox.Canvas.Brush.Color := clBtnFace; BrushBox.Canvas.Brush.Color := clBtnFace;
BrushBox.Canvas.TextOut(10, y - 7, GetEnumName(TypeInfo(TBrushStyle), Ord(bs))); BrushBox.Canvas.TextOut(10, y - 7, GetEnumName(TypeInfo(TBrushStyle), Ord(bs)));
BrushBox.Canvas.Brush.Color := clRed; BrushBox.Canvas.Brush.Color := clRed;
BrushBox.Canvas.Brush.Style := bs; BrushBox.Canvas.Brush.Style := bs;
BrushBox.Canvas.FillRect(120, y - 5, PenBox.Width - 10, y + 5); BrushBox.Canvas.FillRect(120, y - 5, PenBox.Width - 10, y + 5);
inc(y, 15);
end; end;
BrushBox.Canvas.Brush.Color := clBtnFace;
BrushBox.Canvas.TextOut(10, y - 7, 'Pattern');
BrushBox.Canvas.Brush.Color := clRed;
BrushBox.Canvas.Brush.Bitmap := FPattern;
BrushBox.Canvas.FillRect(120, y - 5, PenBox.Width - 10, y + 5);
end; end;
procedure TForm1.PenBoxPaint(Sender: TObject); procedure TForm1.PenBoxPaint(Sender: TObject);