aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/gfx/staticbitmap.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2010-07-29 19:53:02 +0000
committerEugene Sandulenko2010-10-12 21:38:20 +0000
commita683a420a9e43705c972b5e74d55e319729e1a81 (patch)
treebde6e4abd417bdfaec120aa951da9a19be36b654 /engines/sword25/gfx/staticbitmap.cpp
parent7723d91c957d07205c51be32498d45cd0a78568f (diff)
downloadscummvm-rg350-a683a420a9e43705c972b5e74d55e319729e1a81.tar.gz
scummvm-rg350-a683a420a9e43705c972b5e74d55e319729e1a81.tar.bz2
scummvm-rg350-a683a420a9e43705c972b5e74d55e319729e1a81.zip
SWORD25: Importing original sources
svn-id: r53171
Diffstat (limited to 'engines/sword25/gfx/staticbitmap.cpp')
-rwxr-xr-xengines/sword25/gfx/staticbitmap.cpp218
1 files changed, 218 insertions, 0 deletions
diff --git a/engines/sword25/gfx/staticbitmap.cpp b/engines/sword25/gfx/staticbitmap.cpp
new file mode 100755
index 0000000000..34d89107f1
--- /dev/null
+++ b/engines/sword25/gfx/staticbitmap.cpp
@@ -0,0 +1,218 @@
+// -----------------------------------------------------------------------------
+// This file is part of Broken Sword 2.5
+// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer
+//
+// Broken Sword 2.5 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.
+//
+// Broken Sword 2.5 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 Broken Sword 2.5; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+// -----------------------------------------------------------------------------
+
+// -----------------------------------------------------------------------------
+// Includes
+// -----------------------------------------------------------------------------
+
+#include "staticbitmap.h"
+#include "bitmapresource.h"
+#include "package/packagemanager.h"
+#include "kernel/outputpersistenceblock.h"
+#include "kernel/inputpersistenceblock.h"
+
+// -----------------------------------------------------------------------------
+// Logging
+// -----------------------------------------------------------------------------
+
+#define BS_LOG_PREFIX "STATICBITMAP"
+
+// -----------------------------------------------------------------------------
+// Konstruktion / Destruktion
+// -----------------------------------------------------------------------------
+
+BS_StaticBitmap::BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const std::string& Filename) :
+ BS_Bitmap(ParentPtr, TYPE_STATICBITMAP)
+{
+ // Das BS_Bitmap konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
+ if (!m_InitSuccess) return;
+
+ m_InitSuccess = InitBitmapResource(Filename);
+}
+
+// -----------------------------------------------------------------------------
+
+BS_StaticBitmap::BS_StaticBitmap(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
+ BS_Bitmap(ParentPtr, TYPE_STATICBITMAP, Handle)
+{
+ m_InitSuccess = Unpersist(Reader);
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_StaticBitmap::InitBitmapResource(const std::string & Filename)
+{
+ // Bild-Resource laden
+ BS_Resource* ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(Filename);
+ if (!ResourcePtr)
+ {
+ BS_LOG_ERRORLN("Could not request resource \"%s\".", Filename.c_str());
+ return false;
+ }
+ if (ResourcePtr->GetType() != BS_Resource::TYPE_BITMAP)
+ {
+ BS_LOG_ERRORLN("Requested resource \"%s\" is not a bitmap.", Filename.c_str());
+ return false;
+ }
+
+ BS_BitmapResource * BitmapPtr = static_cast<BS_BitmapResource*>(ResourcePtr);
+
+ // Den eindeutigen Dateinamen zum späteren Referenzieren speichern
+ m_ResourceFilename = BitmapPtr->GetFileName();
+
+ // RenderObject Eigenschaften aktualisieren
+ m_OriginalWidth = m_Width = BitmapPtr->GetWidth();
+ m_OriginalHeight = m_Height = BitmapPtr->GetHeight();
+
+ // Bild-Resource freigeben
+ BitmapPtr->Release();
+
+ return true;
+}
+
+// -----------------------------------------------------------------------------
+
+BS_StaticBitmap::~BS_StaticBitmap()
+{
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_StaticBitmap::DoRender()
+{
+ // Bitmap holen
+ BS_Resource* ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
+ BS_ASSERT(ResourcePtr);
+ BS_ASSERT(ResourcePtr->GetType() == BS_Resource::TYPE_BITMAP);
+ BS_BitmapResource * BitmapResourcePtr = static_cast<BS_BitmapResource*>(ResourcePtr);
+
+ // Framebufferobjekt holen
+ BS_GraphicEngine * GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
+ BS_ASSERT(GfxPtr);
+
+ // Bitmap zeichnen
+ bool Result;
+ if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f)
+ {
+ Result = BitmapResourcePtr->Blit(m_AbsoluteX, m_AbsoluteY,
+ (m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
+ (m_FlipH ? BS_BitmapResource::FLIP_H : 0),
+ 0, m_ModulationColor, -1, -1);
+ }
+ else
+ {
+ Result = BitmapResourcePtr->Blit(m_AbsoluteX, m_AbsoluteY,
+ (m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
+ (m_FlipH ? BS_BitmapResource::FLIP_H : 0),
+ 0, m_ModulationColor, m_Width, m_Height);
+ }
+
+ // Resource freigeben
+ BitmapResourcePtr->Release();
+
+ return Result;
+}
+
+// -----------------------------------------------------------------------------
+
+unsigned int BS_StaticBitmap::GetPixel(int X, int Y) const
+{
+ BS_ASSERT(X >= 0 && X < m_Width);
+ BS_ASSERT(Y >= 0 && Y < m_Height);
+
+ BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
+ BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
+ BS_BitmapResource* pBitmapResource = static_cast<BS_BitmapResource*>(pResource);
+ unsigned int Result = pBitmapResource->GetPixel(X, Y);
+ pResource->Release();
+ return Result;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_StaticBitmap::SetContent(const std::vector<unsigned char> & Pixeldata, unsigned int Offset, unsigned int Stride)
+{
+ BS_LOG_ERRORLN("SetContent() ist not supported with this object.");
+ return false;
+}
+
+// -----------------------------------------------------------------------------
+// Auskunftsmethoden
+// -----------------------------------------------------------------------------
+
+bool BS_StaticBitmap::IsAlphaAllowed() const
+{
+ BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
+ BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
+ bool Result = static_cast<BS_BitmapResource*>(pResource)->IsAlphaAllowed();
+ pResource->Release();
+ return Result;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_StaticBitmap::IsColorModulationAllowed() const
+{
+ BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
+ BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
+ bool Result = static_cast<BS_BitmapResource*>(pResource)->IsColorModulationAllowed();
+ pResource->Release();
+ return Result;
+}
+
+// -----------------------------------------------------------------------------
+
+bool BS_StaticBitmap::IsScalingAllowed() const
+{
+ BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
+ BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
+ bool Result = static_cast<BS_BitmapResource*>(pResource)->IsScalingAllowed();
+ pResource->Release();
+ return Result;
+}
+
+// -----------------------------------------------------------------------------
+// Persistenz
+// -----------------------------------------------------------------------------
+
+bool BS_StaticBitmap::Persist(BS_OutputPersistenceBlock & Writer)
+{
+ bool Result = true;
+
+ Result &= BS_Bitmap::Persist(Writer);
+ Writer.Write(m_ResourceFilename);
+
+ Result &= BS_RenderObject::PersistChildren(Writer);
+
+ return Result;
+}
+
+bool BS_StaticBitmap::Unpersist(BS_InputPersistenceBlock & Reader)
+{
+ bool Result = true;
+
+ Result &= BS_Bitmap::Unpersist(Reader);
+ std::string ResourceFilename;
+ Reader.Read(ResourceFilename);
+ Result &= InitBitmapResource(ResourceFilename);
+
+ Result &= BS_RenderObject::UnpersistChildren(Reader);
+
+ return Reader.IsGood() && Result;
+}