It is currently Fri Jun 22, 2018 1:00 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [VectorDrawing-v561]Rotate/ResetCoordinates() changes units.
PostPosted: Thu Jan 11, 2018 4:25 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2665
Location: Boston, MA
I cannot draw shapes correctly(in original Pixel units) after a RotateCoordinates() or ResetCoordinates() command?
I have to StopVectorDrawing() and start another StartVectorDrawing() session to draw as normal.
See the Blue rectangle outline running Bug() and NoBug().

EDIT:
Workaround: SaveVectorState() prior to RotateCoordinates(), then RestoreVectorState().

Code:
EnableExplicit
Procedure Bug()
  Protected.s s$ = "1234"
  Protected.d rWd, rHt, rX, rY
  Protected.d tWd, tHt, tX, tY
  Protected.i evWW, hFnt, txSize
  If OpenWindow(0, 0, 0, 300, 300, "Rotate Coordinates Bug?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 300, 300)
    LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
    hFnt = FontID(0)
    If StartVectorDrawing(CanvasVectorOutput(0))
      ;/////////////////////////////////////////////////////
      ; Horizontal Rectangle
      ;/////////////////////////////////////////////////////
      rWd = 140
      rHt = 30
      AddPathBox(5, 5, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = 30
      VectorFont(hFnt, txSize)
      tHt = VectorTextHeight(s$)
      tWd = VectorTextWidth(s$)
      MovePathCursor(5+rwd/2-twd/2, 5+rht/2-tht/2)
      DrawVectorText(s$)
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, Text Wd & Ht swapped.
      ;/////////////////////////////////////////////////////
      rWd = 30
      rHt = 140
      AddPathBox(150, 5, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 255, 0, 255))
      StrokePath(1)
      tht = VectorTextWidth(s$)
      twd = VectorTextHeight(s$)
      MovePathCursor(150+rwd/2-twd/2, 5+rht/2+tht/2)
      RotateCoordinates(PathCursorX(), PathCursorY(), -90)
      DrawVectorText(s$)
      ResetCoordinates()
    ;NOBUG;;  StopVectorDrawing()
    ;NOBUG;;EndIf
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, But text drawn as topdown paragraph.
      ;/////////////////////////////////////////////////////
    ;NOBUG;;If StartVectorDrawing(CanvasVectorOutput(0))
      rWd = 30
      rHt = 140
      AddPathBox(5, 40, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 0, 255, 255))
      StrokePath(1)
      ; Try paragraph text
      VectorFont(hFnt, txSize-6)
      s$ = "1" + #LF$ + "2" + #LF$ + "3" + #LF$ + "4"
      twd = VectorTextWidth(s$)
      tht = VectorTextHeight(s$)
      MovePathCursor(5+rwd/2-twd/2, 40+rht/2-tht/2)
      DrawVectorParagraph(s$, 30, 140, #PB_VectorParagraph_Center)
      StopVectorDrawing()
    EndIf
    Repeat
      evWW = WaitWindowEvent()
    Until evWW = #PB_Event_CloseWindow
  EndIf
EndProcedure
Procedure NoBug()
  Protected.s s$ = "1234"
  Protected.d rWd, rHt, rX, rY
  Protected.d tWd, tHt, tX, tY
  Protected.i evWW, hFnt, txSize
  If OpenWindow(0, 0, 0, 300, 300, "Rotate Coordinates Issue?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 300, 300)
    LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
    hFnt = FontID(0)
    If StartVectorDrawing(CanvasVectorOutput(0))
      ;/////////////////////////////////////////////////////
      ; Horizontal Rectangle
      ;/////////////////////////////////////////////////////
      rWd = 140
      rHt = 30
      AddPathBox(5, 5, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      txSize = 30
      VectorFont(hFnt, txSize)
      tHt = VectorTextHeight(s$)
      tWd = VectorTextWidth(s$)
      MovePathCursor(5+rwd/2-twd/2, 5+rht/2-tht/2)
      DrawVectorText(s$)
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, Text Wd & Ht swapped.
      ;/////////////////////////////////////////////////////
      rWd = 30
      rHt = 140
      AddPathBox(150, 5, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 255, 0, 255))
      StrokePath(1)
      tht = VectorTextWidth(s$)
      twd = VectorTextHeight(s$)
      MovePathCursor(150+rwd/2-twd/2, 5+rht/2+tht/2)
      RotateCoordinates(PathCursorX(), PathCursorY(), -90)
      DrawVectorText(s$)
      ResetCoordinates()
      StopVectorDrawing()
    EndIf
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, But text drawn as topdown paragraph.
      ;/////////////////////////////////////////////////////
    If StartVectorDrawing(CanvasVectorOutput(0))
      rWd = 30
      rHt = 140
      AddPathBox(5, 40, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 0, 255, 255))
      StrokePath(1)
      ; Try paragraph text
      VectorFont(hFnt, txSize-6)
      s$ = "1" + #LF$ + "2" + #LF$ + "3" + #LF$ + "4"
      twd = VectorTextWidth(s$)
      tht = VectorTextHeight(s$)
      MovePathCursor(5+rwd/2-twd/2, 40+rht/2-tht/2)
      DrawVectorParagraph(s$, 30, 140, #PB_VectorParagraph_Center)
      StopVectorDrawing()
    EndIf
    Repeat
      evWW = WaitWindowEvent()
    Until evWW = #PB_Event_CloseWindow
  EndIf
EndProcedure
CompilerIf 1
  Bug()
CompilerElse
  NoBug()
CompilerEndIf

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Last edited by skywalk on Thu Jan 11, 2018 7:30 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: [VectorDrawing-v561] RotateCoordinates() changes units?
PostPosted: Thu Jan 11, 2018 5:39 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2665
Location: Boston, MA
Also, the drawing behavior is different if I startvectordrawing and immediately issue a ResetCoordinates()?

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: [VectorDrawing-v561] RotateCoordinates() changes units?
PostPosted: Thu Jan 11, 2018 6:24 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Wed Oct 29, 2003 4:35 pm
Posts: 10405
Location: Beyond the pale...
I think there is a problem even without RotateCoordinates().

In the following the initial red box does not appear to have a stroke width of 1px. Whereas, after issuing ResetCoordinates(), the second box (blue) does seem to have the correct stroke width.

The initial box seems to be rendered with a pen of thickness 1pt as opposed to 1px.

PB 5.62 beta 1 x64, win 7.

Code:
If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 200)
    If StartVectorDrawing(CanvasVectorOutput(0))
      AddPathBox(50, 50, 200, 50)
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      ResetCoordinates()
      AddPathBox(150, 75, 200, 50)
      VectorSourceColor(RGBA(0, 0, 255, 255))
      StrokePath(1)
      StopVectorDrawing()
    EndIf
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf

_________________
I may look like a mule, but I'm not a complete ass.


Top
 Profile  
Reply with quote  
 Post subject: Re: [VectorDrawing-v561] RotateCoordinates() changes units?
PostPosted: Thu Jan 11, 2018 7:16 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2665
Location: Boston, MA
Yes, there is no way to return to #PB_Unit_Pixel, the original units of StartVectorDrawing(CanvasVectorOutput(0, #PB_Unit_Pixel)).
RotateCoordinates() and ResetCoordinates() jump to #PB_Unit_Point.
So, I have to StopVectorDrawing() and StartVectorDrawing() all over again to get #PB_Unit_Pixel.

EDIT: I found another workaround.
Code:
      SaveVectorState()
      RotateCoordinates(PathCursorX(), PathCursorY(), -90)
      DrawVectorText(s$)
      RestoreVectorState()
      ;ResetCoordinates() ;<-- no need now to mess up my units!

_________________
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum


Top
 Profile  
Reply with quote  
 Post subject: Re: [VectorDrawing-v561]Rotate/ResetCoordinates() changes un
PostPosted: Thu Jan 11, 2018 9:06 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1575
Location: Uttoxeter, UK
@skywalk,

I am assuming you are coding on a PC.
On my PC, Windows 10 x64, I get the same thin edged blue box, when I run the code below.
This appears to be a Windows related bug as when the code below is run on my MacBook the blue box has edges the same thickness as the red and green boxes. Unfortunately the text, that should be, in the blue box is 'off the window' on the left! Looks like there is another bug on the Mac.

Code:
EnableExplicit
Procedure.i fntv_SizeFitRect(txt$, hFnt.i, RectWd.d, RectHt.d)
  ; USE:    Loop through VectorFont sizes until exceed Rectangle.
  ;         Must be called from within a StartVectorDrawing() block.
  ; RETURN: Font Size of current VectorFont(), which is left in play.
  ;         i > 0 = no rotation. i < 0 = rotated.
  Protected.i i
  If txt$
    RectWd - 0
    RectHt - 0
    If RectWd > RectHt
      For i = 1 To 100
        VectorFont(hFnt, i)
        If ((VectorTextWidth(txt$) > RectWd) Or (VectorTextHeight(txt$) > RectHt))
          i - 1
          Break
        EndIf
      Next i
    Else
      For i = 1 To 100
        VectorFont(hFnt, i)
        If ((VectorTextWidth(txt$) > RectHt) Or (VectorTextHeight(txt$) > RectWd))
          i = -1 * (i + 2)
          Break
        EndIf
      Next i
    EndIf
  EndIf
  ProcedureReturn i
EndProcedure
Procedure Main()
  Protected.s s$ = "1234"
  Protected.d rWd, rHt, rX, rY
  Protected.d tWd, tHt, tX, tY
  Protected.i evWW, hFnt, txSize
  If OpenWindow(0, 0, 0, 300, 300, "DrawVectorText() in a box?", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 300, 300)
    LoadFont(0, "Segoe UI", 8, #PB_Font_Bold)
    hFnt = FontID(0)
    If StartVectorDrawing(CanvasVectorOutput(0))
      ;/////////////////////////////////////////////////////
      ; Horizontal Rectangle
      ;/////////////////////////////////////////////////////
      rWd = 140
      rHt = 30
      AddPathBox(5, 5, rWd, rHt)     ; 0° Rectangle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(1)
      ;StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rwd, rht)
      tHt = VectorTextHeight(s$)
      tWd = VectorTextWidth(s$)
      MovePathCursor(5+rwd/2-twd/2, 5+rht/2-tht/2)
      DrawVectorText(s$)
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, Text Wd & Ht swapped.
      ;/////////////////////////////////////////////////////
      rWd = 30
      rHt = 140
      AddPathBox(150, 5, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 255, 0, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rWd, rHt)
      If txSize > 0
        twd = VectorTextWidth(s$)
        tht = VectorTextHeight(s$)
      Else
        tht = VectorTextWidth(s$)
        twd = VectorTextHeight(s$)
      EndIf
      MovePathCursor(150+rwd/2-twd/2, 5+rht/2+tht/2)
      RotateCoordinates(PathCursorX(), PathCursorY(), -90)
      DrawVectorText(s$)
      ResetCoordinates()
      ;/////////////////////////////////////////////////////
      ; Rectangle Rotated -90°, But text drawn as topdown paragraph.
      ;/////////////////////////////////////////////////////
      rWd = 30
      rHt = 140
      AddPathBox(5, 40, rWd, rHt)   ; Orig Rectangle rotated -90°
      VectorSourceColor(RGBA(0, 0, 255, 255))
      StrokePath(1)
      txSize = fntv_SizeFitRect(s$, hFnt, rWd, rHt)
      If txSize > 0
        twd = VectorTextWidth(s$)
        tht = VectorTextHeight(s$)
      Else
        ; Try paragraph text
        s$ = "1" + #LF$ + "2" + #LF$ + "3" + #LF$ + "4"
        twd = VectorTextWidth(s$)
        tht = VectorTextHeight(s$)
      EndIf
      MovePathCursor(5+rwd/2-twd/2, 40+rht/2-tht/2)
      DrawVectorParagraph(s$, 30, 140, #PB_VectorParagraph_Center)
      StopVectorDrawing()
    EndIf
    Repeat
      evWW = WaitWindowEvent()
    Until evWW = #PB_Event_CloseWindow
  EndIf
EndProcedure
Main()

_________________
DE AA EB


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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