zenilib: zenilib/jni/application/bootstrap.cpp Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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() {
32 get_Controllers().reset_vibration_all();
33 }
34
35 void on_cover() {
36 get_Controllers().reset_vibration_all();
37 }
38
39 void on_controller_button(const SDL_ControllerButtonEvent &event) {
40 if(event.button == SDL_CONTROLLER_BUTTON_BACK && event.state == SDL_PRESSED)
41 get_Game().push_Popup_Menu_State();
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() {
62 Widget_Gamestate::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
86 get_Controllers();
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 }
Zeni::get_Controllers
Controllers & get_Controllers()
Get access to the singleton.
Definition: Controllers.cpp:59
Zeni::get_Sounds
Sounds & get_Sounds()
Get access to the singleton.
Definition: Sounds.cpp:62
main
int main(int argc, char **argv)
Definition: bootstrap.cpp:102
SDL_CONTROLLER_BUTTON_BACK
Definition: SDL_gamecontroller.h:244
Zeni::get_Colors
Colors & get_Colors()
Get access to the singleton.
Definition: Colors.cpp:51
f
GLclampf f
Definition: glew.h:3390
Zeni::Widget_Gamestate
Gamestate with some helpers for dealing with Widgets.
Definition: Widget_Gamestate.h:38
Zeni::Title_State
Provide a simple title screen for games.
Definition: Title_State.h:40
Zeni::Controllers::reset_vibration_all
void reset_vibration_all()
Set vibration for all controllers to &lt;0,0&gt;
Definition: Controllers.cpp:204
Zeni::render
static void render(const Vertex_Buffer_Macrorenderer &macrorenderer, std::vector< Vertex_Buffer::Vertex_Buffer_Range * > &descriptors)
Definition: Vertex_Buffer.cpp:581
zenilib.h
Zeni::Game::pop_state
Gamestate pop_state()
Pop a Gamestate off the stack. Pop the current Gamestate with caution. All members will instantly bec...
Definition: Game.cpp:90
SDL_KeyboardEvent::state
Uint8 state
Definition: SDL_events.h:181
Zeni::Window::set_mouse_state
void set_mouse_state(const Mouse_State &mouse_state)
Definition: Window.cpp:478
SDL_ControllerButtonEvent::state
Uint8 state
Definition: SDL_events.h:364
Zeni::get_Game
Game & get_Game()
Get access to the singleton.
Definition: Game.cpp:58
Zeni::ZENI_CENTER
Definition: Font.h:68
SDLK_ESCAPE
Definition: SDL_keycode.h:52
SDL_KeyboardEvent
Keyboard button event structure (event.key.*)
Definition: SDL_events.h:176
g_bootstrap
class Bootstrap g_bootstrap
Zeni::Font
Font Abstraction.
Definition: Font.h:70
SDL_KeyboardEvent::keysym
SDL_Keysym keysym
Definition: SDL_events.h:185
Zeni::g_gzi
Gamestate_Zero_Initializer * g_gzi
Definition: Game.cpp:31
Zeni::get_Textures
Textures & get_Textures()
Get access to the singleton.
Definition: Textures.cpp:64
Zeni::get_Window
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
SDL_ControllerButtonEvent::button
Uint8 button
Definition: SDL_events.h:363
SDL_ControllerButtonEvent
Game controller button event structure (event.cbutton.*)
Definition: SDL_events.h:358
Zeni::Gamestate_Base
The base class for all gamestates.
Definition: Gamestate.h:82
SDL_Keysym::sym
SDL_Keycode sym
Definition: SDL_keyboard.h:50
Zeni::get_Fonts
Fonts & get_Fonts()
Get access to the singleton.
Definition: Fonts.cpp:60
zenilib_main
int zenilib_main(int argc, char **argv)
Definition: main.cpp:279
Zeni::get_Video
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
Zeni::Font::get_text_height
float get_text_height() const
Get the height of the font. The width is usually half the height, by default.
Definition: Font.hxx:29
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
Zeni::Point2f
A 2D Point represented with floats.
Definition: Coordinate.h:98
Zeni::Game::push_Popup_Menu_State
void push_Popup_Menu_State()
Definition: Game.cpp:547
Zeni::Gamestate_Zero_Initializer
Definition: Game.h:57
event
cl_event event
Definition: glew.h:3556
Zeni::Font::render_text
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.