Code: Select all
; Define Objects
#MaxObjects=10
#MaxElements=40
#MaxParameter=6
#Offset=250
#Screen=220
Enumeration
#Null
#Set
#Line
#Poly
EndEnumeration
DataSection
Data.w #Set,370,200
Data.w #Poly
Data.w 370,130,371,130, 280,130,280,160
Data.w 0
Data.w #Null
; End
Data.w #Null
EndDataSection
Structure etype
type.w
val.w[#MaxParameter]
EndStructure
Structure otype
elements.w
e.etype[#MaxElements]
EndStructure
Global object
Global Dim o.otype(#MaxObjects)
Enumeration
#Canvas
#Log
EndEnumeration
; EndDefine
Procedure ObjectInit()
Protected element
Protected type
Protected n,z,value
Protected x,y
Repeat
element=0
Repeat
Read.w type
; Debug Chr(type)
If type
With o(object)\e[element]
Select type
Case #Set,#Line
z=2
Case #Poly
Repeat
Read.w value
If value
\type=#Line
\val[0]=value-#Offset
Read.w value
\val[1]=value-#Offset
x=\val[0]
y=o(object)\e[element]\val[1]
element+1
EndIf
Until value=#Null
z=0
Default
Debug "Error at object "+object+" / element "+element
End
EndSelect
If z
\type=type
For n=0 To z-1
Read.w \val[n]
If n<2; x/y
\val[n]-#Offset
ElseIf n=4; endwinkel, rotation
\val[5]=1-Bool(\val[4]>999)<<1
\val[4]=\val[4]%1000
EndIf
Next n
Select type
Case #Set
x=\val[0]
y=o(object)\e[element]\val[1]
Case #Line
x=\val[0]
y=o(object)\e[element]\val[1]
EndSelect
element+1
EndIf
o(object)\elements=element
EndWith
EndIf
Until type=#Null
object+1
Until element=0
object-1
Protected i,j,k
Protected s.s
For i=0 To object-1
For j=0 To o(i)\elements-1
s=Chr(o(i)\e[j]\type)+": "
For k=0 To 1
s+" "+Str(o(i)\e[j]\val[k])
Next k
Next j
Next i
EndProcedure
Procedure ObjectDraw(nr,x=#Offset,y=#Offset,len.f=100,zoom.f=1,rotation=0)
Protected i,j,k
Protected l,m,n
Protected x_,y_,z
n=0
m=0
RotateCoordinates(#Screen,#Screen,rotation)
For i=0 To o(nr)\elements-1
With o(nr)\e[i]
Select \type
Case #Set
MovePathCursor(\val[0]*zoom+x,\val[1]*zoom+y)
;AddPathText("S"+Str(i))
Case #Line
AddPathLine(\val[0]*zoom+x,\val[1]*zoom+y)
; If rotation
; MovePathCursor(\val[0]*zoom+x,\val[1]*zoom+y); Workaround
; EndIf
;AddPathText("L"+Str(i))
Debug "Line "+Str(\val[0]*zoom+x)+" / "+Str(\val[1]*zoom+y)
EndSelect
EndWith
Next i
ResetCoordinates()
EndProcedure
#WinX=960
#WinY=440
LoadFont(0,"",10)
OpenWindow(0,0,0,#WinX,#WinY,"Symbols",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CanvasGadget(#Canvas,0,0,#WinX,#WinY)
ObjectInit()
width=5
StartVectorDrawing(CanvasVectorOutput(0))
VectorSourceColor($FFFFFFFF)
FillVectorOutput()
VectorFont(FontID(0),10)
For i=1 To 10
ObjectDraw(0,#Screen,#Screen,100,1,i*30)
VectorSourceColor($ff0000A0)
StrokePath(width)
Debug "-"
Next i
StopVectorDrawing()
Repeat : Select WaitWindowEvent() : Case #PB_Event_CloseWindow,#WM_CHAR : End : EndSelect : ForEver