UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_behaviour.cpp File Reference

Go to the source code of this file.

Macros

#define LOCAL_PROPERTY_SIZE   128
 

Functions

const struct value_sUI_RegisterNodePropertyPosSize_ (uiBehaviour_t *behaviour, const char *name, int type, size_t pos, size_t size)
 Register a property to a behaviour. It should not be used in the code. More...
 
const struct value_sUI_RegisterNodeMethod (uiBehaviour_t *behaviour, const char *name, uiNodeMethod_t function)
 Register a node method to a behaviour. More...
 
const value_tUI_GetPropertyFromBehaviour (const uiBehaviour_t *behaviour, const char *name)
 Get a property from a behaviour or his inheritance It use a dichotomic search. More...
 
const value_tUI_GetPropertyOrLuaMethod (const uiNode_t *node, const char *name, value_t *out)
 Get a property or lua based method from a node, node behaviour or inherted behaviour. More...
 
void UI_InitializeNodeBehaviour (uiBehaviour_t *behaviour)
 Initialize a node behaviour memory, after registration, and before using it. More...
 
void UI_AddBehaviourMethod (uiBehaviour_t *behaviour, const char *name, LUA_METHOD fcn)
 Adds a lua based method to the list of available behaviour methods for calling. More...
 
bool UI_GetBehaviourMethod (const uiBehaviour_t *behaviour, const char *name, LUA_METHOD &fcn)
 Finds the lua based method on this behaviour or its super. More...
 
bool UI_HasBehaviourMethod (uiBehaviour_t *behaviour, const char *name)
 Returns true if a node method of given name is available on this behaviour or its super. More...
 

Macro Definition Documentation

#define LOCAL_PROPERTY_SIZE   128

Size of the temporary property-list allocation (per behaviour)

Definition at line 38 of file ui_behaviour.cpp.

Referenced by UI_RegisterNodePropertyPosSize_().

Function Documentation

void UI_AddBehaviourMethod ( uiBehaviour_t behaviour,
const char *  name,
LUA_METHOD  fcn 
)

Adds a lua based method to the list of available behaviour methods for calling.

Parameters
[in]behaviourThe behaviour to extend.
[in]nameThe name of the new method to add
[in]fcnThe lua based function reference.
Note
If the method name is already defined, the new method is not added and a warning will be issued in the log.

Definition at line 251 of file ui_behaviour.cpp.

References Com_Printf(), HASH_Insert(), HASH_NewTable(), uiBehaviour_t::name, and uiBehaviour_t::nodeMethods.

Referenced by uiNode_t_add_classmethod().

bool UI_GetBehaviourMethod ( const uiBehaviour_t behaviour,
const char *  name,
LUA_METHOD fcn 
)

Finds the lua based method on this behaviour or its super.

Parameters
[in]behaviourThe node behaviour to examine.
[in]nameThe name of the method to find
[out]fcnA reference to a LUA_METHOD value to the corresponding lua based function or to LUA_NOREF if the method is not found
Returns
True if the method is found, false otherwise.

Definition at line 272 of file ui_behaviour.cpp.

References HASH_Get(), uiBehaviour_t::nodeMethods, and uiBehaviour_t::super.

Referenced by UI_GetNodeMethod(), UI_HasBehaviourMethod(), and UI_HasNodeMethod().

const value_t* UI_GetPropertyFromBehaviour ( const uiBehaviour_t behaviour,
const char *  name 
)

Get a property from a behaviour or his inheritance It use a dichotomic search.

Return a property from a node behaviour.

Parameters
[in]behaviourContext behaviour
[in]nameProperty name we search
Returns
A value_t with the requested name, else nullptr

Definition at line 100 of file ui_behaviour.cpp.

References uiBehaviour_t::localProperties, uiBehaviour_t::propertyCount, Q_strcasecmp, value_s::string, and uiBehaviour_t::super.

Referenced by uiFuncNode::onLoaded(), uiPanelNode::onPropertyChanged(), uiConFuncNode::onWindowClosed(), uiConFuncNode::onWindowOpened(), UI_GenInjectedString(), UI_GetPropertyOrLuaMethod(), UI_InitializeNodeBehaviour(), UI_ParseNodeBody(), UI_ParseNodeProperties(), and UI_Window_SetCloseButton().

const value_t* UI_GetPropertyOrLuaMethod ( const uiNode_t node,
const char *  name,
value_t out 
)

Get a property or lua based method from a node, node behaviour or inherted behaviour.

Return a property or lua based method from a node, node behaviour or inherited behaviour.

