zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bootstrap.cpp
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2  * Copyleft (C) 2011 Mitchell Keith Bloch (bazald).
3  *
4  * This source file is simply under the public domain.
5  */
6 
7 #include <zenilib.h>
8 
9 #if defined(_DEBUG) && defined(_WINDOWS)
10 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
11 #define new DEBUG_NEW
12 #endif
13 
14 using namespace std;
15 using namespace Zeni;
16 
17 class Play_State : public Gamestate_Base {
18  Play_State(const Play_State &);
19  Play_State operator=(const Play_State &);
20 
21 public:
22  Play_State() {
23  set_pausable(true);
24  }
25 
26 private:
27  void on_push() {
28  get_Window().set_mouse_state(Window::MOUSE_HIDDEN);
29  }
30 
31  void on_pop() {
33  }
34 
35  void on_cover() {
37  }
38 
39  void on_controller_button(const SDL_ControllerButtonEvent &event) {
40  if(event.button == SDL_CONTROLLER_BUTTON_BACK && event.state == SDL_PRESSED)
42  }
43 };
44 
45 class Instructions_State : public Widget_Gamestate {
46  Instructions_State(const Instructions_State &);
47  Instructions_State operator=(const Instructions_State &);
48 
49 public:
50  Instructions_State()
51  : Widget_Gamestate(make_pair(Point2f(0.0f, 0.0f), Point2f(800.0f, 600.0f)))
52  {
53  }
54 
55 private:
56  void on_key(const SDL_KeyboardEvent &event) {
57  if(event.keysym.sym == SDLK_ESCAPE && event.state == SDL_PRESSED)
58  get_Game().pop_state();
59  }
60 
61  void render() {
63 
64  Zeni::Font &fr = get_Fonts()["title"];
65 
66  fr.render_text(
67 #if defined(_WINDOWS)
68  "ALT+F4"
69 #elif defined(_MACOSX)
70  "Apple+Q"
71 #else
72  "Ctrl+Q"
73 #endif
74  " to Quit",
75  Point2f(400.0f, 300.0f - 0.5f * fr.get_text_height()),
76  get_Colors()["title_text"],
77  ZENI_CENTER);
78  }
79 };
80 
81 class Bootstrap {
82  class Gamestate_One_Initializer : public Gamestate_Zero_Initializer {
83  virtual Gamestate_Base * operator()() {
84  Window::set_title("zenilib Application");
85 
87  get_Video();
88  get_Textures();
89  get_Fonts();
90  get_Sounds();
91 
92  return new Title_State<Play_State, Instructions_State>("Zenipex Library\nApplication");
93  }
94  } m_goi;
95 
96 public:
97  Bootstrap() {
98  g_gzi = &m_goi;
99  }
100 } g_bootstrap;
101 
102 int main(int argc, char **argv) {
103  return zenilib_main(argc, argv);
104 }
Controllers & get_Controllers()
Get access to the singleton.
Definition: Controllers.cpp:59
Sounds & get_Sounds()
Get access to the singleton.
Definition: Sounds.cpp:62
int main(int argc, char **argv)
Definition: bootstrap.cpp:102
Colors & get_Colors()
Get access to the singleton.
Definition: Colors.cpp:51
GLclampf f
Definition: glew.h:3390
Gamestate with some helpers for dealing with Widgets.
Provide a simple title screen for games.
Definition: Title_State.h:40
void reset_vibration_all()
Set vibration for all controllers to &lt;0,0&gt;
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
Gamestate pop_state()
Pop a Gamestate off the stack. Pop the current Gamestate with caution. All members will instantly bec...
Definition: Game.cpp:90
void set_mouse_state(const Mouse_State &mouse_state)
Definition: Window.cpp:478
Game & get_Game()
Get access to the singleton.
Definition: Game.cpp:58
Keyboard button event structure (event.key.*)
Definition: SDL_events.h:176
class Bootstrap g_bootstrap
Font Abstraction.
Definition: Font.h:70
SDL_Keysym keysym
Definition: SDL_events.h:185
Gamestate_Zero_Initializer * g_gzi
Definition: Game.cpp:31
Textures & get_Textures()
Get access to the singleton.
Definition: Textures.cpp:64
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
Game controller button event structure (event.cbutton.*)
Definition: SDL_events.h:358
The base class for all gamestates.
Definition: Gamestate.h:82
SDL_Keycode sym
Definition: SDL_keyboard.h:50
Fonts & get_Fonts()
Get access to the singleton.
Definition: Fonts.cpp:60
int zenilib_main(int argc, char **argv)
Definition: main.cpp:279
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
float get_text_height() const
Get the height of the font. The width is usually half the height, by default.
Definition: Font.hxx:29
#define SDL_PRESSED
Definition: SDL_events.h:50
A 2D Point represented with floats.
Definition: Coordinate.h:98
void push_Popup_Menu_State()
Definition: Game.cpp:547
cl_event event
Definition: glew.h:3556
virtual void render_text(const String &text, const Point2f &position, const Color &color, const JUSTIFY &justify=ZENI_DEFAULT_JUSTIFY) const =0
Render text at screen position (x, y), with justification JUSTIFY.