UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_nodes.cpp File Reference
#include "../../common/hashtable.h"
#include "../../common/scripts_lua.h"
#include "ui_main.h"
#include "ui_internal.h"
#include "ui_behaviour.h"
#include "ui_node.h"
#include "ui_nodes.h"
#include "ui_parse.h"
#include "ui_input.h"
#include "node/ui_node_abstractnode.h"
#include "node/ui_node_abstractscrollbar.h"
#include "node/ui_node_abstractoption.h"
#include "node/ui_node_abstractvalue.h"
#include "node/ui_node_bar.h"
#include "node/ui_node_base.h"
#include "node/ui_node_baseinventory.h"
#include "node/ui_node_battlescape.h"
#include "node/ui_node_button.h"
#include "node/ui_node_checkbox.h"
#include "node/ui_node_controls.h"
#include "node/ui_node_container.h"
#include "node/ui_node_data.h"
#include "node/ui_node_editor.h"
#include "node/ui_node_geoscape.h"
#include "node/ui_node_image.h"
#include "node/ui_node_item.h"
#include "node/ui_node_linechart.h"
#include "node/ui_node_material_editor.h"
#include "node/ui_node_messagelist.h"
#include "node/ui_node_model.h"
#include "node/ui_node_option.h"
#include "node/ui_node_optionlist.h"
#include "node/ui_node_optiontree.h"
#include "node/ui_node_panel.h"
#include "node/ui_node_radar.h"
#include "node/ui_node_radiobutton.h"
#include "node/ui_node_rows.h"
#include "node/ui_node_selectbox.h"
#include "node/ui_node_sequence.h"
#include "node/ui_node_string.h"
#include "node/ui_node_special.h"
#include "node/ui_node_spinner.h"
#include "node/ui_node_tab.h"
#include "node/ui_node_tbar.h"
#include "node/ui_node_text.h"
#include "node/ui_node_text2.h"
#include "node/ui_node_textlist.h"
#include "node/ui_node_textentry.h"
#include "node/ui_node_texture.h"
#include "node/ui_node_timer.h"
#include "node/ui_node_video.h"
#include "node/ui_node_vscrollbar.h"
#include "node/ui_node_zone.h"
#include "ui_lua.h"

Go to the source code of this file.

Macros

#define NUMBER_OF_BEHAVIOURS   lengthof(registerFunctions)
 

Typedefs

typedef void(* registerFunction_t )(uiBehaviour_t *node)
 

Functions

bool UI_CheckVisibility (uiNode_t *node)
 Check the if conditions for a given node. More...
 
const char * UI_GetPath (const uiNode_t *node)
 Return a path from a window to a node. More...
 
void UI_ReadNodePath (const char *path, const uiNode_t *relativeNode, const uiNode_t *iterationNode, uiNode_t **resultNode, const value_t **resultProperty, value_t *luaMethod)
 Read a path and return every we can use (node and property) More...
 
uiNode_tUI_GetNodeByPath (const char *path)
 Return a node by a path name (names with dot separation) It is a simplification facade over UI_ReadNodePath. More...
 
static uiNode_tUI_AllocNodeWithoutNew (const char *name, const char *type, bool isDynamic)
 Allocate a node into the UI memory (do not call behaviour->new) More...
 
uiNode_tUI_AllocNode (const char *name, const char *type, bool isDynamic)
 Allocate a node into the UI memory. More...
 
uiNode_tUI_CloneNode (const uiNode_t *node, uiNode_t *newWindow, bool recursive, const char *newName, bool isDynamic)
 Clone a node. More...
 
static uiNode_tUI_GetNodeInTreeAtPosition (uiNode_t *node, int rx, int ry)
 Return the first visible node at a position. More...
 
uiNode_tUI_GetNodeAtPosition (int x, int y)
 Return the first visible node at a position. More...
 
uiBehaviour_tUI_GetNodeBehaviour (const char *name)
 Return a node behaviour by name. More...
 
uiBehaviour_tUI_GetNodeBehaviourByIndex (int index)
 
int UI_GetNodeBehaviourCount (void)
 
void UI_DeleteAllChild (uiNode_t *node)
 Remove all child from a node (only remove dynamic memory allocation nodes) More...
 
static void UI_BeforeDeletingNode (const uiNode_t *node)
 
void UI_DeleteNode (uiNode_t *node)
 
void UI_InitNodes (void)
 

Variables

static const registerFunction_t registerFunctions []
 List of functions to register nodes. More...
 
