diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-06 19:21:56 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-12-06 19:21:56 +0100 |
commit | 05e099c03a2242bf5194d06191a0ff667d404817 (patch) | |
tree | 0904b649fe224482516d6c5fd71a25f1d2d91802 /src/crepe/facade/SDLContext.cpp | |
parent | 83ee80ea439fc6a9042307a25b214b3efcf28d91 (diff) |
implemented feedback
Diffstat (limited to 'src/crepe/facade/SDLContext.cpp')
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index cf9f7d5..4cc2206 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -15,13 +15,13 @@ #include <stdexcept> #include "../api/Camera.h" +#include "../api/Color.h" #include "../api/Config.h" #include "../api/Sprite.h" #include "../api/Texture.h" #include "../util/Log.h" #include "SDLContext.h" -#include "api/Color.h" #include "types.h" using namespace crepe; @@ -230,14 +230,17 @@ SDL_Rect SDLContext::get_src_rect(const Sprite & sprite) const { }; } -SDL_FRect SDLContext::get_dst_rect(const DstRect & ctx) const { +SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { const Sprite::Data & data = ctx.sprite.data; - vec2 size = {data.size.x == 0 && data.size.y != 0 ? data.size.y * ctx.sprite.aspect_ratio - : data.size.x, - data.size.y == 0 && data.size.x != 0 ? data.size.x / ctx.sprite.aspect_ratio - : data.size.y}; + vec2 size; + if (data.size.x == 0 && data.size.y != 0) { + size.x = data.size.y * ctx.sprite.aspect_ratio; + } + if (data.size.y == 0 && data.size.x != 0) { + size.y = data.size.x / ctx.sprite.aspect_ratio; + } const CameraValues & cam = ctx.cam; @@ -264,7 +267,7 @@ void SDLContext::draw(const RenderContext & ctx) { | (SDL_FLIP_VERTICAL * data.flip.flip_y)); SDL_Rect srcrect = this->get_src_rect(ctx.sprite); - SDL_FRect dstrect = this->get_dst_rect(SDLContext::DstRect{ + SDL_FRect dstrect = this->get_dst_rect(SDLContext::DestinationRectangleData{ .sprite = ctx.sprite, .cam = ctx.cam, .pos = ctx.pos, @@ -294,8 +297,8 @@ SDLContext::CameraValues SDLContext::set_camera(const Camera & cam) { vec2 & render_scale = ret_cam.render_scale; zoomed_viewport = cam.viewport_size * cam_data.zoom; - double screen_aspect = static_cast<double>(cam.screen.x) / cam.screen.y; - double viewport_aspect = zoomed_viewport.x / zoomed_viewport.y; + float screen_aspect = static_cast<float>(cam.screen.x) / cam.screen.y; + float viewport_aspect = zoomed_viewport.x / zoomed_viewport.y; // calculate black bars if (screen_aspect > viewport_aspect) { |