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