Vectordrawing Flip Coordinates for Math/Cad Output

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Vectordrawing Flip Coordinates for Math/Cad Output

Post by mk-soft »

For graphical output of mathematical or CAD coordinates, you often need the correct alignment of the Y-axis and the direction of rotation.

This is possible with FlipCoordinatesY, but unfortunately it is not possible to suppress the rotation of the texts.
Maybe an additional parameter that does not mirror the text.
Or a parameter that always remains flipped, even after ResetCoordinates.

Current solution.

Code: Select all

;-TOP
; Flip Y-Coordinates by mk-soft, v0.6

EnableExplicit

Global _IsFlipped_, _OldY_.d

Macro _PB_(Function)
  Function
EndMacro

Macro BeginFlipCoordinates()
  FlipCoordinatesY(VectorOutputHeight() * 0.5) : _IsFlipped_ = #True
EndMacro

Macro EndFlipCoordinates()
  _PB_(ResetCoordinates)() : _IsFlipped_ = #False
EndMacro

Macro ResetCoordinates(_Value_=#PB_Coordinate_User)
  _PB_(ResetCoordinates)(_Value_) : If _IsFlipped_ : FlipCoordinatesY(VectorOutputHeight() * 0.5, _Value_) : EndIf
EndMacro

Macro DrawVectorText(_Text_)
  If _IsFlipped_
    _OldY_ = PathCursorY()
    FlipCoordinatesY(_OldY_) : _PB_(DrawVectorText)(_Text_) : FlipCoordinatesY(_OldY_)
  Else
    _PB_(DrawVectorText)(_Text_)
  EndIf
EndMacro

Define i

If OpenWindow(0, 0, 0, 450, 300, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  CanvasGadget(0, 0, 0, 450, 300)
  LoadFont(0, "Impact", 11)
  
  If StartVectorDrawing(CanvasVectorOutput(0))
    VectorFont(FontID(0))
    
    MovePathCursor(10, 10)
    DrawVectorText("Flip Coordinates Example")
    
    BeginFlipCoordinates()
    
    ; Part 1
    ResetCoordinates()
    
    AddPathSegments("M 40 20 L 120 20 L 120 60 L 200 60 L 200 100 L 280 100 L 280 140 L 360 140 L 360 180")
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(5, #PB_Path_RoundCorner)
    
    MovePathCursor(10, 30)
    RotateCoordinates(10, 30, 45)
    DrawVectorText("Red Line")
    
    ;Part 2
    ResetCoordinates()
    
    TranslateCoordinates(50, 50)      
    
    AddPathSegments("M 40 20 L 120 20 L 120 60 L 200 60 L 200 100 L 280 100 L 280 140 L 360 140 L 360 180")
    VectorSourceColor(RGBA(0, 0, 255, 255))
    StrokePath(5, #PB_Path_RoundCorner)
    
    MovePathCursor(10, 30)
    RotateCoordinates(10, 30, 45)
    DrawVectorText("Blue Line")
    
    ; Part 3
    ResetCoordinates()
    
    AddPathCircle(80, 80, 50, 0, 45)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(5, #PB_Path_RoundCorner)
    
    AddPathCircle(80, 80, 50, 45, 90)
    VectorSourceColor(RGBA(0, 0, 255, 255))
    StrokePath(5, #PB_Path_RoundCorner)
    
    ; Part 4
    ResetCoordinates()
    
    VectorSourceColor(RGBA(64, 64, 64, 255))
    For i = 0 To 260 Step 20
      MovePathCursor(420, i + 20)
      DrawVectorText(Str(i))
    Next
    
    EndFlipCoordinates()
    
    StopVectorDrawing()
  EndIf
  
  Repeat
    Define Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
[/size]
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