From 8eb1625aea5ccaa07414e699e784440a94277ab0 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 26 Oct 2016 07:32:25 -0400 Subject: Scaling work --- assets/NPC.png | Bin 473 -> 624 bytes assets/style/classic/bg/bgFarMountain.png | Bin 151687 -> 148956 bytes assets/style/classic/bg/forestTileBack.png | Bin 20973 -> 33765 bytes assets/style/classic/bg/forestTileFar.png | Bin 23788 -> 36779 bytes assets/style/classic/bg/forestTileFront.png | Bin 17530 -> 28679 bytes assets/style/classic/bg/forestTileMid.png | Bin 19778 -> 32169 bytes assets/style/classic/house1.png | Bin 1434 -> 2455 bytes include/events.hpp | 8 ++++++++ include/window.hpp | 6 +++++- src/engine.cpp | 2 +- src/ui.cpp | 16 ++++++++++++++-- src/window.cpp | 17 +++++++++++++++++ 12 files changed, 45 insertions(+), 4 deletions(-) diff --git a/assets/NPC.png b/assets/NPC.png index fdebfa9..8381988 100644 Binary files a/assets/NPC.png and b/assets/NPC.png differ diff --git a/assets/style/classic/bg/bgFarMountain.png b/assets/style/classic/bg/bgFarMountain.png index 2ec7dae..8721571 100644 Binary files a/assets/style/classic/bg/bgFarMountain.png and b/assets/style/classic/bg/bgFarMountain.png differ diff --git a/assets/style/classic/bg/forestTileBack.png b/assets/style/classic/bg/forestTileBack.png index c3a7daf..1bb1ffc 100644 Binary files a/assets/style/classic/bg/forestTileBack.png and b/assets/style/classic/bg/forestTileBack.png differ diff --git a/assets/style/classic/bg/forestTileFar.png b/assets/style/classic/bg/forestTileFar.png index 1302130..c2716a5 100644 Binary files a/assets/style/classic/bg/forestTileFar.png and b/assets/style/classic/bg/forestTileFar.png differ diff --git a/assets/style/classic/bg/forestTileFront.png b/assets/style/classic/bg/forestTileFront.png index 5b2d250..44b2cfc 100644 Binary files a/assets/style/classic/bg/forestTileFront.png and b/assets/style/classic/bg/forestTileFront.png differ diff --git a/assets/style/classic/bg/forestTileMid.png b/assets/style/classic/bg/forestTileMid.png index 152af65..5dfd2c8 100644 Binary files a/assets/style/classic/bg/forestTileMid.png and b/assets/style/classic/bg/forestTileMid.png differ diff --git a/assets/style/classic/house1.png b/assets/style/classic/house1.png index 025b169..54a9a02 100644 Binary files a/assets/style/classic/house1.png and b/assets/style/classic/house1.png differ diff --git a/include/events.hpp b/include/events.hpp index 7f70c04..5cd8040 100644 --- a/include/events.hpp +++ b/include/events.hpp @@ -47,4 +47,12 @@ struct BGMToggleEvent { World *world; }; +struct WindowResizeEvent { + WindowResizeEvent(int w, int h) + : x(w), y(h) {} + + int x; + int y; +}; + #endif // EVENTS_HPP_ diff --git a/include/window.hpp b/include/window.hpp index d168a54..364ac8f 100644 --- a/include/window.hpp +++ b/include/window.hpp @@ -5,7 +5,9 @@ #include -class WindowSystem : public entityx::System { +#include + +class WindowSystem : public entityx::System, public entityx::Receiver { private: SDL_Window *window; SDL_GLContext glContext; @@ -15,7 +17,9 @@ public: 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_ 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