CUGL 1.3
Cornell University Game Library
CULayout.h
1 //
2 // CULayout.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides an abstract class interface for Java-style Layout
6 // managers. This gives us more flexibility for creating scene graphs
7 // on different resolution devices.
8 //
9 //
10 // CUGL MIT License:
11 // This software is provided 'as-is', without any express or implied
12 // warranty. In no event will the authors be held liable for any damages
13 // arising from the use of this software.
14 //
15 // Permission is granted to anyone to use this software for any purpose,
16 // including commercial applications, and to alter it and redistribute it
17 // freely, subject to the following restrictions:
18 //
19 // 1. The origin of this software must not be misrepresented; you must not
20 // claim that you wrote the original software. If you use this software
21 // in a product, an acknowledgment in the product documentation would be
22 // appreciated but is not required.
23 //
24 // 2. Altered source versions must be plainly marked as such, and must not
25 // be misrepresented as being the original software.
26 //
27 // 3. This notice may not be removed or altered from any source distribution.
28 //
29 // Author: Walker White and Enze Zhou
30 // Version: 1/8/18
31 //
32 #ifndef __CU_LAYOUT_H__
33 #define __CU_LAYOUT_H__
34 #include <cugl/2d/CUNode.h>
35 #include <cugl/assets/CUJsonValue.h>
36 
37 namespace cugl {
38 
39 
61 class Layout {
62 #pragma mark -
63 #pragma mark Constructors
64 public:
73  enum class Anchor : int {
75  BOTTOM_LEFT = 0,
77  MIDDLE_LEFT = 1,
79  TOP_LEFT = 2,
81  BOTTOM_CENTER = 3,
83  CENTER = 4,
85  TOP_CENTER = 5,
87  BOTTOM_RIGHT = 6,
89  MIDDLE_RIGHT = 7,
91  TOP_RIGHT = 8,
93  BOTTOM_FILL = 9,
95  MIDDLE_FILL = 10,
97  TOP_FILL = 11,
99  LEFT_FILL = 12,
101  CENTER_FILL = 13,
103  RIGHT_FILL = 14,
105  TOTAL_FILL = 15,
107  NONE = 16
108  };
109 
116  Layout() {}
117 
121  ~Layout() { dispose(); }
122 
128  virtual void dispose() {}
129 
139  virtual bool init() { return true; }
140 
152  virtual bool initWithData(const std::shared_ptr<JsonValue>& data) { return false; }
153 
154 #pragma mark Layout
155 
172  virtual bool add(const std::string key, const std::shared_ptr<JsonValue>& data) { return false; }
173 
188  virtual bool remove(const std::string key) { return false; }
189 
206  virtual void layout(Node* node) {}
207 
208 #pragma mark Layout Helpers
209 
221  static Anchor getAnchor(const std::string& x_anchor, const std::string& y_anchor);
222 
235  static void placeNode(Node* node, Anchor anchor, const Rect& bounds, const Vec2& offset);
236 
248  static void reanchor(Node* node, Anchor anchor);
249 
250 };
251 
252 }
253 #endif /* __CU_LAYOUT_H__ */
cugl::Layout::Anchor::TOP_FILL
cugl::Layout::Anchor::TOP_LEFT
cugl::Layout::Anchor::MIDDLE_LEFT
cugl::Layout
Definition: CULayout.h:61
cugl::Layout::Anchor::BOTTOM_FILL
cugl::Layout::Anchor::CENTER
cugl::Layout::~Layout
~Layout()
Definition: CULayout.h:121
cugl::Rect
Definition: CURect.h:45
cugl::Layout::Anchor::BOTTOM_LEFT
cugl::Layout::Anchor::NONE
cugl::Layout::Anchor::TOP_RIGHT
cugl::Layout::placeNode
static void placeNode(Node *node, Anchor anchor, const Rect &bounds, const Vec2 &offset)
cugl::Layout::Anchor::LEFT_FILL
cugl::Layout::init
virtual bool init()
Definition: CULayout.h:139
cugl::Layout::Anchor::MIDDLE_RIGHT
cugl::Layout::remove
virtual bool remove(const std::string key)
Definition: CULayout.h:188
cugl::Node
Definition: CUNode.h:92
cugl::Layout::Anchor::TOTAL_FILL
cugl::Layout::Anchor::BOTTOM_CENTER
cugl::Vec2
Definition: CUVec2.h:61
cugl::Layout::layout
virtual void layout(Node *node)
Definition: CULayout.h:206
cugl::Layout::initWithData
virtual bool initWithData(const std::shared_ptr< JsonValue > &data)
Definition: CULayout.h:152
cugl::Layout::Anchor::RIGHT_FILL
cugl::Layout::Anchor::TOP_CENTER
cugl::Layout::add
virtual bool add(const std::string key, const std::shared_ptr< JsonValue > &data)
Definition: CULayout.h:172
cugl::Layout::Layout
Layout()
Definition: CULayout.h:116
cugl::Layout::Anchor::BOTTOM_RIGHT
cugl::Layout::dispose
virtual void dispose()
Definition: CULayout.h:128
cugl::Layout::Anchor
Anchor
Definition: CULayout.h:73
cugl::Layout::getAnchor
static Anchor getAnchor(const std::string &x_anchor, const std::string &y_anchor)
cugl::Layout::Anchor::MIDDLE_FILL
cugl::Layout::Anchor::CENTER_FILL
cugl::Layout::reanchor
static void reanchor(Node *node, Anchor anchor)