Use a MyGUI widget to render the screen fader (Fixes #1741, Fixes #1719)

deque
scrawl 11 years ago
parent b58b8c6f8f
commit a18cec7c8e

@ -102,7 +102,6 @@ set(LIBDIR ${CMAKE_SOURCE_DIR}/libs)
set(OENGINE_OGRE set(OENGINE_OGRE
${LIBDIR}/openengine/ogre/renderer.cpp ${LIBDIR}/openengine/ogre/renderer.cpp
${LIBDIR}/openengine/ogre/fader.cpp
${LIBDIR}/openengine/ogre/lights.cpp ${LIBDIR}/openengine/ogre/lights.cpp
${LIBDIR}/openengine/ogre/selectionbuffer.cpp ${LIBDIR}/openengine/ogre/selectionbuffer.cpp
${LIBDIR}/openengine/ogre/imagerotate.cpp ${LIBDIR}/openengine/ogre/imagerotate.cpp

@ -33,7 +33,7 @@ add_openmw_dir (mwgui
merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks merchantrepair repair soulgemdialog companionwindow bookpage journalviewmodel journalbooks
keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview keywordsearch itemmodel containeritemmodel inventoryitemmodel sortfilteritemmodel itemview
tradeitemmodel companionitemmodel pickpocketitemmodel fontloader controllers savegamedialog tradeitemmodel companionitemmodel pickpocketitemmodel fontloader controllers savegamedialog
recharge mode videowidget backgroundimage itemwidget recharge mode videowidget backgroundimage itemwidget screenfader
) )
add_openmw_dir (mwdialogue add_openmw_dir (mwdialogue

@ -331,6 +331,15 @@ namespace MWBase
virtual void removeCurrentModal(MWGui::WindowModal* input) = 0; virtual void removeCurrentModal(MWGui::WindowModal* input) = 0;
virtual void pinWindow (MWGui::GuiWindow window) = 0; virtual void pinWindow (MWGui::GuiWindow window) = 0;
/// Fade the screen in, over \a time seconds
virtual void fadeScreenIn(const float time) = 0;
/// Fade the screen out to black, over \a time seconds
virtual void fadeScreenOut(const float time) = 0;
/// Fade the screen to a specified percentage of black, over \a time seconds
virtual void fadeScreenTo(const int percent, const float time) = 0;
/// Darken the screen by \a factor (1.0 = no darkening). Works independently from screen fading.
virtual void setScreenFactor (float factor) = 0;
}; };
} }