static uiBehaviour_t nodeBehaviourList [NUMBER_OF_BEHAVIOURS]
 List of all node behaviours, indexes by nodetype num. More...
 

Macro Definition Documentation

#define NUMBER_OF_BEHAVIOURS   lengthof(registerFunctions)

Definition at line 140 of file ui_nodes.cpp.

Referenced by UI_GetNodeBehaviour(), UI_GetNodeBehaviourCount(), and UI_InitNodes().

Typedef Documentation

typedef void(* registerFunction_t)(uiBehaviour_t *node)

Definition at line 83 of file ui_nodes.cpp.

Function Documentation

uiNode_t* UI_AllocNode ( const char *  name,
const char *  type,
bool  isDynamic 
)

Allocate a node into the UI memory.

Note
It's not a dynamic memory allocation. Please only use it at the loading time
Todo:
Assert out when we are not in parsing/loading stage
Parameters
[in]nameName of the new node, else nullptr if we don't want to edit it.
[in]typeName of the node behavior
[in]isDynamicAllocate a node in static or dynamic memory
This method can be merged with UI_AllocNodeWithoutNew. Since all nodes are dynamic, there is no real reason to distinguish between types of allocation.

Definition at line 381 of file ui_nodes.cpp.

References uiNode_t::dynamic, UI_AllocNodeWithoutNew(), UI_Node_InitNode(), UI_Node_InitNodeDynamic(), and UI_Node_Loading().

Referenced by uiConFuncNode::onLoaded(), UI_AbstractNodeCallCreateChild(), UI_AllocOptionNode(), UI_CreateComponent(), UI_CreateControl(), UI_CreateWindow(), UI_ParseComponent(), UI_ParseNode(), UI_ParseWindow(), UI_Window_SetCloseButton(), and UI_Window_SetDragButton().

static uiNode_t* UI_AllocNodeWithoutNew ( const char *  name,
const char *  type,
bool  isDynamic 
)
static

Allocate a node into the UI memory (do not call behaviour->new)

Note
It's not a dynamic memory allocation. Please only use it at the loading time
Todo:
Assert out when we are not in parsing/loading stage
Parameters
[in]nameName of the new node, else nullptr if we don't want to edit it.
[in]typeName of the node behavior
[in]isDynamicAllocate a node in static or dynamic memory

Definition at line 332 of file ui_nodes.cpp.

References uiNode_t::behaviour, Com_Error(), Com_Printf(), uiNode_t::dynamic, ERR_FATAL, uiBehaviour_t::extraDataSize, Mem_PoolAlloc, uiNode_t::name, uiGlobal_s::numNodes, Q_strncpyz(), STRUCT_MEMORY_ALIGN, UI_AllocHunkMemory(), ui_dynPool, UI_GetNodeBehaviour(), ui_global, and UI_Node_IsAbstract().

Referenced by UI_AllocNode(), and UI_CloneNode().

static void UI_BeforeDeletingNode ( const uiNode_t node)
static

Definition at line 607 of file ui_nodes.cpp.

References UI_GetHoveredNode(), and UI_InvalidateMouse().

Referenced by UI_DeleteNode().

bool UI_CheckVisibility ( uiNode_t node)

Check the if conditions for a given node.

See also
V_UI_IF
Returns
false if the node is not drawn due to not meet if conditions

Definition at line 152 of file ui_nodes.cpp.

References uiNode_t::lua_onVisibleWhen, uiCallContext_s::source, UI_ExecuteLuaEventScript_ReturnBool(), UI_GetBooleanFromExpression(), uiCallContext_s::useCmdParam, and uiNode_t::visibilityCondition.

Referenced by UI_CheckMouseMove(), UI_DrawModelNode(), UI_DrawNode(), and UI_GetNodeInTreeAtPosition().

uiNode_t* UI_CloneNode ( const uiNode_t node,
uiNode_t newWindow,
bool  recursive,
const char *  newName,
bool  isDynamic 
)

Clone a node.

Parameters
[in]nodeNode to clone
[in]recursiveTrue if we also must clone subnodes
[in]newWindowWindow where the nodes must be add (this function only link node into window, not window into the new node)
[in]newNameNew node name, else nullptr to use the source name
[in]isDynamicAllocate a node in static or dynamic memory
Todo:

exclude rect is not safe cloned.

actions are not cloned. It is be a problem if we use add/remove listener into a cloned node.

Definition at line 409 of file ui_nodes.cpp.

