From 33cd5566909ac089cdf56db38a3d1daf0cb7dd10 Mon Sep 17 00:00:00 2001 From: heavydemon21 Date: Mon, 9 Dec 2024 15:35:36 +0100 Subject: fixed the aspect ratio and removed the ratio from sprite and give it to texture. however the problem still lies with if animator is given the aspect ratio is then off --- src/crepe/api/Texture.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/crepe/api/Texture.cpp') diff --git a/src/crepe/api/Texture.cpp b/src/crepe/api/Texture.cpp index 2ac8606..b0863cb 100644 --- a/src/crepe/api/Texture.cpp +++ b/src/crepe/api/Texture.cpp @@ -1,23 +1,35 @@ #include "../util/Log.h" +#include "manager/Mediator.h" +#include "facade/SDLContext.h" #include "Asset.h" #include "Resource.h" #include "Texture.h" -#include "facade/SDLContext.h" -#include "manager/Mediator.h" #include "types.h" using namespace crepe; using namespace std; -Texture::Texture(const Asset & src, Mediator & mediator) : Resource(src, mediator) { +Texture::Texture(const Asset & src, Mediator & mediator) : Resource(src, mediator){ dbg_trace(); SDLContext & ctx = mediator.sdl_context; this->texture = ctx.texture_from_path(src.get_path()); this->size = ctx.get_size(*this); + this->aspect_ratio = static_cast(this->size.x) / this->size.y; } Texture::~Texture() { dbg_trace(); this->texture.reset(); } + +const ivec2 & Texture::get_size() const noexcept{ + return this->size; +} +const float & Texture::get_ratio() const noexcept{ + return this->aspect_ratio; +} + +SDL_Texture * Texture::get_img() const noexcept{ + return this->texture.get(); +} -- cgit v1.2.3