LCL/TShape: Inherit TShape from new TCustomShape class.

This commit is contained in:
wp_xyz 2023-09-12 12:03:44 +02:00
parent 10b0a6050a
commit c15b41d8ed
30 changed files with 93 additions and 86 deletions

View File

@ -273,7 +273,7 @@ type
TShapePointsEvent = procedure (Sender: TObject; var Points: TShapePoints;
var Winding: Boolean) of object;
TShape = class(TGraphicControl)
TCustomShape = class(TGraphicControl)
private
FPen: TPen;
FBrush: TBrush;
@ -298,22 +298,29 @@ type
function PtInShape(const P: TPoint): Boolean;
procedure Paint; override;
procedure StyleChanged(Sender: TObject);
property Brush: TBrush read FBrush write SetBrush;
property Pen: TPen read FPen write SetPen;
property Shape: TShapeType read FShape write SetShape default stRectangle;
property OnShapeClick: TNotifyEvent read FOnShapeClick write FOnShapeClick;
property OnShapePoints: TShapePointsEvent read FOnShapePoints write SetOnShapePoints;
end;
TShape = class(TCustomShape)
published
property Align;
property Anchors;
property BorderSpacing;
property Brush: TBrush read FBrush write SetBrush;
property Brush;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property ParentShowHint;
property Pen: TPen read FPen write SetPen;
property Shape: TShapeType read FShape write SetShape default stRectangle;
property Pen;
property Shape;
property ShowHint;
property Visible;
property OnChangeBounds;
property OnClick;
property OnDragDrop;
@ -335,8 +342,8 @@ type
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnShapeClick: TNotifyEvent read FOnShapeClick write FOnShapeClick;
property OnShapePoints: TShapePointsEvent read FOnShapePoints write SetOnShapePoints;
property OnShapeClick;
property OnShapePoints;
end;

View File

@ -8,7 +8,7 @@
*****************************************************************************
}
constructor TShape.Create(TheOwner: TComponent);
constructor TCustomShape.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
with GetControlClassDefaultSize do
@ -20,7 +20,7 @@ begin
FBrush.OnChange := @StyleChanged;
end;
destructor TShape.Destroy;
destructor TCustomShape.Destroy;
begin
FreeAndNil(FBitmapCopy);
FreeThenNil(FPen);
@ -28,7 +28,7 @@ begin
inherited Destroy;
end;
function TShape.PtInShape(const P: TPoint): Boolean;
function TCustomShape.PtInShape(const P: TPoint): Boolean;
// Return True if point P is inside the actual shape.
begin
UpdateMask;
@ -68,7 +68,7 @@ const
(Sin(9*pi/5 + pi/2), Sin(9*pi/5 - pi/2))
);
procedure TShape.DrawToCanvas(ACanvas: TCanvas);
procedure TCustomShape.DrawToCanvas(ACanvas: TCanvas);
const
cStarError = 2; // Detect N pixels error for 5-star horizontal lines
var
@ -229,7 +229,7 @@ begin
end;
end;
procedure TShape.UpdateMask;
procedure TCustomShape.UpdateMask;
begin
if FBitmapCopy = nil then
begin
@ -246,7 +246,7 @@ begin
DrawToCanvas(FBitmapCopy.Canvas);
end;
procedure TShape.Paint;
procedure TCustomShape.Paint;
begin
Canvas.Pen := FPen;
Canvas.Brush := FBrush;
@ -256,32 +256,32 @@ begin
inherited Paint;
end;
procedure TShape.StyleChanged(Sender: TObject);
procedure TCustomShape.StyleChanged(Sender: TObject);
begin
if (Parent <> nil) and (Visible or (csDesigning in ComponentState))
and Parent.HandleAllocated then
Invalidate;
end;
procedure TShape.SetBrush(Value: TBrush);
procedure TCustomShape.SetBrush(Value: TBrush);
begin
if Value <> Brush then
FBrush.Assign(Value);
end;
procedure TShape.SetOnShapePoints(Value: TShapePointsEvent);
procedure TCustomShape.SetOnShapePoints(Value: TShapePointsEvent);
begin
FOnShapePoints := Value;
Invalidate;
end;
procedure TShape.SetPen(Value: TPen);
procedure TCustomShape.SetPen(Value: TPen);
begin
if Value <> Pen then
FPen.Assign(Value);
end;
procedure TShape.SetShape(Value: TShapeType);
procedure TCustomShape.SetShape(Value: TShapeType);
begin
if FShape <> Value then
begin
@ -290,19 +290,19 @@ begin
end;
end;
class procedure TShape.WSRegisterClass;
class procedure TCustomShape.WSRegisterClass;
begin
inherited WSRegisterClass;
RegisterShape;
RegisterCustomShape;
end;
class function TShape.GetControlClassDefaultSize: TSize;
class function TCustomShape.GetControlClassDefaultSize: TSize;
begin
Result.CX := 65;
Result.CY := 65;
end;
procedure TShape.Click;
procedure TCustomShape.Click;
begin
inherited Click;
if Assigned(OnShapeClick)
@ -310,7 +310,7 @@ begin
OnShapeClick(Self);
end;
procedure TShape.CMShapeHitTest(var Message: TCMHittest);
procedure TCustomShape.CMShapeHitTest(var Message: TCMHittest);
var
p: TPoint;
begin

