lcl: don't auto select TPen.Cosmetic, let user do it through setter

example: adjust Pen and Brush example

git-svn-id: trunk@17362 -
This commit is contained in:
paul 2008-11-13 01:51:31 +00:00
parent e401f5c56b
commit 2965833d06
5 changed files with 64 additions and 71 deletions

View File

@ -218,7 +218,6 @@ object Form1: TForm1
'6'
'7'
)
MaxLength = -1
OnChange = PenChange
Style = csDropDownList
TabOrder = 1
@ -241,7 +240,6 @@ object Form1: TForm1
'Square'
'Flat'
)
MaxLength = -1
OnChange = PenChange
Style = csDropDownList
TabOrder = 2
@ -264,7 +262,6 @@ object Form1: TForm1
'Bevel'
'Mitter'
)
MaxLength = -1
OnChange = PenChange
Style = csDropDownList
TabOrder = 3
@ -296,7 +293,6 @@ object Form1: TForm1
BorderSpacing.Left = 100
BorderSpacing.Top = 7
ItemHeight = 13
MaxLength = -1
OnChange = PenChange
Style = csDropDownList
TabOrder = 5
@ -312,6 +308,7 @@ object Form1: TForm1
BorderSpacing.Left = 100
BorderSpacing.Top = 7
ItemHeight = 13
MaxLength = -1
OnChange = BrushChange
Style = csDropDownList
TabOrder = 6
@ -351,7 +348,6 @@ object Form1: TForm1
'Rectangle'
'Triangle'
)
MaxLength = -1
OnChange = FigureComboChange
Style = csDropDownList
TabOrder = 8

View File

