Neo  0.5.0
Developer Documentation
Neo2DEngine.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 (C) Yannick Pflanzer <neo-engine.de>
3  *
4  * This file is part of Neo2D.
5  *
6  * Neo2D is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Neo2D is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with Neo2D. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Diese Datei ist Teil von Neo2D.
20  *
21  * Neo2D ist Freie Software: Sie können es unter den Bedingungen
22  * der GNU Lesser General Public License, wie von der Free Software Foundation,
23  * Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
24  * veröffentlichten Version, weiterverbreiten und/oder modifizieren.
25  *
26  * Neo2D wird in der Hoffnung, dass es nützlich sein wird, aber
27  * OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
28  * Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
29  * Siehe die GNU Lesser General Public License für weitere Details.
30  *
31  * Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit
32  *diesem
33  * Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
34  */
35 
36 #ifndef __GUI_SYSTEM__
37 #define __GUI_SYSTEM__
38 
39 #ifdef SWIG
40 #define DISOWN(a) %apply SWIGTYPE* DISOWN {a};
41 #else
42 #define DISOWN(a)
43 #endif
44 
45 #ifdef WIN32
46  #ifdef _MSC_VER
47  #pragma warning(disable: 4251)
48  #endif
49 
50  #if defined(NEO2D_DLL)
51  #define NEO2D_EXPORT __declspec( dllexport )
52  #elif defined(NEO_CORE_STATIC)
53  #define NEO2D_EXPORT
54  #else
55  #define NEO2D_EXPORT __declspec( dllimport )
56  #endif
57 
58 #else
59  #define NEO2D_EXPORT
60 #endif
61 
62 #include <NeoEngine.h>
63 #include <map>
64 #include <Canvas.h>
65 #include <string>
66 
67 namespace Neo2D
68 {
69 
70 using namespace Neo;
71 
77 class NEO2D_EXPORT Neo2DEngine
78 {
79 private:
80  struct WidgetId
81  {
82  Widget* w;
83  int id;
84  };
85 
86  bool m_enabled;
87  int m_ids;
88 
89  std::vector<Canvas*> m_canvasVector;
90  std::map<int, WidgetId> m_widgets;
91  std::string m_defaultFont;
92  float m_defaultFontSize;
93 
94  Vector4 m_normalBackground;
95  Vector4 m_hoverBackground;
96  Vector4 m_highlightBackground;
97 
98  bool m_clearScheduled;
99 
100  String m_themeBorderH;
101  String m_themeBorderV;
102  String m_themeBody;
103  String m_themeEdge;
104 
105  String m_themeBorderHHover;
106  String m_themeBorderVHover;
107  String m_themeBodyHover;
108  String m_themeEdgeHover;
109 
110  String m_themeBorderHPressed;
111  String m_themeBorderVPressed;
112  String m_themeBodyPressed;
113  String m_themeEdgePressed;
114 
115  String m_themeDirectory;
116 
117  DataManager m_fontManager;
118  DataManager m_textureManager;
119 
120 public:
121  Neo2DEngine();
122  ~Neo2DEngine();
123 
124  FontRef* loadFont(const char * filename, unsigned int fontsize);
125  TextureRef* loadTexture(const char * filename, const bool mipmap = true, const bool preload = true);
126 
127  const char* getThemeDirectory() { return m_themeDirectory.getSafeString(); }
128 
129  const char* getThemeBorderH() { return m_themeBorderH.getSafeString(); }
130  const char* getThemeBorderV() { return m_themeBorderV.getSafeString(); }
131  const char* getThemeBody() { return m_themeBody.getSafeString(); }
132  const char* getThemeEdge() { return m_themeEdge.getSafeString(); }
133 
134  const char* getThemeBorderHHover() { return m_themeBorderHHover.getSafeString(); }
135  const char* getThemeBorderVHover() { return m_themeBorderVHover.getSafeString(); }
136  const char* getThemeBodyHover() { return m_themeBodyHover.getSafeString(); }
137  const char* getThemeEdgeHover() { return m_themeEdgeHover.getSafeString(); }
138 
139 
140  const char* getThemeBorderHPressed() { return m_themeBorderHPressed.getSafeString(); }
141  const char* getThemeBorderVPressed() { return m_themeBorderVPressed.getSafeString(); }
142  const char* getThemeBodyPressed() { return m_themeBodyPressed.getSafeString(); }
143  const char* getThemeEdgePressed() { return m_themeEdgePressed.getSafeString(); }
144 
158  void setThemeDirectory(const char* dir);
159 
164  static Neo2DEngine* getInstance();
165 
171  void setupLuaInterface(ScriptContext* script);
172 
177  void setEnabled(bool enabled) { m_enabled = enabled; }
178 
182  void draw();
183 
187  void update();
188 
193  const char* getDefaultFont() { return m_defaultFont.c_str(); }
194 
199  float getDefaultFontSize() { return m_defaultFontSize; }
200 
205  void setDefaultFontSize(float s) { m_defaultFontSize = s; }
206 
211  Vector4 getNormalBackground() { return m_normalBackground; }
212 
217  Vector4 getHoverBackground() { return m_hoverBackground; }
218 
223  Vector4 getHighlightBackground() { return m_highlightBackground; }
224 
229  void setNormalBackground(Vector4 color) { m_normalBackground = color; }
230 
235  void setHoverBackground(Vector4 color) { m_hoverBackground = color; }
236 
242  {
243  m_highlightBackground = color;
244  }
245 
252  Widget* getWidget(unsigned int idx);
253 
260  DISOWN(Widget* w) int addWidget(Widget* w);
261 
266  size_t getNumWidgets() { return m_widgets.size(); }
267 
272  DISOWN(Canvas* c) void addCanvas(Canvas* c);
273 
279  Canvas* getCanvas(unsigned int i) { return m_canvasVector[i]; }
280 
285  void updateLayers();
286 
291  void destroyWidget(int id);
292 
296  void clear();
297  void scheduleClear() { m_clearScheduled = true; }
298 
299  bool isMouseOnGui();
300 };
301 }
302 
303 #endif
const char * getThemeBorderH()
Definition: Neo2DEngine.h:129
Definition: Vector4.h:31
Definition: DataManager.h:72
void setNormalBackground(Vector4 color)
Changes the normal background color.
Definition: Neo2DEngine.h:229
void setEnabled(bool enabled)
Enables or disables the GUI.
Definition: Neo2DEngine.h:177
The Canvas class contains all widgets and renders them.
Definition: Canvas.h:109
const char * getThemeEdge()
Definition: Neo2DEngine.h:132
Definition: FontRef.h:32
const char * getThemeEdgeHover()
Definition: Neo2DEngine.h:137
size_t getNumWidgets()
Returns the number of registered widgets.
Definition: Neo2DEngine.h:266
Vector4 getNormalBackground()
Returns the normal background color.
Definition: Neo2DEngine.h:211
const char * getDefaultFont()
Returns the default font.
Definition: Neo2DEngine.h:193
Implements a framework for string manipulation that operates directly on C strings.
Definition: NeoString.h:35
const char * getThemeBorderVPressed()
Definition: Neo2DEngine.h:141
The Widget class contains all information that is common to all GUI widgets.
Definition: Widget.h:72
float getDefaultFontSize()
Returns the default font size.
Definition: Neo2DEngine.h:199
const char * getThemeBody()
Definition: Neo2DEngine.h:131
void setHoverBackground(Vector4 color)
Changes the hover background color.
Definition: Neo2DEngine.h:235
The Neo2DEngine class contains all functionality to set up a GUI.
Definition: Neo2DEngine.h:77
Vector4 getHighlightBackground()
Returns the highlight color.
Definition: Neo2DEngine.h:223
const char * getThemeBodyHover()
Definition: Neo2DEngine.h:136
Definition: Button.h:42
const char * getSafeString(void)
Returns the C string. This method is ensured to return a valid C string and never NULL...
const char * getThemeBorderHPressed()
Definition: Neo2DEngine.h:140
Definition: TextureRef.h:32
const char * getThemeBorderV()
Definition: Neo2DEngine.h:130
Canvas * getCanvas(unsigned int i)
Returns the Canvas with the given index.
Definition: Neo2DEngine.h:279
void setDefaultFontSize(float s)
Changes the default font size.
Definition: Neo2DEngine.h:205
const char * getThemeBorderHHover()
Definition: Neo2DEngine.h:134
Vector4 getHoverBackground()
Returns the hover background color.
Definition: Neo2DEngine.h:217
const char * getThemeBorderVHover()
Definition: Neo2DEngine.h:135
const char * getThemeDirectory()
Definition: Neo2DEngine.h:127
const char * getThemeBodyPressed()
Definition: Neo2DEngine.h:142
Definition: Color.h:29
Class used to manage script functions virtually.
Definition: ScriptContext.h:32
void scheduleClear()
Definition: Neo2DEngine.h:297
void setHighlightBackground(Vector4 color)
Changes the highlight background color.
Definition: Neo2DEngine.h:241
const char * getThemeEdgePressed()
Definition: Neo2DEngine.h:143