UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_texture.cpp
Go to the documentation of this file.
1 
14 /*
15 Copyright (C) 2002-2020 UFO: Alien Invasion.
16 
17 This program is free software; you can redistribute it and/or
18 modify it under the terms of the GNU General Public License
19 as published by the Free Software Foundation; either version 2
20 of the License, or (at your option) any later version.
21 
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 
26 See the GNU General Public License for more details.
27 
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 
32 */
33 
34 #include "../ui_nodes.h"
35 #include "../ui_parse.h"
36 #include "../ui_behaviour.h"
37 #include "../ui_render.h"
38 #include "../../renderer/r_draw.h"
39 #include "ui_node_texture.h"
40 #include "ui_node_abstractnode.h"
41 
42 #include "../../../common/scripts_lua.h"
43 
44 #define EXTRADATA_TYPE 0
45 
51 {
52  vec2_t nodepos;
53  const image_t* image;
54 
55  const char* imageName = UI_GetReferenceString(node, node->image);
56  if (Q_strnull(imageName))
57  return;
58 
59  image = UI_LoadWrappedImage(imageName);
60  if (!image)
61  return;
62 
63  /* avoid potential infinit loop */
64  if (image->height == 0 || image->width == 0)
65  return;
66 
67  UI_GetNodeAbsPos(node, nodepos);
68 
69  UI_DrawNormImage(false, nodepos[0], nodepos[1], node->box.size[0], node->box.size[1], node->box.size[0], node->box.size[1], 0, 0, image);
70 }
71 
73 {
74  behaviour->name = "texture";
75  behaviour->manager = UINodePtr(new uiTextureNode());
76  behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
77  behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiTextureNode_t *");
78 
79  /* Source of the texture */
80  UI_RegisterNodeProperty(behaviour, "src", V_CVAR_OR_STRING, uiNode_t, image);
81 }
bool Q_strnull(const char *string)
Definition: shared.h:138
vec2_t size
Definition: ui_nodes.h:52
#define EXTRADATA_TYPE
const char * name
Definition: ui_behaviour.h:41
UINodePtr manager
Definition: ui_behaviour.h:43
#define UI_RegisterNodeProperty(BEHAVIOUR, NAME, TYPE, OBJECTTYPE, ATTRIBUTE)
Initialize a property.
Definition: ui_behaviour.h:91
int width
Definition: r_image.h:64
SharedPtr< uiNode > UINodePtr
void * lua_SWIG_typeinfo
Definition: ui_behaviour.h:57
void UI_DrawNormImage(bool flip, float x, float y, float w, float h, float sh, float th, float sl, float tl, const image_t *image)
Draw a normalized (to the screen) image.
Definition: ui_render.cpp:126
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
node behaviour, how a node work
Definition: ui_behaviour.h:39
int height
Definition: r_image.h:64
vec_t vec2_t[2]
Definition: ufotypes.h:38
char * image
Definition: ui_nodes.h:123
const struct image_s * UI_LoadWrappedImage(const char *name)
Searches for a wrapped image in the image array.
Definition: ui_render.cpp:106
#define V_CVAR_OR_STRING
Definition: ui_parse.h:69
void draw(uiNode_t *node) override
Draws the texture node.
uiBox_t box
Definition: ui_nodes.h:96
void UI_RegisterTextureNode(uiBehaviour_t *behaviour)