Commit d3c0753e authored by Gerhard Stein's avatar Gerhard Stein

Heavy improvements managemnt of surfaces and bitmaps

parent 3dc0a164
......@@ -31,7 +31,7 @@ string(REGEX REPLACE "[\r\n]" "" CG_VERSION "${CG_VERSION}")
# Since shell script get_version is not processed properly on windows, we have to define manually here.
# TODO: Better system for defining the version
IF(WIN32)
set(CG_VERSION "2.0.2")
set(CG_VERSION "2.0.3")
endif()
# Generate the README file with the correct version string
......
Subproject commit 1606dd44393016d2816a52f34453739d52ed3abf
Subproject commit 61beaebd0212f31298a981b48eb20fa3e85c234a
......@@ -63,7 +63,7 @@ private:
bool m_mustclose;
int m_timer;
std::shared_ptr<SDL_Surface> mpTextVSfc;
std::shared_ptr<SDL_Surface> mpTextVSfc;
};
#endif /* CTEXTVIEWER_H_ */
......@@ -121,7 +121,7 @@ bool CGameLauncher::setupMenu()
mCurrentBmp = std::dynamic_pointer_cast< CGUIBitmap >
( mLauncherDialog.getControlList().back() );
mpPrevievBmpVec.resize(m_Entries.size());
mPreviewBmpPtrVec.resize(m_Entries.size());
std::vector<GameEntry>::iterator it = m_Entries.begin();
unsigned int i=0;
......@@ -136,10 +136,8 @@ bool CGameLauncher::setupMenu()
if(IsFileAvailable(fullfilename))
{
SDL_Surface *pPrimBmp = SDL_LoadBMP(GetFullFileName(fullfilename).c_str());
std::shared_ptr<SDL_Surface> bmpSfcPtr( pPrimBmp );
std::shared_ptr<GsBitmap> pBmp(new GsBitmap(bmpSfcPtr));
mpPrevievBmpVec[i] = pBmp;
mPreviewBmpPtrVec[i].reset(new GsBitmap);
mPreviewBmpPtrVec[i]->loadHQBitmap(fullfilename);
}
i++;
}
......@@ -670,7 +668,7 @@ void CGameLauncher::ponderGameSelDialog(const float deltaT)
mpDemoText->setText(entry.demo ? "Demo" : "");
// Now update the bitmap
mCurrentBmp->setBitmapPtr(mpPrevievBmpVec[mSelection]);
mCurrentBmp->setBitmapPtr(mPreviewBmpPtrVec[mSelection]);
}
mLauncherDialog.processLogic();
......
......@@ -159,7 +159,8 @@ private:
CResourceLoaderBackground mGameScanner;
std::shared_ptr<CGUIBitmap> mCurrentBmp;
std::vector< std::shared_ptr<GsBitmap> > mpPrevievBmpVec;
std::vector< std::shared_ptr<GsBitmap> > mPreviewBmpPtrVec;
CGUIText *mpEpisodeText;
CGUIText *mpDemoText;
CGUIText *mpVersionText;
......
......@@ -90,7 +90,7 @@ void CGameLauncher::ponderDownloadDialog()
mpDDescriptionText->setText(gameEntry.mDescription);
mpCurrentDownloadBmp->setBitmapPtr(gameEntry.pBmp);
mpCurrentDownloadBmp->setBitmapPtr(gameEntry.mBmpPtr);
mLastStoreSelection = sel;
}
......
......@@ -208,9 +208,10 @@ bool GameDownloader::loadCatalogue(const std::string &catalogueFile)
const auto filePath = JoinPaths("cache", gce.mPictureFile);
const auto fullfname = GetFullFileName(filePath);
SDL_Surface *pPrimBmp = IMG_Load( fullfname.c_str() );
std::shared_ptr<SDL_Surface> bmpSfcPtr( pPrimBmp );
gce.pBmp.reset( new GsBitmap(bmpSfcPtr) );
gce.mBmpPtr.reset(new GsBitmap);
gce.mBmpPtr->loadImg(fullfname);
mGameCatalogue.push_back(gce);
}
......
......@@ -15,8 +15,7 @@ struct GameCatalogueEntry
std::string mDescription;
std::string mPictureFile;
// Pointer to the bitmap
std::shared_ptr<GsBitmap> pBmp;
std::shared_ptr<GsBitmap> mBmpPtr;
};
......
......@@ -45,13 +45,10 @@ mCommanderTextSfc(gGraphics.getMiscGsBitmap(0)),
mKeenTextSfc(gGraphics.getMiscGsBitmap(1)),
mSkipSection(false)
{
// auto &tetTest = gGraphics.getMiscGsBitmap(0);
// mCommanderTextSfc = tetTest;
const GsRect<Uint16> gameRect = gVideoDriver.getVidConfig().mGameRect;
gVideoDriver.setNativeResolution(gameRect);
const int episode = gBehaviorEngine.getEpisode();
const auto episode = gBehaviorEngine.getEpisode();
if(episode == 4)
mCreditsBmpID = 98;
......@@ -72,11 +69,11 @@ mSkipSection(false)
// Scale Bitmaps to adapt the resolutions
GsRect<Uint16> cmdTextRect, keenTextRect;
cmdTextRect.w = mCommanderTextSfc.getSDLSurface()->w;
cmdTextRect.w = mCommanderTextSfc.width();
cmdTextRect.x = cmdTextRect.y = 0;
cmdTextRect.h = mCommanderTextSfc.getSDLSurface()->h;
keenTextRect.w = mKeenTextSfc.getSDLSurface()->w;
keenTextRect.h = mKeenTextSfc.getSDLSurface()->h;
cmdTextRect.h = mCommanderTextSfc.height();
keenTextRect.w = mKeenTextSfc.width();
keenTextRect.h = mKeenTextSfc.height();
keenTextRect.x = keenTextRect.y = 0;
cmdTextRect.h *= mScaleFactor;
......
......@@ -59,8 +59,8 @@ void CStatusScreenGalaxy::drawBase(SDL_Rect &EditRect)
GsBitmap &SupportBmp = gGraphics.getMaskedBitmap(2);
SDL_Rect SupportRect;
SupportRect.w = SupportBmp.getSDLSurface()->w;
SupportRect.h = SupportBmp.getSDLSurface()->h;
SupportRect.w = SupportBmp.width();
SupportRect.h = SupportBmp.height();
Dest.x = (DestRect.w-SupportRect.w)/2; Dest.y = 0;
BlitSurface( SupportBmp.getSDLSurface(), NULL, mpStatusSurface.get(), &Dest );
......
......@@ -8,7 +8,7 @@
#include <memory>
#include <base/video/CVideoDriver.h>
#include <base/CInput.h>
#include <widgets/GsBitmap.h>
#include <widgets/GsBitmapBox.h>
#include "CMessageBoxVort.h"
......@@ -16,7 +16,10 @@
#include "sdl/extensions.h"
CMessageBoxVort::CMessageBoxVort(const std::string& Text, bool lower, bool keymsg, bool leftbound) :
CMessageBoxVort::CMessageBoxVort(const std::string& Text,
const bool lower,
const bool keymsg,
const bool leftbound) :
CMessageBox(Text, lower, keymsg, leftbound, CGUIDialog::FXKind::EXPAND)
{
initVorticonBackground();
......@@ -88,6 +91,6 @@ void CMessageBoxVort::addTileAt(Uint16 tile, Uint16 x, Uint16 y)
fRect.transformInverse(scaleRect);
std::shared_ptr<GsBitmap> pBitmap(new GsBitmap(bmpSfc));
addControl( new CGUIBitmap(pBitmap), fRect );
std::shared_ptr<GsBitmap> bmpShared(new GsBitmap(bmpSfc));
addControl( new CGUIBitmap(bmpShared), fRect );
}
......@@ -13,7 +13,10 @@
class CMessageBoxVort : public CMessageBox
{
public:
CMessageBoxVort(const std::string& Text, bool lower = false, bool keymsg = false, bool leftbound = false);
CMessageBoxVort(const std::string& Text,
const bool lower = false,
const bool keymsg = false,
const bool leftbound = false);
void initVorticonBackground();
......
......@@ -247,7 +247,9 @@ void ChangeState (objtype *ob, statetype *state)
ob->ticcount = 0;
if(!state)
{
return;
}
if (state->rightshapenum)
{
......
......@@ -10,8 +10,7 @@
CColorMerge::CColorMerge(const Uint8 speed) :
m_Speed(speed),
m_Alpha(0)
m_Speed(speed)
{
getSnapshot();
}
......@@ -21,18 +20,14 @@ void CColorMerge::getSnapshot()
{
gVideoDriver.collectSurfaces();
mpOldSurface.reset( gVideoDriver.convertThroughBlitSfc( gVideoDriver.mpVideoEngine->getBlitSurface() ), &SDL_FreeSurface );
mOldSurface.createFromSDLSfc(gVideoDriver.mpVideoEngine->getBlitSurface());
}
// Effect cycle
void CColorMerge::ponder(const float deltaT)
{
// Process the effect
#if SDL_VERSION_ATLEAST(2, 0, 0)
SDL_SetSurfaceAlphaMod( mpOldSurface.get(), 255-m_Alpha );
#else
SDL_SetAlpha( mpOldSurface.get(), SDL_SRCALPHA, 255-m_Alpha );
#endif
mOldSurface.setAlpha(255-m_Alpha);
const int sum = m_Alpha + m_Speed;
......@@ -49,8 +44,8 @@ void CColorMerge::ponder(const float deltaT)
void CColorMerge::render()
{
BlitSurface( mpOldSurface.get(), NULL,
gVideoDriver.getBlitSurface(), NULL );
GsWeakSurface weakBlit(gVideoDriver.getBlitSurface());
mOldSurface.blitTo(weakBlit);
}
......@@ -15,8 +15,7 @@
#include <memory>
#include <base/video/GsEffectController.h>
#include <graphics/GsSurface.h>
class CColorMerge : public CEffects
{
......@@ -25,18 +24,15 @@ public:
void ponder(const float deltaT);
void render();
std::shared_ptr<SDL_Surface> &getSfc()
{ return mpOldSurface; }
void getSnapshot();
private:
Uint8 m_Speed;
Uint8 m_Alpha;
Uint8 m_Speed = 0;
Uint8 m_Alpha = 0;
std::shared_ptr<SDL_Surface> mpOldSurface;
GsSurface mOldSurface;
};
#endif /* CCOLORMERGE_H_ */
......@@ -13,13 +13,9 @@ CFlash::CFlash(Uint32 msecs, Uint8 speed, Uint32 color) :
m_StartTime(gTimer.getTicks()),
m_RunTime(msecs),
m_Speed(speed),
m_Color(color),
m_Alpha(0),
m_FadeDir(FADE_IN),
m_Style(FADE_PULSE),
m_MaxAlpha(255),
mFadeSurface(gVideoDriver.convertThroughBlitSfc(gVideoDriver.getBlitSurface()))
m_Color(color)
{
mFadeSurface.createFromSDLSfc(gVideoDriver.getBlitSurface());
mFadeSurface.fill(m_Color);
}
......@@ -28,12 +24,10 @@ CFlash::CFlash(Uint32 msecs, Uint8 speed, Uint32 color, Uint8 m_maxalpha) :
m_RunTime(msecs),
m_Speed(speed),
m_Color(color),
m_Alpha(0),
m_FadeDir(FADE_IN),
m_Style(FADE_NORMAL),
m_MaxAlpha(m_maxalpha),
mFadeSurface(gVideoDriver.convertThroughBlitSfc(gVideoDriver.getBlitSurface()))
m_MaxAlpha(m_maxalpha)
{
mFadeSurface.createFromSDLSfc(gVideoDriver.getBlitSurface());
mFadeSurface.fill(m_Color);
}
......
......@@ -39,10 +39,10 @@ private:
Uint8 m_Speed;
Uint32 m_Color;
Uint8 m_Alpha;
fade_dir m_FadeDir;
Uint8 m_Style;
Uint8 m_MaxAlpha;
Uint8 m_Alpha = 0;
fade_dir m_FadeDir = FADE_IN;
Uint8 m_Style = FADE_PULSE;
Uint8 m_MaxAlpha = 255;
GsSurface mFadeSurface;
};
......
......@@ -23,8 +23,7 @@ mScrollPos(initialPos),
mHDir(hDir),
mVDir(vDir)
{
mpScrollSurface.reset( gVideoDriver.convertThroughBlitSfc(pScrollSurface), &SDL_FreeSurface );
mScrollSurface.createFromSDLSfc(pScrollSurface);
}
CScrollEffect::CScrollEffect(GsWeakSurface &scrollSurface,
......@@ -39,7 +38,7 @@ mScrollPos(initialPos),
mHDir(hDir),
mVDir(vDir)
{
mpScrollSurface.reset( gVideoDriver.convertThroughBlitSfc(scrollSurface.getSDLSurface()), &SDL_FreeSurface );
mScrollSurface.createCopy(scrollSurface);
}
void CScrollEffect::ponder(const float deltaT)
......@@ -73,12 +72,12 @@ void CScrollEffect::ponder(const float deltaT)
if(mVDir == DOWN)
{
posOldSfc = gVideoDriver.getBlitSurface()->h;
posScrollSfc = mpScrollSurface->h;
posScrollSfc = mScrollSurface.height();
}
else
{
posOldSfc = gVideoDriver.getBlitSurface()->w;
posScrollSfc = mpScrollSurface->w;
posScrollSfc = mScrollSurface.width();
}
......@@ -99,27 +98,25 @@ void CScrollEffect::render()
{
SDL_Rect gameres = gVideoDriver.getGameResolution().SDLRect();
SDL_Rect dest = gameres;
SDL_Rect src = mpScrollSurface->clip_rect;
SDL_Rect src = mScrollSurface.getSDLSurface()->clip_rect;
if(mVDir == DOWN)
{
src.y = mpScrollSurface->h-mScrollPos;
src.y = mScrollSurface.height()-mScrollPos;
dest.h = mScrollPos;
}
else if(mHDir == RIGHT)
{
src.x = mpScrollSurface->w-mScrollPos;
src.x = mScrollSurface.width()-mScrollPos;
dest.w = mScrollPos;
}
BlitSurface(mpScrollSurface.get(),
&src,
gVideoDriver.getBlitSurface(),
&dest);
GsWeakSurface blitWeak(gVideoDriver.getBlitSurface());
mScrollSurface.blitTo(blitWeak, src, dest);
}
Sint16 CScrollEffect::getScrollPosition()
int CScrollEffect::getScrollPosition()
{
return mScrollPos;
}
......
......@@ -36,7 +36,7 @@ public:
void ponder(const float deltaT);
void render();
Sint16 getScrollPosition();
int getScrollPosition();
private:
......@@ -46,8 +46,7 @@ private:
int mScrollPos = 0;
const direction_t mHDir;
const direction_t mVDir;
std::shared_ptr<SDL_Surface> mpOldSurface;
std::shared_ptr<SDL_Surface> mpScrollSurface;
GsSurface mOldSurface, mScrollSurface;
float mRemains = 0.0f;
};
......
#ifndef CG__VERSION_H
#define CG__VERSION_H
#define CGVERSION "2.0.2-Release"
#define CGVERSION "2.0.3-Release"
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment