Recent

Author Topic: recent additions to TShape, have ideas for more shapes.  (Read 945 times)

jamie

  • Hero Member
  • *****
  • Posts: 5835
recent additions to TShape, have ideas for more shapes.
« on: September 11, 2023, 05:54:42 pm »
I like the recent addition to the TShape to be able to restrict the click event and also the HitTest that was added.

is it possible to add some basic Hexagon, Heptagon, Octagon, Nonagon, Decagon to the list? It seems we miss this and to use a TShape for flow charting. :D

If that is too complex of an addition, then maybe allow for a Polygone Property specified by the user code and add a customshape to the list to specify the user Polygone property.

 I have done this already in a control of my own because Delphi does not have all these complex shapes in there.

 Just a thought, Thanks.
The only true wisdom is knowing you know nothing

AlexTP

  • Hero Member
  • *****
  • Posts: 2288
    • UVviewsoft
Re: recent additions to TShape, have ideas for more shapes.
« Reply #1 on: September 11, 2023, 05:57:49 pm »
For painting 5-angle star, I have added const, ie array of const, which is ocupying some memory. Pls see the code. I think more shapes will need more such arrays. More memory usage.

wp

  • Hero Member
  • *****
  • Posts: 11445
Re: recent additions to TShape, have ideas for more shapes.
« Reply #2 on: September 11, 2023, 06:09:23 pm »
I have a TShapeEx in the ExCtrls package (https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/exctrls/) which has a Header and a Text property. See https://wiki.freepascal.org/ExCtrls#TShapeEx. Since it is not part of the LCL there is more freedom in extending it. Post a patch for the additional shapes.

AlexTP

  • Hero Member
  • *****
  • Posts: 2288
    • UVviewsoft
Re: recent additions to TShape, have ideas for more shapes.
« Reply #3 on: September 11, 2023, 06:10:37 pm »
Maybe, just maybe, better to add the event like OnGetPolygon so any app can supply its own set of polygon points.

I also think that it's better to add content to TShapeEx.

wp

  • Hero Member
  • *****
  • Posts: 11445
Re: recent additions to TShape, have ideas for more shapes.
« Reply #4 on: September 11, 2023, 08:05:32 pm »
I also think that it's better to add content to TShapeEx.
Looking at this in more detail I found that this is a quite difficult task without rewriting much of the control because it is not possible to extend the TShapeType enumeration by another element. Therefore I decided to put this into TShape where there is a stPolygon type now in which you pass the polygon coordinates in the OnShapePoints event.

The attached project demonstrates the new features. But note: The project requires a very recent Laz/main (https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/6873e2646a944b9b9c1c42410250fa1c913ed531 at least).
« Last Edit: September 11, 2023, 08:07:09 pm by wp »

jamie

  • Hero Member
  • *****
  • Posts: 5835
Re: recent additions to TShape, have ideas for more shapes.
« Reply #5 on: September 11, 2023, 09:09:19 pm »
Can someone remind me how to define a dynamic array of Tpoint directly from a constant set of indices?

I know how to do it with a Const array, but setting the length of the dynamic array and then simply make it equal the values from a constant stream of values like you would creating a const of this same type, is eluding me.


EDIT

  I come up with a solution to that, I create the constant array as a const and use that as the assignment to the dynamic array, that seems to work.

 The only hitch I see atm would need to run a function on the values to auto size the Polygone to fit the current size of the box, otherwise it seems to work.

 I guess a flag could be added to test for that, MakeTOFit :Boolean ...

 Thanks for this additions, I will have to install the Trunk on the work PC to take advantage of this.
« Last Edit: September 11, 2023, 09:22:05 pm by jamie »
The only true wisdom is knowing you know nothing

n7800

  • New Member
  • *
  • Posts: 48
Re: recent additions to TShape, have ideas for more shapes.
« Reply #6 on: September 12, 2023, 09:31:12 am »
Quote
Maybe, just maybe, better to add the event like OnGetPolygon so any app can supply its own set of polygon points.

Events are typically used to obtain "dynamic" data. In addition, using events is inconvenient - you need to create a separate function and assign an event to it.

I think it's enough to just use a property with an array of points:

Code: Pascal  [Select][+][-]
  1. property PolygonPoints: TPointArray

TPointArray defined in GraphType unit, although you could declare it in ExtCtrls.

n7800

  • New Member
  • *
  • Posts: 48
Re: recent additions to TShape, have ideas for more shapes.
« Reply #7 on: September 12, 2023, 09:32:13 am »
Quote
The only hitch I see atm would need to run a function on the values to auto size the Polygone to fit the current size of the box, otherwise it seems to work.

You can also use percentages for coordinates (a floating number from 0.0 to 1.0), but your option is better. I don't think it needs the "MakeToFit" option at all. Who needs to create a figure that won't be completely visible?

n7800

  • New Member
  • *
  • Posts: 48
Re: recent additions to TShape, have ideas for more shapes.
« Reply #8 on: September 12, 2023, 09:54:16 am »
Quote
is it possible to add some basic Hexagon, Heptagon, Octagon, Nonagon, Decagon to the list?

Why not add the "PolygonVerticesCount: integer" property, with which you can specify the number of vertices of the polygon. When you set it, a regular polygon will be automatically generated, and you can easily get "hexagon, heptagon, octagon, nonagon, decagon". And if PolygonVerticesCount is equal to -1, then a custom array of points will be used.

By the way, in this case, triangle and square will be a special case (although they will be inscribed in a circle).
You can even display a circle with zero vertices - this is also a polygon (albeit with an infinite number of vertices).

(PolygonWinding can also be made a property)
« Last Edit: September 12, 2023, 10:18:03 am by n7800 »

n7800

  • New Member
  • *
  • Posts: 48
Re: recent additions to TShape, have ideas for more shapes.
« Reply #9 on: September 12, 2023, 10:21:39 am »
Regular polygons are easy to generate points using a formula, and it is easy to add an Angle or Turn property to it, which will contain the rotation angle. This will make the shapes stTriangle, stTriangleDown, stTriangleLeft, stTriangleRight and stSquaredDiamond "unnecessary".

The "star" is also easy to generate using the formula. For it you only need to specify the inner circle.

n7800

  • New Member
  • *
  • Posts: 48
Re: recent additions to TShape, have ideas for more shapes.
« Reply #10 on: September 12, 2023, 10:23:10 am »
In general, I’m curious, could you tell me for what purposes you use TShape? When I have to work with graphics, I always use TImage or the Canvas property directly. I have not found a single purpose for which I could use it.

jamie

  • Hero Member
  • *****
  • Posts: 5835
Re: recent additions to TShape, have ideas for more shapes.
« Reply #11 on: October 06, 2023, 11:47:09 pm »
I would like to gain access to the Mask image so i can build an array of points that intersect to the image at a specific angle.

For example, If I wanted to intersect at 0 degrees (3600/0) like the format currently use for arcs etc., to plot the X, Y point to where it will meet the image.

  and if I used 45 Degree it would mathematically calculate that angle giving me the plot point.

  The reason for this is I want to connect to the image at whatever angle I wish and maybe even include an option in the parameter to offset Xn. of pixels from the actual contact point.

 Getting access to the masked image would be nice since it does get created at some point, I can free it afterwards, it's not something I need to keep alive.
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018