View File

@ -51,9 +51,9 @@ type
published
end;
{ TCarbonWSShape }
{ TCarbonWSCustomShape }
TCarbonWSShape = class(TWSShape)
TCarbonWSCustomShape = class(TWSCustomShape)
published
end;

View File

@ -62,7 +62,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -351,7 +351,7 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -51,9 +51,9 @@ type
public
end;
{ TCocoaWSShape }
{ TCocoaWSCustomShape }
TCocoaWSShape = class(TWSShape)
TCocoaWSCustomShape = class(TWSCustomShape)
private
protected
public

View File

@ -69,7 +69,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -362,7 +362,7 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -51,9 +51,9 @@ type
published
end;
{ TCDWSShape }
{ TCDWSCustomShape }
TCDWSShape = class(TWSShape)
TCDWSCustomShape = class(TWSCustomShape)
published
end;

View File

@ -58,7 +58,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -364,7 +364,7 @@ begin
Result := False;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -47,9 +47,9 @@ type
public
end;
{ TFpGuiWSShape }
{ TFpGuiWSCustomShape }
TFpGuiWSShape = class(TWSShape)
TFpGuiWSCustomShape = class(TWSCustomShape)
private
protected
public

View File

@ -57,7 +57,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -356,7 +356,7 @@ begin
Result := false;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -46,9 +46,9 @@ type
published
end;
{ TGtkWSShape }
{ TGtkWSCustomShape }
TGtkWSShape = class(TWSShape)
TGtkWSCustomShape = class(TWSCustomShape)
published
end;

View File

@ -58,7 +58,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -399,9 +399,9 @@ begin
{$ENDIF}
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
// RegisterWSComponent(TShape, TGtkWSShape);
// RegisterWSComponent(TCustomShape, TGtkWSCustomShape);
Result := False;
end;

View File

@ -50,9 +50,9 @@ type
published
end;
{ TGtk2WSShape }
{ TGtk2WSCustomShape }
TGtk2WSShape = class(TWSShape)
TGtk2WSCustomShape = class(TWSCustomShape)
published
end;

View File

@ -80,7 +80,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -402,9 +402,9 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
// RegisterWSComponent(TShape, TGtk2WSShape);
// RegisterWSComponent(TShape, TGtk2WSCustomShape);
Result := False;
end;

View File

@ -41,9 +41,9 @@ type
published
end;
{ TGtk3WSShape }
{ TGtk3WSCustomShape }
TGtk3WSShape = class(TWSShape)
TGtk3WSCustomShape = class(TWSCustomShape)
published
end;

View File

@ -73,7 +73,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -404,9 +404,9 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
// RegisterWSComponent(TShape, TGtk2WSShape);
// RegisterWSComponent(TCustomShape, TGtk2WSCustomShape);
Result := False;
end;