References Com_Printf(), uiNode_t::dynamic, uiNode_t::firstChild, HASH_CloneTable(), uiNode_t::lastChild, uiNode_t::name, uiNode_t::next, uiNode_t::nodeMethods, uiNode_t::parent, Q_strncpyz(), uiNode_t::root, uiNode_t::super, UI_AllocNodeWithoutNew(), UI_AppendNode(), UI_CloneNode(), UI_Node_Clone(), UI_Node_GetMemorySize(), UI_Node_GetWidgetName(), and UI_Node_InitNodeDynamic().

Referenced by UI_AbstractNodeCallCreateChild(), UI_CloneNode(), UI_CreateComponent(), UI_CreateControl(), UI_CreateWindow(), UI_ParseComponent(), UI_ParseNode(), and UI_ParseWindow().

void UI_DeleteAllChild ( uiNode_t node)

Remove all child from a node (only remove dynamic memory allocation nodes)

Parameters
nodeThe node we want to clean

Definition at line 596 of file ui_nodes.cpp.

References uiNode_t::firstChild, uiNode_t::next, and UI_DeleteNode().

Referenced by UI_AbstractNodeCallRemovaAllChild(), UI_DeleteNode(), and uiNode_t_remove_children().

uiBehaviour_t* UI_GetNodeBehaviour ( const char *  name)

Return a node behaviour by name.

Note
Use a dichotomic search. nodeBehaviourList must be sorted by name.
Parameters
[in]nameBehaviour name requested
Returns
The bahaviour found, else nullptr

Definition at line 559 of file ui_nodes.cpp.

References NUMBER_OF_BEHAVIOURS.

Referenced by TEST_F(), UFO_AnalyseTestWindow(), UI_AllocNodeWithoutNew(), UI_CreateComponent(), UI_CreateControl(), UI_InitializeNodeBehaviour(), UI_ParseComponent(), UI_ParseNode(), and UI_Shutdown().

uiBehaviour_t* UI_GetNodeBehaviourByIndex ( int  index)

Definition at line 582 of file ui_nodes.cpp.

References index.

int UI_GetNodeBehaviourCount ( void  )

Definition at line 587 of file ui_nodes.cpp.

References NUMBER_OF_BEHAVIOURS.

uiNode_t* UI_GetNodeByPath ( const char *  path)

Return a node by a path name (names with dot separation) It is a simplification facade over UI_ReadNodePath.

Returns
The requested node, else nullptr if not found
1 // get keylist node from options_keys node from options window
2 node = UI_GetNodeByPath("options.options_keys.keylist");
3 @sa UI_ReadNodePath

Definition at line 313 of file ui_nodes.cpp.

References Com_Printf(), and UI_ReadNodePath().

Referenced by GAME_GetImportData(), UI_AddListener_f(), UI_PushDropDownWindow_f(), UI_RemoveListener_f(), and UI_TextScrollEnd().

static uiNode_t* UI_GetNodeInTreeAtPosition ( uiNode_t node,
int  rx,
int  ry 
)
static

Return the first visible node at a position.

Parameters
[in]nodeNode where we must search
[in]rxRelative x position to the parent of the node
[in]ryRelative y position to the parent of the node
Returns
The first visible node at position, else nullptr
Todo:
we should improve the loop (last-to-first)

Definition at line 467 of file ui_nodes.cpp.

References uiNode_t::box, uiNode_t::firstChild, uiNode_t::firstExcludeRect, uiNode_t::ghost, uiNode_t::invis, uiExcludeRect_s::next, uiNode_t::next, uiBox_t::pos, uiBox_t::size, UI_CheckVisibility(), UI_DebugMode(), UI_Node_GetClientPosition(), UI_Node_IsScrollableContainer(), and UI_Node_IsVirtual().

Referenced by UI_GetNodeAtPosition().

const char* UI_GetPath ( const uiNode_t node)

Return a path from a window to a node.

Returns
A path "windowname.nodename.nodename.givennodename"
Note
Use a static buffer for the result
Todo:
we can use something faster than cat

Definition at line 174 of file ui_nodes.cpp.

References i, name, uiNode_t::parent, and Q_strcat().

