Step 4 - Implement Paint and PointInObject Methods

From RAD Studio
Jump to: navigation, search

Go Up to Creating a FireMonkey Primitive Control

This is the final step to complete this primitive component. Define the following additional members (members previously created are not listed here):

type
  TRegularPolygon = class(TShape)
  protected
    procedure Paint; override;
  public
    function PointInObject(X, Y: Single): Boolean; override;
  end;

As in the previous steps, use CTRL+SHIFT+C to create placeholders for these methods. Implement these methods as follows:

procedure TRegularPolygon.Paint;
begin
  CreatePath;
  Canvas.FillPath(FPath, AbsoluteOpacity);
  Canvas.DrawPath(FPath, AbsoluteOpacity);
end;

function TRegularPolygon.PointInObject(X, Y: Single): Boolean;
begin
  CreatePath;
  Result := Canvas.PtInPath(AbsoluteToLocal(PointF(X, Y)), FPath);
end;

Now the TRegularPolygon component is implemented. In the Project Manager, right-click the TRegularPolygon.bpl package and select Build from the context menu. Then select Install to install the developed component package and to register the designed component:

2657.png

Now you can see the new behavior of the TRegularPolygon component in the Form Designer.

Previous

Next