2010-07-31 09:53:02 +00:00
|
|
|
|
/* 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.
|
|
|
|
|
*
|
|
|
|
|
* $URL$
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2010-08-06 13:13:25 +00:00
|
|
|
|
/*
|
2010-07-31 09:53:02 +00:00
|
|
|
|
* This code is based on Broken Sword 2.5 engine
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
|
|
|
|
*
|
|
|
|
|
* Licensed under GNU GPL v2
|
|
|
|
|
*
|
|
|
|
|
*/
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Includes
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-07-30 09:02:39 +00:00
|
|
|
|
#include "sword25/gfx/staticbitmap.h"
|
|
|
|
|
#include "sword25/gfx/bitmapresource.h"
|
|
|
|
|
#include "sword25/package/packagemanager.h"
|
|
|
|
|
#include "sword25/kernel/outputpersistenceblock.h"
|
|
|
|
|
#include "sword25/kernel/inputpersistenceblock.h"
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-08-05 12:48:19 +00:00
|
|
|
|
namespace Sword25 {
|
|
|
|
|
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Logging
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#define BS_LOG_PREFIX "STATICBITMAP"
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Konstruktion / Destruktion
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
StaticBitmap::StaticBitmap(RenderObjectPtr<RenderObject> parentPtr, const Common::String &filename) :
|
|
|
|
|
Bitmap(parentPtr, TYPE_STATICBITMAP) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Das BS_Bitmap konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
2010-09-02 17:11:45 +00:00
|
|
|
|
if (!_initSuccess)
|
|
|
|
|
return;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
_initSuccess = initBitmapResource(filename);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
StaticBitmap::StaticBitmap(InputPersistenceBlock &reader, RenderObjectPtr<RenderObject> parentPtr, uint handle) :
|
|
|
|
|
Bitmap(parentPtr, TYPE_STATICBITMAP, handle) {
|
|
|
|
|
_initSuccess = unpersist(reader);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool StaticBitmap::initBitmapResource(const Common::String &filename) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Bild-Resource laden
|
2010-09-02 17:11:45 +00:00
|
|
|
|
Resource *resourcePtr = Kernel::GetInstance()->GetResourceManager()->RequestResource(filename);
|
|
|
|
|
if (!resourcePtr) {
|
|
|
|
|
BS_LOG_ERRORLN("Could not request resource \"%s\".", filename.c_str());
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-09-02 17:11:45 +00:00
|
|
|
|
if (resourcePtr->GetType() != Resource::TYPE_BITMAP) {
|
|
|
|
|
BS_LOG_ERRORLN("Requested resource \"%s\" is not a bitmap.", filename.c_str());
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
BitmapResource *bitmapPtr = static_cast<BitmapResource *>(resourcePtr);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Den eindeutigen Dateinamen zum sp<73>teren Referenzieren speichern
|
2010-09-02 17:11:45 +00:00
|
|
|
|
_resourceFilename = bitmapPtr->getFileName();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// RenderObject Eigenschaften aktualisieren
|
2010-09-02 17:11:45 +00:00
|
|
|
|
_originalWidth = _width = bitmapPtr->getWidth();
|
|
|
|
|
_originalHeight = _height = bitmapPtr->getHeight();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Bild-Resource freigeben
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bitmapPtr->release();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
StaticBitmap::~StaticBitmap() {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool StaticBitmap::doRender() {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Bitmap holen
|
2010-09-02 17:11:45 +00:00
|
|
|
|
Resource *resourcePtr = Kernel::GetInstance()->GetResourceManager()->RequestResource(_resourceFilename);
|
|
|
|
|
BS_ASSERT(resourcePtr);
|
|
|
|
|
BS_ASSERT(resourcePtr->GetType() == Resource::TYPE_BITMAP);
|
|
|
|
|
BitmapResource *bitmapResourcePtr = static_cast<BitmapResource *>(resourcePtr);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Framebufferobjekt holen
|
2010-09-02 17:11:45 +00:00
|
|
|
|
GraphicEngine *gfxPtr = static_cast<GraphicEngine *>(Kernel::GetInstance()->GetService("gfx"));
|
|
|
|
|
BS_ASSERT(gfxPtr);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Bitmap zeichnen
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool result;
|
|
|
|
|
if (_scaleFactorX == 1.0f && _scaleFactorY == 1.0f) {
|
|
|
|
|
result = bitmapResourcePtr->blit(_absoluteX, _absoluteY,
|
|
|
|
|
(_flipV ? BitmapResource::FLIP_V : 0) |
|
|
|
|
|
(_flipH ? BitmapResource::FLIP_H : 0),
|
|
|
|
|
0, _modulationColor, -1, -1);
|
2010-08-06 13:13:25 +00:00
|
|
|
|
} else {
|
2010-09-02 17:11:45 +00:00
|
|
|
|
result = bitmapResourcePtr->blit(_absoluteX, _absoluteY,
|
|
|
|
|
(_flipV ? BitmapResource::FLIP_V : 0) |
|
|
|
|
|
(_flipH ? BitmapResource::FLIP_H : 0),
|
|
|
|
|
0, _modulationColor, _width, _height);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resource freigeben
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bitmapResourcePtr->release();
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
return result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
uint StaticBitmap::getPixel(int x, int y) const {
|
|
|
|
|
BS_ASSERT(x >= 0 && x < _width);
|
|
|
|
|
BS_ASSERT(y >= 0 && y < _height);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
Resource *pResource = Kernel::GetInstance()->GetResourceManager()->RequestResource(_resourceFilename);
|
2010-08-18 12:58:22 +00:00
|
|
|
|
BS_ASSERT(pResource->GetType() == Resource::TYPE_BITMAP);
|
2010-08-18 10:52:24 +00:00
|
|
|
|
BitmapResource *pBitmapResource = static_cast<BitmapResource *>(pResource);
|
2010-09-02 17:11:45 +00:00
|
|
|
|
uint result = pBitmapResource->getPixel(x, y);
|
|
|
|
|
pResource->release();
|
|
|
|
|
return result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool StaticBitmap::setContent(const byte *pixeldata, uint size, uint offset, uint stride) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_LOG_ERRORLN("SetContent() ist not supported with this object.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Auskunftsmethoden
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool StaticBitmap::isAlphaAllowed() const {
|
|
|
|
|
Resource *pResource = Kernel::GetInstance()->GetResourceManager()->RequestResource(_resourceFilename);
|
2010-08-18 12:58:22 +00:00
|
|
|
|
BS_ASSERT(pResource->GetType() == Resource::TYPE_BITMAP);
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool result = static_cast<BitmapResource *>(pResource)->isAlphaAllowed();
|
|
|
|
|
pResource->release();
|
|
|
|
|
return result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool StaticBitmap::isColorModulationAllowed() const {
|
|
|
|
|
Resource *pResource = Kernel::GetInstance()->GetResourceManager()->RequestResource(_resourceFilename);
|
2010-08-18 12:58:22 +00:00
|
|
|
|
BS_ASSERT(pResource->GetType() == Resource::TYPE_BITMAP);
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool result = static_cast<BitmapResource *>(pResource)->isColorModulationAllowed();
|
|
|
|
|
pResource->release();
|
|
|
|
|
return result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool StaticBitmap::isScalingAllowed() const {
|
|
|
|
|
Resource *pResource = Kernel::GetInstance()->GetResourceManager()->RequestResource(_resourceFilename);
|
2010-08-18 12:58:22 +00:00
|
|
|
|
BS_ASSERT(pResource->GetType() == Resource::TYPE_BITMAP);
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool result = static_cast<BitmapResource *>(pResource)->isScalingAllowed();
|
|
|
|
|
pResource->release();
|
|
|
|
|
return result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Persistenz
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool StaticBitmap::persist(OutputPersistenceBlock &writer) {
|
|
|
|
|
bool result = true;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
result &= Bitmap::persist(writer);
|
|
|
|
|
writer.write(_resourceFilename);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
result &= RenderObject::persistChildren(writer);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
return result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
bool StaticBitmap::unpersist(InputPersistenceBlock &reader) {
|
|
|
|
|
bool result = true;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
result &= Bitmap::unpersist(reader);
|
|
|
|
|
Common::String resourceFilename;
|
|
|
|
|
reader.read(resourceFilename);
|
|
|
|
|
result &= initBitmapResource(resourceFilename);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
result &= RenderObject::unpersistChildren(reader);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-09-02 17:11:45 +00:00
|
|
|
|
return reader.isGood() && result;
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
2010-08-05 12:48:19 +00:00
|
|
|
|
|
|
|
|
|
} // End of namespace Sword25
|