Giter VIP home page Giter VIP logo

castlelines2d's People

Contributors

kumurtash avatar michaliskambi avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

michaliskambi

castlelines2d's Issues

Use TRegisteredComponent.OnCreate to create initial TCastlePolygon2D / TCastleLine2D contents at design-time

I noticed you use a pattern like this to fill a newly-created instance of TCastlePolygon2D / TCastleLine2D with initial points:

constructor TCastlePolygon2D.Create(AOwner: TComponent);
begin
  inherited;
  ...

  {$ifdef CASTLE_DESIGN_MODE}
  Points.Add(Vector2(0,80));
  Points.Add(Vector2(25,35));
  ....
  ReLoad;
  {$endif}
end;

It means that this initialization happens always (at design-time, in editor) when TCastlePolygon2D is created, even when TCastlePolygon2D is created only to be deserialized (loaded) from a JSON file. In your code, these Points will be effectively overridden later by TCastleLine2DBase.CustomSerialization, which makes the end result correct... but adding these points at every construction is unnecessary.

It may be better to just add these initial points once when the TCastlePolygon2D / TCastleLine2D are added by user to the design. This is the purpose of TRegisteredComponent.OnCreate method. See https://castle-engine.io/custom_components#_children_components_that_user_can_freely_edit_and_remove_using_tregisteredcomponent_oncreate for usage, although the example there is more complicated than you need, as the example shows how to add children components. You instead want to just initialize points. Something like this may be good:

type
  TCastlePolygon2D = class...
  private
    class procedure CreateInitialPoints(Sender: TObject);
    ...
  end;

class procedure TCastlePolygon2D.CreateInitialPoints(Sender: TObject);
begin
  P := Sender as TCastlePolygon2D;
  P.Points.Add(Vector2(0,80));
  P.Points.Add(Vector2(25,35));
  ....
  P.ReLoad;
end;

var
  R: TRegisteredComponent;
initialization
  R := TRegisteredComponent.Create;
  R.ComponentClass := TCastlePolygon2D;
  R.Caption := ['Polygon2D Transform'];
  R.OnCreate := {$ifdef FPC}@{$endif}TMyRectanglesGroup.CreateInitialPoints;
  RegisterSerializableComponent(R);
end.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.