It is currently Tue Mar 31, 2020 9:00 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Vectordrawing Flip Coordinates for Math/Cad Output
PostPosted: Sat Nov 09, 2019 11:59 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2329
Location: Germany
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:
;-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

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye