Cette bibliothèque utilisant GDI, il est possible de dessiner directement sur la fenêtre et d'ajouter une interaction au survol des objets dessinés.
Cette petite démo affiche un cercle, un rectangle et un polygone horrible. Survolé chacun de ces objet avec la souris.
Code : Tout sélectionner
Enumeration window
#mainform
EndEnumeration
Enumeration gadget
#result
EndEnumeration
Enumeration font
#fontvector
#fontapp
EndEnumeration
Declare draw()
;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)
TextGadget(#PB_Any, 20, 100, 200, 20, "Forme selectionnée")
StringGadget(#result, 220, 100, 200, 22, "")
If StartVectorDrawing(WindowVectorOutput(0))
;Titre
MovePathCursor(20, 10)
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
Repeat
Event = WaitWindowEvent()
If EventType() = -1
Draw()
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Procedure Draw()
x = WindowMouseX(0)
y = WindowMouseY(0)
SetGadgetText(#Result, "")
If StartVectorDrawing(WindowVectorOutput(0))
;Cercle
AddPathCircle(50, 220, 30) ;Ajout cercle
If IsInsidePath(x, y, #PB_Coordinate_Device)
;Curseur dans le cercle
SetGadgetText(#Result, "Cercle bleu")
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, 200, 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, 180)
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
