25 #include "../../common/hashtable.h"
26 #include "../../common/scripts_lua.h"
140 #define NUMBER_OF_BEHAVIOURS lengthof(registerFunctions)
176 static char result[512];
193 Q_strcat(result,
sizeof(result),
".");
223 const char* nextName;
224 char nextCommand =
'^';
226 *resultNode =
nullptr;
228 *resultProperty =
nullptr;
231 while (nextName && nextName[0] !=
'\0') {
232 const char* begin = nextName;
233 char command = nextCommand;
234 nextName = strpbrk(begin,
".@#");
239 assert(nextName - begin + 1 <=
sizeof(name));
240 Q_strncpyz(name, begin, nextName - begin + 1);
241 nextCommand = *nextName;
248 if (relativeNode ==
nullptr)
250 node =
const_cast<uiNode_t *
>(relativeNode);
251 }
else if (
Q_streq(name,
"parent")) {
252 if (relativeNode ==
nullptr)
254 node = relativeNode->
parent;
255 }
else if (
Q_streq(name,
"root")) {
256 if (relativeNode ==
nullptr)
258 node = relativeNode->
root;
259 }
else if (
Q_streq(name,
"child")) {
260 if (iterationNode ==
nullptr)
262 node =
const_cast<uiNode_t *
>(iterationNode);
269 else if (
Q_streq(name,
"root"))
270 childnode = node->
root;
274 if (luaMethod && !childnode) {
276 if (luaMethod->
type) {
289 assert(nextCommand ==
'\0');
316 const value_t*
property =
nullptr;
319 Com_Printf(
"WARNING: Search for node using path [%s] returns property [%s]\n", path, property->string);
339 if (behaviour ==
nullptr)
340 Com_Error(
ERR_FATAL,
"UI_AllocNodeWithoutNew: Node behaviour '%s' doesn't exist", type);
346 if (memory ==
nullptr)
347 Com_Error(
ERR_FATAL,
"UI_AllocNodeWithoutNew: No more memory to allocate a new node - increase the cvar ui_hunksize");
348 node =
static_cast<uiNode_t*
>(memory);
357 UI_Node_DebugCountWidget(node, 1);
360 Com_Error(
ERR_FATAL,
"UI_AllocNodeWithoutNew: Node behavior '%s' is abstract. We can't instantiate it.", type);
362 if (name !=
nullptr) {
364 if (strlen(node->
name) != strlen(name))
365 Com_Printf(
"UI_AllocNodeWithoutNew: Node name \"%s\" truncated. New name is \"%s\"\n", name, node->
name);
418 if (newName !=
nullptr) {
420 if (strlen(newNode->
name) != strlen(newName))
421 Com_Printf(
"UI_CloneNode: Node name \"%s\" truncated. New name is \"%s\"\n", newName, newNode->
name);
425 if (node->
root == node && newWindow ==
nullptr)
428 newNode->
root = newWindow;
429 newNode->
parent =
nullptr;
432 newNode->
next =
nullptr;
433 newNode->
super = node;
477 if (rx < 0 || ry < 0 || rx >= node->
box.
size[0] || ry >= node->
box.
size[1])
483 vec2_t clientPosition = {0, 0};
488 rx -= clientPosition[0];
489 ry -= clientPosition[1];
498 rx += clientPosition[0];
499 ry += clientPosition[1];
512 if (rx >= excludeRect->pos[0]
513 && rx < excludeRect->pos[0] + excludeRect->size[0]
514 && ry >= excludeRect->pos[1]
515 && ry < excludeRect->pos[1] + excludeRect->size[1])
561 unsigned char min = 0;
565 const int mid = (min + max) >> 1;
566 const int diff = strcmp(nodeBehaviourList[mid].name, name);
571 return &nodeBehaviourList[mid];
584 return &nodeBehaviourList[
index];
629 Com_Printf(
"UI_DeleteNode: Node '%s' contain static nodes. We can't delete it.\n",
UI_GetPath(node));
639 if (property ==
nullptr)
643 if (
void*& mem = Com_GetValue<void*>(node, *property)) {
676 for (i = 0; i < NUMBER_OF_BEHAVIOURS - 1; i++) {
680 if (strcmp(a->
name, b->
name) >= 0) {
682 Com_Error(
ERR_FATAL,
"UI_InitNodes: '%s' is before '%s'. Please order node behaviour registrations by name", a->
name, b->
name);
700 switch (direction % 3) {
702 inner.
pos[0] = this->
pos[0];
705 inner.
pos[0] = this->
pos[0] + (this->
size[0] * 0.5) - (inner.
size[0] * 0.5);
711 switch (direction / 3) {
713 inner.
pos[1] = this->
pos[1];
716 inner.
pos[1] = this->
pos[1] + (this->
size[1] * 0.5) - (inner.
size[1] * 0.5);
722 inner.
pos[1] = this->
pos[1];
void UI_Node_Clone(uiNode_t const *source, uiNode_t *clone)
static uiNode_t * UI_AllocNodeWithoutNew(const char *name, const char *type, bool isDynamic)
Allocate a node into the UI memory (do not call behaviour->new)
uiNode_t * windowStack[UI_MAX_WINDOWSTACK]
void UI_RegisterFuncNode(uiBehaviour_t *behaviour)
void UI_RegisterOptionListNode(uiBehaviour_t *behaviour)
Material editor related header.
void UI_Validate(uiNode_t *node)
Validate a node tree.
void UI_RegisterControlsNode(uiBehaviour_t *behaviour)
void * UI_AllocHunkMemory(size_t size, int align, bool reset)
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)
bool UI_GetBooleanFromExpression(uiAction_t *expression, const uiCallContext_t *context)
Check if an expression is true.
QGL_EXTERN GLint GLenum type
void UI_InitializeNodeBehaviour(uiBehaviour_t *behaviour)
Initialize a node behaviour memory, after registration, and before using it.
static uiBehaviour_t nodeBehaviourList[NUMBER_OF_BEHAVIOURS]
List of all node behaviours, indexes by nodetype num.
Basic lua initialization for the ui.
bool UI_CheckVisibility(uiNode_t *node)
Check the if conditions for a given node.
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_ReadNo...
bool UI_WindowIsFullScreen(const uiNode_t *const node)
Check if a window is fullscreen or not.
bool UI_Node_IsVirtual(uiNode_t const *node)
void UI_Node_InitNode(uiNode_t *node)
void UI_RegisterBattlescapeNode(uiBehaviour_t *behaviour)
uiNode_t * UI_GetNodeAtPosition(int x, int y)
Return the first visible node at a position.
#define Mem_PoolAlloc(size, pool, tagNum)
uiBehaviour_t * behaviour
void UI_RegisterTextEntryNode(uiBehaviour_t *behaviour)
void UI_RegisterItemNode(uiBehaviour_t *behaviour)
void UI_RegisterNullNode(uiBehaviour_t *behaviour)
uiExcludeRect_t * firstExcludeRect
void UI_RegisterMessageListNode(uiBehaviour_t *behaviour)
uiBehaviour_t * UI_GetNodeBehaviourByIndex(int index)
void alignBox(uiBox_t &inner, align_t direction)
void UI_RegisterEditorNode(uiBehaviour_t *behaviour)
void UI_RegisterSelectBoxNode(uiBehaviour_t *behaviour)
void UI_RegisterMaterialEditorNode(uiBehaviour_t *behaviour)
void Com_Printf(const char *const fmt,...)
bool UI_Node_IsScrollableContainer(uiNode_t const *node)
Define common thing for GUI controls which allow to edit a value (scroolbar, spinner, and more)
void UI_RegisterLineChartNode(uiBehaviour_t *behaviour)
Registers lineChart node.
void UI_AppendNode(uiNode_t *const parent, uiNode_t *newNode)
add a node at the end of the node child
void UI_RegisterSpinnerNode(uiBehaviour_t *behaviour)
void UI_DeleteNode(uiNode_t *node)
void UI_RegisterZoneNode(uiBehaviour_t *behaviour)
static const registerFunction_t registerFunctions[]
List of functions to register nodes.
void UI_RegisterAbstractOptionNode(uiBehaviour_t *behaviour)
void UI_FreeStringProperty(void *pointer)
Free a string property if it is allocated into ui_dynStringPool.
void UI_RegisterWindowNode(uiBehaviour_t *behaviour)
void UI_RegisterTBarNode(uiBehaviour_t *behaviour)
void UI_RegisterRowsNode(uiBehaviour_t *behaviour)
Internal data use by the UI package.
C interface to allow to access to cpp node code.
void Com_Error(int code, const char *fmt,...)
uiNode_t * UI_RemoveNode(uiNode_t *const node, uiNode_t *child)
Remove a node from a parent node.
uiNode_t * UI_AllocNode(const char *name, const char *type, bool isDynamic)
Allocate a node into the UI memory.
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
void UI_RegisterBaseLayoutNode(uiBehaviour_t *behaviour)
align_t
We need this here for checking the boundaries from script values.
#define STRUCT_MEMORY_ALIGN
void UI_RegisterStringNode(uiBehaviour_t *behaviour)
void UI_RegisterTextListNode(uiBehaviour_t *behaviour)
void UI_DeleteAllChild(uiNode_t *node)
Remove all child from a node (only remove dynamic memory allocation nodes)
void UI_RegisterModelNode(uiBehaviour_t *behaviour)
void UI_RegisterSequenceNode(uiBehaviour_t *behaviour)
void UI_RegisterVideoNode(uiBehaviour_t *behaviour)
void UI_RegisterTextNode(uiBehaviour_t *behaviour)
const char * UI_GetPath(const uiNode_t *node)
Return a path from a window to a node.
void UI_Node_GetClientPosition(uiNode_t const *node, vec2_t position)
void UI_RegisterTimerNode(uiBehaviour_t *behaviour)
bool UI_Node_IsWindow(uiNode_t const *node)
uiNode_t * UI_WindowNodeGetIndexedChild(uiNode_t *const node, const char *childName)
Get a node from child index.
static uiNode_t * UI_GetNodeInTreeAtPosition(uiNode_t *node, int rx, int ry)
Return the first visible node at a position.
Atomic structure used to define most of the UI.
intptr_t UI_Node_GetMemorySize(uiNode_t const *node)
#define NUMBER_OF_BEHAVIOURS
void(* registerFunction_t)(uiBehaviour_t *node)
const GLuint *typedef void(APIENTRY *GenRenderbuffersEXT_t)(GLsizei
uiNode_t * UI_CloneNode(const uiNode_t *node, uiNode_t *newWindow, bool recursive, const char *newName, bool isDynamic)
Clone a node.
Contain the context of the calling of a function.
hashTable_s * nodeMethods
void UI_RegisterOptionNode(uiBehaviour_t *behaviour)
uiNode_t * UI_GetWindow(const char *name)
Searches all windows for the specified one.
void UI_RegisterDataNode(uiBehaviour_t *behaviour)
void UI_RegisterPanelNode(uiBehaviour_t *behaviour)
bool UI_Node_IsAbstract(uiNode_t const *node)
bool UI_WindowIsModal(uiNode_t const *const node)
True if the window is a modal.
void UI_RegisterBaseInventoryNode(uiBehaviour_t *behaviour)
struct uiAction_s * visibilityCondition
uiNode_t * UI_GetNode(const uiNode_t *node, const char *name)
Search a child node by given name.
node behaviour, how a node work
static void UI_BeforeDeletingNode(const uiNode_t *node)
LUA_EVENT lua_onVisibleWhen
void UI_RegisterContainerNode(uiBehaviour_t *behaviour)
uiBehaviour_t * UI_GetNodeBehaviour(const char *name)
Return a node behaviour by name.
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
void UI_RegisterCheckBoxNode(uiBehaviour_t *behaviour)
void UI_RegisterCvarFuncNode(uiBehaviour_t *behaviour)
void UI_Node_InitNodeDynamic(uiNode_t *node)
void UI_RegisterAbstractValueNode(uiBehaviour_t *behaviour)
hashTable_s * HASH_CloneTable(hashTable_s *source)
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
const value_t ** localProperties
void UI_RegisterText2Node(uiBehaviour_t *behaviour)
int UI_DebugMode(void)
Get the current debug mode (0 mean disabled)
void UI_RegisterTabNode(uiBehaviour_t *behaviour)
bool UI_WindowIsDropDown(uiNode_t const *const node)
True if the window is a drop down.
void UI_RegisterGeoscapeNode(uiBehaviour_t *behaviour)
const char * UI_Node_GetWidgetName(uiNode_t const *node)
void UI_RegisterAbstractNode(uiBehaviour_t *behaviour)
void UI_Node_Loading(uiNode_t *node)
void UI_RegisterOptionTreeNode(uiBehaviour_t *behaviour)
void UI_RegisterImageNode(uiBehaviour_t *behaviour)
void UI_RegisterTextureNode(uiBehaviour_t *behaviour)
struct uiExcludeRect_s * next
void UI_RegisterConFuncNode(uiBehaviour_t *behaviour)
int UI_GetNodeBehaviourCount(void)
void UI_Node_DeleteNode(uiNode_t *node)
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.
void UI_RegisterRadarNode(uiBehaviour_t *behaviour)
void UI_RegisterBarNode(uiBehaviour_t *behaviour)
bool UI_ExecuteLuaEventScript_ReturnBool(uiNode_t *node, LUA_EVENT event, bool &result)
Executes a lua event handler and returns the result as a boolean.