@ -69,48 +69,47 @@ LazarusResources.Add('TForm1','FORMDATA',[
+'eTop.Control'#7#13'PenStyleCombo'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'L'
+'eft'#2'd'#6'Height'#2#21#3'Top'#3#4#1#5'Width'#2'n'#18'BorderSpacing.Left'#2
+'d'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#13#9'ItemIndex'#2#0#13'Items.'
+'Strings'#1#6#1'1'#6#1'2'#6#1'3'#6#1'4'#6#1'5'#6#1'6'#6#1'7'#0#9'MaxLength'#2
+#255#8'OnChange'#7#9'PenChange'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#1
+#4'Text'#6#1'1'#0#0#9'TComboBox'#9'CapsCombo'#22'AnchorSideLeft.Control'#7#5
+'Owner'#21'AnchorSideTop.Control'#7#11'PenColorBox'#18'AnchorSideTop.Side'#7
+#9'asrBottom'#4'Left'#2'd'#6'Height'#2#21#3'Top'#3'='#1#5'Width'#2'n'#18'Bor'
+'derSpacing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#13#9'ItemI'
+'ndex'#2#0#13'Items.Strings'#1#6#5'Round'#6#6'Square'#6#4'Flat'#0#9'MaxLengt'
+'h'#2#255#8'OnChange'#7#9'PenChange'#5'Style'#7#14'csDropDownList'#8'TabOrde'
+'r'#2#2#4'Text'#6#5'Round'#0#0#9'TComboBox'#9'JoinCombo'#22'AnchorSideLeft.C'
+'ontrol'#7#5'Owner'#21'AnchorSideTop.Control'#7#9'CapsCombo'#18'AnchorSideTo'
+'p.Side'#7#9'asrBottom'#4'Left'#2'd'#6'Height'#2#21#3'Top'#3'Y'#1#5'Width'#2
+'n'#18'BorderSpacing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#13
+#9'ItemIndex'#2#0#13'Items.Strings'#1#6#5'Round'#6#5'Bevel'#6#6'Mitter'#0#9
+'MaxLength'#2#255#8'OnChange'#7#9'PenChange'#5'Style'#7#14'csDropDownList'#8
+'TabOrder'#2#3#4'Text'#6#5'Round'#0#0#9'TColorBox'#11'PenColorBox'#22'Anchor'
+'SideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Control'#7#10'WidthCombo'#18
+'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2'd'#6'Height'#2#22#3'Top'#3' '#1
+#5'Width'#2'n'#5'Style'#11#16'cbStandardColors'#16'cbExtendedColors'#14'cbSy'
+'stemColors'#13'cbCustomColor'#13'cbPrettyNames'#0#18'BorderSpacing.Left'#2
+'d'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#16#8'OnChange'#7#9'PenChange'
+#8'TabOrder'#2#4#0#0#9'TComboBox'#13'PenStyleCombo'#22'AnchorSideLeft.Contro'
+'l'#7#5'Owner'#21'AnchorSideTop.Control'#7#6'Label1'#18'AnchorSideTop.Side'#7
+#9'asrBottom'#4'Left'#2'd'#6'Height'#2#21#3'Top'#3#232#0#5'Width'#2'n'#18'Bo'
+'rderSpacing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#13#9'MaxL'
+'ength'#2#255#8'OnChange'#7#9'PenChange'#5'Style'#7#14'csDropDownList'#8'Tab'
+'Order'#2#5#0#0#9'TComboBox'#15'BrushStyleCombo'#22'AnchorSideLeft.Control'#7
+#5'Owner'#21'AnchorSideTop.Control'#7#6'Label2'#18'AnchorSideTop.Side'#7#9'a'
+'srBottom'#4'Left'#2'd'#6'Height'#2#21#3'Top'#3#138#1#5'Width'#2'n'#18'Borde'
+'rSpacing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#13#8'OnChang'
+'e'#7#11'BrushChange'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#6#0#0#9'TC'
+'olorBox'#13'BrushColorBox'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorS'
+'ideTop.Control'#7#15'BrushStyleCombo'#18'AnchorSideTop.Side'#7#9'asrBottom'
+#4'Left'#2'd'#6'Height'#2#22#3'Top'#3#166#1#5'Width'#2'n'#8'Selected'#7#9'cl'
+'BtnFace'#5'Style'#11#16'cbStandardColors'#16'cbExtendedColors'#14'cbSystemC'
+'olors'#13'cbCustomColor'#13'cbPrettyNames'#0#18'BorderSpacing.Left'#2'd'#17
+'BorderSpacing.Top'#2#7#10'ItemHeight'#2#16#8'OnChange'#7#11'BrushChange'#8
+'TabOrder'#2#7#0#0#9'TComboBox'#11'FigureCombo'#22'AnchorSideLeft.Control'#7
+#5'Owner'#21'AnchorSideTop.Control'#7#8'PaintBox'#18'AnchorSideTop.Side'#7#9
+'asrBottom'#4'Left'#2'd'#6'Height'#2#21#3'Top'#3#183#0#5'Width'#2'n'#18'Bord'
+'erSpacing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#13#9'ItemIn'
+'dex'#2#0#13'Items.Strings'#1#6#4'Line'#6#8'PolyLine'#6#7'Ellipse'#6#9'Recta'
+'ngle'#6#8'Triangle'#0#9'MaxLength'#2#255#8'OnChange'#7#17'FigureComboChange'
+'Strings'#1#6#1'1'#6#1'2'#6#1'3'#6#1'4'#6#1'5'#6#1'6'#6#1'7'#0#8'OnChange'#7
+#9'PenChange'#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#1#4'Text'#6#1'1'#0
+#0#9'TComboBox'#9'CapsCombo'#22'AnchorSideLeft.Control'#7#5'Owner'#21'Anchor'
+'SideTop.Control'#7#11'PenColorBox'#18'AnchorSideTop.Side'#7#9'asrBottom'#4
+'Left'#2'd'#6'Height'#2#21#3'Top'#3'='#1#5'Width'#2'n'#18'BorderSpacing.Left'
+#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#13#9'ItemIndex'#2#0#13'Item'
+'s.Strings'#1#6#5'Round'#6#6'Square'#6#4'Flat'#0#8'OnChange'#7#9'PenChange'#5
+'Style'#7#14'csDropDownList'#8'TabOrder'#2#2#4'Text'#6#5'Round'#0#0#9'TCombo'
+'Box'#9'JoinCombo'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Co'
+'ntrol'#7#9'CapsCombo'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2'd'#6
+'Height'#2#21#3'Top'#3'Y'#1#5'Width'#2'n'#18'BorderSpacing.Left'#2'd'#17'Bor'
+'derSpacing.Top'#2#7#10'ItemHeight'#2#13#9'ItemIndex'#2#0#13'Items.Strings'#1
+#6#5'Round'#6#5'Bevel'#6#6'Mitter'#0#8'OnChange'#7#9'PenChange'#5'Style'#7#14
+'csDropDownList'#8'TabOrder'#2#3#4'Text'#6#5'Round'#0#0#9'TColorBox'#11'PenC'
+'olorBox'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Control'#7
+#10'WidthCombo'#18'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2'd'#6'Height'
+#2#22#3'Top'#3' '#1#5'Width'#2'n'#5'Style'#11#16'cbStandardColors'#16'cbExte'
+'ndedColors'#14'cbSystemColors'#13'cbCustomColor'#13'cbPrettyNames'#0#18'Bor'
+'derSpacing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#16#8'OnCha'
+'nge'#7#9'PenChange'#8'TabOrder'#2#4#0#0#9'TComboBox'#13'PenStyleCombo'#22'A'
+'nchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Control'#7#6'Label1'#18
+'AnchorSideTop.Side'#7#9'asrBottom'#4'Left'#2'd'#6'Height'#2#21#3'Top'#3#232
+#0#5'Width'#2'n'#18'BorderSpacing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'It'
+'emHeight'#2#13#8'OnChange'#7#9'PenChange'#5'Style'#7#14'csDropDownList'#8'T'
+'abOrder'#2#5#0#0#9'TComboBox'#15'BrushStyleCombo'#22'AnchorSideLeft.Control'
+#7#5'Owner'#21'AnchorSideTop.Control'#7#6'Label2'#18'AnchorSideTop.Side'#7#9
+'asrBottom'#4'Left'#2'd'#6'Height'#2#21#3'Top'#3#138#1#5'Width'#2'n'#18'Bord'
+'erSpacing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#13#9'MaxLen'
+'gth'#2#255#8'OnChange'#7#11'BrushChange'#5'Style'#7#14'csDropDownList'#8'Ta'
+'bOrder'#2#6#0#0#9'TColorBox'#13'BrushColorBox'#22'AnchorSideLeft.Control'#7
+#5'Owner'#21'AnchorSideTop.Control'#7#15'BrushStyleCombo'#18'AnchorSideTop.S'
+'ide'#7#9'asrBottom'#4'Left'#2'd'#6'Height'#2#22#3'Top'#3#166#1#5'Width'#2'n'
+#8'Selected'#7#9'clBtnFace'#5'Style'#11#16'cbStandardColors'#16'cbExtendedCo'
+'lors'#14'cbSystemColors'#13'cbCustomColor'#13'cbPrettyNames'#0#18'BorderSpa'
+'cing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHeight'#2#16#8'OnChange'#7
+#11'BrushChange'#8'TabOrder'#2#7#0#0#9'TComboBox'#11'FigureCombo'#22'AnchorS'
+'ideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Control'#7#8'PaintBox'#18'Anch'
+'orSideTop.Side'#7#9'asrBottom'#4'Left'#2'd'#6'Height'#2#21#3'Top'#3#183#0#5
+'Width'#2'n'#18'BorderSpacing.Left'#2'd'#17'BorderSpacing.Top'#2#7#10'ItemHe'
+'ight'#2#13#9'ItemIndex'#2#0#13'Items.Strings'#1#6#4'Line'#6#8'PolyLine'#6#7
+'Ellipse'#6#9'Rectangle'#6#8'Triangle'#0#8'OnChange'#7#17'FigureComboChange'
+#5'Style'#7#14'csDropDownList'#8'TabOrder'#2#8#4'Text'#6#4'Line'#0#0#9'TChec'
+'kBox'#10'cbCosmetic'#22'AnchorSideLeft.Control'#7#10'WidthCombo'#19'AnchorS'
+'ideLeft.Side'#7#9'asrBottom'#21'AnchorSideTop.Control'#7#10'WidthCombo'#18

View File

@ -176,17 +176,12 @@ procedure TForm1.PenChange(Sender: TObject);
var
Dashes: array[0..3] of DWord = (1, 1, 1, 1);
begin
cbCosmetic.Enabled := WidthCombo.ItemIndex = 0;
if PenStyleCombo.ItemIndex <> -1 then
PaintBox.Canvas.Pen.Style := TPenStyle(PenStyleCombo.ItemIndex);
PaintBox.Canvas.Pen.Color := PenColorBox.Selected;
if cbCosmetic.Enabled and cbCosmetic.Checked then
PaintBox.Canvas.Pen.Width := 0
else
PaintBox.Canvas.Pen.Width := StrToInt(WidthCombo.Text);
PaintBox.Canvas.Pen.Width := StrToInt(WidthCombo.Text);
PaintBox.Canvas.Pen.Cosmetic := cbCosmetic.Checked;
PaintBox.Canvas.Pen.EndCap := TPenEndCap(CapsCombo.ItemIndex);
PaintBox.Canvas.Pen.JoinStyle := TPenJoinStyle(JoinCombo.ItemIndex);
PaintBox.Canvas.Pen.SetPattern(Dashes);

View File

@ -595,6 +595,7 @@ type
function GetHandle: HPEN;
function GetReference: TWSPenReference;
procedure ReferenceNeeded;
procedure SetCosmetic(const AValue: Boolean);
procedure SetHandle(const Value: HPEN);
protected
procedure DoAllocateResources; override;
@ -619,7 +620,7 @@ type
procedure SetPattern(APattern: TPenPattern); reintroduce;
published
property Color: TColor read FColor write SetColor default clBlack;
property Cosmetic: Boolean read FCosmetic;
property Cosmetic: Boolean read FCosmetic write SetCosmetic;
property EndCap: TPenEndCap read FEndCap write SetEndCap default pecRound;
property JoinStyle: TPenJoinStyle read FJoinStyle write SetJoinStyle default pjsRound;
property Mode default pmCopy;

View File

@ -193,16 +193,9 @@ end;
------------------------------------------------------------------------------}
procedure TPen.SetWidth(Value : Integer);
begin
// Cosmetic pen is a pen which has width = 0. FCL does not allow pens < 1.
// FCosmetic field contains a knowledge about passed value
if (Value = 0) and (Width = 1) and Cosmetic then
Exit;
if (Width <> Value) or ((Width = 1) and Cosmetic) then
if (Width <> Value) then
begin
FreeReference;
FCosmetic := Value = 0;
inherited SetWidth(Value);
Changed;
end;
@ -256,15 +249,11 @@ var
begin
if Source is TPen then
begin
if APen.Cosmetic then
Width := 0
else
Width := APen.Width;
Width := APen.Width;
SetColor(APen.Color, TFPCanvasHelper(Source).FPColor);
Style := APen.Style;
Mode := APen.Mode;
Cosmetic := APen.Cosmetic;
JoinStyle := APen.JoinStyle;
EndCap := APen.EndCap;
end
@ -377,14 +366,17 @@ var
AExtPen: TExtLogPen;
ALogBrush: TLogBrush;
CachedPen: TPenHandleCacheDescriptor;
IsGeometric: Boolean;
begin
if FReference.Allocated then Exit;
IsGeometric := (Width > 1) or not Cosmetic;
FillChar(AExtPen, SizeOf(AExtPen), 0);
with AExtPen do
begin
elpPenStyle := PEN_STYLES[Style] or PEN_GEOMETRIC[not Cosmetic];
if not Cosmetic then
elpPenStyle := PEN_STYLES[Style] or PEN_GEOMETRIC[IsGeometric];
if IsGeometric then
elpPenStyle := elpPenStyle or PEN_ENDCAP[EndCap] or PEN_JOIN[JoinStyle];
elpWidth := Width;
elpBrushStyle := BS_SOLID;
@ -434,6 +426,16 @@ begin
FPenHandleCached := True;
end;
procedure TPen.SetCosmetic(const AValue: Boolean);
begin
if Cosmetic <> AValue then
begin
FreeReference;
FCosmetic := AValue;
Changed;
end;
end;
procedure TPen.SetEndCap(const AValue: TPenEndCap);
begin
if EndCap <> AValue then