Ruby: How to shift GraphicsPath?

For general discussion related FlowStone
Post Reply
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Ruby: How to shift GraphicsPath?

Post by KG_is_back »

Let's say I have a GraphicsPath and I what to shift it or perhaps rotate it. Is there a method to do do it?

So far only way I can think of is to create new Path with all the elements shifted, which is not very convenient (especially if the elements are added at various places in code).
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: Ruby: How to shift GraphicsPath?

Post by Nubeat7 »

yes, if the different path elements are not directly related, like for a hanging cable, it will be pretty inconvenient to change each element by itself - i don't think that there is another way..

maybe its easier to create a bitmap from the view and resize, place or rotate the image
KG_is_back
Posts: 1196
Joined: Tue Oct 22, 2013 5:43 pm
Location: Slovakia

Re: Ruby: How to shift GraphicsPath?

Post by KG_is_back »

Yeah,... I've found something:
https://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.graphicspath.transform(v=vs.110).aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

Dunno if it's usable in Flowstone's Ruby.

Making a bitmap is not always a solution. For example the color may not be decided at the moment when shifting is needed.
Also I often use GraphicsPaths to define mouse interaction areas for "isInMousePoint" method, when more complicated shapes are used. That's also the case - I need to shift it, because the module gui should be scrollable. I know there are several alternatives, but I'm specifically asking if this solution is possible.
tulamide
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Ruby: How to shift GraphicsPath?

Post by tulamide »

KG_is_back wrote:Yeah,... I've found something:
https://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.graphicspath.transform(v=vs.110).aspx?cs-save-lang=1&cs-lang=cpp#code-snippet-1

Dunno if it's usable in Flowstone's Ruby.

Making a bitmap is not always a solution. For example the color may not be decided at the moment when shifting is needed.
Also I often use GraphicsPaths to define mouse interaction areas for "isInMousePoint" method, when more complicated shapes are used. That's also the case - I need to shift it, because the module gui should be scrollable. I know there are several alternatives, but I'm specifically asking if this solution is possible.


No, a transform matrix is not supported from the GraphicsPath class. However you might want to take a look at my spline class. I make use of graphic paths a lot there. The way I worked was to use my own transform matrix by normalizing each single part of the path. That means, instead of directly making a draw call like a rectangle with [10, 10, 20, 20], I calculate the ratio of the rect (1:1) and translate it to a coordinate system, where -1 means most left, most top and +1 one most right, most bottom, with 0 being the center of the object. A class keeps those values [-1, -1, 1, 1], and calculates the final gridstep values only in the draw method by calling a class method with the final dimensions: center 20,20 and size 20, 20 (All values just simplified examples)
It's not much work for the drawing method to do. Tests with the spline class let me draw thousands of graphic path elements reacting in realtime to audio input.
"There lies the dog buried" (German saying translated literally)
Post Reply