From 525ef0f4b4ddc4d48774b2763b878892a1cb185a Mon Sep 17 00:00:00 2001 From: Igor Ribeiro Barbosa Duarte Date: Thu, 9 Jun 2016 20:25:31 -0300 Subject: [PATCH] Adding fullscreen/windowed mode option --- include/engine.h | 1 + include/kernel.h | 1 + include/video.h | 1 + kernel/sdl2/sdl2kernel.cpp | 17 +++++++++++++++++ kernel/sdl2/sdl2kernel.h | 4 ++++ src/engine.cpp | 5 +++++ test/src/test_level.cpp | 5 +++++ 7 files changed, 34 insertions(+) diff --git a/include/engine.h b/include/engine.h index e016425..c4fa6ec 100644 --- a/include/engine.h +++ b/include/engine.h @@ -33,6 +33,7 @@ namespace ijengine { namespace video { Window * create_window(const string& title, int w, int h, double scale); + void set_full_screen(int mode); } namespace audio { diff --git a/include/kernel.h b/include/kernel.h index 03dbe4b..28e23aa 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -27,6 +27,7 @@ namespace ijengine { virtual Window * create_window(const string& title, int w, int h, double scale) = 0; + virtual void set_full_screen(int mode) = 0; virtual void set_audio_dir(const string& dir_path) = 0; virtual void play_audio_from_path(const string& title) = 0; diff --git a/include/video.h b/include/video.h index 4551efd..1cfd1ff 100644 --- a/include/video.h +++ b/include/video.h @@ -13,6 +13,7 @@ namespace ijengine { public: virtual ~Video() = default; virtual Window * create_window(const string& title, int w, int h) = 0; + virtual void set_full_screen(int mode) = 0; }; } diff --git a/kernel/sdl2/sdl2kernel.cpp b/kernel/sdl2/sdl2kernel.cpp index 76dca80..89b3768 100644 --- a/kernel/sdl2/sdl2kernel.cpp +++ b/kernel/sdl2/sdl2kernel.cpp @@ -60,9 +60,26 @@ SDL2Kernel::create_window(const string& title, int w, int h, double scale) SDL_SetWindowTitle(window, title.c_str()); SDL_RenderSetScale(renderer, scale, scale); + m_window = window; + return new SDL2Window(window, renderer); } +void +SDL2Kernel::set_full_screen(int mode) +{ + int flag; + + if(mode == 0) + flag = 0; + else if(mode == 1) + flag = SDL_WINDOW_FULLSCREEN; + else + flag = SDL_WINDOW_FULLSCREEN_DESKTOP; + + SDL_SetWindowFullscreen(m_window, flag); +} + static KeyboardEvent::Modifier key_modifier(Uint16 modifier) { diff --git a/kernel/sdl2/sdl2kernel.h b/kernel/sdl2/sdl2kernel.h index 64d21ba..5f6ba4c 100644 --- a/kernel/sdl2/sdl2kernel.h +++ b/kernel/sdl2/sdl2kernel.h @@ -17,6 +17,8 @@ class SDL2Kernel : public Kernel { Window * create_window(const string& title, int w, int h, double scale); + void set_full_screen(int mode); + void set_audio_dir(const string& dir_path); void play_audio_from_path(const string& title); void stop_audio(); @@ -44,6 +46,8 @@ class SDL2Kernel : public Kernel { void init_table(); void update_pending_events(unsigned now); + + SDL_Window *m_window; }; #endif diff --git a/src/engine.cpp b/src/engine.cpp index bc2c42e..f1e5067 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -81,6 +81,11 @@ namespace ijengine { return kernel->create_window(title, w, h, scale); } + + void + set_full_screen(int mode){ + return kernel->set_full_screen(mode); + } } namespace audio diff --git a/test/src/test_level.cpp b/test/src/test_level.cpp index 6c525a1..e656041 100644 --- a/test/src/test_level.cpp +++ b/test/src/test_level.cpp @@ -12,6 +12,11 @@ TestLevel::TestLevel(int r, int g, int b, const string& next_level, const string { RandomRect *rect = new RandomRect(r, g, b, 200, 200); + //0 for windowed mode + //1 for fullscreen mode + //2 for fullscreen-desktop mode + video::set_full_screen(0); + add_child(rect); }