Referenced by _wrap_nodepath(), uiModelNode::doLayout(), uiTextNode::doLayout(), uiSelectBoxNode::drawOverWindow(), Key_WriteBindings(), uiRadioButtonNode::onActivate(), uiVScrollbarNode::onLoaded(), uiConFuncNode::onLoaded(), uiImageNode::onLoaded(), uiText2Node::onLoaded(), uiFuncNode::onLoaded(), uiTabNode::onWindowOpened(), UI_AbstractOption_GetCurrentValue(), UI_AddLineChartCoord(), UI_AddLineChartLine(), UI_AddListener(), UI_ColumnLayout(), UI_CreateControl(), UI_CvarListenerNodeBind(), UI_DeleteNode(), UI_ExecuteActions(), UI_ExecuteCallAction(), UI_ExecuteLuaConFunc(), UI_ExecuteLuaEventScript(), UI_ExecuteLuaEventScript_DragDrop(), UI_ExecuteLuaEventScript_DragDrop_IsDropped(), UI_ExecuteLuaEventScript_DragDrop_XY(), UI_ExecuteLuaEventScript_DxDy(), UI_ExecuteLuaEventScript_Key(), UI_ExecuteLuaEventScript_ParamList(), UI_ExecuteLuaEventScript_ReturnBool(), UI_ExecuteLuaEventScript_XY(), UI_ExecuteLuaMethod(), UI_ExecuteSetAction(), UI_GenInjectedString(), UI_GetFloatFromNodeProperty(), UI_GetNodeAbsPos(), UI_GetNodeFromExpression(), UI_GetNodeScreenPos(), UI_GetStringFromNodeProperty(), UI_InitRawActionValue(), UI_Node_GetText(), UI_NodeSetProperty(), UI_NodeSetPropertyFromRAW(), UI_ParseActionList(), UI_ParseCallAction(), UI_ParseEventProperty(), UI_ParseExcludeRect(), UI_ParseNode(), UI_ParseNodeBody(), UI_ParseNodeProperties(), UI_ParseSetAction(), UI_ShowChartDots(), and UI_ShowChartLine().

void UI_ReadNodePath ( const char *  path,
const uiNode_t relativeNode,
const uiNode_t iterationNode,
uiNode_t **  resultNode,
const value_t **  resultProperty,
value_t luaMethod 
)

Read a path and return every we can use (node and property)

The path token must be a window name, and then node child. Reserved token 'root' and 'parent' can be used to navigate. If relativeNode is set, the path can start with reserved token 'this', 'root', 'parent' and 'child' (relative to this node). The function can return a node property by using a '@', the path 'foo@pos' will return the window foo and the property 'pos' from the 'window' behaviour.

Parameters
[in]pathPath to read. Contain a node location with dot seprator and a facultative property
[in]relativeNoderelative node where the path start. It allow to use facultative command to start the path (this, parent, root).
[in]iterationNoderelative node referencing child in 'forchildin' iteration, mapped to '*node:child', can be nullptr
[out]resultNodeNode found. Else nullptr.
[out]resultPropertyProperty found. Else nullptr.
[in,out]luaMethodA pointer to a value_t structure that is filled with a lua based method identification, can be nullptr
Note
If luaMethod is set, the method will scan the known lua methods defined on the behaviour. If luaMethod is not set, only registered local properties are scanned.
Todo:
Speed up, evilly used function, use strncmp instead of using buffer copy (name[MAX_VAR])
Note
If luaMethod is set, make sure to release the allocated .name string.
Todo:
FIXME use a warning instead of an assert

Definition at line 219 of file ui_nodes.cpp.

References MAX_VAR, name, uiNode_t::parent, Q_streq, Q_strncpyz(), uiNode_t::root, value_s::type, UI_GetNode(), UI_GetPropertyOrLuaMethod(), UI_GetWindow(), UI_Node_IsWindow(), and UI_WindowNodeGetIndexedChild().

Referenced by UI_AddListener_f(), UI_ExecuteCallAction(), UI_ExecuteSetAction(), UI_GenInjectedString(), UI_GetBooleanFromExpression(), UI_GetNodeByPath(), UI_GetNodeFromExpression(), UI_RemoveListener_f(), and UI_SetKeyBindingEx().

Variable Documentation

uiBehaviour_t nodeBehaviourList[NUMBER_OF_BEHAVIOURS]
static

List of all node behaviours, indexes by nodetype num.

Definition at line 145 of file ui_nodes.cpp.

Referenced by UI_InitNodes().

const registerFunction_t registerFunctions[]
static

List of functions to register nodes.

Note
Functions must be sorted by node name

Definition at line 89 of file ui_nodes.cpp.

Referenced by UI_InitNodes().