aboutsummaryrefslogtreecommitdiff
path: root/engines/wintermute/BFader.cpp
diff options
context:
space:
mode:
authorEinar Johan Trøan Sømåen2012-03-06 03:09:12 +0100
committerEinar Johan Trøan Sømåen2012-06-02 12:12:22 +0200
commitb602b511607ac7bae911a5306bbe8301fdad4708 (patch)
tree9d58ffb57d434d8330e22c059239f7f0b1849487 /engines/wintermute/BFader.cpp
parent72a44cdc7b2040037a97f00c0c218b7f6bd9cd31 (diff)
downloadscummvm-rg350-b602b511607ac7bae911a5306bbe8301fdad4708.tar.gz
scummvm-rg350-b602b511607ac7bae911a5306bbe8301fdad4708.tar.bz2
scummvm-rg350-b602b511607ac7bae911a5306bbe8301fdad4708.zip
WINTERMUTE: Add the files for the rest of the B-classes.
Diffstat (limited to 'engines/wintermute/BFader.cpp')
-rw-r--r--engines/wintermute/BFader.cpp175
1 files changed, 175 insertions, 0 deletions
diff --git a/engines/wintermute/BFader.cpp b/engines/wintermute/BFader.cpp
new file mode 100644
index 0000000000..f64023a08d
--- /dev/null
+++ b/engines/wintermute/BFader.cpp
@@ -0,0 +1,175 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/*
+ * This file is based on WME Lite.
+ * http://dead-code.org/redir.php?target=wmelite
+ * Copyright (c) 2011 Jan Nedoma
+ */
+
+#include "dcgf.h"
+#include "BFader.h"
+#include "BGame.h"
+#include "PlatformSDL.h"
+
+namespace WinterMute {
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+IMPLEMENT_PERSISTENT(CBFader, false)
+
+//////////////////////////////////////////////////////////////////////////
+CBFader::CBFader(CBGame *inGame): CBObject(inGame) {
+ m_Active = false;
+ m_Red = m_Green = m_Blue = 0;
+ m_CurrentAlpha = 0x00;
+ m_SourceAlpha = 0;
+ m_TargetAlpha = 0;
+ m_Duration = 1000;
+ m_StartTime = 0;
+ m_System = false;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+CBFader::~CBFader() {
+
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+HRESULT CBFader::Update() {
+ if (!m_Active) return S_OK;
+
+ int AlphaDelta = m_TargetAlpha - m_SourceAlpha;
+
+ uint32 time;
+
+ if (m_System) time = CBPlatform::GetTime() - m_StartTime;
+ else time = Game->m_Timer - m_StartTime;
+
+ if (time >= m_Duration) m_CurrentAlpha = m_TargetAlpha;
+ else {
+ m_CurrentAlpha = m_SourceAlpha + (float)time / (float)m_Duration * AlphaDelta;
+ }
+ m_CurrentAlpha = MIN(255, std::max(m_CurrentAlpha, (byte )0));
+
+ m_Ready = time >= m_Duration;
+ if (m_Ready && m_CurrentAlpha == 0x00) m_Active = false;
+
+ return S_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+HRESULT CBFader::Display() {
+ if (!m_Active) return S_OK;
+
+ if (m_CurrentAlpha > 0x00) return Game->m_Renderer->FadeToColor(DRGBA(m_Red, m_Green, m_Blue, m_CurrentAlpha));
+ else return S_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+HRESULT CBFader::Deactivate() {
+ m_Active = false;
+ m_Ready = true;
+ return S_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+HRESULT CBFader::FadeIn(uint32 SourceColor, uint32 Duration, bool System) {
+ m_Ready = false;
+ m_Active = true;
+
+ m_Red = D3DCOLGetR(SourceColor);
+ m_Green = D3DCOLGetG(SourceColor);
+ m_Blue = D3DCOLGetB(SourceColor);
+
+ m_SourceAlpha = D3DCOLGetA(SourceColor);
+ m_TargetAlpha = 0;
+
+ m_Duration = Duration;
+ m_System = System;
+
+ if (m_System) m_StartTime = CBPlatform::GetTime();
+ else m_StartTime = Game->m_Timer;
+
+ return S_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+HRESULT CBFader::FadeOut(uint32 TargetColor, uint32 Duration, bool System) {
+ m_Ready = false;
+ m_Active = true;
+
+ m_Red = D3DCOLGetR(TargetColor);
+ m_Green = D3DCOLGetG(TargetColor);
+ m_Blue = D3DCOLGetB(TargetColor);
+
+ //m_SourceAlpha = 0;
+ m_SourceAlpha = m_CurrentAlpha;
+ m_TargetAlpha = D3DCOLGetA(TargetColor);
+
+ m_Duration = Duration;
+ m_System = System;
+
+ if (m_System) m_StartTime = CBPlatform::GetTime();
+ else m_StartTime = Game->m_Timer;
+
+
+ return S_OK;
+}
+
+
+//////////////////////////////////////////////////////////////////////////
+uint32 CBFader::GetCurrentColor() {
+ return DRGBA(m_Red, m_Green, m_Blue, m_CurrentAlpha);
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////
+HRESULT CBFader::Persist(CBPersistMgr *PersistMgr) {
+ CBObject::Persist(PersistMgr);
+
+ PersistMgr->Transfer(TMEMBER(m_Active));
+ PersistMgr->Transfer(TMEMBER(m_Blue));
+ PersistMgr->Transfer(TMEMBER(m_CurrentAlpha));
+ PersistMgr->Transfer(TMEMBER(m_Duration));
+ PersistMgr->Transfer(TMEMBER(m_Green));
+ PersistMgr->Transfer(TMEMBER(m_Red));
+ PersistMgr->Transfer(TMEMBER(m_SourceAlpha));
+ PersistMgr->Transfer(TMEMBER(m_StartTime));
+ PersistMgr->Transfer(TMEMBER(m_TargetAlpha));
+ PersistMgr->Transfer(TMEMBER(m_System));
+
+ if (m_System && !PersistMgr->m_Saving) m_StartTime = 0;
+
+ return S_OK;
+}
+
+} // end of namespace WinterMute