View File

@ -60,7 +60,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -350,7 +350,7 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -56,7 +56,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -319,7 +319,7 @@ begin
Result := False;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -44,9 +44,9 @@ type
published
end;
{ TQtWSShape }
{ TQtWSCustomShape }
TQtWSShape = class(TWSShape)
TQtWSCustomShape = class(TWSCustomShape)
published
end;

View File

@ -57,7 +57,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -366,7 +366,7 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -43,9 +43,9 @@ type
published
end;
{ TQtWSShape }
{ TQtWSCustomShape }
TQtWSShape = class(TWSShape)
TQtWSCustomShape = class(TWSCustomShape)
published
end;

View File

@ -57,7 +57,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -369,7 +369,7 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -43,9 +43,9 @@ type
published
end;
{ TQtWSShape }
{ TQtWSCustomShape }
TQtWSShape = class(TWSShape)
TQtWSCustomShape = class(TWSCustomShape)
published
end;

View File

@ -57,7 +57,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -369,7 +369,7 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -47,9 +47,9 @@ type
published
end;
{ TWin32WSShape }
{ TWin32WSCustomShape }
TWin32WSShape = class(TWSShape)
TWin32WSCustomShape = class(TWSCustomShape)
published
end;

View File

@ -57,7 +57,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -371,7 +371,7 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -50,9 +50,9 @@ type
public
end;
{ TWinCEWSShape }
{ TWinCEWSCustomShape }
TWinCEWSShape = class(TWSShape)
TWinCEWSCustomShape = class(TWSCustomShape)
private
protected
public

View File

@ -57,7 +57,7 @@ function RegisterCustomLabel: Boolean;
// extctrls
function RegisterCustomPage: Boolean;
function RegisterCustomNotebook: Boolean;
function RegisterShape: Boolean;
function RegisterCustomShape: Boolean;
function RegisterCustomSplitter: Boolean;
function RegisterPaintBox: Boolean;
function RegisterCustomImage: Boolean;
@ -360,7 +360,7 @@ begin
Result := True;
end;
function RegisterShape: Boolean; alias : 'WSRegisterShape';
function RegisterCustomShape: Boolean; alias : 'WSRegisterCustomShape';
begin
Result := False;
end;

View File

@ -57,9 +57,9 @@ type
const ADefaultColorType: TDefaultColorType): TColor; override;
end;
{ TWSShape }
{ TWSCustomShape }
TWSShape = class(TWSGraphicControl)
TWSCustomShape = class(TWSGraphicControl)
published
end;
@ -162,7 +162,7 @@ type
{ WidgetSetRegistration }
procedure RegisterShape;
procedure RegisterCustomShape;
procedure RegisterCustomSplitter;
procedure RegisterPaintBox;
procedure RegisterCustomImage;
@ -224,14 +224,14 @@ end;
{ WidgetSetRegistration }
procedure RegisterShape;
procedure RegisterCustomShape;
const
Done: Boolean = False;
begin
if Done then exit;
WSRegisterShape;
// if not WSRegisterShape then
// RegisterWSComponent(TShape, TWSShape);
WSRegisterCustomShape;
// if not WSRegisterCustomShape then
// RegisterWSComponent(TCustomShape, TWSCustomShape);
Done := True;
end;

View File

@ -79,7 +79,7 @@ function WSRegisterCustomLabel: Boolean; external name 'WSRegisterCustomLa
// extctrls
function WSRegisterCustomPage: Boolean; external name 'WSRegisterCustomPage';
function WSRegisterCustomNotebook: Boolean; external name 'WSRegisterCustomNotebook';
function WSRegisterShape: Boolean; external name 'WSRegisterShape';
function WSRegisterCustomShape: Boolean; external name 'WSRegisterCustomShape';
function WSRegisterCustomSplitter: Boolean; external name 'WSRegisterCustomSplitter';
function WSRegisterPaintBox: Boolean; external name 'WSRegisterPaintBox';
function WSRegisterCustomImage: Boolean; external name 'WSRegisterCustomImage';