Pure procédural
Code : Tout sélectionner
Prototype p_draw(*s)
Structure _Shape
x.i ; position X
y.i ; position Y
color.i
draw.p_draw
EndStructure
Structure _Box Extends _Shape
w.i ; width
h.i ; height
EndStructure
Structure _Circle Extends _Shape
r.i ; radius
EndStructure
Structure Sheet
Map *myShapes._Shape()
EndStructure
Global mySheet.Sheet
Procedure draw_Box(*s._Box)
With *s
AddPathBox(\x,\y,\w,\h)
VectorSourceColor(\color)
FillPath()
EndWith
EndProcedure
Procedure draw_Circle(*s._Circle)
With *s
AddPathCircle(\x,\y,\r)
VectorSourceColor(\color)
FillPath()
EndWith
EndProcedure
Procedure addBox(id,x,y,w,h,color)
Protected *this._Box = AllocateStructure(_Box)
With *this
\w = w
\h = h
\x = x
\y = y
\color = color
\draw = @draw_Box()
EndWith
AddMapElement(mySheet\myShapes(),Str(id))
mySheet\myShapes() = *this
EndProcedure
Procedure addCircle(id,x,y,r,color)
Protected *this._Circle = AllocateStructure(_Circle)
With *this
\x = x
\y = y
\r = r
\color = color
\draw = @draw_Circle()
EndWith
AddMapElement(mySheet\myShapes(),Str(id))
mySheet\myShapes() = *this
EndProcedure
Procedure shapeGetX(id)
If FindMapElement(mySheet\myShapes(),Str(id))
ProcedureReturn mySheet\myShapes()\x
EndIf
EndProcedure
Procedure draw()
With mySheet
StartVectorDrawing(CanvasVectorOutput(0))
ForEach \myShapes()
\myShapes()\draw(\myShapes())
Next
StopVectorDrawing()
EndWith
EndProcedure
Procedure evExit()
End
EndProcedure
Procedure OpenMainForm()
OpenWindow(0,0,0,800,600,"Way 1",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CanvasGadget(0,0,0,800,600)
addBox(0,10,10,200,100,$FFBF473F)
addBox(1,400,10,50,60,$FFBF47C9)
addCircle(2,100,400,20,$FF2147C9)
addCircle(3,200,400,20,$FF2193C9)
draw()
BindEvent(#PB_Event_CloseWindow,@evExit(),0)
EndProcedure
OpenMainForm()
Debug shapeGetX(3)
Repeat
WaitWindowEvent()
ForEver