mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-14 02:19:39 +02:00
LCL/TShape: Add user-defined polygon shape. No allocation of mask in constructor.
This commit is contained in:
parent
b473b8b1ed
commit
3ec349e0eb
@ -266,7 +266,12 @@ type
|
||||
TShapeType = (stRectangle, stSquare, stRoundRect, stRoundSquare,
|
||||
stEllipse, stCircle, stSquaredDiamond, stDiamond,
|
||||
stTriangle, stTriangleLeft, stTriangleRight, stTriangleDown,
|
||||
stStar, stStarDown);
|
||||
stStar, stStarDown, stPolygon);
|
||||
|
||||
TShapePoints = array of TPoint;
|
||||
|
||||
TShapePointsEvent = procedure (Sender: TObject; var Points: TShapePoints;
|
||||
var Winding: Boolean) of object;
|
||||
|
||||
TShape = class(TGraphicControl)
|
||||
private
|
||||
@ -275,9 +280,11 @@ type
|
||||
FShape: TShapeType;
|
||||
FBitmapCopy: TBitmap; // For testing if a mouse click is on the actual shape.
|
||||
FOnShapeClick: TNotifyEvent;
|
||||
FOnShapePoints: TShapePointsEvent;
|
||||
procedure SetBrush(Value: TBrush);
|
||||
procedure SetPen(Value: TPen);
|
||||
procedure SetShape(Value: TShapeType);
|
||||
procedure SetOnShapePoints(Value: TShapePointsEvent);
|
||||
protected
|
||||
class procedure WSRegisterClass; override;
|
||||
class function GetControlClassDefaultSize: TSize; override;
|
||||
@ -329,6 +336,7 @@ type
|
||||
property OnStartDock;
|
||||
property OnStartDrag;
|
||||
property OnShapeClick: TNotifyEvent read FOnShapeClick write FOnShapeClick;
|
||||
property OnShapePoints: TShapePointsEvent read FOnShapePoints write SetOnShapePoints;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -18,8 +18,6 @@ begin
|
||||
FPen.OnChange := @StyleChanged;
|
||||
FBrush := TBrush.Create;
|
||||
FBrush.OnChange := @StyleChanged;
|
||||
FBitmapCopy := TBitmap.Create;
|
||||
FBitmapCopy.Monochrome := True;
|
||||
end;
|
||||
|
||||
destructor TShape.Destroy;
|
||||
@ -79,6 +77,8 @@ var
|
||||
P: array[0..3] of TPoint;
|
||||
PStar: array[0..10] of TPoint;
|
||||
PenInc, PenDec: Integer;
|
||||
PolygonPts: array of TPoint;
|
||||
PolygonWinding: Boolean;
|
||||
RadiusBig, RadiusBig2, RadiusSm, i: Integer;
|
||||
PCenter: TPoint;
|
||||
begin
|
||||
@ -207,6 +207,15 @@ begin
|
||||
PStar[10] := PStar[0];
|
||||
ACanvas.Polygon(PStar);
|
||||
end;
|
||||
stPolygon:
|
||||
if Assigned(FOnShapePoints) then
|
||||
begin
|
||||
PolygonPts := nil;
|
||||
PolygonWinding := false;
|
||||
FOnShapePoints(Self, PolygonPts, PolygonWinding);
|
||||
if Length(PolygonPts) > 2 then
|
||||
ACanvas.Polygon(PolygonPts, PolygonWinding);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -250,6 +259,12 @@ begin
|
||||
FBrush.Assign(Value);
|
||||
end;
|
||||
|
||||
procedure TShape.SetOnShapePoints(Value: TShapePointsEvent);
|
||||
begin
|
||||
FOnShapePoints := Value;
|
||||
Invalidate;
|
||||
end;
|
||||
|
||||
procedure TShape.SetPen(Value: TPen);
|
||||
begin
|
||||
if Value <> Pen then
|
||||
|
Loading…
Reference in New Issue
Block a user