Page 1 of 1

DrawVectorImage() ignores TranslateCoordinates() et al

Posted: Fri Jul 06, 2018 9:27 am
by Wolfgang2
Dear Forum,

It seems that DrawVectorImage() does not respect TranslateCoordinates() or ScaleCoordinates()
System: Windows7prof, PureBasic 5.62 X64

At below code, anything works as expected, just the image is neither moved nor scaled.

Code: Select all

;VecCoordTest

OpenWindow(0,80,10,2000,1000,"test",#PB_Window_SystemMenu)
CanvasGadget(1,0,0,1990,990,#PB_Canvas_Container)
TextGadget(2,3,3,800,20,"text")
CloseGadgetList()
LoadFont(0, "Arial", 5, #PB_Font_Bold)
Define ImgFile.s = "C:\Program Files\PureBasic\Examples\Sources\Data\PureBasic.bmp"
Global BgImg = LoadImage(#PB_Any,ImgFile)
Global ScaleW.f = 100/ImageWidth(BgImg)
Global ScaleH.f = 100/ImageHeight(BgImg)


Procedure DrawBox(color,txt.s)
  VectorSourceColor(color)
  AddPathBox(-50,-50,100,100)
  MovePathCursor(-50,0)
  AddPathLine(50,0)
  MovePathCursor(0,-50)
  AddPathLine(0,50)
  MovePathCursor(-40,0)
  DrawVectorText("-50,0")
  MovePathCursor(40,0)
  DrawVectorText("50,0")
  MovePathCursor(0,-40)
  DrawVectorText("0,-50")
  MovePathCursor(0,40)
  DrawVectorText("0,50")
  MovePathCursor(40,40)
  DrawVectorText(txt)
  StrokePath(1)
EndProcedure


Procedure Redraw()
If StartVectorDrawing(CanvasVectorOutput(1,#PB_Unit_Millimeter))
  VectorFont(FontID(0),5)
  
  TranslateCoordinates(150,100)     ; viewport
  
  BeginVectorLayer()                ; BG image  
  ScaleCoordinates(1.5,1.5)
  RotateCoordinates(0,0,45)
  DrawBox(RGBA(0,0,255,255),"BG_img")  
  EndVectorLayer()
  
  TranslateCoordinates(50,20)       ; we are now at the frame ref
  
  DrawBox(RGBA(0,0,0,255),"frmeref")
  
  BeginVectorLayer()                ; we are now at patch 1
  TranslateCoordinates(-100,-40)
  DrawBox(RGBA(255,100,0,255),"P1")
  EndVectorLayer()
  
  BeginVectorLayer()
  TranslateCoordinates(10,10)
  RotateCoordinates(10,10,-30)
  DrawBox(RGBA(0,255,100,255),"P2")
  EndVectorLayer()
  
  DrawBox(RGBA(0,0,0,255),"VP")
  
   BeginVectorLayer()                                       ; <- this also makes no difference
   ScaleCoordinates(ScaleW,ScaleH,#PB_Coordinate_Source)             ; <- this does nothing
   TranslateCoordinates(100,100)                                     ; <- this does nothing
   DrawVectorImage(ImageID(BgImg))
   EndVectorLayer()
  
  StopVectorDrawing()
Else
  MessageRequester("E","StartVectorDrawing failed")
EndIf
EndProcedure


Define M_X.i, M_Y.i
Define TM_X.f,TM_Y.f, TP_X.f,TP_Y.f, P2_X,P2_Y

Redraw()
Repeat
  If EventType() = #PB_EventType_MouseMove
    StartVectorDrawing(CanvasVectorOutput(1,#PB_Unit_Millimeter))
    TranslateCoordinates(150,100)                 ; viewport
    TranslateCoordinates(50,20)                   ; frame ref
    M_X = GetGadgetAttribute(1,#PB_Canvas_MouseX)
    M_Y = GetGadgetAttribute(1,#PB_Canvas_MouseY)
    TM_X = ConvertCoordinateX(M_x,M_y,#PB_Coordinate_Device,#PB_Coordinate_User)
    TM_Y = ConvertCoordinateY(M_x,M_y,#PB_Coordinate_Device,#PB_Coordinate_User)
    
    BeginVectorLayer()
    TranslateCoordinates(-100,-40)    
    TP_X = ConvertCoordinateX(M_x,M_y,#PB_Coordinate_Device,#PB_Coordinate_User)
    TP_Y = ConvertCoordinateY(M_x,M_y,#PB_Coordinate_Device,#PB_Coordinate_User)
    EndVectorLayer()
    
    BeginVectorLayer()
    TranslateCoordinates(10,10)
    RotateCoordinates(10,10,-30)
    P2_X = ConvertCoordinateX(M_x,M_y,#PB_Coordinate_Device,#PB_Coordinate_User)
    P2_Y = ConvertCoordinateY(M_x,M_y,#PB_Coordinate_Device,#PB_Coordinate_User)
    EndVectorLayer()
       
    StopVectorDrawing()
    SetGadgetText(2,"Pix_X:"+Str(M_x)+"  Pix_y:"+Str(M_Y)+"    Usr_X:"+StrF(TM_x,1)+"  Usr_Y:"+StrF(TM_Y,1)+"     P1_X:"+StrF(TP_X,1)+"  P1_Y:"+StrF(TP_Y,1) + "    P2_X:"+StrF(P2_X,1)+"  P2_Y:"+StrF(P2_Y,1))
    ;Redraw()
    Debug "mouse move"  
  EndIf
Until WaitWindowEvent() = #PB_Event_CloseWindow


Could anyone please confirm and ideally present an idea how to make it work ?

If you use VectorSourceImage() with FillVectorOutput() translations and scaling do work. BUT this method is very slooow, it takes about 240msec. to put a 29kByte PNG on a canvas that way.



[ UPDATE ]

some more testing showed:
ScaleCoordinates() alone works
TranslateCoordinates() does not work
BUT if you do TranslateCoordinates() followed by a StrokePath() ( no need to actually HAVE a path, funny enough ), the subsequent DrawVectorImage() indeed IS translated.
Without the StrokePath() , the following DrawVectorImage() is NOT translated.

Pretty strange this !



With best regards,
Wolfgang

Re: DrawVectorImage() ignores TranslateCoordinates() et al

Posted: Fri Jul 06, 2018 2:56 pm
by #NULL
Maybe you need to MovePathCursor() to make use of the translation. The folloing seems to work correctly:

Code: Select all

Enumeration
  #imgSrc
  #imgOut
EndEnumeration
CreateImage(#imgSrc, 10, 10, 32, $ff8888ff);red
CreateImage(#imgOut, 600, 600, 32, $ffff8888);blue
StartVectorDrawing(ImageVectorOutput(#imgOut))

DrawVectorImage(ImageID(#imgSrc)) ; (0,0)

MovePathCursor(20,10)
DrawVectorImage(ImageID(#imgSrc)) ; (20,10)

TranslateCoordinates(20, 20)
MovePathCursor(0,0)
DrawVectorImage(ImageID(#imgSrc)) ; (20,20)
MovePathCursor(20,10)
DrawVectorImage(ImageID(#imgSrc)) ; (40,30)

StopVectorDrawing()
ShowLibraryViewer("image", #imgOut)
OpenWindow(0,100,100,100,100,"10")
Repeat : WaitWindowEvent() : Until Event() = #PB_Event_CloseWindow
..but only with MovePathCursor(0,0)

Re: DrawVectorImage() ignores TranslateCoordinates() et al

Posted: Fri Jul 06, 2018 3:04 pm
by #NULL
BTW with you code i see scaling, translation and rotation going on, but i don't know what it's supposed to look like. (Linux here)

Re: DrawVectorImage() ignores TranslateCoordinates() et al

Posted: Fri Jul 06, 2018 6:37 pm
by Oma
Hi Wolfgang2,
did you try a ScaleCoordinates(ScaleW,ScaleH,#PB_Coordinate_User) too?

It should work, see the modified PB example ...

Code: Select all

  If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 200)
    
    LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/PureBasicLogo.bmp")

    If StartVectorDrawing(CanvasVectorOutput(0))
    	;****
    	ScaleCoordinates(0.5, 0.5, #PB_Coordinate_User)
    	;****
      MovePathCursor(50, 50)
      DrawVectorImage(ImageID(0), 127)
      
      MovePathCursor(75, 75)
      DrawVectorImage(ImageID(0), 127, ImageWidth(0) / 2, ImageHeight(0))

      MovePathCursor(120, 0)
      RotateCoordinates(120, 0, 35)
      DrawVectorImage(ImageID(0), 127)
    
      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
Regards, Charly

Re: DrawVectorImage() ignores TranslateCoordinates() et al

Posted: Fri Jul 13, 2018 7:59 am
by Wolfgang2
Hi Oma and #Null,

Thanks for your replies. I am pretty sure I tried different combinations of scalings and coordinates systems.
Anyhow, as I am a result driven guy, I for now leave it as it is. With the dummy StrokePath(), it works.
I am surprised that you can StrokePath() without having a path at all.

Wolfgang2

Re: DrawVectorImage() ignores TranslateCoordinates() et al

Posted: Fri Jul 13, 2018 8:03 am
by Wolfgang2
#NULL wrote:BTW with you code i see scaling, translation and rotation going on, but i don't know what it's supposed to look like. (Linux here)
It is a bunch of squares, rotyated, translated and scaled. I put a screenshot here:

https://share.mailbox.org/ajax/share/05 ... g/NDgvNjIx