Skip to content

Commit

Permalink
Animated Messagebox fixes for the scaled ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerhard Stein committed Jul 9, 2024
1 parent 3d17f5a commit 0b0f661
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 34 deletions.
10 changes: 9 additions & 1 deletion GsKit/base/interface/Geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -270,7 +278,7 @@ struct GsRect
auto result = *this;
result.intersect(other);
return result;
}
}

GsVec2D<T> pos, dim;
};
Expand Down
78 changes: 50 additions & 28 deletions src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@
namespace galaxy
{

//constexpr int FONT_ID = 0;

CMessageBoxBitmapGalaxy::CMessageBoxBitmapGalaxy(int sprVar,
const std::string& Text,
const GsBitmap &BitmapRef,
const direction_t alignment,
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();
Expand All @@ -41,9 +39,7 @@ mAlignment(alignment)
{
// After 240 time frames the dialog closes automatically
mShowtime = 240;

mMBAnimatedSurface.createRGBSurface(mMBRect);
mMBAnimatedSurface.makeBlitCompatible();
mHasAnimation = true;
}
}

Expand All @@ -57,47 +53,79 @@ 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;
rect.y = (rect.h-mTextHeight)/2;

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<Uint16> 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<Uint16> 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<Uint16> bmpPos = {bmpX, 10};

const GsRect<Uint16> frameRect =
{0, 0,
static_cast<Uint16>(frame.width()*scaling),
static_cast<Uint16>(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++;

if(mAnimtimer >= 15)
{
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++;
}
Expand All @@ -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);
}
}


Expand Down
18 changes: 13 additions & 5 deletions src/engine/keen/galaxy/common/dialog/CMessageBoxBitmapGalaxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "graphics/GsGraphics.h"
#include "engine/core/CSpriteObject.h"

#include <vector>

namespace galaxy
{

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0b0f661

Please sign in to comment.