zenilib  0.5.3.0
 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 
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;
43 
44  m_mouse_state = wr.get_mouse_state();
46  }
47 
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
56  m_widgets.on_event(event);
57  if(!m_widgets.is_busy())
59  }
60 
62  m_widgets.on_event(event, m_projector);
63  }
64 
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 
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 
81  }
82 
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 }
Mouse_State get_mouse_state() const
Find out if the mouse cursor is grabbed/hidden/relative.
Definition: Window.cpp:465
void on_key(const SDL_KeyboardEvent &event)
Override this input callback in your Gamestates. See SDL documentation for details.
const Color & get_clear_Color() const
Get the blank background color.
Definition: Video.hxx:114
const bool & fix_aspect_ratio() const
The Video Rendering Singleton.
Definition: Video.h:71
virtual void set_clear_Color(const Color &color)=0
Set the blank background color.
Definition: Video.cpp:214
void perform_logic()
Then perform logic. Called by Game as part of the main gameloop.
const std::pair< Point2f, Point2f > & get_virtual_window() const
void render() const
Definition: Widget.hxx:111
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
virtual void on_key(const SDL_KeyboardEvent &event)
Override this input callback in your Gamestates. See SDL documentation for details.
Definition: Gamestate.cpp:99
void on_mouse_button(const SDL_MouseButtonEvent &event)
Override this input callback in your Gamestates. See SDL documentation for details.
Keyboard button event structure (event.key.*)
Definition: SDL_events.h:176
struct Zeni::Game::Controller_Mouse controller_mouse
void set_2d()
Set the default 2D view filling the entire display area.
Definition: Video.hxx:93
void on_event(const SDL_KeyboardEvent &event)
Definition: Widget.hxx:69
The 2D Projector.
Definition: Projector.h:86
void on_pop()
Called when the Gamestate is popped off the stack in Game.
virtual void perform_logic()
Definition: Widget.cpp:1583
Mouse wheel event structure (event.wheel.*)
Definition: SDL_events.h:251
Window & get_Window()
Get access to the singleton.
Definition: Window.cpp:392
void render()
Then render. Called by Game as part of the main gameloop.
void on_push()
Called when the Gamestate is pushed onto the stack in Game.
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
Mouse motion event structure (event.motion.*)
Definition: SDL_events.h:218
Mouse button event structure (event.button.*)
Definition: SDL_events.h:234
const bool & is_busy() const
Definition: Widget.hxx:48
Video & get_Video()
Get access to the singleton.
Definition: Video.cpp:149
The Window Management Singleton.
Definition: Window.h:53
void on_mouse_motion(const SDL_MouseMotionEvent &event)
Override this input callback in your Gamestates. See SDL documentation for details.
cl_event event
Definition: glew.h:3556
A 2D Point represented with integers.
Definition: Coordinate.h:85