Neo  0.5.0
Developer Documentation
Menu.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 diesem
32  * Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
33  */
34 
35 #ifndef __MENU_H__
36 #define __MENU_H__
37 
38 #include <string>
39 #include <vector>
40 #include <NeoEngine.h>
41 #include <Widget.h>
42 #include <Button.h>
43 
44 #define LINE_HEIGHT 25
45 
46 namespace Neo2D
47 {
48 namespace Gui
49 {
50 
51 using namespace Neo;
52 
58 class NEO2D_EXPORT Menu : public Widget
59 {
60 protected:
61 
64  std::vector<Button> m_entries;
66 
67 public:
68  Menu(unsigned int x, unsigned int y, unsigned int width,
69  unsigned int height, const char* label)
70  : Widget(x, y, width, height, label), m_font("assets/default.ttf"),
71  m_selectedEntry(-1), m_waitingForInit(false)
72  {
73  setVisible(false);
74  }
75 
76  Menu(unsigned int x, unsigned int y)
77  : Menu(x, y, 200, 0, "")
78  {
79  }
80 
81  void show() { m_visible = true; m_waitingForInit = true; }
82  Button* getEntry(unsigned int idx) { return &m_entries[idx]; }
83  void addEntry(Button l);
84 
85  void draw(Vector2 offset);
86  void update();
87 };
88 }
89 }
90 #endif
The Menu class implements a basic drop-down menu.
Definition: Menu.h:58
void show()
Definition: Menu.h:81
int m_selectedEntry
Definition: Menu.h:63
std::vector< Button > m_entries
Definition: Menu.h:64
Implements a framework for string manipulation that operates directly on C strings.
Definition: NeoString.h:35
The Widget class contains all information that is common to all GUI widgets.
Definition: Widget.h:72
Button * getEntry(unsigned int idx)
Definition: Menu.h:82
Implements a simple pushable button that calls the specified callback.
Definition: Button.h:67
bool m_waitingForInit
Definition: Menu.h:62
Menu(unsigned int x, unsigned int y)
Definition: Menu.h:76
String m_font
Definition: Menu.h:65
Menu(unsigned int x, unsigned int y, unsigned int width, unsigned int height, const char *label)
Definition: Menu.h:68
Definition: Vector2.h:31
Definition: Button.h:42
Definition: Color.h:29