@ -17,11 +17,6 @@ namespace Ogre
namespace OEngine namespace OEngine
{ {
namespace Render
{
class Fader;
}
namespace Physic namespace Physic
{ {
class PhysicEngine; class PhysicEngine;
@ -113,9 +108,6 @@ namespace MWBase
virtual void readRecord (ESM::ESMReader& reader, int32_t type, virtual void readRecord (ESM::ESMReader& reader, int32_t type,
const std::map<int, int>& contentFileMap) = 0; const std::map<int, int>& contentFileMap) = 0;
virtual OEngine::Render::Fader* getFader() = 0;
///< \todo remove this function. Rendering details should not be exposed.
virtual MWWorld::CellStore *getExterior (int x, int y) = 0; virtual MWWorld::CellStore *getExterior (int x, int y) = 0;
virtual MWWorld::CellStore *getInterior (const std::string& name) = 0; virtual MWWorld::CellStore *getInterior (const std::string& name) = 0;

@ -0,0 +1,111 @@
#include "screenfader.hpp"
namespace MWGui
{
ScreenFader::ScreenFader()
: WindowBase("openmw_screen_fader.layout")
, mMode(FadingMode_In)
, mRemainingTime(0.f)
, mTargetTime(0.f)
, mTargetAlpha(0.f)
, mCurrentAlpha(0.f)
, mStartAlpha(0.f)
, mFactor(1.f)
{
mMainWidget->setSize(MyGUI::RenderManager::getInstance().getViewSize());
setVisible(false);
}
void ScreenFader::update(float dt)
{
if (mRemainingTime > 0)
{
if (mMode == FadingMode_In)
{
mCurrentAlpha -= dt/mTargetTime * (mStartAlpha-mTargetAlpha);
if (mCurrentAlpha < mTargetAlpha) mCurrentAlpha = mTargetAlpha;
}
else if (mMode == FadingMode_Out)
{
mCurrentAlpha += dt/mTargetTime * (mTargetAlpha-mStartAlpha);
if (mCurrentAlpha > mTargetAlpha) mCurrentAlpha = mTargetAlpha;
}
mRemainingTime -= dt;
}
if (1.f-((1.f-mCurrentAlpha) * mFactor) == 0.f)
mMainWidget->setVisible(false);
else
applyAlpha();
}
void ScreenFader::applyAlpha()
{
setVisible(true);
mMainWidget->setAlpha(1.f-((1.f-mCurrentAlpha) * mFactor));
}
void ScreenFader::fadeIn(float time)
{
if (time<0.f) return;
if (time==0.f)
{
mCurrentAlpha = 0.f;
applyAlpha();
return;
}
mStartAlpha = mCurrentAlpha;
mTargetAlpha = 0.f;
mMode = FadingMode_In;
mTargetTime = time;
mRemainingTime = time;
}
void ScreenFader::fadeOut(const float time)
{
if (time<0.f) return;
if (time==0.f)
{
mCurrentAlpha = 1.f;
applyAlpha();
return;
}
mStartAlpha = mCurrentAlpha;
mTargetAlpha = 1.f;
mMode = FadingMode_Out;
mTargetTime = time;
mRemainingTime = time;
}
void ScreenFader::fadeTo(const int percent, const float time)
{
if (time<0.f) return;
if (time==0.f)
{
mCurrentAlpha = percent/100.f;
applyAlpha();
return;
}
mStartAlpha = mCurrentAlpha;
mTargetAlpha = percent/100.f;
if (mTargetAlpha == mStartAlpha) return;
else if (mTargetAlpha > mStartAlpha) mMode = FadingMode_Out;
else mMode = FadingMode_In;
mTargetTime = time;
mRemainingTime = time;
}
void ScreenFader::setFactor(float factor)
{
mFactor = factor;
}
}

@ -0,0 +1,39 @@
#include "windowbase.hpp"
namespace MWGui
{
class ScreenFader : public WindowBase
{
public:
ScreenFader();
void update(float dt);
void fadeIn(const float time);
void fadeOut(const float time);
void fadeTo(const int percent, const float time);
void setFactor (float factor);
private:
enum FadingMode
{
FadingMode_In,
FadingMode_Out
};
void applyAlpha();
FadingMode mMode;
float mRemainingTime;
float mTargetTime;
float mTargetAlpha;
float mCurrentAlpha;
float mStartAlpha;
float mFactor;
};
}

@ -2,8 +2,6 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <openengine/ogre/fader.hpp>
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
@ -171,7 +169,7 @@ namespace MWGui
MWBase::Environment::get().getMechanicsManager()->rest(false); MWBase::Environment::get().getMechanicsManager()->rest(false);
MWBase::Environment::get().getMechanicsManager()->rest(false); MWBase::Environment::get().getMechanicsManager()->rest(false);
MWBase::Environment::get().getWorld ()->getFader()->fadeOut(0.25); MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.25);
mFadeTimeRemaining = 0.5; mFadeTimeRemaining = 0.5;
} }
@ -183,6 +181,6 @@ namespace MWGui
mFadeTimeRemaining -= dt; mFadeTimeRemaining -= dt;
if (mFadeTimeRemaining <= 0) if (mFadeTimeRemaining <= 0)
MWBase::Environment::get().getWorld ()->getFader()->fadeIn(0.25); MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.25);
} }
} }

@ -4,8 +4,6 @@
#include <OgreVector3.h> #include <OgreVector3.h>
#include <libs/openengine/ogre/fader.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
@ -156,7 +154,7 @@ namespace MWGui
MWMechanics::CreatureStats& npcStats = mPtr.getClass().getCreatureStats(mPtr); MWMechanics::CreatureStats& npcStats = mPtr.getClass().getCreatureStats(mPtr);
npcStats.setGoldPool(npcStats.getGoldPool() + price); npcStats.setGoldPool(npcStats.getGoldPool() + price);
MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(1); MWBase::Environment::get().getWindowManager()->fadeScreenOut(1);
ESM::Position pos = *_sender->getUserData<ESM::Position>(); ESM::Position pos = *_sender->getUserData<ESM::Position>();
std::string cellname = _sender->getUserString("Destination"); std::string cellname = _sender->getUserString("Destination");
bool interior = _sender->getUserString("interior") == "y"; bool interior = _sender->getUserString("interior") == "y";
@ -179,8 +177,8 @@ namespace MWGui
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Travel); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Travel);
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Dialogue); MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Dialogue);
MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0); MWBase::Environment::get().getWindowManager()->fadeScreenOut(0);
MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(1); MWBase::Environment::get().getWindowManager()->fadeScreenIn(1);
} }
void TravelWindow::onCancelButtonClicked(MyGUI::Widget* _sender) void TravelWindow::onCancelButtonClicked(MyGUI::Widget* _sender)

