UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_tbar.cpp
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 #include "../ui_nodes.h"
26 #include "../ui_parse.h"
27 #include "../ui_behaviour.h"
28 #include "../ui_render.h"
29 #include "../ui_actions.h"
30 #include "ui_node_tbar.h"
31 #include "ui_node_abstractvalue.h"
32 #include "ui_node_abstractnode.h"
33 
34 #include "../../../common/scripts_lua.h"
35 
36 #define EXTRADATA_TYPE tbarExtraData_t
37 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
38 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
39 
40 #define TEXTURE_WIDTH 250.0
41 
43 
45 {
46  /* dataImageOrModel is the texture name */
47  float shx;
48  vec2_t nodepos;
49  const char* ref = UI_GetReferenceString(node, EXTRADATA(node).image);
50  float pointWidth;
51  float width;
52  if (Q_strnull(ref))
53  return;
54 
55  UI_GetNodeAbsPos(node, nodepos);
56 
57  pointWidth = TEXTURE_WIDTH / 100.0; /* relative to the texture */
58 
59  {
60  float ps;
61  const float min = getMin(node);
62  const float max = getMax(node);
63  float value = getValue(node);
64  /* clamp the value */
65  if (value > max)
66  value = max;
67  if (value < min)
68  value = min;
69  ps = (value - min) / (max - min) * 100;
70  shx = EXTRADATA(node).texl[0]; /* left gap to the texture */
71  shx += round(ps * pointWidth); /* add size from 0..TEXTURE_WIDTH */
72  }
73 
74  width = (shx * node->box.size[0]) / TEXTURE_WIDTH;
75 
76  UI_DrawNormImageByName(false, nodepos[0], nodepos[1], width, node->box.size[1],
77  shx, EXTRADATA(node).texh[1], EXTRADATA(node).texl[0], EXTRADATA(node).texl[1], ref);
78 }
79 
80 void UI_TBar_SetImage(uiNode_t* node, const char* name) {
82  node->image = Mem_PoolStrDup(name, ui_dynStringPool, 0);
83 }
84 
86 {
87  behaviour->name = "tbar";
88  behaviour->extends = "abstractvalue";
89  behaviour->manager = UINodePtr(new uiTBarNode());
90  behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
91  behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiTBarNode_t *");
92 
93  /* Image to use. Each behaviour use it like they want.
94  * @todo use V_REF_OF_STRING when its possible ('image' is never a cvar)
95  */
97 
98  /* @todo Need documentation */
99  UI_RegisterExtradataNodeProperty(behaviour, "texh", V_POS, EXTRADATA_TYPE, texh);
100  /* @todo Need documentation */
101  UI_RegisterExtradataNodeProperty(behaviour, "texl", V_POS, EXTRADATA_TYPE, texl);
102 }
bool Q_strnull(const char *string)
Definition: shared.h:138
vec2_t size
Definition: ui_nodes.h:52
float getMin(uiNode_t const *node)
const char * name
Definition: ui_behaviour.h:41
memPool_t * ui_dynStringPool
Definition: ui_main.cpp:40
UINodePtr manager
Definition: ui_behaviour.h:43
Define common thing for GUI controls which allow to edit a value (scroolbar, spinner, and more)
void UI_FreeStringProperty(void *pointer)
Free a string property if it is allocated into ui_dynStringPool.
Definition: ui_actions.cpp:778
void UI_RegisterTBarNode(uiBehaviour_t *behaviour)
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
Definition: ui_behaviour.h:109
#define EXTRADATA_TYPE
float getMax(uiNode_t const *node)
const image_t * UI_DrawNormImageByName(bool flip, float x, float y, float w, float h, float sh, float th, float sl, float tl, const char *name)
Draws an image or parts of it.
Definition: ui_render.cpp:203
void draw(uiNode_t *node) override
#define TEXTURE_WIDTH
SharedPtr< uiNode > UINodePtr
void * lua_SWIG_typeinfo
Definition: ui_behaviour.h:57
const char * UI_GetReferenceString(const uiNode_t *const node, const char *ref)
Definition: ui_parse.cpp:1406
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
Definition: ui_node.cpp:514
intptr_t extraDataSize
Definition: ui_behaviour.h:54
#define EXTRADATA(node)
node behaviour, how a node work
Definition: ui_behaviour.h:39
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
Definition: r_gl.h:110
void UI_TBar_SetImage(uiNode_t *node, const char *name)
const char * extends
Definition: ui_behaviour.h:42
vec_t vec2_t[2]
Definition: ufotypes.h:38
char * image
Definition: ui_nodes.h:123
#define V_CVAR_OR_STRING
Definition: ui_parse.h:69
#define Mem_PoolStrDup(in, pool, tagNum)
Definition: mem.h:50
uiBox_t box
Definition: ui_nodes.h:96
float getValue(uiNode_t const *node)
Definition: scripts.h:55