UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_nodes.h
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 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 {
49 
50 struct uiBox_t {
53 
54  void clear() {
55  Vector2Clear(pos);
56  Vector2Clear(size);
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;
117 
118  /* other attributes */
121  char* text;
122  char* font;
123  char* image;
124  int border;
131  /* extended behaviour */
134  /* common events */
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));
struct uiAction_s * onWheelDown
Definition: ui_nodes.h:142
int align
Definition: ui_nodes.h:110
bool invalidated
Definition: ui_nodes.h:104
vec2_t size
Definition: ui_nodes.h:52
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
uiNode_t * parent
Definition: ui_nodes.h:92
LUA_EVENT lua_onChange
Definition: ui_nodes.h:162
QGL_EXTERN GLint GLenum type
Definition: r_gl.h:94
uiNode_t * next
Definition: ui_nodes.h:91
struct uiAction_s * onChange
Definition: ui_nodes.h:143
struct uiAction_s * onMouseEnter
Definition: ui_nodes.h:139
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
vec4_t bordercolor
Definition: ui_nodes.h:126
char name[MAX_VAR]
Definition: ui_nodes.h:82
uiBehaviour_t * behaviour
Definition: ui_nodes.h:83
int UI_GetNodeBehaviourCount(void) __attribute__((warn_unused_result))
Definition: ui_nodes.cpp:587
struct uiAction_s * onMouseLeave
Definition: ui_nodes.h:140
LUA_EVENT lua_onKeyPressed
Definition: ui_nodes.h:156
uiExcludeRect_t * firstExcludeRect
Definition: ui_nodes.h:116
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
vec4_t flashColor
Definition: ui_nodes.h:129
void alignBox(uiBox_t &inner, align_t direction)
Definition: ui_nodes.cpp:698
int num
Definition: ui_nodes.h:111
bool dynamic
Definition: ui_nodes.h:85
vec2_t size
Definition: ui_nodes.h:45
LUA_EVENT lua_onWheelDown
Definition: ui_nodes.h:152
#define Vector2Clear(a)
Definition: vector.h:54
char * tooltip
Definition: ui_nodes.h:99
#define __attribute__(x)
Definition: cxx.h:37
struct uiAction_s * onClick
Definition: ui_nodes.h:135
LUA_EVENT lua_onMouseLeave
Definition: ui_nodes.h:161
struct uiExcludeRect_s uiExcludeRect_t
int border
Definition: ui_nodes.h:124
void UI_DeleteNode(uiNode_t *node)
Definition: ui_nodes.cpp:618
LUA_EVENT lua_onMiddleClick
Definition: ui_nodes.h:150
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
uiNode_t * UI_AllocNode(const char *name, const char *type, bool isDynamic)
Allocate a node into the UI memory.
Definition: ui_nodes.cpp:381
bool invis
Definition: ui_nodes.h:101
uiNode_t * root
Definition: ui_nodes.h:93
void UI_DeleteAllChild(uiNode_t *node)
Remove all child from a node (only remove dynamic memory allocation nodes)
Definition: ui_nodes.cpp:596
align_t
We need this here for checking the boundaries from script values.
Definition: scripts.h:90
LUA_EVENT lua_onLoaded
Definition: ui_nodes.h:158
LUA_EVENT lua_onRightClick
Definition: ui_nodes.h:149
bool UI_CheckVisibility(uiNode_t *node)
Check the if conditions for a given node.
Definition: ui_nodes.cpp:152
bool state
Definition: ui_nodes.h:106
char * font
Definition: ui_nodes.h:122
uiNode_t * lastChild
Definition: ui_nodes.h:90
bool ghost
Definition: ui_nodes.h:105
LUA_EVENT lua_onFocusGained
Definition: ui_nodes.h:154
#define MAX_VAR
Definition: shared.h:36
struct uiAction_s * onWheelUp
Definition: ui_nodes.h:141
struct uiAction_s * onMiddleClick
Definition: ui_nodes.h:137
LUA_EVENT lua_onDragDropDrop
Definition: ui_nodes.h:173
vec4_t disabledColor
Definition: ui_nodes.h:103
int padding
Definition: ui_nodes.h:109
bool indexed
Definition: ui_nodes.h:86
bool flash
Definition: ui_nodes.h:107
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_onKeyReleased
Definition: ui_nodes.h:157
void clear()
Definition: ui_nodes.h:54
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
vec2_t pos
Definition: ui_nodes.h:43
bool disabled
Definition: ui_nodes.h:102
uiBehaviour_t * UI_GetNodeBehaviour(const char *name) __attribute__((warn_unused_result))
Return a node behaviour by name.
Definition: ui_nodes.cpp:559
QGL_EXTERN GLuint index
Definition: r_gl.h:110
Contain the context of the calling of a function.
Definition: ui_actions.h:208
struct uiAction_s * onRightClick
Definition: ui_nodes.h:136
hashTable_s * nodeMethods
Definition: ui_nodes.h:132
vec4_t bgcolor
Definition: ui_nodes.h:125
vec4_t selectedColor
Definition: ui_nodes.h:128
LUA_EVENT lua_onDragDropEnter
Definition: ui_nodes.h:167
struct uiAction_s * visibilityCondition
Definition: ui_nodes.h:112
node behaviour, how a node work
Definition: ui_behaviour.h:39
LUA_EVENT lua_onVisibleWhen
Definition: ui_nodes.h:163
int contentAlign
Definition: ui_nodes.h:120
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
vec4_t color
Definition: ui_nodes.h:127
struct uiAction_s * onWheel
Definition: ui_nodes.h:138
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
LUA_EVENT lua_onActivate
Definition: ui_nodes.h:159
#define Vector2Copy(src, dest)
Definition: vector.h:52
vec_t vec2_t[2]
Definition: ufotypes.h:38
uiNode_t const * super
Definition: ui_nodes.h:84
LUA_EVENT lua_onMouseEnter
Definition: ui_nodes.h:160
uiBehaviour_t * UI_GetNodeBehaviourByIndex(int index) __attribute__((warn_unused_result))
Definition: ui_nodes.cpp:582
LUA_EVENT lua_onDragDropMove
Definition: ui_nodes.h:171
float flashSpeed
Definition: ui_nodes.h:108
char * image
Definition: ui_nodes.h:123
LUA_EVENT lua_onFocusLost
Definition: ui_nodes.h:155
LUA_EVENT lua_onWheelUp
Definition: ui_nodes.h:151
uiNode_t * firstChild
Definition: ui_nodes.h:89
void expand(int dist)
Definition: ui_nodes.h:64
LUA_EVENT lua_onClick
Definition: ui_nodes.h:148
uiBox_t box
Definition: ui_nodes.h:96
Model that have more than one part (top and down part of an aircraft)
Definition: ui_node_model.h:47
LUA_EVENT lua_onDragDropLeave
Definition: ui_nodes.h:169
struct uiExcludeRect_s * next
Definition: ui_nodes.h:47
Atomic element to store UI scripts The parser use this atom to translate script action into many tree...
Definition: ui_actions.h:144
void set(vec2_t pos, vec2_t size)
Definition: ui_nodes.h:59
struct uiKeyBinding_s * key
Definition: ui_nodes.h:100
LUA_EVENT lua_onWheel
Definition: ui_nodes.h:153
char * text
Definition: ui_nodes.h:121
int deleteTime
Definition: ui_nodes.h:113
void UI_InitNodes(void)
Definition: ui_nodes.cpp:658
vec_t vec4_t[4]
Definition: ufotypes.h:40
vec2_t pos
Definition: ui_nodes.h:51
LUA_EVENT lua_onDragDropFinished
Definition: ui_nodes.h:175