@ -2,8 +2,6 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <libs/openengine/ogre/fader.hpp>
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
@ -128,7 +126,7 @@ namespace MWGui
MWBase::Environment::get().getStateManager()->quickSave("Autosave"); MWBase::Environment::get().getStateManager()->quickSave("Autosave");
MWBase::World* world = MWBase::Environment::get().getWorld(); MWBase::World* world = MWBase::Environment::get().getWorld();
world->getFader ()->fadeOut(0.2); MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.2);
setVisible(false); setVisible(false);
mProgressBar.setVisible (true); mProgressBar.setVisible (true);
@ -243,7 +241,7 @@ namespace MWGui
void WaitDialog::stopWaiting () void WaitDialog::stopWaiting ()
{ {
MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(0.2); MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.2);
mProgressBar.setVisible (false); mProgressBar.setVisible (false);
MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Rest); MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Rest);
MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_RestBed); MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_RestBed);

@ -65,6 +65,7 @@
#include "videowidget.hpp" #include "videowidget.hpp"
#include "backgroundimage.hpp" #include "backgroundimage.hpp"
#include "itemwidget.hpp" #include "itemwidget.hpp"
#include "screenfader.hpp"
namespace MWGui namespace MWGui
{ {
@ -112,6 +113,7 @@ namespace MWGui
, mCompanionWindow(NULL) , mCompanionWindow(NULL)
, mVideoBackground(NULL) , mVideoBackground(NULL)
, mVideoWidget(NULL) , mVideoWidget(NULL)
, mScreenFader(NULL)
, mTranslationDataStorage (translationDataStorage) , mTranslationDataStorage (translationDataStorage)
, mCharGen(NULL) , mCharGen(NULL)
, mInputBlocker(NULL) , mInputBlocker(NULL)
@ -267,6 +269,7 @@ namespace MWGui
mSoulgemDialog = new SoulgemDialog(mMessageBoxManager); mSoulgemDialog = new SoulgemDialog(mMessageBoxManager);
mCompanionWindow = new CompanionWindow(mDragAndDrop, mMessageBoxManager); mCompanionWindow = new CompanionWindow(mDragAndDrop, mMessageBoxManager);
trackWindow(mCompanionWindow, "companion"); trackWindow(mCompanionWindow, "companion");
mScreenFader = new ScreenFader();
mInputBlocker = mGui->createWidget<MyGUI::Widget>("",0,0,w,h,MyGUI::Align::Default,"Overlay"); mInputBlocker = mGui->createWidget<MyGUI::Widget>("",0,0,w,h,MyGUI::Align::Default,"Overlay");
@ -357,6 +360,7 @@ namespace MWGui
delete mCursorManager; delete mCursorManager;
delete mRecharge; delete mRecharge;
delete mCompanionWindow; delete mCompanionWindow;
delete mScreenFader;
cleanupGarbage(); cleanupGarbage();
@ -858,6 +862,8 @@ namespace MWGui
mCompanionWindow->checkReferenceAvailable(); mCompanionWindow->checkReferenceAvailable();
mConsole->checkReferenceAvailable(); mConsole->checkReferenceAvailable();
mCompanionWindow->onFrame(); mCompanionWindow->onFrame();
mScreenFader->update(frameDuration);
} }
void WindowManager::changeCell(MWWorld::CellStore* cell) void WindowManager::changeCell(MWWorld::CellStore* cell)
@ -1688,4 +1694,24 @@ namespace MWGui
updateVisible(); updateVisible();
} }
void WindowManager::fadeScreenIn(const float time)
{
mScreenFader->fadeIn(time);
}
void WindowManager::fadeScreenOut(const float time)
{
mScreenFader->fadeOut(time);
}
void WindowManager::fadeScreenTo(const int percent, const float time)
{
mScreenFader->fadeTo(percent, time);
}
void WindowManager::setScreenFactor(float factor)
{
mScreenFader->setFactor(factor);
}
} }

