Feel free to move it back to coding questions, or delete it and anwer in the original post, no problem.
Code: Select all
#TEST_ME = 0
; IsInsideStroke seems to always return 1, even if the point to check is far away from the path.
; Looks like IsInlineStroke() has problems working with numbers smaller than 1?
;#TEST_ME = 1
; Due to the manual the device coordinates (#PB_Coordinate_Device) should be fixed/unchangable
; no matter how much you extend/shrink the user coordinates via ScaleCoordinates/Translatecoordinates
; Why is the IsInsideStroke then not working with the mouse coordinates?
;#TEST_ME = 2
; Adding a simple ResetCoordinates() will make the Cursor selection work again
; Why is it like this, shouldn't the device coordinates be indepenant of any squeezing/extracting of the user coordinates and always work with the mouse coordinates??
Procedure draw()
Protected x, y
Static Once
If StartVectorDrawing(CanvasVectorOutput(0))
VectorSourceColor($FFFFFFFF)
FillVectorOutput()
ResetCoordinates()
ScaleCoordinates(10, 100000)
TranslateCoordinates(0.1, 0.0013)
AddPathSegments("M 10 0.0001 L 20 0.003 L 30 0.0001 L 40 0.003")
CompilerIf #TEST_ME = 0
Debug "Testing (in User Coordinate system) if point 20 / 0.003 is on path (should be, see AddPathSegments)"
Debug IsInsideStroke(20, 0.003, 0.01, #PB_Path_Default, #PB_Coordinate_User)
Debug "Now testing (in User Coordinate system) if point 20 / 0.1 is on path (for sure not, I even used a ridiculous small width to test!)"
Debug IsInsideStroke(20, 0.100, 0.000001, #PB_Path_Default, #PB_Coordinate_User)
Debug "???"
VectorSourceColor(RGBA(255, 0, 0, 255))
CompilerElse
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
If Once = 0
Once = 1
Debug "Move cursor and when you are above the path, the color should switch to blue"
EndIf
CompilerIf #TEST_ME = 2
ResetCoordinates()
CompilerEndIf
If IsInsideStroke(x, y, 8, #PB_Path_Default, #PB_Coordinate_Device)
VectorSourceColor(RGBA(0, 0, 255, 255))
Else
VectorSourceColor(RGBA(255, 0, 0, 255))
EndIf
CompilerEndIf
StrokePath(0.01)
StopVectorDrawing()
EndIf
EndProcedure
If OpenWindow(0, 0, 0, 1000, 500, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 1000, 500)
draw()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
CompilerIf #TEST_ME > 0
If EventGadget() = 0 And EventType() = #PB_EventType_MouseMove
draw()
EndIf
CompilerEndIf
EndSelect
ForEver
EndIf