diff options
Diffstat (limited to 'src/crepe')
-rw-r--r-- | src/crepe/api/Config.h | 6 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 24 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.h | 3 |
3 files changed, 17 insertions, 16 deletions
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h index e1aef7d..6de93f0 100644 --- a/src/crepe/api/Config.h +++ b/src/crepe/api/Config.h @@ -65,9 +65,9 @@ public: //! default window settings struct { - //TODO make this constexpr because this will never change - vec2 def_size = {1080,720}; - vec2 pos = {0,0}; + //TODO make this constexpr because this will never change + vec2 def_size = {1080, 720}; + vec2 pos = {0, 0}; float zoom = 1.0f; } win_set; diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 8b29f8a..ac6b089 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -17,8 +17,8 @@ #include "../api/Transform.h" #include "../util/Log.h" -#include "types.h" #include "SDLContext.h" +#include "types.h" using namespace crepe; using namespace std; @@ -123,7 +123,8 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos, pixel_height *= img_scale; 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)); + int pixel_y + = static_cast<int>((pos.y - cam_pos.y + this->window.y / 2 - pixel_height / 2)); return SDL_Rect{ .x = pixel_x, @@ -133,9 +134,9 @@ SDL_Rect SDLContext::get_dst_rect(const Sprite & sprite, const vec2 & pos, }; } -void SDLContext::draw_particle(const Sprite & sprite, const vec2 & pos, - const double & angle, const vec2 & cam_pos, - const double & img_scale, const vec2 & cam_scale) { +void SDLContext::draw_particle(const Sprite & sprite, const vec2 & pos, const double & angle, + const vec2 & cam_pos, const double & img_scale, + const vec2 & cam_scale) { SDL_RendererFlip render_flip = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x) @@ -148,8 +149,8 @@ void SDLContext::draw_particle(const Sprite & sprite, const vec2 & pos, &dstrect, angle, NULL, render_flip); } -void SDLContext::draw(const Sprite & sprite, const Transform & transform, - const vec2 & cam_pos, const vec2 & cam_scale) { +void SDLContext::draw(const Sprite & sprite, const Transform & transform, const vec2 & cam_pos, + const vec2 & cam_scale) { SDL_RendererFlip render_flip = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * sprite.flip.flip_x) @@ -166,19 +167,20 @@ void SDLContext::draw(const Sprite & sprite, const Transform & transform, void SDLContext::set_camera(const Camera & cam, vec2 & scale) { // resize window - if ((int)this->window.x != (int) cam.screen.x || (int)this->window.y != (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->window = cam.screen; } double screen_aspect = cam.screen.x / cam.screen.y; double viewport_aspect = cam.viewport.x / cam.viewport.y; - + // decide scaling factor for world to screen scale = cam.screen / cam.viewport * cam.zoom; SDL_Rect view; - + // calculate black bars if (screen_aspect > viewport_aspect) { // lettorboxing @@ -192,7 +194,7 @@ void SDLContext::set_camera(const Camera & cam, vec2 & scale) { view.x = 0; view.y = static_cast<int>(cam.screen.y - view.h) / 2; } - // set drawing area + // set drawing area SDL_RenderSetViewport(this->game_renderer.get(), &view); SDL_RenderSetLogicalSize(this->game_renderer.get(), cam.viewport.x, cam.viewport.y); diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h index f72eecb..542a8bf 100644 --- a/src/crepe/facade/SDLContext.h +++ b/src/crepe/facade/SDLContext.h @@ -135,8 +135,7 @@ private: * \param cam_scale camera scalar for world to screen */ void draw_particle(const Sprite & sprite, const vec2 & pos, const double & angle, - const vec2 & cam_pos, const double & img_scale, - const vec2 & cam_scale); + const vec2 & cam_pos, const double & img_scale, const vec2 & cam_scale); //! Clears the screen, preparing for a new frame. void clear_screen(); |