Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
sdl2_window.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef SIMULANT_WINDOW_H_INCLUDED
20 #define SIMULANT_WINDOW_H_INCLUDED
21 
22 #include <string>
23 
24 #include <SDL.h>
25 #if defined(__WIN32__)
26  #undef main
27 #endif
28 #include "sdl2_keycodes.h"
29 #include "generic/managed.h"
30 #include "window.h"
31 
32 namespace smlt {
33 
34 int event_filter(void* user_data, SDL_Event* event);
35 
36 class SDL2Window : public Window {
37 public:
38 
39  static Window::ptr create(Application* app) {
40  return Window::create<SDL2Window>(app);
41  }
42 
43  SDL2Window();
44  virtual ~SDL2Window();
45 
46  void set_title(const std::string& title) override;
47  void show_cursor(bool value=true) override;
48  void lock_cursor(bool cursor_locked=true) override;
49  void cursor_position(int32_t& mouse_x, int32_t& mouse_y) override;
50 
51 private:
52  bool _init_window() override;
53  bool _init_renderer(Renderer* renderer) override;
54 
55  SDL_Window* screen_;
56  SDL_GLContext context_;
57 
58  void destroy_window() override;
59 
60  void check_events() override;
61  void swap_buffers() override;
62 
63  friend int event_filter(void* user_data, SDL_Event* event);
64 
65  void denormalize(float x, float y, int& xout, int& yout);
66 
67  std::shared_ptr<SoundDriver> create_sound_driver(const std::string &from_config) override;
68 
69  void initialize_input_controller(InputState &controller) override;
70 
71  /* This is for testing mainly. If you set config.desktop.enable_virtual_screen = true */
72  void initialize_virtual_screen(uint16_t width, uint16_t height, ScreenFormat format, uint16_t integer_scale);
73 
74  std::vector<SDL_Joystick*> open_joysticks_;
75  std::vector<SDL_GameController*> open_controllers_;
76 
77  bool initialize_screen(Screen *screen) override;
78  void shutdown_screen(Screen* screen) override;
79  void render_screen(Screen* screen, const uint8_t* data) override;
80 
81  friend class Application;
82 };
83 
84 }
85 
86 #endif // WINDOW_H_INCLUDED
smlt::Application
Definition: application.h:167
smlt
Definition: animation.cpp:25
smlt::Window
Definition: window.h:65
smlt::Screen
Definition: screen.h:20
smlt::Renderer
Definition: renderer.h:40
smlt::InputState
Definition: input_state.h:150
smlt::SDL2Window
Definition: sdl2_window.h:36