aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp2
-rw-r--r--src/ui.cpp16
-rw-r--r--src/window.cpp17
3 files changed, 32 insertions, 3 deletions
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 <config.hpp>
#include <world.hpp>
+#include <window.hpp>
#include <ui.hpp>
#include <inventory.hpp>
-#include <window.hpp>
#include <components.hpp>
#include <player.hpp>
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 <render.hpp>
#include <engine.hpp>
#include <events.hpp>
+#include <window.hpp>
extern Menu* currentMenu;
-extern SDL_Window *window;
-
std::array<SDL_Keycode, 6> 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<WindowResizeEvent>(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 <config.hpp>
+#include <SDL2/SDL_opengl.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
@@ -61,6 +62,22 @@ void WindowSystem::die(void)
SDL_DestroyWindow(window);
}
+
+void WindowSystem::configure(entityx::EventManager &ev)
+{
+ ev.subscribe<WindowResizeEvent>(*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;