World *world;
};
+struct WindowResizeEvent {
+ WindowResizeEvent(int w, int h)
+ : x(w), y(h) {}
+
+ int x;
+ int y;
+};
+
#endif // EVENTS_HPP_
#include <SDL2/SDL.h>
-class WindowSystem : public entityx::System<WindowSystem> {
+#include <events.hpp>
+
+class WindowSystem : public entityx::System<WindowSystem>, public entityx::Receiver<WindowSystem> {
private:
SDL_Window *window;
SDL_GLContext glContext;
void die(void);
+ void configure(entityx::EventManager &ev);
void update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt) override;
+ void receive(const WindowResizeEvent&);
};
#endif // WINDOW_HPP_
#include <config.hpp>
#include <world.hpp>
+#include <window.hpp>
#include <ui.hpp>
#include <inventory.hpp>
-#include <window.hpp>
#include <components.hpp>
#include <player.hpp>
#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
};
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:
#include <config.hpp>
+#include <SDL2/SDL_opengl.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
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;