UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_abstractscrollable.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "../ui_main.h"
27#include "../ui_parse.h"
28#include "../ui_behaviour.h"
29#include "../ui_font.h"
30#include "../ui_render.h"
31#include "../ui_actions.h"
32#include "../ui_lua.h"
33
36
37#include "../../client.h" /* gettext _() */
38
40
41#define EXTRADATA_TYPE abstractScrollableExtraData_t
42#define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
43
48{
50
51 if (!Vector2Equal(node->box.size, EXTRADATA(node).cacheSize)) {
52 Vector2Copy(node->box.size, EXTRADATA(node).cacheSize);
53 return true;
54 }
55 return false;
56}
57
64{
65 /* clap position */
66 if (viewPos > this->fullSize - this->viewSize)
67 viewPos = this->fullSize - this->viewSize;
68 if (viewPos < 0)
69 viewPos = 0;
70
71 /* no changes */
72 if (this->viewPos == viewPos) {
73 return false;
74 }
75
76 this->viewPos = viewPos;
77 return true;
78}
79
88{
89 bool updated = false;
90
91 /* default values */
92 if (viewPos == -1)
93 viewPos = this->viewPos;
94 if (viewSize == -1)
95 viewSize = this->viewSize;
96 if (fullSize == -1)
97 fullSize = this->fullSize;
98
99 /* fix limits */
100 if (viewSize < 0)
101 viewSize = 0;
102 if (fullSize < 0)
103 fullSize = 0;
104 if (viewPos < 0)
105 viewPos = 0;
106
107 /* clap position */
108 if (viewSize >= fullSize)
109 viewPos = 0;
110 else if (viewPos > fullSize - viewSize)
112
113 /* update */
114 if (this->viewPos != viewPos) {
115 this->viewPos = viewPos;
116 updated = true;
117 }
118 if (this->viewSize != viewSize) {
119 this->viewSize = viewSize;
120 updated = true;
121 }
122 if (this->fullSize != fullSize) {
123 this->fullSize = fullSize;
124 updated = true;
125 }
126
127 return updated;
128}
129
132 EXTRADATA(node).lua_onViewChange = LUA_NOREF;
133}
134
143bool uiAbstractScrollableNode::setScrollY (uiNode_t* node, int viewPos, int viewSize, int fullSize)
144{
145 bool updated;
146 assert(UI_Node_IsScrollableContainer(node));
147
148 updated = EXTRADATA(node).scrollY.set(viewPos, viewSize, fullSize);
149
150 if (updated) {
151 if (EXTRADATA(node).onViewChange) {
152 UI_ExecuteEventActions(node, EXTRADATA(node).onViewChange);
153 }
154 else if (EXTRADATA(node).lua_onViewChange != LUA_NOREF) {
155 UI_ExecuteLuaEventScript (node, EXTRADATA(node).lua_onViewChange);
156 }
157 }
158
159
160 return updated;
161}
162
164 const int pos = EXTRADATA(node).scrollY.viewPos - 10;
165 setScrollY(node, (pos >= 0)?pos:0, -1, -1);
166}
168 setScrollY(node, EXTRADATA(node).scrollY.viewPos + 10, -1, -1);
169}
171 setScrollY(node, EXTRADATA(node).scrollY.viewPos - 1, -1, -1);
172}
174 setScrollY(node, EXTRADATA(node).scrollY.viewPos + 1, -1, -1);
175}
177 setScrollY(node, 0, -1, -1);
178}
180 setScrollY(node, EXTRADATA(node).scrollY.fullSize, -1, -1);
181}
182
187{
189 b->pageUp(node);
190}
191
193{
195 b->pageDown(node);
196}
197
199{
201 b->moveUp(node);
202}
203
205{
207 b->moveDown (node);
208}
209
211{
213 b->moveHome (node);
214}
215
220{
222 b->moveEnd (node);
223}
224
230{
231 assert(UI_Node_IsScrollableContainer(node));
232 return setScrollY(node, EXTRADATA(node).scrollY.viewPos + offset, -1, -1);
233}
234
236{
237 behaviour->name = "abstractscrollable";
238 behaviour->manager = UINodePtr(new uiAbstractScrollableNode());
239 behaviour->isAbstract = true;
240 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
241 behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiAbstractScrollableNode_t *");
242
243 /* position of the vertical view (into the full number of elements the node contain) */
244 UI_RegisterExtradataNodeProperty(behaviour, "viewpos", V_INT, EXTRADATA_TYPE, scrollY.viewPos);
245 /* size of the vertical view (proportional to the number of elements the node can display without moving) */
246 UI_RegisterExtradataNodeProperty(behaviour, "viewsize", V_INT, EXTRADATA_TYPE, scrollY.viewSize);
247 /* full vertical size (proportional to the number of elements the node contain) */
248 UI_RegisterExtradataNodeProperty(behaviour, "fullsize", V_INT, EXTRADATA_TYPE, scrollY.fullSize);
249 /* Called when one of the properties viewpos/viewsize/fullsize change */
250 UI_RegisterExtradataNodeProperty(behaviour, "onviewchange", V_UI_ACTION, EXTRADATA_TYPE, onViewChange);
251
252 /* Call it to vertically scroll the document up */
254 /* Call it to vertically scroll the document down */
256 /* Call it to vertically scroll the document up */
258 /* Call it to vertically scroll the document down */
260 /* Call it to vertically reset the scroll position to 0 */
262 /* Call it to vertically move the scroll to the end of the document */
264}
PointerType get() const
Definition sharedptr.h:197
bool scrollY(uiNode_t *node, int offset)
Scroll the Y scroll with a relative position, and call event if need.
void initNode(uiNode_t *node) override
bool setScrollY(uiNode_t *node, int viewPos, int viewSize, int fullSize)
Set the Y scroll to a position, and call event if need.
bool isSizeChange(uiNode_t *node)
return true if the node size change and update the cache
virtual void initNode(uiNode_t *node)
Primary header for client.
voidpf uLong offset
Definition ioapi.h:45
@ V_INT
Definition scripts.h:52
Header for lua script functions.
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
Contain the context of the calling of a function.
Definition ui_actions.h:208
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
uiBehaviour_t * behaviour
Definition ui_nodes.h:83
uiBox_t box
Definition ui_nodes.h:96
bool move(int viewPos)
Fix a new position.
bool set(int viewPos, int viewSize, int fullSize)
Set the scroll to a position.
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
const struct value_s * UI_RegisterNodeMethod(uiBehaviour_t *behaviour, const char *name, uiNodeMethod_t function)
Register a node method to a behaviour.
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
Definition ui_lua.cpp:71
Basic lua initialization for the ui.
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
bool UI_Node_IsScrollableContainer(uiNode_t const *node)
Definition ui_node.cpp:93
SharedPtr< uiNode > UINodePtr
#define EXTRADATA_TYPE
#define EXTRADATA(node)
static void UI_AbstractScrollableNodePageUp(uiNode_t *node, const uiCallContext_t *context)
static void UI_AbstractScrollableNodePageDown(uiNode_t *node, const uiCallContext_t *context)
static void UI_AbstractScrollableNodeMoveDown(uiNode_t *node, const uiCallContext_t *context)
static void UI_AbstractScrollableNodeMoveEnd(uiNode_t *node, const uiCallContext_t *context)
static void UI_AbstractScrollableNodeMoveHome(uiNode_t *node, const uiCallContext_t *context)
static void UI_AbstractScrollableNodeMoveUp(uiNode_t *node, const uiCallContext_t *context)
void UI_RegisterAbstractScrollableNode(uiBehaviour_t *behaviour)
base code for scrollable node
#define V_UI_ACTION
Definition ui_parse.h:54
#define Vector2Equal(a, b)
Definition vector.h:67
#define Vector2Copy(src, dest)
Definition vector.h:52