Custom TTMSFNCBloxBlock descendant with fixed aspect ratio

Hello, I am trying to create some custom Blox but am unclear how to do create something with a fixed aspect ratio.

If I override GetBlockPath and add lines (with APath.AddLine) sized to make a square, sure enough the block looks like a square when added to the TTMSFNCBloxControl. However, when I stretch the block, the square stretched into a rectangle.

The same is true if I add a circle with, say, APath.AddEllipse(0, 0, 100, 100).

What do I need to do in order to specify a shape that retains its aspect ratio when the block is resized. I want to make a square and a circle block, which can be made larger or smaller, with the block filling the boundary as best it can (i.e. using the shorter distance in the boundary to decide on edge size or diameter size).

Can you please advise?

Thanks

Can you post or send a sample with the code you already have? We'll be able to look more closely to see what happens and what is missing?

Sure thing:

  TCircleTableBlox = class(TTMSFNCBloxBlock)
  protected
    procedure GetBlockPath(APath: TTMSFNCBloxDGRPath; ADrawer: TTMSFNCBloxBlockDrawer); override;
  end;

  TSquareTableBlox = class(TTMSFNCBloxBlock)
  protected
    procedure GetBlockPath(APath: TTMSFNCBloxDGRPath; ADrawer: TTMSFNCBloxBlockDrawer); override;
  end;
...
{ TCircleTableBlox }

procedure TCircleTableBlox.GetBlockPath(APath: TTMSFNCBloxDGRPath; ADrawer: TTMSFNCBloxBlockDrawer);
begin
  APath.AddEllipse(0, 0, 100, 100);
end;

{ TSquareTableBlox }

procedure TSquareTableBlox.GetBlockPath(APath: TTMSFNCBloxDGRPath; ADrawer: TTMSFNCBloxBlockDrawer);
begin
  APath.AddLine(0, 0, 100, 0);
  APath.AddLine(100, 0, 100, 100);
  APath.AddLine(100, 100, 0, 100);
  APath.AddLine(0, 100, 0, 0);
end;

Clearly this is inadequate for the goal, but I do not understand how to specify a shape that will not transform as the block is resized. In the case of the square block, even if the block is resized to 200 x 100 pixels, I want the block to render as a 100x100 square in the midst of that 200x100 boundary

I believe I have solved this one.

I need to ensure the Restrictions property is set appropriately:

Restrictions := Restrictions + [TTMSFNCBloxRestriction.crKeepRatio]

It turns out that crKeepRatio had been removed from the set of Restrictions, so this one is now addressed.

Thanks

Thank you for the feedback.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.