I try to select some elements on a vector canvas, but I don't understand why I can't select the red circle :
Code: Select all
Structure sShape
name$
selected.a
color.i
x.w
y.w
w.w
h.w
alpha.a
EndStructure
Global Dim shape.sshape(0), NbShape =-1
Procedure Shape_Add(x,y,w,h,color.i)
NbShape +1
i = nbShape
ReDim shape.sShape(i)
With shape(i)
\name$ = "Shape"+Str(i)
\alpha = 255
\color=color
\x=x
\y=y
\w=w
\h=h
EndWith
EndProcedure
#G_canvasVector = 0
Procedure CanvasDraw(update = 0)
HoveredElement = #Null
Static Clic, shift
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
If EventType() = #PB_EventType_KeyDown
If GetGadgetAttribute(#G_canvasVector, #PB_Canvas_Modifiers) & #PB_Canvas_Shift
Shift = 1
EndIf
ElseIf EventType() = #PB_EventType_KeyUp
If Not GetGadgetAttribute(#G_canvasVector, #PB_Canvas_Modifiers) & #PB_Canvas_Shift
Shift = 0
EndIf
EndIf
If EventType() = #PB_EventType_LeftButtonDown
Clic = 1
ElseIf EventType() = #PB_EventType_LeftButtonUp
clic = 0
EndIf
If EventType() = #PB_EventType_LeftButtonDown Or EventType() = #PB_EventType_LeftButtonUp Or update= 1
If StartVectorDrawing(CanvasVectorOutput(0))
SelectedShape = -1
; for selection
For i=ArraySize(shape()) To 0 Step-1
With shape(i)
AddPathEllipse(\x, \y, \w, \h)
If clic=1
clic=0
If IsInsidePath(x, y)
\selected= 1
SelectedShape = i
Break
Else
If shift = 0
\selected= 0
EndIf
EndIf
EndIf
EndWith
Next
If EventType() = #PB_EventType_LeftButtonDown Or update=1
; TO erase the Background
AddPathBox(0,0,GadgetWidth(0),GadgetHeight(0))
VectorSourceColor(RGBA(200,200,200, 255))
FillVectorOutput()
AddPathBox(0,0,GadgetWidth(0),GadgetHeight(0))
VectorSourceColor(RGBA(200,200,200, 255))
FillPath()
For i=0 To ArraySize(shape())
With shape(i)
AddPathEllipse(\x, \y, \w, \h)
; If SelectedShape = i
; Debug \name$
; EndIf
If \selected
\alpha = 120
Debug \name$
Else
\alpha = 255
EndIf
VectorSourceColor(RGBA(Red(\color),Green(\color),Blue(\color),\alpha))
FillPath()
EndWith
Next
EndIf
StopVectorDrawing()
EndIf
EndIf
EndProcedure
w = 800
h = 600
If OpenWindow(0, 0, 0, w, h, "IsInsidePath", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, w, h, #PB_Canvas_Keyboard)
Shape_Add(200,200,400,300,RGBA(120,0,0,255))
Shape_Add(200,200,200,100,RGBA(0,0,120,255))
CanvasDraw(1)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0 ;And EventType() = #PB_EventType_MouseMove
CanvasDraw()
EndIf
Until Event = #PB_Event_CloseWindow
EndIf