1 /**
2  * @file
3  */
4 
5 /*
6 Copyright (C) 2002-2013 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 #pragma once
26 
27 #include "ui_node_abstractscrollable.h"
28 
29 class uiPanelNode : public uiAbstractScrollableNode {
30 	void draw(uiNode_t* node) override;
31 	void onLoaded(uiNode_t* node) override;
32 	void onLoading(uiNode_t* node) override;
33 	void doLayout(uiNode_t* node) override;
34 	void getClientPosition(uiNode_t const* node, vec2_t position) override;
35 	void onPropertyChanged(uiNode_t* node, const value_t* property) override;
36 	bool onScroll(uiNode_t* node, int deltaX, int deltaY) override;
37 	void onMouseUp(uiNode_t* node, int x, int y, int button) override;
38 	bool onMouseLongPress(uiNode_t* node, int x, int y, int button) override;
39 	bool onStartDragging(uiNode_t* node, int startX, int startY, int currentX, int currentY, int button) override;
40 	void onCapturedMouseMove(uiNode_t* node, int x, int y) override;
41 };
42 
43 struct uiBehaviour_t;
44 
45 typedef enum {
46 	LAYOUT_NONE,
47 	LAYOUT_TOP_DOWN_FLOW,
48 	LAYOUT_LEFT_RIGHT_FLOW,
49 	LAYOUT_BORDER,
50 	LAYOUT_PACK,
51 	LAYOUT_STAR,
52 	LAYOUT_CLIENT,
53 	LAYOUT_COLUMN,
54 
55 	LAYOUT_MAX,
56 	LAYOUT_ENSURE_32BIT = 0x7FFFFFFF
57 } panelLayout_t;
58 
59 typedef enum {
60 	LAYOUTALIGN_NONE = 0,
61 
62 	/* vertical and horizontal flag bits */
63 	LAYOUTALIGN_H_MASK    = 0x03,
64 	LAYOUTALIGN_H_LEFT    = 0x01,
65 	LAYOUTALIGN_H_MIDDLE  = 0x02,
66 	LAYOUTALIGN_H_RIGHT   = 0x03,
67 	LAYOUTALIGN_V_MASK    = 0x0C,
68 	LAYOUTALIGN_V_TOP     = 0x04,
69 	LAYOUTALIGN_V_MIDDLE  = 0x08,
70 	LAYOUTALIGN_V_BOTTOM  = 0x0C,
71 
72 	/* common alignment */
73 	LAYOUTALIGN_TOPLEFT     = (LAYOUTALIGN_V_TOP | LAYOUTALIGN_H_LEFT),
74 	LAYOUTALIGN_TOP         = (LAYOUTALIGN_V_TOP | LAYOUTALIGN_H_MIDDLE),
75 	LAYOUTALIGN_TOPRIGHT    = (LAYOUTALIGN_V_TOP | LAYOUTALIGN_H_RIGHT),
76 	LAYOUTALIGN_LEFT        = (LAYOUTALIGN_V_MIDDLE | LAYOUTALIGN_H_LEFT),
77 	LAYOUTALIGN_MIDDLE      = (LAYOUTALIGN_V_MIDDLE | LAYOUTALIGN_H_MIDDLE),
78 	LAYOUTALIGN_RIGHT       = (LAYOUTALIGN_V_MIDDLE | LAYOUTALIGN_H_RIGHT),
79 	LAYOUTALIGN_BOTTOMLEFT  = (LAYOUTALIGN_V_BOTTOM | LAYOUTALIGN_H_LEFT),
80 	LAYOUTALIGN_BOTTOM      = (LAYOUTALIGN_V_BOTTOM | LAYOUTALIGN_H_MIDDLE),
81 	LAYOUTALIGN_BOTTOMRIGHT = (LAYOUTALIGN_V_BOTTOM | LAYOUTALIGN_H_RIGHT),
82 
83 	/* special align, everything bigger 0x10 */
84 	LAYOUTALIGN_SPECIAL     = 0x10,
85 
86 	/* pack and star layout manager only */
87 	LAYOUTALIGN_FILL,
88 
89 	LAYOUTALIGN_MAX,
90 	LAYOUTALIGN_ENSURE_32BIT = 0x7FFFFFFF
91 } layoutAlign_t;
92 
93 /**
94  * @param align a layoutAlign_t
95  * @return LAYOUTALIGN_V_TOP, LAYOUTALIGN_V_MIDDLE, LAYOUTALIGN_V_BOTTOM, else LAYOUTALIGN_NONE
96  */
97 #define UI_GET_VERTICAL_ALIGN(align) ((align >= LAYOUTALIGN_SPECIAL)?LAYOUTALIGN_NONE:(LAYOUTALIGN_V_MASK & align))
98 /**
99  * @param align a layoutAlign_t
100  * @return LAYOUTALIGN_H_LEFT, LAYOUTALIGN_H_MIDDLE, LAYOUTALIGN_H_RIGHT, else LAYOUTALIGN_NONE
101  */
102 #define UI_GET_HORIZONTAL_ALIGN(align) ((align >= LAYOUTALIGN_SPECIAL)?LAYOUTALIGN_NONE:(LAYOUTALIGN_H_MASK & align))
103 
104 /**
105  * @brief extradata for the panel node
106  */
107 typedef struct {
108 	abstractScrollableExtraData_t super;
109 	panelLayout_t layout;		/**< The layout manager the panel is using to render all its children */
110 	int layoutMargin;			/**< The margin between all children nodes of the panel */
111 	int layoutColumns;			/**< The number of columns (only used by LAYOUT_COLUMN)  */
112 	bool wheelScrollable;	/**< If scrolling with mouse wheel is enabled */
113 	/** Sprite used as a background */
114 	uiSprite_t* background;
115 } panelExtraData_t;
116 
117 void UI_RegisterPanelNode(uiBehaviour_t* behaviour);
118 void UI_StarLayout(uiNode_t* node);
119