• News
  • OldBlog

Understanding Parents

All objects in Mana belong to a system reminiscent of a family tree, or if you prefer, a system of folders (directories) and files. The root object is always a module and can be used in combination with other modules in a variety of applications. Also, modules can be distributed on their own so that they may be shared and used in numerous projects.

Objects that are in directories or that are directly linked to other objects can be found using a path name.

//Prototypes/Widget:Window

The above statement refers to the Window prototype object in the Prototypes/Widget directory. The two slashes at the beginning indicate that it is found in the main tree. The colon represents the end of the directory path and the start of the object path, but the parser is forgiving and will accept a slash. The following is also valid.

//Prototypes/Widget/Window

Widgets are often made up of sub-widgets. Objects that are children of other objects can also be accessed using path names.

 MANA.Find( “//Prototypes/Widget:ScrollPanel/ScrollArea” )

The code above returns the scroll area of the prototype scroll panel. Mana uses a prototype/clone system for creating and extending objects. Prototypes are objects with which the end user does not directly interact, but are strictly used to define other objects. When a prototype is cloned, its properties (fields and methods) and all of its children are cloned and become part of the new object.

Here is that window definition from my last post, with some additions.

MANA.Start()
 MANA.Clone( “//Prototypes/Widget/Window”, “MyWindow”, -1, “//MyGui” )
 MANA.THIS:SetPosition( 50, 50 )
 MANA.THIS:SetSize( 300, 200 )
 MANA.Clone( “//Prototypes/Widget/Button”, “OkButton”, -1, “..MyWindow/WindowPanel” )
 MANA.THIS:SetAlignment( -1, 2, -2, -1, 1, -2 )
 MANA.THIS:SetSize( 80, 30 )
MANA.Finish()

The second line (after Start) creates a clone of the window prototype, names it “MyWindow”, and attaches it to the end of the list of child objects for another object in the tree called “MyGui.” Any object created using Init, Clone, or ReadXml between the Start and Finish statements is available on an initialization stack. It can be accessed immediately using the THIS field of the MANA table or using Find with two dots in front of its name.

 MANA.THIS:SetPosition( 50, 50 )

The code above sets the position of the last created object (MyWindow) to 50, 50.

 MANA.Clone( “//Prototypes/Widget/Button”, “OkButton”, -1, “..MyWindow/WindowPanel” )

This line creates a clone of the button prototype, names it “OkButton”, and attaches it to “MyWindow.” The two dots refer to an object previously created on the stack.

NOTE: The WindowPanel sub-object is referenced because windows are made of other components and attaching directly to the window would overdraw them. Your button may draw on top of the frame or title bar and that simply won’t do!

Here is an alternative.

 MANA.Clone( “//Prototypes/Widget/Button”,
 “OkButton”, -1, “>>MyWindow” )

In this variant, the two dots are replaced with two right angle brackets and WindowPanel is omitted. Some objects have an attachment facility, or a set of instructions that regulate how other objects get attached. In this case, the window is being instructed to process the button and attach it to the correct location automatically.

Comments are closed.