La solution est de passer par la lib vector. Un exemple avec ce code. Passe le souris sur le cercle le rectangle et le polygone.
Code : Tout sélectionner
Enumeration window
#mainform
EndEnumeration
Enumeration gadget
#title
#result
#shape
EndEnumeration
Enumeration font
#fontvector
#fontapp
EndEnumeration
Declare DrawTitle()
Declare DrawShape()
;Initialisation des fonts
LoadFont(#fontvector, "Impact", 10)
LoadFont(#fontapp, "Verdana", 11)
SetGadgetFont(#PB_Default, FontID(#fontapp))
If OpenWindow(#mainform, 0, 0, 600, 400, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(#mainform, RGB(255, 255, 255))
Gadget = TextGadget(#PB_Any, 20, 100, 200, 20, "Forme selectionnée")
SetGadgetColor(Gadget, #PB_Gadget_BackColor, RGB(255, 255, 255))
StringGadget(#result, 220, 100, 200, 22, "")
CanvasGadget(#title, 20, 10, 400, 80)
DrawTitle()
CanvasGadget(#shape, 0, 150, 600, 120)
DrawShape()
BindGadgetEvent(#shape, @DrawShape(), #PB_EventType_MouseMove)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Procedure DrawTitle()
If StartVectorDrawing(CanvasVectorOutput(#Title))
VectorFont(FontID(#fontvector), 60)
AddPathText("Mon application")
;Remplissage du texte & contour
VectorSourceColor(RGBA(255, 215, 0, 255))
FillPath(#PB_Path_Preserve)
VectorSourceColor(RGBA(0, 0, 0, 255))
StrokePath(1)
StopVectorDrawing()
EndIf
EndProcedure
Procedure DrawShape()
x = GetGadgetAttribute(#Shape, #PB_Canvas_MouseX)
y = GetGadgetAttribute(#Shape, #PB_Canvas_MouseY)
SetGadgetText(#Result, "")
If StartVectorDrawing(CanvasVectorOutput(#Shape))
;Cercle
AddPathCircle(50, 50, 30) ;Ajout cercle
If IsInsidePath(x, y, #PB_Coordinate_Device)
;Curseur dans le cercle
SetGadgetText(#result, "Cercle vert")
VectorSourceColor(RGBA(0, 255, 0, 255))
Else
;Curseur en dehors du cercle
VectorSourceColor(RGBA(0, 0, 255, 255))
EndIf
FillPath() ;Remplissage avec la couleur couante
;Box
VectorSourceColor(RGBA(255, 0, 0, 255))
AddPathBox(200, 30, 100, 50)
If IsInsidePath(x, y, #PB_Coordinate_Device)
SetGadgetText(#result, "Rectangle rouge")
VectorSourceColor(RGBA(255, 0, 0, 255))
Else
VectorSourceColor(RGBA(0, 0, 255, 255))
EndIf
FillPath()
;Polygone
VectorSourceColor(RGBA(0, 0, 255, 255))
MovePathCursor(450, 20)
AddPathLine(50, 10, #PB_Path_Relative)
AddPathLine(10, 20, #PB_Path_Relative)
AddPathLine(0, 30, #PB_Path_Relative)
AddPathLine(-50, 30, #PB_Path_Relative)
AddPathLine(-50, -30, #PB_Path_Relative)
AddPathLine(-10, -20, #PB_Path_Relative)
AddPathLine(50, -40, #PB_Path_Relative)
If IsInsidePath(x, y, #PB_Coordinate_Device)
SetGadgetText(#result, "Polygone jaune")
VectorSourceColor(RGBA(255, 215, 0, 255))
Else
VectorSourceColor(RGBA(0, 0, 255, 255))
EndIf
FillPath()
StopVectorDrawing()
EndIf
EndProcedure