39 #include "../../common/hashtable.h"
149 return b->
onScroll(node, deltaX, deltaY);
191 return b->
onStartDragging(node, startX, startY, currentX, currentY, button);
223 b->
clone(source, clone);
375 if (node->
text ==
nullptr) {
379 return (node->
text? node->
text :
"");
444 if (
Q_streq(behaviour->name, behaviourName))
485 Com_Printf(
"UI_NodeGetPoint: Align '%d' (0x%X) is not a common alignment", direction, direction);
502 Com_Printf(
"UI_NodeGetPoint: Align '%d' (0x%X) is not a common alignment", direction, direction);
529 pos[0] += node->
box.
pos[0];
530 pos[1] += node->
box.
pos[1];
557 pos[0] += node->
box.
pos[0];
558 pos[1] += node->
box.
pos[1];
562 vec2_t clientPosition = {0, 0};
564 pos[0] += clientPosition[0];
565 pos[1] += clientPosition[1];
580 pos[0] += node->
box.
pos[0];
581 pos[1] += node->
box.
pos[1];
594 assert(node !=
nullptr);
597 assert(x !=
nullptr);
598 assert(y !=
nullptr);
609 vec2_t clientPosition = {0, 0};
611 *x -= clientPosition[0];
612 *y -= clientPosition[1];
649 node->
box.
pos[0] = pos[0];
650 node->
box.
pos[1] = pos[1];
690 if (x != -1) p[0] = x;
else p[0] = node->
box.
pos[0];
691 if (y != -1) p[1] = y;
else p[1] = node->
box.
pos[1];
692 if (w != -1) s[0] = w;
else s[0] = node->
box.
size[0];
693 if (h != -1) s[1] = h;
else s[1] = node->
box.
size[1];
708 for (current = node->
firstChild; current; current = current->
next)
724 if (node == current->
next)
break;
758 assert(!newNode->
next);
761 newNode->
next = *anchor;
774 if (!newNode->
next) {
794 assert(child->
parent == node);
802 if (*anchor == child) {
803 *anchor = child->
next;
818 child->
next =
nullptr;
843 node->
root = newRoot;
863 if (property->
type != rawType) {
864 Com_Printf(
"UI_NodeSetPropertyFromRAW: type %i expected, but @%s type %i found. Property setter to '%s@%s' skipped\n", rawType, property->
string, property->
type,
UI_GetPath(node), property->
string);
873 case V_FLOAT: *Com_GetValue<float* >(node, property) = *static_cast<float const*>(rawValue);
break;
874 case V_INT: *Com_GetValue<int* >(node, property) = *static_cast<int const*>(rawValue);
break;
875 default: Com_GetValue<byte const*>(node, property) = static_cast<byte const*>(rawValue);
break;
878 Com_GetValue<uiAction_t const*>(node, property) = static_cast<uiAction_t const*>(rawValue);
880 Com_GetValue<uiSprite_t const*>(node, property) = static_cast<uiSprite_t const*>(rawValue);
892 const int specialType =
property->type &
V_UI_MASK;
896 switch (specialType) {
907 switch ((
int)property->
type) {
910 char*& b = Com_GetValue<char*>(node, property);
922 char*& b = Com_GetValue<char*>(node, property);
935 void*
const b = Com_GetValue<void*>(node, property);
936 if (
char const*
const cvar =
Q_strstart((
char const*)b,
"*cvar:"))
946 char*& b = Com_GetValue<char*>(node, property);
956 switch ((
int)property->
type) {
960 Com_GetValue<uiSprite_t const*>(node, property) = sprite;
980 const int baseType =
property->type &
V_UI_MASK;
988 switch ((
int)property->
type) {
1008 Com_Printf(
"UI_GetStringFromNodeProperty: Unsupported string getter for property type 0x%X (%s@%s)\n", property->
type,
UI_GetPath(node), property->
string);
1024 return Com_GetValue<float>(node, property);
1026 void*
const b = Com_GetValue<void*>(node, property);
1027 if (
char const*
const cvarName =
Q_strstart((
char const*)b,
"*cvar:")) {
1028 const cvar_t* cvar =
Cvar_Get(cvarName,
"", 0,
"UI script cvar property");
1031 return *(
const float*) b;
1033 return atof((
const char*)b);
1036 return Com_GetValue<int>(node, property);
1038 return Com_GetValue<bool>(node, property);
1041 Com_Printf(
"UI_GetFloatFromNodeProperty: Unimplemented float getter for property '%s@%s'. If it should return a float, request it.\n",
UI_GetPath(node), property->
string);
1091 Com_Printf(
"UI_AddNodeMethod: method [%s] already defined on this behaviour [%s]\n", name, node->
name);
1108 if (ref->nodeMethods) {
1109 void* val=
HASH_Get(ref->nodeMethods, name, strlen(name));
1110 if (val !=
nullptr) {
void UI_Node_Clone(uiNode_t const *source, uiNode_t *clone)
void UI_Node_PropertyChanged(uiNode_t *node, const value_t *property)
float UI_GetFloatFromNodeProperty(const uiNode_t *node, const value_t *property)
Return a float from a node property.
const char * UI_Node_GetTooltip(uiNode_t *node)
const char * Com_GetLastParseError(void)
virtual bool onDndDrop(uiNode_t *node, int x, int y)
virtual void onWindowActivate(uiNode_t *node)
#define Vector2Equal(a, b)
void UI_Validate(uiNode_t *node)
Validate a node tree.
virtual void onMouseLeave(uiNode_t *node)
bool UI_NodeSetProperty(uiNode_t *node, const value_t *property, const char *value)
Set node property.
virtual bool onDndMove(uiNode_t *node, int x, int y)
virtual void initNodeDynamic(uiNode_t *node)
void UI_Node_MouseUp(uiNode_t *node, int x, int y, int button)
bool UI_NodeInstanceOf(const uiNode_t *node, const char *behaviourName)
Check the node inheritance.
void UI_Node_PosChanged(uiNode_t *node)
void UI_Node_WindowOpened(uiNode_t *node, linkedList_t *params)
virtual void getClientPosition(uiNode_t const *node, vec2_t position)
void UI_Node_CapturedMouseLost(uiNode_t *node)
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
#define V_BASETYPEMASK
Allow to add extra bit into the type.
void UI_UpdateRoot(uiNode_t *node, uiNode_t *newRoot)
virtual void onRightClick(uiNode_t *node, int x, int y)
bool UI_GetBehaviourMethod(const uiBehaviour_t *behaviour, const char *name, LUA_METHOD &fcn)
Finds the lua based method on this behaviour or its super.
bool UI_Node_IsInvisible(uiNode_t const *node)
void UI_Invalidate(uiNode_t *node)
Invalidate a node and all his parent to request a layout update.
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
virtual void onFocusGained(uiNode_t *node)
virtual void onDndLeave(uiNode_t *node)
bool UI_Node_IsVirtual(uiNode_t const *node)
void UI_Node_SetFont(uiNode_t *node, const char *name)
#define UI_GET_HORIZONTAL_ALIGN(align)
void UI_Node_InitNode(uiNode_t *node)
bool UI_Node_IsOptionContainer(uiNode_t const *node)
virtual bool onMouseLongPress(uiNode_t *node, int x, int y, int button)
Send mouse event when a pressed mouse button is dragged.
virtual void onLoaded(uiNode_t *node)
bool UI_Node_MouseLongPress(uiNode_t *node, int x, int y, int button)
bool UI_Node_StartDragging(uiNode_t *node, int startX, int startY, int currentX, int currentY, int button)
void UI_InsertNode(uiNode_t *const parent, uiNode_t *prevNode, uiNode_t *newNode)
Insert a node next another one into a node. If prevNode is nullptr add the node on the head of the wi...
bool UI_Node_Scroll(uiNode_t *node, int deltaX, int deltaY)
uiBehaviour_t * behaviour
virtual void onWindowOpened(uiNode_t *node, linkedList_t *params)
virtual void onMouseUp(uiNode_t *node, int x, int y, int button)
void UI_Node_MouseMove(uiNode_t *node, int x, int y)
const char * UI_Node_GetText(uiNode_t *node)
virtual void onMouseMove(uiNode_t *node, int x, int y)
void UI_AddNodeMethod(uiNode_t *node, const char *name, LUA_METHOD fcn)
Adds a lua based method to the list of available node methods for calling.
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void Com_Printf(const char *const fmt,...)
bool UI_Node_IsScrollableContainer(uiNode_t const *node)
void UI_UnHideNode(uiNode_t *node)
Unhides a given node.
bool UI_NodeInstanceOfPointer(const uiNode_t *node, const uiBehaviour_t *behaviour)
Check the node inheritance.
void UI_Node_DrawOverWindow(uiNode_t *node)
void UI_AppendNode(uiNode_t *const parent, uiNode_t *newNode)
add a node at the end of the node child
void UI_Node_WindowClosed(uiNode_t *node)
virtual void onLoading(uiNode_t *node)
bool UI_WindowNodeRemoveIndexedNode(uiNode_t *const node, uiNode_t *const child)
Remove a node from the child index.
bool UI_Node_IsFlashing(uiNode_t const *node)
hashTable_s * HASH_NewTable(bool ownsKeys, bool ownsValues, bool duplicateOverwrite)
Creates a new hash table and sets it initial capacity.
void UI_Node_SetText(uiNode_t *node, const char *text)
virtual void clone(uiNode_t const *source, uiNode_t *clone)
void UI_FreeStringProperty(void *pointer)
Free a string property if it is allocated into ui_dynStringPool.
void UI_NodeSetBox(uiNode_t *node, float x, float y, float w, float h)
Update the node size and height and fire callbacks.
void UI_Node_RightClick(uiNode_t *node, int x, int y)
void UI_Node_FocusLost(uiNode_t *node)
bool UI_Node_DndFinished(uiNode_t *node, bool isDroped)
Internal data use by the UI package.
C interface to allow to access to cpp node code.
virtual void drawTooltip(const uiNode_t *node, int x, int y) const
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.
bool UI_Node_DndEnter(uiNode_t *node)
bool UI_Node_IsDrawable(uiNode_t const *node)
void UI_MoveNode(uiNode_t *const parent, uiNode_t *prevNode, uiNode_t *node)
Moves a node in the tree.
virtual void onCapturedMouseMove(uiNode_t *node, int x, int y)
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
void UI_Node_SetImage(uiNode_t *node, const char *name)
void UI_Node_FocusGained(uiNode_t *node)
#define Vector2Set(v, x, y)
memPool_t * ui_dynStringPool
void UI_Node_Loaded(uiNode_t *node)
int Com_SetValue(void *base, const void *set, valueTypes_t type, int ofs, size_t size)
bool UI_Node_KeyPressed(uiNode_t *node, unsigned int key, unsigned short unicode)
uiNode_t * UI_FindNode(const uiNode_t *node, const char *name)
Recursive searches for a child node by name in the entire subtree.
virtual int getCellWidth(uiNode_t *node)
bool UI_Node_DndMove(uiNode_t *node, int x, int y)
void UI_Node_Activate(uiNode_t *node)
int UI_Node_GetCellHeight(uiNode_t *node)
const char * Com_ValueToStr(const void *base, const valueTypes_t type, const int ofs)
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)
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
bool UI_Node_IsWindow(uiNode_t const *node)
void * HASH_Get(hashTable_s *t, const void *key, int nkey)
Returns the value for a given key.
virtual bool onScroll(uiNode_t *node, int deltaX, int deltaY)
void UI_NodeGetPoint(const uiNode_t *node, vec2_t pos, int direction)
return a relative position of a point into a node.
const char * UI_GetReferenceString(const uiNode_t *const node, const char *ref)
void UI_HideNode(uiNode_t *node)
Hides a given node.
uiNode_t * UI_GetPrevNode(const uiNode_t *node)
Returns the previous node based on the order of nodes in the parent.
int LUA_METHOD
holds a reference to a lua event handler
void UI_Node_SetDisabled(uiNode_t *node, const bool value)
Atomic structure used to define most of the UI.
void UI_Node_MouseLeave(uiNode_t *node)
intptr_t UI_Node_GetMemorySize(uiNode_t const *node)
bool UI_HasNodeMethod(uiNode_t *node, const char *name)
Returns true if a node method of given name is available on this node or its super.
resultStatus_t Com_ParseValue(void *base, const char *token, valueTypes_t type, int ofs, size_t size, size_t *writtenBytes)
Parse a value from a string.
virtual bool onStartDragging(uiNode_t *node, int startX, int startY, int currentX, int currentY, int button)
Send mouse event when a pressed mouse button is dragged.
bool UI_Node_DndDrop(uiNode_t *node, int x, int y)
LUA_METHOD UI_Node_GetItem(uiNode_t *node, const char *name)
This functions queries a lua based method in the internal uiNode behaviour.
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
float UI_GetReferenceFloat(const uiNode_t *const node, const void *ref)
Returns the value of the reference variable.
bool UI_Node_IsDrawItselfChild(uiNode_t const *node)
hashTable_s * nodeMethods
void UI_NodeSetPropertyFromRAW(uiNode_t *node, const value_t *property, const void *rawValue, int rawType)
virtual void drawOverWindow(uiNode_t *node)
bool UI_Node_IsDisabled(uiNode_t const *node)
virtual bool onDndEnter(uiNode_t *node)
void UI_Node_Draw(uiNode_t *node)
void UI_Node_DrawTooltip(const uiNode_t *node, int x, int y)
void UI_Node_WindowActivate(uiNode_t *node)
virtual void draw(uiNode_t *node)
bool UI_Node_IsAbstract(uiNode_t const *node)
virtual void onMiddleClick(uiNode_t *node, int x, int y)
virtual bool onKeyReleased(uiNode_t *node, unsigned int key, unsigned short unicode)
#define UI_GET_VERTICAL_ALIGN(align)
void UI_Node_SizeChanged(uiNode_t *node)
#define V_CVAR_OR_LONGSTRING
virtual void initNode(uiNode_t *node)
void UI_NodeSetPos(uiNode_t *node, vec2_t pos)
Update the node size and fire the pos callback.
void UI_Node_SetItem(uiNode_t *node, const char *name, LUA_METHOD fcn)
This functions adds a lua based method to the internal uiNode behaviour.
virtual void onFocusLost(uiNode_t *node)
virtual void onMouseDown(uiNode_t *node, int x, int y, int button)
uiNode_t * UI_GetNode(const uiNode_t *node, const char *name)
Search a child node by given name.
void UI_NodeAbsoluteToRelativePos(const uiNode_t *node, int *x, int *y)
Update an absolute position to a relative one.
node behaviour, how a node work
virtual void onWindowClosed(uiNode_t *node)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
virtual void onCapturedMouseLost(uiNode_t *node)
void UI_Node_InitNodeDynamic(uiNode_t *node)
void UI_Node_DndLeave(uiNode_t *node)
virtual void onSizeChanged(uiNode_t *node)
Callback stub.
bool UI_GetNodeMethod(const uiNode_t *node, const char *name, LUA_METHOD &fcn)
Finds the lua based method on this node or its super.
bool UI_Node_IsGhost(uiNode_t const *node)
bool UI_Node_KeyReleased(uiNode_t *node, unsigned int key, unsigned short unicode)
bool UI_Node_IsBattleScape(uiNode_t const *node)
void UI_Node_LeftClick(uiNode_t *node, int x, int y)
virtual void onPropertyChanged(uiNode_t *node, const value_t *property)
virtual void deleteNode(uiNode_t *node)
void UI_Node_DoLayout(uiNode_t *node)
void UI_Node_MiddleClick(uiNode_t *node, int x, int y)
virtual int getCellHeight(uiNode_t *node)
const char * UI_Node_GetWidgetName(uiNode_t const *node)
virtual void onMouseEnter(uiNode_t *node)
#define Mem_PoolStrDup(in, pool, tagNum)
bool UI_WindowNodeAddIndexedNode(uiNode_t *const node, uiNode_t *const child)
Add a node to the child index.
void UI_Node_MouseDown(uiNode_t *node, int x, int y, int button)
const char * UI_GetStringFromNodeProperty(const uiNode_t *node, const value_t *property)
Return a string from a node property.
void UI_Node_Loading(uiNode_t *node)
bool UI_Node_IsFunction(uiNode_t const *node)
uiSprite_t * UI_GetSpriteByName(const char *name)
Return an sprite by is name.
virtual void onLeftClick(uiNode_t *node, int x, int y)
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
virtual void doLayout(uiNode_t *node)
Call to update the node layout. This common code revalidates the node tree.
virtual bool onDndFinished(uiNode_t *node, bool isDropped)
void UI_Node_SetTooltip(uiNode_t *node, const char *tooltip)
int UI_Node_GetCellWidth(uiNode_t *node)
void UI_Node_DeleteNode(uiNode_t *node)
virtual void onActivate(uiNode_t *node)
Activate the node. Can be used without the mouse (ie. a button will execute onClick) ...
void UI_NodeSetSize(uiNode_t *node, vec2_t size)
Update the node size and fire the size callback.
void UI_Node_CapturedMouseMove(uiNode_t *node, int x, int y)
bool HASH_Insert(hashTable_s *t, const void *key, int nkey, const void *value, int nvalue)
Inserts a new value with given key into the hash table.
void UI_NodeRelativeToAbsolutePoint(const uiNode_t *node, vec2_t pos)
Update a relative point to an absolute one.
void UI_GetNodeScreenPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node in the screen. Screen position is not used for the node rende...
void UI_Node_MouseEnter(uiNode_t *node)
virtual bool onKeyPressed(uiNode_t *node, unsigned int key, unsigned short unicode)