Parameters
[in]nodeThe node holding the method
[in]nameProperty name we search
[out]outA reference to a value_t structure wich is filled if a lua based method is available. Set to nullptr to onlys scan for properties and not for lua based methods.
Returns
A value_t with the requested name, else nullptr
Note
This function first searches the local properties of the behaviour before looking into lua based functions.
If a lua function is found, .type is set to V_UI_NODEMETHOD_LUA, .string is set to the method name and .ofs is set to the lua callback id of the function.
After use, be sure to free the allocated .string value!!!

Definition at line 136 of file ui_behaviour.cpp.

References uiNode_t::behaviour, Mem_StrDup, value_s::ofs, value_s::size, value_s::string, value_s::type, UI_GetNodeMethod(), UI_GetPropertyFromBehaviour(), and V_UI_NODEMETHOD_LUA.

Referenced by UI_ReadNodePath().

bool UI_HasBehaviourMethod ( uiBehaviour_t behaviour,
const char *  name 
)

Returns true if a node method of given name is available on this behaviour or its super.

Parameters
[in]behaviourThe node behaviour to examine.
[in]nameThe name of the method to find
Returns
True if the method is found, false otherwise.

Definition at line 292 of file ui_behaviour.cpp.

References UI_GetBehaviourMethod().

void UI_InitializeNodeBehaviour ( uiBehaviour_t behaviour)

Initialize a node behaviour memory, after registration, and before using it.

Parameters
behaviourBehaviour to initialize
Note
This method sets the SWIG type for this behaviour for the runtime conversion of uiNode_t* values to the correct subclass.
Todo:
Find a way to remove that, if possible

<

Todo:
not possible at the moment, not sure its the right way

<

Todo:
not possible at the moment, not sure its the right way

Definition at line 160 of file ui_behaviour.cpp.

References Com_Error(), ERR_FATAL, uiBehaviour_t::extends, uiBehaviour_t::extraDataSize, i, uiBehaviour_t::isInitialized, uiBehaviour_t::localProperties, uiBehaviour_t::manager, Mem_Free, uiBehaviour_t::name, uiBehaviour_t::propertyCount, Q_strcasecmp, Q_streq, Q_strvalid, value_s::string, STRUCT_MEMORY_ALIGN, uiBehaviour_t::super, UI_AllocHunkMemory(), UI_GetNodeBehaviour(), UI_GetPropertyFromBehaviour(), UI_InitializeNodeBehaviour(), and V_UI_NODEMETHOD.

Referenced by UI_InitializeNodeBehaviour(), and UI_InitNodes().

const struct value_s* UI_RegisterNodeMethod ( uiBehaviour_t behaviour,
const char *  name,
uiNodeMethod_t  function 
)

Register a node method to a behaviour.

Parameters
behaviourTarget behaviour
nameName of the property
functionfunction to execute the node method
Returns
A link to the node property

Definition at line 88 of file ui_behaviour.cpp.

References UI_RegisterNodePropertyPosSize_(), and V_UI_NODEMETHOD.

Referenced by UI_RegisterAbstractNode(), UI_RegisterAbstractScrollableNode(), UI_RegisterCheckBoxNode(), UI_RegisterCvarFuncNode(), UI_RegisterEditorNode(), UI_RegisterGeoscapeNode(), UI_RegisterOptionTreeNode(), and UI_RegisterTextEntryNode().

const struct value_s* UI_RegisterNodePropertyPosSize_ ( uiBehaviour_t behaviour,
const char *  name,
int  type,
size_t  pos,
size_t  size 
)

Register a property to a behaviour. It should not be used in the code.

Parameters
behaviourTarget behaviour
nameName of the property
typeType of the property
posposition of the attribute (which store property memory) into the node structure
sizesize of the attribute (which store property memory) into the node structure
See also
UI_RegisterNodeProperty
UI_RegisterExtradataNodeProperty
Returns
A link to the node property

Definition at line 53 of file ui_behaviour.cpp.

References Com_Error(), ERR_FATAL, LOCAL_PROPERTY_SIZE, uiBehaviour_t::localProperties, Mem_PoolAllocTypeN, uiBehaviour_t::name, name, uiBehaviour_t::propertyCount, STRUCT_MEMORY_ALIGN, UI_AllocHunkMemory(), ui_sysPool, V_CVAR_OR_LONGSTRING, V_CVAR_OR_STRING, V_LONGSTRING, and V_STRING.

Referenced by UI_RegisterNodeMethod().