From 0b462ae65121e38d9371a1df3ea92bf661ccf873 Mon Sep 17 00:00:00 2001 From: Is Daouda Date: Wed, 15 Sep 2021 11:17:57 +0000 Subject: [PATCH] Update isEngineSDLWrapper.cpp --- .../islibconnect/isEngineSDLWrapper.cpp | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/app/src/main/cpp/isEngine/system/islibconnect/isEngineSDLWrapper.cpp b/app/src/main/cpp/isEngine/system/islibconnect/isEngineSDLWrapper.cpp index 132b94f..cf4e4e5 100644 --- a/app/src/main/cpp/isEngine/system/islibconnect/isEngineSDLWrapper.cpp +++ b/app/src/main/cpp/isEngine/system/islibconnect/isEngineSDLWrapper.cpp @@ -951,9 +951,9 @@ void RenderWindow::draw(SDLTexture &obj) // We keep the value of the origin x and y of the object to be drawn. // This allows to keep the value of the original variables intact during recalculations. - float objOriginX((obj.getScale().x < 0.f && static_cast(obj.getOrigin().y) == 0 && + float objOriginX((obj.getScale().x < 0.f /*&& static_cast(obj.getOrigin().y) == 0*/ && static_cast(obj.getOrigin().x) == 0) ? obj.getTextureRect().width : obj.getOrigin().x); - float objOriginY((obj.getScale().y < 0.f && static_cast(obj.getOrigin().x) == 0 && + float objOriginY((obj.getScale().y < 0.f /*&& static_cast(obj.getOrigin().x) == 0*/ && static_cast(obj.getOrigin().y) == 0) ? obj.getTextureRect().height : obj.getOrigin().y); float xOrigin(objOriginX); float yOrigin(objOriginY); @@ -972,18 +972,31 @@ void RenderWindow::draw(SDLTexture &obj) yOrigin = rec.h / (obj.getTextureRect().height / objOriginY); // We do a corresponding flip according to the sign of the variables x scale and y scale - if (obj.getScale().x < 0.f && obj.getScale().y < 0.f) obj.m_SDLFlip = (SDL_RendererFlip)(SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL); + if (obj.getScale().x < 0.f && obj.getScale().y < 0.f) + { + obj.m_SDLFlip = (SDL_RendererFlip)(SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL); + if (static_cast(obj.getOrigin().x) != static_cast(obj.getTextureRect().width / 2) && + static_cast(obj.getOrigin().x) != 0) + xOrigin += obj.getTextureRect().width; + if (static_cast(obj.getOrigin().y) != static_cast(obj.getTextureRect().height / 2) && + static_cast(obj.getOrigin().y) != 0) + yOrigin -= obj.getTextureRect().height; + } else if (obj.getScale().x < 0.f) { obj.m_SDLFlip = SDL_FLIP_HORIZONTAL; - //xOrigin *= 1.65f; - //rotation *= -1.f; + if (static_cast(obj.getOrigin().x) != static_cast(obj.getTextureRect().width / 2) && + static_cast(obj.getOrigin().x) != 0) xOrigin += obj.getTextureRect().width; + } + else if (obj.getScale().y < 0.f) + { + obj.m_SDLFlip = SDL_FLIP_VERTICAL; + if (static_cast(obj.getOrigin().y) != static_cast(obj.getTextureRect().height / 2) && + static_cast(obj.getOrigin().y) != 0) + yOrigin -= obj.getTextureRect().height; } - else if (obj.getScale().y < 0.f) obj.m_SDLFlip = SDL_FLIP_VERTICAL; else obj.m_SDLFlip = SDL_FLIP_NONE; - SDL_SetTextureColorMod(obj.getSDLTexture(), obj.getColor().r, obj.getColor().g, obj.getColor().b); - // Move the object according to the position of the camera rec.x = (obj.getPosition().x - xOrigin) - (m_view.getCenter().x - (m_view.getSize().x / 2.f)); rec.y = (obj.getPosition().y - yOrigin) - (m_view.getCenter().y - (m_view.getSize().y / 2.f)); @@ -1018,15 +1031,12 @@ void RenderWindow::draw(SDLTexture &obj) rec.w, obj.getTextureRect().height, objOriginY); } - SDL_SetTextureBlendMode(obj.getSDLTexture(), SDL_BLENDMODE_BLEND); - SDL_SetTextureAlphaMod(obj.getSDLTexture(), obj.getColor().a); - if (obj.m_SDLTextureType == SDLTexture::SDLTextureType::IS_ENGINE_SDL_TEXT) { if (obj.getSDLOutlineTexture() != NULL) { SDL_SetTextureBlendMode(obj.getSDLOutlineTexture(), SDL_BLENDMODE_BLEND); - //SDL_SetTextureAlphaMod(obj.getSDLOutlineTexture(), obj.getColor().a); + SDL_SetTextureAlphaMod(obj.getSDLOutlineTexture(), obj.getColor().a); SDL_Rect SDLoutlineTextureRec, outlineTextureRecSrc; SDLoutlineTextureRec.x = rec.x; @@ -1045,6 +1055,9 @@ void RenderWindow::draw(SDLTexture &obj) &outlineTextureRecSrc, &SDLoutlineTextureRec, rotation, &point, obj.m_SDLFlip); } } + SDL_SetTextureBlendMode(obj.getSDLTexture(), SDL_BLENDMODE_BLEND); + SDL_SetTextureAlphaMod(obj.getSDLTexture(), obj.getColor().a); + SDL_SetTextureColorMod(obj.getSDLTexture(), obj.getColor().r, obj.getColor().g, obj.getColor().b); SDL_RenderCopyEx(is::IS_ENGINE_SDL_renderer, obj.getSDLTexture(), &recSrc, &rec, rotation, &point, obj.m_SDLFlip); }