UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_nodes.h
Go to the documentation of this file.
1
4
5/*
6Copyright (C) 2002-2025 UFO: Alien Invasion.
7
8This program is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public License
10as published by the Free Software Foundation; either version 2
11of the License, or (at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23*/
24
25#pragma once
26
30
31/* prototype */
32struct uiSprite_t;
33struct value_s;
34struct nodeKeyBinding_s;
35struct uiCallContext_s;
36struct uiModel_s;
37struct uiBehaviour_t;
38struct uiLuaCallback_t;
39struct hashTable_s;
40
41typedef struct uiExcludeRect_s {
47 struct uiExcludeRect_s* next;
49
50struct uiBox_t {
53
54 void clear() {
57 }
58
60 Vector2Copy(pos, this->pos);
61 Vector2Copy(size, this->size);
62 }
63
64 void expand(int dist) {
65 pos[0] -= dist;
66 pos[1] -= dist;
67 size[0] += 2 * dist;
68 size[1] += 2 * dist;
69 }
70
74 void alignBox(uiBox_t& inner, align_t direction);
75};
76
80struct uiNode_t {
81 /* common identification */
82 char name[MAX_VAR];
84 uiNode_t const* super;
85 bool dynamic;
86 bool indexed;
87
88 /* common navigation */
94
95 /* common pos */
97
98 /* common attributes */
99 char* tooltip;
100 struct uiKeyBinding_s* key;
101 bool invis;
102 bool disabled;
105 bool ghost;
106 bool state;
107 bool flash;
110 int align;
111 int num;
112 struct uiAction_s* visibilityCondition;
114
117
118 /* other attributes */
121 char* text;
122 char* font;
123 char* image;
124 int border;
130
131 /* extended behaviour */
133
134 /* common events */
135 struct uiAction_s* onClick;
136 struct uiAction_s* onRightClick;
137 struct uiAction_s* onMiddleClick;
138 struct uiAction_s* onWheel;
139 struct uiAction_s* onMouseEnter;
140 struct uiAction_s* onMouseLeave;
141 struct uiAction_s* onWheelUp;
142 struct uiAction_s* onWheelDown;
143 struct uiAction_s* onChange;
144
145 /* common events lua based */
146 /* note: if new events are added here, make sure the value is initialized to LUA_NOREF
147 @sa: UI_AllocNodeWithoutNew */
164
165 bool dragdrop;
176};
177
178
184#define UI_EXTRADATA_POINTER(NODE, TYPE) ((TYPE*)((char*)NODE + sizeof(uiNode_t)))
185#define UI_EXTRADATA(NODE, TYPE) (*UI_EXTRADATA_POINTER(NODE, TYPE))
186#define UI_EXTRADATACONST_POINTER(NODE, TYPE) ((TYPE*)((const char*)NODE + sizeof(uiNode_t)))
187#define UI_EXTRADATACONST(NODE, TYPE) (*UI_EXTRADATACONST_POINTER(NODE, const TYPE))
188
189/* module initialization */
190void UI_InitNodes(void);
191
192/* nodes */
193uiNode_t* UI_AllocNode(const char* name, const char* type, bool isDynamic);
194uiNode_t* UI_GetNodeByPath(const char* path) __attribute__ ((warn_unused_result));
195void UI_ReadNodePath(const char* path, const uiNode_t* relativeNode, const uiNode_t* iterationNode, uiNode_t** resultNode, const value_t** resultProperty, value_t* luaMethod = nullptr);
196uiNode_t* UI_GetNodeAtPosition(int x, int y) __attribute__ ((warn_unused_result));
197const char* UI_GetPath(const uiNode_t* node) __attribute__ ((warn_unused_result));
198uiNode_t* UI_CloneNode(const uiNode_t* node, uiNode_t* newWindow, bool recursive, const char* newName, bool isDynamic) __attribute__ ((warn_unused_result));
199bool UI_CheckVisibility(uiNode_t* node);
200void UI_DeleteAllChild(uiNode_t* node);
201void UI_DeleteNode(uiNode_t* node);
202
203/* behaviours */
204/* @todo move it to main */
205uiBehaviour_t* UI_GetNodeBehaviour(const char* name) __attribute__ ((warn_unused_result));
207int UI_GetNodeBehaviourCount(void) __attribute__ ((warn_unused_result));
#define __attribute__(x)
Definition cxx.h:37
QGL_EXTERN GLuint index
Definition r_gl.h:110
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition r_gl.h:110
Header for script parsing functions.
align_t
We need this here for checking the boundaries from script values.
Definition scripts.h:89
Header for lua script functions.
int LUA_EVENT
holds a reference to a lua event handler
Definition scripts_lua.h:49
#define MAX_VAR
Definition shared.h:36
The hash table structure, contains an array of buckets being indexed by the hash function.
Definition hashtable.cpp:96
node behaviour, how a node work
void alignBox(uiBox_t &inner, align_t direction)
Definition ui_nodes.cpp:698
void expand(int dist)
Definition ui_nodes.h:64
vec2_t size
Definition ui_nodes.h:52
vec2_t pos
Definition ui_nodes.h:51
void set(vec2_t pos, vec2_t size)
Definition ui_nodes.h:59
void clear()
Definition ui_nodes.h:54
struct uiExcludeRect_s * next
Definition ui_nodes.h:47
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
bool disabled
Definition ui_nodes.h:102
char * tooltip
Definition ui_nodes.h:99
int border
Definition ui_nodes.h:124
struct uiAction_s * visibilityCondition
Definition ui_nodes.h:112
struct uiAction_s * onWheelDown
Definition ui_nodes.h:142
vec4_t flashColor
Definition ui_nodes.h:129
uiNode_t const * super
Definition ui_nodes.h:84
uiNode_t * firstChild
Definition ui_nodes.h:89
bool invis
Definition ui_nodes.h:101
uiNode_t * next
Definition ui_nodes.h:91
struct uiAction_s * onMouseLeave
Definition ui_nodes.h:140
LUA_EVENT lua_onDragDropFinished
Definition ui_nodes.h:175
bool flash
Definition ui_nodes.h:107
LUA_EVENT lua_onFocusLost
Definition ui_nodes.h:155
char * text
Definition ui_nodes.h:121
LUA_EVENT lua_onDragDropMove
Definition ui_nodes.h:171
LUA_EVENT lua_onVisibleWhen
Definition ui_nodes.h:163
int contentAlign
Definition ui_nodes.h:120
LUA_EVENT lua_onKeyReleased
Definition ui_nodes.h:157
LUA_EVENT lua_onDragDropEnter
Definition ui_nodes.h:167
int deleteTime
Definition ui_nodes.h:113
bool indexed
Definition ui_nodes.h:86
LUA_EVENT lua_onDragDropLeave
Definition ui_nodes.h:169
LUA_EVENT lua_onWheelDown
Definition ui_nodes.h:152
LUA_EVENT lua_onDragDropDrop
Definition ui_nodes.h:173
LUA_EVENT lua_onLoaded
Definition ui_nodes.h:158
vec4_t color
Definition ui_nodes.h:127
uiNode_t * lastChild
Definition ui_nodes.h:90
bool invalidated
Definition ui_nodes.h:104
bool ghost
Definition ui_nodes.h:105
uiBehaviour_t * behaviour
Definition ui_nodes.h:83
struct uiAction_s * onWheel
Definition ui_nodes.h:138
struct uiAction_s * onMiddleClick
Definition ui_nodes.h:137
LUA_EVENT lua_onRightClick
Definition ui_nodes.h:149
char * font
Definition ui_nodes.h:122
uiExcludeRect_t * firstExcludeRect
Definition ui_nodes.h:116
LUA_EVENT lua_onChange
Definition ui_nodes.h:162
bool dragdrop
Definition ui_nodes.h:165
uiNode_t * parent
Definition ui_nodes.h:92
LUA_EVENT lua_onMouseLeave
Definition ui_nodes.h:161
struct uiAction_s * onChange
Definition ui_nodes.h:143
bool dynamic
Definition ui_nodes.h:85
int align
Definition ui_nodes.h:110
vec4_t selectedColor
Definition ui_nodes.h:128
LUA_EVENT lua_onMiddleClick
Definition ui_nodes.h:150
LUA_EVENT lua_onClick
Definition ui_nodes.h:148
hashTable_s * nodeMethods
Definition ui_nodes.h:132
uiBox_t box
Definition ui_nodes.h:96
LUA_EVENT lua_onKeyPressed
Definition ui_nodes.h:156
float flashSpeed
Definition ui_nodes.h:108
LUA_EVENT lua_onMouseEnter
Definition ui_nodes.h:160
struct uiKeyBinding_s * key
Definition ui_nodes.h:100
char name[MAX_VAR]
Definition ui_nodes.h:82
int padding
Definition ui_nodes.h:109
struct uiAction_s * onClick
Definition ui_nodes.h:135
LUA_EVENT lua_onWheel
Definition ui_nodes.h:153
vec4_t disabledColor
Definition ui_nodes.h:103
struct uiAction_s * onRightClick
Definition ui_nodes.h:136
vec4_t bgcolor
Definition ui_nodes.h:125
int num
Definition ui_nodes.h:111
char * image
Definition ui_nodes.h:123
struct uiAction_s * onMouseEnter
Definition ui_nodes.h:139
vec4_t bordercolor
Definition ui_nodes.h:126
uiNode_t * root
Definition ui_nodes.h:93
struct uiAction_s * onWheelUp
Definition ui_nodes.h:141
LUA_EVENT lua_onActivate
Definition ui_nodes.h:159
LUA_EVENT lua_onFocusGained
Definition ui_nodes.h:154
LUA_EVENT lua_onWheelUp
Definition ui_nodes.h:151
bool state
Definition ui_nodes.h:106
Cross-platform type definitions.
vec_t vec4_t[4]
Definition ufotypes.h:40
vec_t vec2_t[2]
Definition ufotypes.h:38
const char * UI_GetPath(const uiNode_t *node) __attribute__((warn_unused_result))
Return a path from a window to a node.
Definition ui_nodes.cpp:174
void UI_ReadNodePath(const char *path, const uiNode_t *relativeNode, const uiNode_t *iterationNode, uiNode_t **resultNode, const value_t **resultProperty, value_t *luaMethod=nullptr)
Read a path and return every we can use (node and property).
Definition ui_nodes.cpp:219
bool UI_CheckVisibility(uiNode_t *node)
Check the if conditions for a given node.
Definition ui_nodes.cpp:152
void UI_InitNodes(void)
Definition ui_nodes.cpp:658
int UI_GetNodeBehaviourCount(void) __attribute__((warn_unused_result))
Definition ui_nodes.cpp:587
uiNode_t * UI_AllocNode(const char *name, const char *type, bool isDynamic)
Allocate a node into the UI memory.
Definition ui_nodes.cpp:381
uiBehaviour_t * UI_GetNodeBehaviour(const char *name) __attribute__((warn_unused_result))
Return a node behaviour by name.
Definition ui_nodes.cpp:559
uiNode_t * UI_GetNodeByPath(const char *path) __attribute__((warn_unused_result))
Return a node by a path name (names with dot separation) It is a simplification facade over UI_ReadNo...
Definition ui_nodes.cpp:313
uiBehaviour_t * UI_GetNodeBehaviourByIndex(int index) __attribute__((warn_unused_result))
Definition ui_nodes.cpp:582
void UI_DeleteAllChild(uiNode_t *node)
Remove all child from a node (only remove dynamic memory allocation nodes).
Definition ui_nodes.cpp:596
uiNode_t * UI_CloneNode(const uiNode_t *node, uiNode_t *newWindow, bool recursive, const char *newName, bool isDynamic) __attribute__((warn_unused_result))
Clone a node.
Definition ui_nodes.cpp:409
uiNode_t * UI_GetNodeAtPosition(int x, int y) __attribute__((warn_unused_result))
Return the first visible node at a position.
Definition ui_nodes.cpp:527
void UI_DeleteNode(uiNode_t *node)
Definition ui_nodes.cpp:618
#define Vector2Clear(a)
Definition vector.h:54
#define Vector2Copy(src, dest)
Definition vector.h:52