@ -86,6 +86,7 @@ namespace MWGui
class CompanionWindow; class CompanionWindow;
class VideoWidget; class VideoWidget;
class WindowModal; class WindowModal;
class ScreenFader;
class WindowManager : public MWBase::WindowManager class WindowManager : public MWBase::WindowManager
{ {
@ -324,6 +325,15 @@ namespace MWGui
virtual void pinWindow (MWGui::GuiWindow window); virtual void pinWindow (MWGui::GuiWindow window);
/// Fade the screen in, over \a time seconds
virtual void fadeScreenIn(const float time);
/// Fade the screen out to black, over \a time seconds
virtual void fadeScreenOut(const float time);
/// Fade the screen to a specified percentage of black, over \a time seconds
virtual void fadeScreenTo(const int percent, const float time);
/// Darken the screen by \a factor (1.0 = no darkening). Works independently from screen fading.
virtual void setScreenFactor (float factor);
private: private:
bool mConsoleOnlyScripts; bool mConsoleOnlyScripts;
@ -373,6 +383,7 @@ namespace MWGui
CompanionWindow* mCompanionWindow; CompanionWindow* mCompanionWindow;
MyGUI::ImageBox* mVideoBackground; MyGUI::ImageBox* mVideoBackground;
VideoWidget* mVideoWidget; VideoWidget* mVideoWidget;
ScreenFader* mScreenFader;
Translation::Storage& mTranslationDataStorage; Translation::Storage& mTranslationDataStorage;
Cursor* mSoftwareCursor; Cursor* mSoftwareCursor;

@ -212,11 +212,6 @@ MWRender::Actors& RenderingManager::getActors(){
return *mActors; return *mActors;
} }
OEngine::Render::Fader* RenderingManager::getFader()
{
return mRendering.getFader();
}
MWRender::Camera* RenderingManager::getCamera() const MWRender::Camera* RenderingManager::getCamera() const
{ {
return mCamera; return mCamera;
@ -345,7 +340,7 @@ void RenderingManager::update (float duration, bool paused)
MWWorld::Ptr player = world->getPlayerPtr(); MWWorld::Ptr player = world->getPlayerPtr();
int blind = player.getClass().getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::Blind).mMagnitude; int blind = player.getClass().getCreatureStats(player).getMagicEffects().get(ESM::MagicEffect::Blind).mMagnitude;
mRendering.getFader()->setFactor(std::max(0.f, 1.f-(blind / 100.f))); MWBase::Environment::get().getWindowManager()->setScreenFactor(std::max(0.f, 1.f-(blind / 100.f)));
setAmbientMode(); setAmbientMode();
// player position // player position

@ -4,8 +4,6 @@
#include "sky.hpp" #include "sky.hpp"
#include "debugging.hpp" #include "debugging.hpp"
#include <openengine/ogre/fader.hpp>
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
@ -98,8 +96,6 @@ public:
void toggleLight(); void toggleLight();
bool toggleRenderMode(int mode); bool toggleRenderMode(int mode);
OEngine::Render::Fader* getFader();
void removeCell (MWWorld::CellStore *store); void removeCell (MWWorld::CellStore *store);
/// \todo this function should be removed later. Instead the rendering subsystems should track /// \todo this function should be removed later. Instead the rendering subsystems should track

@ -3,8 +3,6 @@
#include <cstdlib> #include <cstdlib>
#include <libs/openengine/ogre/fader.hpp>
#include <components/compiler/extensions.hpp> #include <components/compiler/extensions.hpp>
#include <components/compiler/opcodes.hpp> #include <components/compiler/opcodes.hpp>
#include <components/compiler/locals.hpp> #include <components/compiler/locals.hpp>
@ -248,7 +246,7 @@ namespace MWScript
Interpreter::Type_Float time = runtime[0].mFloat; Interpreter::Type_Float time = runtime[0].mFloat;
runtime.pop(); runtime.pop();
MWBase::Environment::get().getWorld()->getFader()->fadeIn(time); MWBase::Environment::get().getWindowManager()->fadeScreenIn(time);
} }
}; };
@ -261,7 +259,7 @@ namespace MWScript
Interpreter::Type_Float time = runtime[0].mFloat; Interpreter::Type_Float time = runtime[0].mFloat;
runtime.pop(); runtime.pop();
MWBase::Environment::get().getWorld()->getFader()->fadeOut(time); MWBase::Environment::get().getWindowManager()->fadeScreenOut(time);
} }
}; };
@ -277,7 +275,7 @@ namespace MWScript
Interpreter::Type_Float time = runtime[0].mFloat; Interpreter::Type_Float time = runtime[0].mFloat;
runtime.pop(); runtime.pop();
MWBase::Environment::get().getWorld()->getFader()->fadeTo(alpha, time); MWBase::Environment::get().getWindowManager()->fadeScreenTo(alpha, time);
} }
}; };

