1 /** 2 * @file 3 */ 4 5 /* 6 Copyright (C) 2002-2013 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 30 /* prototype */ 31 struct uiSprite_t; 32 struct value_s; 33 struct nodeKeyBinding_s; 34 struct uiCallContext_s; 35 struct uiModel_s; 36 struct uiBehaviour_t; 37 38 typedef struct uiExcludeRect_s { 39 /** position of the exclude rect relative to node position */ 40 vec2_t pos; 41 /** size of the exclude rect */ 42 vec2_t size; 43 /** next exclude rect used by the node */ 44 struct uiExcludeRect_s* next; 45 } uiExcludeRect_t; 46 47 struct uiBox_t { 48 vec2_t pos; 49 vec2_t size; 50 clearuiBox_t51 void clear() { 52 Vector2Clear(pos); 53 Vector2Clear(size); 54 } 55 setuiBox_t56 void set(vec2_t pos, vec2_t size) { 57 Vector2Copy(pos, this->pos); 58 Vector2Copy(size, this->size); 59 } 60 expanduiBox_t61 void expand(int dist) { 62 pos[0] -= dist; 63 pos[1] -= dist; 64 size[0] += 2 * dist; 65 size[1] += 2 * dist; 66 } 67 68 /** 69 * Align an inner box to this box. 70 */ 71 void alignBox(uiBox_t& inner, align_t direction); 72 }; 73 74 /** 75 * @brief Atomic structure used to define most of the UI 76 */ 77 struct uiNode_t { 78 /* common identification */ 79 char name[MAX_VAR]; /**< name from the script files */ 80 uiBehaviour_t* behaviour; 81 uiNode_t const* super; /**< Node inherited, else nullptr */ 82 bool dynamic; /** If true, it use dynamic memory */ 83 bool indexed; /** If true, the node name indexed into his window */ 84 85 /* common navigation */ 86 uiNode_t* firstChild; /**< first element of linked list of child */ 87 uiNode_t* lastChild; /**< last element of linked list of child */ 88 uiNode_t* next; /**< Next element into linked list */ 89 uiNode_t* parent; /**< Parent window, else nullptr */ 90 uiNode_t* root; /**< Shortcut to the root node */ 91 92 /* common pos */ 93 uiBox_t box; 94 95 /* common attributes */ 96 const char* tooltip; /**< holds the tooltip */ 97 struct uiKeyBinding_s* key; /**< key bindings - used as tooltip */ 98 bool invis; /**< true if the node is invisible */ 99 bool disabled; /**< true if the node is inactive */ 100 bool invalidated; /**< true if we need to update the layout */ 101 bool ghost; /**< true if the node is not tangible */ 102 bool state; /**< is node hovered */ 103 bool flash; /**< is node flashing */ 104 float flashSpeed; /**< speed of the flashing effect */ 105 int padding; /**< padding for this node - default 3 - see bgcolor */ 106 int align; /**< used to identify node position into a parent using a layout manager. Else it do nothing. */ 107 int num; /**< used to identify child into a parent; not sure it is need @todo delete it */ 108 struct uiAction_s* visibilityCondition; /**< cvar condition to display/hide the node */ 109 int deleteTime; /**< delayed delete time */ 110 111 /** linked list of exclude rect, which exclude node zone for hover or click functions */ 112 uiExcludeRect_t* firstExcludeRect; 113 114 /* other attributes */ 115 /** @todo needs cleanup */ 116 int contentAlign; /**< Content alignment inside nodes */ 117 char* text; /**< Text we want to display */ 118 const char* font; /**< Font to draw text */ 119 const char* image; 120 int border; /**< border for this node - thickness in pixel - default 0 - also see bgcolor */ 121 vec4_t bgcolor; /**< rgba */ 122 vec4_t bordercolor; /**< rgba - see border and padding */ 123 vec4_t color; /**< rgba */ 124 vec4_t selectedColor; /**< rgba The color to draw the line specified by textLineSelected in. */ 125 vec4_t flashColor; /**< rgbx The color of the flashing effect. */ 126 127 /* common events */ 128 struct uiAction_s* onClick; 129 struct uiAction_s* onRightClick; 130 struct uiAction_s* onMiddleClick; 131 struct uiAction_s* onWheel; 132 struct uiAction_s* onMouseEnter; 133 struct uiAction_s* onMouseLeave; 134 struct uiAction_s* onWheelUp; 135 struct uiAction_s* onWheelDown; 136 struct uiAction_s* onChange; /**< called when the widget change from an user action */ 137 }; 138 139 140 /** 141 * @brief Return extradata structure from a node 142 * @param TYPE Extradata type 143 * @param NODE Pointer to the node 144 */ 145 #define UI_EXTRADATA_POINTER(NODE, TYPE) ((TYPE*)((char*)NODE + sizeof(uiNode_t))) 146 #define UI_EXTRADATA(NODE, TYPE) (*UI_EXTRADATA_POINTER(NODE, TYPE)) 147 #define UI_EXTRADATACONST_POINTER(NODE, TYPE) ((TYPE*)((const char*)NODE + sizeof(uiNode_t))) 148 #define UI_EXTRADATACONST(NODE, TYPE) (*UI_EXTRADATACONST_POINTER(NODE, const TYPE)) 149 150 /* module initialization */ 151 void UI_InitNodes(void); 152 153 /* nodes */ 154 uiNode_t* UI_AllocNode(const char* name, const char* type, bool isDynamic); 155 uiNode_t* UI_GetNodeByPath(const char* path) __attribute__ ((warn_unused_result)); 156 void UI_ReadNodePath(const char* path, const uiNode_t* relativeNode, uiNode_t** resultNode, const value_t** resultProperty); 157 uiNode_t* UI_GetNodeAtPosition(int x, int y) __attribute__ ((warn_unused_result)); 158 const char* UI_GetPath(const uiNode_t* node) __attribute__ ((warn_unused_result)); 159 uiNode_t* UI_CloneNode(uiNode_t const* node, uiNode_t* newWindow, bool recursive, const char* newName, bool isDynamic) __attribute__ ((warn_unused_result)); 160 bool UI_CheckVisibility(uiNode_t* node); 161 void UI_DeleteAllChild(uiNode_t* node); 162 void UI_DeleteNode(uiNode_t* node); 163 164 /* behaviours */ 165 /* @todo move it to main */ 166 uiBehaviour_t* UI_GetNodeBehaviour(const char* name) __attribute__ ((warn_unused_result)); 167 uiBehaviour_t* UI_GetNodeBehaviourByIndex(int index) __attribute__ ((warn_unused_result)); 168 int UI_GetNodeBehaviourCount(void) __attribute__ ((warn_unused_result)); 169