zenilib: zenilib/jni/external/zenilib/zeni_rest/Widget_Gamestate.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
Widget_Gamestate.cpp
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib 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 * zenilib 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 zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <zeni_rest.h>
19
20 namespace Zeni {
21
22 Widget_Gamestate::Widget_Gamestate(const std::pair<Point2f, Point2f> &virtual_window_, const bool &fix_aspect_ratio_)
23 : m_virtual_window(virtual_window_),
24 m_fix_aspect_ratio(fix_aspect_ratio_)
25 {
26 }
27
28 const std::pair<Point2f, Point2f> & Widget_Gamestate::get_virtual_window() const {
29 return m_virtual_window;
30 }
31
32 const bool & Widget_Gamestate::fix_aspect_ratio() const {
33 return m_fix_aspect_ratio;
34 }
35
36 void Widget_Gamestate::on_push() {
37 Window &wr = get_Window();
38
39 m_clear_color = get_Video().get_clear_Color();
40
41 m_controller_mouse = get_Game().controller_mouse.enabled;
42 get_Game().controller_mouse.enabled = true;
43
44 m_mouse_state = wr.get_mouse_state();
45 wr.set_mouse_state(Window::MOUSE_NORMAL);
46 }
47
48 void Widget_Gamestate::on_pop() {
49 get_Video().set_clear_Color(m_clear_color);
50 get_Window().set_mouse_state(m_mouse_state);
51 get_Game().controller_mouse.enabled = m_controller_mouse;
52 }
53
54 #ifndef ANDROID
55 void Widget_Gamestate::on_key(const SDL_KeyboardEvent &event) {
56 m_widgets.on_event(event);
57 if(!m_widgets.is_busy())
58 Gamestate_Base::on_key(event);
59 }
60
61 void Widget_Gamestate::on_mouse_button(const SDL_MouseButtonEvent &event) {
62 m_widgets.on_event(event, m_projector);
63 }
64
65 void Widget_Gamestate::on_mouse_motion(const SDL_MouseMotionEvent &event) {
66 m_widgets.on_event(event, m_projector);
67 }
68
69 #if SDL_VERSION_ATLEAST(2,0,0)
70 void Widget_Gamestate::on_mouse_wheel(const SDL_MouseWheelEvent &event) {
71 m_widgets.on_event(event, m_projector);
72 }
73 #endif
74 #endif
75
76 void Widget_Gamestate::perform_logic() {
77 m_viewport = get_Video().calculate_viewport(m_virtual_window, std::make_pair(Point2i(), get_Window().get_size()), m_fix_aspect_ratio);
78 m_projector = Projector2D(m_virtual_window, m_viewport);
79
80 m_widgets.perform_logic();
81 }
82
83 void Widget_Gamestate::render() {
84 Video &vr = get_Video();
85
86 vr.set_2d(m_virtual_window, m_fix_aspect_ratio);
87
88 m_widgets.render();
89 }
90
91 }
Zeni::Window::get_mouse_state
Mouse_State get_mouse_state() const
Find out if the mouse cursor is grabbed/hidden/relative.
Definition: Window.cpp:465
Zeni::Widget_Gamestate::on_key
void on_key(const SDL_KeyboardEvent &event)
Override this input callback in your Gamestates. See SDL documentation for details.
Definition: Widget_Gamestate.cpp:55
Zeni::Video::get_clear_Color
const Color & get_clear_Color() const
Get the blank background color.
Definition: Video.hxx:114
Zeni::Widget_Gamestate::fix_aspect_ratio
const bool & fix_aspect_ratio() const
Definition: Widget_Gamestate.cpp:32
Zeni::Video
The Video Rendering Singleton.
Definition: Video.h:71
Zeni::Video::set_clear_Color
virtual void set_clear_Color(const Color &color)=0
Set the blank background color.
Definition: Video.cpp:214
Zeni::Widget_Gamestate::perform_logic
void perform_logic()
Then perform logic. Called by Game as part of the main gameloop.
Definition: Widget_Gamestate.cpp:76
Zeni::Widget_Gamestate::get_virtual_window
const std::pair< Point2f, Point2f > & get_virtual_window() const
Definition: Widget_Gamestate.cpp:28
Zeni::Widget::render
void render() const
Definition: Widget.hxx:111
zeni_rest.h
Zeni::Window::MOUSE_NORMAL
Definition: Window.h:98
Zeni::Window::set_mouse_state
void set_mouse_state(const Mouse_State &mouse_state)
Definition: Window.cpp:478
Zeni::get_Game
Game & get_Game()
Get access to the singleton.
Definition: Game.cpp:58
Zeni::Gamestate_Base::on_key
virtual void on_key(const SDL_KeyboardEvent &event)
Override this input callback in your Gamestates. See SDL documentation for details.
Definition: Gamestate.cpp:99
Zeni::Widget_Gamestate::on_mouse_button
void on_mouse_button(const SDL_MouseButtonEvent &event)
Override this input callback in your Gamestates. See SDL documentation for details.
Definition: Widget_Gamestate.cpp:61
SDL_KeyboardEvent
Keyboard button event structure (event.key.*)
Definition: SDL_events.h:176
Zeni::Game::controller_mouse
struct Zeni::Game::Controller_Mouse controller_mouse
Zeni::Video::set_2d
void set_2d()
Set the default 2D view filling the entire display area.
Definition: Video.hxx:93
Zeni::Widget::on_event
void on_event(const SDL_KeyboardEvent &event)
Definition: Widget.hxx:69
Zeni::Projector2D
The 2D Projector.
Definition: Projector.h:86
Zeni::Widget_Gamestate::on_pop
void on_pop()
Called when the Gamestate is popped off the stack in Game.
Definition: Widget_Gamestate.cpp:48
Zeni::Widgets::perform_logic
virtual void perform_logic()
Definition: Widget.cpp:1583
SDL_MouseWheelEvent
Mouse wheel event structure (event.wheel.*)
Definition: SDL_events.h:251
Zeni::get_Window
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
Zeni::Widget_Gamestate::render
void render()
Then render. Called by Game as part of the main gameloop.
Definition: Widget_Gamestate.cpp:83
Zeni::Widget_Gamestate::on_push
void on_push()
Called when the Gamestate is pushed onto the stack in Game.
Definition: Widget_Gamestate.cpp:36
Zeni::Video::calculate_viewport
std::pair< Point2i, Point2i > calculate_viewport(const std::pair< Point2f, Point2f > &camera2d, const std::pair< Point2i, Point2i > &viewport, const bool &fix_aspect_ratio)
Calculate the viewport.
Definition: Video.cpp:242
Zeni::Game::Controller_Mouse::enabled
bool enabled
Definition: Game.h:131
SDL_MouseMotionEvent
Mouse motion event structure (event.motion.*)
Definition: SDL_events.h:218
SDL_MouseButtonEvent
Mouse button event structure (event.button.*)
Definition: SDL_events.h:234
Zeni::Widget::is_busy
const bool & is_busy() const
Definition: Widget.hxx:48
Zeni::get_Video
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
Zeni::Window
The Window Management Singleton.
Definition: Window.h:53
Zeni::Widget_Gamestate::m_widgets
Widgets m_widgets
Definition: Widget_Gamestate.h:63
Zeni::Widget_Gamestate::on_mouse_motion
void on_mouse_motion(const SDL_MouseMotionEvent &event)
Override this input callback in your Gamestates. See SDL documentation for details.
Definition: Widget_Gamestate.cpp:65
event
cl_event event
Definition: glew.h:3556
Zeni::Point2i
A 2D Point represented with integers.
Definition: Coordinate.h:85