@ -4,8 +4,6 @@
#include <components/nif/niffile.hpp> #include <components/nif/niffile.hpp>
#include <libs/openengine/ogre/fader.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" /// FIXME #include "../mwbase/world.hpp" /// FIXME
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
@ -406,7 +404,7 @@ namespace MWWorld
void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position) void Scene::changeToInteriorCell (const std::string& cellName, const ESM::Position& position)
{ {
Nif::NIFFile::CacheLock lock; Nif::NIFFile::CacheLock lock;
MWBase::Environment::get().getWorld ()->getFader ()->fadeOut(0.5); MWBase::Environment::get().getWindowManager()->fadeScreenOut(0.5);
Loading::Listener* loadingListener = MWBase::Environment::get().getWindowManager()->getLoadingScreen(); Loading::Listener* loadingListener = MWBase::Environment::get().getWindowManager()->getLoadingScreen();
Loading::ScopedLoad load(loadingListener); Loading::ScopedLoad load(loadingListener);
@ -432,7 +430,7 @@ namespace MWWorld
world->rotateObject(world->getPlayerPtr(), x, y, z); world->rotateObject(world->getPlayerPtr(), x, y, z);
world->getPlayerPtr().getClass().adjustPosition(world->getPlayerPtr(), true); world->getPlayerPtr().getClass().adjustPosition(world->getPlayerPtr(), true);
world->getFader()->fadeIn(0.5f); MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5);
return; return;
} }
@ -480,7 +478,7 @@ namespace MWWorld
MWBase::Environment::get().getWorld()->adjustSky(); MWBase::Environment::get().getWorld()->adjustSky();
mCellChanged = true; mCellChanged = true;
MWBase::Environment::get().getWorld ()->getFader ()->fadeIn(0.5); MWBase::Environment::get().getWindowManager()->fadeScreenIn(0.5);
} }
void Scene::changeToExteriorCell (const ESM::Position& position) void Scene::changeToExteriorCell (const ESM::Position& position)

