Page 1 of 1

Ruby: How to shift GraphicsPath?

Posted: Thu Apr 23, 2015 5:26 pm
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).

Re: Ruby: How to shift GraphicsPath?

Posted: Thu Apr 23, 2015 7:38 pm
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

Re: Ruby: How to shift GraphicsPath?

Posted: Thu Apr 23, 2015 8:18 pm
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.

Re: Ruby: How to shift GraphicsPath?

Posted: Thu Apr 23, 2015 9:55 pm
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.