diff options
Diffstat (limited to 'src/crepe/facade')
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 12 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 4 |
2 files changed, 7 insertions, 9 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index fc59d84..8b29f8a 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -30,14 +30,13 @@ SDLContext & SDLContext::get_instance() { SDLContext::SDLContext() { dbg_trace(); - // FIXME: read window defaults from config manager if (SDL_Init(SDL_INIT_VIDEO) != 0) { throw runtime_error(format("SDLContext: SDL_Init error: {}", SDL_GetError())); } SDL_Window * tmp_window = SDL_CreateWindow("Crepe Game Engine", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - this->viewport.w, this->viewport.h, 0); + this->window.x, this->window.y, 0); if (!tmp_window) { throw runtime_error(format("SDLContext: SDL_Window error: {}", SDL_GetError())); } @@ -123,8 +122,8 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos, pixel_width *= img_scale; pixel_height *= img_scale; - int pixel_x = static_cast<int>((pos.x - cam_pos.x + this->viewport.w / 2 - pixel_width / 2)); - int pixel_y = static_cast<int>((pos.y - cam_pos.y + this->viewport.h / 2 - pixel_height / 2)); + int pixel_x = static_cast<int>((pos.x - cam_pos.x + this->window.x / 2 - pixel_width / 2)); + int pixel_y = static_cast<int>((pos.y - cam_pos.y + this->window.y / 2 - pixel_height / 2)); return SDL_Rect{ .x = pixel_x, @@ -167,10 +166,9 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform, void SDLContext::set_camera(const Camera & cam, vec2 & scale) { // resize window - if (this->viewport.w != (int) cam.screen.x || this->viewport.h != (int) cam.screen.y) { + if ((int)this->window.x != (int) cam.screen.x || (int)this->window.y != (int) cam.screen.y) { SDL_SetWindowSize(this->game_window.get(), (int) cam.screen.x, (int) cam.screen.y); - this->viewport.h = (int)cam.screen.y; - this->viewport.w = (int)cam.screen.x; + this->window = cam.screen; } double screen_aspect = cam.screen.x / cam.screen.y; diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index c9f3299..f72eecb 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -13,6 +13,7 @@ #include "../api/Transform.h" #include "api/Camera.h" +#include "api/Config.h" #include "types.h" namespace crepe { @@ -179,8 +180,7 @@ private: std::unique_ptr<SDL_Renderer, std::function<void(SDL_Renderer *)>> game_renderer; //! viewport for the camera window - //todo change this so that it becomes a vec2 for only width and height - SDL_Rect viewport = {0, 0, 1200, 1200}; + vec2 window = Config::get_instance().win_set.def_size; }; } // namespace crepe |