UFO: Alien Invasion
Doxygen documentation generating
ui_nodes.h
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2023 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23 */
24 
25 #pragma once
26 
27 #include "../../shared/ufotypes.h"
28 #include "../../common/scripts.h"
29 #include "../../common/scripts_lua.h"
30 
31 /* prototype */
32 struct uiSprite_t;
33 struct value_s;
34 struct nodeKeyBinding_s;
35 struct uiCallContext_s;
36 struct uiModel_s;
37 struct uiBehaviour_t;
38 struct uiLuaCallback_t;
39 struct hashTable_s;
40 
41 typedef struct uiExcludeRect_s {
47  struct uiExcludeRect_s* next;
49 
50 struct uiBox_t {
53 
54  void clear() {
57  }
58 
59  void set(vec2_t pos, vec2_t size) {
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 
80 struct uiNode_t {
81  /* common identification */
82  char name[MAX_VAR];
84  uiNode_t const* super;
85  bool dynamic;
86  bool indexed;
88  /* common navigation */
95  /* common pos */
97 
98  /* common attributes */
99  char* tooltip;
100  struct uiKeyBinding_s* key;
101  bool invis;
102  bool disabled;
104  bool invalidated;
105  bool ghost;
106  bool state;
107  bool flash;
108  float flashSpeed;
109  int padding;
110  int align;
111  int num;
112  struct uiAction_s* visibilityCondition;
117 
118  /* other attributes */
121  char* text;
122  char* font;
123  char* image;
124  int border;
131  /* extended behaviour */
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;
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 */
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 */
190 void UI_InitNodes(void);
191 
192 /* nodes */
193 uiNode_t* UI_AllocNode(const char* name, const char* type, bool isDynamic);
194 uiNode_t* UI_GetNodeByPath(const char* path) __attribute__ ((warn_unused_result));
195 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);
196 uiNode_t* UI_GetNodeAtPosition(int x, int y) __attribute__ ((warn_unused_result));
197 const char* UI_GetPath(const uiNode_t* node) __attribute__ ((warn_unused_result));
198 uiNode_t* UI_CloneNode(const uiNode_t* node, uiNode_t* newWindow, bool recursive, const char* newName, bool isDynamic) __attribute__ ((warn_unused_result));
199 bool UI_CheckVisibility(uiNode_t* node);
200 void UI_DeleteAllChild(uiNode_t* node);
201 void UI_DeleteNode(uiNode_t* node);
202 
203 /* behaviours */
204 /* @todo move it to main */
205 uiBehaviour_t* UI_GetNodeBehaviour(const char* name) __attribute__ ((warn_unused_result));
206 uiBehaviour_t* UI_GetNodeBehaviourByIndex(int index) __attribute__ ((warn_unused_result));
207 int UI_GetNodeBehaviourCount(void) __attribute__ ((warn_unused_result));
bool disabled
Definition: ui_nodes.h:102
LUA_EVENT lua_onFocusGained
Definition: ui_nodes.h:154
vec4_t bordercolor
Definition: ui_nodes.h:126
int border
Definition: ui_nodes.h:124
uiNode_t const * super
Definition: ui_nodes.h:84
bool ghost
Definition: ui_nodes.h:105
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
LUA_EVENT lua_onDragDropFinished
Definition: ui_nodes.h:175
uiExcludeRect_t * firstExcludeRect
Definition: ui_nodes.h:116
vec4_t selectedColor
Definition: ui_nodes.h:128
struct uiAction_s * onChange
Definition: ui_nodes.h:143
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
vec4_t bgcolor
Definition: ui_nodes.h:125
struct uiAction_s * onMouseLeave
Definition: ui_nodes.h:140
uiBehaviour_t * behaviour
Definition: ui_nodes.h:83
LUA_EVENT lua_onWheelDown
Definition: ui_nodes.h:152
bool invis
Definition: ui_nodes.h:101
struct uiAction_s * onMouseEnter
Definition: ui_nodes.h:139
struct uiAction_s * onWheelUp
Definition: ui_nodes.h:141
uiBox_t box
Definition: ui_nodes.h:96
struct uiAction_s * onClick
Definition: ui_nodes.h:135
int LUA_EVENT
holds a reference to a lua event handler
Definition: scripts_lua.h:49
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
int UI_GetNodeBehaviourCount(void) __attribute__((warn_unused_result))
Definition: ui_nodes.cpp:587
LUA_EVENT lua_onWheelUp
Definition: ui_nodes.h:151
voidpf void uLong size
Definition: ioapi.h:42
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
int align
Definition: ui_nodes.h:110
bool indexed
Definition: ui_nodes.h:86
struct uiAction_s * onWheelDown
Definition: ui_nodes.h:142
struct uiAction_s * visibilityCondition
Definition: ui_nodes.h:112
#define Vector2Clear(a)
Definition: vector.h:54
#define __attribute__(x)
Definition: cxx.h:37
char * font
Definition: ui_nodes.h:122
vec2_t pos
Definition: ui_nodes.h:51
LUA_EVENT lua_onMouseEnter
Definition: ui_nodes.h:160
void UI_DeleteNode(uiNode_t *node)
Definition: ui_nodes.cpp:618
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
char * image
Definition: ui_nodes.h:123
uiNode_t * UI_AllocNode(const char *name, const char *type, bool isDynamic)
Allocate a node into the UI memory.
Definition: ui_nodes.cpp:381
LUA_EVENT lua_onMouseLeave
Definition: ui_nodes.h:161
bool state
Definition: ui_nodes.h:106
LUA_EVENT lua_onMiddleClick
Definition: ui_nodes.h:150
struct uiAction_s * onRightClick
Definition: ui_nodes.h:136
void UI_DeleteAllChild(uiNode_t *node)
Remove all child from a node (only remove dynamic memory allocation nodes)
Definition: ui_nodes.cpp:596
bool invalidated
Definition: ui_nodes.h:104
align_t
We need this here for checking the boundaries from script values.
Definition: scripts.h:89
bool dynamic
Definition: ui_nodes.h:85
bool UI_CheckVisibility(uiNode_t *node)
Check the if conditions for a given node.
Definition: ui_nodes.cpp:152
bool flash
Definition: ui_nodes.h:107
struct uiAction_s * onWheel
Definition: ui_nodes.h:138
#define MAX_VAR
Definition: shared.h:36
char * text
Definition: ui_nodes.h:121
char name[MAX_VAR]
Definition: ui_nodes.h:82
int deleteTime
Definition: ui_nodes.h:113
int padding
Definition: ui_nodes.h:109
uiNode_t * next
Definition: ui_nodes.h:91
uiNode_t * parent
Definition: ui_nodes.h:92
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
LUA_EVENT lua_onKeyPressed
Definition: ui_nodes.h:156
vec2_t pos
Definition: ui_nodes.h:43
void clear()
Definition: ui_nodes.h:54
uiNode_t * root
Definition: ui_nodes.h:93
uiBehaviour_t * UI_GetNodeBehaviour(const char *name) __attribute__((warn_unused_result))
Return a node behaviour by name.
Definition: ui_nodes.cpp:559
hashTable_s * nodeMethods
Definition: ui_nodes.h:132
QGL_EXTERN GLuint index
Definition: r_gl.h:110
LUA_EVENT lua_onDragDropLeave
Definition: ui_nodes.h:169
uiNode_t * firstChild
Definition: ui_nodes.h:89
LUA_EVENT lua_onFocusLost
Definition: ui_nodes.h:155
int contentAlign
Definition: ui_nodes.h:120
LUA_EVENT lua_onVisibleWhen
Definition: ui_nodes.h:163
vec4_t color
Definition: ui_nodes.h:127
LUA_EVENT lua_onKeyReleased
Definition: ui_nodes.h:157
vec4_t disabledColor
Definition: ui_nodes.h:103
LUA_EVENT lua_onWheel
Definition: ui_nodes.h:153
LUA_EVENT lua_onDragDropMove
Definition: ui_nodes.h:171
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
LUA_EVENT lua_onClick
Definition: ui_nodes.h:148
void expand(int dist)
Definition: ui_nodes.h:64
float flashSpeed
Definition: ui_nodes.h:108
LUA_EVENT lua_onLoaded
Definition: ui_nodes.h:158
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
#define Vector2Copy(src, dest)
Definition: vector.h:52
vec_t vec2_t[2]
Definition: ufotypes.h:38
uiBehaviour_t * UI_GetNodeBehaviourByIndex(int index) __attribute__((warn_unused_result))
Definition: ui_nodes.cpp:582
struct uiExcludeRect_s * next
Definition: ui_nodes.h:47
The hash table structure, contains an array of buckets being indexed by the hash function.
Definition: hashtable.cpp:96
bool dragdrop
Definition: ui_nodes.h:165
struct uiAction_s * onMiddleClick
Definition: ui_nodes.h:137
node behaviour, how a node work
Definition: ui_behaviour.h:39
vec2_t size
Definition: ui_nodes.h:52
LUA_EVENT lua_onDragDropEnter
Definition: ui_nodes.h:167
struct uiKeyBinding_s * key
Definition: ui_nodes.h:100
int num
Definition: ui_nodes.h:111
char * tooltip
Definition: ui_nodes.h:99
vec4_t flashColor
Definition: ui_nodes.h:129
uiNode_t * lastChild
Definition: ui_nodes.h:90
LUA_EVENT lua_onDragDropDrop
Definition: ui_nodes.h:173
LUA_EVENT lua_onActivate
Definition: ui_nodes.h:159
LUA_EVENT lua_onRightClick
Definition: ui_nodes.h:149
void alignBox(uiBox_t &inner, align_t direction)
Definition: ui_nodes.cpp:698
LUA_EVENT lua_onChange
Definition: ui_nodes.h:162
vec2_t size
Definition: ui_nodes.h:45
void UI_InitNodes(void)
Definition: ui_nodes.cpp:658
vec_t vec4_t[4]
Definition: ufotypes.h:40