25 #include "../ui_main.h"
26 #include "../ui_parse.h"
27 #include "../ui_behaviour.h"
28 #include "../ui_render.h"
29 #include "../ui_actions.h"
30 #include "../ui_input.h"
31 #include "../ui_sprite.h"
32 #include "../ui_lua.h"
36 #include "../../../common/scripts.h"
37 #include "../../input/cl_keys.h"
39 #include "../../../common/scripts_lua.h"
41 #define EXTRADATA_TYPE panelExtraData_t
42 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
43 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
85 newSize[1] = child->
box.
size[1];
88 child->
box.
pos[1] = positionY;
89 positionY += child->
box.
size[1] + margin;
100 if (
EXTRADATA(node).super.onViewChange) {
103 else if (
EXTRADATA(node).super.lua_onViewChange != LUA_NOREF) {
129 newSize[0] = child->
box.
size[0];
131 child->
box.
pos[0] = positionX;
133 positionX += child->
box.
size[0] + margin;
164 newSize[0] = maxX - minX;
165 newSize[1] = child->
box.
size[1];
169 minY += child->
box.
size[1] + margin;
178 newSize[0] = maxX - minX;
179 newSize[1] = child->
box.
size[1];
183 maxY -= child->
box.
size[1] + margin;
192 newSize[0] = child->
box.
size[0];
193 newSize[1] = maxY - minY;
197 minX += child->
box.
size[0] + margin;
206 newSize[0] = child->
box.
size[0];
207 newSize[1] = maxY - minY;
211 maxX -= child->
box.
size[0] + margin;
220 newSize[0] = maxX - minX;
221 newSize[1] = maxY - minY;
250 switch (child->align) {
252 newSize[0] = maxX - minX;
253 newSize[1] = child->box.size[1];
255 child->box.pos[0] = minX;
256 child->box.pos[1] = minY;
257 minY += child->box.size[1] + margin;
260 newSize[0] = maxX - minX;
261 newSize[1] = child->box.size[1];
263 child->box.pos[0] = minX;
264 child->box.pos[1] = maxY - child->box.size[1];
265 maxY -= child->box.size[1] + margin;
268 newSize[0] = child->box.size[0];
269 newSize[1] = maxY - minY;
271 child->box.pos[0] = minX;
272 child->box.pos[1] = minY;
273 minX += child->box.size[0] + margin;
276 newSize[0] = child->box.size[0];
277 newSize[1] = maxY - minY;
279 child->box.pos[0] = maxX - child->box.size[0];
280 child->box.pos[1] = minY;
281 maxX -= child->box.size[0] + margin;
284 newSize[0] = maxX - minX;
285 newSize[1] = maxY - minY;
287 child->box.pos[0] = minX;
288 child->box.pos[1] = minY;
311 child->box.pos[0] = 0;
312 child->box.pos[1] = 0;
323 child->box.pos[0] += destination[0] - source[0];
324 child->box.pos[1] += destination[1] - source[1];
338 value = child->box.pos[0] + child->box.size[0];
341 value = child->box.pos[1] + child->box.size[1];
349 bool updated =
EXTRADATA(node).super.scrollX.set(-1, node->
box.
size[0], width);
350 updated =
EXTRADATA(node).super.scrollY.set(-1, node->
box.
size[1], height) || updated;
352 if (
EXTRADATA(node).super.onViewChange) {
355 else if (
EXTRADATA(node).super.lua_onViewChange != LUA_NOREF) {
375 if (
EXTRADATA(node).layoutColumns <= 0) {
376 Com_Printf(
"UI_ColumnLayout: Column number must be positive (%s). Layout ignored.",
UI_GetPath(node));
385 for (i = 0; i <
EXTRADATA(node).layoutColumns; i++) {
386 if (child ==
nullptr)
389 if (child->
box.
size[1] > rowHeight) {
390 rowHeight = child->
box.
size[1];
397 for (i = 1; i <
EXTRADATA(node).layoutColumns; i++) {
398 columnPos[
i] = columnPos[i - 1] + columnSize[i - 1] +
EXTRADATA(node).layoutMargin;
405 const int column = i %
EXTRADATA(node).layoutColumns;
410 y += rowHeight +
EXTRADATA(node).layoutMargin;
413 child->
box.
pos[0] = columnPos[column];
422 const int column =
EXTRADATA(node).layoutColumns;
423 int width = columnPos[column - 1] + columnSize[column - 1] + node->
padding;
424 int height = y + rowHeight + node->
padding;
428 updated =
EXTRADATA(node).super.scrollY.set(-1, node->
box.
size[1], height) || updated;
430 if (
EXTRADATA(node).super.onViewChange) {
433 else if (
EXTRADATA(node).super.lua_onViewChange != LUA_NOREF) {
495 bool hasSomethingToScroll =
EXTRADATA(node).super.scrollX.fullSize >
EXTRADATA(node).super.scrollX.viewSize
545 if (propertyPadding ==
nullptr) {
549 if (property == propertyLayoutColumns ||property == propertyLayoutMargin || property == propertyPadding) {
567 if (!
EXTRADATA(node).wheelScrollable || deltaY == 0)
570 updated =
EXTRADATA(node).super.scrollX.moveDelta(deltaX * 50);
571 updated |=
EXTRADATA(node).super.scrollY.moveDelta(deltaY * 50);
573 if (
EXTRADATA(node).super.onViewChange) {
576 else if (
EXTRADATA(node).super.lua_onViewChange != LUA_NOREF) {
604 localBehaviour = behaviour;
605 behaviour->
extends =
"abstractscrollable";
606 behaviour->
name =
"panel";
struct uiAction_s * onWheelDown
void onPropertyChanged(uiNode_t *node, const value_t *property) override
#define Mem_AllocTypeN(type, n)
void draw(uiNode_t *node) override
Handles Button draw.
static void UI_ClientLayout(uiNode_t *node)
void doLayout(uiNode_t *node) override
Call to update the node layout. This common code revalidates the node tree.
void UI_Invalidate(uiNode_t *node)
Invalidate a node and all his parent to request a layout update.
uiBehaviour_t * behaviour
static const value_t * propertyLayoutMargin
static const uiBehaviour_t * localBehaviour
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
void UI_DrawSpriteInBox(bool flip, const uiSprite_t *sprite, uiSpriteStatus_t status, int posX, int posY, int sizeX, int sizeY)
void Com_Printf(const char *const fmt,...)
virtual void onLoading(uiNode_t *node)
bool onMouseLongPress(uiNode_t *node, int x, int y, int button) override
Send mouse event when a pressed mouse button is dragged.
const value_t * UI_GetPropertyFromBehaviour(const uiBehaviour_t *behaviour, const char *name)
Get a property from a behaviour or his inheritance It use a dichotomic search.
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
void onLoaded(uiNode_t *node) override
Handled after the end of the load of the node from script (all data and/or child are set) ...
bool onScroll(uiNode_t *node, int deltaX, int deltaY) override
Handle mouse wheel scrolling.
bool UI_Node_IsDrawable(uiNode_t const *node)
struct uiAction_s * onWheelUp
void onLoading(uiNode_t *node) override
Handled after the end of the load of the node from script (all data and/or child are set) ...
#define EXTRADATACONST(node)
void onCapturedMouseMove(uiNode_t *node, int x, int y) override
void onMouseUp(uiNode_t *node, int x, int y, int button) override
SharedPtr< uiNode > UINodePtr
const char * UI_GetPath(const uiNode_t *node)
Return a path from a window to a node.
static void UI_PackLayout(uiNode_t *node, int margin)
Create a pack layout with child of the node. Set position and size of nodes one by one...
static const value_t * propertyPadding
#define UI_EXTRADATA(NODE, TYPE)
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
void UI_NodeGetPoint(const uiNode_t *node, vec2_t pos, int direction)
return a relative position of a point into a node.
bool onStartDragging(uiNode_t *node, int startX, int startY, int currentX, int currentY, int button) override
Send mouse event when a pressed mouse button is dragged.
Atomic structure used to define most of the UI.
static const value_t * propertyLayoutColumns
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 Com_RegisterConstInt(const char *name, int value)
Register mappings between script strings and enum values for values of the type V_INT.
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
void UI_RegisterPanelNode(uiBehaviour_t *behaviour)
#define Vector2FromInt(x, y)
static void UI_TopDownFlowLayout(uiNode_t *node, int margin)
Create a top-down flow layout with child of the node. Child position is automatically set...
node behaviour, how a node work
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
struct uiAction_s * onWheel
virtual void onPropertyChanged(uiNode_t *node, const value_t *property)
static void UI_LeftRightFlowLayout(uiNode_t *node, int margin)
Create a left-right flow layout with child of the node. Child position is automatically set...
void UI_Node_DoLayout(uiNode_t *node)
void getClientPosition(uiNode_t const *node, vec2_t position) override
static void UI_ColumnLayout(uiNode_t *node)
Do column layout. A grid layout according to a fixed number of column. Check to first row to see the ...
uiSprite_t * UI_GetSpriteByName(const char *name)
Return an sprite by is name.
virtual void doLayout(uiNode_t *node)
Call to update the node layout. This common code revalidates the node tree.
void UI_StarLayout(uiNode_t *node)
Do a star layout with child according to there num.
void UI_NodeSetSize(uiNode_t *node, vec2_t size)
Update the node size and fire the size callback.
void UI_Panel_SetBackgroundByName(uiNode_t *node, const char *name)
void UI_NodeRelativeToAbsolutePoint(const uiNode_t *node, vec2_t pos)
Update a relative point to an absolute one.
static void UI_BorderLayout(uiNode_t *node, int margin)
Create a border layout with child of the node. Child with BORDERLAYOUT_TOP and BORDERLAYOUT_BOTTOM nu...