@ -1555,11 +1555,6 @@ namespace MWWorld
mWeatherManager->modRegion(regionid, chances); mWeatherManager->modRegion(regionid, chances);
} }
OEngine::Render::Fader* World::getFader()
{
return mRendering->getFader();
}
Ogre::Vector2 World::getNorthVector (CellStore* cell) Ogre::Vector2 World::getNorthVector (CellStore* cell)
{ {
MWWorld::CellRefList<ESM::Static>& statics = cell->get<ESM::Static>(); MWWorld::CellRefList<ESM::Static>& statics = cell->get<ESM::Static>();

@ -169,9 +169,6 @@ namespace MWWorld
virtual void readRecord (ESM::ESMReader& reader, int32_t type, virtual void readRecord (ESM::ESMReader& reader, int32_t type,
const std::map<int, int>& contentFileMap); const std::map<int, int>& contentFileMap);
virtual OEngine::Render::Fader* getFader();
///< \todo remove this function. Rendering details should not be exposed.
virtual CellStore *getExterior (int x, int y); virtual CellStore *getExterior (int x, int y);
virtual CellStore *getInterior (const std::string& name); virtual CellStore *getInterior (const std::string& name);

@ -80,6 +80,7 @@ set(MYGUI_FILES
openmw_companion_window.layout openmw_companion_window.layout
openmw_savegame_dialog.layout openmw_savegame_dialog.layout
openmw_recharge_dialog.layout openmw_recharge_dialog.layout
openmw_screen_fader.layout
DejaVuLGCSansMono.ttf DejaVuLGCSansMono.ttf
markers.png markers.png
../launcher/images/openmw.png ../launcher/images/openmw.png

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layer"> <MyGUI type="Layer">
<Layer name="Render" overlapped="false" peek="false"/>
<Layer name="HUD" overlapped="false" peek="true"/> <Layer name="HUD" overlapped="false" peek="true"/>
<Layer name="Menu" overlapped="false" peek="false"/> <Layer name="Menu" overlapped="false" peek="false"/>
<Layer name="Windows" overlapped="true" peek="true"/> <Layer name="Windows" overlapped="true" peek="true"/>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout">
<Widget type="ImageBox" skin="ImageBox" layer="Render" position="0 0 300 200" name="_Main" align="Stretch">
<Property key="ImageTexture" value="black.png"/>
</Widget>
</MyGUI>

@ -1,136 +0,0 @@
#include "fader.hpp"
#include <OgreMaterial.h>
#include <OgreTechnique.h>
#include <OgreMaterialManager.h>
#include <OgreResourceGroupManager.h>
#include <OgreRectangle2D.h>
#include <OgreSceneManager.h>
#include <OgreSceneNode.h>
using namespace Ogre;
using namespace OEngine::Render;
Fader::Fader(Ogre::SceneManager* sceneMgr)
: mSceneMgr(sceneMgr)
, mMode(FadingMode_In)
, mRemainingTime(0.f)
, mTargetTime(0.f)
, mTargetAlpha(0.f)
, mCurrentAlpha(0.f)
, mStartAlpha(0.f)
, mFactor(1.f)
{
// Create the fading material
MaterialPtr material = MaterialManager::getSingleton().create("FadeInOutMaterial", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
Pass* pass = material->getTechnique(0)->getPass(0);
pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
pass->setDepthWriteEnabled (false);
mFadeTextureUnit = pass->createTextureUnitState("black.png");
mFadeTextureUnit->setColourOperationEx(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, ColourValue(0.f, 0.f, 0.f)); // always black colour
mRectangle = new Ogre::Rectangle2D(true);
mRectangle->setCorners(-1.0, 1.0, 1.0, -1.0);
mRectangle->setMaterial("FadeInOutMaterial");
mRectangle->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY-1);
// Use infinite AAB to always stay visible
Ogre::AxisAlignedBox aabInf;
aabInf.setInfinite();
mRectangle->setBoundingBox(aabInf);
// Attach background to the scene
Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
node->attachObject(mRectangle);
mRectangle->setVisible(false);
mRectangle->setVisibilityFlags (2048);
}
Fader::~Fader()
{
delete mRectangle;
}
void Fader::update(float dt)
{
if (mRemainingTime > 0)
{
if (mMode == FadingMode_In)
{
mCurrentAlpha -= dt/mTargetTime * (mStartAlpha-mTargetAlpha);
if (mCurrentAlpha < mTargetAlpha) mCurrentAlpha = mTargetAlpha;
}
else if (mMode == FadingMode_Out)
{
mCurrentAlpha += dt/mTargetTime * (mTargetAlpha-mStartAlpha);
if (mCurrentAlpha > mTargetAlpha) mCurrentAlpha = mTargetAlpha;
}
mRemainingTime -= dt;
}
if (1.f-((1.f-mCurrentAlpha) * mFactor) == 0.f)
mRectangle->setVisible(false);
else
applyAlpha();
}
void Fader::applyAlpha()
{
mRectangle->setVisible(true);
mFadeTextureUnit->setAlphaOperation(LBX_SOURCE1, LBS_MANUAL, LBS_CURRENT, 1.f-((1.f-mCurrentAlpha) * mFactor));
}
void Fader::fadeIn(float time)
{
if (time<0.f) return;
if (time==0.f)
{
mCurrentAlpha = 0.f;
applyAlpha();
return;
}
mStartAlpha = mCurrentAlpha;
mTargetAlpha = 0.f;
mMode = FadingMode_In;
mTargetTime = time;
mRemainingTime = time;
}
void Fader::fadeOut(const float time)
{
if (time<0.f) return;
if (time==0.f)
{
mCurrentAlpha = 1.f;
applyAlpha();
return;
}
mStartAlpha = mCurrentAlpha;
mTargetAlpha = 1.f;
mMode = FadingMode_Out;
mTargetTime = time;
mRemainingTime = time;
}
void Fader::fadeTo(const int percent, const float time)
{
if (time<0.f) return;
if (time==0.f)
{
mCurrentAlpha = percent/100.f;
applyAlpha();
return;
}
mStartAlpha = mCurrentAlpha;
mTargetAlpha = percent/100.f;
if (mTargetAlpha == mStartAlpha) return;
else if (mTargetAlpha > mStartAlpha) mMode = FadingMode_Out;
else mMode = FadingMode_In;
mTargetTime = time;
mRemainingTime = time;
}

@ -1,59 +0,0 @@
#ifndef OENGINE_OGRE_FADE_H
#define OENGINE_OGRE_FADE_H
/*
A class that handles fading in the screen from black or fading it out to black.
To achieve this, it uses a full-screen Rectangle2d
*/
namespace Ogre
{
class TextureUnitState;
class Rectangle2D;
class SceneManager;
}
namespace OEngine {
namespace Render
{
class Fader
{
public:
Fader(Ogre::SceneManager* sceneMgr);
~Fader();
void update(float dt);
void fadeIn(const float time);
void fadeOut(const float time);
void fadeTo(const int percent, const float time);
void setFactor (float factor) { mFactor = factor; }
private:
enum FadingMode
{
FadingMode_In,
FadingMode_Out
};
void applyAlpha();
Ogre::TextureUnitState* mFadeTextureUnit;
Ogre::Rectangle2D* mRectangle;
FadingMode mMode;
float mRemainingTime;
float mTargetTime;
float mTargetAlpha;
float mCurrentAlpha;
float mStartAlpha;
float mFactor;
Ogre::SceneManager* mSceneMgr;
};
}}
#endif

@ -1,5 +1,4 @@
#include "renderer.hpp" #include "renderer.hpp"
#include "fader.hpp"
#include <SDL.h> #include <SDL.h>
@ -27,9 +26,6 @@ using namespace OEngine::Render;
void OgreRenderer::cleanup() void OgreRenderer::cleanup()
{ {
delete mFader;
mFader = NULL;
if (mWindow) if (mWindow)
Ogre::Root::getSingleton().destroyRenderTarget(mWindow); Ogre::Root::getSingleton().destroyRenderTarget(mWindow);
mWindow = NULL; mWindow = NULL;
@ -46,7 +42,6 @@ void OgreRenderer::cleanup()
void OgreRenderer::update(float dt) void OgreRenderer::update(float dt)
{ {
mFader->update(dt);
} }
void OgreRenderer::screenshot(const std::string &file) void OgreRenderer::screenshot(const std::string &file)
@ -161,8 +156,6 @@ void OgreRenderer::createWindow(const std::string &title, const WindowSettings&
mScene = mRoot->createSceneManager(ST_GENERIC); mScene = mRoot->createSceneManager(ST_GENERIC);
mFader = new Fader(mScene);
mCamera = mScene->createCamera("cam"); mCamera = mScene->createCamera("cam");
// Create one viewport, entire window // Create one viewport, entire window

@ -43,8 +43,6 @@ namespace OEngine
std::string icon; std::string icon;
}; };
class Fader;
class WindowSizeListener class WindowSizeListener
{ {
public: public:
@ -62,8 +60,6 @@ namespace OEngine
OgreInit::OgreInit* mOgreInit; OgreInit::OgreInit* mOgreInit;
Fader* mFader;
WindowSizeListener* mWindowListener; WindowSizeListener* mWindowListener;
int mWindowWidth; int mWindowWidth;
@ -79,7 +75,6 @@ namespace OEngine
, mCamera(NULL) , mCamera(NULL)
, mView(NULL) , mView(NULL)
, mOgreInit(NULL) , mOgreInit(NULL)
, mFader(NULL)
, mWindowListener(NULL) , mWindowListener(NULL)
, mWindowWidth(0) , mWindowWidth(0)
, mWindowHeight(0) , mWindowHeight(0)
@ -131,9 +126,6 @@ namespace OEngine
/// Get the scene manager /// Get the scene manager
Ogre::SceneManager *getScene() { return mScene; } Ogre::SceneManager *getScene() { return mScene; }
/// Get the screen colour fader
Fader *getFader() { return mFader; }
/// Camera /// Camera
Ogre::Camera *getCamera() { return mCamera; } Ogre::Camera *getCamera() { return mCamera; }

Loading…
Cancel
Save