From 0b0f661947588f1007b223ea2a58534efdb2a794 Mon Sep 17 00:00:00 2001 From: Gerhard Stein Date: Tue, 9 Jul 2024 19:10:42 +0200 Subject: [PATCH] Animated Messagebox fixes for the scaled ones --- GsKit/base/interface/Geometry.h | 10 ++- .../common/dialog/CMessageBoxBitmapGalaxy.cpp | 78 ++++++++++++------- .../common/dialog/CMessageBoxBitmapGalaxy.h | 18 +++-- 3 files changed, 72 insertions(+), 34 deletions(-) diff --git a/GsKit/base/interface/Geometry.h b/GsKit/base/interface/Geometry.h index 99489b0bf..4206bc551 100644 --- a/GsKit/base/interface/Geometry.h +++ b/GsKit/base/interface/Geometry.h @@ -126,6 +126,14 @@ struct GsRect return Rect; } + void scale(const int value) + { + pos.x *= value; + pos.y *= value; + dim.x *= value; + dim.y *= value; + } + void transformInverse(const GsRect &scaleRect) { dim.x /= scaleRect.dim.x; @@ -270,7 +278,7 @@ struct GsRect auto result = *this; result.intersect(other); return result; - } + } GsVec2D pos, dim; }; diff --git a/src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.cpp b/src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.cpp index 12eeaae06..a3ddab349 100644 --- a/src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.cpp +++ b/src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.cpp @@ -14,8 +14,6 @@ namespace galaxy { -//constexpr int FONT_ID = 0; - CMessageBoxBitmapGalaxy::CMessageBoxBitmapGalaxy(int sprVar, const std::string& Text, const GsBitmap &BitmapRef, @@ -23,16 +21,16 @@ CMessageBoxBitmapGalaxy::CMessageBoxBitmapGalaxy(int sprVar, const bool animation, CEvent *closeEv) : CMessageBoxGalaxy(sprVar, Text, closeEv), -mBitmap(BitmapRef), +mMainBitmap(BitmapRef), mAlignment(alignment) { // Looking if the Bitmap is too big for the Message box. In that case enlarge it! - if( (mBitmap.height()+26) > mMBRect.h ) + if( (mMainBitmap.height()+26) > mMBRect.h ) { - mMBRect.h = mBitmap.height()+26; + mMBRect.h = mMainBitmap.height()+26; } - mMBRect.w += (mBitmap.width()+32); + mMBRect.w += (mMainBitmap.width()+32); mMBSurface.createRGBSurface(mMBRect); mMBSurface.makeBlitCompatible(); @@ -41,9 +39,7 @@ mAlignment(alignment) { // After 240 time frames the dialog closes automatically mShowtime = 240; - - mMBAnimatedSurface.createRGBSurface(mMBRect); - mMBAnimatedSurface.makeBlitCompatible(); + mHasAnimation = true; } } @@ -57,7 +53,7 @@ void CMessageBoxBitmapGalaxy::init() // Move text to the right if bitmap is on the left side if( mAlignment == LEFT ) - rect.x += mBitmap.width(); + rect.x += mMainBitmap.width(); rect.w -= 16; rect.h -= 8; @@ -65,24 +61,63 @@ void CMessageBoxBitmapGalaxy::init() initText(rect); - const Uint16 bmpX = ( mAlignment == LEFT ) ? 10 : mMBRect.w-(mBitmap.width()+32); - mBitmap._draw( bmpX, 10, mMBSurface.getSDLSurface() ); - const int scaling = gVideoDriver.getOptimalScaling(); + mMBRect.w *= scaling; mMBRect.h *= scaling; + mMBSurface.scaleTo(mMBRect, VidFilter(scaling) ); + renderCurrentBitmap(0); + GsRect gameRes = gVideoDriver.getGameResolution(); mMBRect.x = (gameRes.dim.x-mMBRect.w)/2; mMBRect.y = (gameRes.dim.y-mMBRect.h)/2; } +void CMessageBoxBitmapGalaxy::renderCurrentBitmap(const int frametoRender) +{ + GsBitmap frame(mMainBitmap); + + if(frametoRender > 0) + { + std::string aniBmpStr = "KEENTHUMBSUPLOADING"; + aniBmpStr += itoa(frametoRender); + + const GsBitmap &aniBmpRef = *gGraphics.getBitmapFromStr(mSprVar, aniBmpStr); + + GsVec2D aniBmpPos = + { frame.width()-aniBmpRef.width(), + frame.height()-aniBmpRef.height() }; + + // Creates the right animation of the frame to blit + aniBmpRef._draw( aniBmpPos.x, aniBmpPos.y, frame.getSDLSurface() ); + } + + const int scaling = gVideoDriver.getOptimalScaling(); + + { + const Uint16 bmpX = ( mAlignment == LEFT ) ? 10 : + (mMBSurface.width()/scaling)-(frame.width()+20); + GsVec2D bmpPos = {bmpX, 10}; + + const GsRect frameRect = + {0, 0, + static_cast(frame.width()*scaling), + static_cast(frame.height()*scaling)}; + frame.scaleTo(frameRect); + + bmpPos *= scaling; + + frame._draw( bmpPos.x, bmpPos.y, mMBSurface.getSDLSurface() ); + } +} + void CMessageBoxBitmapGalaxy::ponder(const int deltaT) { CMessageBoxGalaxy::ponder(deltaT); - if(!mMBAnimatedSurface.empty() && mAnimFrame < 6) + if(mHasAnimation && mAnimFrame < 6) { mAnimtimer++; @@ -90,14 +125,7 @@ void CMessageBoxBitmapGalaxy::ponder(const int deltaT) { mAnimtimer = 0; - std::string bmpStr = "KEENTHUMBSUPLOADING"; - bmpStr += itoa(mAnimFrame); - - const GsBitmap &bitmapRef = *gGraphics.getBitmapFromStr(mSprVar, bmpStr); - - const Uint16 bmpX = 10+mBitmap.width()-bitmapRef.width(); - const Uint16 bmpY = 10+mBitmap.height()-bitmapRef.height(); - bitmapRef._draw( bmpX, bmpY, mMBSurface.getSDLSurface() ); + renderCurrentBitmap(mAnimFrame); mAnimFrame++; } @@ -119,12 +147,6 @@ void CMessageBoxBitmapGalaxy::ponder(const int deltaT) void CMessageBoxBitmapGalaxy::render() { CMessageBoxGalaxy::render(); - - if(!mMBAnimatedSurface.empty()) - { - BlitSurface(mMBAnimatedSurface.getSDLSurface(), nullptr, - gVideoDriver.getBlitSurface(), &mMBRect); - } } diff --git a/src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.h b/src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.h index f5e5f214a..b38e8bd3e 100644 --- a/src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.h +++ b/src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.h @@ -12,6 +12,8 @@ #include "graphics/GsGraphics.h" #include "engine/core/CSpriteObject.h" +#include + namespace galaxy { @@ -39,18 +41,24 @@ class CMessageBoxBitmapGalaxy : public CMessageBoxGalaxy private: - const GsBitmap &mBitmap; - const direction_t mAlignment; + const GsBitmap &mMainBitmap; + const direction_t mAlignment; /** - * @brief mMBAnimatedSurface Some boxes have animation, - * like Billys hand forming a fist + * @brief mHasAnimation Some message boxes have animation, + * like Billys hand forming a fist */ - GsSurface mMBAnimatedSurface; + bool mHasAnimation = false; int mAnimtimer = 0; int mAnimFrame = 1; int mShowtime = -1; + + /** + * @brief renderCurrentBitmap Draws the current Bitmap, this might change depending + * on the animation settings. + */ + void renderCurrentBitmap(const int frametoRender); }; void showModalMsgWithBmp(const int sprVar, const std::string &text,