UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_texture.cpp
Go to the documentation of this file.
1
13
14/*
15Copyright (C) 2002-2025 UFO: Alien Invasion.
16
17This program is free software; you can redistribute it and/or
18modify it under the terms of the GNU General Public License
19as published by the Free Software Foundation; either version 2
20of the License, or (at your option) any later version.
21
22This program is distributed in the hope that it will be useful,
23but WITHOUT ANY WARRANTY; without even the implied warranty of
24MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25
26See the GNU General Public License for more details.
27
28You should have received a copy of the GNU General Public License
29along with this program; if not, write to the Free Software
30Foundation, 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"
39#include "ui_node_texture.h"
41
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}
void draw(uiNode_t *node) override
Draws the texture node.
Header for lua script functions.
bool Q_strnull(const char *string)
Definition shared.h:138
int height
Definition r_image.h:64
int width
Definition r_image.h:64
node behaviour, how a node work
const char * name
void * lua_SWIG_typeinfo
UINodePtr manager
intptr_t extraDataSize
vec2_t size
Definition ui_nodes.h:52
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
uiBox_t box
Definition ui_nodes.h:96
char * image
Definition ui_nodes.h:123
vec_t vec2_t[2]
Definition ufotypes.h:38
#define UI_RegisterNodeProperty(BEHAVIOUR, NAME, TYPE, OBJECTTYPE, ATTRIBUTE)
Initialize a property.
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:526
SharedPtr< uiNode > UINodePtr
#define EXTRADATA_TYPE
void UI_RegisterTextureNode(uiBehaviour_t *behaviour)
const char * UI_GetReferenceString(const uiNode_t *const node, const char *ref)
#define V_CVAR_OR_STRING
Definition ui_parse.h:69
const struct image_s * UI_LoadWrappedImage(const char *name)
Searches for a wrapped image in the image array.
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.