Vector Drawing Change coordinates system

Just starting out? Need help? Post your questions and find answers here.
IdeasVacuum
Always Here
Always Here
Posts: 6425
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Vector Drawing Change coordinates system

Post by IdeasVacuum »

Hi Guys

I love the PB forum :wink: Thanks for the many replies and smart ideas. I have had a ton of great ideas for other parts of the App but had a brain freeze when first trying-out the Vector Lib.

The image I posted is representative of the number of lines that make the shape, +- 3 or 4, so very light data. My App adds some geometry too. With the Compiler set to dpi aware, the resulting diagram, in pixels, is actually way more accurate than required, so I'm chuffed about that.

I think the AddPathBox() function might be Fred's own addition? It would be incredibly useful if we had a function to define the ordinate system - for "serious" drawing, that would negate a lot of Flip Coordinate calls and other bits of incoming data management.

It's a pity that the function naming is rather inconsistent too. Could have prefixed every Lib function with "Vector"........
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Vector Drawing Change coordinates system

Post by Little John »

This is all that's needed:

Code: Select all

Macro ReverseVector_Y_Coordinates()
   FlipCoordinatesY(VectorOutputHeight() / 2)
EndMacro
Working demo:

Code: Select all

; PB 5.71

EnableExplicit

Macro ReverseVector_Y_Coordinates()
   FlipCoordinatesY(VectorOutputHeight() / 2)
EndMacro


Macro Vector_LineXY (_x1_, _y1_, _x2_, _y2_)
   MovePathCursor(_x1_, _y1_)
   AddPathLine(_x2_, _y2_)
EndMacro

#Window = 0
#Canvas = 0

Define event.i, width.i=450, height.i=300

If OpenWindow(#Window, 0, 0, width, height, "Standard math coordinate system", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) = 0
   MessageRequester("Fatal error", "Can't open main window.")
   End
EndIf

CanvasGadget(#Canvas, 0, 0, width, height)

If StartVectorDrawing(CanvasVectorOutput(#Canvas))
   ; Draw a blue "L" near the lower left corner,
   ; using the standard math coordinate system:
   ReverseVector_Y_Coordinates()
   Vector_LineXY(20, 80, 20, 20)
   Vector_LineXY(20, 20, 50, 20)
   VectorSourceColor(RGBA(0, 0, 255, 255))
   StrokePath(5)
   
   ResetCoordinates()       ; Restore the default coordinate system.
   StopVectorDrawing()
EndIf

Repeat
   event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Vector Drawing Change coordinates system

Post by mk-soft »

Like my example with macros. "Begin - EndFlipCoordinates".
You can also do this between DrawVectorText and ResetCoordinates.

viewtopic.php?f=13&t=73976&start=0#p544297
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Vector Drawing Change coordinates system

Post by Little John »

mk-soft wrote:Like my example with macros. "Begin - EndFlipCoordinates".
You can also do this between DrawVectorText and ResetCoordinates.

viewtopic.php?f=13&t=73976&start=0#p544297
Sorry, in my opinion your code is unnecessarily complicated (as well as other codes in this thread).
So I felt the need to show that there is a simple and straightforward solution to the problem.
Post Reply