Bubba-3D  0.9.0
Awesome game engine!
Layout.h
1 /*
2  * This file is part of Bubba-3D.
3  *
4  * Bubba-3D is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Bubba-3D is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with Bubba-3D. If not, see http://www.gnu.org/licenses/.
16  */
17 #pragma once
18 
19 #include <vector>
20 #include <map>
21 #include <Dimension.h>
22 #include <functional>
23 
24 class Texture;
25 class HUDGraphic;
26 class IHudDrawable;
27 class InsideChecker;
28 class GLSquare;
29 
33 class Layout {
34 
35 public:
36  Layout() = default;
37  virtual ~Layout() = default;
38 
39  enum ListenerType {
40  ON_CLICK_LISTENER,
41  ON_HOVER_LISTENER
42  };
43 
44  typedef std::function<void (int x, int y, Layout* element, bool enteredElseLeaving)> EventFunction;
45 
57  virtual std::map<std::string, IHudDrawable*> getGLSquares(float layoutXPos,float layoutYPos,
58  float layoutWidth, float layoutHeight);
59 
66  virtual Dimension getWidth() = 0;
71  virtual Dimension getHeight() = 0;
72 
84  virtual void getGLSquares(float layoutXPos,float layoutYPos, float layoutWidth,
85  float layoutHeight, std::map<std::string, IHudDrawable*> *map) = 0;
86 
87  virtual HUDGraphic* getGraphic();
88 
92  virtual Layout* setBackground(HUDGraphic *graphic);
93 
99  virtual Layout* setLayoutId(std::string id);
100 
106  virtual Layout* findById(std::string id);
107 
108  virtual void invokeListeners(int x, int y, ListenerType listenerType);
109  virtual void invokeListenersInternal(int x, int y, ListenerType listenerType, bool mayBeHit);
110 
111  virtual Layout* addClickListener(EventFunction eventFunction);
112  virtual Layout* addHoverListener(EventFunction eventFunction);
113 
118  virtual void addChild(Layout* child);
119 
120  virtual void clearChildren();
121  virtual void clearHoverListeners();
122  virtual void clearClickListeners();
123 
124  virtual void callListeners(int x, int y, ListenerType listenerType, bool enteringElseLeaving);
125 
126  virtual void updateGraphic();
127  virtual IHudDrawable* getRenderedBackground();
128 
129 protected:
130  std::vector<Layout*> children;
131  HUDGraphic* graphic = nullptr;
132  std::string id = "";
133  InsideChecker* insideChecker = nullptr;
134 
135  std::vector<EventFunction>* hoverListeners = new std::vector<EventFunction>();
136  std::vector<EventFunction>* clickListeners = new std::vector<EventFunction>();
137  GLSquare* renderedBackground = nullptr;
138 
139  bool hoveredBackground = false;
140  bool mouseWasDown = false;
141 
142  std::string getNextRandId();
143 };
virtual std::map< std::string, IHudDrawable * > getGLSquares(float layoutXPos, float layoutYPos, float layoutWidth, float layoutHeight)
Definition: Layout.cpp:34
virtual Layout * setLayoutId(std::string id)
Definition: Layout.cpp:92
virtual Layout * setBackground(HUDGraphic *graphic)
Definition: Layout.cpp:108
Definition: Layout.h:33