Hmm would this style of organization help you? Maybe it's a bit much but if i were wanting to make a work around it maybe something close to this. Note: This was quick coding so i didn't add any memory freeing management.
I am trying to show some of the possible flexibility and alternative methods all in one
.
Code: Select all
DeclareModule world
Interface _
getwidth()
getheight()
EndInterface
Interface Main_Methods
ShowBoxes()
newbox(Name$,x,y,width,height)
EndInterface
Structure box
*interface
x.l
y.l
width.l
height.l
EndStructure
Structure main
*interface
Map *Box._()
EndStructure
Structure NewObject
*Functions.Main_Methods
*Vars.main
EndStructure
Declare create()
EndDeclareModule
Module world
Procedure create()
*new.main = AllocateStructure(main)
*new\interface = ?Main_Methods
*object.NewObject = AllocateStructure(NewObject)
*object\Functions = *new
*object\Vars = *new
ProcedureReturn *object
EndProcedure
Procedure NewBox(*self.main,Name$,x,y,width,height)
With *self
AddMapElement(\Box(),name$)
*this.box = AllocateStructure(box)
*this\x = x
*this\y = y
*this\width = width
*this\height = height
*this\interface = ?Box_Methods
\Box() = *this
EndWith
EndProcedure
Procedure showboxes(*self.main)
Debug "name: x,y,width,height"
ForEach *self\Box()
*this.box = *self\Box()
Debug MapKey(*self\Box()) + ":" + Str(*this\x) + "," + Str(*this\y) + "," + Str(*this\width) + "," + Str(*this\height)
Next
EndProcedure
Procedure GetWidth(*self.box)
ProcedureReturn *self\width
EndProcedure
Procedure getheight(*self.box)
ProcedureReturn *self\height
EndProcedure
DataSection
Main_Methods:
Data.i @showboxes(),@newbox()
Box_Methods:
Data.i @getwidth(),@getheight()
EndDataSection
EndModule
*Galaxy.world::NewObject = world::create()
*Galaxy\Functions\newbox("Small",0,0,10,10)
*Galaxy\Functions\newbox("Medium",0,0,100,100)
*Galaxy\Functions\newbox("Large",0,0,1000,1000)
*Galaxy\Functions\newbox("Random",Random(1000),Random(1000),Random(1000),Random(1000))
*Galaxy\Functions\ShowBoxes()
Debug "Large Width:" + Str(*Galaxy\Vars\Box("Large")\getwidth())
Debug ""
Debug "Lets get all the heights"
ForEach *Galaxy\Vars\Box()
Debug MapKey(*Galaxy\Vars\Box()) + "::" + "Height = " + Str(*Galaxy\Vars\Box()\getheight())
Next