From 8eb1625aea5ccaa07414e699e784440a94277ab0 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 26 Oct 2016 07:32:25 -0400 Subject: Scaling work --- src/engine.cpp | 2 +- src/ui.cpp | 16 ++++++++++++++-- src/window.cpp | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/engine.cpp b/src/engine.cpp index 90cfb3a..f4d19a2 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -2,9 +2,9 @@ #include #include +#include #include #include -#include #include #include diff --git a/src/ui.cpp b/src/ui.cpp index 43dd6cc..4731261 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -8,11 +8,10 @@ #include #include #include +#include extern Menu* currentMenu; -extern SDL_Window *window; - std::array controlMap = { SDLK_w, SDLK_a, SDLK_d, SDLK_LSHIFT, SDLK_LCTRL, SDLK_e }; @@ -1244,6 +1243,19 @@ void InputSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, case SDL_QUIT: game::endGame(); break; + + // window events - used for resizing and stuff + case SDL_WINDOWEVENT: + switch (e.window.event) { + case SDL_WINDOWEVENT_RESIZED: + std::cout << "Window " << e.window.windowID << " resized to: " << e.window.data1 << ", " << e.window.data2 << std::endl; + auto w = e.window.data1; + auto h = e.window.data2; + ev.emit(w,h); + break; + } + break; + // mouse movement - update mouse vector case SDL_MOUSEMOTION: diff --git a/src/window.cpp b/src/window.cpp index e21bf69..69c383c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -61,6 +62,22 @@ void WindowSystem::die(void) SDL_DestroyWindow(window); } + +void WindowSystem::configure(entityx::EventManager &ev) +{ + ev.subscribe(*this); +} + + +void WindowSystem::receive(const WindowResizeEvent &wre) +{ + + game::SCREEN_WIDTH = wre.x; + game::SCREEN_HEIGHT = wre.y; + glViewport(0, 0, wre.x, wre.y); + SDL_SetWindowSize(window, wre.x, wre.y); +} + void WindowSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) { (void)en; -- cgit v1.2.3