SWORD25: Mass-astyle.
svn-id: r53222
This commit is contained in:
parent
ca17def625
commit
47904bc7b2
146 changed files with 5057 additions and 5644 deletions
|
@ -38,7 +38,9 @@ namespace Sword25 {
|
||||||
|
|
||||||
#define BS_LOG_PREFIX "MOVIEPLAYER"
|
#define BS_LOG_PREFIX "MOVIEPLAYER"
|
||||||
|
|
||||||
BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel) { return new BS_MoviePlayer(pKernel); }
|
BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel) {
|
||||||
|
return new BS_MoviePlayer(pKernel);
|
||||||
|
}
|
||||||
|
|
||||||
BS_MoviePlayer::BS_MoviePlayer(BS_Kernel *pKernel) : BS_Service(pKernel) {
|
BS_MoviePlayer::BS_MoviePlayer(BS_Kernel *pKernel) : BS_Service(pKernel) {
|
||||||
if (!_RegisterScriptBindings())
|
if (!_RegisterScriptBindings())
|
||||||
|
|
26
engines/sword25/fmv/theora_decoder.h
Executable file → Normal file
26
engines/sword25/fmv/theora_decoder.h
Executable file → Normal file
|
@ -34,7 +34,7 @@
|
||||||
#include <vorbis/codec.h>
|
#include <vorbis/codec.h>
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
class SeekableReadStream;
|
class SeekableReadStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Sword25 {
|
namespace Sword25 {
|
||||||
|
@ -65,16 +65,28 @@ public:
|
||||||
*/
|
*/
|
||||||
Graphics::Surface *decodeNextFrame();
|
Graphics::Surface *decodeNextFrame();
|
||||||
|
|
||||||
bool isVideoLoaded() const { return _fileStream != 0; }
|
bool isVideoLoaded() const {
|
||||||
uint16 getWidth() const { return _surface->w; }
|
return _fileStream != 0;
|
||||||
uint16 getHeight() const { return _surface->h; }
|
}
|
||||||
uint32 getFrameCount() const { return _frameCount; }
|
uint16 getWidth() const {
|
||||||
Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 0, 0, 0); }
|
return _surface->w;
|
||||||
|
}
|
||||||
|
uint16 getHeight() const {
|
||||||
|
return _surface->h;
|
||||||
|
}
|
||||||
|
uint32 getFrameCount() const {
|
||||||
|
return _frameCount;
|
||||||
|
}
|
||||||
|
Graphics::PixelFormat getPixelFormat() const {
|
||||||
|
return Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
uint32 getElapsedTime() const;
|
uint32 getElapsedTime() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Common::Rational getFrameRate() const { return _frameRate; }
|
Common::Rational getFrameRate() const {
|
||||||
|
return _frameRate;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void queuePage(ogg_page *page);
|
void queuePage(ogg_page *page);
|
||||||
|
|
|
@ -57,9 +57,8 @@ namespace Sword25 {
|
||||||
// Konstruktion / Destruktion
|
// Konstruktion / Destruktion
|
||||||
// --------------------------
|
// --------------------------
|
||||||
|
|
||||||
BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String & FileName) :
|
BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String &FileName) :
|
||||||
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION)
|
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION) {
|
||||||
{
|
|
||||||
// Das BS_RenderObject konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
// Das BS_RenderObject konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||||
if (!m_InitSuccess) return;
|
if (!m_InitSuccess) return;
|
||||||
|
|
||||||
|
@ -76,9 +75,8 @@ BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const BS_AnimationTemplate & Template) :
|
BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const BS_AnimationTemplate &Template) :
|
||||||
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION)
|
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION) {
|
||||||
{
|
|
||||||
// Das BS_RenderObject konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
// Das BS_RenderObject konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||||
if (!m_InitSuccess) return;
|
if (!m_InitSuccess) return;
|
||||||
|
|
||||||
|
@ -95,9 +93,8 @@ BS_Animation::BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Animation::BS_Animation(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
BS_Animation::BS_Animation(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||||
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION, Handle)
|
BS_TimedRenderObject(ParentPtr, BS_RenderObject::TYPE_ANIMATION, Handle) {
|
||||||
{
|
|
||||||
// Das BS_RenderObject konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
// Das BS_RenderObject konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||||
if (!m_InitSuccess) return;
|
if (!m_InitSuccess) return;
|
||||||
|
|
||||||
|
@ -109,14 +106,12 @@ BS_Animation::BS_Animation(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::InitializeAnimationResource(const Common::String &FileName)
|
void BS_Animation::InitializeAnimationResource(const Common::String &FileName) {
|
||||||
{
|
|
||||||
// Die Resource wird für die gesamte Lebensdauer des Animations-Objektes gelockt.
|
// Die Resource wird für die gesamte Lebensdauer des Animations-Objektes gelockt.
|
||||||
BS_Resource * ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(FileName);
|
BS_Resource *ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(FileName);
|
||||||
if (ResourcePtr && ResourcePtr->GetType() == BS_Resource::TYPE_ANIMATION)
|
if (ResourcePtr && ResourcePtr->GetType() == BS_Resource::TYPE_ANIMATION)
|
||||||
m_AnimationResourcePtr = static_cast<BS_AnimationResource *>(ResourcePtr);
|
m_AnimationResourcePtr = static_cast<BS_AnimationResource *>(ResourcePtr);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("The resource \"%s\" could not be requested. The Animation can't be created.", FileName.c_str());
|
BS_LOG_ERRORLN("The resource \"%s\" could not be requested. The Animation can't be created.", FileName.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -127,8 +122,7 @@ void BS_Animation::InitializeAnimationResource(const Common::String &FileName)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::InitMembers()
|
void BS_Animation::InitMembers() {
|
||||||
{
|
|
||||||
m_CurrentFrame = 0;
|
m_CurrentFrame = 0;
|
||||||
m_CurrentFrameTime = 0;
|
m_CurrentFrameTime = 0;
|
||||||
m_Direction = FORWARD;
|
m_Direction = FORWARD;
|
||||||
|
@ -146,17 +140,15 @@ void BS_Animation::InitMembers()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Animation::~BS_Animation()
|
BS_Animation::~BS_Animation() {
|
||||||
{
|
if (GetAnimationDescription()) {
|
||||||
if (GetAnimationDescription())
|
|
||||||
{
|
|
||||||
Stop();
|
Stop();
|
||||||
GetAnimationDescription()->Unlock();
|
GetAnimationDescription()->Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete Callbacks
|
// Delete Callbacks
|
||||||
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_DeleteCallbacks.begin();
|
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_DeleteCallbacks.begin();
|
||||||
for (; it != m_DeleteCallbacks.end(); it++) ((*it).Callback)((*it).Data);
|
for (; it != m_DeleteCallbacks.end(); it++)((*it).Callback)((*it).Data);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +156,7 @@ BS_Animation::~BS_Animation()
|
||||||
// Steuermethoden
|
// Steuermethoden
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::Play()
|
void BS_Animation::Play() {
|
||||||
{
|
|
||||||
// Wenn die Animation zuvor komplett durchgelaufen ist, wird sie wieder von Anfang abgespielt
|
// Wenn die Animation zuvor komplett durchgelaufen ist, wird sie wieder von Anfang abgespielt
|
||||||
if (m_Finished) Stop();
|
if (m_Finished) Stop();
|
||||||
|
|
||||||
|
@ -175,16 +166,14 @@ void BS_Animation::Play()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::Pause()
|
void BS_Animation::Pause() {
|
||||||
{
|
|
||||||
m_Running = false;
|
m_Running = false;
|
||||||
UnlockAllFrames();
|
UnlockAllFrames();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::Stop()
|
void BS_Animation::Stop() {
|
||||||
{
|
|
||||||
m_CurrentFrame = 0;
|
m_CurrentFrame = 0;
|
||||||
m_CurrentFrameTime = 0;
|
m_CurrentFrameTime = 0;
|
||||||
m_Direction = FORWARD;
|
m_Direction = FORWARD;
|
||||||
|
@ -193,13 +182,11 @@ void BS_Animation::Stop()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::SetFrame(unsigned int Nr)
|
void BS_Animation::SetFrame(unsigned int Nr) {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
|
|
||||||
if (Nr >= animationDescriptionPtr->GetFrameCount())
|
if (Nr >= animationDescriptionPtr->GetFrameCount()) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Tried to set animation to illegal frame (%d). Value must be between 0 and %d.",
|
BS_LOG_ERRORLN("Tried to set animation to illegal frame (%d). Value must be between 0 and %d.",
|
||||||
Nr, animationDescriptionPtr->GetFrameCount());
|
Nr, animationDescriptionPtr->GetFrameCount());
|
||||||
return;
|
return;
|
||||||
|
@ -215,33 +202,29 @@ void BS_Animation::SetFrame(unsigned int Nr)
|
||||||
// Rendern
|
// Rendern
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Animation::DoRender()
|
bool BS_Animation::DoRender() {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
BS_ASSERT(m_CurrentFrame < animationDescriptionPtr->GetFrameCount());
|
BS_ASSERT(m_CurrentFrame < animationDescriptionPtr->GetFrameCount());
|
||||||
|
|
||||||
// Bitmap des aktuellen Frames holen
|
// Bitmap des aktuellen Frames holen
|
||||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(m_CurrentFrame).FileName);
|
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(m_CurrentFrame).FileName);
|
||||||
BS_ASSERT(pResource);
|
BS_ASSERT(pResource);
|
||||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||||
BS_BitmapResource * pBitmapResource = static_cast<BS_BitmapResource*>(pResource);
|
BS_BitmapResource *pBitmapResource = static_cast<BS_BitmapResource *>(pResource);
|
||||||
|
|
||||||
// Framebufferobjekt holen
|
// Framebufferobjekt holen
|
||||||
BS_GraphicEngine * pGfx = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
BS_GraphicEngine *pGfx = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||||
BS_ASSERT(pGfx);
|
BS_ASSERT(pGfx);
|
||||||
|
|
||||||
// Bitmap zeichnen
|
// Bitmap zeichnen
|
||||||
bool Result;
|
bool Result;
|
||||||
if (IsScalingAllowed() && (m_Width != pBitmapResource->GetWidth() || m_Height != pBitmapResource->GetHeight()))
|
if (IsScalingAllowed() && (m_Width != pBitmapResource->GetWidth() || m_Height != pBitmapResource->GetHeight())) {
|
||||||
{
|
|
||||||
Result = pBitmapResource->Blit(m_AbsoluteX, m_AbsoluteY,
|
Result = pBitmapResource->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipH ? BS_BitmapResource::FLIP_H : 0),
|
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||||
0, m_ModulationColor, m_Width, m_Height);
|
0, m_ModulationColor, m_Width, m_Height);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Result = pBitmapResource->Blit(m_AbsoluteX, m_AbsoluteY,
|
Result = pBitmapResource->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||||
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipH ? BS_BitmapResource::FLIP_H : 0),
|
(animationDescriptionPtr->GetFrame(m_CurrentFrame).FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||||
|
@ -258,15 +241,13 @@ bool BS_Animation::DoRender()
|
||||||
// Frame Notifikation
|
// Frame Notifikation
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::FrameNotification(int TimeElapsed)
|
void BS_Animation::FrameNotification(int TimeElapsed) {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
BS_ASSERT(TimeElapsed >= 0);
|
BS_ASSERT(TimeElapsed >= 0);
|
||||||
|
|
||||||
// Nur wenn die Animation läuft wird sie auch weiterbewegt
|
// Nur wenn die Animation läuft wird sie auch weiterbewegt
|
||||||
if (m_Running)
|
if (m_Running) {
|
||||||
{
|
|
||||||
int OldFrame = m_CurrentFrame;
|
int OldFrame = m_CurrentFrame;
|
||||||
|
|
||||||
// Gesamte vergangene Zeit bestimmen (inkl. Restzeit des aktuellen Frames)
|
// Gesamte vergangene Zeit bestimmen (inkl. Restzeit des aktuellen Frames)
|
||||||
|
@ -280,8 +261,7 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
||||||
|
|
||||||
// Neuen Frame bestimmen (je nach aktuellener Abspielrichtung wird addiert oder subtrahiert)
|
// Neuen Frame bestimmen (je nach aktuellener Abspielrichtung wird addiert oder subtrahiert)
|
||||||
int TmpCurFrame = m_CurrentFrame;
|
int TmpCurFrame = m_CurrentFrame;
|
||||||
switch (m_Direction)
|
switch (m_Direction) {
|
||||||
{
|
|
||||||
case FORWARD:
|
case FORWARD:
|
||||||
TmpCurFrame += SkipFrames;
|
TmpCurFrame += SkipFrames;
|
||||||
break;
|
break;
|
||||||
|
@ -295,17 +275,13 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Überläufe behandeln
|
// Überläufe behandeln
|
||||||
if (TmpCurFrame < 0)
|
if (TmpCurFrame < 0) {
|
||||||
{
|
|
||||||
// Loop-Point Callbacks
|
// Loop-Point Callbacks
|
||||||
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_LoopPointCallbacks.begin();
|
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_LoopPointCallbacks.begin();
|
||||||
while (it != m_LoopPointCallbacks.end())
|
while (it != m_LoopPointCallbacks.end()) {
|
||||||
{
|
if (((*it).Callback)((*it).Data) == false) {
|
||||||
if (((*it).Callback)((*it).Data) == false)
|
|
||||||
{
|
|
||||||
it = m_LoopPointCallbacks.erase(it);
|
it = m_LoopPointCallbacks.erase(it);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,21 +289,17 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
||||||
BS_ASSERT(animationDescriptionPtr->GetAnimationType() == AT_JOJO);
|
BS_ASSERT(animationDescriptionPtr->GetAnimationType() == AT_JOJO);
|
||||||
TmpCurFrame = - TmpCurFrame;
|
TmpCurFrame = - TmpCurFrame;
|
||||||
m_Direction = FORWARD;
|
m_Direction = FORWARD;
|
||||||
}
|
} else if (static_cast<unsigned int>(TmpCurFrame) >= animationDescriptionPtr->GetFrameCount()) {
|
||||||
else if (static_cast<unsigned int>(TmpCurFrame) >= animationDescriptionPtr->GetFrameCount())
|
|
||||||
{
|
|
||||||
// Loop-Point Callbacks
|
// Loop-Point Callbacks
|
||||||
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_LoopPointCallbacks.begin();
|
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_LoopPointCallbacks.begin();
|
||||||
while (it != m_LoopPointCallbacks.end())
|
while (it != m_LoopPointCallbacks.end()) {
|
||||||
{
|
|
||||||
if (((*it).Callback)((*it).Data) == false)
|
if (((*it).Callback)((*it).Data) == false)
|
||||||
it = m_LoopPointCallbacks.erase(it);
|
it = m_LoopPointCallbacks.erase(it);
|
||||||
else
|
else
|
||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (animationDescriptionPtr->GetAnimationType())
|
switch (animationDescriptionPtr->GetAnimationType()) {
|
||||||
{
|
|
||||||
case AT_ONESHOT:
|
case AT_ONESHOT:
|
||||||
TmpCurFrame = animationDescriptionPtr->GetFrameCount() - 1;
|
TmpCurFrame = animationDescriptionPtr->GetFrameCount() - 1;
|
||||||
m_Finished = true;
|
m_Finished = true;
|
||||||
|
@ -348,16 +320,13 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_CurrentFrame != TmpCurFrame)
|
if (m_CurrentFrame != TmpCurFrame) {
|
||||||
{
|
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
|
|
||||||
if (animationDescriptionPtr->GetFrame(m_CurrentFrame).Action != "")
|
if (animationDescriptionPtr->GetFrame(m_CurrentFrame).Action != "") {
|
||||||
{
|
|
||||||
// Action Callbacks
|
// Action Callbacks
|
||||||
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_ActionCallbacks.begin();
|
Common::Array<ANIMATION_CALLBACK_DATA>::iterator it = m_ActionCallbacks.begin();
|
||||||
while (it != m_ActionCallbacks.end())
|
while (it != m_ActionCallbacks.end()) {
|
||||||
{
|
|
||||||
if (((*it).Callback)((*it).Data) == false)
|
if (((*it).Callback)((*it).Data) == false)
|
||||||
it = m_ActionCallbacks.erase(it);
|
it = m_ActionCallbacks.erase(it);
|
||||||
else
|
else
|
||||||
|
@ -378,16 +347,15 @@ void BS_Animation::FrameNotification(int TimeElapsed)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::ComputeCurrentCharacteristics()
|
void BS_Animation::ComputeCurrentCharacteristics() {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
const BS_AnimationResource::Frame & CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
const BS_AnimationResource::Frame &CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
||||||
|
|
||||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
||||||
BS_ASSERT(pResource);
|
BS_ASSERT(pResource);
|
||||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||||
BS_BitmapResource* pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
BS_BitmapResource *pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
||||||
|
|
||||||
// Größe des Bitmaps auf die Animation übertragen
|
// Größe des Bitmaps auf die Animation übertragen
|
||||||
m_Width = static_cast<int>(pBitmap->GetWidth() * m_ScaleFactorX);
|
m_Width = static_cast<int>(pBitmap->GetWidth() * m_ScaleFactorX);
|
||||||
|
@ -404,16 +372,12 @@ void BS_Animation::ComputeCurrentCharacteristics()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Animation::LockAllFrames()
|
bool BS_Animation::LockAllFrames() {
|
||||||
{
|
if (!m_FramesLocked) {
|
||||||
if (!m_FramesLocked)
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
{
|
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
for (unsigned int i = 0; i < animationDescriptionPtr->GetFrameCount(); ++i)
|
for (unsigned int i = 0; i < animationDescriptionPtr->GetFrameCount(); ++i) {
|
||||||
{
|
if (!BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(i).FileName)) {
|
||||||
if (!BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(i).FileName))
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not lock all animation frames.");
|
BS_LOG_ERRORLN("Could not lock all animation frames.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -427,17 +391,13 @@ bool BS_Animation::LockAllFrames()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Animation::UnlockAllFrames()
|
bool BS_Animation::UnlockAllFrames() {
|
||||||
{
|
if (m_FramesLocked) {
|
||||||
if (m_FramesLocked)
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
{
|
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
for (unsigned int i = 0; i < animationDescriptionPtr->GetFrameCount(); ++i)
|
for (unsigned int i = 0; i < animationDescriptionPtr->GetFrameCount(); ++i) {
|
||||||
{
|
BS_Resource *pResource;
|
||||||
BS_Resource* pResource;
|
if (!(pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(i).FileName))) {
|
||||||
if (!(pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(animationDescriptionPtr->GetFrame(i).FileName)))
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not unlock all animation frames.");
|
BS_LOG_ERRORLN("Could not unlock all animation frames.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -457,54 +417,48 @@ bool BS_Animation::UnlockAllFrames()
|
||||||
// Getter
|
// Getter
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Animation::ANIMATION_TYPES BS_Animation::GetAnimationType() const
|
BS_Animation::ANIMATION_TYPES BS_Animation::GetAnimationType() const {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
return animationDescriptionPtr->GetAnimationType();
|
return animationDescriptionPtr->GetAnimationType();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int BS_Animation::GetFPS() const
|
int BS_Animation::GetFPS() const {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
return animationDescriptionPtr->GetFPS();
|
return animationDescriptionPtr->GetFPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int BS_Animation::GetFrameCount() const
|
int BS_Animation::GetFrameCount() const {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
return animationDescriptionPtr->GetFrameCount();
|
return animationDescriptionPtr->GetFrameCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Animation::IsScalingAllowed() const
|
bool BS_Animation::IsScalingAllowed() const {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
return animationDescriptionPtr->IsScalingAllowed();
|
return animationDescriptionPtr->IsScalingAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Animation::IsAlphaAllowed() const
|
bool BS_Animation::IsAlphaAllowed() const {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
return animationDescriptionPtr->IsAlphaAllowed();
|
return animationDescriptionPtr->IsAlphaAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Animation::IsColorModulationAllowed() const
|
bool BS_Animation::IsColorModulationAllowed() const {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
return animationDescriptionPtr->IsColorModulationAllowed();
|
return animationDescriptionPtr->IsColorModulationAllowed();
|
||||||
}
|
}
|
||||||
|
@ -513,8 +467,7 @@ bool BS_Animation::IsColorModulationAllowed() const
|
||||||
// Positionieren
|
// Positionieren
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::SetPos(int RelX, int RelY)
|
void BS_Animation::SetPos(int RelX, int RelY) {
|
||||||
{
|
|
||||||
m_RelX = RelX;
|
m_RelX = RelX;
|
||||||
m_RelY = RelY;
|
m_RelY = RelY;
|
||||||
|
|
||||||
|
@ -523,8 +476,7 @@ void BS_Animation::SetPos(int RelX, int RelY)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::SetX(int RelX)
|
void BS_Animation::SetX(int RelX) {
|
||||||
{
|
|
||||||
m_RelX = RelX;
|
m_RelX = RelX;
|
||||||
|
|
||||||
ComputeCurrentCharacteristics();
|
ComputeCurrentCharacteristics();
|
||||||
|
@ -532,8 +484,7 @@ void BS_Animation::SetX(int RelX)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::SetY(int RelY)
|
void BS_Animation::SetY(int RelY) {
|
||||||
{
|
|
||||||
m_RelY = RelY;
|
m_RelY = RelY;
|
||||||
|
|
||||||
ComputeCurrentCharacteristics();
|
ComputeCurrentCharacteristics();
|
||||||
|
@ -543,19 +494,16 @@ void BS_Animation::SetY(int RelY)
|
||||||
// Darstellungsart festlegen
|
// Darstellungsart festlegen
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::SetAlpha(int Alpha)
|
void BS_Animation::SetAlpha(int Alpha) {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
if (!animationDescriptionPtr->IsAlphaAllowed())
|
if (!animationDescriptionPtr->IsAlphaAllowed()) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set alpha value on an animation that does not support alpha. Call was ignored.");
|
BS_LOG_WARNINGLN("Tried to set alpha value on an animation that does not support alpha. Call was ignored.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int NewModulationColor = (m_ModulationColor & 0x00ffffff) | Alpha << 24;
|
unsigned int NewModulationColor = (m_ModulationColor & 0x00ffffff) | Alpha << 24;
|
||||||
if (NewModulationColor != m_ModulationColor)
|
if (NewModulationColor != m_ModulationColor) {
|
||||||
{
|
|
||||||
m_ModulationColor = NewModulationColor;
|
m_ModulationColor = NewModulationColor;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
}
|
}
|
||||||
|
@ -563,19 +511,16 @@ void BS_Animation::SetAlpha(int Alpha)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::SetModulationColor(unsigned int ModulationColor)
|
void BS_Animation::SetModulationColor(unsigned int ModulationColor) {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
if (!animationDescriptionPtr->IsColorModulationAllowed())
|
if (!animationDescriptionPtr->IsColorModulationAllowed()) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set modulation color on an animation that does not support color modulation. Call was ignored");
|
BS_LOG_WARNINGLN("Tried to set modulation color on an animation that does not support color modulation. Call was ignored");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int NewModulationColor = (ModulationColor & 0x00ffffff) | (m_ModulationColor & 0xff000000);
|
unsigned int NewModulationColor = (ModulationColor & 0x00ffffff) | (m_ModulationColor & 0xff000000);
|
||||||
if (NewModulationColor != m_ModulationColor)
|
if (NewModulationColor != m_ModulationColor) {
|
||||||
{
|
|
||||||
m_ModulationColor = NewModulationColor;
|
m_ModulationColor = NewModulationColor;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
}
|
}
|
||||||
|
@ -583,26 +528,22 @@ void BS_Animation::SetModulationColor(unsigned int ModulationColor)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::SetScaleFactor(float ScaleFactor)
|
void BS_Animation::SetScaleFactor(float ScaleFactor) {
|
||||||
{
|
|
||||||
SetScaleFactorX(ScaleFactor);
|
SetScaleFactorX(ScaleFactor);
|
||||||
SetScaleFactorY(ScaleFactor);
|
SetScaleFactorY(ScaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::SetScaleFactorX(float ScaleFactorX)
|
void BS_Animation::SetScaleFactorX(float ScaleFactorX) {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
if (!animationDescriptionPtr->IsScalingAllowed())
|
if (!animationDescriptionPtr->IsScalingAllowed()) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set x scale factor on an animation that does not support scaling. Call was ignored");
|
BS_LOG_WARNINGLN("Tried to set x scale factor on an animation that does not support scaling. Call was ignored");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ScaleFactorX != m_ScaleFactorX)
|
if (ScaleFactorX != m_ScaleFactorX) {
|
||||||
{
|
|
||||||
m_ScaleFactorX = ScaleFactorX;
|
m_ScaleFactorX = ScaleFactorX;
|
||||||
if (m_ScaleFactorX <= 0.0f) m_ScaleFactorX = 0.001f;
|
if (m_ScaleFactorX <= 0.0f) m_ScaleFactorX = 0.001f;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
|
@ -612,18 +553,15 @@ void BS_Animation::SetScaleFactorX(float ScaleFactorX)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::SetScaleFactorY(float ScaleFactorY)
|
void BS_Animation::SetScaleFactorY(float ScaleFactorY) {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
if (!animationDescriptionPtr->IsScalingAllowed())
|
if (!animationDescriptionPtr->IsScalingAllowed()) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set y scale factor on an animation that does not support scaling. Call was ignored");
|
BS_LOG_WARNINGLN("Tried to set y scale factor on an animation that does not support scaling. Call was ignored");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ScaleFactorY != m_ScaleFactorY)
|
if (ScaleFactorY != m_ScaleFactorY) {
|
||||||
{
|
|
||||||
m_ScaleFactorY = ScaleFactorY;
|
m_ScaleFactorY = ScaleFactorY;
|
||||||
if (m_ScaleFactorY <= 0.0f) m_ScaleFactorY = 0.001f;
|
if (m_ScaleFactorY <= 0.0f) m_ScaleFactorY = 0.001f;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
|
@ -633,53 +571,47 @@ void BS_Animation::SetScaleFactorY(float ScaleFactorY)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
const Common::String & BS_Animation::GetCurrentAction() const
|
const Common::String &BS_Animation::GetCurrentAction() const {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
return animationDescriptionPtr->GetFrame(m_CurrentFrame).Action;
|
return animationDescriptionPtr->GetFrame(m_CurrentFrame).Action;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int BS_Animation::GetX() const
|
int BS_Animation::GetX() const {
|
||||||
{
|
|
||||||
return m_RelX;
|
return m_RelX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int BS_Animation::GetY() const
|
int BS_Animation::GetY() const {
|
||||||
{
|
|
||||||
return m_RelY;
|
return m_RelY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int BS_Animation::GetAbsoluteX() const
|
int BS_Animation::GetAbsoluteX() const {
|
||||||
{
|
|
||||||
return m_AbsoluteX + (m_RelX - m_X);
|
return m_AbsoluteX + (m_RelX - m_X);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int BS_Animation::GetAbsoluteY() const
|
int BS_Animation::GetAbsoluteY() const {
|
||||||
{
|
|
||||||
return m_AbsoluteY + (m_RelY - m_Y);
|
return m_AbsoluteY + (m_RelY - m_Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int BS_Animation::ComputeXModifier() const
|
int BS_Animation::ComputeXModifier() const {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
const BS_AnimationResource::Frame & CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
const BS_AnimationResource::Frame &CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
||||||
|
|
||||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
||||||
BS_ASSERT(pResource);
|
BS_ASSERT(pResource);
|
||||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||||
BS_BitmapResource* pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
BS_BitmapResource *pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
||||||
|
|
||||||
int Result = CurFrame.FlipV ? - static_cast<int>((pBitmap->GetWidth() - 1 - CurFrame.HotspotX) * m_ScaleFactorX) :
|
int Result = CurFrame.FlipV ? - static_cast<int>((pBitmap->GetWidth() - 1 - CurFrame.HotspotX) * m_ScaleFactorX) :
|
||||||
- static_cast<int>(CurFrame.HotspotX * m_ScaleFactorX);
|
- static_cast<int>(CurFrame.HotspotX * m_ScaleFactorX);
|
||||||
|
@ -691,16 +623,15 @@ int BS_Animation::ComputeXModifier() const
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
int BS_Animation::ComputeYModifier() const
|
int BS_Animation::ComputeYModifier() const {
|
||||||
{
|
BS_AnimationDescription *animationDescriptionPtr = GetAnimationDescription();
|
||||||
BS_AnimationDescription * animationDescriptionPtr = GetAnimationDescription();
|
|
||||||
BS_ASSERT(animationDescriptionPtr);
|
BS_ASSERT(animationDescriptionPtr);
|
||||||
const BS_AnimationResource::Frame & CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
const BS_AnimationResource::Frame &CurFrame = animationDescriptionPtr->GetFrame(m_CurrentFrame);
|
||||||
|
|
||||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(CurFrame.FileName);
|
||||||
BS_ASSERT(pResource);
|
BS_ASSERT(pResource);
|
||||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||||
BS_BitmapResource* pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
BS_BitmapResource *pBitmap = static_cast<BS_BitmapResource *>(pResource);
|
||||||
|
|
||||||
int Result = CurFrame.FlipH ? - static_cast<int>((pBitmap->GetHeight() - 1 - CurFrame.HotspotY) * m_ScaleFactorY) :
|
int Result = CurFrame.FlipH ? - static_cast<int>((pBitmap->GetHeight() - 1 - CurFrame.HotspotY) * m_ScaleFactorY) :
|
||||||
- static_cast<int>(CurFrame.HotspotY * m_ScaleFactorY);
|
- static_cast<int>(CurFrame.HotspotY * m_ScaleFactorY);
|
||||||
|
@ -712,8 +643,7 @@ int BS_Animation::ComputeYModifier() const
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::RegisterActionCallback(ANIMATION_CALLBACK Callback, unsigned int Data)
|
void BS_Animation::RegisterActionCallback(ANIMATION_CALLBACK Callback, unsigned int Data) {
|
||||||
{
|
|
||||||
ANIMATION_CALLBACK_DATA CD;
|
ANIMATION_CALLBACK_DATA CD;
|
||||||
CD.Callback = Callback;
|
CD.Callback = Callback;
|
||||||
CD.Data = Data;
|
CD.Data = Data;
|
||||||
|
@ -722,8 +652,7 @@ void BS_Animation::RegisterActionCallback(ANIMATION_CALLBACK Callback, unsigned
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::RegisterLoopPointCallback(ANIMATION_CALLBACK Callback, unsigned int Data)
|
void BS_Animation::RegisterLoopPointCallback(ANIMATION_CALLBACK Callback, unsigned int Data) {
|
||||||
{
|
|
||||||
ANIMATION_CALLBACK_DATA CD;
|
ANIMATION_CALLBACK_DATA CD;
|
||||||
CD.Callback = Callback;
|
CD.Callback = Callback;
|
||||||
CD.Data = Data;
|
CD.Data = Data;
|
||||||
|
@ -732,8 +661,7 @@ void BS_Animation::RegisterLoopPointCallback(ANIMATION_CALLBACK Callback, unsign
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::RegisterDeleteCallback(ANIMATION_CALLBACK Callback, unsigned int Data)
|
void BS_Animation::RegisterDeleteCallback(ANIMATION_CALLBACK Callback, unsigned int Data) {
|
||||||
{
|
|
||||||
ANIMATION_CALLBACK_DATA CD;
|
ANIMATION_CALLBACK_DATA CD;
|
||||||
CD.Callback = Callback;
|
CD.Callback = Callback;
|
||||||
CD.Data = Data;
|
CD.Data = Data;
|
||||||
|
@ -744,15 +672,13 @@ void BS_Animation::RegisterDeleteCallback(ANIMATION_CALLBACK Callback, unsigned
|
||||||
// Persistenz
|
// Persistenz
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::PersistCallbackVector(BS_OutputPersistenceBlock & Writer, const Common::Array<ANIMATION_CALLBACK_DATA> & Vector)
|
void BS_Animation::PersistCallbackVector(BS_OutputPersistenceBlock &Writer, const Common::Array<ANIMATION_CALLBACK_DATA> & Vector) {
|
||||||
{
|
|
||||||
// Anzahl an Callbacks persistieren.
|
// Anzahl an Callbacks persistieren.
|
||||||
Writer.Write(Vector.size());
|
Writer.Write(Vector.size());
|
||||||
|
|
||||||
// Alle Callbacks einzeln persistieren.
|
// Alle Callbacks einzeln persistieren.
|
||||||
Common::Array<ANIMATION_CALLBACK_DATA>::const_iterator It = Vector.begin();
|
Common::Array<ANIMATION_CALLBACK_DATA>::const_iterator It = Vector.begin();
|
||||||
while (It != Vector.end())
|
while (It != Vector.end()) {
|
||||||
{
|
|
||||||
Writer.Write(BS_CallbackRegistry::GetInstance().ResolveCallbackPointer(It->Callback));
|
Writer.Write(BS_CallbackRegistry::GetInstance().ResolveCallbackPointer(It->Callback));
|
||||||
Writer.Write(It->Data);
|
Writer.Write(It->Data);
|
||||||
|
|
||||||
|
@ -762,8 +688,7 @@ void BS_Animation::PersistCallbackVector(BS_OutputPersistenceBlock & Writer, con
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Animation::UnpersistCallbackVector(BS_InputPersistenceBlock & Reader, Common::Array<ANIMATION_CALLBACK_DATA> & Vector)
|
void BS_Animation::UnpersistCallbackVector(BS_InputPersistenceBlock &Reader, Common::Array<ANIMATION_CALLBACK_DATA> & Vector) {
|
||||||
{
|
|
||||||
// Callbackvector leeren.
|
// Callbackvector leeren.
|
||||||
Vector.resize(0);
|
Vector.resize(0);
|
||||||
|
|
||||||
|
@ -772,8 +697,7 @@ void BS_Animation::UnpersistCallbackVector(BS_InputPersistenceBlock & Reader, Co
|
||||||
Reader.Read(CallbackCount);
|
Reader.Read(CallbackCount);
|
||||||
|
|
||||||
// Alle Callbacks einzeln wieder herstellen.
|
// Alle Callbacks einzeln wieder herstellen.
|
||||||
for (unsigned int i = 0; i < CallbackCount; ++i)
|
for (unsigned int i = 0; i < CallbackCount; ++i) {
|
||||||
{
|
|
||||||
ANIMATION_CALLBACK_DATA CallbackData;
|
ANIMATION_CALLBACK_DATA CallbackData;
|
||||||
|
|
||||||
Common::String CallbackFunctionName;
|
Common::String CallbackFunctionName;
|
||||||
|
@ -788,8 +712,7 @@ void BS_Animation::UnpersistCallbackVector(BS_InputPersistenceBlock & Reader, Co
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Animation::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_Animation::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_RenderObject::Persist(Writer);
|
Result &= BS_RenderObject::Persist(Writer);
|
||||||
|
@ -806,20 +729,15 @@ bool BS_Animation::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
Writer.Write(static_cast<unsigned int>(m_Direction));
|
Writer.Write(static_cast<unsigned int>(m_Direction));
|
||||||
|
|
||||||
// Je nach Animationstyp entweder das Template oder die Ressource speichern.
|
// Je nach Animationstyp entweder das Template oder die Ressource speichern.
|
||||||
if (m_AnimationResourcePtr)
|
if (m_AnimationResourcePtr) {
|
||||||
{
|
|
||||||
unsigned int Marker = 0;
|
unsigned int Marker = 0;
|
||||||
Writer.Write(Marker);
|
Writer.Write(Marker);
|
||||||
Writer.Write(m_AnimationResourcePtr->GetFileName());
|
Writer.Write(m_AnimationResourcePtr->GetFileName());
|
||||||
}
|
} else if (m_AnimationTemplateHandle) {
|
||||||
else if (m_AnimationTemplateHandle)
|
|
||||||
{
|
|
||||||
unsigned int Marker = 1;
|
unsigned int Marker = 1;
|
||||||
Writer.Write(Marker);
|
Writer.Write(Marker);
|
||||||
Writer.Write(m_AnimationTemplateHandle);
|
Writer.Write(m_AnimationTemplateHandle);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
BS_ASSERT(false);
|
BS_ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,8 +755,7 @@ bool BS_Animation::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Animation::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_Animation::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_RenderObject::Unpersist(Reader);
|
Result &= BS_RenderObject::Unpersist(Reader);
|
||||||
|
@ -859,18 +776,13 @@ bool BS_Animation::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||||
// Animationstyp einlesen.
|
// Animationstyp einlesen.
|
||||||
unsigned int Marker;
|
unsigned int Marker;
|
||||||
Reader.Read(Marker);
|
Reader.Read(Marker);
|
||||||
if (Marker == 0)
|
if (Marker == 0) {
|
||||||
{
|
|
||||||
Common::String ResourceFilename;
|
Common::String ResourceFilename;
|
||||||
Reader.Read(ResourceFilename);
|
Reader.Read(ResourceFilename);
|
||||||
InitializeAnimationResource(ResourceFilename);
|
InitializeAnimationResource(ResourceFilename);
|
||||||
}
|
} else if (Marker == 1) {
|
||||||
else if (Marker == 1)
|
|
||||||
{
|
|
||||||
Reader.Read(m_AnimationTemplateHandle);
|
Reader.Read(m_AnimationTemplateHandle);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
BS_ASSERT(false);
|
BS_ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -888,8 +800,7 @@ bool BS_Animation::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_AnimationDescription * BS_Animation::GetAnimationDescription() const
|
BS_AnimationDescription *BS_Animation::GetAnimationDescription() const {
|
||||||
{
|
|
||||||
if (m_AnimationResourcePtr) return m_AnimationResourcePtr;
|
if (m_AnimationResourcePtr) return m_AnimationResourcePtr;
|
||||||
else return BS_AnimationTemplateRegistry::GetInstance().ResolveHandle(m_AnimationTemplateHandle);
|
else return BS_AnimationTemplateRegistry::GetInstance().ResolveHandle(m_AnimationTemplateHandle);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,18 +53,16 @@ class BS_AnimationTemplate;
|
||||||
class BS_AnimationDescription;
|
class BS_AnimationDescription;
|
||||||
class BS_InputPersistenceBlock;
|
class BS_InputPersistenceBlock;
|
||||||
|
|
||||||
class BS_Animation : public BS_TimedRenderObject
|
class BS_Animation : public BS_TimedRenderObject {
|
||||||
{
|
friend class BS_RenderObject;
|
||||||
friend class BS_RenderObject;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String & FileName);
|
BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String &FileName);
|
||||||
BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const BS_AnimationTemplate & Template);
|
BS_Animation(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const BS_AnimationTemplate &Template);
|
||||||
BS_Animation(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
BS_Animation(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ANIMATION_TYPES
|
enum ANIMATION_TYPES {
|
||||||
{
|
|
||||||
AT_ONESHOT,
|
AT_ONESHOT,
|
||||||
AT_LOOP,
|
AT_LOOP,
|
||||||
AT_JOJO
|
AT_JOJO
|
||||||
|
@ -125,16 +123,20 @@ public:
|
||||||
@brief Gibt den Skalierungsfakter der Animation auf der X-Achse zurück.
|
@brief Gibt den Skalierungsfakter der Animation auf der X-Achse zurück.
|
||||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||||
*/
|
*/
|
||||||
float GetScaleFactorX() const { return m_ScaleFactorX; }
|
float GetScaleFactorX() const {
|
||||||
|
return m_ScaleFactorX;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt den Skalierungsfakter der Animation auf der Y-Achse zurück.
|
@brief Gibt den Skalierungsfakter der Animation auf der Y-Achse zurück.
|
||||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||||
*/
|
*/
|
||||||
float GetScaleFactorY() const { return m_ScaleFactorY; }
|
float GetScaleFactorY() const {
|
||||||
|
return m_ScaleFactorY;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
virtual void FrameNotification(int TimeElapsed);
|
virtual void FrameNotification(int TimeElapsed);
|
||||||
|
|
||||||
|
@ -144,9 +146,13 @@ public:
|
||||||
bool IsScalingAllowed() const;
|
bool IsScalingAllowed() const;
|
||||||
bool IsAlphaAllowed() const;
|
bool IsAlphaAllowed() const;
|
||||||
bool IsColorModulationAllowed() const;
|
bool IsColorModulationAllowed() const;
|
||||||
unsigned int GetCurrentFrame() const { return m_CurrentFrame; }
|
unsigned int GetCurrentFrame() const {
|
||||||
const Common::String & GetCurrentAction() const ;
|
return m_CurrentFrame;
|
||||||
bool IsRunning() const { return m_Running; }
|
}
|
||||||
|
const Common::String &GetCurrentAction() const ;
|
||||||
|
bool IsRunning() const {
|
||||||
|
return m_Running;
|
||||||
|
}
|
||||||
|
|
||||||
typedef bool (*ANIMATION_CALLBACK)(unsigned int);
|
typedef bool (*ANIMATION_CALLBACK)(unsigned int);
|
||||||
|
|
||||||
|
@ -158,8 +164,7 @@ protected:
|
||||||
virtual bool DoRender();
|
virtual bool DoRender();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum DIRECTION
|
enum DIRECTION {
|
||||||
{
|
|
||||||
FORWARD,
|
FORWARD,
|
||||||
BACKWARD
|
BACKWARD
|
||||||
};
|
};
|
||||||
|
@ -174,12 +179,11 @@ private:
|
||||||
bool m_Running;
|
bool m_Running;
|
||||||
bool m_Finished;
|
bool m_Finished;
|
||||||
DIRECTION m_Direction;
|
DIRECTION m_Direction;
|
||||||
BS_AnimationResource * m_AnimationResourcePtr;
|
BS_AnimationResource *m_AnimationResourcePtr;
|
||||||
unsigned int m_AnimationTemplateHandle;
|
unsigned int m_AnimationTemplateHandle;
|
||||||
bool m_FramesLocked;
|
bool m_FramesLocked;
|
||||||
|
|
||||||
struct ANIMATION_CALLBACK_DATA
|
struct ANIMATION_CALLBACK_DATA {
|
||||||
{
|
|
||||||
ANIMATION_CALLBACK Callback;
|
ANIMATION_CALLBACK Callback;
|
||||||
unsigned int Data;
|
unsigned int Data;
|
||||||
};
|
};
|
||||||
|
@ -217,9 +221,9 @@ private:
|
||||||
int ComputeYModifier() const;
|
int ComputeYModifier() const;
|
||||||
|
|
||||||
void InitMembers();
|
void InitMembers();
|
||||||
void PersistCallbackVector(BS_OutputPersistenceBlock & Writer, const Common::Array<ANIMATION_CALLBACK_DATA> & Vector);
|
void PersistCallbackVector(BS_OutputPersistenceBlock &Writer, const Common::Array<ANIMATION_CALLBACK_DATA> & Vector);
|
||||||
void UnpersistCallbackVector(BS_InputPersistenceBlock & Reader, Common::Array<ANIMATION_CALLBACK_DATA> & Vector);
|
void UnpersistCallbackVector(BS_InputPersistenceBlock &Reader, Common::Array<ANIMATION_CALLBACK_DATA> & Vector);
|
||||||
BS_AnimationDescription * GetAnimationDescription() const;
|
BS_AnimationDescription *GetAnimationDescription() const;
|
||||||
void InitializeAnimationResource(const Common::String &FileName);
|
void InitializeAnimationResource(const Common::String &FileName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,7 @@ namespace Sword25 {
|
||||||
// Persistenz
|
// Persistenz
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationDescription::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_AnimationDescription::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
Writer.Write(static_cast<unsigned int>(m_AnimationType));
|
Writer.Write(static_cast<unsigned int>(m_AnimationType));
|
||||||
Writer.Write(m_FPS);
|
Writer.Write(m_FPS);
|
||||||
Writer.Write(m_MillisPerFrame);
|
Writer.Write(m_MillisPerFrame);
|
||||||
|
@ -60,8 +59,7 @@ bool BS_AnimationDescription::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationDescription::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_AnimationDescription::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
unsigned int AnimationType;
|
unsigned int AnimationType;
|
||||||
Reader.Read(AnimationType);
|
Reader.Read(AnimationType);
|
||||||
m_AnimationType = static_cast<BS_Animation::ANIMATION_TYPES>(AnimationType);
|
m_AnimationType = static_cast<BS_Animation::ANIMATION_TYPES>(AnimationType);
|
||||||
|
|
|
@ -49,8 +49,7 @@ namespace Sword25 {
|
||||||
// Klassendefinition
|
// Klassendefinition
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_AnimationDescription : public BS_Persistable
|
class BS_AnimationDescription : public BS_Persistable {
|
||||||
{
|
|
||||||
protected:
|
protected:
|
||||||
BS_AnimationDescription() :
|
BS_AnimationDescription() :
|
||||||
m_AnimationType(BS_Animation::AT_LOOP),
|
m_AnimationType(BS_Animation::AT_LOOP),
|
||||||
|
@ -62,8 +61,7 @@ protected:
|
||||||
{};
|
{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct Frame
|
struct Frame {
|
||||||
{
|
|
||||||
// Die Hotspot-Angabe bezieht sich auf das ungeflippte Bild!!
|
// Die Hotspot-Angabe bezieht sich auf das ungeflippte Bild!!
|
||||||
int HotspotX;
|
int HotspotX;
|
||||||
int HotspotY;
|
int HotspotY;
|
||||||
|
@ -77,7 +75,7 @@ public:
|
||||||
// Abstrakte Methoden
|
// Abstrakte Methoden
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
virtual const Frame & GetFrame(unsigned int Index) const = 0;
|
virtual const Frame &GetFrame(unsigned int Index) const = 0;
|
||||||
virtual unsigned int GetFrameCount() const = 0;
|
virtual unsigned int GetFrameCount() const = 0;
|
||||||
virtual void Unlock() = 0;
|
virtual void Unlock() = 0;
|
||||||
|
|
||||||
|
@ -85,15 +83,27 @@ public:
|
||||||
// Getter Methoden
|
// Getter Methoden
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Animation::ANIMATION_TYPES GetAnimationType() const { return m_AnimationType; }
|
BS_Animation::ANIMATION_TYPES GetAnimationType() const {
|
||||||
int GetFPS() const { return m_FPS; }
|
return m_AnimationType;
|
||||||
int GetMillisPerFrame() const { return m_MillisPerFrame; }
|
}
|
||||||
bool IsScalingAllowed() const { return m_ScalingAllowed; }
|
int GetFPS() const {
|
||||||
bool IsAlphaAllowed() const { return m_AlphaAllowed; }
|
return m_FPS;
|
||||||
bool IsColorModulationAllowed() const { return m_ColorModulationAllowed; }
|
}
|
||||||
|
int GetMillisPerFrame() const {
|
||||||
|
return m_MillisPerFrame;
|
||||||
|
}
|
||||||
|
bool IsScalingAllowed() const {
|
||||||
|
return m_ScalingAllowed;
|
||||||
|
}
|
||||||
|
bool IsAlphaAllowed() const {
|
||||||
|
return m_AlphaAllowed;
|
||||||
|
}
|
||||||
|
bool IsColorModulationAllowed() const {
|
||||||
|
return m_ColorModulationAllowed;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BS_Animation::ANIMATION_TYPES m_AnimationType;
|
BS_Animation::ANIMATION_TYPES m_AnimationType;
|
||||||
|
|
|
@ -54,23 +54,21 @@ namespace Sword25 {
|
||||||
// Constants
|
// Constants
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
const int DEFAULT_FPS = 10;
|
||||||
const int DEFAULT_FPS = 10;
|
const int MIN_FPS = 1;
|
||||||
const int MIN_FPS = 1;
|
const int MAX_FPS = 200;
|
||||||
const int MAX_FPS = 200;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Construction / Destruction
|
// Construction / Destruction
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
BS_AnimationResource::BS_AnimationResource(const Common::String &FileName) :
|
||||||
BS_Resource(FileName, BS_Resource::TYPE_ANIMATION),
|
BS_Resource(FileName, BS_Resource::TYPE_ANIMATION),
|
||||||
m_Valid(false)
|
m_Valid(false) {
|
||||||
{
|
|
||||||
// Pointer auf den Package-Manager bekommen
|
// Pointer auf den Package-Manager bekommen
|
||||||
BS_PackageManager* PackagePtr = BS_Kernel::GetInstance()->GetPackage();
|
BS_PackageManager *PackagePtr = BS_Kernel::GetInstance()->GetPackage();
|
||||||
BS_ASSERT(PackagePtr);
|
BS_ASSERT(PackagePtr);
|
||||||
|
|
||||||
// Animations-XML laden
|
// Animations-XML laden
|
||||||
|
@ -79,9 +77,8 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
||||||
// Die Daten werden zunächst über den Package-Manager gelesen und dann in einen um ein Byte größeren Buffer kopiert und
|
// Die Daten werden zunächst über den Package-Manager gelesen und dann in einen um ein Byte größeren Buffer kopiert und
|
||||||
// NULL-Terminiert, da TinyXML NULL-Terminierte Daten benötigt.
|
// NULL-Terminiert, da TinyXML NULL-Terminierte Daten benötigt.
|
||||||
unsigned int FileSize;
|
unsigned int FileSize;
|
||||||
char * LoadBuffer = (char *) PackagePtr->GetFile(GetFileName(), &FileSize);
|
char *LoadBuffer = (char *) PackagePtr->GetFile(GetFileName(), &FileSize);
|
||||||
if (!LoadBuffer)
|
if (!LoadBuffer) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not read \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("Could not read \"%s\".", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -94,27 +91,24 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
||||||
// Datei parsen
|
// Datei parsen
|
||||||
Doc.Parse(&WorkBuffer[0]);
|
Doc.Parse(&WorkBuffer[0]);
|
||||||
free(WorkBuffer);
|
free(WorkBuffer);
|
||||||
if (Doc.Error())
|
if (Doc.Error()) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("The following TinyXML-Error occured while parsing \"%s\": %s", GetFileName().c_str(), Doc.ErrorDesc());
|
BS_LOG_ERRORLN("The following TinyXML-Error occured while parsing \"%s\": %s", GetFileName().c_str(), Doc.ErrorDesc());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wurzelknoten des Animations-Tags finden, prüfen und Attribute auslesen.
|
// Wurzelknoten des Animations-Tags finden, prüfen und Attribute auslesen.
|
||||||
TiXmlElement* pElement;
|
TiXmlElement *pElement;
|
||||||
{
|
|
||||||
TiXmlNode* pNode = Doc.FirstChild("animation");
|
|
||||||
if (!pNode || pNode->Type() != TiXmlNode::ELEMENT)
|
|
||||||
{
|
{
|
||||||
|
TiXmlNode *pNode = Doc.FirstChild("animation");
|
||||||
|
if (!pNode || pNode->Type() != TiXmlNode::ELEMENT) {
|
||||||
BS_LOG_ERRORLN("No <animation> tag found in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("No <animation> tag found in \"%s\".", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pElement = pNode->ToElement();
|
pElement = pNode->ToElement();
|
||||||
|
|
||||||
// Animation-Tag parsen
|
// Animation-Tag parsen
|
||||||
if (!ParseAnimationTag(*pElement, m_FPS, m_AnimationType))
|
if (!ParseAnimationTag(*pElement, m_FPS, m_AnimationType)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("An error occurred while parsing <animation> tag in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("An error occurred while parsing <animation> tag in \"%s\".", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -131,13 +125,11 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nacheinander alle Frames-Informationen erstellen.
|
// Nacheinander alle Frames-Informationen erstellen.
|
||||||
TiXmlElement* pFrameElement = pElement->FirstChild("frame")->ToElement();
|
TiXmlElement *pFrameElement = pElement->FirstChild("frame")->ToElement();
|
||||||
while (pFrameElement)
|
while (pFrameElement) {
|
||||||
{
|
|
||||||
Frame CurFrame;
|
Frame CurFrame;
|
||||||
|
|
||||||
if (!ParseFrameTag(*pFrameElement, CurFrame, *PackagePtr))
|
if (!ParseFrameTag(*pFrameElement, CurFrame, *PackagePtr)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("An error occurred in \"%s\" while parsing <frame> tag.", GetFileName().c_str());
|
BS_LOG_ERRORLN("An error occurred in \"%s\" while parsing <frame> tag.", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -150,22 +142,19 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
||||||
PackagePtr->ChangeDirectory(OldDirectory);
|
PackagePtr->ChangeDirectory(OldDirectory);
|
||||||
|
|
||||||
// Sicherstellen, dass die Animation mindestens einen Frame besitzt
|
// Sicherstellen, dass die Animation mindestens einen Frame besitzt
|
||||||
if (m_Frames.empty())
|
if (m_Frames.empty()) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("\"%s\" does not have any frames.", GetFileName().c_str());
|
BS_LOG_ERRORLN("\"%s\" does not have any frames.", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alle Frame-Dateien werden vorgecached
|
// Alle Frame-Dateien werden vorgecached
|
||||||
if (!PrecacheAllFrames())
|
if (!PrecacheAllFrames()) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not precache all frames of \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("Could not precache all frames of \"%s\".", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feststellen, ob die Animation skalierbar ist
|
// Feststellen, ob die Animation skalierbar ist
|
||||||
if (!ComputeFeatures())
|
if (!ComputeFeatures()) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not determine the features of \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("Could not determine the features of \"%s\".", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -177,27 +166,22 @@ BS_AnimationResource::BS_AnimationResource(const Common::String& FileName) :
|
||||||
// Dokument-Parsermethoden
|
// Dokument-Parsermethoden
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationResource::ParseAnimationTag(TiXmlElement& AnimationTag, int& FPS, BS_Animation::ANIMATION_TYPES & AnimationType)
|
bool BS_AnimationResource::ParseAnimationTag(TiXmlElement &AnimationTag, int &FPS, BS_Animation::ANIMATION_TYPES &AnimationType) {
|
||||||
{
|
|
||||||
// FPS einlesen
|
// FPS einlesen
|
||||||
const char* FPSString;
|
const char *FPSString;
|
||||||
if (FPSString = AnimationTag.Attribute("fps"))
|
if (FPSString = AnimationTag.Attribute("fps")) {
|
||||||
{
|
|
||||||
int TempFPS;
|
int TempFPS;
|
||||||
if (!BS_String::ToInt(Common::String(FPSString), TempFPS) || TempFPS < MIN_FPS || TempFPS > MAX_FPS)
|
if (!BS_String::ToInt(Common::String(FPSString), TempFPS) || TempFPS < MIN_FPS || TempFPS > MAX_FPS) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Illegal fps value (\"%s\") in <animation> tag in \"%s\". Assuming default (\"%d\"). "
|
BS_LOG_WARNINGLN("Illegal fps value (\"%s\") in <animation> tag in \"%s\". Assuming default (\"%d\"). "
|
||||||
"The fps value has to be between %d and %d.",
|
"The fps value has to be between %d and %d.",
|
||||||
FPSString, GetFileName().c_str(), DEFAULT_FPS, MIN_FPS, MAX_FPS);
|
FPSString, GetFileName().c_str(), DEFAULT_FPS, MIN_FPS, MAX_FPS);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
FPS = TempFPS;
|
FPS = TempFPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop-Typ einlesen
|
// Loop-Typ einlesen
|
||||||
const char* LoopTypeString;
|
const char *LoopTypeString;
|
||||||
if (LoopTypeString = AnimationTag.Attribute("type"))
|
if (LoopTypeString = AnimationTag.Attribute("type")) {
|
||||||
{
|
|
||||||
if (strcmp(LoopTypeString, "oneshot") == 0)
|
if (strcmp(LoopTypeString, "oneshot") == 0)
|
||||||
AnimationType = BS_Animation::AT_ONESHOT;
|
AnimationType = BS_Animation::AT_ONESHOT;
|
||||||
else if (strcmp(LoopTypeString, "loop") == 0)
|
else if (strcmp(LoopTypeString, "loop") == 0)
|
||||||
|
@ -214,27 +198,24 @@ bool BS_AnimationResource::ParseAnimationTag(TiXmlElement& AnimationTag, int& FP
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationResource::ParseFrameTag(TiXmlElement& FrameTag, Frame& Frame_, BS_PackageManager& PackageManager)
|
bool BS_AnimationResource::ParseFrameTag(TiXmlElement &FrameTag, Frame &Frame_, BS_PackageManager &PackageManager) {
|
||||||
{
|
const char *FileString = FrameTag.Attribute("file");
|
||||||
const char* FileString = FrameTag.Attribute("file");
|
if (!FileString) {
|
||||||
if (!FileString)
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("<frame> tag without file attribute occurred in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("<frame> tag without file attribute occurred in \"%s\".", GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Frame_.FileName = PackageManager.GetAbsolutePath(FileString);
|
Frame_.FileName = PackageManager.GetAbsolutePath(FileString);
|
||||||
if (Frame_.FileName == "")
|
if (Frame_.FileName == "") {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create absolute path for file specified in <frame> tag in \"%s\": \"%s\".", GetFileName().c_str(), FileString);
|
BS_LOG_ERRORLN("Could not create absolute path for file specified in <frame> tag in \"%s\": \"%s\".", GetFileName().c_str(), FileString);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* ActionString = FrameTag.Attribute("action");
|
const char *ActionString = FrameTag.Attribute("action");
|
||||||
if (ActionString)
|
if (ActionString)
|
||||||
Frame_.Action = ActionString;
|
Frame_.Action = ActionString;
|
||||||
|
|
||||||
const char* HotspotxString = FrameTag.Attribute("hotspotx");
|
const char *HotspotxString = FrameTag.Attribute("hotspotx");
|
||||||
const char* HotspotyString = FrameTag.Attribute("hotspoty");
|
const char *HotspotyString = FrameTag.Attribute("hotspoty");
|
||||||
if ((!HotspotxString && HotspotyString) ||
|
if ((!HotspotxString && HotspotyString) ||
|
||||||
(HotspotxString && !HotspotyString))
|
(HotspotxString && !HotspotyString))
|
||||||
BS_LOG_WARNINGLN("%s attribute occurred without %s attribute in <frame> tag in \"%s\". Assuming default (\"0\").",
|
BS_LOG_WARNINGLN("%s attribute occurred without %s attribute in <frame> tag in \"%s\". Assuming default (\"0\").",
|
||||||
|
@ -245,37 +226,31 @@ bool BS_AnimationResource::ParseFrameTag(TiXmlElement& FrameTag, Frame& Frame_,
|
||||||
Frame_.HotspotX = 0;
|
Frame_.HotspotX = 0;
|
||||||
if (HotspotxString && !BS_String::ToInt(Common::String(HotspotxString), Frame_.HotspotX))
|
if (HotspotxString && !BS_String::ToInt(Common::String(HotspotxString), Frame_.HotspotX))
|
||||||
BS_LOG_WARNINGLN("Illegal hotspotx value (\"%s\") in frame tag in \"%s\". Assuming default (\"%s\").",
|
BS_LOG_WARNINGLN("Illegal hotspotx value (\"%s\") in frame tag in \"%s\". Assuming default (\"%s\").",
|
||||||
HotspotxString,GetFileName().c_str(), Frame_.HotspotX);
|
HotspotxString, GetFileName().c_str(), Frame_.HotspotX);
|
||||||
|
|
||||||
Frame_.HotspotY = 0;
|
Frame_.HotspotY = 0;
|
||||||
if (HotspotyString && !BS_String::ToInt(Common::String(HotspotyString), Frame_.HotspotY))
|
if (HotspotyString && !BS_String::ToInt(Common::String(HotspotyString), Frame_.HotspotY))
|
||||||
BS_LOG_WARNINGLN("Illegal hotspoty value (\"%s\") in frame tag in \"%s\". Assuming default (\"%s\").",
|
BS_LOG_WARNINGLN("Illegal hotspoty value (\"%s\") in frame tag in \"%s\". Assuming default (\"%s\").",
|
||||||
HotspotyString, GetFileName().c_str(), Frame_.HotspotY);
|
HotspotyString, GetFileName().c_str(), Frame_.HotspotY);
|
||||||
|
|
||||||
const char* FlipVString = FrameTag.Attribute("flipv");
|
const char *FlipVString = FrameTag.Attribute("flipv");
|
||||||
if (FlipVString)
|
if (FlipVString) {
|
||||||
{
|
if (!BS_String::ToBool(Common::String(FlipVString), Frame_.FlipV)) {
|
||||||
if (!BS_String::ToBool(Common::String(FlipVString), Frame_.FlipV))
|
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Illegal flipv value (\"%s\") in <frame> tag in \"%s\". Assuming default (\"false\").",
|
BS_LOG_WARNINGLN("Illegal flipv value (\"%s\") in <frame> tag in \"%s\". Assuming default (\"false\").",
|
||||||
FlipVString, GetFileName().c_str());
|
FlipVString, GetFileName().c_str());
|
||||||
Frame_.FlipV = false;
|
Frame_.FlipV = false;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
Frame_.FlipV = false;
|
Frame_.FlipV = false;
|
||||||
|
|
||||||
const char* FlipHString = FrameTag.Attribute("fliph");
|
const char *FlipHString = FrameTag.Attribute("fliph");
|
||||||
if (FlipHString)
|
if (FlipHString) {
|
||||||
{
|
if (!BS_String::ToBool(FlipHString, Frame_.FlipH)) {
|
||||||
if (!BS_String::ToBool(FlipHString, Frame_.FlipH))
|
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Illegal fliph value (\"%s\") in <frame> tag in \"%s\". Assuming default (\"false\").",
|
BS_LOG_WARNINGLN("Illegal fliph value (\"%s\") in <frame> tag in \"%s\". Assuming default (\"false\").",
|
||||||
FlipHString, GetFileName().c_str());
|
FlipHString, GetFileName().c_str());
|
||||||
Frame_.FlipH = false;
|
Frame_.FlipH = false;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
Frame_.FlipH = false;
|
Frame_.FlipH = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -283,19 +258,15 @@ bool BS_AnimationResource::ParseFrameTag(TiXmlElement& FrameTag, Frame& Frame_,
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_AnimationResource::~BS_AnimationResource()
|
BS_AnimationResource::~BS_AnimationResource() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationResource::PrecacheAllFrames() const
|
bool BS_AnimationResource::PrecacheAllFrames() const {
|
||||||
{
|
|
||||||
Common::Array<Frame>::const_iterator Iter = m_Frames.begin();
|
Common::Array<Frame>::const_iterator Iter = m_Frames.begin();
|
||||||
for (; Iter != m_Frames.end(); ++Iter)
|
for (; Iter != m_Frames.end(); ++Iter) {
|
||||||
{
|
if (!BS_Kernel::GetInstance()->GetResourceManager()->PrecacheResource((*Iter).FileName)) {
|
||||||
if (!BS_Kernel::GetInstance()->GetResourceManager()->PrecacheResource((*Iter).FileName))
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not precache \"%s\".", (*Iter).FileName.c_str());
|
BS_LOG_ERRORLN("Could not precache \"%s\".", (*Iter).FileName.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -306,8 +277,7 @@ bool BS_AnimationResource::PrecacheAllFrames() const
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationResource::ComputeFeatures()
|
bool BS_AnimationResource::ComputeFeatures() {
|
||||||
{
|
|
||||||
BS_ASSERT(m_Frames.size());
|
BS_ASSERT(m_Frames.size());
|
||||||
|
|
||||||
// Alle Features werden als vorhanden angenommen
|
// Alle Features werden als vorhanden angenommen
|
||||||
|
@ -317,11 +287,9 @@ bool BS_AnimationResource::ComputeFeatures()
|
||||||
|
|
||||||
// Alle Frame durchgehen und alle Features deaktivieren, die auch nur von einem Frame nicht unterstützt werden.
|
// Alle Frame durchgehen und alle Features deaktivieren, die auch nur von einem Frame nicht unterstützt werden.
|
||||||
Common::Array<Frame>::const_iterator Iter = m_Frames.begin();
|
Common::Array<Frame>::const_iterator Iter = m_Frames.begin();
|
||||||
for (; Iter != m_Frames.end(); ++Iter)
|
for (; Iter != m_Frames.end(); ++Iter) {
|
||||||
{
|
BS_BitmapResource *pBitmap;
|
||||||
BS_BitmapResource* pBitmap;
|
if (!(pBitmap = static_cast<BS_BitmapResource *>(BS_Kernel::GetInstance()->GetResourceManager()->RequestResource((*Iter).FileName)))) {
|
||||||
if (!(pBitmap = static_cast<BS_BitmapResource*> (BS_Kernel::GetInstance()->GetResourceManager()->RequestResource((*Iter).FileName))))
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not request \"%s\".", (*Iter).FileName.c_str());
|
BS_LOG_ERRORLN("Could not request \"%s\".", (*Iter).FileName.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,23 +63,43 @@ class BS_PackageManager;
|
||||||
// Class Definition
|
// Class Definition
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_AnimationResource : public BS_Resource, public BS_AnimationDescription
|
class BS_AnimationResource : public BS_Resource, public BS_AnimationDescription {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BS_AnimationResource(const Common::String & FileName);
|
BS_AnimationResource(const Common::String &FileName);
|
||||||
virtual ~BS_AnimationResource();
|
virtual ~BS_AnimationResource();
|
||||||
|
|
||||||
virtual const Frame & GetFrame(unsigned int Index) const { BS_ASSERT(Index < m_Frames.size()); return m_Frames[Index]; }
|
virtual const Frame &GetFrame(unsigned int Index) const {
|
||||||
virtual unsigned int GetFrameCount() const { return m_Frames.size(); }
|
BS_ASSERT(Index < m_Frames.size());
|
||||||
virtual void Unlock() { Release(); }
|
return m_Frames[Index];
|
||||||
|
}
|
||||||
|
virtual unsigned int GetFrameCount() const {
|
||||||
|
return m_Frames.size();
|
||||||
|
}
|
||||||
|
virtual void Unlock() {
|
||||||
|
Release();
|
||||||
|
}
|
||||||
|
|
||||||
BS_Animation::ANIMATION_TYPES GetAnimationType() const { return m_AnimationType; }
|
BS_Animation::ANIMATION_TYPES GetAnimationType() const {
|
||||||
int GetFPS() const { return m_FPS; }
|
return m_AnimationType;
|
||||||
int GetMillisPerFrame() const { return m_MillisPerFrame; }
|
}
|
||||||
bool IsScalingAllowed() const { return m_ScalingAllowed; }
|
int GetFPS() const {
|
||||||
bool IsAlphaAllowed() const { return m_AlphaAllowed; }
|
return m_FPS;
|
||||||
bool IsColorModulationAllowed() const { return m_ColorModulationAllowed; }
|
}
|
||||||
bool IsValid() const { return m_Valid; }
|
int GetMillisPerFrame() const {
|
||||||
|
return m_MillisPerFrame;
|
||||||
|
}
|
||||||
|
bool IsScalingAllowed() const {
|
||||||
|
return m_ScalingAllowed;
|
||||||
|
}
|
||||||
|
bool IsAlphaAllowed() const {
|
||||||
|
return m_AlphaAllowed;
|
||||||
|
}
|
||||||
|
bool IsColorModulationAllowed() const {
|
||||||
|
return m_ColorModulationAllowed;
|
||||||
|
}
|
||||||
|
bool IsValid() const {
|
||||||
|
return m_Valid;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_Valid;
|
bool m_Valid;
|
||||||
|
@ -89,8 +109,8 @@ private:
|
||||||
//@{
|
//@{
|
||||||
/** @name Dokument-Parser Methoden */
|
/** @name Dokument-Parser Methoden */
|
||||||
|
|
||||||
bool ParseAnimationTag(TiXmlElement& AnimationTag, int& FPS, BS_Animation::ANIMATION_TYPES & AnimationType);
|
bool ParseAnimationTag(TiXmlElement &AnimationTag, int &FPS, BS_Animation::ANIMATION_TYPES &AnimationType);
|
||||||
bool ParseFrameTag(TiXmlElement& FrameTag, Frame& Frame, BS_PackageManager& PackageManager);
|
bool ParseFrameTag(TiXmlElement &FrameTag, Frame &Frame, BS_PackageManager &PackageManager);
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
|
@ -53,16 +53,12 @@ namespace Sword25 {
|
||||||
// Konstruktion / Destruktion
|
// Konstruktion / Destruktion
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_AnimationTemplate::Create(const Common::String & SourceAnimation)
|
unsigned int BS_AnimationTemplate::Create(const Common::String &SourceAnimation) {
|
||||||
{
|
BS_AnimationTemplate *AnimationTemplatePtr = new BS_AnimationTemplate(SourceAnimation);
|
||||||
BS_AnimationTemplate * AnimationTemplatePtr = new BS_AnimationTemplate(SourceAnimation);
|
|
||||||
|
|
||||||
if (AnimationTemplatePtr->IsValid())
|
if (AnimationTemplatePtr->IsValid()) {
|
||||||
{
|
|
||||||
return BS_AnimationTemplateRegistry::GetInstance().ResolvePtr(AnimationTemplatePtr);
|
return BS_AnimationTemplateRegistry::GetInstance().ResolvePtr(AnimationTemplatePtr);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
delete AnimationTemplatePtr;
|
delete AnimationTemplatePtr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -70,16 +66,12 @@ unsigned int BS_AnimationTemplate::Create(const Common::String & SourceAnimation
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_AnimationTemplate::Create(const BS_AnimationTemplate & Other)
|
unsigned int BS_AnimationTemplate::Create(const BS_AnimationTemplate &Other) {
|
||||||
{
|
BS_AnimationTemplate *AnimationTemplatePtr = new BS_AnimationTemplate(Other);
|
||||||
BS_AnimationTemplate * AnimationTemplatePtr = new BS_AnimationTemplate(Other);
|
|
||||||
|
|
||||||
if (AnimationTemplatePtr->IsValid())
|
if (AnimationTemplatePtr->IsValid()) {
|
||||||
{
|
|
||||||
return BS_AnimationTemplateRegistry::GetInstance().ResolvePtr(AnimationTemplatePtr);
|
return BS_AnimationTemplateRegistry::GetInstance().ResolvePtr(AnimationTemplatePtr);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
delete AnimationTemplatePtr;
|
delete AnimationTemplatePtr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -87,16 +79,12 @@ unsigned int BS_AnimationTemplate::Create(const BS_AnimationTemplate & Other)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_AnimationTemplate::Create(BS_InputPersistenceBlock & Reader, unsigned int Handle)
|
unsigned int BS_AnimationTemplate::Create(BS_InputPersistenceBlock &Reader, unsigned int Handle) {
|
||||||
{
|
BS_AnimationTemplate *AnimationTemplatePtr = new BS_AnimationTemplate(Reader, Handle);
|
||||||
BS_AnimationTemplate * AnimationTemplatePtr = new BS_AnimationTemplate(Reader, Handle);
|
|
||||||
|
|
||||||
if (AnimationTemplatePtr->IsValid())
|
if (AnimationTemplatePtr->IsValid()) {
|
||||||
{
|
|
||||||
return BS_AnimationTemplateRegistry::GetInstance().ResolvePtr(AnimationTemplatePtr);
|
return BS_AnimationTemplateRegistry::GetInstance().ResolvePtr(AnimationTemplatePtr);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
delete AnimationTemplatePtr;
|
delete AnimationTemplatePtr;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -104,8 +92,7 @@ unsigned int BS_AnimationTemplate::Create(BS_InputPersistenceBlock & Reader, uns
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_AnimationTemplate::BS_AnimationTemplate(const Common::String & SourceAnimation)
|
BS_AnimationTemplate::BS_AnimationTemplate(const Common::String &SourceAnimation) {
|
||||||
{
|
|
||||||
// Objekt registrieren.
|
// Objekt registrieren.
|
||||||
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this);
|
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this);
|
||||||
|
|
||||||
|
@ -120,8 +107,7 @@ BS_AnimationTemplate::BS_AnimationTemplate(const Common::String & SourceAnimatio
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_AnimationTemplate::BS_AnimationTemplate(const BS_AnimationTemplate & Other)
|
BS_AnimationTemplate::BS_AnimationTemplate(const BS_AnimationTemplate &Other) {
|
||||||
{
|
|
||||||
// Objekt registrieren.
|
// Objekt registrieren.
|
||||||
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this);
|
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this);
|
||||||
|
|
||||||
|
@ -147,8 +133,7 @@ BS_AnimationTemplate::BS_AnimationTemplate(const BS_AnimationTemplate & Other)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_AnimationTemplate::BS_AnimationTemplate(BS_InputPersistenceBlock & Reader, unsigned int Handle)
|
BS_AnimationTemplate::BS_AnimationTemplate(BS_InputPersistenceBlock &Reader, unsigned int Handle) {
|
||||||
{
|
|
||||||
// Objekt registrieren.
|
// Objekt registrieren.
|
||||||
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this, Handle);
|
BS_AnimationTemplateRegistry::GetInstance().RegisterObject(this, Handle);
|
||||||
|
|
||||||
|
@ -158,12 +143,10 @@ BS_AnimationTemplate::BS_AnimationTemplate(BS_InputPersistenceBlock & Reader, un
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_AnimationResource * BS_AnimationTemplate::RequestSourceAnimation(const Common::String & SourceAnimation) const
|
BS_AnimationResource *BS_AnimationTemplate::RequestSourceAnimation(const Common::String &SourceAnimation) const {
|
||||||
{
|
BS_ResourceManager *RMPtr = BS_Kernel::GetInstance()->GetResourceManager();
|
||||||
BS_ResourceManager * RMPtr = BS_Kernel::GetInstance()->GetResourceManager();
|
BS_Resource *ResourcePtr;
|
||||||
BS_Resource * ResourcePtr;
|
if (NULL == (ResourcePtr = RMPtr->RequestResource(SourceAnimation)) || ResourcePtr->GetType() != BS_Resource::TYPE_ANIMATION) {
|
||||||
if (NULL == (ResourcePtr = RMPtr->RequestResource(SourceAnimation)) || ResourcePtr->GetType() != BS_Resource::TYPE_ANIMATION)
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("The resource \"%s\" could not be requested or is has an invalid type. The animation template can't be created.", SourceAnimation.c_str());
|
BS_LOG_ERRORLN("The resource \"%s\" could not be requested or is has an invalid type. The animation template can't be created.", SourceAnimation.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -172,11 +155,9 @@ BS_AnimationResource * BS_AnimationTemplate::RequestSourceAnimation(const Common
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_AnimationTemplate::~BS_AnimationTemplate()
|
BS_AnimationTemplate::~BS_AnimationTemplate() {
|
||||||
{
|
|
||||||
// Animations-Resource freigeben
|
// Animations-Resource freigeben
|
||||||
if (m_SourceAnimationPtr)
|
if (m_SourceAnimationPtr) {
|
||||||
{
|
|
||||||
m_SourceAnimationPtr->Release();
|
m_SourceAnimationPtr->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,64 +167,52 @@ BS_AnimationTemplate::~BS_AnimationTemplate()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_AnimationTemplate::AddFrame(int Index)
|
void BS_AnimationTemplate::AddFrame(int Index) {
|
||||||
{
|
if (ValidateSourceIndex(Index)) {
|
||||||
if (ValidateSourceIndex(Index))
|
|
||||||
{
|
|
||||||
m_Frames.push_back(m_SourceAnimationPtr->GetFrame(Index));
|
m_Frames.push_back(m_SourceAnimationPtr->GetFrame(Index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_AnimationTemplate::SetFrame(int DestIndex, int SrcIndex)
|
void BS_AnimationTemplate::SetFrame(int DestIndex, int SrcIndex) {
|
||||||
{
|
if (ValidateDestIndex(DestIndex) && ValidateSourceIndex(SrcIndex)) {
|
||||||
if (ValidateDestIndex(DestIndex) && ValidateSourceIndex(SrcIndex))
|
|
||||||
{
|
|
||||||
m_Frames[DestIndex] = m_SourceAnimationPtr->GetFrame(SrcIndex);
|
m_Frames[DestIndex] = m_SourceAnimationPtr->GetFrame(SrcIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationTemplate::ValidateSourceIndex(unsigned int Index) const
|
bool BS_AnimationTemplate::ValidateSourceIndex(unsigned int Index) const {
|
||||||
{
|
if (Index > m_SourceAnimationPtr->GetFrameCount()) {
|
||||||
if (Index > m_SourceAnimationPtr->GetFrameCount())
|
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to insert a frame (\"%d\") that does not exist in the source animation (\"%s\"). Ignoring call.",
|
BS_LOG_WARNINGLN("Tried to insert a frame (\"%d\") that does not exist in the source animation (\"%s\"). Ignoring call.",
|
||||||
Index, m_SourceAnimationPtr->GetFileName().c_str());
|
Index, m_SourceAnimationPtr->GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationTemplate::ValidateDestIndex(unsigned int Index) const
|
bool BS_AnimationTemplate::ValidateDestIndex(unsigned int Index) const {
|
||||||
{
|
if (Index > m_Frames.size()) {
|
||||||
if (Index > m_Frames.size())
|
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to change a nonexistent frame (\"%d\") in a template animation. Ignoring call.",
|
BS_LOG_WARNINGLN("Tried to change a nonexistent frame (\"%d\") in a template animation. Ignoring call.",
|
||||||
Index);
|
Index);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_AnimationTemplate::SetFPS(int FPS)
|
void BS_AnimationTemplate::SetFPS(int FPS) {
|
||||||
{
|
|
||||||
m_FPS = FPS;
|
m_FPS = FPS;
|
||||||
m_MillisPerFrame = 1000000 / m_FPS;
|
m_MillisPerFrame = 1000000 / m_FPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationTemplate::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_AnimationTemplate::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
// Parent persistieren.
|
// Parent persistieren.
|
||||||
|
@ -254,8 +223,7 @@ bool BS_AnimationTemplate::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// Frames einzeln persistieren.
|
// Frames einzeln persistieren.
|
||||||
Common::Array<const Frame>::const_iterator Iter = m_Frames.begin();
|
Common::Array<const Frame>::const_iterator Iter = m_Frames.begin();
|
||||||
while (Iter != m_Frames.end())
|
while (Iter != m_Frames.end()) {
|
||||||
{
|
|
||||||
Writer.Write(Iter->HotspotX);
|
Writer.Write(Iter->HotspotX);
|
||||||
Writer.Write(Iter->HotspotY);
|
Writer.Write(Iter->HotspotY);
|
||||||
Writer.Write(Iter->FlipV);
|
Writer.Write(Iter->FlipV);
|
||||||
|
@ -274,8 +242,7 @@ bool BS_AnimationTemplate::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationTemplate::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_AnimationTemplate::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
// Parent wieder herstellen.
|
// Parent wieder herstellen.
|
||||||
|
@ -286,8 +253,7 @@ bool BS_AnimationTemplate::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||||
Reader.Read(FrameCount);
|
Reader.Read(FrameCount);
|
||||||
|
|
||||||
// Frames einzeln wieder herstellen.
|
// Frames einzeln wieder herstellen.
|
||||||
for (unsigned int i = 0; i < FrameCount; ++i)
|
for (unsigned int i = 0; i < FrameCount; ++i) {
|
||||||
{
|
|
||||||
Frame frame;
|
Frame frame;
|
||||||
Reader.Read(frame.HotspotX);
|
Reader.Read(frame.HotspotX);
|
||||||
Reader.Read(frame.HotspotY);
|
Reader.Read(frame.HotspotY);
|
||||||
|
|
|
@ -59,27 +59,35 @@ class BS_AnimationResource;
|
||||||
// Klassendefinition
|
// Klassendefinition
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_AnimationTemplate : public BS_AnimationDescription
|
class BS_AnimationTemplate : public BS_AnimationDescription {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static unsigned int Create(const Common::String & SourceAnimation);
|
static unsigned int Create(const Common::String &SourceAnimation);
|
||||||
static unsigned int Create(const BS_AnimationTemplate & Other);
|
static unsigned int Create(const BS_AnimationTemplate &Other);
|
||||||
static unsigned int Create(BS_InputPersistenceBlock & Reader, unsigned int Handle);
|
static unsigned int Create(BS_InputPersistenceBlock &Reader, unsigned int Handle);
|
||||||
BS_AnimationTemplate * ResolveHandle(unsigned int Handle) const;
|
BS_AnimationTemplate *ResolveHandle(unsigned int Handle) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BS_AnimationTemplate(const Common::String & SourceAnimation);
|
BS_AnimationTemplate(const Common::String &SourceAnimation);
|
||||||
BS_AnimationTemplate(const BS_AnimationTemplate & Other);
|
BS_AnimationTemplate(const BS_AnimationTemplate &Other);
|
||||||
BS_AnimationTemplate(BS_InputPersistenceBlock & Reader, unsigned int Handle);
|
BS_AnimationTemplate(BS_InputPersistenceBlock &Reader, unsigned int Handle);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~BS_AnimationTemplate();
|
~BS_AnimationTemplate();
|
||||||
|
|
||||||
virtual const Frame & GetFrame(unsigned int Index) const { BS_ASSERT(Index < m_Frames.size()); return m_Frames[Index]; }
|
virtual const Frame &GetFrame(unsigned int Index) const {
|
||||||
virtual unsigned int GetFrameCount() const { return m_Frames.size(); }
|
BS_ASSERT(Index < m_Frames.size());
|
||||||
virtual void Unlock() { delete this; }
|
return m_Frames[Index];
|
||||||
|
}
|
||||||
|
virtual unsigned int GetFrameCount() const {
|
||||||
|
return m_Frames.size();
|
||||||
|
}
|
||||||
|
virtual void Unlock() {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
bool IsValid() const { return m_Valid; }
|
bool IsValid() const {
|
||||||
|
return m_Valid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Fügt einen neuen Frame zur Animation hinzu.
|
@brief Fügt einen neuen Frame zur Animation hinzu.
|
||||||
|
@ -101,7 +109,9 @@ public:
|
||||||
@brief Setzt den Animationstyp.
|
@brief Setzt den Animationstyp.
|
||||||
@param Type der Typ der Animation. Muss aus den enum BS_Animation::ANIMATION_TYPES sein.
|
@param Type der Typ der Animation. Muss aus den enum BS_Animation::ANIMATION_TYPES sein.
|
||||||
*/
|
*/
|
||||||
void SetAnimationType(BS_Animation::ANIMATION_TYPES Type) { m_AnimationType = Type; }
|
void SetAnimationType(BS_Animation::ANIMATION_TYPES Type) {
|
||||||
|
m_AnimationType = Type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Setzt die Abspielgeschwindigkeit.
|
@brief Setzt die Abspielgeschwindigkeit.
|
||||||
|
@ -109,15 +119,15 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetFPS(int FPS);
|
void SetFPS(int FPS);
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Common::Array<const Frame> m_Frames;
|
Common::Array<const Frame> m_Frames;
|
||||||
BS_AnimationResource * m_SourceAnimationPtr;
|
BS_AnimationResource *m_SourceAnimationPtr;
|
||||||
bool m_Valid;
|
bool m_Valid;
|
||||||
|
|
||||||
BS_AnimationResource * RequestSourceAnimation(const Common::String & SourceAnimation) const;
|
BS_AnimationResource *RequestSourceAnimation(const Common::String &SourceAnimation) const;
|
||||||
bool ValidateSourceIndex(unsigned int Index) const;
|
bool ValidateSourceIndex(unsigned int Index) const;
|
||||||
bool ValidateDestIndex(unsigned int Index) const;
|
bool ValidateDestIndex(unsigned int Index) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -57,22 +57,19 @@ std::auto_ptr<BS_AnimationTemplateRegistry> BS_AnimationTemplateRegistry::m_Inst
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_AnimationTemplateRegistry::LogErrorLn(const char * Message) const
|
void BS_AnimationTemplateRegistry::LogErrorLn(const char *Message) const {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN(Message);
|
BS_LOG_ERRORLN(Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_AnimationTemplateRegistry::LogWarningLn(const char * Message) const
|
void BS_AnimationTemplateRegistry::LogWarningLn(const char *Message) const {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN(Message);
|
BS_LOG_WARNINGLN(Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationTemplateRegistry::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_AnimationTemplateRegistry::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
// Das nächste zu vergebene Handle schreiben.
|
// Das nächste zu vergebene Handle schreiben.
|
||||||
|
@ -83,8 +80,7 @@ bool BS_AnimationTemplateRegistry::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// Alle BS_AnimationTemplates persistieren.
|
// Alle BS_AnimationTemplates persistieren.
|
||||||
HANDLE2PTR_MAP::const_iterator Iter = m_Handle2PtrMap.begin();
|
HANDLE2PTR_MAP::const_iterator Iter = m_Handle2PtrMap.begin();
|
||||||
while (Iter != m_Handle2PtrMap.end())
|
while (Iter != m_Handle2PtrMap.end()) {
|
||||||
{
|
|
||||||
// Handle persistieren.
|
// Handle persistieren.
|
||||||
Writer.Write(Iter->first);
|
Writer.Write(Iter->first);
|
||||||
|
|
||||||
|
@ -99,8 +95,7 @@ bool BS_AnimationTemplateRegistry::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_AnimationTemplateRegistry::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_AnimationTemplateRegistry::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
// Das nächste zu vergebene Handle wieder herstellen.
|
// Das nächste zu vergebene Handle wieder herstellen.
|
||||||
|
@ -114,8 +109,7 @@ bool BS_AnimationTemplateRegistry::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||||
Reader.Read(AnimationTemplateCount);
|
Reader.Read(AnimationTemplateCount);
|
||||||
|
|
||||||
// Alle gespeicherten BS_AnimationTemplates wieder herstellen.
|
// Alle gespeicherten BS_AnimationTemplates wieder herstellen.
|
||||||
for (unsigned int i = 0; i < AnimationTemplateCount; ++i)
|
for (unsigned int i = 0; i < AnimationTemplateCount; ++i) {
|
||||||
{
|
|
||||||
// Handle lesen.
|
// Handle lesen.
|
||||||
unsigned int Handle;
|
unsigned int Handle;
|
||||||
Reader.Read(Handle);
|
Reader.Read(Handle);
|
||||||
|
|
|
@ -59,21 +59,19 @@ class BS_AnimationTemplate;
|
||||||
// Klassendeklaration
|
// Klassendeklaration
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_AnimationTemplateRegistry : public BS_ObjectRegistry<BS_AnimationTemplate>, public BS_Persistable
|
class BS_AnimationTemplateRegistry : public BS_ObjectRegistry<BS_AnimationTemplate>, public BS_Persistable {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static BS_AnimationTemplateRegistry & GetInstance()
|
static BS_AnimationTemplateRegistry &GetInstance() {
|
||||||
{
|
|
||||||
if (!m_InstancePtr.get()) m_InstancePtr.reset(new BS_AnimationTemplateRegistry);
|
if (!m_InstancePtr.get()) m_InstancePtr.reset(new BS_AnimationTemplateRegistry);
|
||||||
return *m_InstancePtr.get();
|
return *m_InstancePtr.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void LogErrorLn(const char * Message) const;
|
virtual void LogErrorLn(const char *Message) const;
|
||||||
virtual void LogWarningLn(const char * Message) const;
|
virtual void LogWarningLn(const char *Message) const;
|
||||||
|
|
||||||
static std::auto_ptr<BS_AnimationTemplateRegistry> m_InstancePtr;
|
static std::auto_ptr<BS_AnimationTemplateRegistry> m_InstancePtr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,30 +58,25 @@ BS_Bitmap::BS_Bitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, TYPES Type,
|
||||||
m_ScaleFactorX(1.0f),
|
m_ScaleFactorX(1.0f),
|
||||||
m_ScaleFactorY(1.0f),
|
m_ScaleFactorY(1.0f),
|
||||||
m_FlipH(false),
|
m_FlipH(false),
|
||||||
m_FlipV(false)
|
m_FlipV(false) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Bitmap::~BS_Bitmap()
|
BS_Bitmap::~BS_Bitmap() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Darstellungsart festlegen
|
// Darstellungsart festlegen
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Bitmap::SetAlpha(int Alpha)
|
void BS_Bitmap::SetAlpha(int Alpha) {
|
||||||
{
|
if (!IsAlphaAllowed()) {
|
||||||
if (!IsAlphaAllowed())
|
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set alpha value on a bitmap that does not support alpha blending. Call was ignored.");
|
BS_LOG_WARNINGLN("Tried to set alpha value on a bitmap that does not support alpha blending. Call was ignored.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Alpha < 0 || Alpha > 255)
|
if (Alpha < 0 || Alpha > 255) {
|
||||||
{
|
|
||||||
int OldAlpha = Alpha;
|
int OldAlpha = Alpha;
|
||||||
if (Alpha < 0) Alpha = 0;
|
if (Alpha < 0) Alpha = 0;
|
||||||
if (Alpha > 255) Alpha = 255;
|
if (Alpha > 255) Alpha = 255;
|
||||||
|
@ -91,8 +86,7 @@ void BS_Bitmap::SetAlpha(int Alpha)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int NewModulationColor = (m_ModulationColor & 0x00ffffff) | Alpha << 24;
|
unsigned int NewModulationColor = (m_ModulationColor & 0x00ffffff) | Alpha << 24;
|
||||||
if (NewModulationColor != m_ModulationColor)
|
if (NewModulationColor != m_ModulationColor) {
|
||||||
{
|
|
||||||
m_ModulationColor = NewModulationColor;
|
m_ModulationColor = NewModulationColor;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
}
|
}
|
||||||
|
@ -100,17 +94,14 @@ void BS_Bitmap::SetAlpha(int Alpha)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Bitmap::SetModulationColor(unsigned int ModulationColor)
|
void BS_Bitmap::SetModulationColor(unsigned int ModulationColor) {
|
||||||
{
|
if (!IsColorModulationAllowed()) {
|
||||||
if (!IsColorModulationAllowed())
|
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set modulation color of a bitmap that does not support color modulation. Call was ignored.");
|
BS_LOG_WARNINGLN("Tried to set modulation color of a bitmap that does not support color modulation. Call was ignored.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int NewModulationColor = (ModulationColor & 0x00ffffff) | (m_ModulationColor & 0xff000000);
|
unsigned int NewModulationColor = (ModulationColor & 0x00ffffff) | (m_ModulationColor & 0xff000000);
|
||||||
if (NewModulationColor != m_ModulationColor)
|
if (NewModulationColor != m_ModulationColor) {
|
||||||
{
|
|
||||||
m_ModulationColor = NewModulationColor;
|
m_ModulationColor = NewModulationColor;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
}
|
}
|
||||||
|
@ -118,30 +109,25 @@ void BS_Bitmap::SetModulationColor(unsigned int ModulationColor)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Bitmap::SetScaleFactor(float ScaleFactor)
|
void BS_Bitmap::SetScaleFactor(float ScaleFactor) {
|
||||||
{
|
|
||||||
SetScaleFactorX(ScaleFactor);
|
SetScaleFactorX(ScaleFactor);
|
||||||
SetScaleFactorY(ScaleFactor);
|
SetScaleFactorY(ScaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Bitmap::SetScaleFactorX(float ScaleFactorX)
|
void BS_Bitmap::SetScaleFactorX(float ScaleFactorX) {
|
||||||
{
|
if (!IsScalingAllowed()) {
|
||||||
if (!IsScalingAllowed())
|
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap that does not support scaling. Call was ignored.");
|
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap that does not support scaling. Call was ignored.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ScaleFactorX < 0)
|
if (ScaleFactorX < 0) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap to a negative value. Call was ignored.");
|
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap to a negative value. Call was ignored.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ScaleFactorX != m_ScaleFactorX)
|
if (ScaleFactorX != m_ScaleFactorX) {
|
||||||
{
|
|
||||||
m_ScaleFactorX = ScaleFactorX;
|
m_ScaleFactorX = ScaleFactorX;
|
||||||
m_Width = static_cast<int>(m_OriginalWidth * m_ScaleFactorX);
|
m_Width = static_cast<int>(m_OriginalWidth * m_ScaleFactorX);
|
||||||
if (m_ScaleFactorX <= 0.0f) m_ScaleFactorX = 0.001f;
|
if (m_ScaleFactorX <= 0.0f) m_ScaleFactorX = 0.001f;
|
||||||
|
@ -151,22 +137,18 @@ void BS_Bitmap::SetScaleFactorX(float ScaleFactorX)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Bitmap::SetScaleFactorY(float ScaleFactorY)
|
void BS_Bitmap::SetScaleFactorY(float ScaleFactorY) {
|
||||||
{
|
if (!IsScalingAllowed()) {
|
||||||
if (!IsScalingAllowed())
|
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap that does not support scaling. Call was ignored.");
|
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap that does not support scaling. Call was ignored.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ScaleFactorY < 0)
|
if (ScaleFactorY < 0) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap to a negative value. Call was ignored.");
|
BS_LOG_WARNINGLN("Tried to set scale factor of a bitmap to a negative value. Call was ignored.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ScaleFactorY != m_ScaleFactorY)
|
if (ScaleFactorY != m_ScaleFactorY) {
|
||||||
{
|
|
||||||
m_ScaleFactorY = ScaleFactorY;
|
m_ScaleFactorY = ScaleFactorY;
|
||||||
m_Height = static_cast<int>(m_OriginalHeight * ScaleFactorY);
|
m_Height = static_cast<int>(m_OriginalHeight * ScaleFactorY);
|
||||||
if (m_ScaleFactorY <= 0.0f) m_ScaleFactorY = 0.001f;
|
if (m_ScaleFactorY <= 0.0f) m_ScaleFactorY = 0.001f;
|
||||||
|
@ -176,16 +158,14 @@ void BS_Bitmap::SetScaleFactorY(float ScaleFactorY)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Bitmap::SetFlipH(bool FlipH)
|
void BS_Bitmap::SetFlipH(bool FlipH) {
|
||||||
{
|
|
||||||
m_FlipH = FlipH;
|
m_FlipH = FlipH;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Bitmap::SetFlipV(bool FlipV)
|
void BS_Bitmap::SetFlipV(bool FlipV) {
|
||||||
{
|
|
||||||
m_FlipV = FlipV;
|
m_FlipV = FlipV;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
}
|
}
|
||||||
|
@ -194,8 +174,7 @@ void BS_Bitmap::SetFlipV(bool FlipV)
|
||||||
// Persistenz
|
// Persistenz
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Bitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_Bitmap::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_RenderObject::Persist(Writer);
|
Result &= BS_RenderObject::Persist(Writer);
|
||||||
|
@ -212,8 +191,7 @@ bool BS_Bitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Bitmap::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_Bitmap::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_RenderObject::Unpersist(Reader);
|
Result &= BS_RenderObject::Unpersist(Reader);
|
||||||
|
|
|
@ -48,8 +48,7 @@ namespace Sword25 {
|
||||||
// Klassendeklaration
|
// Klassendeklaration
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_Bitmap : public BS_RenderObject
|
class BS_Bitmap : public BS_RenderObject {
|
||||||
{
|
|
||||||
protected:
|
protected:
|
||||||
BS_Bitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, TYPES Type, unsigned int Handle = 0);
|
BS_Bitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, TYPES Type, unsigned int Handle = 0);
|
||||||
|
|
||||||
|
@ -106,35 +105,47 @@ public:
|
||||||
@brief Gibt den aktuellen Alphawert des Bildes zurück.
|
@brief Gibt den aktuellen Alphawert des Bildes zurück.
|
||||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsAlphaAllowed() true zurückgibt.
|
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsAlphaAllowed() true zurückgibt.
|
||||||
*/
|
*/
|
||||||
int GetAlpha() { return m_ModulationColor >> 24; }
|
int GetAlpha() {
|
||||||
|
return m_ModulationColor >> 24;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt die aktuelle 24bit RGB Modulationsfarde des Bildes zurück.
|
@brief Gibt die aktuelle 24bit RGB Modulationsfarde des Bildes zurück.
|
||||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsColorModulationAllowed() true zurückgibt.
|
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsColorModulationAllowed() true zurückgibt.
|
||||||
*/
|
*/
|
||||||
int GetModulationColor() { return m_ModulationColor & 0x00ffffff; }
|
int GetModulationColor() {
|
||||||
|
return m_ModulationColor & 0x00ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt den Skalierungsfakter des Bitmaps auf der X-Achse zurück.
|
@brief Gibt den Skalierungsfakter des Bitmaps auf der X-Achse zurück.
|
||||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||||
*/
|
*/
|
||||||
float GetScaleFactorX() const { return m_ScaleFactorX; }
|
float GetScaleFactorX() const {
|
||||||
|
return m_ScaleFactorX;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt den Skalierungsfakter des Bitmaps auf der Y-Achse zurück.
|
@brief Gibt den Skalierungsfakter des Bitmaps auf der Y-Achse zurück.
|
||||||
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
@remark Diese Methode darf nur aufgerufen werden, wenn die Methode IsScalingAllowed() true zurückgibt.
|
||||||
*/
|
*/
|
||||||
float GetScaleFactorY() const { return m_ScaleFactorY; }
|
float GetScaleFactorY() const {
|
||||||
|
return m_ScaleFactorY;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt zurück, ob das Bild an der X-Achse gespiegelt angezeigt wird.
|
@brief Gibt zurück, ob das Bild an der X-Achse gespiegelt angezeigt wird.
|
||||||
*/
|
*/
|
||||||
bool IsFlipH() { return m_FlipH; }
|
bool IsFlipH() {
|
||||||
|
return m_FlipH;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt zurück, ob das Bild an der Y-Achse gespiegelt angezeigt wird.
|
@brief Gibt zurück, ob das Bild an der Y-Achse gespiegelt angezeigt wird.
|
||||||
*/
|
*/
|
||||||
bool IsFlipV() { return m_FlipV; }
|
bool IsFlipV() {
|
||||||
|
return m_FlipV;
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Die folgenden Methoden müssen alle BS_Bitmap-Klassen implementieren
|
// Die folgenden Methoden müssen alle BS_Bitmap-Klassen implementieren
|
||||||
|
@ -168,8 +179,8 @@ public:
|
||||||
virtual bool IsColorModulationAllowed() const = 0;
|
virtual bool IsColorModulationAllowed() const = 0;
|
||||||
virtual bool IsSetContentAllowed() const = 0;
|
virtual bool IsSetContentAllowed() const = 0;
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool m_FlipH;
|
bool m_FlipH;
|
||||||
|
|
|
@ -47,23 +47,20 @@ namespace Sword25 {
|
||||||
// Konstruktion / Destruktion
|
// Konstruktion / Destruktion
|
||||||
// --------------------------
|
// --------------------------
|
||||||
|
|
||||||
BS_BitmapResource::BS_BitmapResource(const Common::String & Filename, BS_Image * pImage) :
|
BS_BitmapResource::BS_BitmapResource(const Common::String &Filename, BS_Image *pImage) :
|
||||||
m_Valid(false),
|
m_Valid(false),
|
||||||
m_pImage(pImage),
|
m_pImage(pImage),
|
||||||
BS_Resource(Filename, BS_Resource::TYPE_BITMAP)
|
BS_Resource(Filename, BS_Resource::TYPE_BITMAP) {
|
||||||
{
|
|
||||||
m_Valid = m_pImage != 0;
|
m_Valid = m_pImage != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_BitmapResource::~BS_BitmapResource()
|
BS_BitmapResource::~BS_BitmapResource() {
|
||||||
{
|
|
||||||
delete m_pImage;
|
delete m_pImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_BitmapResource::GetPixel(int X, int Y) const
|
unsigned int BS_BitmapResource::GetPixel(int X, int Y) const {
|
||||||
{
|
|
||||||
BS_ASSERT(X >= 0 && X < m_pImage->GetWidth());
|
BS_ASSERT(X >= 0 && X < m_pImage->GetWidth());
|
||||||
BS_ASSERT(Y >= 0 && Y < m_pImage->GetHeight());
|
BS_ASSERT(Y >= 0 && Y < m_pImage->GetHeight());
|
||||||
|
|
||||||
|
|
|
@ -48,14 +48,12 @@ namespace Sword25 {
|
||||||
|
|
||||||
class BS_Rect;
|
class BS_Rect;
|
||||||
|
|
||||||
class BS_BitmapResource : public BS_Resource
|
class BS_BitmapResource : public BS_Resource {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@brief Die möglichen Flippingparameter für die Blit-Methode.
|
@brief Die möglichen Flippingparameter für die Blit-Methode.
|
||||||
*/
|
*/
|
||||||
enum FLIP_FLAGS
|
enum FLIP_FLAGS {
|
||||||
{
|
|
||||||
/// Das Bild wird nicht gespiegelt.
|
/// Das Bild wird nicht gespiegelt.
|
||||||
FLIP_NONE = 0,
|
FLIP_NONE = 0,
|
||||||
/// Das Bild wird an der horizontalen Achse gespiegelt.
|
/// Das Bild wird an der horizontalen Achse gespiegelt.
|
||||||
|
@ -68,23 +66,31 @@ public:
|
||||||
FLIP_VH = FLIP_H | FLIP_V
|
FLIP_VH = FLIP_H | FLIP_V
|
||||||
};
|
};
|
||||||
|
|
||||||
BS_BitmapResource(const Common::String & Filename, BS_Image * pImage);
|
BS_BitmapResource(const Common::String &Filename, BS_Image *pImage);
|
||||||
virtual ~BS_BitmapResource();
|
virtual ~BS_BitmapResource();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt zurück, ob das Objekt einen gültigen Zustand hat.
|
@brief Gibt zurück, ob das Objekt einen gültigen Zustand hat.
|
||||||
*/
|
*/
|
||||||
bool IsValid() const { return m_Valid; }
|
bool IsValid() const {
|
||||||
|
return m_Valid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Breite des Bitmaps zurück.
|
@brief Gibt die Breite des Bitmaps zurück.
|
||||||
*/
|
*/
|
||||||
int GetWidth() const { BS_ASSERT(m_pImage); return m_pImage->GetWidth(); }
|
int GetWidth() const {
|
||||||
|
BS_ASSERT(m_pImage);
|
||||||
|
return m_pImage->GetWidth();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Höhe des Bitmaps zurück.
|
@brief Gibt die Höhe des Bitmaps zurück.
|
||||||
*/
|
*/
|
||||||
int GetHeight() const { BS_ASSERT(m_pImage); return m_pImage->GetHeight(); }
|
int GetHeight() const {
|
||||||
|
BS_ASSERT(m_pImage);
|
||||||
|
return m_pImage->GetHeight();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Rendert das Bild in den Framebuffer.
|
@brief Rendert das Bild in den Framebuffer.
|
||||||
|
@ -124,10 +130,9 @@ public:
|
||||||
*/
|
*/
|
||||||
bool Blit(int PosX = 0, int PosY = 0,
|
bool Blit(int PosX = 0, int PosY = 0,
|
||||||
int Flipping = FLIP_NONE,
|
int Flipping = FLIP_NONE,
|
||||||
BS_Rect* pSrcPartRect = NULL,
|
BS_Rect *pSrcPartRect = NULL,
|
||||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||||
int Width = -1, int Height = -1)
|
int Width = -1, int Height = -1) {
|
||||||
{
|
|
||||||
BS_ASSERT(m_pImage);
|
BS_ASSERT(m_pImage);
|
||||||
return m_pImage->Blit(PosX, PosY, Flipping, pSrcPartRect, Color, Width, Height);
|
return m_pImage->Blit(PosX, PosY, Flipping, pSrcPartRect, Color, Width, Height);
|
||||||
}
|
}
|
||||||
|
@ -145,7 +150,10 @@ public:
|
||||||
BS_RGB und BS_ARGB benutzt werden.
|
BS_RGB und BS_ARGB benutzt werden.
|
||||||
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
||||||
*/
|
*/
|
||||||
bool Fill(const BS_Rect* pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0)) { BS_ASSERT(m_pImage); return m_pImage->Fill(pFillRect, Color); }
|
bool Fill(const BS_Rect *pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0)) {
|
||||||
|
BS_ASSERT(m_pImage);
|
||||||
|
return m_pImage->Fill(pFillRect, Color);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Liest einen Pixel des Bildes.
|
@brief Liest einen Pixel des Bildes.
|
||||||
|
@ -164,30 +172,45 @@ public:
|
||||||
@brief Überprüft, ob das BS_Image ein Zielbild für einen Blit-Aufruf sein kann.
|
@brief Überprüft, ob das BS_Image ein Zielbild für einen Blit-Aufruf sein kann.
|
||||||
@return Gibt false zurück, falls ein Blit-Aufruf mit diesem Objekt als Ziel nicht gestattet ist.
|
@return Gibt false zurück, falls ein Blit-Aufruf mit diesem Objekt als Ziel nicht gestattet ist.
|
||||||
*/
|
*/
|
||||||
bool IsBlitTarget() { BS_ASSERT(m_pImage); return m_pImage->IsBlitTarget(); }
|
bool IsBlitTarget() {
|
||||||
|
BS_ASSERT(m_pImage);
|
||||||
|
return m_pImage->IsBlitTarget();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt true zurück, falls das BS_Image bei einem Aufruf von Blit() skaliert dargestellt werden kann.
|
@brief Gibt true zurück, falls das BS_Image bei einem Aufruf von Blit() skaliert dargestellt werden kann.
|
||||||
*/
|
*/
|
||||||
bool IsScalingAllowed() { BS_ASSERT(m_pImage); return m_pImage->IsScalingAllowed(); }
|
bool IsScalingAllowed() {
|
||||||
|
BS_ASSERT(m_pImage);
|
||||||
|
return m_pImage->IsScalingAllowed();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt true zurück, wenn das BS_Image mit einem Aufruf von Fill() gefüllt werden kann.
|
@brief Gibt true zurück, wenn das BS_Image mit einem Aufruf von Fill() gefüllt werden kann.
|
||||||
*/
|
*/
|
||||||
bool IsFillingAllowed() { BS_ASSERT(m_pImage); return m_pImage->IsFillingAllowed(); }
|
bool IsFillingAllowed() {
|
||||||
|
BS_ASSERT(m_pImage);
|
||||||
|
return m_pImage->IsFillingAllowed();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit einem Alphawert dargestellt werden kann.
|
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit einem Alphawert dargestellt werden kann.
|
||||||
*/
|
*/
|
||||||
bool IsAlphaAllowed() { BS_ASSERT(m_pImage); return m_pImage->IsAlphaAllowed(); }
|
bool IsAlphaAllowed() {
|
||||||
|
BS_ASSERT(m_pImage);
|
||||||
|
return m_pImage->IsAlphaAllowed();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit Farbmodulation dargestellt werden kann.
|
@brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit Farbmodulation dargestellt werden kann.
|
||||||
*/
|
*/
|
||||||
bool IsColorModulationAllowed() { BS_ASSERT(m_pImage); return m_pImage->IsColorModulationAllowed(); }
|
bool IsColorModulationAllowed() {
|
||||||
|
BS_ASSERT(m_pImage);
|
||||||
|
return m_pImage->IsColorModulationAllowed();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BS_Image * m_pImage;
|
BS_Image *m_pImage;
|
||||||
bool m_Valid;
|
bool m_Valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,7 @@ namespace Sword25 {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_DynamicBitmap::BS_DynamicBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Width, unsigned int Height) :
|
BS_DynamicBitmap::BS_DynamicBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Width, unsigned int Height) :
|
||||||
BS_Bitmap(ParentPtr, TYPE_DYNAMICBITMAP)
|
BS_Bitmap(ParentPtr, TYPE_DYNAMICBITMAP) {
|
||||||
{
|
|
||||||
// Das BS_Bitmap konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
// Das BS_Bitmap konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||||
if (!m_InitSuccess) return;
|
if (!m_InitSuccess) return;
|
||||||
|
|
||||||
|
@ -66,16 +65,14 @@ BS_DynamicBitmap::BS_DynamicBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_DynamicBitmap::BS_DynamicBitmap(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
BS_DynamicBitmap::BS_DynamicBitmap(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||||
BS_Bitmap(ParentPtr, TYPE_DYNAMICBITMAP, Handle)
|
BS_Bitmap(ParentPtr, TYPE_DYNAMICBITMAP, Handle) {
|
||||||
{
|
|
||||||
m_InitSuccess = Unpersist(Reader);
|
m_InitSuccess = Unpersist(Reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_DynamicBitmap::CreateGLImage(unsigned int Width, unsigned int Height)
|
bool BS_DynamicBitmap::CreateGLImage(unsigned int Width, unsigned int Height) {
|
||||||
{
|
|
||||||
// GLImage mit den gewünschten Maßen erstellen
|
// GLImage mit den gewünschten Maßen erstellen
|
||||||
bool Result;
|
bool Result;
|
||||||
m_Image.reset(new BS_GLImage(Width, Height, Result));
|
m_Image.reset(new BS_GLImage(Width, Height, Result));
|
||||||
|
@ -88,14 +85,12 @@ bool BS_DynamicBitmap::CreateGLImage(unsigned int Width, unsigned int Height)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_DynamicBitmap::~BS_DynamicBitmap()
|
BS_DynamicBitmap::~BS_DynamicBitmap() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_DynamicBitmap::GetPixel(int X, int Y) const
|
unsigned int BS_DynamicBitmap::GetPixel(int X, int Y) const {
|
||||||
{
|
|
||||||
BS_ASSERT(X >= 0 && X < m_Width);
|
BS_ASSERT(X >= 0 && X < m_Width);
|
||||||
BS_ASSERT(Y >= 0 && Y < m_Height);
|
BS_ASSERT(Y >= 0 && Y < m_Height);
|
||||||
|
|
||||||
|
@ -104,23 +99,19 @@ unsigned int BS_DynamicBitmap::GetPixel(int X, int Y) const
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_DynamicBitmap::DoRender()
|
bool BS_DynamicBitmap::DoRender() {
|
||||||
{
|
|
||||||
// Framebufferobjekt holen
|
// Framebufferobjekt holen
|
||||||
BS_GraphicEngine * pGfx = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
BS_GraphicEngine *pGfx = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||||
BS_ASSERT(pGfx);
|
BS_ASSERT(pGfx);
|
||||||
|
|
||||||
// Bitmap zeichnen
|
// Bitmap zeichnen
|
||||||
bool Result;
|
bool Result;
|
||||||
if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f)
|
if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f) {
|
||||||
{
|
|
||||||
Result = m_Image->Blit(m_AbsoluteX, m_AbsoluteY,
|
Result = m_Image->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||||
0, m_ModulationColor, -1, -1);
|
0, m_ModulationColor, -1, -1);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Result = m_Image->Blit(m_AbsoluteX, m_AbsoluteY,
|
Result = m_Image->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||||
|
@ -132,8 +123,7 @@ bool BS_DynamicBitmap::DoRender()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_DynamicBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
bool BS_DynamicBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||||
{
|
|
||||||
return m_Image->SetContent(Pixeldata, Offset, Stride);
|
return m_Image->SetContent(Pixeldata, Offset, Stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,29 +131,25 @@ bool BS_DynamicBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, un
|
||||||
// Auskunftsmethoden
|
// Auskunftsmethoden
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_DynamicBitmap::IsScalingAllowed() const
|
bool BS_DynamicBitmap::IsScalingAllowed() const {
|
||||||
{
|
|
||||||
return m_Image->IsScalingAllowed();
|
return m_Image->IsScalingAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_DynamicBitmap::IsAlphaAllowed() const
|
bool BS_DynamicBitmap::IsAlphaAllowed() const {
|
||||||
{
|
|
||||||
return m_Image->IsAlphaAllowed();
|
return m_Image->IsAlphaAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_DynamicBitmap::IsColorModulationAllowed() const
|
bool BS_DynamicBitmap::IsColorModulationAllowed() const {
|
||||||
{
|
|
||||||
return m_Image->IsColorModulationAllowed();
|
return m_Image->IsColorModulationAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_DynamicBitmap::IsSetContentAllowed() const
|
bool BS_DynamicBitmap::IsSetContentAllowed() const {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,8 +157,7 @@ bool BS_DynamicBitmap::IsSetContentAllowed() const
|
||||||
// Persistenz
|
// Persistenz
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_DynamicBitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_DynamicBitmap::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_Bitmap::Persist(Writer);
|
Result &= BS_Bitmap::Persist(Writer);
|
||||||
|
@ -186,8 +171,7 @@ bool BS_DynamicBitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BS_DynamicBitmap::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_DynamicBitmap::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_Bitmap::Unpersist(Reader);
|
Result &= BS_Bitmap::Unpersist(Reader);
|
||||||
|
|
|
@ -54,9 +54,8 @@ namespace Sword25 {
|
||||||
// Klassendeklaration
|
// Klassendeklaration
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_DynamicBitmap : public BS_Bitmap
|
class BS_DynamicBitmap : public BS_Bitmap {
|
||||||
{
|
friend class BS_RenderObject;
|
||||||
friend class BS_RenderObject;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~BS_DynamicBitmap();
|
virtual ~BS_DynamicBitmap();
|
||||||
|
@ -70,15 +69,15 @@ public:
|
||||||
virtual bool IsColorModulationAllowed() const;
|
virtual bool IsColorModulationAllowed() const;
|
||||||
virtual bool IsSetContentAllowed() const;
|
virtual bool IsSetContentAllowed() const;
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool DoRender();
|
virtual bool DoRender();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BS_DynamicBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Width, unsigned int Height);
|
BS_DynamicBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Width, unsigned int Height);
|
||||||
BS_DynamicBitmap(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
BS_DynamicBitmap(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||||
|
|
||||||
bool CreateGLImage(unsigned int Width, unsigned int Height);
|
bool CreateGLImage(unsigned int Width, unsigned int Height);
|
||||||
|
|
||||||
|
|
|
@ -60,31 +60,27 @@ static const unsigned int DEFAULT_GAPWIDTH = 1;
|
||||||
// Konstruktion / Destruktion
|
// Konstruktion / Destruktion
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_FontResource::BS_FontResource(BS_Kernel* pKernel, const Common::String& FileName) :
|
BS_FontResource::BS_FontResource(BS_Kernel *pKernel, const Common::String &FileName) :
|
||||||
_pKernel(pKernel),
|
_pKernel(pKernel),
|
||||||
_Valid(false),
|
_Valid(false),
|
||||||
BS_Resource(FileName, BS_Resource::TYPE_FONT)
|
BS_Resource(FileName, BS_Resource::TYPE_FONT) {
|
||||||
{
|
|
||||||
// XML Fontdatei parsen
|
// XML Fontdatei parsen
|
||||||
TiXmlDocument Doc;
|
TiXmlDocument Doc;
|
||||||
if (!_ParseXMLDocument(FileName, Doc))
|
if (!_ParseXMLDocument(FileName, Doc)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("The following TinyXML-Error occured while parsing \"%s\": %s", GetFileName().c_str(), Doc.ErrorDesc());
|
BS_LOG_ERRORLN("The following TinyXML-Error occured while parsing \"%s\": %s", GetFileName().c_str(), Doc.ErrorDesc());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Font-Tag finden
|
// Font-Tag finden
|
||||||
TiXmlElement* pElement = Doc.FirstChildElement("font");
|
TiXmlElement *pElement = Doc.FirstChildElement("font");
|
||||||
if (!pElement)
|
if (!pElement) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("No <font> tag found in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("No <font> tag found in \"%s\".", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Font-Tag parsen
|
// Font-Tag parsen
|
||||||
Common::String BitmapFileName;
|
Common::String BitmapFileName;
|
||||||
if (!_ParseFontTag(*pElement, BitmapFileName, _LineHeight, _GapWidth))
|
if (!_ParseFontTag(*pElement, BitmapFileName, _LineHeight, _GapWidth)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("An error occurred while parsing <font> tag in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("An error occurred while parsing <font> tag in \"%s\".", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -93,21 +89,19 @@ BS_FontResource::BS_FontResource(BS_Kernel* pKernel, const Common::String& FileN
|
||||||
{
|
{
|
||||||
// Pointer auf den Package-Manager bekommen
|
// Pointer auf den Package-Manager bekommen
|
||||||
BS_ASSERT(_pKernel);
|
BS_ASSERT(_pKernel);
|
||||||
BS_PackageManager* pPackage = static_cast<BS_PackageManager *>(_pKernel->GetService("package"));
|
BS_PackageManager *pPackage = static_cast<BS_PackageManager *>(_pKernel->GetService("package"));
|
||||||
BS_ASSERT(pPackage);
|
BS_ASSERT(pPackage);
|
||||||
|
|
||||||
// Absoluten, eindeutigen Pfad bestimmen
|
// Absoluten, eindeutigen Pfad bestimmen
|
||||||
_BitmapFileName = pPackage->GetAbsolutePath(BitmapFileName);
|
_BitmapFileName = pPackage->GetAbsolutePath(BitmapFileName);
|
||||||
if (_BitmapFileName == "")
|
if (_BitmapFileName == "") {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Image file \"%s\" was specified in <font> tag of \"%s\" but could not be found.",
|
BS_LOG_ERRORLN("Image file \"%s\" was specified in <font> tag of \"%s\" but could not be found.",
|
||||||
_BitmapFileName.c_str(), GetFileName().c_str());
|
_BitmapFileName.c_str(), GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bitmapdatei cachen
|
// Bitmapdatei cachen
|
||||||
if (!_pKernel->GetResourceManager()->PrecacheResource(_BitmapFileName))
|
if (!_pKernel->GetResourceManager()->PrecacheResource(_BitmapFileName)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not precache \"%s\".", _BitmapFileName.c_str());
|
BS_LOG_ERRORLN("Could not precache \"%s\".", _BitmapFileName.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -115,21 +109,18 @@ BS_FontResource::BS_FontResource(BS_Kernel* pKernel, const Common::String& FileN
|
||||||
|
|
||||||
// Das Erste Character-Tag finden
|
// Das Erste Character-Tag finden
|
||||||
pElement = pElement->FirstChildElement("character");
|
pElement = pElement->FirstChildElement("character");
|
||||||
if (!pElement)
|
if (!pElement) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("No <character> tag found in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("No <character> tag found in \"%s\".", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alle Character-Tags parsen
|
// Alle Character-Tags parsen
|
||||||
while (pElement)
|
while (pElement) {
|
||||||
{
|
|
||||||
int CharCode;
|
int CharCode;
|
||||||
BS_Rect CharRect;
|
BS_Rect CharRect;
|
||||||
|
|
||||||
// Aktuelles Character-Tag parsen
|
// Aktuelles Character-Tag parsen
|
||||||
if (!_ParseCharacterTag(*pElement, CharCode, CharRect))
|
if (!_ParseCharacterTag(*pElement, CharCode, CharRect)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("An error occured while parsing a <character> tag in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("An error occured while parsing a <character> tag in \"%s\".", GetFileName().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -148,19 +139,17 @@ BS_FontResource::BS_FontResource(BS_Kernel* pKernel, const Common::String& FileN
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_FontResource::_ParseXMLDocument(const Common::String & FileName, TiXmlDocument & Doc) const
|
bool BS_FontResource::_ParseXMLDocument(const Common::String &FileName, TiXmlDocument &Doc) const {
|
||||||
{
|
|
||||||
// Pointer auf den Package-Manager bekommen
|
// Pointer auf den Package-Manager bekommen
|
||||||
BS_ASSERT(_pKernel);
|
BS_ASSERT(_pKernel);
|
||||||
BS_PackageManager* pPackage = static_cast<BS_PackageManager *>(_pKernel->GetService("package"));
|
BS_PackageManager *pPackage = static_cast<BS_PackageManager *>(_pKernel->GetService("package"));
|
||||||
BS_ASSERT(pPackage);
|
BS_ASSERT(pPackage);
|
||||||
|
|
||||||
// Die Daten werden zunächst über den Package-Manager gelesen und dann in einen um ein Byte größeren Buffer kopiert
|
// Die Daten werden zunächst über den Package-Manager gelesen und dann in einen um ein Byte größeren Buffer kopiert
|
||||||
// und NULL-Terminiert, da TinyXML NULL-Terminierte Daten benötigt.
|
// und NULL-Terminiert, da TinyXML NULL-Terminierte Daten benötigt.
|
||||||
unsigned int FileSize;
|
unsigned int FileSize;
|
||||||
char * LoadBuffer = (char*) pPackage->GetFile(GetFileName(), &FileSize);
|
char *LoadBuffer = (char *) pPackage->GetFile(GetFileName(), &FileSize);
|
||||||
if (!LoadBuffer)
|
if (!LoadBuffer) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not read \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("Could not read \"%s\".", GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -182,21 +171,18 @@ bool BS_FontResource::_ParseXMLDocument(const Common::String & FileName, TiXmlDo
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_FontResource::_ParseFontTag(TiXmlElement & Tag, Common::String & BitmapFileName, int & Lineheight, int & GapWidth) const
|
bool BS_FontResource::_ParseFontTag(TiXmlElement &Tag, Common::String &BitmapFileName, int &Lineheight, int &GapWidth) const {
|
||||||
{
|
|
||||||
// Bitmap Attribut auslesen
|
// Bitmap Attribut auslesen
|
||||||
const char * BitmapString = Tag.Attribute("bitmap");
|
const char *BitmapString = Tag.Attribute("bitmap");
|
||||||
if (!BitmapString)
|
if (!BitmapString) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("<font> tag without bitmap attribute occurred in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("<font> tag without bitmap attribute occurred in \"%s\".", GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
BitmapFileName = BitmapString;
|
BitmapFileName = BitmapString;
|
||||||
|
|
||||||
// Lineheight Attribut auslesen
|
// Lineheight Attribut auslesen
|
||||||
const char * LineheightString = Tag.Attribute("lineheight");
|
const char *LineheightString = Tag.Attribute("lineheight");
|
||||||
if (!LineheightString || !BS_String::ToInt(Common::String(LineheightString), Lineheight) || Lineheight < 0)
|
if (!LineheightString || !BS_String::ToInt(Common::String(LineheightString), Lineheight) || Lineheight < 0) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Illegal or missing lineheight attribute in <font> tag in \"%s\". Assuming default (\"%d\").",
|
BS_LOG_WARNINGLN("Illegal or missing lineheight attribute in <font> tag in \"%s\". Assuming default (\"%d\").",
|
||||||
GetFileName().c_str(), DEFAULT_LINEHEIGHT);
|
GetFileName().c_str(), DEFAULT_LINEHEIGHT);
|
||||||
Lineheight = DEFAULT_LINEHEIGHT;
|
Lineheight = DEFAULT_LINEHEIGHT;
|
||||||
|
@ -204,9 +190,8 @@ bool BS_FontResource::_ParseFontTag(TiXmlElement & Tag, Common::String & BitmapF
|
||||||
|
|
||||||
|
|
||||||
// Gap Attribut auslesen
|
// Gap Attribut auslesen
|
||||||
const char * GapString = Tag.Attribute("gap");
|
const char *GapString = Tag.Attribute("gap");
|
||||||
if (!GapString || !BS_String::ToInt(Common::String(GapString), GapWidth) || GapWidth < 0)
|
if (!GapString || !BS_String::ToInt(Common::String(GapString), GapWidth) || GapWidth < 0) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Illegal or missing gap attribute in <font> tag in \"%s\". Assuming default (\"%d\").",
|
BS_LOG_WARNINGLN("Illegal or missing gap attribute in <font> tag in \"%s\". Assuming default (\"%d\").",
|
||||||
GetFileName().c_str(), DEFAULT_GAPWIDTH);
|
GetFileName().c_str(), DEFAULT_GAPWIDTH);
|
||||||
GapWidth = DEFAULT_GAPWIDTH;
|
GapWidth = DEFAULT_GAPWIDTH;
|
||||||
|
@ -217,12 +202,10 @@ bool BS_FontResource::_ParseFontTag(TiXmlElement & Tag, Common::String & BitmapF
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_FontResource::_ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect & Rect) const
|
bool BS_FontResource::_ParseCharacterTag(TiXmlElement &Tag, int &Code, BS_Rect &Rect) const {
|
||||||
{
|
|
||||||
// Code Attribut auslesen
|
// Code Attribut auslesen
|
||||||
const char * CodeString = Tag.Attribute("code");
|
const char *CodeString = Tag.Attribute("code");
|
||||||
if (!CodeString || !BS_String::ToInt(Common::String(CodeString), Code) || Code < 0 || Code >= 256)
|
if (!CodeString || !BS_String::ToInt(Common::String(CodeString), Code) || Code < 0 || Code >= 256) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Illegal or missing code attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("Illegal or missing code attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +221,7 @@ bool BS_FontResource::_ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect
|
||||||
Rect.left = tmp;
|
Rect.left = tmp;
|
||||||
|
|
||||||
// Right Attribut auslesen
|
// Right Attribut auslesen
|
||||||
const char * RightString = Tag.Attribute("right");
|
const char *RightString = Tag.Attribute("right");
|
||||||
if (!RightString || !BS_String::ToInt(RightString, tmp) || tmp < 0) {
|
if (!RightString || !BS_String::ToInt(RightString, tmp) || tmp < 0) {
|
||||||
BS_LOG_ERRORLN("Illegal or missing right attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("Illegal or missing right attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
|
@ -246,7 +229,7 @@ bool BS_FontResource::_ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect
|
||||||
Rect.right = tmp;
|
Rect.right = tmp;
|
||||||
|
|
||||||
// Top Attribut auslesen
|
// Top Attribut auslesen
|
||||||
const char * TopString = Tag.Attribute("top");
|
const char *TopString = Tag.Attribute("top");
|
||||||
if (!TopString || !BS_String::ToInt(TopString, tmp) || tmp < 0) {
|
if (!TopString || !BS_String::ToInt(TopString, tmp) || tmp < 0) {
|
||||||
BS_LOG_ERRORLN("Illegal or missing top attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("Illegal or missing top attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
|
@ -254,9 +237,8 @@ bool BS_FontResource::_ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect
|
||||||
Rect.top = tmp;
|
Rect.top = tmp;
|
||||||
|
|
||||||
// Bottom Attribut auslesen
|
// Bottom Attribut auslesen
|
||||||
const char * BottomString = Tag.Attribute("bottom");
|
const char *BottomString = Tag.Attribute("bottom");
|
||||||
if (!BottomString || !BS_String::ToInt(BottomString, tmp) || tmp < 0)
|
if (!BottomString || !BS_String::ToInt(BottomString, tmp) || tmp < 0) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Illegal or missing bottom attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
BS_LOG_ERRORLN("Illegal or missing bottom attribute in <character> tag in \"%s\".", GetFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,8 +58,7 @@ class BS_Kernel;
|
||||||
// Klassendefinition
|
// Klassendefinition
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_FontResource : public BS_Resource
|
class BS_FontResource : public BS_Resource {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@brief Erzeugt eine neues Exemplar von BS_FontResource
|
@brief Erzeugt eine neues Exemplar von BS_FontResource
|
||||||
|
@ -67,43 +66,54 @@ public:
|
||||||
@param FileName der Dateiname der zu ladenen Resource
|
@param FileName der Dateiname der zu ladenen Resource
|
||||||
@remark Wenn der Konstruktor erfolgreich ausgeführt werden konnte gibt die Methode IsValid true zurück.
|
@remark Wenn der Konstruktor erfolgreich ausgeführt werden konnte gibt die Methode IsValid true zurück.
|
||||||
*/
|
*/
|
||||||
BS_FontResource(BS_Kernel * pKernel, const Common::String & FileName);
|
BS_FontResource(BS_Kernel *pKernel, const Common::String &FileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt true zurück, wenn das Objekt korrekt initialisiert wurde.
|
@brief Gibt true zurück, wenn das Objekt korrekt initialisiert wurde.
|
||||||
|
|
||||||
Diese Methode kann dazu benutzt werden um festzustellen, ob der Konstruktor erfolgreich ausgeführt wurde.
|
Diese Methode kann dazu benutzt werden um festzustellen, ob der Konstruktor erfolgreich ausgeführt wurde.
|
||||||
*/
|
*/
|
||||||
bool IsValid() const { return _Valid; }
|
bool IsValid() const {
|
||||||
|
return _Valid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Zeilenhöhe des Fonts in Pixeln zurück.
|
@brief Gibt die Zeilenhöhe des Fonts in Pixeln zurück.
|
||||||
|
|
||||||
Die Zeilenhöhe ist der Wert, der zur Y-Koordinate addiert wird, wenn ein Zeilenumbruch auftritt.
|
Die Zeilenhöhe ist der Wert, der zur Y-Koordinate addiert wird, wenn ein Zeilenumbruch auftritt.
|
||||||
*/
|
*/
|
||||||
int GetLineHeight() const { return _LineHeight; }
|
int GetLineHeight() const {
|
||||||
|
return _LineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt den Buchstabenabstand der Fonts in Pixeln zurück.
|
@brief Gibt den Buchstabenabstand der Fonts in Pixeln zurück.
|
||||||
|
|
||||||
Der Buchstabenabstand ist der Wert, der zwischen zwei Buchstaben freigelassen wird.
|
Der Buchstabenabstand ist der Wert, der zwischen zwei Buchstaben freigelassen wird.
|
||||||
*/
|
*/
|
||||||
int GetGapWidth() const { return _GapWidth; }
|
int GetGapWidth() const {
|
||||||
|
return _GapWidth;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt das Bounding-Rect eines Zeichens auf der Charactermap zurück.
|
@brief Gibt das Bounding-Rect eines Zeichens auf der Charactermap zurück.
|
||||||
@param Character der ASCII-Code des Zeichens
|
@param Character der ASCII-Code des Zeichens
|
||||||
@return Das Bounding-Rect des übergebenen Zeichens auf der Charactermap.
|
@return Das Bounding-Rect des übergebenen Zeichens auf der Charactermap.
|
||||||
*/
|
*/
|
||||||
const BS_Rect & GetCharacterRect(int Character) const { BS_ASSERT(Character >= 0 && Character < 256); return _CharacterRects[Character]; }
|
const BS_Rect &GetCharacterRect(int Character) const {
|
||||||
|
BS_ASSERT(Character >= 0 && Character < 256);
|
||||||
|
return _CharacterRects[Character];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt den Dateinamen der Charactermap zurück.
|
@brief Gibt den Dateinamen der Charactermap zurück.
|
||||||
*/
|
*/
|
||||||
const Common::String & GetCharactermapFileName() const { return _BitmapFileName; }
|
const Common::String &GetCharactermapFileName() const {
|
||||||
|
return _BitmapFileName;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BS_Kernel * _pKernel;
|
BS_Kernel *_pKernel;
|
||||||
bool _Valid;
|
bool _Valid;
|
||||||
Common::String _BitmapFileName;
|
Common::String _BitmapFileName;
|
||||||
int _LineHeight;
|
int _LineHeight;
|
||||||
|
@ -114,9 +124,9 @@ private:
|
||||||
// Hilfsmethoden
|
// Hilfsmethoden
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool _ParseXMLDocument(const Common::String & FileName, TiXmlDocument & Doc) const;
|
bool _ParseXMLDocument(const Common::String &FileName, TiXmlDocument &Doc) const;
|
||||||
bool _ParseFontTag(TiXmlElement & Tag, Common::String & BitmapFileName, int & LineHeight, int & GapWidth) const;
|
bool _ParseFontTag(TiXmlElement &Tag, Common::String &BitmapFileName, int &LineHeight, int &GapWidth) const;
|
||||||
bool _ParseCharacterTag(TiXmlElement & Tag, int & Code, BS_Rect & Rect) const;
|
bool _ParseCharacterTag(TiXmlElement &Tag, int &Code, BS_Rect &Rect) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sword25
|
} // End of namespace Sword25
|
||||||
|
|
|
@ -44,8 +44,7 @@ BS_Framecounter::BS_Framecounter(int UpdateFrequency) :
|
||||||
SetUpdateFrequency(UpdateFrequency);
|
SetUpdateFrequency(UpdateFrequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_Framecounter::Update()
|
void BS_Framecounter::Update() {
|
||||||
{
|
|
||||||
// Aktuellen Systemtimerstand auslesen
|
// Aktuellen Systemtimerstand auslesen
|
||||||
uint64_t Timer = g_system->getMillis() * 1000;
|
uint64_t Timer = g_system->getMillis() * 1000;
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns the current FPS value.
|
* Returns the current FPS value.
|
||||||
*/
|
*/
|
||||||
int GetFPS() const { return m_FPS; }
|
int GetFPS() const {
|
||||||
|
return m_FPS;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_FPS;
|
int m_FPS;
|
||||||
|
|
|
@ -60,18 +60,17 @@ using namespace Lua;
|
||||||
|
|
||||||
static const unsigned int FRAMETIME_SAMPLE_COUNT = 5; // Anzahl der Framezeiten über die, die Framezeit gemittelt wird
|
static const unsigned int FRAMETIME_SAMPLE_COUNT = 5; // Anzahl der Framezeiten über die, die Framezeit gemittelt wird
|
||||||
|
|
||||||
BS_GraphicEngine::BS_GraphicEngine(BS_Kernel * pKernel) :
|
BS_GraphicEngine::BS_GraphicEngine(BS_Kernel *pKernel) :
|
||||||
m_Width(0),
|
m_Width(0),
|
||||||
m_Height(0),
|
m_Height(0),
|
||||||
m_BitDepth(0),
|
m_BitDepth(0),
|
||||||
m_Windowed(0),
|
m_Windowed(0),
|
||||||
m_LastTimeStamp((uint64)-1), // max. BS_INT64 um beim ersten Aufruf von _UpdateLastFrameDuration() einen Reset zu erzwingen
|
m_LastTimeStamp((uint64) - 1), // max. BS_INT64 um beim ersten Aufruf von _UpdateLastFrameDuration() einen Reset zu erzwingen
|
||||||
m_LastFrameDuration(0),
|
m_LastFrameDuration(0),
|
||||||
m_TimerActive(true),
|
m_TimerActive(true),
|
||||||
m_FrameTimeSampleSlot(0),
|
m_FrameTimeSampleSlot(0),
|
||||||
m_RepaintedPixels(0),
|
m_RepaintedPixels(0),
|
||||||
BS_ResourceService(pKernel)
|
BS_ResourceService(pKernel) {
|
||||||
{
|
|
||||||
for (int i = 0; i < FRAMETIME_SAMPLE_COUNT; i++)
|
for (int i = 0; i < FRAMETIME_SAMPLE_COUNT; i++)
|
||||||
m_FrameTimeSamples[i] = 0;
|
m_FrameTimeSamples[i] = 0;
|
||||||
|
|
||||||
|
@ -83,8 +82,7 @@ BS_GraphicEngine::BS_GraphicEngine(BS_Kernel * pKernel) :
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_GraphicEngine::UpdateLastFrameDuration()
|
void BS_GraphicEngine::UpdateLastFrameDuration() {
|
||||||
{
|
|
||||||
// Aktuelle Zeit holen
|
// Aktuelle Zeit holen
|
||||||
uint64_t CurrentTime = BS_Kernel::GetInstance()->GetMicroTicks();
|
uint64_t CurrentTime = BS_Kernel::GetInstance()->GetMicroTicks();
|
||||||
|
|
||||||
|
@ -106,15 +104,12 @@ void BS_GraphicEngine::UpdateLastFrameDuration()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
bool DoSaveScreenshot(BS_GraphicEngine &GraphicEngine, const Common::String &Filename, bool Thumbnail) {
|
||||||
bool DoSaveScreenshot(BS_GraphicEngine & GraphicEngine, const Common::String & Filename, bool Thumbnail)
|
|
||||||
{
|
|
||||||
unsigned int Width;
|
unsigned int Width;
|
||||||
unsigned int Height;
|
unsigned int Height;
|
||||||
Common::Array<unsigned int> Data;
|
Common::Array<unsigned int> Data;
|
||||||
if (!GraphicEngine.GetScreenshot(Width, Height, Data))
|
if (!GraphicEngine.GetScreenshot(Width, Height, Data)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Call to GetScreenshot() failed. Cannot save screenshot.");
|
BS_LOG_ERRORLN("Call to GetScreenshot() failed. Cannot save screenshot.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -125,29 +120,25 @@ namespace
|
||||||
return BS_Screenshot::SaveThumbnailToFile(Width, Height, Data, Filename);
|
return BS_Screenshot::SaveThumbnailToFile(Width, Height, Data, Filename);
|
||||||
else
|
else
|
||||||
return BS_Screenshot::SaveToFile(Width, Height, Data, Filename);
|
return BS_Screenshot::SaveToFile(Width, Height, Data, Filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_GraphicEngine::SaveScreenshot(const Common::String & Filename)
|
bool BS_GraphicEngine::SaveScreenshot(const Common::String &Filename) {
|
||||||
{
|
|
||||||
return DoSaveScreenshot(*this, Filename, false);
|
return DoSaveScreenshot(*this, Filename, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_GraphicEngine::SaveThumbnailScreenshot( const Common::String & Filename )
|
bool BS_GraphicEngine::SaveThumbnailScreenshot(const Common::String &Filename) {
|
||||||
{
|
|
||||||
return DoSaveScreenshot(*this, Filename, true);
|
return DoSaveScreenshot(*this, Filename, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_GraphicEngine::ARGBColorToLuaColor(lua_State * L, unsigned int Color)
|
void BS_GraphicEngine::ARGBColorToLuaColor(lua_State *L, unsigned int Color) {
|
||||||
{
|
lua_Number Components[4] = {
|
||||||
lua_Number Components[4] =
|
|
||||||
{
|
|
||||||
(Color >> 16) & 0xff, // Rot
|
(Color >> 16) & 0xff, // Rot
|
||||||
(Color >> 8) & 0xff, // Grün
|
(Color >> 8) & 0xff, // Grün
|
||||||
Color & 0xff, // Blau
|
Color & 0xff, // Blau
|
||||||
|
@ -156,8 +147,7 @@ void BS_GraphicEngine::ARGBColorToLuaColor(lua_State * L, unsigned int Color)
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
|
||||||
for (unsigned int i = 1; i <= 4; i++)
|
for (unsigned int i = 1; i <= 4; i++) {
|
||||||
{
|
|
||||||
lua_pushnumber(L, i);
|
lua_pushnumber(L, i);
|
||||||
lua_pushnumber(L, Components[i - 1]);
|
lua_pushnumber(L, Components[i - 1]);
|
||||||
lua_settable(L, -3);
|
lua_settable(L, -3);
|
||||||
|
@ -166,8 +156,7 @@ void BS_GraphicEngine::ARGBColorToLuaColor(lua_State * L, unsigned int Color)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_GraphicEngine::LuaColorToARGBColor(lua_State * L, int StackIndex)
|
unsigned int BS_GraphicEngine::LuaColorToARGBColor(lua_State *L, int StackIndex) {
|
||||||
{
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
int __startStackDepth = lua_gettop(L);
|
int __startStackDepth = lua_gettop(L);
|
||||||
#endif
|
#endif
|
||||||
|
@ -199,8 +188,7 @@ unsigned int BS_GraphicEngine::LuaColorToARGBColor(lua_State * L, int StackIndex
|
||||||
|
|
||||||
// Alpha Farbkomponente auslesen
|
// Alpha Farbkomponente auslesen
|
||||||
unsigned int Alpha = 0xff;
|
unsigned int Alpha = 0xff;
|
||||||
if (n == 4)
|
if (n == 4) {
|
||||||
{
|
|
||||||
lua_rawgeti(L, StackIndex, 4);
|
lua_rawgeti(L, StackIndex, 4);
|
||||||
Alpha = static_cast<unsigned int>(lua_tonumber(L, -1));
|
Alpha = static_cast<unsigned int>(lua_tonumber(L, -1));
|
||||||
if (!lua_isnumber(L, -1) || Alpha >= 256) luaL_argcheck(L, 0, StackIndex, "alpha color component must be an integer between 0 and 255");
|
if (!lua_isnumber(L, -1) || Alpha >= 256) luaL_argcheck(L, 0, StackIndex, "alpha color component must be an integer between 0 and 255");
|
||||||
|
@ -216,16 +204,14 @@ unsigned int BS_GraphicEngine::LuaColorToARGBColor(lua_State * L, int StackIndex
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_GraphicEngine::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_GraphicEngine::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
Writer.Write(m_TimerActive);
|
Writer.Write(m_TimerActive);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_GraphicEngine::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_GraphicEngine::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
Reader.Read(m_TimerActive);
|
Reader.Read(m_TimerActive);
|
||||||
return Reader.IsGood();
|
return Reader.IsGood();
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,38 +207,58 @@ public:
|
||||||
/**
|
/**
|
||||||
* Specifies the time (in microseconds) since the last frame has passed
|
* Specifies the time (in microseconds) since the last frame has passed
|
||||||
*/
|
*/
|
||||||
int GetLastFrameDurationMicro() { if (m_TimerActive) return m_LastFrameDuration; else return 0; }
|
int GetLastFrameDurationMicro() {
|
||||||
|
if (m_TimerActive) return m_LastFrameDuration;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the time (in microseconds) the previous frame took
|
* Specifies the time (in microseconds) the previous frame took
|
||||||
*/
|
*/
|
||||||
float GetLastFrameDuration() { if (m_TimerActive) return static_cast<float>(m_LastFrameDuration) / 1000000.0f; else return 0; }
|
float GetLastFrameDuration() {
|
||||||
|
if (m_TimerActive) return static_cast<float>(m_LastFrameDuration) / 1000000.0f;
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void StopMainTimer() { m_TimerActive = false; }
|
void StopMainTimer() {
|
||||||
void ResumeMainTimer() { m_TimerActive = true; }
|
m_TimerActive = false;
|
||||||
float GetSecondaryFrameDuration() { return static_cast<float>(m_LastFrameDuration) / 1000000.0f; }
|
}
|
||||||
|
void ResumeMainTimer() {
|
||||||
|
m_TimerActive = true;
|
||||||
|
}
|
||||||
|
float GetSecondaryFrameDuration() {
|
||||||
|
return static_cast<float>(m_LastFrameDuration) / 1000000.0f;
|
||||||
|
}
|
||||||
|
|
||||||
// Accessor methods
|
// Accessor methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the width of the output buffer in pixels
|
* Returns the width of the output buffer in pixels
|
||||||
*/
|
*/
|
||||||
int GetDisplayWidth() { return m_Width; }
|
int GetDisplayWidth() {
|
||||||
|
return m_Width;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the height of the output buffer in pixels
|
* Returns the height of the output buffer in pixels
|
||||||
*/
|
*/
|
||||||
int GetDisplayHeight() { return m_Height; }
|
int GetDisplayHeight() {
|
||||||
|
return m_Height;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the bounding box of the output buffer: (0, 0, Width, Height)
|
* Returns the bounding box of the output buffer: (0, 0, Width, Height)
|
||||||
*/
|
*/
|
||||||
BS_Rect& GetDisplayRect() { return m_ScreenRect; }
|
BS_Rect &GetDisplayRect() {
|
||||||
|
return m_ScreenRect;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the bit depth of the output buffer
|
* Returns the bit depth of the output buffer
|
||||||
*/
|
*/
|
||||||
int GetBitDepth() { return m_BitDepth; }
|
int GetBitDepth() {
|
||||||
|
return m_BitDepth;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the frame buffer change is to be synchronised with Vsync. This is turned on by default.
|
* Determines whether the frame buffer change is to be synchronised with Vsync. This is turned on by default.
|
||||||
|
@ -256,7 +276,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns true if the engine is running in Windowed mode.
|
* Returns true if the engine is running in Windowed mode.
|
||||||
*/
|
*/
|
||||||
bool IsWindowed() { return m_Windowed; }
|
bool IsWindowed() {
|
||||||
|
return m_Windowed;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills a rectangular area of the frame buffer with a colour.
|
* Fills a rectangular area of the frame buffer with a colour.
|
||||||
|
@ -267,12 +289,16 @@ public:
|
||||||
* @param Color The 32-bit colour with which the area is to be filled. The default is BS_RGB(0, 0, 0) (black)
|
* @param Color The 32-bit colour with which the area is to be filled. The default is BS_RGB(0, 0, 0) (black)
|
||||||
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
||||||
*/
|
*/
|
||||||
virtual bool Fill(const BS_Rect * FillRectPtr = 0, unsigned int Color = BS_RGB(0, 0, 0)) = 0;
|
virtual bool Fill(const BS_Rect *FillRectPtr = 0, unsigned int Color = BS_RGB(0, 0, 0)) = 0;
|
||||||
|
|
||||||
// Debugging Methods
|
// Debugging Methods
|
||||||
|
|
||||||
int GetFPSCount() const { return m_FPSCounter.GetFPS(); }
|
int GetFPSCount() const {
|
||||||
int GetRepaintedPixels() const { return m_RepaintedPixels; }
|
return m_FPSCounter.GetFPS();
|
||||||
|
}
|
||||||
|
int GetRepaintedPixels() const {
|
||||||
|
return m_RepaintedPixels;
|
||||||
|
}
|
||||||
|
|
||||||
// Access methods
|
// Access methods
|
||||||
|
|
||||||
|
@ -306,7 +332,7 @@ public:
|
||||||
* unknown, -1 is returned
|
* unknown, -1 is returned
|
||||||
*/
|
*/
|
||||||
static int CalcPitch(BS_GraphicEngine::COLOR_FORMATS ColorFormat, int Width) {
|
static int CalcPitch(BS_GraphicEngine::COLOR_FORMATS ColorFormat, int Width) {
|
||||||
switch (ColorFormat){
|
switch (ColorFormat) {
|
||||||
case BS_GraphicEngine::CF_RGB16:
|
case BS_GraphicEngine::CF_RGB16:
|
||||||
case BS_GraphicEngine::CF_RGB15:
|
case BS_GraphicEngine::CF_RGB15:
|
||||||
return Width * 2;
|
return Width * 2;
|
||||||
|
@ -337,7 +363,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
// Constructor
|
// Constructor
|
||||||
// -----------
|
// -----------
|
||||||
BS_GraphicEngine(BS_Kernel* pKernel);
|
BS_GraphicEngine(BS_Kernel *pKernel);
|
||||||
|
|
||||||
// Display Variables
|
// Display Variables
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -50,10 +50,8 @@ namespace Sword25 {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
unsigned int FindEmbeddedPNG(const char *FileDataPtr, unsigned int FileSize) {
|
||||||
unsigned int FindEmbeddedPNG(const char * FileDataPtr, unsigned int FileSize)
|
|
||||||
{
|
|
||||||
// Einen Stringstream mit dem Anfang der Datei intialisieren. 512 Byte sollten hierfür genügen.
|
// Einen Stringstream mit dem Anfang der Datei intialisieren. 512 Byte sollten hierfür genügen.
|
||||||
istringstream StringStream(string(FileDataPtr, FileDataPtr + min(static_cast<unsigned int>(512), FileSize)));
|
istringstream StringStream(string(FileDataPtr, FileDataPtr + min(static_cast<unsigned int>(512), FileSize)));
|
||||||
|
|
||||||
|
@ -64,24 +62,21 @@ namespace
|
||||||
if (!StringStream.good()) return 0;
|
if (!StringStream.good()) return 0;
|
||||||
|
|
||||||
// Testen, ob wir tatsächlich einen Spielstand haben.
|
// Testen, ob wir tatsächlich einen Spielstand haben.
|
||||||
if (Marker == "BS25SAVEGAME")
|
if (Marker == "BS25SAVEGAME") {
|
||||||
{
|
|
||||||
// Offset zum PNG innerhalb des Spielstandes berechnen und zurückgeben.
|
// Offset zum PNG innerhalb des Spielstandes berechnen und zurückgeben.
|
||||||
return static_cast<unsigned int>(StringStream.tellg()) + CompressedGamedataSize + 1;
|
return static_cast<unsigned int>(StringStream.tellg()) + CompressedGamedataSize + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_B25SLoader::IsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize)
|
bool BS_B25SLoader::IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize) {
|
||||||
{
|
|
||||||
// PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen.
|
// PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen.
|
||||||
unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize);
|
unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize);
|
||||||
if (PNGOffset > 0)
|
if (PNGOffset > 0) {
|
||||||
{
|
|
||||||
return BS_PNGLoader::DoIsCorrectImageFormat(FileDataPtr + PNGOffset, FileSize - PNGOffset);
|
return BS_PNGLoader::DoIsCorrectImageFormat(FileDataPtr + PNGOffset, FileSize - PNGOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,13 +85,11 @@ bool BS_B25SLoader::IsCorrectImageFormat(const char * FileDataPtr, unsigned int
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_B25SLoader::DecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
bool BS_B25SLoader::DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||||
int & Width, int & Height, int & Pitch)
|
int &Width, int &Height, int &Pitch) {
|
||||||
{
|
|
||||||
// PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen.
|
// PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen.
|
||||||
unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize);
|
unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize);
|
||||||
if (PNGOffset > 0)
|
if (PNGOffset > 0) {
|
||||||
{
|
|
||||||
return BS_PNGLoader::DoDecodeImage(FileDataPtr + PNGOffset, FileSize - PNGOffset, ColorFormat, UncompressedDataPtr, Width, Height, Pitch);
|
return BS_PNGLoader::DoDecodeImage(FileDataPtr + PNGOffset, FileSize - PNGOffset, ColorFormat, UncompressedDataPtr, Width, Height, Pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,12 +98,10 @@ bool BS_B25SLoader::DecodeImage(const char * FileDataPtr, unsigned int FileSize,
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_B25SLoader::ImageProperties(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height)
|
bool BS_B25SLoader::ImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height) {
|
||||||
{
|
|
||||||
// PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen.
|
// PNG innerhalb des Spielstandes finden und den Methodenaufruf zu BS_PNGLoader weiterreichen.
|
||||||
unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize);
|
unsigned int PNGOffset = FindEmbeddedPNG(FileDataPtr, FileSize);
|
||||||
if (PNGOffset > 0)
|
if (PNGOffset > 0) {
|
||||||
{
|
|
||||||
return BS_PNGLoader::DoImageProperties(FileDataPtr + PNGOffset, FileSize - PNGOffset, ColorFormat, Width, Height);
|
return BS_PNGLoader::DoImageProperties(FileDataPtr + PNGOffset, FileSize - PNGOffset, ColorFormat, Width, Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,21 +48,19 @@ namespace Sword25 {
|
||||||
// Klassendeklaration
|
// Klassendeklaration
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_B25SLoader : public BS_ImageLoader
|
class BS_B25SLoader : public BS_ImageLoader {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static BS_ImageLoader * CreateInstance()
|
static BS_ImageLoader *CreateInstance() {
|
||||||
{
|
#include "sword25/kernel/memlog_off.h"
|
||||||
#include "sword25/kernel/memlog_off.h"
|
|
||||||
return static_cast<BS_ImageLoader *>(new BS_B25SLoader());
|
return static_cast<BS_ImageLoader *>(new BS_B25SLoader());
|
||||||
#include "sword25/kernel/memlog_on.h"
|
#include "sword25/kernel/memlog_on.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool IsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize);
|
virtual bool IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize);
|
||||||
virtual bool DecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
virtual bool DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||||
int & Width, int & Height, int & Pitch);
|
int &Width, int &Height, int &Pitch);
|
||||||
virtual bool ImageProperties(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height);
|
virtual bool ImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,7 @@
|
||||||
|
|
||||||
namespace Sword25 {
|
namespace Sword25 {
|
||||||
|
|
||||||
class BS_Image
|
class BS_Image {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
virtual ~BS_Image() {};
|
virtual ~BS_Image() {};
|
||||||
|
|
||||||
|
@ -61,8 +60,7 @@ public:
|
||||||
/**
|
/**
|
||||||
@brief Die möglichen Flippingparameter für die Blit-Methode.
|
@brief Die möglichen Flippingparameter für die Blit-Methode.
|
||||||
*/
|
*/
|
||||||
enum FLIP_FLAGS
|
enum FLIP_FLAGS {
|
||||||
{
|
|
||||||
/// Das Bild wird nicht gespiegelt.
|
/// Das Bild wird nicht gespiegelt.
|
||||||
FLIP_NONE = 0,
|
FLIP_NONE = 0,
|
||||||
/// Das Bild wird an der horizontalen Achse gespiegelt.
|
/// Das Bild wird an der horizontalen Achse gespiegelt.
|
||||||
|
@ -138,7 +136,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||||
int Flipping = FLIP_NONE,
|
int Flipping = FLIP_NONE,
|
||||||
BS_Rect* pPartRect = NULL,
|
BS_Rect *pPartRect = NULL,
|
||||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||||
int Width = -1, int Height = -1) = 0;
|
int Width = -1, int Height = -1) = 0;
|
||||||
|
|
||||||
|
@ -154,7 +152,7 @@ public:
|
||||||
BS_RGB und BS_ARGB benutzt werden.
|
BS_RGB und BS_ARGB benutzt werden.
|
||||||
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
@remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt.
|
||||||
*/
|
*/
|
||||||
virtual bool Fill(const BS_Rect* pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0)) = 0;
|
virtual bool Fill(const BS_Rect *pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0)) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Füllt den Inhalt des Bildes mit Pixeldaten.
|
@brief Füllt den Inhalt des Bildes mit Pixeldaten.
|
||||||
|
|
|
@ -40,26 +40,24 @@ namespace Sword25 {
|
||||||
#define BS_LOG_PREFIX "IMAGELOADER"
|
#define BS_LOG_PREFIX "IMAGELOADER"
|
||||||
|
|
||||||
// Statische Elemente der Klasse BS_ImageLoader intialisieren.
|
// Statische Elemente der Klasse BS_ImageLoader intialisieren.
|
||||||
std::list<BS_ImageLoader*> BS_ImageLoader::_ImageLoaderList;
|
std::list<BS_ImageLoader *> BS_ImageLoader::_ImageLoaderList;
|
||||||
bool BS_ImageLoader::_ImageLoaderListInitialized = false;
|
bool BS_ImageLoader::_ImageLoaderListInitialized = false;
|
||||||
|
|
||||||
// Lade Methode
|
// Lade Methode
|
||||||
// ------------
|
// ------------
|
||||||
|
|
||||||
bool BS_ImageLoader::LoadImage(const char* pFileData, unsigned int FileSize,
|
bool BS_ImageLoader::LoadImage(const char *pFileData, unsigned int FileSize,
|
||||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||||
char*& pUncompressedData,
|
char*& pUncompressedData,
|
||||||
int& Width, int& Height,
|
int &Width, int &Height,
|
||||||
int& Pitch)
|
int &Pitch) {
|
||||||
{
|
|
||||||
// Falls die Liste der BS_ImageLoader noch nicht initialisiert wurde, wird dies getan.
|
// Falls die Liste der BS_ImageLoader noch nicht initialisiert wurde, wird dies getan.
|
||||||
if (!_ImageLoaderListInitialized)
|
if (!_ImageLoaderListInitialized)
|
||||||
_InitializeLoaderList();
|
_InitializeLoaderList();
|
||||||
|
|
||||||
// Passenden BS_ImageLoader finden und Bild dekodieren
|
// Passenden BS_ImageLoader finden und Bild dekodieren
|
||||||
BS_ImageLoader* pLoader = _FindSuitableImageLoader(pFileData, FileSize);
|
BS_ImageLoader *pLoader = _FindSuitableImageLoader(pFileData, FileSize);
|
||||||
if (pLoader)
|
if (pLoader) {
|
||||||
{
|
|
||||||
return pLoader->DecodeImage(pFileData, FileSize,
|
return pLoader->DecodeImage(pFileData, FileSize,
|
||||||
ColorFormat,
|
ColorFormat,
|
||||||
pUncompressedData,
|
pUncompressedData,
|
||||||
|
@ -73,18 +71,16 @@ bool BS_ImageLoader::LoadImage(const char* pFileData, unsigned int FileSize,
|
||||||
// Info Methode
|
// Info Methode
|
||||||
// ------------
|
// ------------
|
||||||
|
|
||||||
bool BS_ImageLoader::ExtractImageProperties(const char* pFileData, unsigned int FileSize,
|
bool BS_ImageLoader::ExtractImageProperties(const char *pFileData, unsigned int FileSize,
|
||||||
BS_GraphicEngine::COLOR_FORMATS& ColorFormat,
|
BS_GraphicEngine::COLOR_FORMATS &ColorFormat,
|
||||||
int& Width, int& Height)
|
int &Width, int &Height) {
|
||||||
{
|
|
||||||
// Falls die Liste der BS_ImageLoader noch nicht initialisiert wurde, wird dies getan.
|
// Falls die Liste der BS_ImageLoader noch nicht initialisiert wurde, wird dies getan.
|
||||||
if (!_ImageLoaderListInitialized)
|
if (!_ImageLoaderListInitialized)
|
||||||
_InitializeLoaderList();
|
_InitializeLoaderList();
|
||||||
|
|
||||||
// Passenden BS_ImageLoader finden und Bildeigenschaften auslesen.
|
// Passenden BS_ImageLoader finden und Bildeigenschaften auslesen.
|
||||||
BS_ImageLoader* pLoader = _FindSuitableImageLoader(pFileData, FileSize);
|
BS_ImageLoader *pLoader = _FindSuitableImageLoader(pFileData, FileSize);
|
||||||
if (pLoader)
|
if (pLoader) {
|
||||||
{
|
|
||||||
return pLoader->ImageProperties(pFileData, FileSize,
|
return pLoader->ImageProperties(pFileData, FileSize,
|
||||||
ColorFormat,
|
ColorFormat,
|
||||||
Width, Height);
|
Width, Height);
|
||||||
|
@ -96,8 +92,7 @@ bool BS_ImageLoader::ExtractImageProperties(const char* pFileData, unsigned int
|
||||||
// Verwaltungs Methoden
|
// Verwaltungs Methoden
|
||||||
// --------------------
|
// --------------------
|
||||||
|
|
||||||
void BS_ImageLoader::_InitializeLoaderList()
|
void BS_ImageLoader::_InitializeLoaderList() {
|
||||||
{
|
|
||||||
// Von jedem BS_ImageLoader wird eine Instanz erzeugt, diese fügen sich selbständig in die BS_ImageLoader-Liste ein.
|
// Von jedem BS_ImageLoader wird eine Instanz erzeugt, diese fügen sich selbständig in die BS_ImageLoader-Liste ein.
|
||||||
for (int i = 0; i < BS_IMAGELOADER_COUNT; i++)
|
for (int i = 0; i < BS_IMAGELOADER_COUNT; i++)
|
||||||
BS_IMAGELOADER_IDS[i]();
|
BS_IMAGELOADER_IDS[i]();
|
||||||
|
@ -109,24 +104,19 @@ void BS_ImageLoader::_InitializeLoaderList()
|
||||||
atexit(BS_ImageLoader::_DeinitializeLoaderList);
|
atexit(BS_ImageLoader::_DeinitializeLoaderList);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_ImageLoader::_DeinitializeLoaderList()
|
void BS_ImageLoader::_DeinitializeLoaderList() {
|
||||||
{
|
while (!_ImageLoaderList.empty()) {
|
||||||
while (!_ImageLoaderList.empty())
|
|
||||||
{
|
|
||||||
delete _ImageLoaderList.back();
|
delete _ImageLoaderList.back();
|
||||||
_ImageLoaderList.pop_back();
|
_ImageLoaderList.pop_back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_ImageLoader* BS_ImageLoader::_FindSuitableImageLoader(const char* pFileData, unsigned int FileSize)
|
BS_ImageLoader *BS_ImageLoader::_FindSuitableImageLoader(const char *pFileData, unsigned int FileSize) {
|
||||||
{
|
|
||||||
// Alle BS_ImageLoader-Objekte durchgehen, bis eins gefunden wurde, dass das Bild laden kann
|
// Alle BS_ImageLoader-Objekte durchgehen, bis eins gefunden wurde, dass das Bild laden kann
|
||||||
std::list<BS_ImageLoader*>::iterator Iter = _ImageLoaderList.begin();
|
std::list<BS_ImageLoader *>::iterator Iter = _ImageLoaderList.begin();
|
||||||
for (; Iter != _ImageLoaderList.end(); ++Iter)
|
for (; Iter != _ImageLoaderList.end(); ++Iter) {
|
||||||
{
|
|
||||||
// Falls ein geeigneter BS-ImageLoader gefunden wurde, wird er zurückgegeben.
|
// Falls ein geeigneter BS-ImageLoader gefunden wurde, wird er zurückgegeben.
|
||||||
if ((*Iter)->IsCorrectImageFormat(pFileData, FileSize))
|
if ((*Iter)->IsCorrectImageFormat(pFileData, FileSize)) {
|
||||||
{
|
|
||||||
return (*Iter);
|
return (*Iter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,7 @@ namespace Sword25 {
|
||||||
- Zum Konvertieren der Bilddaten können die Hilfsmethoden dieser Klasse benutzt werden, die ARGB Bilddaten in alle benötigten
|
- Zum Konvertieren der Bilddaten können die Hilfsmethoden dieser Klasse benutzt werden, die ARGB Bilddaten in alle benötigten
|
||||||
Farbformate konvertieren.
|
Farbformate konvertieren.
|
||||||
*/
|
*/
|
||||||
class BS_ImageLoader
|
class BS_ImageLoader {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//@{
|
//@{
|
||||||
|
@ -105,11 +104,11 @@ public:
|
||||||
@remark Die Größe der Ausgabedaten in Bytes kann wie folgt berechnet werden: Pitch * Height.
|
@remark Die Größe der Ausgabedaten in Bytes kann wie folgt berechnet werden: Pitch * Height.
|
||||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||||
*/
|
*/
|
||||||
static bool LoadImage(const char* pFileData, unsigned int FileSize,
|
static bool LoadImage(const char *pFileData, unsigned int FileSize,
|
||||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||||
char*& pUncompressedData,
|
char*& pUncompressedData,
|
||||||
int& Width, int& Height,
|
int &Width, int &Height,
|
||||||
int& Pitch);
|
int &Pitch);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Liest die Bildeigenschaften eines Bildes aus.
|
@brief Liest die Bildeigenschaften eines Bildes aus.
|
||||||
|
@ -122,9 +121,9 @@ public:
|
||||||
@return Gibt false zurück, wenn die Bildeigenschaften nicht ausgelesen werden konnten.
|
@return Gibt false zurück, wenn die Bildeigenschaften nicht ausgelesen werden konnten.
|
||||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||||
*/
|
*/
|
||||||
static bool ExtractImageProperties(const char* pFileData, unsigned int FileSize,
|
static bool ExtractImageProperties(const char *pFileData, unsigned int FileSize,
|
||||||
BS_GraphicEngine::COLOR_FORMATS& ColorFormat,
|
BS_GraphicEngine::COLOR_FORMATS &ColorFormat,
|
||||||
int& Width, int& Height);
|
int &Width, int &Height);
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -137,8 +136,7 @@ protected:
|
||||||
Diese Liste enthält jeweils eine Instanz jedes #BS_ImageLoader und wird benutzt um beliebige Bilddateien einem Loader zuzuordnen.
|
Diese Liste enthält jeweils eine Instanz jedes #BS_ImageLoader und wird benutzt um beliebige Bilddateien einem Loader zuzuordnen.
|
||||||
@remark Dieser Konstruktor ist protected damit nur #BS_ImageLoader-Objekte diese Klasse instanziieren können.
|
@remark Dieser Konstruktor ist protected damit nur #BS_ImageLoader-Objekte diese Klasse instanziieren können.
|
||||||
*/
|
*/
|
||||||
BS_ImageLoader()
|
BS_ImageLoader() {
|
||||||
{
|
|
||||||
// Klasse registrieren
|
// Klasse registrieren
|
||||||
_ImageLoaderList.push_front(this);
|
_ImageLoaderList.push_front(this);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +151,7 @@ protected:
|
||||||
@return Gibt true zurück, wenn der #BS_ImageLoader das Bild lesen kann, ansonsten false.
|
@return Gibt true zurück, wenn der #BS_ImageLoader das Bild lesen kann, ansonsten false.
|
||||||
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
||||||
*/
|
*/
|
||||||
virtual bool IsCorrectImageFormat(const char* pFileData, unsigned int FileSize) = 0;
|
virtual bool IsCorrectImageFormat(const char *pFileData, unsigned int FileSize) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Lädt eine Bilddatei.
|
@brief Lädt eine Bilddatei.
|
||||||
|
@ -175,11 +173,11 @@ protected:
|
||||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||||
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
||||||
*/
|
*/
|
||||||
virtual bool DecodeImage(const char* pFileData, unsigned int FileSize,
|
virtual bool DecodeImage(const char *pFileData, unsigned int FileSize,
|
||||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||||
char*& pUncompressedData,
|
char*& pUncompressedData,
|
||||||
int& Width, int& Height,
|
int &Width, int &Height,
|
||||||
int& Pitch) = 0;
|
int &Pitch) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Liest die Bildeigenschaften aus.
|
@brief Liest die Bildeigenschaften aus.
|
||||||
|
@ -192,9 +190,9 @@ protected:
|
||||||
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
@remark Es darf nicht vergessen werden, die Ausgabedaten nach erfolgter Benutzung mit delete freizugeben.
|
||||||
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
@remark Diese Methode muss von allen BS_ImageLoader Klassen implementiert werden.
|
||||||
*/
|
*/
|
||||||
virtual bool ImageProperties(const char* pFileData, unsigned int FileSize,
|
virtual bool ImageProperties(const char *pFileData, unsigned int FileSize,
|
||||||
BS_GraphicEngine::COLOR_FORMATS& ColorFormat,
|
BS_GraphicEngine::COLOR_FORMATS &ColorFormat,
|
||||||
int& Width, int& Height) = 0;
|
int &Width, int &Height) = 0;
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
@ -209,11 +207,9 @@ protected:
|
||||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
||||||
Es sind mindestens Width * 2 Byte notwendig.
|
Es sind mindestens Width * 2 Byte notwendig.
|
||||||
*/
|
*/
|
||||||
static void RowARGB32ToRGB16(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
static void RowARGB32ToRGB16(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||||
{
|
for (unsigned int i = 0; i < Width; i++) {
|
||||||
for (unsigned int i = 0; i < Width; i++)
|
((uint16_t *)pDestData)[i] = ((pSrcData[2] >> 3) << 11) | ((pSrcData[1] >> 2) << 5) | (pSrcData[0] >> 3);
|
||||||
{
|
|
||||||
((uint16_t*)pDestData)[i] = ((pSrcData[2] >> 3) << 11) | ((pSrcData[1] >> 2) << 5) | (pSrcData[0] >> 3);
|
|
||||||
pSrcData += 4;
|
pSrcData += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,11 +222,9 @@ protected:
|
||||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
||||||
Es sind mindestens Width * 2 Byte notwendig.
|
Es sind mindestens Width * 2 Byte notwendig.
|
||||||
*/
|
*/
|
||||||
static void RowARGB32ToRGB15(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
static void RowARGB32ToRGB15(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||||
{
|
for (unsigned int i = 0; i < Width; i++) {
|
||||||
for (unsigned int i = 0; i < Width; i++)
|
((uint16_t *)pDestData)[i] = ((pSrcData[2] >> 3) << 10) | ((pSrcData[1] >> 3) << 5) | (pSrcData[0] >> 3);
|
||||||
{
|
|
||||||
((uint16_t*)pDestData)[i] = ((pSrcData[2] >> 3) << 10) | ((pSrcData[1] >> 3) << 5) | (pSrcData[0] >> 3);
|
|
||||||
pSrcData += 4;
|
pSrcData += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,13 +237,11 @@ protected:
|
||||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß sein muss.<br>
|
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß sein muss.<br>
|
||||||
Es sind mindestens ((Width + 3) / 4) * 12 Byte notwendig.
|
Es sind mindestens ((Width + 3) / 4) * 12 Byte notwendig.
|
||||||
*/
|
*/
|
||||||
static void RowARGB32ToRGB16_INTERLEAVED(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
static void RowARGB32ToRGB16_INTERLEAVED(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||||
{
|
|
||||||
// Die Pixelblöcke erstellen, dabei werden immer jeweils 4 Pixel zu einem Block zusammengefasst
|
// Die Pixelblöcke erstellen, dabei werden immer jeweils 4 Pixel zu einem Block zusammengefasst
|
||||||
unsigned int BlockFillCount = 0;
|
unsigned int BlockFillCount = 0;
|
||||||
unsigned int AlphaBlock = 0;
|
unsigned int AlphaBlock = 0;
|
||||||
for (unsigned int i = 0; i < Width; i++)
|
for (unsigned int i = 0; i < Width; i++) {
|
||||||
{
|
|
||||||
// Alphawert in den Alphablock schreiben
|
// Alphawert in den Alphablock schreiben
|
||||||
AlphaBlock = (AlphaBlock >> 8) | (pSrcData[BlockFillCount * 4 + 3] << 24);
|
AlphaBlock = (AlphaBlock >> 8) | (pSrcData[BlockFillCount * 4 + 3] << 24);
|
||||||
|
|
||||||
|
@ -257,14 +249,13 @@ protected:
|
||||||
BlockFillCount++;
|
BlockFillCount++;
|
||||||
|
|
||||||
// Sobald 4 Alphawerte gesammelt wurden, oder die Zeile zu Ende ist wird der Pixelblock in den Zielpuffer geschrieben
|
// Sobald 4 Alphawerte gesammelt wurden, oder die Zeile zu Ende ist wird der Pixelblock in den Zielpuffer geschrieben
|
||||||
if (BlockFillCount == 4 || i == (Width - 1))
|
if (BlockFillCount == 4 || i == (Width - 1)) {
|
||||||
{
|
|
||||||
// Falls der AlphaBlock nicht ganz gefüllt ist muss geshiftet werden um sicherzustellen, dass die Alphawerte
|
// Falls der AlphaBlock nicht ganz gefüllt ist muss geshiftet werden um sicherzustellen, dass die Alphawerte
|
||||||
// "left aligned" sind.
|
// "left aligned" sind.
|
||||||
AlphaBlock >>= (4 - BlockFillCount) * 8;
|
AlphaBlock >>= (4 - BlockFillCount) * 8;
|
||||||
|
|
||||||
// Alphablock schreiben
|
// Alphablock schreiben
|
||||||
*((unsigned int*)pDestData) = AlphaBlock;
|
*((unsigned int *)pDestData) = AlphaBlock;
|
||||||
pDestData += 4;
|
pDestData += 4;
|
||||||
|
|
||||||
// Pixel konvertieren und schreiben
|
// Pixel konvertieren und schreiben
|
||||||
|
@ -290,13 +281,11 @@ protected:
|
||||||
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
@remark Es gilt zu beachten, dass der Zielpuffer ausreichend groß ist.<br>
|
||||||
Es sind mindestens (Width / 4 + Width % 4) * 3 Byte notwendig.
|
Es sind mindestens (Width / 4 + Width % 4) * 3 Byte notwendig.
|
||||||
*/
|
*/
|
||||||
static void RowARGB32ToRGB15_INTERLEAVED(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
static void RowARGB32ToRGB15_INTERLEAVED(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||||
{
|
|
||||||
// Die Pixelblöcke erstellen, dabei werden immer jeweils 4 Pixel zu einem Block zusammengefasst
|
// Die Pixelblöcke erstellen, dabei werden immer jeweils 4 Pixel zu einem Block zusammengefasst
|
||||||
unsigned int BlockFillCount = 0;
|
unsigned int BlockFillCount = 0;
|
||||||
unsigned int AlphaBlock = 0;
|
unsigned int AlphaBlock = 0;
|
||||||
for (unsigned int i = 0; i < Width; i++)
|
for (unsigned int i = 0; i < Width; i++) {
|
||||||
{
|
|
||||||
// Alphawert in den Alphablock schreiben
|
// Alphawert in den Alphablock schreiben
|
||||||
AlphaBlock = (AlphaBlock >> 8) | (pSrcData[BlockFillCount * 4 + 3] << 24);
|
AlphaBlock = (AlphaBlock >> 8) | (pSrcData[BlockFillCount * 4 + 3] << 24);
|
||||||
|
|
||||||
|
@ -304,14 +293,13 @@ protected:
|
||||||
BlockFillCount++;
|
BlockFillCount++;
|
||||||
|
|
||||||
// Sobald 4 Alphawerte gesammelt wurden, oder die Zeile zu Ende ist wird der Pixelblock in den Zielpuffer geschrieben
|
// Sobald 4 Alphawerte gesammelt wurden, oder die Zeile zu Ende ist wird der Pixelblock in den Zielpuffer geschrieben
|
||||||
if (BlockFillCount == 4 || i == (Width - 1))
|
if (BlockFillCount == 4 || i == (Width - 1)) {
|
||||||
{
|
|
||||||
// Falls der AlphaBlock nicht ganz gefüllt ist muss geshiftet werden um sicherzustellen, dass die Alphawerte
|
// Falls der AlphaBlock nicht ganz gefüllt ist muss geshiftet werden um sicherzustellen, dass die Alphawerte
|
||||||
// "left aligned" sind.
|
// "left aligned" sind.
|
||||||
AlphaBlock >>= (4 - BlockFillCount) * 8;
|
AlphaBlock >>= (4 - BlockFillCount) * 8;
|
||||||
|
|
||||||
// Alphablock schreiben
|
// Alphablock schreiben
|
||||||
*((unsigned int*)pDestData) = AlphaBlock;
|
*((unsigned int *)pDestData) = AlphaBlock;
|
||||||
pDestData += 4;
|
pDestData += 4;
|
||||||
|
|
||||||
// Pixel konvertieren und schreiben
|
// Pixel konvertieren und schreiben
|
||||||
|
@ -335,10 +323,8 @@ protected:
|
||||||
@param pDestData ein Pointer auf den Zielpuffern.
|
@param pDestData ein Pointer auf den Zielpuffern.
|
||||||
@param Width die Anzahl der Pixel in der Bildzeile.
|
@param Width die Anzahl der Pixel in der Bildzeile.
|
||||||
*/
|
*/
|
||||||
static void RowARGB32ToABGR32(unsigned char* pSrcData, unsigned char* pDestData, unsigned int Width)
|
static void RowARGB32ToABGR32(unsigned char *pSrcData, unsigned char *pDestData, unsigned int Width) {
|
||||||
{
|
for (unsigned int i = 0; i < Width; ++i) {
|
||||||
for (unsigned int i = 0; i < Width; ++i)
|
|
||||||
{
|
|
||||||
*pDestData++ = pSrcData[2];
|
*pDestData++ = pSrcData[2];
|
||||||
*pDestData++ = pSrcData[1];
|
*pDestData++ = pSrcData[1];
|
||||||
*pDestData++ = pSrcData[0];
|
*pDestData++ = pSrcData[0];
|
||||||
|
@ -366,9 +352,9 @@ private:
|
||||||
@brief Sucht zu Bilddaten ein BS_ImageLoader Objekt, dass die Bilddaten dekodieren kann.
|
@brief Sucht zu Bilddaten ein BS_ImageLoader Objekt, dass die Bilddaten dekodieren kann.
|
||||||
@return Gibt einen Pointer auf ein passendes BS_ImageLoader Objekt zurück, oder NULL, wenn kein passendes Objekt gefunden wurde.
|
@return Gibt einen Pointer auf ein passendes BS_ImageLoader Objekt zurück, oder NULL, wenn kein passendes Objekt gefunden wurde.
|
||||||
*/
|
*/
|
||||||
static BS_ImageLoader* _FindSuitableImageLoader(const char* pFileData, unsigned int FileSize);
|
static BS_ImageLoader *_FindSuitableImageLoader(const char *pFileData, unsigned int FileSize);
|
||||||
|
|
||||||
static std::list<BS_ImageLoader*> _ImageLoaderList; // Die Liste aller BS_ImageLoader-Objekte
|
static std::list<BS_ImageLoader *> _ImageLoaderList; // Die Liste aller BS_ImageLoader-Objekte
|
||||||
static bool _ImageLoaderListInitialized; // Gibt an, ob die Liste schon intialisiert wurde
|
static bool _ImageLoaderListInitialized; // Gibt an, ob die Liste schon intialisiert wurde
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,9 +51,8 @@ namespace Sword25 {
|
||||||
|
|
||||||
// Die Tabelle enthält Pointer auf statische Member-Funktionen innerhalb der Klassen, die eine Instanz der Klasse
|
// Die Tabelle enthält Pointer auf statische Member-Funktionen innerhalb der Klassen, die eine Instanz der Klasse
|
||||||
// erzeugen
|
// erzeugen
|
||||||
typedef BS_ImageLoader* (*BS_IMAGELOADER_NEW)();
|
typedef BS_ImageLoader*(*BS_IMAGELOADER_NEW)();
|
||||||
const BS_IMAGELOADER_NEW BS_IMAGELOADER_IDS[] =
|
const BS_IMAGELOADER_NEW BS_IMAGELOADER_IDS[] = {
|
||||||
{
|
|
||||||
BS_PNGLoader::CreateInstance,
|
BS_PNGLoader::CreateInstance,
|
||||||
BS_B25SLoader::CreateInstance,
|
BS_B25SLoader::CreateInstance,
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,29 +48,26 @@ namespace Sword25 {
|
||||||
// Konstruktor / Destruktor
|
// Konstruktor / Destruktor
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_PNGLoader::BS_PNGLoader()
|
BS_PNGLoader::BS_PNGLoader() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Laden
|
// Laden
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void png_user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
static void png_user_read_data(png_structp png_ptr, png_bytep data, png_size_t length) {
|
||||||
{
|
memcpy(data, (char *)png_ptr->io_ptr, length);
|
||||||
memcpy(data, (char*)png_ptr->io_ptr, length);
|
png_ptr->io_ptr = (void *)((png_size_t)png_ptr->io_ptr + length);
|
||||||
png_ptr->io_ptr = (void*)((png_size_t)png_ptr->io_ptr + length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
bool BS_PNGLoader::DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||||
int & Width, int & Height, int & Pitch)
|
int &Width, int &Height, int &Pitch) {
|
||||||
{
|
|
||||||
png_structp png_ptr = NULL;
|
png_structp png_ptr = NULL;
|
||||||
png_infop info_ptr = NULL;
|
png_infop info_ptr = NULL;
|
||||||
png_bytep RawDataBuffer = NULL;
|
png_bytep RawDataBuffer = NULL;
|
||||||
png_bytep* pRowPtr = NULL;
|
png_bytep *pRowPtr = NULL;
|
||||||
|
|
||||||
int BitDepth;
|
int BitDepth;
|
||||||
int ColorType;
|
int ColorType;
|
||||||
|
@ -83,31 +80,26 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
||||||
ColorFormat != BS_GraphicEngine::CF_RGB16_INTERLEAVED &&
|
ColorFormat != BS_GraphicEngine::CF_RGB16_INTERLEAVED &&
|
||||||
ColorFormat != BS_GraphicEngine::CF_RGB15_INTERLEAVED &&
|
ColorFormat != BS_GraphicEngine::CF_RGB15_INTERLEAVED &&
|
||||||
ColorFormat != BS_GraphicEngine::CF_ARGB32 &&
|
ColorFormat != BS_GraphicEngine::CF_ARGB32 &&
|
||||||
ColorFormat != BS_GraphicEngine::CF_ABGR32)
|
ColorFormat != BS_GraphicEngine::CF_ABGR32) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Illegal or unsupported color format.");
|
BS_LOG_ERRORLN("Illegal or unsupported color format.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
// PNG Signatur überprüfen
|
// PNG Signatur überprüfen
|
||||||
if (!png_check_sig(reinterpret_cast<png_bytep>(const_cast<char *>(FileDataPtr)), 8))
|
if (!png_check_sig(reinterpret_cast<png_bytep>(const_cast<char *>(FileDataPtr)), 8)) {
|
||||||
{
|
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Die beiden PNG Strukturen erstellen
|
// Die beiden PNG Strukturen erstellen
|
||||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
if (!png_ptr)
|
if (!png_ptr) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create libpng read struct.");
|
BS_LOG_ERRORLN("Could not create libpng read struct.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
info_ptr = png_create_info_struct(png_ptr);
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (!info_ptr)
|
if (!info_ptr) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create libpng info struct.");
|
BS_LOG_ERRORLN("Could not create libpng info struct.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
@ -116,13 +108,13 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
||||||
if (setjmp(png_jmpbuf(png_ptr))) throw(0);
|
if (setjmp(png_jmpbuf(png_ptr))) throw(0);
|
||||||
|
|
||||||
// Alternative Lesefunktion benutzen
|
// Alternative Lesefunktion benutzen
|
||||||
png_set_read_fn(png_ptr, (void*)FileDataPtr, png_user_read_data);
|
png_set_read_fn(png_ptr, (void *)FileDataPtr, png_user_read_data);
|
||||||
|
|
||||||
// PNG Header einlesen
|
// PNG Header einlesen
|
||||||
png_read_info(png_ptr, info_ptr);
|
png_read_info(png_ptr, info_ptr);
|
||||||
|
|
||||||
// PNG Informationen auslesen
|
// PNG Informationen auslesen
|
||||||
png_get_IHDR(png_ptr, info_ptr, (unsigned long*)&Width, (unsigned long*)&Height, &BitDepth, &ColorType, &InterlaceType, NULL, NULL);
|
png_get_IHDR(png_ptr, info_ptr, (unsigned long *)&Width, (unsigned long *)&Height, &BitDepth, &ColorType, &InterlaceType, NULL, NULL);
|
||||||
|
|
||||||
// Pitch des Ausgabebildes berechnen
|
// Pitch des Ausgabebildes berechnen
|
||||||
Pitch = BS_GraphicEngine::CalcPitch(ColorFormat, Width);
|
Pitch = BS_GraphicEngine::CalcPitch(ColorFormat, Width);
|
||||||
|
@ -130,8 +122,7 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
||||||
// Speicher für die endgültigen Bilddaten reservieren
|
// Speicher für die endgültigen Bilddaten reservieren
|
||||||
// Dieses geschieht vor dem reservieren von Speicher für temporäre Bilddaten um die Fragmentierung des Speichers gering zu halten
|
// Dieses geschieht vor dem reservieren von Speicher für temporäre Bilddaten um die Fragmentierung des Speichers gering zu halten
|
||||||
UncompressedDataPtr = new char[Pitch * Height];
|
UncompressedDataPtr = new char[Pitch * Height];
|
||||||
if (!UncompressedDataPtr)
|
if (!UncompressedDataPtr) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not allocate memory for output image.");
|
BS_LOG_ERRORLN("Could not allocate memory for output image.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
@ -156,49 +147,45 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
||||||
|
|
||||||
// Nachdem die Transformationen registriert wurden, werden die Bilddaten erneut eingelesen
|
// Nachdem die Transformationen registriert wurden, werden die Bilddaten erneut eingelesen
|
||||||
png_read_update_info(png_ptr, info_ptr);
|
png_read_update_info(png_ptr, info_ptr);
|
||||||
png_get_IHDR(png_ptr, info_ptr, (unsigned long*)&Width, (unsigned long*)&Height, &BitDepth, &ColorType, NULL, NULL, NULL);
|
png_get_IHDR(png_ptr, info_ptr, (unsigned long *)&Width, (unsigned long *)&Height, &BitDepth, &ColorType, NULL, NULL, NULL);
|
||||||
|
|
||||||
// PNGs ohne Interlacing werden Zeilenweise eingelesen
|
// PNGs ohne Interlacing werden Zeilenweise eingelesen
|
||||||
if (InterlaceType == PNG_INTERLACE_NONE)
|
if (InterlaceType == PNG_INTERLACE_NONE) {
|
||||||
{
|
|
||||||
// Speicher für eine Bildzeile reservieren
|
// Speicher für eine Bildzeile reservieren
|
||||||
RawDataBuffer = new png_byte[png_get_rowbytes(png_ptr, info_ptr)];
|
RawDataBuffer = new png_byte[png_get_rowbytes(png_ptr, info_ptr)];
|
||||||
if (!RawDataBuffer)
|
if (!RawDataBuffer) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not allocate memory for row buffer.");
|
BS_LOG_ERRORLN("Could not allocate memory for row buffer.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bilddaten zeilenweise einlesen und in das gewünschte Zielformat konvertieren
|
// Bilddaten zeilenweise einlesen und in das gewünschte Zielformat konvertieren
|
||||||
for (i = 0; i < Height; i++)
|
for (i = 0; i < Height; i++) {
|
||||||
{
|
|
||||||
// Zeile einlesen
|
// Zeile einlesen
|
||||||
png_read_row(png_ptr, RawDataBuffer, NULL);
|
png_read_row(png_ptr, RawDataBuffer, NULL);
|
||||||
|
|
||||||
// Zeile konvertieren
|
// Zeile konvertieren
|
||||||
switch (ColorFormat)
|
switch (ColorFormat) {
|
||||||
{
|
|
||||||
case BS_GraphicEngine::CF_RGB16:
|
case BS_GraphicEngine::CF_RGB16:
|
||||||
RowARGB32ToRGB16((unsigned char*)RawDataBuffer,
|
RowARGB32ToRGB16((unsigned char *)RawDataBuffer,
|
||||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||||
Width);
|
Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BS_GraphicEngine::CF_RGB15:
|
case BS_GraphicEngine::CF_RGB15:
|
||||||
RowARGB32ToRGB15((unsigned char*)RawDataBuffer,
|
RowARGB32ToRGB15((unsigned char *)RawDataBuffer,
|
||||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||||
Width);
|
Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BS_GraphicEngine::CF_RGB16_INTERLEAVED:
|
case BS_GraphicEngine::CF_RGB16_INTERLEAVED:
|
||||||
RowARGB32ToRGB16_INTERLEAVED((unsigned char*)RawDataBuffer,
|
RowARGB32ToRGB16_INTERLEAVED((unsigned char *)RawDataBuffer,
|
||||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||||
Width);
|
Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BS_GraphicEngine::CF_RGB15_INTERLEAVED:
|
case BS_GraphicEngine::CF_RGB15_INTERLEAVED:
|
||||||
RowARGB32ToRGB15_INTERLEAVED((unsigned char*)RawDataBuffer,
|
RowARGB32ToRGB15_INTERLEAVED((unsigned char *)RawDataBuffer,
|
||||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||||
Width);
|
Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -209,8 +196,8 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BS_GraphicEngine::CF_ABGR32:
|
case BS_GraphicEngine::CF_ABGR32:
|
||||||
RowARGB32ToABGR32((unsigned char*)RawDataBuffer,
|
RowARGB32ToABGR32((unsigned char *)RawDataBuffer,
|
||||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||||
Width);
|
Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -220,20 +207,17 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// PNGs mit Interlacing werden an einem Stück eingelesen
|
// PNGs mit Interlacing werden an einem Stück eingelesen
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
// Speicher für das komplette Bild reservieren
|
// Speicher für das komplette Bild reservieren
|
||||||
RawDataBuffer = new png_byte[png_get_rowbytes(png_ptr, info_ptr) * Height];
|
RawDataBuffer = new png_byte[png_get_rowbytes(png_ptr, info_ptr) * Height];
|
||||||
if (!RawDataBuffer)
|
if (!RawDataBuffer) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not allocate memory for raw image buffer.");
|
BS_LOG_ERRORLN("Could not allocate memory for raw image buffer.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Speicher für die Rowpointer reservieren
|
// Speicher für die Rowpointer reservieren
|
||||||
pRowPtr = new png_bytep[Height];
|
pRowPtr = new png_bytep[Height];
|
||||||
if (!pRowPtr)
|
if (!pRowPtr) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not allocate memory for row pointers.");
|
BS_LOG_ERRORLN("Could not allocate memory for row pointers.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
@ -246,33 +230,32 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
||||||
png_read_image(png_ptr, pRowPtr);
|
png_read_image(png_ptr, pRowPtr);
|
||||||
|
|
||||||
// Bilddaten zeilenweise in das gewünschte Ausgabeformat konvertieren
|
// Bilddaten zeilenweise in das gewünschte Ausgabeformat konvertieren
|
||||||
switch (ColorFormat)
|
switch (ColorFormat) {
|
||||||
{
|
|
||||||
case BS_GraphicEngine::CF_RGB16:
|
case BS_GraphicEngine::CF_RGB16:
|
||||||
for (i = 0; i < Height; i++)
|
for (i = 0; i < Height; i++)
|
||||||
RowARGB32ToRGB16((unsigned char*)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
RowARGB32ToRGB16((unsigned char *)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||||
Width);
|
Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BS_GraphicEngine::CF_RGB15:
|
case BS_GraphicEngine::CF_RGB15:
|
||||||
for (i = 0; i < Height; i++)
|
for (i = 0; i < Height; i++)
|
||||||
RowARGB32ToRGB15((unsigned char*)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
RowARGB32ToRGB15((unsigned char *)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||||
Width);
|
Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BS_GraphicEngine::CF_RGB16_INTERLEAVED:
|
case BS_GraphicEngine::CF_RGB16_INTERLEAVED:
|
||||||
for (i = 0; i < Height; i++)
|
for (i = 0; i < Height; i++)
|
||||||
RowARGB32ToRGB16_INTERLEAVED((unsigned char*)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
RowARGB32ToRGB16_INTERLEAVED((unsigned char *)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||||
Width);
|
Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BS_GraphicEngine::CF_RGB15_INTERLEAVED:
|
case BS_GraphicEngine::CF_RGB15_INTERLEAVED:
|
||||||
for (i = 0; i < Height; i++)
|
for (i = 0; i < Height; i++)
|
||||||
RowARGB32ToRGB15_INTERLEAVED((unsigned char*)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
RowARGB32ToRGB15_INTERLEAVED((unsigned char *)(&RawDataBuffer[i * png_get_rowbytes(png_ptr, info_ptr)]),
|
||||||
(unsigned char*)&UncompressedDataPtr[i * Pitch],
|
(unsigned char *)&UncompressedDataPtr[i * Pitch],
|
||||||
Width);
|
Width);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -296,8 +279,7 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
||||||
delete[] RawDataBuffer;
|
delete[] RawDataBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(int)
|
catch (int) {
|
||||||
{
|
|
||||||
delete[] pRowPtr;
|
delete[] pRowPtr;
|
||||||
delete[] RawDataBuffer;
|
delete[] RawDataBuffer;
|
||||||
if (png_ptr) png_destroy_read_struct(&png_ptr, NULL, NULL);
|
if (png_ptr) png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||||
|
@ -313,40 +295,35 @@ bool BS_PNGLoader::DoDecodeImage(const char * FileDataPtr, unsigned int FileSize
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_PNGLoader::DecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
bool BS_PNGLoader::DecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||||
int & Width, int & Height, int & Pitch)
|
int &Width, int &Height, int &Pitch) {
|
||||||
{
|
|
||||||
return DoDecodeImage(FileDataPtr, FileSize, ColorFormat, UncompressedDataPtr, Width, Height, Pitch);
|
return DoDecodeImage(FileDataPtr, FileSize, ColorFormat, UncompressedDataPtr, Width, Height, Pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_PNGLoader::DoImageProperties(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height)
|
bool BS_PNGLoader::DoImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height) {
|
||||||
{
|
|
||||||
// PNG Signatur überprüfen
|
// PNG Signatur überprüfen
|
||||||
if (!DoIsCorrectImageFormat(FileDataPtr, FileSize)) return false;
|
if (!DoIsCorrectImageFormat(FileDataPtr, FileSize)) return false;
|
||||||
|
|
||||||
png_structp png_ptr = NULL;
|
png_structp png_ptr = NULL;
|
||||||
png_infop info_ptr = NULL;
|
png_infop info_ptr = NULL;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
// Die beiden PNG Strukturen erstellen
|
// Die beiden PNG Strukturen erstellen
|
||||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
if (!png_ptr)
|
if (!png_ptr) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create libpng read struct.");
|
BS_LOG_ERRORLN("Could not create libpng read struct.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
info_ptr = png_create_info_struct(png_ptr);
|
info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (!info_ptr)
|
if (!info_ptr) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create libpng info struct.");
|
BS_LOG_ERRORLN("Could not create libpng info struct.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alternative Lesefunktion benutzen
|
// Alternative Lesefunktion benutzen
|
||||||
png_set_read_fn(png_ptr, (void*)FileDataPtr, png_user_read_data);
|
png_set_read_fn(png_ptr, (void *)FileDataPtr, png_user_read_data);
|
||||||
|
|
||||||
// PNG Header einlesen
|
// PNG Header einlesen
|
||||||
png_read_info(png_ptr, info_ptr);
|
png_read_info(png_ptr, info_ptr);
|
||||||
|
@ -354,7 +331,7 @@ bool BS_PNGLoader::DoImageProperties(const char * FileDataPtr, unsigned int File
|
||||||
// PNG Informationen auslesen
|
// PNG Informationen auslesen
|
||||||
int BitDepth;
|
int BitDepth;
|
||||||
int ColorType;
|
int ColorType;
|
||||||
png_get_IHDR(png_ptr, info_ptr, (unsigned long*)&Width, (unsigned long*)&Height, &BitDepth, &ColorType, NULL, NULL, NULL);
|
png_get_IHDR(png_ptr, info_ptr, (unsigned long *)&Width, (unsigned long *)&Height, &BitDepth, &ColorType, NULL, NULL, NULL);
|
||||||
|
|
||||||
// PNG-ColorType in BS ColorFormat konvertieren.
|
// PNG-ColorType in BS ColorFormat konvertieren.
|
||||||
if (ColorType & PNG_COLOR_MASK_ALPHA || png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
if (ColorType & PNG_COLOR_MASK_ALPHA || png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||||
|
@ -366,8 +343,7 @@ bool BS_PNGLoader::DoImageProperties(const char * FileDataPtr, unsigned int File
|
||||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (int)
|
catch (int) {
|
||||||
{
|
|
||||||
if (png_ptr) png_destroy_read_struct(&png_ptr, NULL, NULL);
|
if (png_ptr) png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||||
if (info_ptr) png_destroy_read_struct(NULL, &info_ptr, NULL);
|
if (info_ptr) png_destroy_read_struct(NULL, &info_ptr, NULL);
|
||||||
|
|
||||||
|
@ -381,8 +357,7 @@ bool BS_PNGLoader::DoImageProperties(const char * FileDataPtr, unsigned int File
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_PNGLoader::ImageProperties(const char* FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height)
|
bool BS_PNGLoader::ImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height) {
|
||||||
{
|
|
||||||
return DoImageProperties(FileDataPtr, FileSize, ColorFormat, Width, Height);
|
return DoImageProperties(FileDataPtr, FileSize, ColorFormat, Width, Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -390,18 +365,16 @@ bool BS_PNGLoader::ImageProperties(const char* FileDataPtr, unsigned int FileSiz
|
||||||
// Header überprüfen
|
// Header überprüfen
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_PNGLoader::DoIsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize)
|
bool BS_PNGLoader::DoIsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize) {
|
||||||
{
|
|
||||||
if (FileSize > 8)
|
if (FileSize > 8)
|
||||||
return png_check_sig((unsigned char*)FileDataPtr, 8) ? true : false;
|
return png_check_sig((unsigned char *)FileDataPtr, 8) ? true : false;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_PNGLoader::IsCorrectImageFormat(const char* FileDataPtr, unsigned int FileSize)
|
bool BS_PNGLoader::IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize) {
|
||||||
{
|
|
||||||
return DoIsCorrectImageFormat(FileDataPtr, FileSize);
|
return DoIsCorrectImageFormat(FileDataPtr, FileSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,32 +50,30 @@
|
||||||
namespace Sword25 {
|
namespace Sword25 {
|
||||||
|
|
||||||
// Klassendefinition
|
// Klassendefinition
|
||||||
class BS_PNGLoader : public BS_ImageLoader
|
class BS_PNGLoader : public BS_ImageLoader {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static BS_ImageLoader* CreateInstance()
|
static BS_ImageLoader *CreateInstance() {
|
||||||
{
|
#include "sword25/kernel/memlog_off.h"
|
||||||
#include "sword25/kernel/memlog_off.h"
|
return (BS_ImageLoader *) new BS_PNGLoader();
|
||||||
return (BS_ImageLoader*) new BS_PNGLoader();
|
#include "sword25/kernel/memlog_on.h"
|
||||||
#include "sword25/kernel/memlog_on.h"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alle virtuellen Methoden von BS_ImageLoader sind hier als static-Methode implementiert, damit sie von BS_B25SLoader aufgerufen werden können.
|
// Alle virtuellen Methoden von BS_ImageLoader sind hier als static-Methode implementiert, damit sie von BS_B25SLoader aufgerufen werden können.
|
||||||
// Die virtuellen Methoden rufen diese Methoden auf.
|
// Die virtuellen Methoden rufen diese Methoden auf.
|
||||||
static bool DoIsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize);
|
static bool DoIsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize);
|
||||||
static bool DoDecodeImage(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
static bool DoDecodeImage(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS ColorFormat, char * & UncompressedDataPtr,
|
||||||
int & Width, int & Height, int & Pitch);
|
int &Width, int &Height, int &Pitch);
|
||||||
static bool DoImageProperties(const char * FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height);
|
static bool DoImageProperties(const char *FileDataPtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BS_PNGLoader();
|
BS_PNGLoader();
|
||||||
bool DecodeImage(const char * pFileData, unsigned int FileSize,
|
bool DecodeImage(const char *pFileData, unsigned int FileSize,
|
||||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
BS_GraphicEngine::COLOR_FORMATS ColorFormat,
|
||||||
char * & pUncompressedData,
|
char * & pUncompressedData,
|
||||||
int & Width, int & Height,
|
int &Width, int &Height,
|
||||||
int & Pitch);
|
int &Pitch);
|
||||||
bool IsCorrectImageFormat(const char * FileDataPtr, unsigned int FileSize);
|
bool IsCorrectImageFormat(const char *FileDataPtr, unsigned int FileSize);
|
||||||
bool ImageProperties(const char * FileDatePtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS & ColorFormat, int & Width, int & Height);
|
bool ImageProperties(const char *FileDatePtr, unsigned int FileSize, BS_GraphicEngine::COLOR_FORMATS &ColorFormat, int &Width, int &Height);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sword25
|
} // End of namespace Sword25
|
||||||
|
|
|
@ -68,23 +68,19 @@ typedef int16_t s32;
|
||||||
// Diese Klasse ist speziell dafür ausgestattet.
|
// Diese Klasse ist speziell dafür ausgestattet.
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_VectorImage::SWFBitStream
|
class BS_VectorImage::SWFBitStream {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
SWFBitStream(const unsigned char * pData, unsigned int DataSize) :
|
SWFBitStream(const unsigned char *pData, unsigned int DataSize) :
|
||||||
m_Pos(pData), m_End(pData + DataSize), m_WordMask(0)
|
m_Pos(pData), m_End(pData + DataSize), m_WordMask(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline u32 GetBits(unsigned int BitCount)
|
inline u32 GetBits(unsigned int BitCount) {
|
||||||
{
|
if (BitCount == 0 || BitCount > 32) {
|
||||||
if (BitCount == 0 || BitCount > 32)
|
|
||||||
{
|
|
||||||
throw(runtime_error("SWFBitStream::GetBits() must read at least 1 and at most 32 bits at a time"));
|
throw(runtime_error("SWFBitStream::GetBits() must read at least 1 and at most 32 bits at a time"));
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 value = 0;
|
u32 value = 0;
|
||||||
while (BitCount)
|
while (BitCount) {
|
||||||
{
|
|
||||||
if (m_WordMask == 0) FlushByte();
|
if (m_WordMask == 0) FlushByte();
|
||||||
|
|
||||||
value <<= 1;
|
value <<= 1;
|
||||||
|
@ -97,8 +93,7 @@ public:
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline s32 GetSignedBits(unsigned int BitCount)
|
inline s32 GetSignedBits(unsigned int BitCount) {
|
||||||
{
|
|
||||||
// Bits einlesen
|
// Bits einlesen
|
||||||
u32 Temp = GetBits(BitCount);
|
u32 Temp = GetBits(BitCount);
|
||||||
|
|
||||||
|
@ -109,8 +104,7 @@ public:
|
||||||
return Temp;
|
return Temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline u32 GetU32()
|
inline u32 GetU32() {
|
||||||
{
|
|
||||||
u32 Byte1 = GetU8();
|
u32 Byte1 = GetU8();
|
||||||
u32 Byte2 = GetU8();
|
u32 Byte2 = GetU8();
|
||||||
u32 Byte3 = GetU8();
|
u32 Byte3 = GetU8();
|
||||||
|
@ -119,16 +113,14 @@ public:
|
||||||
return Byte1 | (Byte2 << 8) | (Byte3 << 16) | (Byte4 << 24);
|
return Byte1 | (Byte2 << 8) | (Byte3 << 16) | (Byte4 << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline u16 GetU16()
|
inline u16 GetU16() {
|
||||||
{
|
|
||||||
u32 Byte1 = GetU8();
|
u32 Byte1 = GetU8();
|
||||||
u32 Byte2 = GetU8();
|
u32 Byte2 = GetU8();
|
||||||
|
|
||||||
return Byte1 | (Byte2 << 8);
|
return Byte1 | (Byte2 << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline u8 GetU8()
|
inline u8 GetU8() {
|
||||||
{
|
|
||||||
FlushByte();
|
FlushByte();
|
||||||
u8 Value = m_Word;
|
u8 Value = m_Word;
|
||||||
m_WordMask = 0;
|
m_WordMask = 0;
|
||||||
|
@ -137,39 +129,30 @@ public:
|
||||||
return Value;
|
return Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FlushByte()
|
inline void FlushByte() {
|
||||||
{
|
if (m_WordMask != 128) {
|
||||||
if (m_WordMask != 128)
|
if (m_Pos >= m_End) {
|
||||||
{
|
|
||||||
if (m_Pos >= m_End)
|
|
||||||
{
|
|
||||||
throw(runtime_error("Attempted to read past end of file"));
|
throw(runtime_error("Attempted to read past end of file"));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
m_Word = *m_Pos++;
|
m_Word = *m_Pos++;
|
||||||
m_WordMask = 128;
|
m_WordMask = 128;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SkipBytes(unsigned int SkipLength)
|
inline void SkipBytes(unsigned int SkipLength) {
|
||||||
{
|
|
||||||
FlushByte();
|
FlushByte();
|
||||||
if (m_Pos + SkipLength >= m_End)
|
if (m_Pos + SkipLength >= m_End) {
|
||||||
{
|
|
||||||
throw(runtime_error("Attempted to read past end of file"));
|
throw(runtime_error("Attempted to read past end of file"));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
m_Pos += SkipLength;
|
m_Pos += SkipLength;
|
||||||
m_Word = *(m_Pos - 1);
|
m_Word = *(m_Pos - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const unsigned char * m_Pos;
|
const unsigned char *m_Pos;
|
||||||
const unsigned char * m_End;
|
const unsigned char *m_End;
|
||||||
|
|
||||||
u8 m_Word;
|
u8 m_Word;
|
||||||
unsigned int m_WordMask;
|
unsigned int m_WordMask;
|
||||||
|
@ -180,21 +163,19 @@ private:
|
||||||
// Konstanten und Hilfsfunktionen
|
// Konstanten und Hilfsfunktionen
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
// -----------------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------------
|
// Konstanten
|
||||||
// Konstanten
|
// -----------------------------------------------------------------------------
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const u32 MAX_ACCEPTED_FLASH_VERSION = 3; // Die höchste Flash-Dateiversion, die vom Lader akzeptiert wird
|
const u32 MAX_ACCEPTED_FLASH_VERSION = 3; // Die höchste Flash-Dateiversion, die vom Lader akzeptiert wird
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Konvertiert SWF-Rechteckdaten in einem Bitstrom in BS_Rect-Objekte
|
// Konvertiert SWF-Rechteckdaten in einem Bitstrom in BS_Rect-Objekte
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Rect FlashRectToBSRect(BS_VectorImage::SWFBitStream & bs)
|
BS_Rect FlashRectToBSRect(BS_VectorImage::SWFBitStream &bs) {
|
||||||
{
|
|
||||||
bs.FlushByte();
|
bs.FlushByte();
|
||||||
|
|
||||||
// Feststellen mit wie vielen Bits die einzelnen Komponenten kodiert sind
|
// Feststellen mit wie vielen Bits die einzelnen Komponenten kodiert sind
|
||||||
|
@ -207,34 +188,33 @@ namespace
|
||||||
s32 YMax = bs.GetSignedBits(BitsPerValue);
|
s32 YMax = bs.GetSignedBits(BitsPerValue);
|
||||||
|
|
||||||
return BS_Rect(XMin, YMin, XMax + 1, YMax + 1);
|
return BS_Rect(XMin, YMin, XMax + 1, YMax + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Konvertiert SWF-Farben in AntiGrain Farben
|
// Konvertiert SWF-Farben in AntiGrain Farben
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
agg::rgba8 FlashColorToAGGRGBA8(unsigned int FlashColor)
|
agg::rgba8 FlashColorToAGGRGBA8(unsigned int FlashColor) {
|
||||||
{
|
|
||||||
agg::rgba8 ResultColor((FlashColor >> 16) & 0xff, (FlashColor >> 8) & 0xff, FlashColor & 0xff, FlashColor >> 24);
|
agg::rgba8 ResultColor((FlashColor >> 16) & 0xff, (FlashColor >> 8) & 0xff, FlashColor & 0xff, FlashColor >> 24);
|
||||||
ResultColor.premultiply();
|
ResultColor.premultiply();
|
||||||
return ResultColor;
|
return ResultColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// Berechnet die Bounding-Box eines BS_VectorImageElement
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct CBBGetId {
|
||||||
|
CBBGetId(const BS_VectorImageElement &VectorImageElement_) : VectorImageElement(VectorImageElement_) {}
|
||||||
|
unsigned operator [](unsigned i) const {
|
||||||
|
return VectorImageElement.GetPathInfo(i).GetID();
|
||||||
}
|
}
|
||||||
|
const BS_VectorImageElement &VectorImageElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
BS_Rect CalculateBoundingBox(const BS_VectorImageElement &VectorImageElement) {
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Berechnet die Bounding-Box eines BS_VectorImageElement
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
struct CBBGetId
|
|
||||||
{
|
|
||||||
CBBGetId(const BS_VectorImageElement & VectorImageElement_) : VectorImageElement(VectorImageElement_) {}
|
|
||||||
unsigned operator [] (unsigned i) const { return VectorImageElement.GetPathInfo(i).GetID(); }
|
|
||||||
const BS_VectorImageElement & VectorImageElement;
|
|
||||||
};
|
|
||||||
|
|
||||||
BS_Rect CalculateBoundingBox(const BS_VectorImageElement & VectorImageElement)
|
|
||||||
{
|
|
||||||
agg::path_storage Path = VectorImageElement.GetPaths();
|
agg::path_storage Path = VectorImageElement.GetPaths();
|
||||||
CBBGetId IdSource(VectorImageElement);
|
CBBGetId IdSource(VectorImageElement);
|
||||||
|
|
||||||
|
@ -242,7 +222,7 @@ namespace
|
||||||
agg::bounding_rect(Path, IdSource, 0, VectorImageElement.GetPathCount(), &x1, &y1, &x2, &y2);
|
agg::bounding_rect(Path, IdSource, 0, VectorImageElement.GetPathCount(), &x1, &y1, &x2, &y2);
|
||||||
|
|
||||||
return BS_Rect(static_cast<int>(x1), static_cast<int>(y1), static_cast<int>(x2) + 1, static_cast<int>(y2) + 1);
|
return BS_Rect(static_cast<int>(x1), static_cast<int>(y1), static_cast<int>(x2) + 1, static_cast<int>(y2) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,16 +230,14 @@ namespace
|
||||||
// Konstruktion
|
// Konstruktion
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int FileSize, bool & Success)
|
BS_VectorImage::BS_VectorImage(const unsigned char *pFileData, unsigned int FileSize, bool &Success) {
|
||||||
{
|
|
||||||
Success = false;
|
Success = false;
|
||||||
|
|
||||||
// Bitstream-Objekt erzeugen
|
// Bitstream-Objekt erzeugen
|
||||||
// Im Folgenden werden die Dateidaten aus diesem ausgelesen.
|
// Im Folgenden werden die Dateidaten aus diesem ausgelesen.
|
||||||
SWFBitStream bs(pFileData, FileSize);
|
SWFBitStream bs(pFileData, FileSize);
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
// SWF-Signatur überprüfen
|
// SWF-Signatur überprüfen
|
||||||
u32 Signature[3];
|
u32 Signature[3];
|
||||||
Signature[0] = bs.GetU8();
|
Signature[0] = bs.GetU8();
|
||||||
|
@ -267,24 +245,21 @@ BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int Fil
|
||||||
Signature[2] = bs.GetU8();
|
Signature[2] = bs.GetU8();
|
||||||
if (Signature[0] != 'F' ||
|
if (Signature[0] != 'F' ||
|
||||||
Signature[1] != 'W' ||
|
Signature[1] != 'W' ||
|
||||||
Signature[2] != 'S')
|
Signature[2] != 'S') {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("File is not a valid SWF-file");
|
BS_LOG_ERRORLN("File is not a valid SWF-file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Versionsangabe überprüfen
|
// Versionsangabe überprüfen
|
||||||
u32 Version = bs.GetU8();
|
u32 Version = bs.GetU8();
|
||||||
if (Version > MAX_ACCEPTED_FLASH_VERSION)
|
if (Version > MAX_ACCEPTED_FLASH_VERSION) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("File is of version %d. Highest accepted version is %d.", Version, MAX_ACCEPTED_FLASH_VERSION);
|
BS_LOG_ERRORLN("File is of version %d. Highest accepted version is %d.", Version, MAX_ACCEPTED_FLASH_VERSION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dateigröße auslesen und mit der tatsächlichen Größe vergleichen
|
// Dateigröße auslesen und mit der tatsächlichen Größe vergleichen
|
||||||
u32 StoredFileSize = bs.GetU32();
|
u32 StoredFileSize = bs.GetU32();
|
||||||
if (StoredFileSize != FileSize)
|
if (StoredFileSize != FileSize) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("File is not a valid SWF-file");
|
BS_LOG_ERRORLN("File is not a valid SWF-file");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -299,8 +274,7 @@ BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int Fil
|
||||||
// Tags parsen
|
// Tags parsen
|
||||||
// Da wir uns nur für das erste DefineShape-Tag interessieren
|
// Da wir uns nur für das erste DefineShape-Tag interessieren
|
||||||
bool KeepParsing = true;
|
bool KeepParsing = true;
|
||||||
while (KeepParsing)
|
while (KeepParsing) {
|
||||||
{
|
|
||||||
// Tags beginnen immer an Bytegrenzen
|
// Tags beginnen immer an Bytegrenzen
|
||||||
bs.FlushByte();
|
bs.FlushByte();
|
||||||
|
|
||||||
|
@ -310,8 +284,7 @@ BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int Fil
|
||||||
u32 TagLength = TagTypeAndLength & 0x3f;
|
u32 TagLength = TagTypeAndLength & 0x3f;
|
||||||
if (TagLength == 0x3f) TagLength = bs.GetU32();
|
if (TagLength == 0x3f) TagLength = bs.GetU32();
|
||||||
|
|
||||||
switch (TagType)
|
switch (TagType) {
|
||||||
{
|
|
||||||
case 2:
|
case 2:
|
||||||
// DefineShape
|
// DefineShape
|
||||||
Success = ParseDefineShape(2, bs);
|
Success = ParseDefineShape(2, bs);
|
||||||
|
@ -330,8 +303,7 @@ BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int Fil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (runtime_error & e)
|
catch (runtime_error &e) {
|
||||||
{
|
|
||||||
// Fehler loggen und Funktion verlassen
|
// Fehler loggen und Funktion verlassen
|
||||||
// Success ist somit "false" und signalisiert dem Programmierer, dass die Konstruktion fehlgeschlagen ist.
|
// Success ist somit "false" und signalisiert dem Programmierer, dass die Konstruktion fehlgeschlagen ist.
|
||||||
BS_LOG_ERRORLN("The following exception occured while parsing a SWF-file: %s", e.what());
|
BS_LOG_ERRORLN("The following exception occured while parsing a SWF-file: %s", e.what());
|
||||||
|
@ -345,8 +317,7 @@ BS_VectorImage::BS_VectorImage(const unsigned char * pFileData, unsigned int Fil
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream &bs) {
|
||||||
{
|
|
||||||
u32 ShapeID = bs.GetU16();
|
u32 ShapeID = bs.GetU16();
|
||||||
|
|
||||||
// Bounding Box auslesen
|
// Bounding Box auslesen
|
||||||
|
@ -368,13 +339,11 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
||||||
// ------------------
|
// ------------------
|
||||||
|
|
||||||
bool EndOfShapeDiscovered = false;
|
bool EndOfShapeDiscovered = false;
|
||||||
while (!EndOfShapeDiscovered)
|
while (!EndOfShapeDiscovered) {
|
||||||
{
|
|
||||||
u32 TypeFlag = bs.GetBits(1);
|
u32 TypeFlag = bs.GetBits(1);
|
||||||
|
|
||||||
// Non-Edge Record
|
// Non-Edge Record
|
||||||
if (TypeFlag == 0)
|
if (TypeFlag == 0) {
|
||||||
{
|
|
||||||
// Feststellen welche Parameter gesetzt werden
|
// Feststellen welche Parameter gesetzt werden
|
||||||
u32 StateNewStyles = bs.GetBits(1);
|
u32 StateNewStyles = bs.GetBits(1);
|
||||||
u32 StateLineStyle = bs.GetBits(1);
|
u32 StateLineStyle = bs.GetBits(1);
|
||||||
|
@ -386,43 +355,37 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
||||||
if (!StateNewStyles && !StateLineStyle && !StateFillStyle0 && !StateFillStyle1 && !StateMoveTo)
|
if (!StateNewStyles && !StateLineStyle && !StateFillStyle0 && !StateFillStyle1 && !StateMoveTo)
|
||||||
EndOfShapeDiscovered = true;
|
EndOfShapeDiscovered = true;
|
||||||
// Parameter dekodieren
|
// Parameter dekodieren
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
s32 MoveDeltaX = 0;
|
s32 MoveDeltaX = 0;
|
||||||
s32 MoveDeltaY = 0;
|
s32 MoveDeltaY = 0;
|
||||||
if (StateMoveTo)
|
if (StateMoveTo) {
|
||||||
{
|
|
||||||
u32 MoveToBits = bs.GetBits(5);
|
u32 MoveToBits = bs.GetBits(5);
|
||||||
MoveDeltaX = bs.GetSignedBits(MoveToBits);
|
MoveDeltaX = bs.GetSignedBits(MoveToBits);
|
||||||
MoveDeltaY = bs.GetSignedBits(MoveToBits);
|
MoveDeltaY = bs.GetSignedBits(MoveToBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StateFillStyle0)
|
if (StateFillStyle0) {
|
||||||
{
|
|
||||||
if (NumFillBits > 0)
|
if (NumFillBits > 0)
|
||||||
FillStyle0 = bs.GetBits(NumFillBits);
|
FillStyle0 = bs.GetBits(NumFillBits);
|
||||||
else
|
else
|
||||||
FillStyle0 = 0;
|
FillStyle0 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StateFillStyle1)
|
if (StateFillStyle1) {
|
||||||
{
|
|
||||||
if (NumFillBits > 0)
|
if (NumFillBits > 0)
|
||||||
FillStyle1 = bs.GetBits(NumFillBits);
|
FillStyle1 = bs.GetBits(NumFillBits);
|
||||||
else
|
else
|
||||||
FillStyle1 = 0;
|
FillStyle1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StateLineStyle)
|
if (StateLineStyle) {
|
||||||
{
|
|
||||||
if (NumLineBits)
|
if (NumLineBits)
|
||||||
LineStyle = bs.GetBits(NumLineBits);
|
LineStyle = bs.GetBits(NumLineBits);
|
||||||
else
|
else
|
||||||
NumLineBits = 0;
|
NumLineBits = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StateNewStyles)
|
if (StateNewStyles) {
|
||||||
{
|
|
||||||
// An dieser Stelle werden in Flash die alten Style-Definitionen verworfen und mit den neuen überschrieben.
|
// An dieser Stelle werden in Flash die alten Style-Definitionen verworfen und mit den neuen überschrieben.
|
||||||
// Es wird ein neues Element begonnen.
|
// Es wird ein neues Element begonnen.
|
||||||
m_Elements.resize(m_Elements.size() + 1);
|
m_Elements.resize(m_Elements.size() + 1);
|
||||||
|
@ -430,8 +393,7 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ein neuen Pfad erzeugen, es sei denn, es wurden nur neue Styles definiert
|
// Ein neuen Pfad erzeugen, es sei denn, es wurden nur neue Styles definiert
|
||||||
if (StateLineStyle || StateFillStyle0 || StateFillStyle1 || StateMoveTo)
|
if (StateLineStyle || StateFillStyle0 || StateFillStyle1 || StateMoveTo) {
|
||||||
{
|
|
||||||
// Letzte Zeichenposition merken, beim Aufruf von start_new_path() wird die Zeichenpostionen auf 0, 0 zurückgesetzt
|
// Letzte Zeichenposition merken, beim Aufruf von start_new_path() wird die Zeichenpostionen auf 0, 0 zurückgesetzt
|
||||||
double LastX = m_Elements.back().m_Paths.last_x();
|
double LastX = m_Elements.back().m_Paths.last_x();
|
||||||
double LastY = m_Elements.back().m_Paths.last_y();
|
double LastY = m_Elements.back().m_Paths.last_y();
|
||||||
|
@ -449,14 +411,12 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Edge Record
|
// Edge Record
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
u32 EdgeFlag = bs.GetBits(1);
|
u32 EdgeFlag = bs.GetBits(1);
|
||||||
u32 NumBits = bs.GetBits(4) + 2;
|
u32 NumBits = bs.GetBits(4) + 2;
|
||||||
|
|
||||||
// Curved edge
|
// Curved edge
|
||||||
if (EdgeFlag == 0)
|
if (EdgeFlag == 0) {
|
||||||
{
|
|
||||||
s32 ControlDeltaX = bs.GetSignedBits(NumBits);
|
s32 ControlDeltaX = bs.GetSignedBits(NumBits);
|
||||||
s32 ControlDeltaY = bs.GetSignedBits(NumBits);
|
s32 ControlDeltaY = bs.GetSignedBits(NumBits);
|
||||||
s32 AnchorDeltaX = bs.GetSignedBits(NumBits);
|
s32 AnchorDeltaX = bs.GetSignedBits(NumBits);
|
||||||
|
@ -469,19 +429,15 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
||||||
m_Elements.back().m_Paths.curve3(ControlX, ControlY, AnchorX, AnchorY);
|
m_Elements.back().m_Paths.curve3(ControlX, ControlY, AnchorX, AnchorY);
|
||||||
}
|
}
|
||||||
// Staight edge
|
// Staight edge
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
s32 DeltaX = 0;
|
s32 DeltaX = 0;
|
||||||
s32 DeltaY = 0;
|
s32 DeltaY = 0;
|
||||||
|
|
||||||
u32 GeneralLineFlag = bs.GetBits(1);
|
u32 GeneralLineFlag = bs.GetBits(1);
|
||||||
if (GeneralLineFlag)
|
if (GeneralLineFlag) {
|
||||||
{
|
|
||||||
DeltaX = bs.GetSignedBits(NumBits);
|
DeltaX = bs.GetSignedBits(NumBits);
|
||||||
DeltaY = bs.GetSignedBits(NumBits);
|
DeltaY = bs.GetSignedBits(NumBits);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
u32 VertLineFlag = bs.GetBits(1);
|
u32 VertLineFlag = bs.GetBits(1);
|
||||||
if (VertLineFlag)
|
if (VertLineFlag)
|
||||||
DeltaY = bs.GetSignedBits(NumBits);
|
DeltaY = bs.GetSignedBits(NumBits);
|
||||||
|
@ -504,8 +460,7 @@ bool BS_VectorImage::ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsigned int & NumFillBits, unsigned int & NumLineBits)
|
bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream &bs, unsigned int &NumFillBits, unsigned int &NumLineBits) {
|
||||||
{
|
|
||||||
bs.FlushByte();
|
bs.FlushByte();
|
||||||
|
|
||||||
// Fillstyles parsen
|
// Fillstyles parsen
|
||||||
|
@ -518,15 +473,12 @@ bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsi
|
||||||
// Alle Fillstyles einlesen, falls ein Fillstyle mit Typ != 0 gefunden wird, wird das Parsen abgebrochen.
|
// Alle Fillstyles einlesen, falls ein Fillstyle mit Typ != 0 gefunden wird, wird das Parsen abgebrochen.
|
||||||
// Es wird nur "solid fill" (Typ 0) unterstützt.
|
// Es wird nur "solid fill" (Typ 0) unterstützt.
|
||||||
m_Elements.back().m_FillStyles.reserve(FillStyleCount);
|
m_Elements.back().m_FillStyles.reserve(FillStyleCount);
|
||||||
for (unsigned int i = 0; i < FillStyleCount; ++i)
|
for (unsigned int i = 0; i < FillStyleCount; ++i) {
|
||||||
{
|
|
||||||
u8 Type = bs.GetU8();
|
u8 Type = bs.GetU8();
|
||||||
u32 Color;
|
u32 Color;
|
||||||
if (ShapeType == 3)
|
if (ShapeType == 3) {
|
||||||
{
|
|
||||||
Color = (bs.GetU8() << 16) | (bs.GetU8() << 8) | bs.GetU8() | (bs.GetU8() << 24);
|
Color = (bs.GetU8() << 16) | (bs.GetU8() << 8) | bs.GetU8() | (bs.GetU8() << 24);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
Color = bs.GetBits(24) | (0xff << 24);
|
Color = bs.GetBits(24) | (0xff << 24);
|
||||||
if (Type != 0) return false;
|
if (Type != 0) return false;
|
||||||
|
|
||||||
|
@ -542,8 +494,7 @@ bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsi
|
||||||
|
|
||||||
// Alle Linestyles einlesen
|
// Alle Linestyles einlesen
|
||||||
m_Elements.back().m_LineStyles.reserve(LineStyleCount);
|
m_Elements.back().m_LineStyles.reserve(LineStyleCount);
|
||||||
for (unsigned int i = 0; i < LineStyleCount; ++i)
|
for (unsigned int i = 0; i < LineStyleCount; ++i) {
|
||||||
{
|
|
||||||
double Width = bs.GetU16();
|
double Width = bs.GetU16();
|
||||||
u32 Color;
|
u32 Color;
|
||||||
if (ShapeType == 3)
|
if (ShapeType == 3)
|
||||||
|
@ -564,8 +515,7 @@ bool BS_VectorImage::ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsi
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_VectorImage::Fill(const BS_Rect* pFillRect, unsigned int Color)
|
bool BS_VectorImage::Fill(const BS_Rect *pFillRect, unsigned int Color) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Fill() is not supported.");
|
BS_LOG_ERRORLN("Fill() is not supported.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -573,16 +523,14 @@ bool BS_VectorImage::Fill(const BS_Rect* pFillRect, unsigned int Color)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_VectorImage::GetPixel(int X, int Y)
|
unsigned int BS_VectorImage::GetPixel(int X, int Y) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("GetPixel() is not supported. Returning black.");
|
BS_LOG_ERRORLN("GetPixel() is not supported. Returning black.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_VectorImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
bool BS_VectorImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("SetContent() is not supported.");
|
BS_LOG_ERRORLN("SetContent() is not supported.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,16 +59,23 @@ class BS_VectorImage;
|
||||||
gespeichert werden.
|
gespeichert werden.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BS_VectorPathInfo
|
class BS_VectorPathInfo {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BS_VectorPathInfo(unsigned int ID, unsigned int LineStyle, unsigned int FillStyle0, unsigned int FillStyle1) :
|
BS_VectorPathInfo(unsigned int ID, unsigned int LineStyle, unsigned int FillStyle0, unsigned int FillStyle1) :
|
||||||
m_ID(ID), m_LineStyle(LineStyle), m_FillStyle0(FillStyle0), m_FillStyle1(FillStyle1) {};
|
m_ID(ID), m_LineStyle(LineStyle), m_FillStyle0(FillStyle0), m_FillStyle1(FillStyle1) {};
|
||||||
|
|
||||||
unsigned int GetID() const { return m_ID; }
|
unsigned int GetID() const {
|
||||||
unsigned int GetLineStyle() const { return m_LineStyle; }
|
return m_ID;
|
||||||
unsigned int GetFillStyle0() const { return m_FillStyle0; }
|
}
|
||||||
unsigned int GetFillStyle1() const { return m_FillStyle1; }
|
unsigned int GetLineStyle() const {
|
||||||
|
return m_LineStyle;
|
||||||
|
}
|
||||||
|
unsigned int GetFillStyle0() const {
|
||||||
|
return m_FillStyle0;
|
||||||
|
}
|
||||||
|
unsigned int GetFillStyle1() const {
|
||||||
|
return m_FillStyle1;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned int m_ID;
|
unsigned int m_ID;
|
||||||
|
@ -82,42 +89,50 @@ private:
|
||||||
@brief Ein Element eines Vektorbild. Ein BS_VectorImage besteht aus diesen Elementen, die jeweils einen Teil der Graphik definieren.
|
@brief Ein Element eines Vektorbild. Ein BS_VectorImage besteht aus diesen Elementen, die jeweils einen Teil der Graphik definieren.
|
||||||
Werden alle Elemente eines Vektorbildes übereinandergelegt, ergibt sich das komplette Bild.
|
Werden alle Elemente eines Vektorbildes übereinandergelegt, ergibt sich das komplette Bild.
|
||||||
*/
|
*/
|
||||||
class BS_VectorImageElement
|
class BS_VectorImageElement {
|
||||||
{
|
friend BS_VectorImage;
|
||||||
friend BS_VectorImage;
|
|
||||||
public:
|
public:
|
||||||
const agg::path_storage & GetPaths() const { return m_Paths; }
|
const agg::path_storage &GetPaths() const {
|
||||||
unsigned int GetPathCount() const { return m_PathInfos.size(); }
|
return m_Paths;
|
||||||
const BS_VectorPathInfo & GetPathInfo(unsigned int PathNr) const { BS_ASSERT(PathNr < GetPathCount()); return m_PathInfos[PathNr]; }
|
}
|
||||||
|
unsigned int GetPathCount() const {
|
||||||
|
return m_PathInfos.size();
|
||||||
|
}
|
||||||
|
const BS_VectorPathInfo &GetPathInfo(unsigned int PathNr) const {
|
||||||
|
BS_ASSERT(PathNr < GetPathCount());
|
||||||
|
return m_PathInfos[PathNr];
|
||||||
|
}
|
||||||
|
|
||||||
double GetLineStyleWidth(unsigned int LineStyle) const
|
double GetLineStyleWidth(unsigned int LineStyle) const {
|
||||||
{
|
|
||||||
BS_ASSERT(LineStyle < m_LineStyles.size());
|
BS_ASSERT(LineStyle < m_LineStyles.size());
|
||||||
return m_LineStyles[LineStyle].Width;
|
return m_LineStyles[LineStyle].Width;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int GetLineStyleCount() const { return m_LineStyles.size(); }
|
unsigned int GetLineStyleCount() const {
|
||||||
|
return m_LineStyles.size();
|
||||||
|
}
|
||||||
|
|
||||||
const agg::rgba8 & GetLineStyleColor(unsigned int LineStyle) const
|
const agg::rgba8 &GetLineStyleColor(unsigned int LineStyle) const {
|
||||||
{
|
|
||||||
BS_ASSERT(LineStyle < m_LineStyles.size());
|
BS_ASSERT(LineStyle < m_LineStyles.size());
|
||||||
return m_LineStyles[LineStyle].Color;
|
return m_LineStyles[LineStyle].Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int GetFillStyleCount() const { return m_FillStyles.size(); }
|
unsigned int GetFillStyleCount() const {
|
||||||
|
return m_FillStyles.size();
|
||||||
|
}
|
||||||
|
|
||||||
const agg::rgba8 & GetFillStyleColor(unsigned int FillStyle) const
|
const agg::rgba8 &GetFillStyleColor(unsigned int FillStyle) const {
|
||||||
{
|
|
||||||
BS_ASSERT(FillStyle < m_FillStyles.size());
|
BS_ASSERT(FillStyle < m_FillStyles.size());
|
||||||
return m_FillStyles[FillStyle];
|
return m_FillStyles[FillStyle];
|
||||||
}
|
}
|
||||||
|
|
||||||
const BS_Rect & GetBoundingBox() const { return m_BoundingBox; }
|
const BS_Rect &GetBoundingBox() const {
|
||||||
|
return m_BoundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct LineStyleType
|
struct LineStyleType {
|
||||||
{
|
LineStyleType(double Width_, const agg::rgba8 &Color_) : Width(Width_), Color(Color_) {};
|
||||||
LineStyleType(double Width_, const agg::rgba8 & Color_) : Width(Width_), Color(Color_) {};
|
|
||||||
double Width;
|
double Width;
|
||||||
agg::rgba8 Color;
|
agg::rgba8 Color;
|
||||||
};
|
};
|
||||||
|
@ -136,46 +151,68 @@ private:
|
||||||
Objekte dieser Klasse enthalten die Informationen eines SWF-Shapes.
|
Objekte dieser Klasse enthalten die Informationen eines SWF-Shapes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BS_VectorImage : public BS_Image
|
class BS_VectorImage : public BS_Image {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BS_VectorImage(const unsigned char * pFileData, unsigned int FileSize, bool & Success);
|
BS_VectorImage(const unsigned char *pFileData, unsigned int FileSize, bool &Success);
|
||||||
|
|
||||||
unsigned int GetElementCount() const { return m_Elements.size(); }
|
unsigned int GetElementCount() const {
|
||||||
const BS_VectorImageElement & GetElement(unsigned int ElementNr) const
|
return m_Elements.size();
|
||||||
{
|
}
|
||||||
|
const BS_VectorImageElement &GetElement(unsigned int ElementNr) const {
|
||||||
BS_ASSERT(ElementNr < m_Elements.size());
|
BS_ASSERT(ElementNr < m_Elements.size());
|
||||||
return m_Elements[ElementNr];
|
return m_Elements[ElementNr];
|
||||||
}
|
}
|
||||||
const BS_Rect & GetBoundingBox() const { return m_BoundingBox; }
|
const BS_Rect &GetBoundingBox() const {
|
||||||
|
return m_BoundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Die abstrakten Methoden von BS_Image
|
// Die abstrakten Methoden von BS_Image
|
||||||
//
|
//
|
||||||
virtual int GetWidth() const { return m_BoundingBox.GetWidth(); }
|
virtual int GetWidth() const {
|
||||||
virtual int GetHeight() const { return m_BoundingBox.GetHeight(); }
|
return m_BoundingBox.GetWidth();
|
||||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const { return BS_GraphicEngine::CF_ARGB32; }
|
}
|
||||||
virtual bool Fill(const BS_Rect* pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0));
|
virtual int GetHeight() const {
|
||||||
|
return m_BoundingBox.GetHeight();
|
||||||
|
}
|
||||||
|
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const {
|
||||||
|
return BS_GraphicEngine::CF_ARGB32;
|
||||||
|
}
|
||||||
|
virtual bool Fill(const BS_Rect *pFillRect = 0, unsigned int Color = BS_RGB(0, 0, 0));
|
||||||
virtual unsigned int GetPixel(int X, int Y);
|
virtual unsigned int GetPixel(int X, int Y);
|
||||||
virtual bool IsBlitSource() const { return true; }
|
virtual bool IsBlitSource() const {
|
||||||
virtual bool IsBlitTarget() const { return false; }
|
return true;
|
||||||
virtual bool IsScalingAllowed() const { return true; }
|
}
|
||||||
virtual bool IsFillingAllowed() const { return false; }
|
virtual bool IsBlitTarget() const {
|
||||||
virtual bool IsAlphaAllowed() const { return true; }
|
return false;
|
||||||
virtual bool IsColorModulationAllowed() const { return true; }
|
}
|
||||||
virtual bool IsSetContentAllowed() const { return false; }
|
virtual bool IsScalingAllowed() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
virtual bool IsFillingAllowed() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool IsAlphaAllowed() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
virtual bool IsColorModulationAllowed() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
virtual bool IsSetContentAllowed() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
||||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||||
int Flipping = FLIP_NONE,
|
int Flipping = FLIP_NONE,
|
||||||
BS_Rect* pPartRect = NULL,
|
BS_Rect *pPartRect = NULL,
|
||||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||||
int Width = -1, int Height = -1);
|
int Width = -1, int Height = -1);
|
||||||
|
|
||||||
class SWFBitStream;
|
class SWFBitStream;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ParseDefineShape(unsigned int ShapeType, SWFBitStream & bs);
|
bool ParseDefineShape(unsigned int ShapeType, SWFBitStream &bs);
|
||||||
bool ParseStyles(unsigned int ShapeType, SWFBitStream & bs, unsigned int & NumFillBits, unsigned int & NumLineBits);
|
bool ParseStyles(unsigned int ShapeType, SWFBitStream &bs, unsigned int &NumFillBits, unsigned int &NumLineBits);
|
||||||
|
|
||||||
Common::Array<BS_VectorImageElement> m_Elements;
|
Common::Array<BS_VectorImageElement> m_Elements;
|
||||||
BS_Rect m_BoundingBox;
|
BS_Rect m_BoundingBox;
|
||||||
|
|
|
@ -49,10 +49,9 @@ namespace Sword25 {
|
||||||
// CompoundShape
|
// CompoundShape
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class CompoundShape
|
class CompoundShape {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
CompoundShape(const BS_VectorImageElement & VectorImageElement) :
|
CompoundShape(const BS_VectorImageElement &VectorImageElement) :
|
||||||
m_ImageElement(VectorImageElement),
|
m_ImageElement(VectorImageElement),
|
||||||
m_Path(VectorImageElement.GetPaths()),
|
m_Path(VectorImageElement.GetPaths()),
|
||||||
m_Affine(),
|
m_Affine(),
|
||||||
|
@ -60,25 +59,24 @@ public:
|
||||||
m_Trans(m_Curve, m_Affine)
|
m_Trans(m_Curve, m_Affine)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
unsigned operator [] (unsigned i) const
|
unsigned operator [](unsigned i) const {
|
||||||
{
|
|
||||||
return m_ImageElement.GetPathInfo(i).GetID();
|
return m_ImageElement.GetPathInfo(i).GetID();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned paths() const { return m_ImageElement.GetPathCount(); }
|
unsigned paths() const {
|
||||||
|
return m_ImageElement.GetPathCount();
|
||||||
|
}
|
||||||
|
|
||||||
void rewind(unsigned path_id)
|
void rewind(unsigned path_id) {
|
||||||
{
|
|
||||||
m_Trans.rewind(path_id);
|
m_Trans.rewind(path_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned vertex(double* x, double* y)
|
unsigned vertex(double *x, double *y) {
|
||||||
{
|
|
||||||
return m_Trans.vertex(x, y);
|
return m_Trans.vertex(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const BS_VectorImageElement & m_ImageElement;
|
const BS_VectorImageElement &m_ImageElement;
|
||||||
agg::path_storage m_Path;
|
agg::path_storage m_Path;
|
||||||
agg::trans_affine m_Affine;
|
agg::trans_affine m_Affine;
|
||||||
agg::conv_curve<agg::path_storage> m_Curve;
|
agg::conv_curve<agg::path_storage> m_Curve;
|
||||||
|
@ -90,29 +88,25 @@ private:
|
||||||
// StyleHandler
|
// StyleHandler
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class StyleHandler
|
class StyleHandler {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
StyleHandler(const BS_VectorImageElement & VectorImageElement) : m_ImageElement(VectorImageElement) {}
|
StyleHandler(const BS_VectorImageElement &VectorImageElement) : m_ImageElement(VectorImageElement) {}
|
||||||
|
|
||||||
bool is_solid(unsigned int style) const
|
bool is_solid(unsigned int style) const {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const agg::rgba8 & color(unsigned style) const
|
const agg::rgba8 &color(unsigned style) const {
|
||||||
{
|
|
||||||
return m_ImageElement.GetFillStyleColor(style);
|
return m_ImageElement.GetFillStyleColor(style);
|
||||||
}
|
}
|
||||||
|
|
||||||
void generate_span(agg::rgba8 * span, int x, int y, unsigned len, unsigned style)
|
void generate_span(agg::rgba8 *span, int x, int y, unsigned len, unsigned style) {
|
||||||
{
|
|
||||||
// Wird nicht benutzt
|
// Wird nicht benutzt
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const BS_VectorImageElement & m_ImageElement;
|
const BS_VectorImageElement &m_ImageElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,21 +115,19 @@ private:
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_VectorImageRenderer::BS_VectorImageRenderer() :
|
BS_VectorImageRenderer::BS_VectorImageRenderer() :
|
||||||
PixelFormat(rbuf)
|
PixelFormat(rbuf) {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_VectorImageRenderer::Render(const BS_VectorImage & VectorImage,
|
bool BS_VectorImageRenderer::Render(const BS_VectorImage &VectorImage,
|
||||||
float ScaleFactorX, float ScaleFactorY,
|
float ScaleFactorX, float ScaleFactorY,
|
||||||
unsigned int & Width, unsigned int & Height,
|
unsigned int &Width, unsigned int &Height,
|
||||||
Common::Array<char> & ImageData,
|
Common::Array<char> & ImageData,
|
||||||
float LineScaleFactor,
|
float LineScaleFactor,
|
||||||
bool NoAlphaShapes)
|
bool NoAlphaShapes) {
|
||||||
{
|
|
||||||
Width = static_cast<unsigned int>(VectorImage.GetWidth() * ScaleFactorX);
|
Width = static_cast<unsigned int>(VectorImage.GetWidth() * ScaleFactorX);
|
||||||
Height = static_cast<unsigned int>(VectorImage.GetHeight() * ScaleFactorY);
|
Height = static_cast<unsigned int>(VectorImage.GetHeight() * ScaleFactorY);
|
||||||
|
|
||||||
|
@ -151,9 +143,8 @@ bool BS_VectorImageRenderer::Render(const BS_VectorImage & VectorImage,
|
||||||
Scale = agg::trans_affine_translation(- VectorImage.GetBoundingBox().left, - VectorImage.GetBoundingBox().top);
|
Scale = agg::trans_affine_translation(- VectorImage.GetBoundingBox().left, - VectorImage.GetBoundingBox().top);
|
||||||
Scale *= agg::trans_affine_scaling(ScaleFactorX, ScaleFactorY);
|
Scale *= agg::trans_affine_scaling(ScaleFactorX, ScaleFactorY);
|
||||||
|
|
||||||
for (unsigned int element = 0; element < VectorImage.GetElementCount(); ++element)
|
for (unsigned int element = 0; element < VectorImage.GetElementCount(); ++element) {
|
||||||
{
|
const BS_VectorImageElement &CurImageElement = VectorImage.GetElement(element);
|
||||||
const BS_VectorImageElement & CurImageElement = VectorImage.GetElement(element);
|
|
||||||
|
|
||||||
CompoundShape ImageCompoundShape(CurImageElement);
|
CompoundShape ImageCompoundShape(CurImageElement);
|
||||||
StyleHandler ImageStyleHandler(CurImageElement);
|
StyleHandler ImageStyleHandler(CurImageElement);
|
||||||
|
@ -164,19 +155,16 @@ bool BS_VectorImageRenderer::Render(const BS_VectorImage & VectorImage,
|
||||||
//----------------------
|
//----------------------
|
||||||
CompoundRasterizer.clip_box(0, 0, Width, Height);
|
CompoundRasterizer.clip_box(0, 0, Width, Height);
|
||||||
CompoundRasterizer.reset();
|
CompoundRasterizer.reset();
|
||||||
for(unsigned int i = 0; i < CurImageElement.GetPathCount(); ++i)
|
for (unsigned int i = 0; i < CurImageElement.GetPathCount(); ++i) {
|
||||||
{
|
|
||||||
unsigned int FillStyle0 = CurImageElement.GetPathInfo(i).GetFillStyle0();
|
unsigned int FillStyle0 = CurImageElement.GetPathInfo(i).GetFillStyle0();
|
||||||
unsigned int FillStyle1 = CurImageElement.GetPathInfo(i).GetFillStyle1();
|
unsigned int FillStyle1 = CurImageElement.GetPathInfo(i).GetFillStyle1();
|
||||||
|
|
||||||
if (NoAlphaShapes)
|
if (NoAlphaShapes) {
|
||||||
{
|
|
||||||
if (FillStyle0 != 0 && CurImageElement.GetFillStyleColor(FillStyle0 - 1).a != 255) FillStyle0 = 0;
|
if (FillStyle0 != 0 && CurImageElement.GetFillStyleColor(FillStyle0 - 1).a != 255) FillStyle0 = 0;
|
||||||
if (FillStyle1 != 0 && CurImageElement.GetFillStyleColor(FillStyle1 - 1).a != 255) FillStyle1 = 0;
|
if (FillStyle1 != 0 && CurImageElement.GetFillStyleColor(FillStyle1 - 1).a != 255) FillStyle1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(FillStyle0 != 0 || FillStyle1 != 0)
|
if (FillStyle0 != 0 || FillStyle1 != 0) {
|
||||||
{
|
|
||||||
CompoundRasterizer.styles(FillStyle0 - 1, FillStyle1 - 1);
|
CompoundRasterizer.styles(FillStyle0 - 1, FillStyle1 - 1);
|
||||||
CompoundRasterizer.add_path(Shape, CurImageElement.GetPathInfo(i).GetID());
|
CompoundRasterizer.add_path(Shape, CurImageElement.GetPathInfo(i).GetID());
|
||||||
}
|
}
|
||||||
|
@ -189,13 +177,11 @@ bool BS_VectorImageRenderer::Render(const BS_VectorImage & VectorImage,
|
||||||
Rasterizer.clip_box(0, 0, Width, Height);
|
Rasterizer.clip_box(0, 0, Width, Height);
|
||||||
Stroke.line_join(agg::round_join);
|
Stroke.line_join(agg::round_join);
|
||||||
Stroke.line_cap(agg::round_cap);
|
Stroke.line_cap(agg::round_cap);
|
||||||
for(unsigned int i = 0; i < CurImageElement.GetPathCount(); ++i)
|
for (unsigned int i = 0; i < CurImageElement.GetPathCount(); ++i) {
|
||||||
{
|
|
||||||
Rasterizer.reset();
|
Rasterizer.reset();
|
||||||
|
|
||||||
unsigned int CurrentLineStyle = CurImageElement.GetPathInfo(i).GetLineStyle();
|
unsigned int CurrentLineStyle = CurImageElement.GetPathInfo(i).GetLineStyle();
|
||||||
if (CurrentLineStyle != 0)
|
if (CurrentLineStyle != 0) {
|
||||||
{
|
|
||||||
Stroke.width(ScaleFactorX * CurImageElement.GetLineStyleWidth(CurrentLineStyle - 1) * LineScaleFactor);
|
Stroke.width(ScaleFactorX * CurImageElement.GetLineStyleWidth(CurrentLineStyle - 1) * LineScaleFactor);
|
||||||
Rasterizer.add_path(Stroke, CurImageElement.GetPathInfo(i).GetID());
|
Rasterizer.add_path(Stroke, CurImageElement.GetPathInfo(i).GetID());
|
||||||
ScanlineRenderer.color(CurImageElement.GetLineStyleColor(CurrentLineStyle - 1));
|
ScanlineRenderer.color(CurImageElement.GetLineStyleColor(CurrentLineStyle - 1));
|
||||||
|
|
|
@ -61,14 +61,13 @@ class BS_VectorImage;
|
||||||
@brief Rendert BS_VectorImage Objekte
|
@brief Rendert BS_VectorImage Objekte
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BS_VectorImageRenderer
|
class BS_VectorImageRenderer {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BS_VectorImageRenderer();
|
BS_VectorImageRenderer();
|
||||||
|
|
||||||
bool Render(const BS_VectorImage & VectorImage,
|
bool Render(const BS_VectorImage &VectorImage,
|
||||||
float ScaleFactorX, float ScaleFactorY,
|
float ScaleFactorX, float ScaleFactorY,
|
||||||
unsigned int & Width, unsigned int & Height,
|
unsigned int &Width, unsigned int &Height,
|
||||||
Common::Array<char> & ImageData,
|
Common::Array<char> & ImageData,
|
||||||
float LineScaleFactor = 1.0f,
|
float LineScaleFactor = 1.0f,
|
||||||
bool NoAlphaShapes = false);
|
bool NoAlphaShapes = false);
|
||||||
|
|
|
@ -50,21 +50,19 @@ namespace Sword25 {
|
||||||
// CONSTRUCTION / DESTRUCTION
|
// CONSTRUCTION / DESTRUCTION
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_GLImage::BS_GLImage(const Common::String & Filename, bool & Result) :
|
BS_GLImage::BS_GLImage(const Common::String &Filename, bool &Result) :
|
||||||
m_Sprite(0),
|
m_Sprite(0),
|
||||||
m_Width(0),
|
m_Width(0),
|
||||||
m_Height(0)
|
m_Height(0) {
|
||||||
{
|
|
||||||
Result = false;
|
Result = false;
|
||||||
|
|
||||||
BS_PackageManager * pPackage = static_cast<BS_PackageManager*>(BS_Kernel::GetInstance()->GetService("package"));
|
BS_PackageManager *pPackage = static_cast<BS_PackageManager *>(BS_Kernel::GetInstance()->GetService("package"));
|
||||||
BS_ASSERT(pPackage);
|
BS_ASSERT(pPackage);
|
||||||
|
|
||||||
// Datei laden
|
// Datei laden
|
||||||
char* pFileData;
|
char *pFileData;
|
||||||
unsigned int FileSize;
|
unsigned int FileSize;
|
||||||
if (!(pFileData = (char*) pPackage->GetFile(Filename, &FileSize)))
|
if (!(pFileData = (char *) pPackage->GetFile(Filename, &FileSize))) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("File \"%s\" could not be loaded.", Filename.c_str());
|
BS_LOG_ERRORLN("File \"%s\" could not be loaded.", Filename.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -72,16 +70,14 @@ BS_GLImage::BS_GLImage(const Common::String & Filename, bool & Result) :
|
||||||
// Bildeigenschaften bestimmen
|
// Bildeigenschaften bestimmen
|
||||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat;
|
BS_GraphicEngine::COLOR_FORMATS ColorFormat;
|
||||||
int Pitch;
|
int Pitch;
|
||||||
if (!BS_ImageLoader::ExtractImageProperties(pFileData, FileSize, ColorFormat, m_Width, m_Height))
|
if (!BS_ImageLoader::ExtractImageProperties(pFileData, FileSize, ColorFormat, m_Width, m_Height)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not read image properties.");
|
BS_LOG_ERRORLN("Could not read image properties.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Das Bild dekomprimieren
|
// Das Bild dekomprimieren
|
||||||
char * pUncompressedData;
|
char *pUncompressedData;
|
||||||
if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch))
|
if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not decode image.");
|
BS_LOG_ERRORLN("Could not decode image.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -94,8 +90,7 @@ BS_GLImage::BS_GLImage(const Common::String & Filename, bool & Result) :
|
||||||
(ColorFormat == BS_GraphicEngine::CF_ARGB32) ? GLS_True : GLS_False,
|
(ColorFormat == BS_GraphicEngine::CF_ARGB32) ? GLS_True : GLS_False,
|
||||||
pUncompressedData,
|
pUncompressedData,
|
||||||
&m_Sprite);
|
&m_Sprite);
|
||||||
if (Result != GLS_OK)
|
if (Result != GLS_OK) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(GLSResult));
|
BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(GLSResult));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -109,11 +104,10 @@ BS_GLImage::BS_GLImage(const Common::String & Filename, bool & Result) :
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_GLImage::BS_GLImage(unsigned int Width, unsigned int Height, bool & Result) :
|
BS_GLImage::BS_GLImage(unsigned int Width, unsigned int Height, bool &Result) :
|
||||||
m_Sprite(0),
|
m_Sprite(0),
|
||||||
m_Width(Width),
|
m_Width(Width),
|
||||||
m_Height(Height)
|
m_Height(Height) {
|
||||||
{
|
|
||||||
Result = false;
|
Result = false;
|
||||||
|
|
||||||
// GLS-Sprite mit den Bilddaten erstellen
|
// GLS-Sprite mit den Bilddaten erstellen
|
||||||
|
@ -121,8 +115,7 @@ BS_GLImage::BS_GLImage(unsigned int Width, unsigned int Height, bool & Result) :
|
||||||
GLS_True,
|
GLS_True,
|
||||||
0,
|
0,
|
||||||
&m_Sprite);
|
&m_Sprite);
|
||||||
if (GLSResult != GLS_OK)
|
if (GLSResult != GLS_OK) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(GLSResult));
|
BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(GLSResult));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -133,34 +126,29 @@ BS_GLImage::BS_GLImage(unsigned int Width, unsigned int Height, bool & Result) :
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_GLImage::~BS_GLImage()
|
BS_GLImage::~BS_GLImage() {
|
||||||
{
|
|
||||||
if (m_Sprite) GLS_DeleteSprite(m_Sprite);
|
if (m_Sprite) GLS_DeleteSprite(m_Sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_GLImage::Fill(const BS_Rect* pFillRect, unsigned int Color)
|
bool BS_GLImage::Fill(const BS_Rect *pFillRect, unsigned int Color) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Fill() is not supported.");
|
BS_LOG_ERRORLN("Fill() is not supported.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_GLImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
bool BS_GLImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||||
{
|
|
||||||
// Überprüfen, ob PixelData ausreichend viele Pixel enthält um ein Bild der Größe Width * Height zu erzeugen
|
// Überprüfen, ob PixelData ausreichend viele Pixel enthält um ein Bild der Größe Width * Height zu erzeugen
|
||||||
if (Pixeldata.size() < static_cast<unsigned int>(m_Width * m_Height * 4))
|
if (Pixeldata.size() < static_cast<unsigned int>(m_Width * m_Height * 4)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("PixelData vector is too small to define a 32 bit %dx%d image.", m_Width, m_Height);
|
BS_LOG_ERRORLN("PixelData vector is too small to define a 32 bit %dx%d image.", m_Width, m_Height);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GLS-Sprite mit den Bilddaten füllen
|
// GLS-Sprite mit den Bilddaten füllen
|
||||||
GLS_Result GLSResult = GLS_SetSpriteData(m_Sprite, m_Width, m_Height, &Pixeldata[Offset], Stride / 4);
|
GLS_Result GLSResult = GLS_SetSpriteData(m_Sprite, m_Width, m_Height, &Pixeldata[Offset], Stride / 4);
|
||||||
if (GLSResult != GLS_OK)
|
if (GLSResult != GLS_OK) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("CGLS_SetSpriteData() failed. Reason: %s", GLS_ResultString(GLSResult));
|
BS_LOG_ERRORLN("CGLS_SetSpriteData() failed. Reason: %s", GLS_ResultString(GLSResult));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -170,8 +158,7 @@ bool BS_GLImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_GLImage::GetPixel(int X, int Y)
|
unsigned int BS_GLImage::GetPixel(int X, int Y) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("GetPixel() is not supported. Returning black.");
|
BS_LOG_ERRORLN("GetPixel() is not supported. Returning black.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -180,14 +167,12 @@ unsigned int BS_GLImage::GetPixel(int X, int Y)
|
||||||
|
|
||||||
bool BS_GLImage::Blit(int PosX, int PosY,
|
bool BS_GLImage::Blit(int PosX, int PosY,
|
||||||
int Flipping,
|
int Flipping,
|
||||||
BS_Rect* pPartRect,
|
BS_Rect *pPartRect,
|
||||||
unsigned int Color,
|
unsigned int Color,
|
||||||
int Width, int Height)
|
int Width, int Height) {
|
||||||
{
|
|
||||||
// BS_Rect nach GLS_Rect konvertieren
|
// BS_Rect nach GLS_Rect konvertieren
|
||||||
GLS_Rect SubImage;
|
GLS_Rect SubImage;
|
||||||
if (pPartRect)
|
if (pPartRect) {
|
||||||
{
|
|
||||||
SubImage.x1 = pPartRect->left;
|
SubImage.x1 = pPartRect->left;
|
||||||
SubImage.y1 = pPartRect->top;
|
SubImage.y1 = pPartRect->top;
|
||||||
SubImage.x2 = pPartRect->right;
|
SubImage.x2 = pPartRect->right;
|
||||||
|
|
|
@ -51,16 +51,15 @@ namespace Sword25 {
|
||||||
// FORWARD DECLARATION
|
// FORWARD DECLARATION
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
typedef void * GLS_Sprite;
|
typedef void *GLS_Sprite;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// CLASS DEFINITION
|
// CLASS DEFINITION
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_GLImage : public BS_Image
|
class BS_GLImage : public BS_Image {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BS_GLImage(const Common::String & Filename, bool & Result);
|
BS_GLImage(const Common::String &Filename, bool &Result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Erzeugt ein leeres BS_GLImage
|
@brief Erzeugt ein leeres BS_GLImage
|
||||||
|
@ -70,29 +69,49 @@ public:
|
||||||
@param Result gibt dem Aufrufer bekannt, ob der Konstruktor erfolgreich ausgeführt wurde. Wenn es nach dem Aufruf false enthalten sollte,
|
@param Result gibt dem Aufrufer bekannt, ob der Konstruktor erfolgreich ausgeführt wurde. Wenn es nach dem Aufruf false enthalten sollte,
|
||||||
dürfen keine Methoden am Objekt aufgerufen werden und das Objekt ist sofort zu zerstören.
|
dürfen keine Methoden am Objekt aufgerufen werden und das Objekt ist sofort zu zerstören.
|
||||||
*/
|
*/
|
||||||
BS_GLImage(unsigned int Width, unsigned int Height, bool & Result);
|
BS_GLImage(unsigned int Width, unsigned int Height, bool &Result);
|
||||||
virtual ~BS_GLImage();
|
virtual ~BS_GLImage();
|
||||||
|
|
||||||
virtual int GetWidth() const { return m_Width; }
|
virtual int GetWidth() const {
|
||||||
virtual int GetHeight() const { return m_Height; }
|
return m_Width;
|
||||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const { return BS_GraphicEngine::CF_ARGB32; }
|
}
|
||||||
|
virtual int GetHeight() const {
|
||||||
|
return m_Height;
|
||||||
|
}
|
||||||
|
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const {
|
||||||
|
return BS_GraphicEngine::CF_ARGB32;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||||
int Flipping = BS_Image::FLIP_NONE,
|
int Flipping = BS_Image::FLIP_NONE,
|
||||||
BS_Rect* pPartRect = NULL,
|
BS_Rect *pPartRect = NULL,
|
||||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||||
int Width = -1, int Height = -1);
|
int Width = -1, int Height = -1);
|
||||||
virtual bool Fill(const BS_Rect* pFillRect, unsigned int Color);
|
virtual bool Fill(const BS_Rect *pFillRect, unsigned int Color);
|
||||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset = 0, unsigned int Stride = 0);
|
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset = 0, unsigned int Stride = 0);
|
||||||
virtual unsigned int GetPixel(int X, int Y);
|
virtual unsigned int GetPixel(int X, int Y);
|
||||||
|
|
||||||
virtual bool IsBlitSource() const { return true; }
|
virtual bool IsBlitSource() const {
|
||||||
virtual bool IsBlitTarget() const { return false; }
|
return true;
|
||||||
virtual bool IsScalingAllowed() const { return true; }
|
}
|
||||||
virtual bool IsFillingAllowed() const { return false; }
|
virtual bool IsBlitTarget() const {
|
||||||
virtual bool IsAlphaAllowed() const { return true; }
|
return false;
|
||||||
virtual bool IsColorModulationAllowed() const { return true; }
|
}
|
||||||
virtual bool IsSetContentAllowed() const { return true; }
|
virtual bool IsScalingAllowed() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
virtual bool IsFillingAllowed() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool IsAlphaAllowed() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
virtual bool IsColorModulationAllowed() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
virtual bool IsSetContentAllowed() const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
GLS_Sprite m_Sprite;
|
GLS_Sprite m_Sprite;
|
||||||
int m_Width;
|
int m_Width;
|
||||||
|
|
|
@ -50,23 +50,21 @@ using namespace std;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
const float LINE_SCALE_FACTOR = 1.0f;
|
||||||
const float LINE_SCALE_FACTOR = 1.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_VectorImage::Blit(int PosX, int PosY,
|
bool BS_VectorImage::Blit(int PosX, int PosY,
|
||||||
int Flipping,
|
int Flipping,
|
||||||
BS_Rect* pPartRect,
|
BS_Rect *pPartRect,
|
||||||
unsigned int Color,
|
unsigned int Color,
|
||||||
int Width, int Height)
|
int Width, int Height) {
|
||||||
{
|
|
||||||
static BS_VectorImageRenderer VectorImageRenderer;
|
static BS_VectorImageRenderer VectorImageRenderer;
|
||||||
static vector<char> PixelData;
|
static vector<char> PixelData;
|
||||||
static GLS_Sprite Sprite = 0;
|
static GLS_Sprite Sprite = 0;
|
||||||
static BS_VectorImage * OldThis = 0;
|
static BS_VectorImage *OldThis = 0;
|
||||||
static int OldWidth;
|
static int OldWidth;
|
||||||
static int OldHeight;
|
static int OldHeight;
|
||||||
static GLS_Rect OldSubImage;
|
static GLS_Rect OldSubImage;
|
||||||
|
@ -75,39 +73,33 @@ bool BS_VectorImage::Blit(int PosX, int PosY,
|
||||||
if (Width == 0 || Height == 0) return true;
|
if (Width == 0 || Height == 0) return true;
|
||||||
|
|
||||||
// Sprite erstellen, falls es noch nicht erstellt wurde
|
// Sprite erstellen, falls es noch nicht erstellt wurde
|
||||||
if (Sprite == 0)
|
if (Sprite == 0) {
|
||||||
{
|
|
||||||
GLS_Result Result = GLS_NewSprite(512, 512, GLS_True, 0, &Sprite);
|
GLS_Result Result = GLS_NewSprite(512, 512, GLS_True, 0, &Sprite);
|
||||||
if (Result != GLS_OK)
|
if (Result != GLS_OK) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(Result));
|
BS_LOG_ERRORLN("Could not create GLS_Sprite. Reason: %s", GLS_ResultString(Result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Feststellen, ob das alte Bild im Cache nicht wiederbenutzt werden kann und neu Berechnet werden muss
|
// Feststellen, ob das alte Bild im Cache nicht wiederbenutzt werden kann und neu Berechnet werden muss
|
||||||
if (!(OldThis == this && OldWidth == Width && OldHeight == Height && Sprite != 0))
|
if (!(OldThis == this && OldWidth == Width && OldHeight == Height && Sprite != 0)) {
|
||||||
{
|
|
||||||
float ScaleFactorX = (Width == - 1) ? 1 : static_cast<float>(Width) / static_cast<float>(GetWidth());
|
float ScaleFactorX = (Width == - 1) ? 1 : static_cast<float>(Width) / static_cast<float>(GetWidth());
|
||||||
float ScaleFactorY = (Height == - 1) ? 1: static_cast<float>(Height) / static_cast<float>(GetHeight());
|
float ScaleFactorY = (Height == - 1) ? 1 : static_cast<float>(Height) / static_cast<float>(GetHeight());
|
||||||
|
|
||||||
unsigned int RenderedWidth;
|
unsigned int RenderedWidth;
|
||||||
unsigned int RenderedHeight;
|
unsigned int RenderedHeight;
|
||||||
if (!VectorImageRenderer.Render(*this, ScaleFactorX, ScaleFactorY, RenderedWidth, RenderedHeight, PixelData, LINE_SCALE_FACTOR))
|
if (!VectorImageRenderer.Render(*this, ScaleFactorX, ScaleFactorY, RenderedWidth, RenderedHeight, PixelData, LINE_SCALE_FACTOR)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Call to BS_VectorImageRenderer::Render() failed.");
|
BS_LOG_ERRORLN("Call to BS_VectorImageRenderer::Render() failed.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RenderedWidth > 512 || RenderedHeight > 512)
|
if (RenderedWidth > 512 || RenderedHeight > 512) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Currently the maximum size for scaled vector images is 512x512.");
|
BS_LOG_WARNINGLN("Currently the maximum size for scaled vector images is 512x512.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLS_Result Result = GLS_SetSpriteData(Sprite, RenderedWidth, RenderedHeight, &PixelData[0], 0);
|
GLS_Result Result = GLS_SetSpriteData(Sprite, RenderedWidth, RenderedHeight, &PixelData[0], 0);
|
||||||
if (Result != GLS_OK)
|
if (Result != GLS_OK) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Call to GLS_SetSpriteData() failed. Reason: %s", GLS_ResultString(Result));
|
BS_LOG_ERRORLN("Call to GLS_SetSpriteData() failed. Reason: %s", GLS_ResultString(Result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,16 +68,15 @@ using namespace std;
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
const unsigned int BIT_DEPTH = 32;
|
||||||
const unsigned int BIT_DEPTH = 32;
|
const unsigned int BACKBUFFER_COUNT = 1;
|
||||||
const unsigned int BACKBUFFER_COUNT = 1;
|
const Common::String PNG_EXTENSION(".png");
|
||||||
const Common::String PNG_EXTENSION(".png");
|
const Common::String PNG_S_EXTENSION("_s.png");
|
||||||
const Common::String PNG_S_EXTENSION("_s.png");
|
const Common::String ANI_EXTENSION("_ani.xml");
|
||||||
const Common::String ANI_EXTENSION("_ani.xml");
|
const Common::String FNT_EXTENSION("_fnt.xml");
|
||||||
const Common::String FNT_EXTENSION("_fnt.xml");
|
const Common::String SWF_EXTENSION(".swf");
|
||||||
const Common::String SWF_EXTENSION(".swf");
|
const Common::String B25S_EXTENSION(".b25s");
|
||||||
const Common::String B25S_EXTENSION(".b25s");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,23 +84,20 @@ namespace
|
||||||
// CONSTRUCTION / DESTRUCTION
|
// CONSTRUCTION / DESTRUCTION
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_OpenGLGfx::BS_OpenGLGfx(BS_Kernel * pKernel) :
|
BS_OpenGLGfx::BS_OpenGLGfx(BS_Kernel *pKernel) :
|
||||||
BS_GraphicEngine(pKernel),
|
BS_GraphicEngine(pKernel),
|
||||||
m_GLspritesInitialized(false)
|
m_GLspritesInitialized(false) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_OpenGLGfx::~BS_OpenGLGfx()
|
BS_OpenGLGfx::~BS_OpenGLGfx() {
|
||||||
{
|
|
||||||
if (m_GLspritesInitialized) GLS_Quit();
|
if (m_GLspritesInitialized) GLS_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Service * BS_OpenGLGfx_CreateObject(BS_Kernel* pKernel)
|
BS_Service *BS_OpenGLGfx_CreateObject(BS_Kernel *pKernel) {
|
||||||
{
|
|
||||||
return new BS_OpenGLGfx(pKernel);
|
return new BS_OpenGLGfx(pKernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,18 +106,15 @@ BS_Service * BS_OpenGLGfx_CreateObject(BS_Kernel* pKernel)
|
||||||
// INTERFACE
|
// INTERFACE
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount, bool Windowed)
|
bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount, bool Windowed) {
|
||||||
{
|
|
||||||
// Warnung ausgeben, wenn eine nicht unterstützte Bittiefe gewählt wurde.
|
// Warnung ausgeben, wenn eine nicht unterstützte Bittiefe gewählt wurde.
|
||||||
if (BitDepth != BIT_DEPTH)
|
if (BitDepth != BIT_DEPTH) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Can't use a bit depth of %d (not supported). Falling back to %d.", BitDepth, BIT_DEPTH);
|
BS_LOG_WARNINGLN("Can't use a bit depth of %d (not supported). Falling back to %d.", BitDepth, BIT_DEPTH);
|
||||||
m_BitDepth = BIT_DEPTH;
|
m_BitDepth = BIT_DEPTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warnung ausgeben, wenn nicht genau ein Backbuffer gewählt wurde.
|
// Warnung ausgeben, wenn nicht genau ein Backbuffer gewählt wurde.
|
||||||
if (BackbufferCount != BACKBUFFER_COUNT)
|
if (BackbufferCount != BACKBUFFER_COUNT) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Can't use %d backbuffers (not supported). Falling back to %d.", BackbufferCount, BACKBUFFER_COUNT);
|
BS_LOG_WARNINGLN("Can't use %d backbuffers (not supported). Falling back to %d.", BackbufferCount, BACKBUFFER_COUNT);
|
||||||
BackbufferCount = BACKBUFFER_COUNT;
|
BackbufferCount = BACKBUFFER_COUNT;
|
||||||
}
|
}
|
||||||
|
@ -139,8 +132,7 @@ bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount
|
||||||
// GLsprites initialisieren
|
// GLsprites initialisieren
|
||||||
HWND hwnd = reinterpret_cast<HWND>(BS_Kernel::GetInstance()->GetWindow()->GetWindowHandle());
|
HWND hwnd = reinterpret_cast<HWND>(BS_Kernel::GetInstance()->GetWindow()->GetWindowHandle());
|
||||||
GLS_Result Result = GLS_InitExternalWindow(Width, Height, Windowed ? GLS_False : GLS_True, hwnd);
|
GLS_Result Result = GLS_InitExternalWindow(Width, Height, Windowed ? GLS_False : GLS_True, hwnd);
|
||||||
if (Result != GLS_OK)
|
if (Result != GLS_OK) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not initialize GLsprites. Reason: %s", GLS_ResultString(Result));
|
BS_LOG_ERRORLN("Could not initialize GLsprites. Reason: %s", GLS_ResultString(Result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +145,7 @@ bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount
|
||||||
m_RenderObjectManagerPtr.reset(new BS_RenderObjectManager(Width, Height, BackbufferCount + 1));
|
m_RenderObjectManagerPtr.reset(new BS_RenderObjectManager(Width, Height, BackbufferCount + 1));
|
||||||
|
|
||||||
// Hauptpanel erstellen
|
// Hauptpanel erstellen
|
||||||
m_MainPanelPtr = m_RenderObjectManagerPtr->GetTreeRoot()->AddPanel(Width, Height, BS_ARGB(0,0,0,0));
|
m_MainPanelPtr = m_RenderObjectManagerPtr->GetTreeRoot()->AddPanel(Width, Height, BS_ARGB(0, 0, 0, 0));
|
||||||
if (!m_MainPanelPtr.IsValid()) return false;
|
if (!m_MainPanelPtr.IsValid()) return false;
|
||||||
m_MainPanelPtr->SetVisible(true);
|
m_MainPanelPtr->SetVisible(true);
|
||||||
|
|
||||||
|
@ -162,8 +154,7 @@ bool BS_OpenGLGfx::Init(int Width, int Height, int BitDepth, int BackbufferCount
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::StartFrame(bool UpdateAll)
|
bool BS_OpenGLGfx::StartFrame(bool UpdateAll) {
|
||||||
{
|
|
||||||
// Berechnen, wie viel Zeit seit dem letzten Frame vergangen ist.
|
// Berechnen, wie viel Zeit seit dem letzten Frame vergangen ist.
|
||||||
// Dieser Wert kann über GetLastFrameDuration() von Modulen abgefragt werden, die zeitabhängig arbeiten.
|
// Dieser Wert kann über GetLastFrameDuration() von Modulen abgefragt werden, die zeitabhängig arbeiten.
|
||||||
UpdateLastFrameDuration();
|
UpdateLastFrameDuration();
|
||||||
|
@ -173,8 +164,7 @@ bool BS_OpenGLGfx::StartFrame(bool UpdateAll)
|
||||||
|
|
||||||
// GLsprites bescheidgeben
|
// GLsprites bescheidgeben
|
||||||
GLS_Result Result = GLS_StartFrame();
|
GLS_Result Result = GLS_StartFrame();
|
||||||
if (Result != GLS_OK)
|
if (Result != GLS_OK) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Call to GLS_StartFrame() failed. Reason: %s", GLS_ResultString(Result));
|
BS_LOG_ERRORLN("Call to GLS_StartFrame() failed. Reason: %s", GLS_ResultString(Result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -184,23 +174,20 @@ bool BS_OpenGLGfx::StartFrame(bool UpdateAll)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::EndFrame()
|
bool BS_OpenGLGfx::EndFrame() {
|
||||||
{
|
|
||||||
// Scene zeichnen
|
// Scene zeichnen
|
||||||
m_RenderObjectManagerPtr->Render();
|
m_RenderObjectManagerPtr->Render();
|
||||||
|
|
||||||
// Debug-Lines zeichnen
|
// Debug-Lines zeichnen
|
||||||
if (!m_DebugLines.empty())
|
if (!m_DebugLines.empty()) {
|
||||||
{
|
|
||||||
glEnable(GL_LINE_SMOOTH);
|
glEnable(GL_LINE_SMOOTH);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
|
|
||||||
Common::Array<DebugLine>::const_iterator iter = m_DebugLines.begin();
|
Common::Array<DebugLine>::const_iterator iter = m_DebugLines.begin();
|
||||||
for (; iter != m_DebugLines.end(); ++iter)
|
for (; iter != m_DebugLines.end(); ++iter) {
|
||||||
{
|
const unsigned int &Color = (*iter).Color;
|
||||||
const unsigned int & Color = (*iter).Color;
|
const BS_Vertex &Start = (*iter).Start;
|
||||||
const BS_Vertex & Start = (*iter).Start;
|
const BS_Vertex &End = (*iter).End;
|
||||||
const BS_Vertex & End = (*iter).End;
|
|
||||||
|
|
||||||
glColor4ub((Color >> 16) & 0xff, (Color >> 8) & 0xff, Color & 0xff, Color >> 24);
|
glColor4ub((Color >> 16) & 0xff, (Color >> 8) & 0xff, Color & 0xff, Color >> 24);
|
||||||
glVertex2d(Start.X, Start.Y);
|
glVertex2d(Start.X, Start.Y);
|
||||||
|
@ -215,8 +202,7 @@ bool BS_OpenGLGfx::EndFrame()
|
||||||
|
|
||||||
// Flippen
|
// Flippen
|
||||||
GLS_Result Result = GLS_EndFrame();
|
GLS_Result Result = GLS_EndFrame();
|
||||||
if (Result != GLS_OK)
|
if (Result != GLS_OK) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Call to GLS_EndFrame() failed. Reason: %s", GLS_ResultString(Result));
|
BS_LOG_ERRORLN("Call to GLS_EndFrame() failed. Reason: %s", GLS_ResultString(Result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -229,27 +215,23 @@ bool BS_OpenGLGfx::EndFrame()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectPtr<BS_Panel> BS_OpenGLGfx::GetMainPanel()
|
BS_RenderObjectPtr<BS_Panel> BS_OpenGLGfx::GetMainPanel() {
|
||||||
{
|
|
||||||
return m_MainPanelPtr;
|
return m_MainPanelPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_OpenGLGfx::SetVsync(bool Vsync)
|
void BS_OpenGLGfx::SetVsync(bool Vsync) {
|
||||||
{
|
|
||||||
GLS_Result Result = GLS_SetVSync(Vsync ? GLS_True : GLS_False);
|
GLS_Result Result = GLS_SetVSync(Vsync ? GLS_True : GLS_False);
|
||||||
if (Result != GLS_OK) BS_LOG_WARNINGLN("Could not set vsync status. Reason: %s", GLS_ResultString(Result));
|
if (Result != GLS_OK) BS_LOG_WARNINGLN("Could not set vsync status. Reason: %s", GLS_ResultString(Result));
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::GetVsync() const
|
bool BS_OpenGLGfx::GetVsync() const {
|
||||||
{
|
|
||||||
GLS_Bool Status;
|
GLS_Bool Status;
|
||||||
GLS_Result Result = GLS_IsVsync(&Status);
|
GLS_Result Result = GLS_IsVsync(&Status);
|
||||||
if (Result != GLS_OK)
|
if (Result != GLS_OK) {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN("Could not get vsync status. Returning false. Reason: %s", GLS_ResultString(Result));
|
BS_LOG_WARNINGLN("Could not get vsync status. Returning false. Reason: %s", GLS_ResultString(Result));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -259,12 +241,10 @@ bool BS_OpenGLGfx::GetVsync() const
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::Fill(const BS_Rect* FillRectPtr, unsigned int Color)
|
bool BS_OpenGLGfx::Fill(const BS_Rect *FillRectPtr, unsigned int Color) {
|
||||||
{
|
|
||||||
BS_Rect Rect;
|
BS_Rect Rect;
|
||||||
|
|
||||||
if (!FillRectPtr)
|
if (!FillRectPtr) {
|
||||||
{
|
|
||||||
Rect.left = 0;
|
Rect.left = 0;
|
||||||
Rect.top = 0;
|
Rect.top = 0;
|
||||||
Rect.right = m_Width;
|
Rect.right = m_Width;
|
||||||
|
@ -286,8 +266,7 @@ bool BS_OpenGLGfx::Fill(const BS_Rect* FillRectPtr, unsigned int Color)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::GetScreenshot(unsigned int & Width, unsigned int & Height, vector<unsigned int> & Data)
|
bool BS_OpenGLGfx::GetScreenshot(unsigned int &Width, unsigned int &Height, vector<unsigned int> & Data) {
|
||||||
{
|
|
||||||
if (!ReadFramebufferContents(m_Width, m_Height, Data)) return false;
|
if (!ReadFramebufferContents(m_Width, m_Height, Data)) return false;
|
||||||
|
|
||||||
// Die Größe des Framebuffers zurückgeben.
|
// Die Größe des Framebuffers zurückgeben.
|
||||||
|
@ -303,15 +282,13 @@ bool BS_OpenGLGfx::GetScreenshot(unsigned int & Width, unsigned int & Height, ve
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::ReadFramebufferContents(unsigned int Width, unsigned int Height, Common::Array<unsigned int> & Data)
|
bool BS_OpenGLGfx::ReadFramebufferContents(unsigned int Width, unsigned int Height, Common::Array<unsigned int> & Data) {
|
||||||
{
|
|
||||||
Data.resize(Width * Height);
|
Data.resize(Width * Height);
|
||||||
glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, &Data[0]);
|
glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, &Data[0]);
|
||||||
|
|
||||||
if (glGetError() == 0)
|
if (glGetError() == 0)
|
||||||
return true;
|
return true;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
Data.clear();
|
Data.clear();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -319,11 +296,9 @@ bool BS_OpenGLGfx::ReadFramebufferContents(unsigned int Width, unsigned int Heig
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_OpenGLGfx::ReverseRGBAComponentOrder(vector<unsigned int> & Data)
|
void BS_OpenGLGfx::ReverseRGBAComponentOrder(vector<unsigned int> & Data) {
|
||||||
{
|
|
||||||
vector<unsigned int>::iterator It = Data.begin();
|
vector<unsigned int>::iterator It = Data.begin();
|
||||||
while (It != Data.end())
|
while (It != Data.end()) {
|
||||||
{
|
|
||||||
unsigned int Pixel = *It;
|
unsigned int Pixel = *It;
|
||||||
*It = (Pixel & 0xff00ff00) | ((Pixel >> 16) & 0xff) | ((Pixel & 0xff) << 16);
|
*It = (Pixel & 0xff00ff00) | ((Pixel >> 16) & 0xff) | ((Pixel & 0xff) << 16);
|
||||||
++It;
|
++It;
|
||||||
|
@ -332,12 +307,10 @@ void BS_OpenGLGfx::ReverseRGBAComponentOrder(vector<unsigned int> & Data)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_OpenGLGfx::FlipImagedataVertical(unsigned int Width, unsigned int Height, vector<unsigned int> & Data)
|
void BS_OpenGLGfx::FlipImagedataVertical(unsigned int Width, unsigned int Height, vector<unsigned int> & Data) {
|
||||||
{
|
|
||||||
vector<unsigned int> LineBuffer(Width);
|
vector<unsigned int> LineBuffer(Width);
|
||||||
|
|
||||||
for (unsigned int Y = 0; Y < Height / 2; ++Y)
|
for (unsigned int Y = 0; Y < Height / 2; ++Y) {
|
||||||
{
|
|
||||||
vector<unsigned int>::iterator Line1It = Data.begin() + Y * Width;
|
vector<unsigned int>::iterator Line1It = Data.begin() + Y * Width;
|
||||||
vector<unsigned int>::iterator Line2It = Data.begin() + (Height - 1 - Y) * Width;
|
vector<unsigned int>::iterator Line2It = Data.begin() + (Height - 1 - Y) * Width;
|
||||||
copy(Line1It, Line1It + Width, LineBuffer.begin());
|
copy(Line1It, Line1It + Width, LineBuffer.begin());
|
||||||
|
@ -350,8 +323,7 @@ void BS_OpenGLGfx::FlipImagedataVertical(unsigned int Width, unsigned int Height
|
||||||
// RESOURCE MANAGING
|
// RESOURCE MANAGING
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static bool DoesStringEndWith(const Common::String & String, const std::string & OtherString)
|
static bool DoesStringEndWith(const Common::String &String, const std::string &OtherString) {
|
||||||
{
|
|
||||||
Common::String::size_type StringPos = String.rfind(OtherString);
|
Common::String::size_type StringPos = String.rfind(OtherString);
|
||||||
if (StringPos == Common::String::npos) return false;
|
if (StringPos == Common::String::npos) return false;
|
||||||
|
|
||||||
|
@ -360,24 +332,20 @@ static bool DoesStringEndWith(const Common::String & String, const std::string &
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
BS_Resource *BS_OpenGLGfx::LoadResource(const Common::String &FileName) {
|
||||||
{
|
|
||||||
BS_ASSERT(CanLoadResource(FileName));
|
BS_ASSERT(CanLoadResource(FileName));
|
||||||
|
|
||||||
// Bild für den Softwarebuffer laden
|
// Bild für den Softwarebuffer laden
|
||||||
if (DoesStringEndWith(FileName, PNG_S_EXTENSION))
|
if (DoesStringEndWith(FileName, PNG_S_EXTENSION)) {
|
||||||
{
|
|
||||||
bool Result;
|
bool Result;
|
||||||
BS_SWImage * pImage = new BS_SWImage(FileName, Result);
|
BS_SWImage *pImage = new BS_SWImage(FileName, Result);
|
||||||
if (!Result)
|
if (!Result) {
|
||||||
{
|
|
||||||
delete pImage;
|
delete pImage;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_BitmapResource * pResource = new BS_BitmapResource(FileName, pImage);
|
BS_BitmapResource *pResource = new BS_BitmapResource(FileName, pImage);
|
||||||
if (!pResource->IsValid())
|
if (!pResource->IsValid()) {
|
||||||
{
|
|
||||||
delete pResource;
|
delete pResource;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -386,19 +354,16 @@ BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sprite-Bild laden
|
// Sprite-Bild laden
|
||||||
if (DoesStringEndWith(FileName, PNG_EXTENSION) || DoesStringEndWith(FileName, B25S_EXTENSION))
|
if (DoesStringEndWith(FileName, PNG_EXTENSION) || DoesStringEndWith(FileName, B25S_EXTENSION)) {
|
||||||
{
|
|
||||||
bool Result;
|
bool Result;
|
||||||
BS_GLImage * pImage = new BS_GLImage(FileName, Result);
|
BS_GLImage *pImage = new BS_GLImage(FileName, Result);
|
||||||
if (!Result)
|
if (!Result) {
|
||||||
{
|
|
||||||
delete pImage;
|
delete pImage;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_BitmapResource * pResource = new BS_BitmapResource(FileName, pImage);
|
BS_BitmapResource *pResource = new BS_BitmapResource(FileName, pImage);
|
||||||
if (!pResource->IsValid())
|
if (!pResource->IsValid()) {
|
||||||
{
|
|
||||||
delete pResource;
|
delete pResource;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -408,33 +373,29 @@ BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
||||||
|
|
||||||
|
|
||||||
// Vectorgraphik laden
|
// Vectorgraphik laden
|
||||||
if (DoesStringEndWith(FileName, SWF_EXTENSION))
|
if (DoesStringEndWith(FileName, SWF_EXTENSION)) {
|
||||||
{
|
|
||||||
// Pointer auf Package-Manager holen
|
// Pointer auf Package-Manager holen
|
||||||
BS_PackageManager * pPackage = BS_Kernel::GetInstance()->GetPackage();
|
BS_PackageManager *pPackage = BS_Kernel::GetInstance()->GetPackage();
|
||||||
BS_ASSERT(pPackage);
|
BS_ASSERT(pPackage);
|
||||||
|
|
||||||
// Datei laden
|
// Datei laden
|
||||||
unsigned char* pFileData;
|
unsigned char *pFileData;
|
||||||
unsigned int FileSize;
|
unsigned int FileSize;
|
||||||
if (!(pFileData = static_cast<unsigned char*>(pPackage->GetFile(FileName, &FileSize))))
|
if (!(pFileData = static_cast<unsigned char *>(pPackage->GetFile(FileName, &FileSize)))) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("File \"%s\" could not be loaded.", FileName.c_str());
|
BS_LOG_ERRORLN("File \"%s\" could not be loaded.", FileName.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Result;
|
bool Result;
|
||||||
BS_VectorImage * pImage = new BS_VectorImage(pFileData, FileSize, Result);
|
BS_VectorImage *pImage = new BS_VectorImage(pFileData, FileSize, Result);
|
||||||
if (!Result)
|
if (!Result) {
|
||||||
{
|
|
||||||
delete pImage;
|
delete pImage;
|
||||||
delete [] pFileData;
|
delete [] pFileData;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_BitmapResource * pResource = new BS_BitmapResource(FileName, pImage);
|
BS_BitmapResource *pResource = new BS_BitmapResource(FileName, pImage);
|
||||||
if (!pResource->IsValid())
|
if (!pResource->IsValid()) {
|
||||||
{
|
|
||||||
delete pResource;
|
delete pResource;
|
||||||
delete [] pFileData;
|
delete [] pFileData;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -445,26 +406,22 @@ BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animation laden
|
// Animation laden
|
||||||
if (DoesStringEndWith(FileName, ANI_EXTENSION))
|
if (DoesStringEndWith(FileName, ANI_EXTENSION)) {
|
||||||
{
|
BS_AnimationResource *pResource = new BS_AnimationResource(FileName);
|
||||||
BS_AnimationResource * pResource = new BS_AnimationResource(FileName);
|
|
||||||
if (pResource->IsValid())
|
if (pResource->IsValid())
|
||||||
return pResource;
|
return pResource;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
delete pResource;
|
delete pResource;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Font laden
|
// Font laden
|
||||||
if (DoesStringEndWith(FileName, FNT_EXTENSION))
|
if (DoesStringEndWith(FileName, FNT_EXTENSION)) {
|
||||||
{
|
BS_FontResource *pResource = new BS_FontResource(BS_Kernel::GetInstance(), FileName);
|
||||||
BS_FontResource * pResource = new BS_FontResource(BS_Kernel::GetInstance(), FileName);
|
|
||||||
if (pResource->IsValid())
|
if (pResource->IsValid())
|
||||||
return pResource;
|
return pResource;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
delete pResource;
|
delete pResource;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -476,8 +433,7 @@ BS_Resource * BS_OpenGLGfx::LoadResource(const Common::String& FileName)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::CanLoadResource(const Common::String& FileName)
|
bool BS_OpenGLGfx::CanLoadResource(const Common::String &FileName) {
|
||||||
{
|
|
||||||
return DoesStringEndWith(FileName, PNG_EXTENSION) ||
|
return DoesStringEndWith(FileName, PNG_EXTENSION) ||
|
||||||
DoesStringEndWith(FileName, ANI_EXTENSION) ||
|
DoesStringEndWith(FileName, ANI_EXTENSION) ||
|
||||||
DoesStringEndWith(FileName, FNT_EXTENSION) ||
|
DoesStringEndWith(FileName, FNT_EXTENSION) ||
|
||||||
|
@ -490,8 +446,7 @@ bool BS_OpenGLGfx::CanLoadResource(const Common::String& FileName)
|
||||||
// DEBUGGING
|
// DEBUGGING
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_OpenGLGfx::DrawDebugLine(const BS_Vertex & Start, const BS_Vertex & End, unsigned int Color)
|
void BS_OpenGLGfx::DrawDebugLine(const BS_Vertex &Start, const BS_Vertex &End, unsigned int Color) {
|
||||||
{
|
|
||||||
m_DebugLines.push_back(DebugLine(Start, End, Color));
|
m_DebugLines.push_back(DebugLine(Start, End, Color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,8 +454,7 @@ void BS_OpenGLGfx::DrawDebugLine(const BS_Vertex & Start, const BS_Vertex & End,
|
||||||
// PERSISTENZ
|
// PERSISTENZ
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_OpenGLGfx::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
result &= BS_GraphicEngine::Persist(Writer);
|
result &= BS_GraphicEngine::Persist(Writer);
|
||||||
|
@ -511,8 +465,7 @@ bool BS_OpenGLGfx::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_OpenGLGfx::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_OpenGLGfx::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
|
|
||||||
result &= BS_GraphicEngine::Unpersist(Reader);
|
result &= BS_GraphicEngine::Unpersist(Reader);
|
||||||
|
|
|
@ -67,10 +67,9 @@ class BS_RenderObjectManager;
|
||||||
// CLASS DECLARATION
|
// CLASS DECLARATION
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_OpenGLGfx : public BS_GraphicEngine
|
class BS_OpenGLGfx : public BS_GraphicEngine {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BS_OpenGLGfx(BS_Kernel* pKernel);
|
BS_OpenGLGfx(BS_Kernel *pKernel);
|
||||||
virtual ~BS_OpenGLGfx();
|
virtual ~BS_OpenGLGfx();
|
||||||
|
|
||||||
// Interface
|
// Interface
|
||||||
|
@ -84,23 +83,23 @@ public:
|
||||||
virtual void SetVsync(bool Vsync);
|
virtual void SetVsync(bool Vsync);
|
||||||
virtual bool GetVsync() const;
|
virtual bool GetVsync() const;
|
||||||
|
|
||||||
virtual bool Fill(const BS_Rect* FillRectPtr = 0, unsigned int Color = BS_RGB(0, 0, 0));
|
virtual bool Fill(const BS_Rect *FillRectPtr = 0, unsigned int Color = BS_RGB(0, 0, 0));
|
||||||
virtual bool GetScreenshot(unsigned int & Width, unsigned int & Height, Common::Array<unsigned int> & Data);
|
virtual bool GetScreenshot(unsigned int &Width, unsigned int &Height, Common::Array<unsigned int> & Data);
|
||||||
|
|
||||||
// Resource-Managing Methoden
|
// Resource-Managing Methoden
|
||||||
// --------------------------
|
// --------------------------
|
||||||
virtual BS_Resource* LoadResource(const Common::String& FileName);
|
virtual BS_Resource *LoadResource(const Common::String &FileName);
|
||||||
virtual bool CanLoadResource(const Common::String& FileName);
|
virtual bool CanLoadResource(const Common::String &FileName);
|
||||||
|
|
||||||
// Debugging Methoden
|
// Debugging Methoden
|
||||||
// ------------------
|
// ------------------
|
||||||
virtual void DrawDebugLine(const BS_Vertex & Start, const BS_Vertex & End, unsigned int Color);
|
virtual void DrawDebugLine(const BS_Vertex &Start, const BS_Vertex &End, unsigned int Color);
|
||||||
static const char * GetGLSResultString(GLS_Result Result);
|
static const char *GetGLSResultString(GLS_Result Result);
|
||||||
|
|
||||||
// Persistenz Methoden
|
// Persistenz Methoden
|
||||||
// -------------------
|
// -------------------
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_GLspritesInitialized;
|
bool m_GLspritesInitialized;
|
||||||
|
@ -109,9 +108,8 @@ private:
|
||||||
|
|
||||||
std::auto_ptr<BS_RenderObjectManager> m_RenderObjectManagerPtr;
|
std::auto_ptr<BS_RenderObjectManager> m_RenderObjectManagerPtr;
|
||||||
|
|
||||||
struct DebugLine
|
struct DebugLine {
|
||||||
{
|
DebugLine(const BS_Vertex &_Start, const BS_Vertex &_End, unsigned int _Color) :
|
||||||
DebugLine(const BS_Vertex & _Start, const BS_Vertex & _End, unsigned int _Color) :
|
|
||||||
Start(_Start),
|
Start(_Start),
|
||||||
End(_End),
|
End(_End),
|
||||||
Color(_Color) {};
|
Color(_Color) {};
|
||||||
|
|
|
@ -50,21 +50,19 @@ namespace Sword25 {
|
||||||
// CONSTRUCTION / DESTRUCTION
|
// CONSTRUCTION / DESTRUCTION
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_SWImage::BS_SWImage(const Common::String & Filename, bool & Result) :
|
BS_SWImage::BS_SWImage(const Common::String &Filename, bool &Result) :
|
||||||
_ImageDataPtr(0),
|
_ImageDataPtr(0),
|
||||||
m_Width(0),
|
m_Width(0),
|
||||||
m_Height(0)
|
m_Height(0) {
|
||||||
{
|
|
||||||
Result = false;
|
Result = false;
|
||||||
|
|
||||||
BS_PackageManager * pPackage = static_cast<BS_PackageManager*>(BS_Kernel::GetInstance()->GetService("package"));
|
BS_PackageManager *pPackage = static_cast<BS_PackageManager *>(BS_Kernel::GetInstance()->GetService("package"));
|
||||||
BS_ASSERT(pPackage);
|
BS_ASSERT(pPackage);
|
||||||
|
|
||||||
// Datei laden
|
// Datei laden
|
||||||
char* pFileData;
|
char *pFileData;
|
||||||
unsigned int FileSize;
|
unsigned int FileSize;
|
||||||
if (!(pFileData = (char*) pPackage->GetFile(Filename, &FileSize)))
|
if (!(pFileData = (char *) pPackage->GetFile(Filename, &FileSize))) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("File \"%s\" could not be loaded.", Filename.c_str());
|
BS_LOG_ERRORLN("File \"%s\" could not be loaded.", Filename.c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -72,16 +70,14 @@ BS_SWImage::BS_SWImage(const Common::String & Filename, bool & Result) :
|
||||||
// Bildeigenschaften bestimmen
|
// Bildeigenschaften bestimmen
|
||||||
BS_GraphicEngine::COLOR_FORMATS ColorFormat;
|
BS_GraphicEngine::COLOR_FORMATS ColorFormat;
|
||||||
int Pitch;
|
int Pitch;
|
||||||
if (!BS_ImageLoader::ExtractImageProperties(pFileData, FileSize, ColorFormat, m_Width, m_Height))
|
if (!BS_ImageLoader::ExtractImageProperties(pFileData, FileSize, ColorFormat, m_Width, m_Height)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not read image properties.");
|
BS_LOG_ERRORLN("Could not read image properties.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Das Bild dekomprimieren
|
// Das Bild dekomprimieren
|
||||||
char * pUncompressedData;
|
char *pUncompressedData;
|
||||||
if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch))
|
if (!BS_ImageLoader::LoadImage(pFileData, FileSize, BS_GraphicEngine::CF_ABGR32, pUncompressedData, m_Width, m_Height, Pitch)) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not decode image.");
|
BS_LOG_ERRORLN("Could not decode image.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -97,8 +93,7 @@ BS_SWImage::BS_SWImage(const Common::String & Filename, bool & Result) :
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_SWImage::~BS_SWImage()
|
BS_SWImage::~BS_SWImage() {
|
||||||
{
|
|
||||||
delete [] _ImageDataPtr;
|
delete [] _ImageDataPtr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,34 +102,30 @@ BS_SWImage::~BS_SWImage()
|
||||||
|
|
||||||
bool BS_SWImage::Blit(int PosX, int PosY,
|
bool BS_SWImage::Blit(int PosX, int PosY,
|
||||||
int Flipping,
|
int Flipping,
|
||||||
BS_Rect* pPartRect,
|
BS_Rect *pPartRect,
|
||||||
unsigned int Color,
|
unsigned int Color,
|
||||||
int Width, int Height)
|
int Width, int Height) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Blit() is not supported.");
|
BS_LOG_ERRORLN("Blit() is not supported.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_SWImage::Fill(const BS_Rect* pFillRect, unsigned int Color)
|
bool BS_SWImage::Fill(const BS_Rect *pFillRect, unsigned int Color) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Fill() is not supported.");
|
BS_LOG_ERRORLN("Fill() is not supported.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_SWImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
bool BS_SWImage::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("SetContent() is not supported.");
|
BS_LOG_ERRORLN("SetContent() is not supported.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_SWImage::GetPixel(int X, int Y)
|
unsigned int BS_SWImage::GetPixel(int X, int Y) {
|
||||||
{
|
|
||||||
BS_ASSERT(X >= 0 && X < m_Width);
|
BS_ASSERT(X >= 0 && X < m_Width);
|
||||||
BS_ASSERT(Y >= 0 && Y < m_Height);
|
BS_ASSERT(Y >= 0 && Y < m_Height);
|
||||||
|
|
||||||
|
|
|
@ -50,34 +50,53 @@ namespace Sword25 {
|
||||||
// CLASS DEFINITION
|
// CLASS DEFINITION
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_SWImage : public BS_Image
|
class BS_SWImage : public BS_Image {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BS_SWImage(const Common::String & Filename, bool & Result);
|
BS_SWImage(const Common::String &Filename, bool &Result);
|
||||||
virtual ~BS_SWImage();
|
virtual ~BS_SWImage();
|
||||||
|
|
||||||
virtual int GetWidth() const { return m_Width; }
|
virtual int GetWidth() const {
|
||||||
virtual int GetHeight() const { return m_Height; }
|
return m_Width;
|
||||||
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const { return BS_GraphicEngine::CF_ARGB32; }
|
}
|
||||||
|
virtual int GetHeight() const {
|
||||||
|
return m_Height;
|
||||||
|
}
|
||||||
|
virtual BS_GraphicEngine::COLOR_FORMATS GetColorFormat() const {
|
||||||
|
return BS_GraphicEngine::CF_ARGB32;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Blit(int PosX = 0, int PosY = 0,
|
virtual bool Blit(int PosX = 0, int PosY = 0,
|
||||||
int Flipping = BS_Image::FLIP_NONE,
|
int Flipping = BS_Image::FLIP_NONE,
|
||||||
BS_Rect* pPartRect = NULL,
|
BS_Rect *pPartRect = NULL,
|
||||||
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
unsigned int Color = BS_ARGB(255, 255, 255, 255),
|
||||||
int Width = -1, int Height = -1);
|
int Width = -1, int Height = -1);
|
||||||
virtual bool Fill(const BS_Rect* FillRectPtr, unsigned int Color);
|
virtual bool Fill(const BS_Rect *FillRectPtr, unsigned int Color);
|
||||||
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
virtual bool SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride);
|
||||||
virtual unsigned int GetPixel(int X, int Y);
|
virtual unsigned int GetPixel(int X, int Y);
|
||||||
|
|
||||||
virtual bool IsBlitSource() const { return false; }
|
virtual bool IsBlitSource() const {
|
||||||
virtual bool IsBlitTarget() const { return false; }
|
return false;
|
||||||
virtual bool IsScalingAllowed() const { return false; }
|
}
|
||||||
virtual bool IsFillingAllowed() const { return false; }
|
virtual bool IsBlitTarget() const {
|
||||||
virtual bool IsAlphaAllowed() const { return false; }
|
return false;
|
||||||
virtual bool IsColorModulationAllowed() const { return false; }
|
}
|
||||||
virtual bool IsSetContentAllowed() const { return false; }
|
virtual bool IsScalingAllowed() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool IsFillingAllowed() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool IsAlphaAllowed() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool IsColorModulationAllowed() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool IsSetContentAllowed() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
unsigned int * _ImageDataPtr;
|
unsigned int *_ImageDataPtr;
|
||||||
|
|
||||||
int m_Width;
|
int m_Width;
|
||||||
int m_Height;
|
int m_Height;
|
||||||
|
|
|
@ -55,21 +55,18 @@ namespace Sword25 {
|
||||||
|
|
||||||
BS_Panel::BS_Panel(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, int Width, int Height, unsigned int Color) :
|
BS_Panel::BS_Panel(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, int Width, int Height, unsigned int Color) :
|
||||||
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_PANEL),
|
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_PANEL),
|
||||||
m_Color(Color)
|
m_Color(Color) {
|
||||||
{
|
|
||||||
m_InitSuccess = false;
|
m_InitSuccess = false;
|
||||||
|
|
||||||
m_Width = Width;
|
m_Width = Width;
|
||||||
m_Height = Height;
|
m_Height = Height;
|
||||||
|
|
||||||
if (m_Width < 0)
|
if (m_Width < 0) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Tried to initialise a panel with an invalid width (%d).", m_Width);
|
BS_LOG_ERRORLN("Tried to initialise a panel with an invalid width (%d).", m_Width);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_Height < 0)
|
if (m_Height < 0) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Tried to initialise a panel with an invalid height (%d).", m_Height);
|
BS_LOG_ERRORLN("Tried to initialise a panel with an invalid height (%d).", m_Height);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -79,28 +76,25 @@ BS_Panel::BS_Panel(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, int Width, int
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Panel::BS_Panel(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
BS_Panel::BS_Panel(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||||
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_PANEL, Handle)
|
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_PANEL, Handle) {
|
||||||
{
|
|
||||||
m_InitSuccess = Unpersist(Reader);
|
m_InitSuccess = Unpersist(Reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Panel::~BS_Panel()
|
BS_Panel::~BS_Panel() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Rendern
|
// Rendern
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Panel::DoRender()
|
bool BS_Panel::DoRender() {
|
||||||
{
|
|
||||||
// Falls der Alphawert 0 ist, ist das Panel komplett durchsichtig und es muss nichts gezeichnet werden.
|
// Falls der Alphawert 0 ist, ist das Panel komplett durchsichtig und es muss nichts gezeichnet werden.
|
||||||
if (m_Color >> 24 == 0) return true;
|
if (m_Color >> 24 == 0) return true;
|
||||||
|
|
||||||
BS_GraphicEngine * GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
BS_GraphicEngine *GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||||
BS_ASSERT(GfxPtr);
|
BS_ASSERT(GfxPtr);
|
||||||
|
|
||||||
return GfxPtr->Fill(&m_BBox, m_Color);
|
return GfxPtr->Fill(&m_BBox, m_Color);
|
||||||
|
@ -110,8 +104,7 @@ bool BS_Panel::DoRender()
|
||||||
// Persistenz
|
// Persistenz
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Panel::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_Panel::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_RenderObject::Persist(Writer);
|
Result &= BS_RenderObject::Persist(Writer);
|
||||||
|
@ -124,8 +117,7 @@ bool BS_Panel::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Panel::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_Panel::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_RenderObject::Unpersist(Reader);
|
Result &= BS_RenderObject::Unpersist(Reader);
|
||||||
|
|
|
@ -48,22 +48,26 @@ namespace Sword25 {
|
||||||
// Class Definition
|
// Class Definition
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_Panel : public BS_RenderObject
|
class BS_Panel : public BS_RenderObject {
|
||||||
{
|
friend class BS_RenderObject;
|
||||||
friend class BS_RenderObject;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BS_Panel(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, int Width, int Height, unsigned int Color);
|
BS_Panel(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, int Width, int Height, unsigned int Color);
|
||||||
BS_Panel(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
BS_Panel(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~BS_Panel();
|
virtual ~BS_Panel();
|
||||||
|
|
||||||
unsigned int GetColor() const { return m_Color; }
|
unsigned int GetColor() const {
|
||||||
void SetColor(unsigned int Color) { m_Color = Color; ForceRefresh(); }
|
return m_Color;
|
||||||
|
}
|
||||||
|
void SetColor(unsigned int Color) {
|
||||||
|
m_Color = Color;
|
||||||
|
ForceRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool DoRender();
|
virtual bool DoRender();
|
||||||
|
|
|
@ -70,8 +70,7 @@ BS_RenderObject::BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject> ParentPtr,
|
||||||
m_Type(Type),
|
m_Type(Type),
|
||||||
m_InitSuccess(false),
|
m_InitSuccess(false),
|
||||||
m_RefreshForced(true),
|
m_RefreshForced(true),
|
||||||
m_Handle(0)
|
m_Handle(0) {
|
||||||
{
|
|
||||||
// Renderobject registrieren, abhängig vom Handle-Parameter entweder mit beliebigem oder vorgegebenen Handle.
|
// Renderobject registrieren, abhängig vom Handle-Parameter entweder mit beliebigem oder vorgegebenen Handle.
|
||||||
if (Handle == 0)
|
if (Handle == 0)
|
||||||
m_Handle = BS_RenderObjectRegistry::GetInstance().RegisterObject(this);
|
m_Handle = BS_RenderObjectRegistry::GetInstance().RegisterObject(this);
|
||||||
|
@ -83,15 +82,11 @@ BS_RenderObject::BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject> ParentPtr,
|
||||||
|
|
||||||
// Dieses Objekt zu den Kindern der Elternobjektes hinzufügen, falls nicht Wurzel (ParentPtr ungültig) und dem
|
// Dieses Objekt zu den Kindern der Elternobjektes hinzufügen, falls nicht Wurzel (ParentPtr ungültig) und dem
|
||||||
// selben RenderObjektManager zuweisen.
|
// selben RenderObjektManager zuweisen.
|
||||||
if (m_ParentPtr.IsValid())
|
if (m_ParentPtr.IsValid()) {
|
||||||
{
|
|
||||||
m_ManagerPtr = m_ParentPtr->GetManager();
|
m_ManagerPtr = m_ParentPtr->GetManager();
|
||||||
m_ParentPtr->AddObject(this);
|
m_ParentPtr->AddObject(this);
|
||||||
}
|
} else {
|
||||||
else
|
if (GetType() != TYPE_ROOT) {
|
||||||
{
|
|
||||||
if (GetType() != TYPE_ROOT)
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Tried to create a non-root render object and has no parent. All non-root render objects have to have a parent.");
|
BS_LOG_ERRORLN("Tried to create a non-root render object and has no parent. All non-root render objects have to have a parent.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -102,8 +97,7 @@ BS_RenderObject::BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject> ParentPtr,
|
||||||
m_InitSuccess = true;
|
m_InitSuccess = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_RenderObject::~BS_RenderObject()
|
BS_RenderObject::~BS_RenderObject() {
|
||||||
{
|
|
||||||
// Objekt aus dem Elternobjekt entfernen.
|
// Objekt aus dem Elternobjekt entfernen.
|
||||||
if (m_ParentPtr.IsValid()) m_ParentPtr->DetatchChildren(this);
|
if (m_ParentPtr.IsValid()) m_ParentPtr->DetatchChildren(this);
|
||||||
|
|
||||||
|
@ -115,8 +109,7 @@ BS_RenderObject::~BS_RenderObject()
|
||||||
|
|
||||||
// Rendern
|
// Rendern
|
||||||
// -------
|
// -------
|
||||||
bool BS_RenderObject::Render()
|
bool BS_RenderObject::Render() {
|
||||||
{
|
|
||||||
// Objektänderungen validieren
|
// Objektänderungen validieren
|
||||||
ValidateObject();
|
ValidateObject();
|
||||||
|
|
||||||
|
@ -124,8 +117,7 @@ bool BS_RenderObject::Render()
|
||||||
if (!m_Visible) return true;
|
if (!m_Visible) return true;
|
||||||
|
|
||||||
// Falls notwendig, wird die Renderreihenfolge der Kinderobjekte aktualisiert.
|
// Falls notwendig, wird die Renderreihenfolge der Kinderobjekte aktualisiert.
|
||||||
if (m_ChildChanged)
|
if (m_ChildChanged) {
|
||||||
{
|
|
||||||
SortRenderObjects();
|
SortRenderObjects();
|
||||||
m_ChildChanged = false;
|
m_ChildChanged = false;
|
||||||
}
|
}
|
||||||
|
@ -144,8 +136,7 @@ bool BS_RenderObject::Render()
|
||||||
// Objektverwaltung
|
// Objektverwaltung
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|
||||||
void BS_RenderObject::ValidateObject()
|
void BS_RenderObject::ValidateObject() {
|
||||||
{
|
|
||||||
// Die Veränderungen in den Objektvariablen aufheben
|
// Die Veränderungen in den Objektvariablen aufheben
|
||||||
m_OldBBox = m_BBox;
|
m_OldBBox = m_BBox;
|
||||||
m_OldVisible = m_Visible;
|
m_OldVisible = m_Visible;
|
||||||
|
@ -155,8 +146,7 @@ void BS_RenderObject::ValidateObject()
|
||||||
m_RefreshForced = false;
|
m_RefreshForced = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BS_RenderObject::UpdateObjectState()
|
bool BS_RenderObject::UpdateObjectState() {
|
||||||
{
|
|
||||||
// Falls sich das Objekt verändert hat, muss der interne Zustand neu berechnet werden und evtl. Update-Regions für den nächsten Frame
|
// Falls sich das Objekt verändert hat, muss der interne Zustand neu berechnet werden und evtl. Update-Regions für den nächsten Frame
|
||||||
// registriert werden.
|
// registriert werden.
|
||||||
if ((CalcBoundingBox() != m_OldBBox) ||
|
if ((CalcBoundingBox() != m_OldBBox) ||
|
||||||
|
@ -164,8 +154,7 @@ bool BS_RenderObject::UpdateObjectState()
|
||||||
(m_X != m_OldX) ||
|
(m_X != m_OldX) ||
|
||||||
(m_Y != m_OldY) ||
|
(m_Y != m_OldY) ||
|
||||||
(m_Z != m_OldZ) ||
|
(m_Z != m_OldZ) ||
|
||||||
m_RefreshForced)
|
m_RefreshForced) {
|
||||||
{
|
|
||||||
// Renderrang des Objektes neu bestimmen, da sich dieser verändert haben könnte
|
// Renderrang des Objektes neu bestimmen, da sich dieser verändert haben könnte
|
||||||
if (m_ParentPtr.IsValid()) m_ParentPtr->SignalChildChange();
|
if (m_ParentPtr.IsValid()) m_ParentPtr->SignalChildChange();
|
||||||
|
|
||||||
|
@ -184,14 +173,12 @@ bool BS_RenderObject::UpdateObjectState()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_RenderObject::UpdateBoxes()
|
void BS_RenderObject::UpdateBoxes() {
|
||||||
{
|
|
||||||
// Bounding-Box aktualisieren
|
// Bounding-Box aktualisieren
|
||||||
m_BBox = CalcBoundingBox();
|
m_BBox = CalcBoundingBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_Rect BS_RenderObject::CalcBoundingBox() const
|
BS_Rect BS_RenderObject::CalcBoundingBox() const {
|
||||||
{
|
|
||||||
// Die Bounding-Box mit der Objektgröße initialisieren.
|
// Die Bounding-Box mit der Objektgröße initialisieren.
|
||||||
BS_Rect BBox(0, 0, m_Width, m_Height);
|
BS_Rect BBox(0, 0, m_Width, m_Height);
|
||||||
|
|
||||||
|
@ -204,22 +191,19 @@ BS_Rect BS_RenderObject::CalcBoundingBox() const
|
||||||
return BBox;
|
return BBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_RenderObject::CalcAbsolutePos(int& X, int& Y) const
|
void BS_RenderObject::CalcAbsolutePos(int &X, int &Y) const {
|
||||||
{
|
|
||||||
X = CalcAbsoluteX();
|
X = CalcAbsoluteX();
|
||||||
Y = CalcAbsoluteY();
|
Y = CalcAbsoluteY();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BS_RenderObject::CalcAbsoluteX() const
|
int BS_RenderObject::CalcAbsoluteX() const {
|
||||||
{
|
|
||||||
if (m_ParentPtr.IsValid())
|
if (m_ParentPtr.IsValid())
|
||||||
return m_ParentPtr->GetAbsoluteX() + m_X;
|
return m_ParentPtr->GetAbsoluteX() + m_X;
|
||||||
else
|
else
|
||||||
return m_X;
|
return m_X;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BS_RenderObject::CalcAbsoluteY() const
|
int BS_RenderObject::CalcAbsoluteY() const {
|
||||||
{
|
|
||||||
if (m_ParentPtr.IsValid())
|
if (m_ParentPtr.IsValid())
|
||||||
return m_ParentPtr->GetAbsoluteY() + m_Y;
|
return m_ParentPtr->GetAbsoluteY() + m_Y;
|
||||||
else
|
else
|
||||||
|
@ -229,21 +213,17 @@ int BS_RenderObject::CalcAbsoluteY() const
|
||||||
// Baumverwaltung
|
// Baumverwaltung
|
||||||
// --------------
|
// --------------
|
||||||
|
|
||||||
void BS_RenderObject::DeleteAllChildren()
|
void BS_RenderObject::DeleteAllChildren() {
|
||||||
{
|
|
||||||
// Es ist nicht notwendig die Liste zu iterieren, da jedes Kind für sich DetatchChildren an diesem Objekt aufruft und sich somit
|
// Es ist nicht notwendig die Liste zu iterieren, da jedes Kind für sich DetatchChildren an diesem Objekt aufruft und sich somit
|
||||||
// selber entfernt. Daher muss immer nur ein beliebiges Element (hier das letzte) gelöscht werden, bis die Liste leer ist.
|
// selber entfernt. Daher muss immer nur ein beliebiges Element (hier das letzte) gelöscht werden, bis die Liste leer ist.
|
||||||
while (!m_Children.empty())
|
while (!m_Children.empty()) {
|
||||||
{
|
|
||||||
BS_RenderObjectPtr<BS_RenderObject> CurPtr = m_Children.back();
|
BS_RenderObjectPtr<BS_RenderObject> CurPtr = m_Children.back();
|
||||||
CurPtr.Erase();
|
CurPtr.Erase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BS_RenderObject::AddObject(BS_RenderObjectPtr<BS_RenderObject> pObject)
|
bool BS_RenderObject::AddObject(BS_RenderObjectPtr<BS_RenderObject> pObject) {
|
||||||
{
|
if (!pObject.IsValid()) {
|
||||||
if (!pObject.IsValid())
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Tried to add a null object to a renderobject.");
|
BS_LOG_ERRORLN("Tried to add a null object to a renderobject.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -257,13 +237,11 @@ bool BS_RenderObject::AddObject(BS_RenderObjectPtr<BS_RenderObject> pObject)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BS_RenderObject::DetatchChildren(BS_RenderObjectPtr<BS_RenderObject> pObject)
|
bool BS_RenderObject::DetatchChildren(BS_RenderObjectPtr<BS_RenderObject> pObject) {
|
||||||
{
|
|
||||||
// Kinderliste durchgehen und Objekt entfernen falls vorhanden
|
// Kinderliste durchgehen und Objekt entfernen falls vorhanden
|
||||||
RENDEROBJECT_ITER it = m_Children.begin();
|
RENDEROBJECT_ITER it = m_Children.begin();
|
||||||
for (; it != m_Children.end(); ++it)
|
for (; it != m_Children.end(); ++it)
|
||||||
if (*it == pObject)
|
if (*it == pObject) {
|
||||||
{
|
|
||||||
m_Children.erase(it);
|
m_Children.erase(it);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -272,13 +250,11 @@ bool BS_RenderObject::DetatchChildren(BS_RenderObjectPtr<BS_RenderObject> pObjec
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_RenderObject::SortRenderObjects()
|
void BS_RenderObject::SortRenderObjects() {
|
||||||
{
|
|
||||||
std::sort(m_Children.begin(), m_Children.end(), Greater);
|
std::sort(m_Children.begin(), m_Children.end(), Greater);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_RenderObject::UpdateAbsolutePos()
|
void BS_RenderObject::UpdateAbsolutePos() {
|
||||||
{
|
|
||||||
CalcAbsolutePos(m_AbsoluteX, m_AbsoluteY);
|
CalcAbsolutePos(m_AbsoluteX, m_AbsoluteY);
|
||||||
|
|
||||||
RENDEROBJECT_ITER it = m_Children.begin();
|
RENDEROBJECT_ITER it = m_Children.begin();
|
||||||
|
@ -289,42 +265,36 @@ void BS_RenderObject::UpdateAbsolutePos()
|
||||||
// Get-Methoden
|
// Get-Methoden
|
||||||
// ------------
|
// ------------
|
||||||
|
|
||||||
bool BS_RenderObject::GetObjectIntersection(BS_RenderObjectPtr<BS_RenderObject> pObject, BS_Rect& Result)
|
bool BS_RenderObject::GetObjectIntersection(BS_RenderObjectPtr<BS_RenderObject> pObject, BS_Rect &Result) {
|
||||||
{
|
|
||||||
return m_BBox.Intersect(pObject->GetBBox(), Result);
|
return m_BBox.Intersect(pObject->GetBBox(), Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set-Methoden
|
// Set-Methoden
|
||||||
// ------------
|
// ------------
|
||||||
void BS_RenderObject::SetPos(int X, int Y)
|
void BS_RenderObject::SetPos(int X, int Y) {
|
||||||
{
|
|
||||||
m_X = X;
|
m_X = X;
|
||||||
m_Y = Y;
|
m_Y = Y;
|
||||||
UpdateAbsolutePos();
|
UpdateAbsolutePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_RenderObject::SetX(int X)
|
void BS_RenderObject::SetX(int X) {
|
||||||
{
|
|
||||||
m_X = X;
|
m_X = X;
|
||||||
UpdateAbsolutePos();
|
UpdateAbsolutePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_RenderObject::SetY(int Y)
|
void BS_RenderObject::SetY(int Y) {
|
||||||
{
|
|
||||||
m_Y = Y;
|
m_Y = Y;
|
||||||
UpdateAbsolutePos();
|
UpdateAbsolutePos();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_RenderObject::SetZ(int Z)
|
void BS_RenderObject::SetZ(int Z) {
|
||||||
{
|
|
||||||
if (Z < 0)
|
if (Z < 0)
|
||||||
BS_LOG_ERRORLN("Tried to set a negative Z value (%d).", Z);
|
BS_LOG_ERRORLN("Tried to set a negative Z value (%d).", Z);
|
||||||
else
|
else
|
||||||
m_Z = Z;
|
m_Z = Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BS_RenderObject::SetVisible(bool Visible)
|
void BS_RenderObject::SetVisible(bool Visible) {
|
||||||
{
|
|
||||||
m_Visible = Visible;
|
m_Visible = Visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,13 +302,11 @@ void BS_RenderObject::SetVisible(bool Visible)
|
||||||
// Objekterzeuger
|
// Objekterzeuger
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const Common::String& Filename)
|
BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const Common::String &Filename) {
|
||||||
{
|
|
||||||
BS_RenderObjectPtr<BS_Animation> AniPtr(new BS_Animation(this, Filename));
|
BS_RenderObjectPtr<BS_Animation> AniPtr(new BS_Animation(this, Filename));
|
||||||
if (AniPtr.IsValid() && AniPtr->GetInitSuccess())
|
if (AniPtr.IsValid() && AniPtr->GetInitSuccess())
|
||||||
return AniPtr;
|
return AniPtr;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if (AniPtr.IsValid()) AniPtr.Erase();
|
if (AniPtr.IsValid()) AniPtr.Erase();
|
||||||
return BS_RenderObjectPtr<BS_Animation>();
|
return BS_RenderObjectPtr<BS_Animation>();
|
||||||
}
|
}
|
||||||
|
@ -347,13 +315,11 @@ BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const Common::Str
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const BS_AnimationTemplate & AnimationTemplate)
|
BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const BS_AnimationTemplate &AnimationTemplate) {
|
||||||
{
|
BS_Animation *AniPtr = new BS_Animation(this, AnimationTemplate);
|
||||||
BS_Animation * AniPtr = new BS_Animation(this, AnimationTemplate);
|
|
||||||
if (AniPtr && AniPtr->GetInitSuccess())
|
if (AniPtr && AniPtr->GetInitSuccess())
|
||||||
return AniPtr;
|
return AniPtr;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
delete AniPtr;
|
delete AniPtr;
|
||||||
return BS_RenderObjectPtr<BS_Animation>();
|
return BS_RenderObjectPtr<BS_Animation>();
|
||||||
}
|
}
|
||||||
|
@ -361,13 +327,11 @@ BS_RenderObjectPtr<BS_Animation> BS_RenderObject::AddAnimation(const BS_Animatio
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddBitmap(const Common::String& Filename)
|
BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddBitmap(const Common::String &Filename) {
|
||||||
{
|
|
||||||
BS_RenderObjectPtr<BS_Bitmap> BitmapPtr(new BS_StaticBitmap(this, Filename));
|
BS_RenderObjectPtr<BS_Bitmap> BitmapPtr(new BS_StaticBitmap(this, Filename));
|
||||||
if (BitmapPtr.IsValid() && BitmapPtr->GetInitSuccess())
|
if (BitmapPtr.IsValid() && BitmapPtr->GetInitSuccess())
|
||||||
return BS_RenderObjectPtr<BS_Bitmap>(BitmapPtr);
|
return BS_RenderObjectPtr<BS_Bitmap>(BitmapPtr);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if (BitmapPtr.IsValid()) BitmapPtr.Erase();
|
if (BitmapPtr.IsValid()) BitmapPtr.Erase();
|
||||||
return BS_RenderObjectPtr<BS_Bitmap>();
|
return BS_RenderObjectPtr<BS_Bitmap>();
|
||||||
}
|
}
|
||||||
|
@ -375,13 +339,11 @@ BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddBitmap(const Common::String& F
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddDynamicBitmap(unsigned int Width, unsigned int Height)
|
BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddDynamicBitmap(unsigned int Width, unsigned int Height) {
|
||||||
{
|
|
||||||
BS_RenderObjectPtr<BS_Bitmap> BitmapPtr(new BS_DynamicBitmap(this, Width, Height));
|
BS_RenderObjectPtr<BS_Bitmap> BitmapPtr(new BS_DynamicBitmap(this, Width, Height));
|
||||||
if (BitmapPtr.IsValid() && BitmapPtr->GetInitSuccess())
|
if (BitmapPtr.IsValid() && BitmapPtr->GetInitSuccess())
|
||||||
return BitmapPtr;
|
return BitmapPtr;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if (BitmapPtr.IsValid()) BitmapPtr.Erase();
|
if (BitmapPtr.IsValid()) BitmapPtr.Erase();
|
||||||
return BS_RenderObjectPtr<BS_Bitmap>();
|
return BS_RenderObjectPtr<BS_Bitmap>();
|
||||||
}
|
}
|
||||||
|
@ -389,13 +351,11 @@ BS_RenderObjectPtr<BS_Bitmap> BS_RenderObject::AddDynamicBitmap(unsigned int Wid
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectPtr<BS_Panel> BS_RenderObject::AddPanel(int Width, int Height, unsigned int Color)
|
BS_RenderObjectPtr<BS_Panel> BS_RenderObject::AddPanel(int Width, int Height, unsigned int Color) {
|
||||||
{
|
|
||||||
BS_RenderObjectPtr<BS_Panel> PanelPtr(new BS_Panel(this, Width, Height, Color));
|
BS_RenderObjectPtr<BS_Panel> PanelPtr(new BS_Panel(this, Width, Height, Color));
|
||||||
if (PanelPtr.IsValid() && PanelPtr->GetInitSuccess())
|
if (PanelPtr.IsValid() && PanelPtr->GetInitSuccess())
|
||||||
return PanelPtr;
|
return PanelPtr;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
if (PanelPtr.IsValid()) PanelPtr.Erase();
|
if (PanelPtr.IsValid()) PanelPtr.Erase();
|
||||||
return BS_RenderObjectPtr<BS_Panel>();
|
return BS_RenderObjectPtr<BS_Panel>();
|
||||||
}
|
}
|
||||||
|
@ -403,16 +363,12 @@ BS_RenderObjectPtr<BS_Panel> BS_RenderObject::AddPanel(int Width, int Height, un
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectPtr<BS_Text> BS_RenderObject::AddText(const Common::String & Font, const std::string & Text)
|
BS_RenderObjectPtr<BS_Text> BS_RenderObject::AddText(const Common::String &Font, const std::string &Text) {
|
||||||
{
|
|
||||||
BS_RenderObjectPtr<BS_Text> TextPtr(new BS_Text(this));
|
BS_RenderObjectPtr<BS_Text> TextPtr(new BS_Text(this));
|
||||||
if (TextPtr.IsValid() && TextPtr->GetInitSuccess() && TextPtr->SetFont(Font))
|
if (TextPtr.IsValid() && TextPtr->GetInitSuccess() && TextPtr->SetFont(Font)) {
|
||||||
{
|
|
||||||
TextPtr->SetText(Text);
|
TextPtr->SetText(Text);
|
||||||
return TextPtr;
|
return TextPtr;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (TextPtr.IsValid()) TextPtr.Erase();
|
if (TextPtr.IsValid()) TextPtr.Erase();
|
||||||
return BS_RenderObjectPtr<BS_Text>();
|
return BS_RenderObjectPtr<BS_Text>();
|
||||||
}
|
}
|
||||||
|
@ -421,8 +377,7 @@ BS_RenderObjectPtr<BS_Text> BS_RenderObject::AddText(const Common::String & Font
|
||||||
// Persistenz-Methoden
|
// Persistenz-Methoden
|
||||||
// -------------------
|
// -------------------
|
||||||
|
|
||||||
bool BS_RenderObject::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_RenderObject::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
// Typ und Handle werden als erstes gespeichert, damit beim Laden ein Objekt vom richtigen Typ mit dem richtigen Handle erzeugt werden kann.
|
// Typ und Handle werden als erstes gespeichert, damit beim Laden ein Objekt vom richtigen Typ mit dem richtigen Handle erzeugt werden kann.
|
||||||
Writer.Write(static_cast<unsigned int>(m_Type));
|
Writer.Write(static_cast<unsigned int>(m_Type));
|
||||||
Writer.Write(m_Handle);
|
Writer.Write(m_Handle);
|
||||||
|
@ -458,8 +413,7 @@ bool BS_RenderObject::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_RenderObject::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_RenderObject::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
// Typ und Handle wurden schon von RecreatePersistedRenderObject() ausgelesen. Jetzt werden die restlichen Objekteigenschaften ausgelesen.
|
// Typ und Handle wurden schon von RecreatePersistedRenderObject() ausgelesen. Jetzt werden die restlichen Objekteigenschaften ausgelesen.
|
||||||
Reader.Read(m_X);
|
Reader.Read(m_X);
|
||||||
Reader.Read(m_Y);
|
Reader.Read(m_Y);
|
||||||
|
@ -496,8 +450,7 @@ bool BS_RenderObject::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_RenderObject::PersistChildren(BS_OutputPersistenceBlock & Writer)
|
bool BS_RenderObject::PersistChildren(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
// Kinderanzahl speichern.
|
// Kinderanzahl speichern.
|
||||||
|
@ -505,8 +458,7 @@ bool BS_RenderObject::PersistChildren(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// Rekursiv alle Kinder speichern.
|
// Rekursiv alle Kinder speichern.
|
||||||
RENDEROBJECT_LIST::iterator It = m_Children.begin();
|
RENDEROBJECT_LIST::iterator It = m_Children.begin();
|
||||||
while (It != m_Children.end())
|
while (It != m_Children.end()) {
|
||||||
{
|
|
||||||
Result &= (*It)->Persist(Writer);
|
Result &= (*It)->Persist(Writer);
|
||||||
++It;
|
++It;
|
||||||
}
|
}
|
||||||
|
@ -516,8 +468,7 @@ bool BS_RenderObject::PersistChildren(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_RenderObject::UnpersistChildren(BS_InputPersistenceBlock & Reader)
|
bool BS_RenderObject::UnpersistChildren(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
// Kinderanzahl einlesen.
|
// Kinderanzahl einlesen.
|
||||||
|
@ -526,8 +477,7 @@ bool BS_RenderObject::UnpersistChildren(BS_InputPersistenceBlock & Reader)
|
||||||
if (!Reader.IsGood()) return false;
|
if (!Reader.IsGood()) return false;
|
||||||
|
|
||||||
// Alle Kinder rekursiv wieder herstellen.
|
// Alle Kinder rekursiv wieder herstellen.
|
||||||
for (unsigned int i = 0; i < ChildrenCount; ++i)
|
for (unsigned int i = 0; i < ChildrenCount; ++i) {
|
||||||
{
|
|
||||||
if (!RecreatePersistedRenderObject(Reader).IsValid()) return false;
|
if (!RecreatePersistedRenderObject(Reader).IsValid()) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,8 +486,7 @@ bool BS_RenderObject::UnpersistChildren(BS_InputPersistenceBlock & Reader)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectPtr<BS_RenderObject> BS_RenderObject::RecreatePersistedRenderObject(BS_InputPersistenceBlock & Reader)
|
BS_RenderObjectPtr<BS_RenderObject> BS_RenderObject::RecreatePersistedRenderObject(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
BS_RenderObjectPtr<BS_RenderObject> Result;
|
BS_RenderObjectPtr<BS_RenderObject> Result;
|
||||||
|
|
||||||
// Typ und Handle auslesen.
|
// Typ und Handle auslesen.
|
||||||
|
@ -547,8 +496,7 @@ BS_RenderObjectPtr<BS_RenderObject> BS_RenderObject::RecreatePersistedRenderObje
|
||||||
Reader.Read(Handle);
|
Reader.Read(Handle);
|
||||||
if (!Reader.IsGood()) return Result;
|
if (!Reader.IsGood()) return Result;
|
||||||
|
|
||||||
switch (Type)
|
switch (Type) {
|
||||||
{
|
|
||||||
case TYPE_PANEL:
|
case TYPE_PANEL:
|
||||||
Result = new BS_Panel(Reader, this, Handle);
|
Result = new BS_Panel(Reader, this, Handle);
|
||||||
break;
|
break;
|
||||||
|
@ -578,8 +526,7 @@ BS_RenderObjectPtr<BS_RenderObject> BS_RenderObject::RecreatePersistedRenderObje
|
||||||
|
|
||||||
// Hilfs-Methoden
|
// Hilfs-Methoden
|
||||||
// --------------
|
// --------------
|
||||||
bool BS_RenderObject::Greater(const BS_RenderObjectPtr<BS_RenderObject> lhs, const BS_RenderObjectPtr<BS_RenderObject> rhs)
|
bool BS_RenderObject::Greater(const BS_RenderObjectPtr<BS_RenderObject> lhs, const BS_RenderObjectPtr<BS_RenderObject> rhs) {
|
||||||
{
|
|
||||||
// Das Objekt mit dem kleinem Z-Wert müssen zuerst gerendert werden.
|
// Das Objekt mit dem kleinem Z-Wert müssen zuerst gerendert werden.
|
||||||
if (lhs->m_Z != rhs->m_Z)
|
if (lhs->m_Z != rhs->m_Z)
|
||||||
return lhs->m_Z < rhs->m_Z;
|
return lhs->m_Z < rhs->m_Z;
|
||||||
|
|
|
@ -75,13 +75,11 @@ class BS_Text;
|
||||||
Diese Klasse erledigt Aufgaben wie: minimales Neuzeichnen, Renderreihenfolge, Objekthierachie.
|
Diese Klasse erledigt Aufgaben wie: minimales Neuzeichnen, Renderreihenfolge, Objekthierachie.
|
||||||
Alle BS_RenderObject Instanzen werden von einem BS_RenderObjektManager in einem Baum verwaltet.
|
Alle BS_RenderObject Instanzen werden von einem BS_RenderObjektManager in einem Baum verwaltet.
|
||||||
*/
|
*/
|
||||||
class BS_RenderObject
|
class BS_RenderObject {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
// Konstanten
|
// Konstanten
|
||||||
// ----------
|
// ----------
|
||||||
enum TYPES
|
enum TYPES {
|
||||||
{
|
|
||||||
/// Das Wurzelobjekt. Siehe BS_RenderObjectManager
|
/// Das Wurzelobjekt. Siehe BS_RenderObjectManager
|
||||||
TYPE_ROOT,
|
TYPE_ROOT,
|
||||||
/// Ein Image. Siehe BS_Bitmap.
|
/// Ein Image. Siehe BS_Bitmap.
|
||||||
|
@ -158,36 +156,36 @@ public:
|
||||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||||
*/
|
*/
|
||||||
BS_RenderObjectPtr<BS_Bitmap> ToBitmap()
|
BS_RenderObjectPtr<BS_Bitmap> ToBitmap() {
|
||||||
{
|
if (m_Type == TYPE_STATICBITMAP || m_Type == TYPE_DYNAMICBITMAP) return BS_RenderObjectPtr<BS_Bitmap>(this);
|
||||||
if (m_Type == TYPE_STATICBITMAP || m_Type == TYPE_DYNAMICBITMAP) return BS_RenderObjectPtr<BS_Bitmap>(this); else return BS_RenderObjectPtr<BS_Bitmap>();
|
else return BS_RenderObjectPtr<BS_Bitmap>();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@brief Castet das Objekt zu einem BS_Animation-Objekt wenn zulässig.
|
@brief Castet das Objekt zu einem BS_Animation-Objekt wenn zulässig.
|
||||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||||
*/
|
*/
|
||||||
BS_RenderObjectPtr<BS_Animation> ToAnimation()
|
BS_RenderObjectPtr<BS_Animation> ToAnimation() {
|
||||||
{
|
if (m_Type == TYPE_ANIMATION) return BS_RenderObjectPtr<BS_Animation>(this);
|
||||||
if (m_Type == TYPE_ANIMATION) return BS_RenderObjectPtr<BS_Animation>(this); else return BS_RenderObjectPtr<BS_Animation>();
|
else return BS_RenderObjectPtr<BS_Animation>();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@brief Castet das Objekt zu einem BS_Panel-Objekt wenn zulässig.
|
@brief Castet das Objekt zu einem BS_Panel-Objekt wenn zulässig.
|
||||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||||
*/
|
*/
|
||||||
BS_RenderObjectPtr<BS_Panel> ToPanel()
|
BS_RenderObjectPtr<BS_Panel> ToPanel() {
|
||||||
{
|
if (m_Type == TYPE_PANEL) return BS_RenderObjectPtr<BS_Panel>(this);
|
||||||
if (m_Type == TYPE_PANEL) return BS_RenderObjectPtr<BS_Panel>(this); else return BS_RenderObjectPtr<BS_Panel>();
|
else return BS_RenderObjectPtr<BS_Panel>();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@brief Castet das Object zu einem BS_Text-Objekt wenn zulässig.
|
@brief Castet das Object zu einem BS_Text-Objekt wenn zulässig.
|
||||||
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
@return Gibt einen BS_RenderObjectPtr auf das Objekt zurück.<br>
|
||||||
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
Falls der Cast nicht zulässig ist, wird ein ungültiger BS_RenderObjectPtr zurückgegeben.
|
||||||
*/
|
*/
|
||||||
BS_RenderObjectPtr<BS_Text> ToText()
|
BS_RenderObjectPtr<BS_Text> ToText() {
|
||||||
{
|
if (m_Type == TYPE_TEXT) return BS_RenderObjectPtr<BS_Text>(this);
|
||||||
if (m_Type == TYPE_TEXT) return BS_RenderObjectPtr<BS_Text>(this); else return BS_RenderObjectPtr<BS_Text>();
|
else return BS_RenderObjectPtr<BS_Text>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Konstruktor / Desktruktor
|
// Konstruktor / Desktruktor
|
||||||
|
@ -270,19 +268,27 @@ public:
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Position des Objektes auf der X-Achse relativ zum Elternobjekt zurück.
|
@brief Gibt die Position des Objektes auf der X-Achse relativ zum Elternobjekt zurück.
|
||||||
*/
|
*/
|
||||||
virtual int GetX() const { return m_X; }
|
virtual int GetX() const {
|
||||||
|
return m_X;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Position des Objektes auf der Y-Achse relativ zum Elternobjekt zurück.
|
@brief Gibt die Position des Objektes auf der Y-Achse relativ zum Elternobjekt zurück.
|
||||||
*/
|
*/
|
||||||
virtual int GetY() const { return m_Y; }
|
virtual int GetY() const {
|
||||||
|
return m_Y;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt die absolute Position des Objektes auf der X-Achse zurück.
|
@brief Gibt die absolute Position des Objektes auf der X-Achse zurück.
|
||||||
*/
|
*/
|
||||||
virtual int GetAbsoluteX() const { return m_AbsoluteX; }
|
virtual int GetAbsoluteX() const {
|
||||||
|
return m_AbsoluteX;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt die absolute Position des Objektes auf der Y-Achse zurück.
|
@brief Gibt die absolute Position des Objektes auf der Y-Achse zurück.
|
||||||
*/
|
*/
|
||||||
virtual int GetAbsoluteY() const { return m_AbsoluteY; }
|
virtual int GetAbsoluteY() const {
|
||||||
|
return m_AbsoluteY;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt den Z-Wert des Objektes relativ zum Elternobjekt zurück.
|
@brief Gibt den Z-Wert des Objektes relativ zum Elternobjekt zurück.
|
||||||
@remark Der Z-Wert legt die Renderreihenfolge der Objekte fest. Objekte mit niedrigem Z-Wert werden vor Objekten mit höherem
|
@remark Der Z-Wert legt die Renderreihenfolge der Objekte fest. Objekte mit niedrigem Z-Wert werden vor Objekten mit höherem
|
||||||
|
@ -290,43 +296,61 @@ public:
|
||||||
Wie alle andere Attribute ist auch dieses relativ zum Elternobjekt, ein Kinderobjekt kann also nie unter seinem
|
Wie alle andere Attribute ist auch dieses relativ zum Elternobjekt, ein Kinderobjekt kann also nie unter seinem
|
||||||
Elternobjekt liegen, auch wenn es einen Z-Wert von 0 hat.
|
Elternobjekt liegen, auch wenn es einen Z-Wert von 0 hat.
|
||||||
*/
|
*/
|
||||||
int GetZ() const { return m_Z; }
|
int GetZ() const {
|
||||||
|
return m_Z;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Breite des Objektes zurück.
|
@brief Gibt die Breite des Objektes zurück.
|
||||||
*/
|
*/
|
||||||
int GetWidth() const { return m_Width; }
|
int GetWidth() const {
|
||||||
|
return m_Width;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Höhe des Objektes zurück.
|
@brief Gibt die Höhe des Objektes zurück.
|
||||||
*/
|
*/
|
||||||
int GetHeight() const { return m_Height; }
|
int GetHeight() const {
|
||||||
|
return m_Height;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt den Sichtbarkeitszustand des Objektes zurück.
|
@brief Gibt den Sichtbarkeitszustand des Objektes zurück.
|
||||||
@return Gibt den Sichtbarkeitszustand des Objektes zurück.<br>
|
@return Gibt den Sichtbarkeitszustand des Objektes zurück.<br>
|
||||||
true entspricht sichtbar, false entspricht unsichtbar.
|
true entspricht sichtbar, false entspricht unsichtbar.
|
||||||
*/
|
*/
|
||||||
bool IsVisible() const { return m_Visible; }
|
bool IsVisible() const {
|
||||||
|
return m_Visible;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt den Typ des Objektes zurück.
|
@brief Gibt den Typ des Objektes zurück.
|
||||||
*/
|
*/
|
||||||
TYPES GetType() const { return m_Type; }
|
TYPES GetType() const {
|
||||||
|
return m_Type;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt zurück, ob das Objekt erfolgreich initialisiert wurde.
|
@brief Gibt zurück, ob das Objekt erfolgreich initialisiert wurde.
|
||||||
@remark Hässlicher Workaround um das Problem, dass Konstruktoren keine Rückgabewerte haben.
|
@remark Hässlicher Workaround um das Problem, dass Konstruktoren keine Rückgabewerte haben.
|
||||||
*/
|
*/
|
||||||
bool GetInitSuccess() const { return m_InitSuccess; }
|
bool GetInitSuccess() const {
|
||||||
|
return m_InitSuccess;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Bounding-Box des Objektes zurück.
|
@brief Gibt die Bounding-Box des Objektes zurück.
|
||||||
@remark Diese Angabe erfolgt ausnahmsweise in Bildschirmkoordianten und nicht relativ zum Elternobjekt.
|
@remark Diese Angabe erfolgt ausnahmsweise in Bildschirmkoordianten und nicht relativ zum Elternobjekt.
|
||||||
*/
|
*/
|
||||||
const BS_Rect& GetBBox() const { return m_BBox; }
|
const BS_Rect &GetBBox() const {
|
||||||
|
return m_BBox;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Stellt sicher, dass das Objekt im nächsten Frame neu gezeichnet wird.
|
@brief Stellt sicher, dass das Objekt im nächsten Frame neu gezeichnet wird.
|
||||||
*/
|
*/
|
||||||
void ForceRefresh() { m_RefreshForced = true; };
|
void ForceRefresh() {
|
||||||
|
m_RefreshForced = true;
|
||||||
|
};
|
||||||
/**
|
/**
|
||||||
@brief Gibt das Handle des Objekte zurück.
|
@brief Gibt das Handle des Objekte zurück.
|
||||||
*/
|
*/
|
||||||
unsigned int GetHandle() const { return m_Handle; }
|
unsigned int GetHandle() const {
|
||||||
|
return m_Handle;
|
||||||
|
}
|
||||||
|
|
||||||
// Persistenz-Methoden
|
// Persistenz-Methoden
|
||||||
// -------------------
|
// -------------------
|
||||||
|
@ -409,7 +433,9 @@ protected:
|
||||||
/**
|
/**
|
||||||
@brief Gibt einen Pointer auf den BS_RenderObjektManager zurück, der das Objekt verwaltet.
|
@brief Gibt einen Pointer auf den BS_RenderObjektManager zurück, der das Objekt verwaltet.
|
||||||
*/
|
*/
|
||||||
BS_RenderObjectManager* GetManager() const { return m_ManagerPtr; }
|
BS_RenderObjectManager *GetManager() const {
|
||||||
|
return m_ManagerPtr;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Fügt dem Objekt ein neues Kinderobjekt hinzu.
|
@brief Fügt dem Objekt ein neues Kinderobjekt hinzu.
|
||||||
@param pObject ein Pointer auf das einzufügende Objekt
|
@param pObject ein Pointer auf das einzufügende Objekt
|
||||||
|
@ -474,14 +500,16 @@ private:
|
||||||
@brief Teilt dem Objekt mit, dass sich eines seiner Kinderobjekte dahingehend verändert hat, die eine erneute Bestimmung der
|
@brief Teilt dem Objekt mit, dass sich eines seiner Kinderobjekte dahingehend verändert hat, die eine erneute Bestimmung der
|
||||||
Rendereihenfolge verlangt.
|
Rendereihenfolge verlangt.
|
||||||
*/
|
*/
|
||||||
void SignalChildChange() { m_ChildChanged = true; }
|
void SignalChildChange() {
|
||||||
|
m_ChildChanged = true;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Berechnet des Schnittrechteck der Bounding-Box des Objektes mit einem anderen Objekt.
|
@brief Berechnet des Schnittrechteck der Bounding-Box des Objektes mit einem anderen Objekt.
|
||||||
@param pObjekt ein Pointer auf das Objekt mit dem geschnitten werden soll
|
@param pObjekt ein Pointer auf das Objekt mit dem geschnitten werden soll
|
||||||
@param Result das Ergebnisrechteck
|
@param Result das Ergebnisrechteck
|
||||||
@return Gibt false zurück, falls sich die Objekte gar nicht schneiden.
|
@return Gibt false zurück, falls sich die Objekte gar nicht schneiden.
|
||||||
*/
|
*/
|
||||||
bool GetObjectIntersection(BS_RenderObjectPtr<BS_RenderObject> pObject, BS_Rect& Result);
|
bool GetObjectIntersection(BS_RenderObjectPtr<BS_RenderObject> pObject, BS_Rect &Result);
|
||||||
/**
|
/**
|
||||||
@brief Vergleichsoperator der auf Objektpointern basiert statt auf Objekten.
|
@brief Vergleichsoperator der auf Objektpointern basiert statt auf Objekten.
|
||||||
@remark Diese Methode wird fürs Sortieren der Kinderliste nach der Rendereihenfolge benutzt.
|
@remark Diese Methode wird fürs Sortieren der Kinderliste nach der Rendereihenfolge benutzt.
|
||||||
|
|
|
@ -57,16 +57,14 @@ namespace Sword25 {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectManager::BS_RenderObjectManager(int Width, int Height, int FramebufferCount) :
|
BS_RenderObjectManager::BS_RenderObjectManager(int Width, int Height, int FramebufferCount) :
|
||||||
m_FrameStarted(false)
|
m_FrameStarted(false) {
|
||||||
{
|
|
||||||
// Wurzel des BS_RenderObject-Baumes erzeugen.
|
// Wurzel des BS_RenderObject-Baumes erzeugen.
|
||||||
m_RootPtr = new BS_RootRenderObject(this, Width, Height);
|
m_RootPtr = new BS_RootRenderObject(this, Width, Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_RenderObjectManager::~BS_RenderObjectManager()
|
BS_RenderObjectManager::~BS_RenderObjectManager() {
|
||||||
{
|
|
||||||
// Die Wurzel des Baumes löschen, damit werden alle BS_RenderObjects mitgelöscht.
|
// Die Wurzel des Baumes löschen, damit werden alle BS_RenderObjects mitgelöscht.
|
||||||
m_RootPtr.Erase();
|
m_RootPtr.Erase();
|
||||||
}
|
}
|
||||||
|
@ -75,8 +73,7 @@ BS_RenderObjectManager::~BS_RenderObjectManager()
|
||||||
// Interface
|
// Interface
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_RenderObjectManager::StartFrame()
|
void BS_RenderObjectManager::StartFrame() {
|
||||||
{
|
|
||||||
m_FrameStarted = true;
|
m_FrameStarted = true;
|
||||||
|
|
||||||
// Verstrichene Zeit bestimmen
|
// Verstrichene Zeit bestimmen
|
||||||
|
@ -90,8 +87,7 @@ void BS_RenderObjectManager::StartFrame()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_RenderObjectManager::Render()
|
bool BS_RenderObjectManager::Render() {
|
||||||
{
|
|
||||||
// Den Objekt-Status des Wurzelobjektes aktualisieren. Dadurch werden rekursiv alle Baumelemente aktualisiert.
|
// Den Objekt-Status des Wurzelobjektes aktualisieren. Dadurch werden rekursiv alle Baumelemente aktualisiert.
|
||||||
// Beim aktualisieren des Objekt-Status werden auch die Update-Rects gefunden, so dass feststeht, was neu gezeichnet
|
// Beim aktualisieren des Objekt-Status werden auch die Update-Rects gefunden, so dass feststeht, was neu gezeichnet
|
||||||
// werden muss.
|
// werden muss.
|
||||||
|
@ -105,15 +101,13 @@ bool BS_RenderObjectManager::Render()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_RenderObjectManager::AttatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> RenderObjectPtr)
|
void BS_RenderObjectManager::AttatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> RenderObjectPtr) {
|
||||||
{
|
|
||||||
m_TimedRenderObjects.push_back(RenderObjectPtr);
|
m_TimedRenderObjects.push_back(RenderObjectPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_RenderObjectManager::DetatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> RenderObjectPtr)
|
void BS_RenderObjectManager::DetatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> RenderObjectPtr) {
|
||||||
{
|
|
||||||
RenderObjectList::iterator Iter = find(m_TimedRenderObjects.begin(), m_TimedRenderObjects.end(), RenderObjectPtr);
|
RenderObjectList::iterator Iter = find(m_TimedRenderObjects.begin(), m_TimedRenderObjects.end(), RenderObjectPtr);
|
||||||
if (Iter != m_TimedRenderObjects.end()) m_TimedRenderObjects.erase(Iter);
|
if (Iter != m_TimedRenderObjects.end()) m_TimedRenderObjects.erase(Iter);
|
||||||
}
|
}
|
||||||
|
@ -122,8 +116,7 @@ void BS_RenderObjectManager::DetatchTimedRenderObject(BS_RenderObjectPtr<BS_Time
|
||||||
// Persistenz
|
// Persistenz
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_RenderObjectManager::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_RenderObjectManager::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
// Alle Kinder des Wurzelknotens speichern. Dadurch werden alle BS_RenderObjects gespeichert rekursiv gespeichert.
|
// Alle Kinder des Wurzelknotens speichern. Dadurch werden alle BS_RenderObjects gespeichert rekursiv gespeichert.
|
||||||
|
@ -134,8 +127,7 @@ bool BS_RenderObjectManager::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
// Referenzen auf die TimedRenderObjects persistieren.
|
// Referenzen auf die TimedRenderObjects persistieren.
|
||||||
Writer.Write(m_TimedRenderObjects.size());
|
Writer.Write(m_TimedRenderObjects.size());
|
||||||
RenderObjectList::const_iterator Iter = m_TimedRenderObjects.begin();
|
RenderObjectList::const_iterator Iter = m_TimedRenderObjects.begin();
|
||||||
while (Iter != m_TimedRenderObjects.end())
|
while (Iter != m_TimedRenderObjects.end()) {
|
||||||
{
|
|
||||||
Writer.Write((*Iter)->GetHandle());
|
Writer.Write((*Iter)->GetHandle());
|
||||||
++Iter;
|
++Iter;
|
||||||
}
|
}
|
||||||
|
@ -148,8 +140,7 @@ bool BS_RenderObjectManager::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_RenderObjectManager::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_RenderObjectManager::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
// Alle Kinder des Wurzelknotens löschen. Damit werden alle BS_RenderObjects gelöscht.
|
// Alle Kinder des Wurzelknotens löschen. Damit werden alle BS_RenderObjects gelöscht.
|
||||||
|
@ -166,8 +157,7 @@ bool BS_RenderObjectManager::Unpersist(BS_InputPersistenceBlock & Reader)
|
||||||
// Referenzen auf die TimedRenderObjects wieder herstellen.
|
// Referenzen auf die TimedRenderObjects wieder herstellen.
|
||||||
unsigned int TimedObjectCount;
|
unsigned int TimedObjectCount;
|
||||||
Reader.Read(TimedObjectCount);
|
Reader.Read(TimedObjectCount);
|
||||||
for (unsigned int i = 0; i < TimedObjectCount; ++i)
|
for (unsigned int i = 0; i < TimedObjectCount; ++i) {
|
||||||
{
|
|
||||||
unsigned int Handle;
|
unsigned int Handle;
|
||||||
Reader.Read(Handle);
|
Reader.Read(Handle);
|
||||||
m_TimedRenderObjects.push_back(Handle);
|
m_TimedRenderObjects.push_back(Handle);
|
||||||
|
|
|
@ -68,8 +68,7 @@ class BS_TimedRenderObject;
|
||||||
Sie sorgt dafür, dass die BS_RenderObjects in der richtigen Reihenfolge gerendert werden und ermöglicht den Zugriff auf die
|
Sie sorgt dafür, dass die BS_RenderObjects in der richtigen Reihenfolge gerendert werden und ermöglicht den Zugriff auf die
|
||||||
BS_RenderObjects über einen String.
|
BS_RenderObjects über einen String.
|
||||||
*/
|
*/
|
||||||
class BS_RenderObjectManager : public BS_Persistable
|
class BS_RenderObjectManager : public BS_Persistable {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@brief Erzeugt ein neues BS_RenderObjectManager-Objekt.
|
@brief Erzeugt ein neues BS_RenderObjectManager-Objekt.
|
||||||
|
@ -99,7 +98,9 @@ public:
|
||||||
/**
|
/**
|
||||||
@brief Gibt einen Pointer auf die Wurzel des Objektbaumes zurück.
|
@brief Gibt einen Pointer auf die Wurzel des Objektbaumes zurück.
|
||||||
*/
|
*/
|
||||||
BS_RenderObjectPtr<BS_RenderObject> GetTreeRoot() { return m_RootPtr; }
|
BS_RenderObjectPtr<BS_RenderObject> GetTreeRoot() {
|
||||||
|
return m_RootPtr;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
@brief Fügt ein BS_TimedRenderObject in die Liste der zeitabhängigen Render-Objekte.
|
@brief Fügt ein BS_TimedRenderObject in die Liste der zeitabhängigen Render-Objekte.
|
||||||
|
|
||||||
|
@ -114,8 +115,8 @@ public:
|
||||||
*/
|
*/
|
||||||
void DetatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> pRenderObject);
|
void DetatchTimedRenderObject(BS_RenderObjectPtr<BS_TimedRenderObject> pRenderObject);
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_FrameStarted;
|
bool m_FrameStarted;
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
namespace Sword25 {
|
namespace Sword25 {
|
||||||
|
|
||||||
BS_RenderObjectPtr::BS_RenderObjectPtr(BS_RenderObject * RenderObjectPtr) {
|
BS_RenderObjectPtr::BS_RenderObjectPtr(BS_RenderObject *RenderObjectPtr) {
|
||||||
m_Handle = RenderObjectPtr->GetHandle();
|
m_Handle = RenderObjectPtr->GetHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,7 @@ class BS_RenderObject;
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
class BS_RenderObjectPtr
|
class BS_RenderObjectPtr {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BS_RenderObjectPtr() : m_Handle(0)
|
BS_RenderObjectPtr() : m_Handle(0)
|
||||||
{}
|
{}
|
||||||
|
@ -64,25 +63,21 @@ public:
|
||||||
BS_RenderObjectPtr(unsigned int Handle) : m_Handle(Handle)
|
BS_RenderObjectPtr(unsigned int Handle) : m_Handle(Handle)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
BS_RenderObjectPtr(BS_RenderObject * RenderObjectPtr);
|
BS_RenderObjectPtr(BS_RenderObject *RenderObjectPtr);
|
||||||
|
|
||||||
T * operator->() const
|
T *operator->() const {
|
||||||
{
|
|
||||||
return static_cast<T *>(BS_RenderObjectRegistry::GetInstance().ResolveHandle(m_Handle));
|
return static_cast<T *>(BS_RenderObjectRegistry::GetInstance().ResolveHandle(m_Handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const BS_RenderObjectPtr<T> & other)
|
bool operator==(const BS_RenderObjectPtr<T> & other) {
|
||||||
{
|
|
||||||
return m_Handle == other.m_Handle;
|
return m_Handle == other.m_Handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsValid() const
|
bool IsValid() const {
|
||||||
{
|
|
||||||
return BS_RenderObjectRegistry::GetInstance().ResolveHandle(m_Handle) != 0;
|
return BS_RenderObjectRegistry::GetInstance().ResolveHandle(m_Handle) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Erase()
|
void Erase() {
|
||||||
{
|
|
||||||
delete static_cast<T *>(BS_RenderObjectRegistry::GetInstance().ResolveHandle(m_Handle));
|
delete static_cast<T *>(BS_RenderObjectRegistry::GetInstance().ResolveHandle(m_Handle));
|
||||||
m_Handle = 0;
|
m_Handle = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,15 +54,13 @@ std::auto_ptr<BS_RenderObjectRegistry> BS_RenderObjectRegistry::m_InstancePtr;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_RenderObjectRegistry::LogErrorLn(const char * Message) const
|
void BS_RenderObjectRegistry::LogErrorLn(const char *Message) const {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN(Message);
|
BS_LOG_ERRORLN(Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_RenderObjectRegistry::LogWarningLn(const char * Message) const
|
void BS_RenderObjectRegistry::LogWarningLn(const char *Message) const {
|
||||||
{
|
|
||||||
BS_LOG_WARNINGLN(Message);
|
BS_LOG_WARNINGLN(Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ class BS_RenderObject;
|
||||||
|
|
||||||
class BS_RenderObjectRegistry : public BS_ObjectRegistry<BS_RenderObject> {
|
class BS_RenderObjectRegistry : public BS_ObjectRegistry<BS_RenderObject> {
|
||||||
public:
|
public:
|
||||||
static BS_RenderObjectRegistry & GetInstance() {
|
static BS_RenderObjectRegistry &GetInstance() {
|
||||||
if (!m_InstancePtr.get()) m_InstancePtr.reset(new BS_RenderObjectRegistry);
|
if (!m_InstancePtr.get()) m_InstancePtr.reset(new BS_RenderObjectRegistry);
|
||||||
return *m_InstancePtr.get();
|
return *m_InstancePtr.get();
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ public:
|
||||||
virtual ~BS_RenderObjectRegistry() {}
|
virtual ~BS_RenderObjectRegistry() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void LogErrorLn(const char * Message) const;
|
virtual void LogErrorLn(const char *Message) const;
|
||||||
virtual void LogWarningLn(const char * Message) const;
|
virtual void LogWarningLn(const char *Message) const;
|
||||||
|
|
||||||
static std::auto_ptr<BS_RenderObjectRegistry> m_InstancePtr;
|
static std::auto_ptr<BS_RenderObjectRegistry> m_InstancePtr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,21 +50,21 @@ class BS_Kernel;
|
||||||
// Klassendefinition
|
// Klassendefinition
|
||||||
class BS_RenderObjectManager;
|
class BS_RenderObjectManager;
|
||||||
|
|
||||||
class BS_RootRenderObject : public BS_RenderObject
|
class BS_RootRenderObject : public BS_RenderObject {
|
||||||
{
|
friend BS_RenderObjectManager;
|
||||||
friend BS_RenderObjectManager;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BS_RootRenderObject(BS_RenderObjectManager * ManagerPtr, int Width, int Height) :
|
BS_RootRenderObject(BS_RenderObjectManager *ManagerPtr, int Width, int Height) :
|
||||||
BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject>(), TYPE_ROOT)
|
BS_RenderObject(BS_RenderObjectPtr<BS_RenderObject>(), TYPE_ROOT) {
|
||||||
{
|
|
||||||
m_ManagerPtr = ManagerPtr;
|
m_ManagerPtr = ManagerPtr;
|
||||||
m_Width = Width;
|
m_Width = Width;
|
||||||
m_Height = Height;
|
m_Height = Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool DoRender() { return true; }
|
virtual bool DoRender() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sword25
|
} // End of namespace Sword25
|
||||||
|
|
|
@ -47,8 +47,7 @@ using namespace std;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
struct RGB_PIXEL
|
struct RGB_PIXEL {
|
||||||
{
|
|
||||||
RGB_PIXEL(unsigned char _Red, unsigned char _Green, unsigned char _Blue) :
|
RGB_PIXEL(unsigned char _Red, unsigned char _Green, unsigned char _Blue) :
|
||||||
Red(_Red),
|
Red(_Red),
|
||||||
Green(_Green),
|
Green(_Green),
|
||||||
|
@ -60,8 +59,7 @@ struct RGB_PIXEL
|
||||||
unsigned char Blue;
|
unsigned char Blue;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const vector<unsigned int> & Data, const string & Filename)
|
bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const vector<unsigned int> & Data, const string &Filename) {
|
||||||
{
|
|
||||||
BS_ASSERT(Data.size() == Width * Height);
|
BS_ASSERT(Data.size() == Width * Height);
|
||||||
|
|
||||||
// Buffer für Bildschirminhalt in RGB reservieren
|
// Buffer für Bildschirminhalt in RGB reservieren
|
||||||
|
@ -70,10 +68,8 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
||||||
|
|
||||||
// Framebufferdaten pixelweise von RGBA nach RGB konvertieren
|
// Framebufferdaten pixelweise von RGBA nach RGB konvertieren
|
||||||
vector<unsigned int>::const_iterator it = Data.begin();
|
vector<unsigned int>::const_iterator it = Data.begin();
|
||||||
for (unsigned int y = 0; y < Height; y++)
|
for (unsigned int y = 0; y < Height; y++) {
|
||||||
{
|
for (unsigned int x = 0; x < Width; x++) {
|
||||||
for (unsigned int x = 0; x < Width; x++)
|
|
||||||
{
|
|
||||||
unsigned int SrcPixel = *it++;
|
unsigned int SrcPixel = *it++;
|
||||||
PixelBuffer.push_back(RGB_PIXEL((SrcPixel >> 16) & 0xff, (SrcPixel >> 8) & 0xff, SrcPixel & 0xff));
|
PixelBuffer.push_back(RGB_PIXEL((SrcPixel >> 16) & 0xff, (SrcPixel >> 8) & 0xff, SrcPixel & 0xff));
|
||||||
}
|
}
|
||||||
|
@ -82,29 +78,25 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
||||||
BS_ASSERT(Data.size() == PixelBuffer.size());
|
BS_ASSERT(Data.size() == PixelBuffer.size());
|
||||||
|
|
||||||
// Variablen für die PNG-Erstellung
|
// Variablen für die PNG-Erstellung
|
||||||
FILE * OutFile = 0;
|
FILE *OutFile = 0;
|
||||||
png_structp png_ptr = 0;
|
png_structp png_ptr = 0;
|
||||||
png_infop info_ptr = 0;
|
png_infop info_ptr = 0;
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
OutFile = fopen(Filename.c_str(), "wb");
|
OutFile = fopen(Filename.c_str(), "wb");
|
||||||
if (!OutFile)
|
if (!OutFile) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create screenshot-file \"%s\".", Filename.c_str());
|
BS_LOG_ERRORLN("Could not create screenshot-file \"%s\".", Filename.c_str());
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
if (!png_ptr)
|
if (!png_ptr) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create PNG write-struct.");
|
BS_LOG_ERRORLN("Could not create PNG write-struct.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||||
if (!info_ptr)
|
if (!info_ptr) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not create PNG info-struct.");
|
BS_LOG_ERRORLN("Could not create PNG info-struct.");
|
||||||
throw(0);
|
throw(0);
|
||||||
}
|
}
|
||||||
|
@ -127,8 +119,7 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
||||||
// Rowpointer erstellen
|
// Rowpointer erstellen
|
||||||
vector<png_bytep> RowPointers;
|
vector<png_bytep> RowPointers;
|
||||||
RowPointers.reserve(Height);
|
RowPointers.reserve(Height);
|
||||||
for (unsigned int i = 0; i < Height; i++)
|
for (unsigned int i = 0; i < Height; i++) {
|
||||||
{
|
|
||||||
RowPointers.push_back((png_bytep)(&PixelBuffer[Width * i]));
|
RowPointers.push_back((png_bytep)(&PixelBuffer[Width * i]));
|
||||||
}
|
}
|
||||||
png_set_rows(png_ptr, info_ptr, &RowPointers[0]);
|
png_set_rows(png_ptr, info_ptr, &RowPointers[0]);
|
||||||
|
@ -142,11 +133,9 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
||||||
fclose(OutFile);
|
fclose(OutFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (int)
|
catch (int) {
|
||||||
{
|
|
||||||
// Wenn die Datei bereits erstellt wurde, Datei schließen und löschen.
|
// Wenn die Datei bereits erstellt wurde, Datei schließen und löschen.
|
||||||
if (OutFile)
|
if (OutFile) {
|
||||||
{
|
|
||||||
fclose(OutFile);
|
fclose(OutFile);
|
||||||
remove(Filename.c_str());
|
remove(Filename.c_str());
|
||||||
}
|
}
|
||||||
|
@ -163,8 +152,7 @@ bool BS_Screenshot::SaveToFile(unsigned int Width, unsigned int Height, const ve
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const vector<unsigned int> & Data, const string & Filename)
|
bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height, const vector<unsigned int> & Data, const string &Filename) {
|
||||||
{
|
|
||||||
//
|
//
|
||||||
// Diese Methode nimmt ein Screenshot mit den Maßen von 800x600 und erzeugt einen Screenshot mit den Maßen von 200x125.
|
// Diese Methode nimmt ein Screenshot mit den Maßen von 800x600 und erzeugt einen Screenshot mit den Maßen von 200x125.
|
||||||
// Dabei werden je 50 Pixel oben und unten abgeschnitten (die Interface-Leisten im Spiel). Das verbleibende Bild von 800x500 wird auf
|
// Dabei werden je 50 Pixel oben und unten abgeschnitten (die Interface-Leisten im Spiel). Das verbleibende Bild von 800x500 wird auf
|
||||||
|
@ -173,8 +161,7 @@ bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height,
|
||||||
//
|
//
|
||||||
|
|
||||||
// Die Ausgangsgröße muss 800x600 sein.
|
// Die Ausgangsgröße muss 800x600 sein.
|
||||||
if (Width != 800 || Height != 600)
|
if (Width != 800 || Height != 600) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("The sreenshot dimensions have to be 800x600 in order to be saved as a thumbnail.");
|
BS_LOG_ERRORLN("The sreenshot dimensions have to be 800x600 in order to be saved as a thumbnail.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -185,15 +172,12 @@ bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height,
|
||||||
// Über das Zielbild iterieren und einen Pixel zur Zeit berechnen.
|
// Über das Zielbild iterieren und einen Pixel zur Zeit berechnen.
|
||||||
unsigned int x, y;
|
unsigned int x, y;
|
||||||
x = y = 0;
|
x = y = 0;
|
||||||
for(vector<unsigned int>::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter)
|
for (vector<unsigned int>::iterator Iter = ThumbnailData.begin(); Iter != ThumbnailData.end(); ++Iter) {
|
||||||
{
|
|
||||||
// Durchschnitt über 4x4 Pixelblock im Quellbild bilden.
|
// Durchschnitt über 4x4 Pixelblock im Quellbild bilden.
|
||||||
unsigned int Alpha, Red, Green, Blue;
|
unsigned int Alpha, Red, Green, Blue;
|
||||||
Alpha = Red = Green = Blue = 0;
|
Alpha = Red = Green = Blue = 0;
|
||||||
for (unsigned int j = 0; j < 4; ++j)
|
for (unsigned int j = 0; j < 4; ++j) {
|
||||||
{
|
for (unsigned int i = 0; i < 4; ++i) {
|
||||||
for (unsigned int i = 0; i < 4; ++i)
|
|
||||||
{
|
|
||||||
unsigned int Pixel = Data[((y * 4) + j + 50) * 800 + ((x * 4) + i)];
|
unsigned int Pixel = Data[((y * 4) + j + 50) * 800 + ((x * 4) + i)];
|
||||||
Alpha += (Pixel >> 24);
|
Alpha += (Pixel >> 24);
|
||||||
Red += (Pixel >> 16) & 0xff;
|
Red += (Pixel >> 16) & 0xff;
|
||||||
|
@ -207,8 +191,7 @@ bool BS_Screenshot::SaveThumbnailToFile(unsigned int Width, unsigned int Height,
|
||||||
|
|
||||||
// Mitzählen an welcher Stelle im Zielbild wir uns befinden.
|
// Mitzählen an welcher Stelle im Zielbild wir uns befinden.
|
||||||
++x;
|
++x;
|
||||||
if (x == 200)
|
if (x == 200) {
|
||||||
{
|
|
||||||
x = 0;
|
x = 0;
|
||||||
++y;
|
++y;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,11 +51,10 @@ namespace Sword25 {
|
||||||
// Class declaration
|
// Class declaration
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_Screenshot
|
class BS_Screenshot {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static bool SaveToFile(unsigned int Width, unsigned int Height, const Common::Array<unsigned int> & Data, const Common::String & Filename);
|
static bool SaveToFile(unsigned int Width, unsigned int Height, const Common::Array<unsigned int> & Data, const Common::String &Filename);
|
||||||
static bool SaveThumbnailToFile(unsigned int Width, unsigned int Height, const Common::Array<unsigned int> & Data, const Common::String & Filename);
|
static bool SaveThumbnailToFile(unsigned int Width, unsigned int Height, const Common::Array<unsigned int> & Data, const Common::String &Filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sword25
|
} // End of namespace Sword25
|
||||||
|
|
|
@ -54,9 +54,8 @@ namespace Sword25 {
|
||||||
// Konstruktion / Destruktion
|
// Konstruktion / Destruktion
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_StaticBitmap::BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String& Filename) :
|
BS_StaticBitmap::BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String &Filename) :
|
||||||
BS_Bitmap(ParentPtr, TYPE_STATICBITMAP)
|
BS_Bitmap(ParentPtr, TYPE_STATICBITMAP) {
|
||||||
{
|
|
||||||
// Das BS_Bitmap konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
// Das BS_Bitmap konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
||||||
if (!m_InitSuccess) return;
|
if (!m_InitSuccess) return;
|
||||||
|
|
||||||
|
@ -65,30 +64,26 @@ BS_StaticBitmap::BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr,
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_StaticBitmap::BS_StaticBitmap(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
BS_StaticBitmap::BS_StaticBitmap(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||||
BS_Bitmap(ParentPtr, TYPE_STATICBITMAP, Handle)
|
BS_Bitmap(ParentPtr, TYPE_STATICBITMAP, Handle) {
|
||||||
{
|
|
||||||
m_InitSuccess = Unpersist(Reader);
|
m_InitSuccess = Unpersist(Reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_StaticBitmap::InitBitmapResource(const Common::String & Filename)
|
bool BS_StaticBitmap::InitBitmapResource(const Common::String &Filename) {
|
||||||
{
|
|
||||||
// Bild-Resource laden
|
// Bild-Resource laden
|
||||||
BS_Resource* ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(Filename);
|
BS_Resource *ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(Filename);
|
||||||
if (!ResourcePtr)
|
if (!ResourcePtr) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not request resource \"%s\".", Filename.c_str());
|
BS_LOG_ERRORLN("Could not request resource \"%s\".", Filename.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (ResourcePtr->GetType() != BS_Resource::TYPE_BITMAP)
|
if (ResourcePtr->GetType() != BS_Resource::TYPE_BITMAP) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Requested resource \"%s\" is not a bitmap.", Filename.c_str());
|
BS_LOG_ERRORLN("Requested resource \"%s\" is not a bitmap.", Filename.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_BitmapResource * BitmapPtr = static_cast<BS_BitmapResource*>(ResourcePtr);
|
BS_BitmapResource *BitmapPtr = static_cast<BS_BitmapResource *>(ResourcePtr);
|
||||||
|
|
||||||
// Den eindeutigen Dateinamen zum späteren Referenzieren speichern
|
// Den eindeutigen Dateinamen zum späteren Referenzieren speichern
|
||||||
m_ResourceFilename = BitmapPtr->GetFileName();
|
m_ResourceFilename = BitmapPtr->GetFileName();
|
||||||
|
@ -105,35 +100,30 @@ bool BS_StaticBitmap::InitBitmapResource(const Common::String & Filename)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_StaticBitmap::~BS_StaticBitmap()
|
BS_StaticBitmap::~BS_StaticBitmap() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_StaticBitmap::DoRender()
|
bool BS_StaticBitmap::DoRender() {
|
||||||
{
|
|
||||||
// Bitmap holen
|
// Bitmap holen
|
||||||
BS_Resource* ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
BS_Resource *ResourcePtr = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||||
BS_ASSERT(ResourcePtr);
|
BS_ASSERT(ResourcePtr);
|
||||||
BS_ASSERT(ResourcePtr->GetType() == BS_Resource::TYPE_BITMAP);
|
BS_ASSERT(ResourcePtr->GetType() == BS_Resource::TYPE_BITMAP);
|
||||||
BS_BitmapResource * BitmapResourcePtr = static_cast<BS_BitmapResource*>(ResourcePtr);
|
BS_BitmapResource *BitmapResourcePtr = static_cast<BS_BitmapResource *>(ResourcePtr);
|
||||||
|
|
||||||
// Framebufferobjekt holen
|
// Framebufferobjekt holen
|
||||||
BS_GraphicEngine * GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
BS_GraphicEngine *GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||||
BS_ASSERT(GfxPtr);
|
BS_ASSERT(GfxPtr);
|
||||||
|
|
||||||
// Bitmap zeichnen
|
// Bitmap zeichnen
|
||||||
bool Result;
|
bool Result;
|
||||||
if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f)
|
if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f) {
|
||||||
{
|
|
||||||
Result = BitmapResourcePtr->Blit(m_AbsoluteX, m_AbsoluteY,
|
Result = BitmapResourcePtr->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||||
0, m_ModulationColor, -1, -1);
|
0, m_ModulationColor, -1, -1);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
Result = BitmapResourcePtr->Blit(m_AbsoluteX, m_AbsoluteY,
|
Result = BitmapResourcePtr->Blit(m_AbsoluteX, m_AbsoluteY,
|
||||||
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
(m_FlipV ? BS_BitmapResource::FLIP_V : 0) |
|
||||||
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
(m_FlipH ? BS_BitmapResource::FLIP_H : 0),
|
||||||
|
@ -148,14 +138,13 @@ bool BS_StaticBitmap::DoRender()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_StaticBitmap::GetPixel(int X, int Y) const
|
unsigned int BS_StaticBitmap::GetPixel(int X, int Y) const {
|
||||||
{
|
|
||||||
BS_ASSERT(X >= 0 && X < m_Width);
|
BS_ASSERT(X >= 0 && X < m_Width);
|
||||||
BS_ASSERT(Y >= 0 && Y < m_Height);
|
BS_ASSERT(Y >= 0 && Y < m_Height);
|
||||||
|
|
||||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||||
BS_BitmapResource* pBitmapResource = static_cast<BS_BitmapResource*>(pResource);
|
BS_BitmapResource *pBitmapResource = static_cast<BS_BitmapResource *>(pResource);
|
||||||
unsigned int Result = pBitmapResource->GetPixel(X, Y);
|
unsigned int Result = pBitmapResource->GetPixel(X, Y);
|
||||||
pResource->Release();
|
pResource->Release();
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -163,8 +152,7 @@ unsigned int BS_StaticBitmap::GetPixel(int X, int Y) const
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_StaticBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride)
|
bool BS_StaticBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, unsigned int Stride) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("SetContent() ist not supported with this object.");
|
BS_LOG_ERRORLN("SetContent() ist not supported with this object.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -173,33 +161,30 @@ bool BS_StaticBitmap::SetContent(const byte *Pixeldata, unsigned int Offset, uns
|
||||||
// Auskunftsmethoden
|
// Auskunftsmethoden
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_StaticBitmap::IsAlphaAllowed() const
|
bool BS_StaticBitmap::IsAlphaAllowed() const {
|
||||||
{
|
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
|
||||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||||
bool Result = static_cast<BS_BitmapResource*>(pResource)->IsAlphaAllowed();
|
bool Result = static_cast<BS_BitmapResource *>(pResource)->IsAlphaAllowed();
|
||||||
pResource->Release();
|
pResource->Release();
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_StaticBitmap::IsColorModulationAllowed() const
|
bool BS_StaticBitmap::IsColorModulationAllowed() const {
|
||||||
{
|
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
|
||||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||||
bool Result = static_cast<BS_BitmapResource*>(pResource)->IsColorModulationAllowed();
|
bool Result = static_cast<BS_BitmapResource *>(pResource)->IsColorModulationAllowed();
|
||||||
pResource->Release();
|
pResource->Release();
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_StaticBitmap::IsScalingAllowed() const
|
bool BS_StaticBitmap::IsScalingAllowed() const {
|
||||||
{
|
BS_Resource *pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
||||||
BS_Resource* pResource = BS_Kernel::GetInstance()->GetResourceManager()->RequestResource(m_ResourceFilename);
|
|
||||||
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
BS_ASSERT(pResource->GetType() == BS_Resource::TYPE_BITMAP);
|
||||||
bool Result = static_cast<BS_BitmapResource*>(pResource)->IsScalingAllowed();
|
bool Result = static_cast<BS_BitmapResource *>(pResource)->IsScalingAllowed();
|
||||||
pResource->Release();
|
pResource->Release();
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
@ -208,8 +193,7 @@ bool BS_StaticBitmap::IsScalingAllowed() const
|
||||||
// Persistenz
|
// Persistenz
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_StaticBitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_StaticBitmap::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_Bitmap::Persist(Writer);
|
Result &= BS_Bitmap::Persist(Writer);
|
||||||
|
@ -220,8 +204,7 @@ bool BS_StaticBitmap::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BS_StaticBitmap::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_StaticBitmap::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_Bitmap::Unpersist(Reader);
|
Result &= BS_Bitmap::Unpersist(Reader);
|
||||||
|
|
|
@ -48,16 +48,15 @@ namespace Sword25 {
|
||||||
// Klassendeklaration
|
// Klassendeklaration
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_StaticBitmap : public BS_Bitmap
|
class BS_StaticBitmap : public BS_Bitmap {
|
||||||
{
|
friend class BS_RenderObject;
|
||||||
friend class BS_RenderObject;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@remark Filename muss absoluter Pfad sein
|
@remark Filename muss absoluter Pfad sein
|
||||||
*/
|
*/
|
||||||
BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String& Filename);
|
BS_StaticBitmap(BS_RenderObjectPtr<BS_RenderObject> ParentPtr, const Common::String &Filename);
|
||||||
BS_StaticBitmap(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
BS_StaticBitmap(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~BS_StaticBitmap();
|
virtual ~BS_StaticBitmap();
|
||||||
|
@ -69,10 +68,12 @@ public:
|
||||||
virtual bool IsScalingAllowed() const;
|
virtual bool IsScalingAllowed() const;
|
||||||
virtual bool IsAlphaAllowed() const;
|
virtual bool IsAlphaAllowed() const;
|
||||||
virtual bool IsColorModulationAllowed() const;
|
virtual bool IsColorModulationAllowed() const;
|
||||||
virtual bool IsSetContentAllowed() const { return false; }
|
virtual bool IsSetContentAllowed() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool DoRender();
|
virtual bool DoRender();
|
||||||
|
@ -80,7 +81,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
Common::String m_ResourceFilename;
|
Common::String m_ResourceFilename;
|
||||||
|
|
||||||
bool InitBitmapResource(const Common::String & Filename);
|
bool InitBitmapResource(const Common::String &Filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sword25
|
} // End of namespace Sword25
|
||||||
|
|
|
@ -56,9 +56,8 @@ namespace Sword25 {
|
||||||
// Konstanten
|
// Konstanten
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace
|
namespace {
|
||||||
{
|
const unsigned int AUTO_WRAP_THRESHOLD_DEFAULT = 300;
|
||||||
const unsigned int AUTO_WRAP_THRESHOLD_DEFAULT = 300;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -69,33 +68,27 @@ BS_Text::BS_Text(BS_RenderObjectPtr<BS_RenderObject> ParentPtr) :
|
||||||
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_TEXT),
|
BS_RenderObject(ParentPtr, BS_RenderObject::TYPE_TEXT),
|
||||||
m_ModulationColor(0xffffffff),
|
m_ModulationColor(0xffffffff),
|
||||||
m_AutoWrap(false),
|
m_AutoWrap(false),
|
||||||
m_AutoWrapThreshold(AUTO_WRAP_THRESHOLD_DEFAULT)
|
m_AutoWrapThreshold(AUTO_WRAP_THRESHOLD_DEFAULT) {
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Text::BS_Text(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
BS_Text::BS_Text(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle) :
|
||||||
BS_RenderObject(ParentPtr, TYPE_TEXT, Handle)
|
BS_RenderObject(ParentPtr, TYPE_TEXT, Handle) {
|
||||||
{
|
|
||||||
m_InitSuccess = Unpersist(Reader);
|
m_InitSuccess = Unpersist(Reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Text::SetFont(const Common::String & Font)
|
bool BS_Text::SetFont(const Common::String &Font) {
|
||||||
{
|
|
||||||
// Font precachen.
|
// Font precachen.
|
||||||
if (GetResourceManager()->PrecacheResource(Font))
|
if (GetResourceManager()->PrecacheResource(Font)) {
|
||||||
{
|
|
||||||
m_Font = Font;
|
m_Font = Font;
|
||||||
UpdateFormat();
|
UpdateFormat();
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Could not precache font \"%s\". Font probably does not exist.", Font.c_str());
|
BS_LOG_ERRORLN("Could not precache font \"%s\". Font probably does not exist.", Font.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -104,8 +97,7 @@ bool BS_Text::SetFont(const Common::String & Font)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Text::SetText(const Common::String & Text)
|
void BS_Text::SetText(const Common::String &Text) {
|
||||||
{
|
|
||||||
m_Text = Text;
|
m_Text = Text;
|
||||||
UpdateFormat();
|
UpdateFormat();
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
|
@ -113,11 +105,9 @@ void BS_Text::SetText(const Common::String & Text)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Text::SetColor(unsigned int ModulationColor)
|
void BS_Text::SetColor(unsigned int ModulationColor) {
|
||||||
{
|
|
||||||
unsigned int NewModulationColor = (ModulationColor & 0x00ffffff) | (m_ModulationColor & 0xff000000);
|
unsigned int NewModulationColor = (ModulationColor & 0x00ffffff) | (m_ModulationColor & 0xff000000);
|
||||||
if (NewModulationColor != m_ModulationColor)
|
if (NewModulationColor != m_ModulationColor) {
|
||||||
{
|
|
||||||
m_ModulationColor = NewModulationColor;
|
m_ModulationColor = NewModulationColor;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
}
|
}
|
||||||
|
@ -125,12 +115,10 @@ void BS_Text::SetColor(unsigned int ModulationColor)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Text::SetAlpha(int Alpha)
|
void BS_Text::SetAlpha(int Alpha) {
|
||||||
{
|
|
||||||
BS_ASSERT(Alpha >= 0 && Alpha < 256);
|
BS_ASSERT(Alpha >= 0 && Alpha < 256);
|
||||||
unsigned int NewModulationColor = (m_ModulationColor & 0x00ffffff) | Alpha << 24;
|
unsigned int NewModulationColor = (m_ModulationColor & 0x00ffffff) | Alpha << 24;
|
||||||
if (NewModulationColor != m_ModulationColor)
|
if (NewModulationColor != m_ModulationColor) {
|
||||||
{
|
|
||||||
m_ModulationColor = NewModulationColor;
|
m_ModulationColor = NewModulationColor;
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
}
|
}
|
||||||
|
@ -138,10 +126,8 @@ void BS_Text::SetAlpha(int Alpha)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Text::SetAutoWrap(bool AutoWrap)
|
void BS_Text::SetAutoWrap(bool AutoWrap) {
|
||||||
{
|
if (AutoWrap != m_AutoWrap) {
|
||||||
if (AutoWrap != m_AutoWrap)
|
|
||||||
{
|
|
||||||
m_AutoWrap = AutoWrap;
|
m_AutoWrap = AutoWrap;
|
||||||
UpdateFormat();
|
UpdateFormat();
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
|
@ -150,10 +136,8 @@ void BS_Text::SetAutoWrap(bool AutoWrap)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Text::SetAutoWrapThreshold(unsigned int AutoWrapThreshold)
|
void BS_Text::SetAutoWrapThreshold(unsigned int AutoWrapThreshold) {
|
||||||
{
|
if (AutoWrapThreshold != m_AutoWrapThreshold) {
|
||||||
if (AutoWrapThreshold != m_AutoWrapThreshold)
|
|
||||||
{
|
|
||||||
m_AutoWrapThreshold = AutoWrapThreshold;
|
m_AutoWrapThreshold = AutoWrapThreshold;
|
||||||
UpdateFormat();
|
UpdateFormat();
|
||||||
ForceRefresh();
|
ForceRefresh();
|
||||||
|
@ -162,39 +146,35 @@ void BS_Text::SetAutoWrapThreshold(unsigned int AutoWrapThreshold)
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Text::DoRender()
|
bool BS_Text::DoRender() {
|
||||||
{
|
|
||||||
// Font-Resource locken.
|
// Font-Resource locken.
|
||||||
BS_FontResource * FontPtr = LockFontResource();
|
BS_FontResource *FontPtr = LockFontResource();
|
||||||
if (!FontPtr) return false;
|
if (!FontPtr) return false;
|
||||||
|
|
||||||
// Charactermap-Resource locken.
|
// Charactermap-Resource locken.
|
||||||
BS_ResourceManager * RMPtr = GetResourceManager();
|
BS_ResourceManager *RMPtr = GetResourceManager();
|
||||||
BS_BitmapResource * CharMapPtr;
|
BS_BitmapResource *CharMapPtr;
|
||||||
{
|
|
||||||
BS_Resource * pResource = RMPtr->RequestResource(FontPtr->GetCharactermapFileName());
|
|
||||||
if (!pResource)
|
|
||||||
{
|
{
|
||||||
|
BS_Resource *pResource = RMPtr->RequestResource(FontPtr->GetCharactermapFileName());
|
||||||
|
if (!pResource) {
|
||||||
BS_LOG_ERRORLN("Could not request resource \"%s\".", FontPtr->GetCharactermapFileName().c_str());
|
BS_LOG_ERRORLN("Could not request resource \"%s\".", FontPtr->GetCharactermapFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (pResource->GetType() != BS_Resource::TYPE_BITMAP)
|
if (pResource->GetType() != BS_Resource::TYPE_BITMAP) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Requested resource \"%s\" is not a bitmap.", FontPtr->GetCharactermapFileName().c_str());
|
BS_LOG_ERRORLN("Requested resource \"%s\" is not a bitmap.", FontPtr->GetCharactermapFileName().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharMapPtr = static_cast<BS_BitmapResource*>(pResource);
|
CharMapPtr = static_cast<BS_BitmapResource *>(pResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Framebufferobjekt holen.
|
// Framebufferobjekt holen.
|
||||||
BS_GraphicEngine * GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
BS_GraphicEngine *GfxPtr = static_cast<BS_GraphicEngine *>(BS_Kernel::GetInstance()->GetService("gfx"));
|
||||||
BS_ASSERT(GfxPtr);
|
BS_ASSERT(GfxPtr);
|
||||||
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
Common::Array<LINE>::iterator Iter = m_Lines.begin();
|
Common::Array<LINE>::iterator Iter = m_Lines.begin();
|
||||||
for (; Iter != m_Lines.end(); ++Iter)
|
for (; Iter != m_Lines.end(); ++Iter) {
|
||||||
{
|
|
||||||
// Feststellen, ob überhaupt Buchstaben der aktuellen Zeile vom Update betroffen sind.
|
// Feststellen, ob überhaupt Buchstaben der aktuellen Zeile vom Update betroffen sind.
|
||||||
BS_Rect CheckRect = (*Iter).BBox;
|
BS_Rect CheckRect = (*Iter).BBox;
|
||||||
CheckRect.Move(m_AbsoluteX, m_AbsoluteY);
|
CheckRect.Move(m_AbsoluteX, m_AbsoluteY);
|
||||||
|
@ -202,8 +182,7 @@ bool BS_Text::DoRender()
|
||||||
// Jeden Buchstaben einzeln Rendern.
|
// Jeden Buchstaben einzeln Rendern.
|
||||||
int CurX = m_AbsoluteX + (*Iter).BBox.left;
|
int CurX = m_AbsoluteX + (*Iter).BBox.left;
|
||||||
int CurY = m_AbsoluteY + (*Iter).BBox.top;
|
int CurY = m_AbsoluteY + (*Iter).BBox.top;
|
||||||
for (unsigned int i = 0; i < (*Iter).Text.size(); ++i)
|
for (unsigned int i = 0; i < (*Iter).Text.size(); ++i) {
|
||||||
{
|
|
||||||
BS_Rect CurRect = FontPtr->GetCharacterRect((unsigned char)(*Iter).Text.at(i));
|
BS_Rect CurRect = FontPtr->GetCharacterRect((unsigned char)(*Iter).Text.at(i));
|
||||||
|
|
||||||
BS_Rect RenderRect(CurX, CurY, CurX + CurRect.GetWidth(), CurY + CurRect.GetHeight());
|
BS_Rect RenderRect(CurX, CurY, CurX + CurRect.GetWidth(), CurY + CurRect.GetHeight());
|
||||||
|
@ -228,34 +207,30 @@ bool BS_Text::DoRender()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_ResourceManager * BS_Text::GetResourceManager()
|
BS_ResourceManager *BS_Text::GetResourceManager() {
|
||||||
{
|
|
||||||
// Pointer auf den Resource-Manager holen.
|
// Pointer auf den Resource-Manager holen.
|
||||||
return BS_Kernel::GetInstance()->GetResourceManager();
|
return BS_Kernel::GetInstance()->GetResourceManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_FontResource * BS_Text::LockFontResource()
|
BS_FontResource *BS_Text::LockFontResource() {
|
||||||
{
|
BS_ResourceManager *RMPtr = GetResourceManager();
|
||||||
BS_ResourceManager * RMPtr = GetResourceManager();
|
|
||||||
|
|
||||||
// Font-Resource locken.
|
// Font-Resource locken.
|
||||||
BS_FontResource * FontPtr;
|
BS_FontResource *FontPtr;
|
||||||
{
|
|
||||||
BS_Resource * ResourcePtr = RMPtr->RequestResource(m_Font);
|
|
||||||
if (!ResourcePtr)
|
|
||||||
{
|
{
|
||||||
|
BS_Resource *ResourcePtr = RMPtr->RequestResource(m_Font);
|
||||||
|
if (!ResourcePtr) {
|
||||||
BS_LOG_ERRORLN("Could not request resource \"%s\".", m_Font.c_str());
|
BS_LOG_ERRORLN("Could not request resource \"%s\".", m_Font.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (ResourcePtr->GetType() != BS_Resource::TYPE_FONT)
|
if (ResourcePtr->GetType() != BS_Resource::TYPE_FONT) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Requested resource \"%s\" is not a font.", m_Font.c_str());
|
BS_LOG_ERRORLN("Requested resource \"%s\" is not a font.", m_Font.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
FontPtr = static_cast<BS_FontResource*>(ResourcePtr);
|
FontPtr = static_cast<BS_FontResource *>(ResourcePtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FontPtr;
|
return FontPtr;
|
||||||
|
@ -263,16 +238,14 @@ BS_FontResource * BS_Text::LockFontResource()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Text::UpdateFormat()
|
void BS_Text::UpdateFormat() {
|
||||||
{
|
BS_FontResource *FontPtr = LockFontResource();
|
||||||
BS_FontResource * FontPtr = LockFontResource();
|
|
||||||
BS_ASSERT(FontPtr);
|
BS_ASSERT(FontPtr);
|
||||||
|
|
||||||
UpdateMetrics(*FontPtr);
|
UpdateMetrics(*FontPtr);
|
||||||
|
|
||||||
m_Lines.resize(1);
|
m_Lines.resize(1);
|
||||||
if (m_AutoWrap && (unsigned int) m_Width >= m_AutoWrapThreshold && m_Text.size() >= 2)
|
if (m_AutoWrap && (unsigned int) m_Width >= m_AutoWrapThreshold && m_Text.size() >= 2) {
|
||||||
{
|
|
||||||
m_Width = 0;
|
m_Width = 0;
|
||||||
unsigned int CurLineWidth = 0;
|
unsigned int CurLineWidth = 0;
|
||||||
unsigned int CurLineHeight = 0;
|
unsigned int CurLineHeight = 0;
|
||||||
|
@ -280,16 +253,14 @@ void BS_Text::UpdateFormat()
|
||||||
unsigned int TempLineWidth = 0;
|
unsigned int TempLineWidth = 0;
|
||||||
unsigned int LastSpace = 0; // we need at least 1 space character to start a new line...
|
unsigned int LastSpace = 0; // we need at least 1 space character to start a new line...
|
||||||
m_Lines[0].Text = "";
|
m_Lines[0].Text = "";
|
||||||
for (unsigned int i = 0; i < m_Text.size(); ++i)
|
for (unsigned int i = 0; i < m_Text.size(); ++i) {
|
||||||
{
|
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
TempLineWidth = 0;
|
TempLineWidth = 0;
|
||||||
LastSpace = 0;
|
LastSpace = 0;
|
||||||
for (j = i; j < m_Text.size(); ++j)
|
for (j = i; j < m_Text.size(); ++j) {
|
||||||
{
|
|
||||||
if ((unsigned char)m_Text[j] == ' ') LastSpace = j;
|
if ((unsigned char)m_Text[j] == ' ') LastSpace = j;
|
||||||
|
|
||||||
const BS_Rect & CurCharRect = FontPtr->GetCharacterRect((unsigned char)m_Text[j]);
|
const BS_Rect &CurCharRect = FontPtr->GetCharacterRect((unsigned char)m_Text[j]);
|
||||||
TempLineWidth += CurCharRect.GetWidth();
|
TempLineWidth += CurCharRect.GetWidth();
|
||||||
TempLineWidth += FontPtr->GetGapWidth();
|
TempLineWidth += FontPtr->GetGapWidth();
|
||||||
|
|
||||||
|
@ -301,11 +272,10 @@ void BS_Text::UpdateFormat()
|
||||||
|
|
||||||
CurLineWidth = 0;
|
CurLineWidth = 0;
|
||||||
CurLineHeight = 0;
|
CurLineHeight = 0;
|
||||||
for (j = i; j < LastSpace; ++j)
|
for (j = i; j < LastSpace; ++j) {
|
||||||
{
|
|
||||||
m_Lines[CurLine].Text += m_Text[j];
|
m_Lines[CurLine].Text += m_Text[j];
|
||||||
|
|
||||||
const BS_Rect & CurCharRect = FontPtr->GetCharacterRect((unsigned char)m_Text[j]);
|
const BS_Rect &CurCharRect = FontPtr->GetCharacterRect((unsigned char)m_Text[j]);
|
||||||
CurLineWidth += CurCharRect.GetWidth();
|
CurLineWidth += CurCharRect.GetWidth();
|
||||||
CurLineWidth += FontPtr->GetGapWidth();
|
CurLineWidth += FontPtr->GetGapWidth();
|
||||||
if ((unsigned int) CurCharRect.GetHeight() > CurLineHeight) CurLineHeight = CurCharRect.GetHeight();
|
if ((unsigned int) CurCharRect.GetHeight() > CurLineHeight) CurLineHeight = CurCharRect.GetHeight();
|
||||||
|
@ -315,8 +285,7 @@ void BS_Text::UpdateFormat()
|
||||||
m_Lines[CurLine].BBox.bottom = CurLineHeight;
|
m_Lines[CurLine].BBox.bottom = CurLineHeight;
|
||||||
if ((unsigned int) m_Width < CurLineWidth) m_Width = CurLineWidth;
|
if ((unsigned int) m_Width < CurLineWidth) m_Width = CurLineWidth;
|
||||||
|
|
||||||
if(LastSpace < m_Text.size())
|
if (LastSpace < m_Text.size()) {
|
||||||
{
|
|
||||||
++CurLine;
|
++CurLine;
|
||||||
BS_ASSERT(CurLine == m_Lines.size());
|
BS_ASSERT(CurLine == m_Lines.size());
|
||||||
m_Lines.resize(CurLine + 1);
|
m_Lines.resize(CurLine + 1);
|
||||||
|
@ -329,18 +298,15 @@ void BS_Text::UpdateFormat()
|
||||||
// Bounding-Box der einzelnen Zeilen relativ zur ersten festlegen (vor allem zentrieren).
|
// Bounding-Box der einzelnen Zeilen relativ zur ersten festlegen (vor allem zentrieren).
|
||||||
m_Height = 0;
|
m_Height = 0;
|
||||||
Common::Array<LINE>::iterator Iter = m_Lines.begin();
|
Common::Array<LINE>::iterator Iter = m_Lines.begin();
|
||||||
for (; Iter != m_Lines.end(); ++Iter)
|
for (; Iter != m_Lines.end(); ++Iter) {
|
||||||
{
|
BS_Rect &BBox = (*Iter).BBox;
|
||||||
BS_Rect & BBox = (*Iter).BBox;
|
|
||||||
BBox.left = (m_Width - BBox.right) / 2;
|
BBox.left = (m_Width - BBox.right) / 2;
|
||||||
BBox.right = BBox.left + BBox.right;
|
BBox.right = BBox.left + BBox.right;
|
||||||
BBox.top = (Iter - m_Lines.begin()) * FontPtr->GetLineHeight();
|
BBox.top = (Iter - m_Lines.begin()) * FontPtr->GetLineHeight();
|
||||||
BBox.bottom = BBox.top + BBox.bottom;
|
BBox.bottom = BBox.top + BBox.bottom;
|
||||||
m_Height += BBox.GetHeight();
|
m_Height += BBox.GetHeight();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// Keine automatische Formatierung, also wird der gesamte Text in nur eine Zeile kopiert.
|
// Keine automatische Formatierung, also wird der gesamte Text in nur eine Zeile kopiert.
|
||||||
m_Lines[0].Text = m_Text;
|
m_Lines[0].Text = m_Text;
|
||||||
m_Lines[0].BBox = BS_Rect(0, 0, m_Width, m_Height);
|
m_Lines[0].BBox = BS_Rect(0, 0, m_Width, m_Height);
|
||||||
|
@ -351,14 +317,12 @@ void BS_Text::UpdateFormat()
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_Text::UpdateMetrics(BS_FontResource & FontResource)
|
void BS_Text::UpdateMetrics(BS_FontResource &FontResource) {
|
||||||
{
|
|
||||||
m_Width = 0;
|
m_Width = 0;
|
||||||
m_Height = 0;
|
m_Height = 0;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < m_Text.size(); ++i)
|
for (unsigned int i = 0; i < m_Text.size(); ++i) {
|
||||||
{
|
const BS_Rect &CurRect = FontResource.GetCharacterRect((unsigned char)m_Text.at(i));
|
||||||
const BS_Rect & CurRect = FontResource.GetCharacterRect((unsigned char)m_Text.at(i));
|
|
||||||
m_Width += CurRect.GetWidth();
|
m_Width += CurRect.GetWidth();
|
||||||
if (i != m_Text.size() - 1) m_Width += FontResource.GetGapWidth();
|
if (i != m_Text.size() - 1) m_Width += FontResource.GetGapWidth();
|
||||||
if (m_Height < CurRect.GetHeight()) m_Height = CurRect.GetHeight();
|
if (m_Height < CurRect.GetHeight()) m_Height = CurRect.GetHeight();
|
||||||
|
@ -369,8 +333,7 @@ void BS_Text::UpdateMetrics(BS_FontResource & FontResource)
|
||||||
// Persistenz
|
// Persistenz
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Text::Persist(BS_OutputPersistenceBlock & Writer)
|
bool BS_Text::Persist(BS_OutputPersistenceBlock &Writer) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_RenderObject::Persist(Writer);
|
Result &= BS_RenderObject::Persist(Writer);
|
||||||
|
@ -386,8 +349,7 @@ bool BS_Text::Persist(BS_OutputPersistenceBlock & Writer)
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BS_Text::Unpersist(BS_InputPersistenceBlock & Reader)
|
bool BS_Text::Unpersist(BS_InputPersistenceBlock &Reader) {
|
||||||
{
|
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
|
|
||||||
Result &= BS_RenderObject::Unpersist(Reader);
|
Result &= BS_RenderObject::Unpersist(Reader);
|
||||||
|
|
|
@ -61,9 +61,8 @@ class BS_ResourceManager;
|
||||||
// Klassendefinition
|
// Klassendefinition
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BS_Text : public BS_RenderObject
|
class BS_Text : public BS_RenderObject {
|
||||||
{
|
friend class BS_RenderObject;
|
||||||
friend class BS_RenderObject;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -71,13 +70,13 @@ public:
|
||||||
@param Font der Dateiname der Fontdatei.
|
@param Font der Dateiname der Fontdatei.
|
||||||
@return Gibt false zurück, wenn der Font nicht gefunden wurde.
|
@return Gibt false zurück, wenn der Font nicht gefunden wurde.
|
||||||
*/
|
*/
|
||||||
bool SetFont(const Common::String & Font);
|
bool SetFont(const Common::String &Font);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Setzt den darzustellenden Text.
|
@brief Setzt den darzustellenden Text.
|
||||||
@param Text der darzustellende Text
|
@param Text der darzustellende Text
|
||||||
*/
|
*/
|
||||||
void SetText(const Common::String & Text);
|
void SetText(const Common::String &Text);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Setzt den Alphawert des Textes.
|
@brief Setzt den Alphawert des Textes.
|
||||||
|
@ -105,12 +104,16 @@ public:
|
||||||
/**
|
/**
|
||||||
@brief Gibt den dargestellten Text zurück.
|
@brief Gibt den dargestellten Text zurück.
|
||||||
*/
|
*/
|
||||||
const Common::String & GetText() { return m_Text; }
|
const Common::String &GetText() {
|
||||||
|
return m_Text;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt den Namen das momentan benutzten Fonts zurück.
|
@brief Gibt den Namen das momentan benutzten Fonts zurück.
|
||||||
*/
|
*/
|
||||||
const Common::String & GetFont() { return m_Font; }
|
const Common::String &GetFont() {
|
||||||
|
return m_Font;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Setzt die Farbe des Textes.
|
@brief Setzt die Farbe des Textes.
|
||||||
|
@ -122,33 +125,41 @@ public:
|
||||||
@brief Gibt den Alphawert des Textes zurück.
|
@brief Gibt den Alphawert des Textes zurück.
|
||||||
@return Der Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
|
@return Der Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
|
||||||
*/
|
*/
|
||||||
int GetAlpha() const { return m_ModulationColor >> 24; }
|
int GetAlpha() const {
|
||||||
|
return m_ModulationColor >> 24;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Farbe des Textes zurück.
|
@brief Gibt die Farbe des Textes zurück.
|
||||||
@return Eine 24-Bit RGB Farbe, die die Farbe des Textes angibt.
|
@return Eine 24-Bit RGB Farbe, die die Farbe des Textes angibt.
|
||||||
*/
|
*/
|
||||||
int GetColor() const { return m_ModulationColor & 0x00ffffff; }
|
int GetColor() const {
|
||||||
|
return m_ModulationColor & 0x00ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt zurück, ob die automatische Formatierung aktiviert ist.
|
@brief Gibt zurück, ob die automatische Formatierung aktiviert ist.
|
||||||
*/
|
*/
|
||||||
bool IsAutoWrapActive() const { return m_AutoWrap; }
|
bool IsAutoWrapActive() const {
|
||||||
|
return m_AutoWrap;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Gibt die Längengrenze des Textes in Pixeln zurück, ab der eine automatische Formatierung vorgenommen wird.
|
@brief Gibt die Längengrenze des Textes in Pixeln zurück, ab der eine automatische Formatierung vorgenommen wird.
|
||||||
*/
|
*/
|
||||||
unsigned int GetAutoWrapThreshold() const { return m_AutoWrapThreshold; }
|
unsigned int GetAutoWrapThreshold() const {
|
||||||
|
return m_AutoWrapThreshold;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer);
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer);
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader);
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool DoRender();
|
virtual bool DoRender();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BS_Text(BS_RenderObjectPtr<BS_RenderObject> ParentPtr);
|
BS_Text(BS_RenderObjectPtr<BS_RenderObject> ParentPtr);
|
||||||
BS_Text(BS_InputPersistenceBlock & Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
BS_Text(BS_InputPersistenceBlock &Reader, BS_RenderObjectPtr<BS_RenderObject> ParentPtr, unsigned int Handle);
|
||||||
|
|
||||||
unsigned int m_ModulationColor;
|
unsigned int m_ModulationColor;
|
||||||
Common::String m_Font;
|
Common::String m_Font;
|
||||||
|
@ -156,8 +167,7 @@ private:
|
||||||
bool m_AutoWrap;
|
bool m_AutoWrap;
|
||||||
unsigned int m_AutoWrapThreshold;
|
unsigned int m_AutoWrapThreshold;
|
||||||
|
|
||||||
struct LINE
|
struct LINE {
|
||||||
{
|
|
||||||
BS_Rect BBox;
|
BS_Rect BBox;
|
||||||
Common::String Text;
|
Common::String Text;
|
||||||
};
|
};
|
||||||
|
@ -165,9 +175,9 @@ private:
|
||||||
Common::Array<LINE> m_Lines;
|
Common::Array<LINE> m_Lines;
|
||||||
|
|
||||||
void UpdateFormat();
|
void UpdateFormat();
|
||||||
void UpdateMetrics(BS_FontResource & FontResource);
|
void UpdateMetrics(BS_FontResource &FontResource);
|
||||||
BS_ResourceManager * GetResourceManager();
|
BS_ResourceManager *GetResourceManager();
|
||||||
BS_FontResource * LockFontResource();
|
BS_FontResource *LockFontResource();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sword25
|
} // End of namespace Sword25
|
||||||
|
|
|
@ -43,14 +43,12 @@ namespace Sword25 {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_TimedRenderObject::BS_TimedRenderObject(BS_RenderObjectPtr<BS_RenderObject> pParent, TYPES Type, unsigned int Handle) :
|
BS_TimedRenderObject::BS_TimedRenderObject(BS_RenderObjectPtr<BS_RenderObject> pParent, TYPES Type, unsigned int Handle) :
|
||||||
BS_RenderObject(pParent, Type, Handle)
|
BS_RenderObject(pParent, Type, Handle) {
|
||||||
{
|
|
||||||
BS_ASSERT(GetManager());
|
BS_ASSERT(GetManager());
|
||||||
GetManager()->AttatchTimedRenderObject(this);
|
GetManager()->AttatchTimedRenderObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_TimedRenderObject::~BS_TimedRenderObject()
|
BS_TimedRenderObject::~BS_TimedRenderObject() {
|
||||||
{
|
|
||||||
BS_ASSERT(GetManager());
|
BS_ASSERT(GetManager());
|
||||||
GetManager()->DetatchTimedRenderObject(this);
|
GetManager()->DetatchTimedRenderObject(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,7 @@ namespace Sword25 {
|
||||||
@brief
|
@brief
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BS_TimedRenderObject : public BS_RenderObject
|
class BS_TimedRenderObject : public BS_RenderObject {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
BS_TimedRenderObject(BS_RenderObjectPtr<BS_RenderObject> pParent, TYPES Type, unsigned int Handle = 0);
|
BS_TimedRenderObject(BS_RenderObjectPtr<BS_RenderObject> pParent, TYPES Type, unsigned int Handle = 0);
|
||||||
~BS_TimedRenderObject();
|
~BS_TimedRenderObject();
|
||||||
|
|
|
@ -57,8 +57,8 @@ namespace Sword25 {
|
||||||
|
|
||||||
class BS_InputEngine : public BS_Service, public BS_Persistable {
|
class BS_InputEngine : public BS_Service, public BS_Persistable {
|
||||||
public:
|
public:
|
||||||
BS_InputEngine(BS_Kernel* pKernel);
|
BS_InputEngine(BS_Kernel *pKernel);
|
||||||
virtual ~BS_InputEngine(){};
|
virtual ~BS_InputEngine() {};
|
||||||
|
|
||||||
// NOTE: These codes are registered in inputengine_script.cpp
|
// NOTE: These codes are registered in inputengine_script.cpp
|
||||||
// Any changes to these enums must also adjust the above file.
|
// Any changes to these enums must also adjust the above file.
|
||||||
|
|
|
@ -61,45 +61,47 @@ static void TheCharacterCallback(int Character);
|
||||||
static void TheCommandCallback(int Command);
|
static void TheCommandCallback(int Command);
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class CharacterCallbackClass : public BS_LuaCallback {
|
class CharacterCallbackClass : public BS_LuaCallback {
|
||||||
public:
|
public:
|
||||||
CharacterCallbackClass(lua_State *L) : BS_LuaCallback(L) {};
|
CharacterCallbackClass(lua_State *L) : BS_LuaCallback(L) {};
|
||||||
|
|
||||||
Common::String Character;
|
Common::String Character;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int PreFunctionInvokation(lua_State *L) {
|
int PreFunctionInvokation(lua_State *L) {
|
||||||
lua_pushstring(L, Character.c_str());
|
lua_pushstring(L, Character.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Common::SharedPtr<CharacterCallbackClass> CharacterCallbackPtr;
|
Common::SharedPtr<CharacterCallbackClass> CharacterCallbackPtr;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
class CommandCallbackClass : public BS_LuaCallback {
|
class CommandCallbackClass : public BS_LuaCallback {
|
||||||
public:
|
public:
|
||||||
CommandCallbackClass(lua_State *L) : BS_LuaCallback(L) { Command = BS_InputEngine::KEY_COMMAND_BACKSPACE; }
|
CommandCallbackClass(lua_State *L) : BS_LuaCallback(L) {
|
||||||
|
Command = BS_InputEngine::KEY_COMMAND_BACKSPACE;
|
||||||
|
}
|
||||||
|
|
||||||
BS_InputEngine::KEY_COMMANDS Command;
|
BS_InputEngine::KEY_COMMANDS Command;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int PreFunctionInvokation(lua_State *L) {
|
int PreFunctionInvokation(lua_State *L) {
|
||||||
lua_pushnumber(L, Command);
|
lua_pushnumber(L, Command);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Common::SharedPtr<CommandCallbackClass> CommandCallbackPtr;
|
Common::SharedPtr<CommandCallbackClass> CommandCallbackPtr;
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
struct CallbackfunctionRegisterer {
|
struct CallbackfunctionRegisterer {
|
||||||
CallbackfunctionRegisterer() {
|
CallbackfunctionRegisterer() {
|
||||||
BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCommandCB", TheCommandCallback);
|
BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCommandCB", TheCommandCallback);
|
||||||
BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCharacterCB", TheCharacterCallback);
|
BS_CallbackRegistry::GetInstance().RegisterCallbackFunction("LuaCharacterCB", TheCharacterCallback);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
static CallbackfunctionRegisterer Instance;
|
static CallbackfunctionRegisterer Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
|
@ -80,7 +80,9 @@ ScummVMInput::~ScummVMInput() {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_Service *ScummVMInput_CreateObject(BS_Kernel *pKernel) { return new ScummVMInput(pKernel); }
|
BS_Service *ScummVMInput_CreateObject(BS_Kernel *pKernel) {
|
||||||
|
return new ScummVMInput(pKernel);
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -102,18 +104,21 @@ void ScummVMInput::Update() {
|
||||||
case Common::EVENT_LBUTTONDOWN:
|
case Common::EVENT_LBUTTONDOWN:
|
||||||
case Common::EVENT_LBUTTONUP:
|
case Common::EVENT_LBUTTONUP:
|
||||||
m_LeftMouseDown = event.type == Common::EVENT_LBUTTONDOWN;
|
m_LeftMouseDown = event.type == Common::EVENT_LBUTTONDOWN;
|
||||||
m_MouseX = event.mouse.x; m_MouseY = event.mouse.y;
|
m_MouseX = event.mouse.x;
|
||||||
|
m_MouseY = event.mouse.y;
|
||||||
handleEvents = false;
|
handleEvents = false;
|
||||||
break;
|
break;
|
||||||
case Common::EVENT_RBUTTONDOWN:
|
case Common::EVENT_RBUTTONDOWN:
|
||||||
case Common::EVENT_RBUTTONUP:
|
case Common::EVENT_RBUTTONUP:
|
||||||
m_RightMouseDown = event.type == Common::EVENT_RBUTTONDOWN;
|
m_RightMouseDown = event.type == Common::EVENT_RBUTTONDOWN;
|
||||||
m_MouseX = event.mouse.x; m_MouseY = event.mouse.y;
|
m_MouseX = event.mouse.x;
|
||||||
|
m_MouseY = event.mouse.y;
|
||||||
handleEvents = false;
|
handleEvents = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Common::EVENT_MOUSEMOVE:
|
case Common::EVENT_MOUSEMOVE:
|
||||||
m_MouseX = event.mouse.x; m_MouseY = event.mouse.y;
|
m_MouseX = event.mouse.x;
|
||||||
|
m_MouseY = event.mouse.y;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Common::EVENT_KEYDOWN:
|
case Common::EVENT_KEYDOWN:
|
||||||
|
|
|
@ -56,7 +56,7 @@ typedef void (*CallbackPtr)(int Command);
|
||||||
|
|
||||||
class BS_CallbackRegistry {
|
class BS_CallbackRegistry {
|
||||||
public:
|
public:
|
||||||
static BS_CallbackRegistry & GetInstance() {
|
static BS_CallbackRegistry &GetInstance() {
|
||||||
static BS_CallbackRegistry Instance;
|
static BS_CallbackRegistry Instance;
|
||||||
return Instance;
|
return Instance;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,9 @@ private:
|
||||||
NameToPtrMap m_NameToPtrMap;
|
NameToPtrMap m_NameToPtrMap;
|
||||||
|
|
||||||
struct CallbackPtr_EqualTo {
|
struct CallbackPtr_EqualTo {
|
||||||
bool operator()(CallbackPtr x, CallbackPtr y) const { return x == y; }
|
bool operator()(CallbackPtr x, CallbackPtr y) const {
|
||||||
|
return x == y;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
struct CallbackPtr_Hash {
|
struct CallbackPtr_Hash {
|
||||||
uint operator()(CallbackPtr x) const {
|
uint operator()(CallbackPtr x) const {
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
// Global constants
|
// Global constants
|
||||||
#if _DEBUG && !DEBUG
|
#if _DEBUG && !DEBUG
|
||||||
#define DEBUG
|
#define DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BS_ACTIVATE_LOGGING // When defined, logging is activated
|
#define BS_ACTIVATE_LOGGING // When defined, logging is activated
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Sword25 {
|
||||||
// Constructor / Destructor
|
// Constructor / Destructor
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_InputPersistenceBlock::BS_InputPersistenceBlock(const void * Data, unsigned int DataLength) :
|
BS_InputPersistenceBlock::BS_InputPersistenceBlock(const void *Data, unsigned int DataLength) :
|
||||||
m_Data(static_cast<const unsigned char *>(Data), DataLength),
|
m_Data(static_cast<const unsigned char *>(Data), DataLength),
|
||||||
m_ErrorState(NONE) {
|
m_ErrorState(NONE) {
|
||||||
m_Iter = m_Data.begin();
|
m_Iter = m_Data.begin();
|
||||||
|
@ -146,7 +146,7 @@ void BS_InputPersistenceBlock::Read(Common::Array<unsigned char> &Value) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
void BS_InputPersistenceBlock::RawRead(void * DestPtr, size_t Size) {
|
void BS_InputPersistenceBlock::RawRead(void *DestPtr, size_t Size) {
|
||||||
if (CheckBlockSize(Size)) {
|
if (CheckBlockSize(Size)) {
|
||||||
memcpy(DestPtr, &*m_Iter, Size);
|
memcpy(DestPtr, &*m_Iter, Size);
|
||||||
m_Iter += Size;
|
m_Iter += Size;
|
||||||
|
|
|
@ -68,8 +68,12 @@ public:
|
||||||
void Read(Common::String &Value);
|
void Read(Common::String &Value);
|
||||||
void Read(Common::Array<unsigned char> &Value);
|
void Read(Common::Array<unsigned char> &Value);
|
||||||
|
|
||||||
bool IsGood() const { return m_ErrorState == NONE; }
|
bool IsGood() const {
|
||||||
ErrorState GetErrorState() const { return m_ErrorState; }
|
return m_ErrorState == NONE;
|
||||||
|
}
|
||||||
|
ErrorState GetErrorState() const {
|
||||||
|
return m_ErrorState;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool CheckMarker(unsigned char Marker);
|
bool CheckMarker(unsigned char Marker);
|
||||||
|
|
|
@ -129,12 +129,11 @@ BS_Kernel::~BS_Kernel() {
|
||||||
// Service Methoden
|
// Service Methoden
|
||||||
// ----------------
|
// ----------------
|
||||||
|
|
||||||
BS_Kernel::Superclass::Superclass (BS_Kernel* pKernel, const Common::String& Identifier) :
|
BS_Kernel::Superclass::Superclass(BS_Kernel *pKernel, const Common::String &Identifier) :
|
||||||
_pKernel(pKernel),
|
_pKernel(pKernel),
|
||||||
_Identifier(Identifier),
|
_Identifier(Identifier),
|
||||||
_ServiceCount(0),
|
_ServiceCount(0),
|
||||||
_ActiveService(NULL)
|
_ActiveService(NULL) {
|
||||||
{
|
|
||||||
for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++)
|
for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++)
|
||||||
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier)
|
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier)
|
||||||
_ServiceCount++;
|
_ServiceCount++;
|
||||||
|
@ -180,20 +179,16 @@ Common::String BS_Kernel::Superclass::GetServiceIdentifier(unsigned int Number)
|
||||||
BS_Service *BS_Kernel::Superclass::NewService(const Common::String &ServiceIdentifier) {
|
BS_Service *BS_Kernel::Superclass::NewService(const Common::String &ServiceIdentifier) {
|
||||||
for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++)
|
for (unsigned int i = 0; i < BS_SERVICE_COUNT; i++)
|
||||||
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier &&
|
if (BS_SERVICE_TABLE[i].SuperclassIdentifier == _Identifier &&
|
||||||
BS_SERVICE_TABLE[i].ServiceIdentifier == ServiceIdentifier)
|
BS_SERVICE_TABLE[i].ServiceIdentifier == ServiceIdentifier) {
|
||||||
{
|
BS_Service *NewService = BS_SERVICE_TABLE[i].CreateMethod(_pKernel);
|
||||||
BS_Service* NewService = BS_SERVICE_TABLE[i].CreateMethod(_pKernel);
|
|
||||||
|
|
||||||
if (NewService)
|
if (NewService) {
|
||||||
{
|
|
||||||
DisconnectService();
|
DisconnectService();
|
||||||
BS_LOGLN("Service '%s' created from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str());
|
BS_LOGLN("Service '%s' created from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str());
|
||||||
_ActiveService = NewService;
|
_ActiveService = NewService;
|
||||||
_ActiveServiceName = BS_SERVICE_TABLE[i].ServiceIdentifier;
|
_ActiveServiceName = BS_SERVICE_TABLE[i].ServiceIdentifier;
|
||||||
return _ActiveService;
|
return _ActiveService;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Failed to create service '%s' from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str());
|
BS_LOG_ERRORLN("Failed to create service '%s' from superclass '%s'.", ServiceIdentifier.c_str(), _Identifier.c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -221,7 +216,7 @@ bool BS_Kernel::Superclass::DisconnectService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
BS_Kernel::Superclass *BS_Kernel::GetSuperclassByIdentifier(const Common::String &Identifier) {
|
BS_Kernel::Superclass *BS_Kernel::GetSuperclassByIdentifier(const Common::String &Identifier) {
|
||||||
Common::Array<Superclass*>::iterator Iter;
|
Common::Array<Superclass *>::iterator Iter;
|
||||||
for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) {
|
for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) {
|
||||||
if ((*Iter)->GetIdentifier() == Identifier)
|
if ((*Iter)->GetIdentifier() == Identifier)
|
||||||
return *Iter;
|
return *Iter;
|
||||||
|
@ -248,7 +243,7 @@ Common::String BS_Kernel::GetSuperclassIdentifier(unsigned int Number) {
|
||||||
if (Number > _SuperclassList.size()) return NULL;
|
if (Number > _SuperclassList.size()) return NULL;
|
||||||
|
|
||||||
unsigned int CurSuperclassOrd = 0;
|
unsigned int CurSuperclassOrd = 0;
|
||||||
Common::Array<Superclass*>::iterator Iter;
|
Common::Array<Superclass *>::iterator Iter;
|
||||||
for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) {
|
for (Iter = _SuperclassList.begin(); Iter != _SuperclassList.end(); ++Iter) {
|
||||||
if (CurSuperclassOrd == Number)
|
if (CurSuperclassOrd == Number)
|
||||||
return ((*Iter)->GetIdentifier());
|
return ((*Iter)->GetIdentifier());
|
||||||
|
@ -264,7 +259,7 @@ Common::String BS_Kernel::GetSuperclassIdentifier(unsigned int Number) {
|
||||||
* @param SuperclassIdentifier The name of the superclass
|
* @param SuperclassIdentifier The name of the superclass
|
||||||
* z.B: "sfx", "gfx", "package" ...
|
* z.B: "sfx", "gfx", "package" ...
|
||||||
*/
|
*/
|
||||||
unsigned int BS_Kernel::GetServiceCount(const Common::String & SuperclassIdentifier) {
|
unsigned int BS_Kernel::GetServiceCount(const Common::String &SuperclassIdentifier) {
|
||||||
Superclass *pSuperclass;
|
Superclass *pSuperclass;
|
||||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier)))
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier)))
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -282,8 +277,8 @@ unsigned int BS_Kernel::GetServiceCount(const Common::String & SuperclassIdentif
|
||||||
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen
|
* Hierbei ist zu beachten, dass der erste Service die Nummer 0 erhält. Number muss also eine Zahl zwischen
|
||||||
* 0 und GetServiceCount() - 1 sein.
|
* 0 und GetServiceCount() - 1 sein.
|
||||||
*/
|
*/
|
||||||
Common::String BS_Kernel::GetServiceIdentifier(const Common::String & SuperclassIdentifier, unsigned int Number) {
|
Common::String BS_Kernel::GetServiceIdentifier(const Common::String &SuperclassIdentifier, unsigned int Number) {
|
||||||
Superclass* pSuperclass;
|
Superclass *pSuperclass;
|
||||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
||||||
|
|
||||||
return (pSuperclass->GetServiceIdentifier(Number));
|
return (pSuperclass->GetServiceIdentifier(Number));
|
||||||
|
@ -298,7 +293,7 @@ Common::String BS_Kernel::GetServiceIdentifier(const Common::String & Superclass
|
||||||
* @param ServiceIdentifier The name of the service
|
* @param ServiceIdentifier The name of the service
|
||||||
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
* For the superclass "sfx" an example could be "Fmod" or "directsound"
|
||||||
*/
|
*/
|
||||||
BS_Service *BS_Kernel::NewService(const Common::String& SuperclassIdentifier, const Common::String& ServiceIdentifier) {
|
BS_Service *BS_Kernel::NewService(const Common::String &SuperclassIdentifier, const Common::String &ServiceIdentifier) {
|
||||||
Superclass *pSuperclass;
|
Superclass *pSuperclass;
|
||||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
||||||
|
|
||||||
|
@ -314,7 +309,7 @@ BS_Service *BS_Kernel::NewService(const Common::String& SuperclassIdentifier, co
|
||||||
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
* @param SuperclassIdentfier The name of the superclass which is to be disconnected
|
||||||
* z.B: "sfx", "gfx", "package" ...
|
* z.B: "sfx", "gfx", "package" ...
|
||||||
*/
|
*/
|
||||||
bool BS_Kernel::DisconnectService(const Common::String& SuperclassIdentifier) {
|
bool BS_Kernel::DisconnectService(const Common::String &SuperclassIdentifier) {
|
||||||
Superclass *pSuperclass;
|
Superclass *pSuperclass;
|
||||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return false;
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return false;
|
||||||
|
|
||||||
|
@ -326,7 +321,7 @@ bool BS_Kernel::DisconnectService(const Common::String& SuperclassIdentifier) {
|
||||||
* @param SuperclassIdentfier The name of the superclass
|
* @param SuperclassIdentfier The name of the superclass
|
||||||
* z.B: "sfx", "gfx", "package" ...
|
* z.B: "sfx", "gfx", "package" ...
|
||||||
*/
|
*/
|
||||||
BS_Service *BS_Kernel::GetService(const Common::String& SuperclassIdentifier) {
|
BS_Service *BS_Kernel::GetService(const Common::String &SuperclassIdentifier) {
|
||||||
Superclass *pSuperclass;
|
Superclass *pSuperclass;
|
||||||
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
if (!(pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier))) return NULL;
|
||||||
|
|
||||||
|
@ -339,8 +334,8 @@ BS_Service *BS_Kernel::GetService(const Common::String& SuperclassIdentifier) {
|
||||||
* @param SuperclassIdentfier The name of the superclass
|
* @param SuperclassIdentfier The name of the superclass
|
||||||
* z.B: "sfx", "gfx", "package" ...
|
* z.B: "sfx", "gfx", "package" ...
|
||||||
*/
|
*/
|
||||||
Common::String BS_Kernel::GetActiveServiceIdentifier(const Common::String& SuperclassIdentifier) {
|
Common::String BS_Kernel::GetActiveServiceIdentifier(const Common::String &SuperclassIdentifier) {
|
||||||
Superclass * pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier);
|
Superclass *pSuperclass = GetSuperclassByIdentifier(SuperclassIdentifier);
|
||||||
if (!pSuperclass) return Common::String("");
|
if (!pSuperclass) return Common::String("");
|
||||||
|
|
||||||
return (pSuperclass->GetActiveServiceName());
|
return (pSuperclass->GetActiveServiceName());
|
||||||
|
@ -386,12 +381,9 @@ size_t BS_Kernel::GetUsedMemory() {
|
||||||
#ifdef SCUMMVM_DISABLED_CODE
|
#ifdef SCUMMVM_DISABLED_CODE
|
||||||
PROCESS_MEMORY_COUNTERS pmc;
|
PROCESS_MEMORY_COUNTERS pmc;
|
||||||
pmc.cb = sizeof(pmc);
|
pmc.cb = sizeof(pmc);
|
||||||
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
|
if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
|
||||||
{
|
|
||||||
return pmc.WorkingSetSize;
|
return pmc.WorkingSetSize;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Call to GetProcessMemoryInfo() failed. Error code: %d", GetLastError());
|
BS_LOG_ERRORLN("Call to GetProcessMemoryInfo() failed. Error code: %d", GetLastError());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -403,7 +395,7 @@ size_t BS_Kernel::GetUsedMemory() {
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active
|
* Returns a pointer to the active Gfx Service, or NULL if no Gfx service is active
|
||||||
*/
|
*/
|
||||||
BS_GraphicEngine * BS_Kernel::GetGfx() {
|
BS_GraphicEngine *BS_Kernel::GetGfx() {
|
||||||
return static_cast<BS_GraphicEngine *>(GetService("gfx"));
|
return static_cast<BS_GraphicEngine *>(GetService("gfx"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +404,7 @@ BS_GraphicEngine * BS_Kernel::GetGfx() {
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the active Sfx Service, or NULL if no Sfx service is active
|
* Returns a pointer to the active Sfx Service, or NULL if no Sfx service is active
|
||||||
*/
|
*/
|
||||||
BS_SoundEngine * BS_Kernel::GetSfx() {
|
BS_SoundEngine *BS_Kernel::GetSfx() {
|
||||||
return static_cast<BS_SoundEngine *>(GetService("sfx"));
|
return static_cast<BS_SoundEngine *>(GetService("sfx"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +413,7 @@ BS_SoundEngine * BS_Kernel::GetSfx() {
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the active input service, or NULL if no input service is active
|
* Returns a pointer to the active input service, or NULL if no input service is active
|
||||||
*/
|
*/
|
||||||
BS_InputEngine * BS_Kernel::GetInput() {
|
BS_InputEngine *BS_Kernel::GetInput() {
|
||||||
return static_cast<BS_InputEngine *>(GetService("input"));
|
return static_cast<BS_InputEngine *>(GetService("input"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +422,7 @@ BS_InputEngine * BS_Kernel::GetInput() {
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the active package manager, or NULL if no manager is active
|
* Returns a pointer to the active package manager, or NULL if no manager is active
|
||||||
*/
|
*/
|
||||||
BS_PackageManager * BS_Kernel::GetPackage() {
|
BS_PackageManager *BS_Kernel::GetPackage() {
|
||||||
return static_cast<BS_PackageManager *>(GetService("package"));
|
return static_cast<BS_PackageManager *>(GetService("package"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,7 +431,7 @@ BS_PackageManager * BS_Kernel::GetPackage() {
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the script engine, or NULL if it is not active
|
* Returns a pointer to the script engine, or NULL if it is not active
|
||||||
*/
|
*/
|
||||||
BS_ScriptEngine * BS_Kernel::GetScript() {
|
BS_ScriptEngine *BS_Kernel::GetScript() {
|
||||||
return static_cast<BS_ScriptEngine *>(GetService("script"));
|
return static_cast<BS_ScriptEngine *>(GetService("script"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +440,7 @@ BS_ScriptEngine * BS_Kernel::GetScript() {
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the movie player, or NULL if it is not active
|
* Returns a pointer to the movie player, or NULL if it is not active
|
||||||
*/
|
*/
|
||||||
BS_MoviePlayer * BS_Kernel::GetFMV() {
|
BS_MoviePlayer *BS_Kernel::GetFMV() {
|
||||||
return static_cast<BS_MoviePlayer *>(GetService("fmv"));
|
return static_cast<BS_MoviePlayer *>(GetService("fmv"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the window object
|
* Returns a pointer to the window object
|
||||||
*/
|
*/
|
||||||
BS_Window *GetWindow() { return _pWindow; }
|
BS_Window *GetWindow() {
|
||||||
|
return _pWindow;
|
||||||
|
}
|
||||||
|
|
||||||
// Service Methods
|
// Service Methods
|
||||||
// ---------------
|
// ---------------
|
||||||
|
@ -139,7 +141,7 @@ public:
|
||||||
* @param SuperclassIdentifier The name of the superclass
|
* @param SuperclassIdentifier The name of the superclass
|
||||||
* z.B: "sfx", "gfx", "package" ...
|
* z.B: "sfx", "gfx", "package" ...
|
||||||
*/
|
*/
|
||||||
unsigned int GetServiceCount(const Common::String & SuperclassIdentifier);
|
unsigned int GetServiceCount(const Common::String &SuperclassIdentifier);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the identifier of a service with a given superclass.
|
* Gets the identifier of a service with a given superclass.
|
||||||
|
@ -166,11 +168,15 @@ public:
|
||||||
/**
|
/**
|
||||||
* Specifies whether the kernel was successfully initialised
|
* Specifies whether the kernel was successfully initialised
|
||||||
*/
|
*/
|
||||||
bool GetInitSuccess() { return _InitSuccess; }
|
bool GetInitSuccess() {
|
||||||
|
return _InitSuccess;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to the BS_ResourceManager
|
* Returns a pointer to the BS_ResourceManager
|
||||||
*/
|
*/
|
||||||
BS_ResourceManager *GetResourceManager() { return _pResourceManager; }
|
BS_ResourceManager *GetResourceManager() {
|
||||||
|
return _pResourceManager;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Returns how much memory is being used
|
* Returns how much memory is being used
|
||||||
*/
|
*/
|
||||||
|
@ -264,19 +270,27 @@ private:
|
||||||
Common::String _ActiveServiceName;
|
Common::String _ActiveServiceName;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Superclass (BS_Kernel *pKernel, const Common::String &Identifier);
|
Superclass(BS_Kernel *pKernel, const Common::String &Identifier);
|
||||||
~Superclass();
|
~Superclass();
|
||||||
|
|
||||||
unsigned int GetServiceCount() const { return _ServiceCount; }
|
unsigned int GetServiceCount() const {
|
||||||
Common::String GetIdentifier() const { return _Identifier; }
|
return _ServiceCount;
|
||||||
BS_Service *GetActiveService() const { return _ActiveService; }
|
}
|
||||||
Common::String GetActiveServiceName() const { return _ActiveServiceName; }
|
Common::String GetIdentifier() const {
|
||||||
|
return _Identifier;
|
||||||
|
}
|
||||||
|
BS_Service *GetActiveService() const {
|
||||||
|
return _ActiveService;
|
||||||
|
}
|
||||||
|
Common::String GetActiveServiceName() const {
|
||||||
|
return _ActiveServiceName;
|
||||||
|
}
|
||||||
Common::String GetServiceIdentifier(unsigned int Number);
|
Common::String GetServiceIdentifier(unsigned int Number);
|
||||||
BS_Service *NewService(const Common::String &ServiceIdentifier);
|
BS_Service *NewService(const Common::String &ServiceIdentifier);
|
||||||
bool DisconnectService();
|
bool DisconnectService();
|
||||||
};
|
};
|
||||||
|
|
||||||
Common::Array<Superclass*> _SuperclassList;
|
Common::Array<Superclass *> _SuperclassList;
|
||||||
Common::Stack<Common::String> _ServiceCreationOrder;
|
Common::Stack<Common::String> _ServiceCreationOrder;
|
||||||
Superclass *GetSuperclassByIdentifier(const Common::String &Identifier);
|
Superclass *GetSuperclassByIdentifier(const Common::String &Identifier);
|
||||||
|
|
||||||
|
@ -327,8 +341,8 @@ private:
|
||||||
*/
|
*/
|
||||||
class BS_ServiceInfo {
|
class BS_ServiceInfo {
|
||||||
public:
|
public:
|
||||||
BS_ServiceInfo(const Common::String &SuperclassIdentifier_, const Common::String& ServiceIdentifier_,
|
BS_ServiceInfo(const Common::String &SuperclassIdentifier_, const Common::String &ServiceIdentifier_,
|
||||||
BS_Service* (*CreateMethod_)(BS_Kernel*)) {
|
BS_Service*(*CreateMethod_)(BS_Kernel *)) {
|
||||||
this->SuperclassIdentifier = SuperclassIdentifier_;
|
this->SuperclassIdentifier = SuperclassIdentifier_;
|
||||||
this->ServiceIdentifier = ServiceIdentifier_;
|
this->ServiceIdentifier = ServiceIdentifier_;
|
||||||
this->CreateMethod = CreateMethod_;
|
this->CreateMethod = CreateMethod_;
|
||||||
|
@ -336,7 +350,7 @@ public:
|
||||||
|
|
||||||
Common::String SuperclassIdentifier;
|
Common::String SuperclassIdentifier;
|
||||||
Common::String ServiceIdentifier;
|
Common::String ServiceIdentifier;
|
||||||
BS_Service* (*CreateMethod)(BS_Kernel *);
|
BS_Service*(*CreateMethod)(BS_Kernel *);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|
|
@ -64,7 +64,7 @@ static int GetActiveServiceIdentifier(lua_State *L) {
|
||||||
BS_Kernel *pKernel = BS_Kernel::GetInstance();
|
BS_Kernel *pKernel = BS_Kernel::GetInstance();
|
||||||
BS_ASSERT(pKernel);
|
BS_ASSERT(pKernel);
|
||||||
|
|
||||||
lua_pushstring(L, pKernel->GetActiveServiceIdentifier(luaL_checkstring(L,1)).c_str());
|
lua_pushstring(L, pKernel->GetActiveServiceIdentifier(luaL_checkstring(L, 1)).c_str());
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ static int GetSuperclassIdentifier(lua_State *L) {
|
||||||
BS_ASSERT(pKernel);
|
BS_ASSERT(pKernel);
|
||||||
|
|
||||||
lua_pushstring(L, pKernel->GetSuperclassIdentifier(
|
lua_pushstring(L, pKernel->GetSuperclassIdentifier(
|
||||||
static_cast<unsigned int>(luaL_checknumber(L,1))).c_str());
|
static_cast<unsigned int>(luaL_checknumber(L, 1))).c_str());
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ static int Crash(lua_State *L) {
|
||||||
static int ExecuteFile(lua_State *L) {
|
static int ExecuteFile(lua_State *L) {
|
||||||
BS_Kernel *pKernel = BS_Kernel::GetInstance();
|
BS_Kernel *pKernel = BS_Kernel::GetInstance();
|
||||||
BS_ASSERT(pKernel);
|
BS_ASSERT(pKernel);
|
||||||
BS_ScriptEngine * pSE = static_cast<BS_ScriptEngine *>(pKernel->GetService("script"));
|
BS_ScriptEngine *pSE = static_cast<BS_ScriptEngine *>(pKernel->GetService("script"));
|
||||||
BS_ASSERT(pSE);
|
BS_ASSERT(pSE);
|
||||||
|
|
||||||
lua_pushbooleancpp(L, pSE->ExecuteFile(luaL_checkstring(L, 1)));
|
lua_pushbooleancpp(L, pSE->ExecuteFile(luaL_checkstring(L, 1)));
|
||||||
|
@ -231,7 +231,7 @@ static int GetUsedMemory(lua_State *L) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static const char * KERNEL_LIBRARY_NAME = "Kernel";
|
static const char *KERNEL_LIBRARY_NAME = "Kernel";
|
||||||
|
|
||||||
static const luaL_reg KERNEL_FUNCTIONS[] = {
|
static const luaL_reg KERNEL_FUNCTIONS[] = {
|
||||||
"DisconnectService", DisconnectService,
|
"DisconnectService", DisconnectService,
|
||||||
|
@ -492,7 +492,7 @@ static int HasFocus(lua_State *L) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static const char * WINDOW_LIBRARY_NAME = "Window";
|
static const char *WINDOW_LIBRARY_NAME = "Window";
|
||||||
|
|
||||||
static const luaL_reg WINDOW_FUNCTIONS[] = {
|
static const luaL_reg WINDOW_FUNCTIONS[] = {
|
||||||
"IsVisible", IsVisible,
|
"IsVisible", IsVisible,
|
||||||
|
@ -622,7 +622,7 @@ static int DumpLockedResources(lua_State *L) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static const char * RESOURCE_LIBRARY_NAME = "Resource";
|
static const char *RESOURCE_LIBRARY_NAME = "Resource";
|
||||||
|
|
||||||
static const luaL_reg RESOURCE_FUNCTIONS[] = {
|
static const luaL_reg RESOURCE_FUNCTIONS[] = {
|
||||||
"PrecacheResource", PrecacheResource,
|
"PrecacheResource", PrecacheResource,
|
||||||
|
@ -705,7 +705,7 @@ static int SaveGame(lua_State *L) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static const char * PERSISTENCE_LIBRARY_NAME = "Persistence";
|
static const char *PERSISTENCE_LIBRARY_NAME = "Persistence";
|
||||||
|
|
||||||
static const luaL_reg PERSISTENCE_FUNCTIONS[] = {
|
static const luaL_reg PERSISTENCE_FUNCTIONS[] = {
|
||||||
"ReloadSlots", ReloadSlots,
|
"ReloadSlots", ReloadSlots,
|
||||||
|
@ -723,7 +723,7 @@ static const luaL_reg PERSISTENCE_FUNCTIONS[] = {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Kernel::_RegisterScriptBindings() {
|
bool BS_Kernel::_RegisterScriptBindings() {
|
||||||
BS_ScriptEngine * pScript = static_cast<BS_ScriptEngine *>(GetService("script"));
|
BS_ScriptEngine *pScript = static_cast<BS_ScriptEngine *>(GetService("script"));
|
||||||
BS_ASSERT(pScript);
|
BS_ASSERT(pScript);
|
||||||
lua_State *L = static_cast<lua_State *>(pScript->GetScriptObject());
|
lua_State *L = static_cast<lua_State *>(pScript->GetScriptObject());
|
||||||
BS_ASSERT(L);
|
BS_ASSERT(L);
|
||||||
|
|
|
@ -46,10 +46,10 @@ static const size_t LOG_BUFFERSIZE = 1024 * 16;
|
||||||
// Logging will take place only when it's activated
|
// Logging will take place only when it's activated
|
||||||
#ifdef BS_ACTIVATE_LOGGING
|
#ifdef BS_ACTIVATE_LOGGING
|
||||||
|
|
||||||
Common::WriteStream* BS_Log::_LogFile = NULL;
|
Common::WriteStream *BS_Log::_LogFile = NULL;
|
||||||
bool BS_Log::_LineBegin = true;
|
bool BS_Log::_LineBegin = true;
|
||||||
const char * BS_Log::_Prefix = NULL;
|
const char *BS_Log::_Prefix = NULL;
|
||||||
const char * BS_Log::_File = NULL;
|
const char *BS_Log::_File = NULL;
|
||||||
int BS_Log::_Line = 0;
|
int BS_Log::_Line = 0;
|
||||||
bool BS_Log::_AutoNewline = false;
|
bool BS_Log::_AutoNewline = false;
|
||||||
Common::Array<BS_Log::LOG_LISTENER_CALLBACK> BS_Log::_LogListener;
|
Common::Array<BS_Log::LOG_LISTENER_CALLBACK> BS_Log::_LogListener;
|
||||||
|
@ -183,7 +183,7 @@ void BS_Log::LogDecorated(const char *Format, ...) {
|
||||||
_FlushLog();
|
_FlushLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
int BS_Log::_WriteLog(const char * Message) {
|
int BS_Log::_WriteLog(const char *Message) {
|
||||||
if (!_LogFile) if (!_CreateLog()) return false;
|
if (!_LogFile) if (!_CreateLog()) return false;
|
||||||
|
|
||||||
Common::Array<LOG_LISTENER_CALLBACK>::iterator Iter = _LogListener.begin();
|
Common::Array<LOG_LISTENER_CALLBACK>::iterator Iter = _LogListener.begin();
|
||||||
|
@ -207,7 +207,7 @@ void BS_Log_C(const char *Message) {
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
void BS_Log_C(const char* Message) {};
|
void BS_Log_C(const char *Message) {};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -56,21 +56,30 @@ namespace Sword25 {
|
||||||
#define BS_LOG_EXTERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
#define BS_LOG_EXTERRORLN BS_Log::SetPrefix(BS_LOG_PREFIX ": ERROR "), BS_Log::SetFile(__FILE__), BS_Log::SetLine(__LINE__), BS_Log::SetAutoNewline(true), BS_Log::LogDecorated
|
||||||
|
|
||||||
// Die Version der Logging-Klasse mit aktiviertem Logging
|
// Die Version der Logging-Klasse mit aktiviertem Logging
|
||||||
class BS_Log
|
class BS_Log {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static void Clear();
|
static void Clear();
|
||||||
static void Log(const char* Format, ...);
|
static void Log(const char *Format, ...);
|
||||||
static void LogPrefix(const char* Prefix, const char* Format, ...);
|
static void LogPrefix(const char *Prefix, const char *Format, ...);
|
||||||
static void LogDecorated(const char* Format, ...);
|
static void LogDecorated(const char *Format, ...);
|
||||||
|
|
||||||
static void SetPrefix(const char* Prefix) { _Prefix = Prefix; }
|
static void SetPrefix(const char *Prefix) {
|
||||||
static void SetFile(const char* File) { _File = File; }
|
_Prefix = Prefix;
|
||||||
static void SetLine(int Line) { _Line = Line; }
|
}
|
||||||
static void SetAutoNewline(bool AutoNewline) { _AutoNewline = AutoNewline; }
|
static void SetFile(const char *File) {
|
||||||
|
_File = File;
|
||||||
|
}
|
||||||
|
static void SetLine(int Line) {
|
||||||
|
_Line = Line;
|
||||||
|
}
|
||||||
|
static void SetAutoNewline(bool AutoNewline) {
|
||||||
|
_AutoNewline = AutoNewline;
|
||||||
|
}
|
||||||
|
|
||||||
typedef void (*LOG_LISTENER_CALLBACK)(const char *);
|
typedef void (*LOG_LISTENER_CALLBACK)(const char *);
|
||||||
static void RegisterLogListener(LOG_LISTENER_CALLBACK Callback) { _LogListener.push_back(Callback); }
|
static void RegisterLogListener(LOG_LISTENER_CALLBACK Callback) {
|
||||||
|
_LogListener.push_back(Callback);
|
||||||
|
}
|
||||||
static bool IsListenerRegistered(LOG_LISTENER_CALLBACK Callback) {
|
static bool IsListenerRegistered(LOG_LISTENER_CALLBACK Callback) {
|
||||||
Common::Array<LOG_LISTENER_CALLBACK>::iterator i;
|
Common::Array<LOG_LISTENER_CALLBACK>::iterator i;
|
||||||
for (i = _LogListener.begin(); i != _LogListener.end(); ++i) {
|
for (i = _LogListener.begin(); i != _LogListener.end(); ++i) {
|
||||||
|
@ -82,17 +91,17 @@ public:
|
||||||
static void _CloseLog();
|
static void _CloseLog();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Common::WriteStream * _LogFile;
|
static Common::WriteStream *_LogFile;
|
||||||
static bool _LineBegin;
|
static bool _LineBegin;
|
||||||
static const char * _Prefix;
|
static const char *_Prefix;
|
||||||
static const char * _File;
|
static const char *_File;
|
||||||
static int _Line;
|
static int _Line;
|
||||||
static bool _AutoNewline;
|
static bool _AutoNewline;
|
||||||
static Common::Array<LOG_LISTENER_CALLBACK> _LogListener;
|
static Common::Array<LOG_LISTENER_CALLBACK> _LogListener;
|
||||||
|
|
||||||
static bool _CreateLog();
|
static bool _CreateLog();
|
||||||
|
|
||||||
static int _WriteLog(const char* Message);
|
static int _WriteLog(const char *Message);
|
||||||
static void _FlushLog();
|
static void _FlushLog();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -116,12 +125,12 @@ private:
|
||||||
class BS_Log {
|
class BS_Log {
|
||||||
public:
|
public:
|
||||||
// This version implements all the various methods as empty stubs
|
// This version implements all the various methods as empty stubs
|
||||||
static void Log(const char* Text, ...) {};
|
static void Log(const char *Text, ...) {};
|
||||||
static void LogPrefix(const char* Prefix, const char* Format, ...) {};
|
static void LogPrefix(const char *Prefix, const char *Format, ...) {};
|
||||||
static void LogDecorated(const char* Format, ...) {};
|
static void LogDecorated(const char *Format, ...) {};
|
||||||
|
|
||||||
static void SetPrefix(const char* Prefix) {};
|
static void SetPrefix(const char *Prefix) {};
|
||||||
static void SetFile(const char* File) {};
|
static void SetFile(const char *File) {};
|
||||||
static void SetLine(int Line) {};
|
static void SetLine(int Line) {};
|
||||||
static void SetAutoNewline(bool AutoNewline) {};
|
static void SetAutoNewline(bool AutoNewline) {};
|
||||||
|
|
||||||
|
|
|
@ -53,49 +53,42 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct
|
typedef struct {
|
||||||
{
|
|
||||||
unsigned int address;
|
unsigned int address;
|
||||||
unsigned int size;
|
unsigned int size;
|
||||||
std::string file;
|
std::string file;
|
||||||
unsigned int line;
|
unsigned int line;
|
||||||
} ALLOC_INFO;
|
} ALLOC_INFO;
|
||||||
|
|
||||||
static const char * MEMLEAK_LOG_FILE = "memory_leaks.txt";
|
static const char *MEMLEAK_LOG_FILE = "memory_leaks.txt";
|
||||||
static const unsigned int BUCKET_COUNT = 1021;
|
static const unsigned int BUCKET_COUNT = 1021;
|
||||||
std::vector< std::vector<ALLOC_INFO> > TrackData(BUCKET_COUNT);
|
std::vector< std::vector<ALLOC_INFO> > TrackData(BUCKET_COUNT);
|
||||||
|
|
||||||
static unsigned int TotalSize = 0;
|
static unsigned int TotalSize = 0;
|
||||||
|
|
||||||
// Diese Klasse stellt sicher, dass beim Programmende, das Memory-Leak Log geschrieben wird.
|
// Diese Klasse stellt sicher, dass beim Programmende, das Memory-Leak Log geschrieben wird.
|
||||||
static class LeakDumper
|
static class LeakDumper {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
LeakDumper() : OutputFilename(BS_FileSystemUtil::GetInstance().GetUserdataDirectory() + "\\" + MEMLEAK_LOG_FILE)
|
LeakDumper() : OutputFilename(BS_FileSystemUtil::GetInstance().GetUserdataDirectory() + "\\" + MEMLEAK_LOG_FILE) {
|
||||||
{
|
|
||||||
// Sicherstellen, dass das Ausgabeverzeichnis für die Datei existiert.
|
// Sicherstellen, dass das Ausgabeverzeichnis für die Datei existiert.
|
||||||
BS_FileSystemUtil::GetInstance().CreateDirectory(BS_FileSystemUtil::GetInstance().GetUserdataDirectory());
|
BS_FileSystemUtil::GetInstance().CreateDirectory(BS_FileSystemUtil::GetInstance().GetUserdataDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
~LeakDumper()
|
~LeakDumper() {
|
||||||
{
|
|
||||||
DumpUnfreed(OutputFilename.c_str());
|
DumpUnfreed(OutputFilename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string OutputFilename;
|
std::string OutputFilename;
|
||||||
} LeakDumperInstance;
|
} LeakDumperInstance;
|
||||||
|
|
||||||
void DumpUnfreed(const char * OutputFilename)
|
void DumpUnfreed(const char *OutputFilename) {
|
||||||
{
|
FILE *Log = fopen(OutputFilename, "w");
|
||||||
FILE * Log = fopen(OutputFilename, "w");
|
|
||||||
fputs("MEMORY LEAK REPORT:\n----------------------\n", Log);
|
fputs("MEMORY LEAK REPORT:\n----------------------\n", Log);
|
||||||
std::vector< std::vector<ALLOC_INFO> >::iterator BucketIter = TrackData.begin();
|
std::vector< std::vector<ALLOC_INFO> >::iterator BucketIter = TrackData.begin();
|
||||||
for (; BucketIter != TrackData.end(); ++BucketIter)
|
for (; BucketIter != TrackData.end(); ++BucketIter) {
|
||||||
{
|
|
||||||
std::vector<ALLOC_INFO>::iterator Iter = (*BucketIter).begin();
|
std::vector<ALLOC_INFO>::iterator Iter = (*BucketIter).begin();
|
||||||
for (; Iter != (*BucketIter).end(); ++Iter)
|
for (; Iter != (*BucketIter).end(); ++Iter) {
|
||||||
{
|
ALLOC_INFO &CurItem = (*Iter);
|
||||||
ALLOC_INFO & CurItem = (*Iter);
|
|
||||||
fprintf(Log, "%-50s LINE:%d ADDRESS:0x%x SIZE:%d\n",
|
fprintf(Log, "%-50s LINE:%d ADDRESS:0x%x SIZE:%d\n",
|
||||||
CurItem.file.c_str(),
|
CurItem.file.c_str(),
|
||||||
CurItem.line,
|
CurItem.line,
|
||||||
|
@ -109,8 +102,7 @@ void DumpUnfreed(const char * OutputFilename)
|
||||||
fclose(Log);
|
fclose(Log);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum)
|
void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum) {
|
||||||
{
|
|
||||||
std::vector<ALLOC_INFO> & CurBucket = TrackData[(addr >> 3) % BUCKET_COUNT];
|
std::vector<ALLOC_INFO> & CurBucket = TrackData[(addr >> 3) % BUCKET_COUNT];
|
||||||
ALLOC_INFO Info;
|
ALLOC_INFO Info;
|
||||||
Info.address = addr;
|
Info.address = addr;
|
||||||
|
@ -122,16 +114,12 @@ void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsign
|
||||||
TotalSize += asize;
|
TotalSize += asize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveTrack(unsigned int addr)
|
void RemoveTrack(unsigned int addr) {
|
||||||
{
|
if (addr != 0 && TrackData.size() == BUCKET_COUNT) {
|
||||||
if (addr != 0 && TrackData.size() == BUCKET_COUNT)
|
|
||||||
{
|
|
||||||
std::vector<ALLOC_INFO> & CurBucket = TrackData[(addr >> 3) % BUCKET_COUNT];
|
std::vector<ALLOC_INFO> & CurBucket = TrackData[(addr >> 3) % BUCKET_COUNT];
|
||||||
std::vector<ALLOC_INFO>::iterator Iter = CurBucket.begin();
|
std::vector<ALLOC_INFO>::iterator Iter = CurBucket.begin();
|
||||||
for (; Iter != CurBucket.end(); ++Iter)
|
for (; Iter != CurBucket.end(); ++Iter) {
|
||||||
{
|
if ((*Iter).address == addr) {
|
||||||
if ((*Iter).address == addr)
|
|
||||||
{
|
|
||||||
TotalSize -= (*Iter).size;
|
TotalSize -= (*Iter).size;
|
||||||
|
|
||||||
std::swap(*Iter, CurBucket.back());
|
std::swap(*Iter, CurBucket.back());
|
||||||
|
|
|
@ -43,25 +43,22 @@
|
||||||
|
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
|
||||||
void DumpUnfreed(const char * OutputFilename);
|
void DumpUnfreed(const char *OutputFilename);
|
||||||
void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum);
|
void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum);
|
||||||
void RemoveTrack(unsigned int addr);
|
void RemoveTrack(unsigned int addr);
|
||||||
|
|
||||||
inline void * __cdecl operator new(unsigned int size, const char *file, int line)
|
inline void *__cdecl operator new(unsigned int size, const char *file, int line) {
|
||||||
{
|
|
||||||
void *ptr = malloc(size);
|
void *ptr = malloc(size);
|
||||||
if (ptr) AddTrack((unsigned int)ptr, size, file, line);
|
if (ptr) AddTrack((unsigned int)ptr, size, file, line);
|
||||||
return(ptr);
|
return(ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void __cdecl operator delete(void *p)
|
inline void __cdecl operator delete(void *p) {
|
||||||
{
|
|
||||||
RemoveTrack((unsigned int)p);
|
RemoveTrack((unsigned int)p);
|
||||||
free(p);
|
free(p);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void __cdecl operator delete[](void *p)
|
inline void __cdecl operator delete[](void *p) {
|
||||||
{
|
|
||||||
RemoveTrack((unsigned int)p);
|
RemoveTrack((unsigned int)p);
|
||||||
free(p);
|
free(p);
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
// Deaktivieren der Memory-Leak Detektion
|
// Deaktivieren der Memory-Leak Detektion
|
||||||
|
|
||||||
#ifdef BS_MEMLOG
|
#ifdef BS_MEMLOG
|
||||||
#ifdef new
|
#ifdef new
|
||||||
#undef new
|
#undef new
|
||||||
#undef DEBUG_NEW
|
#undef DEBUG_NEW
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
// Aktivieren der Memory-Leak Detektion
|
// Aktivieren der Memory-Leak Detektion
|
||||||
|
|
||||||
#ifdef BS_MEMLOG
|
#ifdef BS_MEMLOG
|
||||||
#ifndef DEBUG_NEW
|
#ifndef DEBUG_NEW
|
||||||
#define DEBUG_NEW new(__FILE__, __LINE__)
|
#define DEBUG_NEW new(__FILE__, __LINE__)
|
||||||
#endif
|
#endif
|
||||||
#define new DEBUG_NEW
|
#define new DEBUG_NEW
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -150,7 +150,9 @@ public:
|
||||||
protected:
|
protected:
|
||||||
// FIXME: I'm not entirely sure my current hash function is legitimate
|
// FIXME: I'm not entirely sure my current hash function is legitimate
|
||||||
struct ClassPointer_EqualTo {
|
struct ClassPointer_EqualTo {
|
||||||
bool operator()(const T *x, const T *y) const { return x == y; }
|
bool operator()(const T *x, const T *y) const {
|
||||||
|
return x == y;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
struct ClassPointer_Hash {
|
struct ClassPointer_Hash {
|
||||||
uint operator()(const T *x) const {
|
uint operator()(const T *x) const {
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const unsigned int INITIAL_BUFFER_SIZE = 1024 * 64;
|
const unsigned int INITIAL_BUFFER_SIZE = 1024 * 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Sword25 {
|
namespace Sword25 {
|
||||||
|
|
|
@ -59,8 +59,12 @@ public:
|
||||||
void Write(const Common::String &String);
|
void Write(const Common::String &String);
|
||||||
void Write(const void *BufferPtr, size_t Size);
|
void Write(const void *BufferPtr, size_t Size);
|
||||||
|
|
||||||
const void *GetData() const { return &m_Data[0]; }
|
const void *GetData() const {
|
||||||
unsigned int GetDataSize() const { return m_Data.size(); }
|
return &m_Data[0];
|
||||||
|
}
|
||||||
|
unsigned int GetDataSize() const {
|
||||||
|
return m_Data.size();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WriteMarker(unsigned char Marker);
|
void WriteMarker(unsigned char Marker);
|
||||||
|
|
|
@ -44,8 +44,8 @@ class BS_Persistable {
|
||||||
public:
|
public:
|
||||||
virtual ~BS_Persistable() {};
|
virtual ~BS_Persistable() {};
|
||||||
|
|
||||||
virtual bool Persist(BS_OutputPersistenceBlock & Writer) = 0;
|
virtual bool Persist(BS_OutputPersistenceBlock &Writer) = 0;
|
||||||
virtual bool Unpersist(BS_InputPersistenceBlock & Reader) = 0;
|
virtual bool Unpersist(BS_InputPersistenceBlock &Reader) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sword25
|
} // End of namespace Sword25
|
||||||
|
|
|
@ -49,10 +49,18 @@ namespace Sword25 {
|
||||||
|
|
||||||
class BS_PersistenceBlock {
|
class BS_PersistenceBlock {
|
||||||
public:
|
public:
|
||||||
static unsigned int GetSInt32Size() { return sizeof(signed int) + sizeof(unsigned char); }
|
static unsigned int GetSInt32Size() {
|
||||||
static unsigned int GetUInt32Size() { return sizeof(unsigned int) + sizeof(unsigned char); }
|
return sizeof(signed int) + sizeof(unsigned char);
|
||||||
static unsigned int GetFloat32Size() { return sizeof(float) + sizeof(unsigned char); }
|
}
|
||||||
static unsigned int GetBoolSize() { return sizeof(unsigned char) + sizeof(unsigned char); }
|
static unsigned int GetUInt32Size() {
|
||||||
|
return sizeof(unsigned int) + sizeof(unsigned char);
|
||||||
|
}
|
||||||
|
static unsigned int GetFloat32Size() {
|
||||||
|
return sizeof(float) + sizeof(unsigned char);
|
||||||
|
}
|
||||||
|
static unsigned int GetBoolSize() {
|
||||||
|
return sizeof(unsigned char) + sizeof(unsigned char);
|
||||||
|
}
|
||||||
static unsigned int GetStringSize(const Common::String &String) {
|
static unsigned int GetStringSize(const Common::String &String) {
|
||||||
return static_cast<unsigned int>(sizeof(unsigned int) + String.size() + sizeof(unsigned char));
|
return static_cast<unsigned int>(sizeof(unsigned int) + String.size() + sizeof(unsigned char));
|
||||||
}
|
}
|
||||||
|
@ -90,7 +98,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
static bool IsBigEndian() {
|
static bool IsBigEndian() {
|
||||||
unsigned int Dummy = 1;
|
unsigned int Dummy = 1;
|
||||||
unsigned char * DummyPtr = reinterpret_cast<unsigned char *>(&Dummy);
|
unsigned char *DummyPtr = reinterpret_cast<unsigned char *>(&Dummy);
|
||||||
return DummyPtr[0] == 0;
|
return DummyPtr[0] == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +111,7 @@ private:
|
||||||
|
|
||||||
static void ReverseByteOrder(void *Ptr) {
|
static void ReverseByteOrder(void *Ptr) {
|
||||||
// Reverses the byte order of the 32-bit word pointed to by Ptr
|
// Reverses the byte order of the 32-bit word pointed to by Ptr
|
||||||
unsigned char * CharPtr = static_cast<unsigned char *>(Ptr);
|
unsigned char *CharPtr = static_cast<unsigned char *>(Ptr);
|
||||||
Swap(CharPtr[0], CharPtr[3]);
|
Swap(CharPtr[0], CharPtr[3]);
|
||||||
Swap(CharPtr[1], CharPtr[2]);
|
Swap(CharPtr[1], CharPtr[2]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,35 +58,35 @@ using namespace std;
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace Sword25 {
|
namespace Sword25 {
|
||||||
const char * SAVEGAME_EXTENSION = ".b25s";
|
const char *SAVEGAME_EXTENSION = ".b25s";
|
||||||
const char * SAVEGAME_DIRECTORY = "saves";
|
const char *SAVEGAME_DIRECTORY = "saves";
|
||||||
const char * FILE_MARKER = "BS25SAVEGAME";
|
const char *FILE_MARKER = "BS25SAVEGAME";
|
||||||
const unsigned int SLOT_COUNT = 18;
|
const unsigned int SLOT_COUNT = 18;
|
||||||
const unsigned int FILE_COPY_BUFFER_SIZE = 1024 * 10;
|
const unsigned int FILE_COPY_BUFFER_SIZE = 1024 * 10;
|
||||||
const char *VERSIONID = "1";
|
const char *VERSIONID = "1";
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
Common::String GenerateSavegameFilename(unsigned int SlotID) {
|
Common::String GenerateSavegameFilename(unsigned int SlotID) {
|
||||||
Common::String oss;
|
Common::String oss;
|
||||||
oss += SlotID;
|
oss += SlotID;
|
||||||
oss += SAVEGAME_EXTENSION;
|
oss += SAVEGAME_EXTENSION;
|
||||||
return oss;
|
return oss;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
Common::String GenerateSavegamePath(unsigned int SlotID) {
|
Common::String GenerateSavegamePath(unsigned int SlotID) {
|
||||||
Common::String oss;
|
Common::String oss;
|
||||||
oss = BS_PersistenceService::GetSavegameDirectory();
|
oss = BS_PersistenceService::GetSavegameDirectory();
|
||||||
oss += BS_FileSystemUtil::GetInstance().GetPathSeparator();
|
oss += BS_FileSystemUtil::GetInstance().GetPathSeparator();
|
||||||
oss += GenerateSavegameFilename(SlotID);
|
oss += GenerateSavegameFilename(SlotID);
|
||||||
return oss;
|
return oss;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
Common::String FormatTimestamp(TimeDate Time) {
|
Common::String FormatTimestamp(TimeDate Time) {
|
||||||
// In the original BS2.5 engine, this used a local object to show the date/time as as a string.
|
// In the original BS2.5 engine, this used a local object to show the date/time as as a string.
|
||||||
// For now in ScummVM it's being hardcoded to 'dd-MON-yyyy hh:mm:ss'
|
// For now in ScummVM it's being hardcoded to 'dd-MON-yyyy hh:mm:ss'
|
||||||
Common::String monthList[12] = {
|
Common::String monthList[12] = {
|
||||||
|
@ -99,11 +99,11 @@ namespace Sword25 {
|
||||||
);
|
);
|
||||||
|
|
||||||
return Common::String(buffer);
|
return Common::String(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
Common::String LoadString(Common::InSaveFile *In, uint MaxSize = 999) {
|
Common::String LoadString(Common::InSaveFile *In, uint MaxSize = 999) {
|
||||||
Common::String Result;
|
Common::String Result;
|
||||||
char ch;
|
char ch;
|
||||||
while ((ch = (char)In->readByte()) != '\0') {
|
while ((ch = (char)In->readByte()) != '\0') {
|
||||||
|
@ -112,7 +112,7 @@ namespace Sword25 {
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Sword25 {
|
namespace Sword25 {
|
||||||
|
@ -130,7 +130,9 @@ struct SavegameInformation {
|
||||||
unsigned int GamedataOffset;
|
unsigned int GamedataOffset;
|
||||||
unsigned int GamedataUncompressedLength;
|
unsigned int GamedataUncompressedLength;
|
||||||
|
|
||||||
SavegameInformation() { Clear(); }
|
SavegameInformation() {
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
void Clear() {
|
void Clear() {
|
||||||
IsOccupied = false;
|
IsOccupied = false;
|
||||||
|
@ -163,7 +165,7 @@ struct BS_PersistenceService::Impl {
|
||||||
|
|
||||||
void ReadSlotSavegameInformation(unsigned int SlotID) {
|
void ReadSlotSavegameInformation(unsigned int SlotID) {
|
||||||
// Aktuelle Slotinformationen in den Ausgangszustand versetzen, er wird im Folgenden neu gefüllt.
|
// Aktuelle Slotinformationen in den Ausgangszustand versetzen, er wird im Folgenden neu gefüllt.
|
||||||
SavegameInformation & CurSavegameInfo = m_SavegameInformations[SlotID];
|
SavegameInformation &CurSavegameInfo = m_SavegameInformations[SlotID];
|
||||||
CurSavegameInfo.Clear();
|
CurSavegameInfo.Clear();
|
||||||
|
|
||||||
// Den Dateinamen für den Spielstand des Slots generieren.
|
// Den Dateinamen für den Spielstand des Slots generieren.
|
||||||
|
@ -207,7 +209,7 @@ struct BS_PersistenceService::Impl {
|
||||||
// Construction / Destruction
|
// Construction / Destruction
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
BS_PersistenceService & BS_PersistenceService::GetInstance() {
|
BS_PersistenceService &BS_PersistenceService::GetInstance() {
|
||||||
static BS_PersistenceService Instance;
|
static BS_PersistenceService Instance;
|
||||||
return Instance;
|
return Instance;
|
||||||
}
|
}
|
||||||
|
@ -246,7 +248,7 @@ Common::String BS_PersistenceService::GetSavegameDirectory() {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
bool CheckSlotID(unsigned int SlotID) {
|
bool CheckSlotID(unsigned int SlotID) {
|
||||||
// Überprüfen, ob die Slot-ID zulässig ist.
|
// Überprüfen, ob die Slot-ID zulässig ist.
|
||||||
if (SlotID >= SLOT_COUNT) {
|
if (SlotID >= SLOT_COUNT) {
|
||||||
BS_LOG_ERRORLN("Tried to access an invalid slot (%d). Only slot ids from 0 to %d are allowed.", SlotID, SLOT_COUNT - 1);
|
BS_LOG_ERRORLN("Tried to access an invalid slot (%d). Only slot ids from 0 to %d are allowed.", SlotID, SLOT_COUNT - 1);
|
||||||
|
@ -254,7 +256,7 @@ namespace {
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
@ -386,7 +388,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SavegameInformation & CurSavegameInfo = m_impl->m_SavegameInformations[SlotID];
|
SavegameInformation &CurSavegameInfo = m_impl->m_SavegameInformations[SlotID];
|
||||||
|
|
||||||
// Überprüfen, ob der Slot belegt ist.
|
// Überprüfen, ob der Slot belegt ist.
|
||||||
if (!CurSavegameInfo.IsOccupied) {
|
if (!CurSavegameInfo.IsOccupied) {
|
||||||
|
@ -398,8 +400,7 @@ bool BS_PersistenceService::LoadGame(unsigned int SlotID) {
|
||||||
// Im Debug-Modus wird dieser Test übersprungen. Für das Testen ist es hinderlich auf die Einhaltung dieser strengen Bedingung zu bestehen,
|
// Im Debug-Modus wird dieser Test übersprungen. Für das Testen ist es hinderlich auf die Einhaltung dieser strengen Bedingung zu bestehen,
|
||||||
// da sich die Versions-ID bei jeder Codeänderung mitändert.
|
// da sich die Versions-ID bei jeder Codeänderung mitändert.
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
if (!CurSavegameInfo.IsCompatible)
|
if (!CurSavegameInfo.IsCompatible) {
|
||||||
{
|
|
||||||
BS_LOG_ERRORLN("Tried to load a savegame (%d) that is not compatible with this engine version.", SlotID);
|
BS_LOG_ERRORLN("Tried to load a savegame (%d) that is not compatible with this engine version.", SlotID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,12 +71,12 @@ public:
|
||||||
Common::String &GetSavegameDescription(unsigned int SlotID);
|
Common::String &GetSavegameDescription(unsigned int SlotID);
|
||||||
Common::String &GetSavegameFilename(unsigned int SlotID);
|
Common::String &GetSavegameFilename(unsigned int SlotID);
|
||||||
|
|
||||||
bool SaveGame(unsigned int SlotID, const Common::String & ScreenshotFilename);
|
bool SaveGame(unsigned int SlotID, const Common::String &ScreenshotFilename);
|
||||||
bool LoadGame(unsigned int SlotID);
|
bool LoadGame(unsigned int SlotID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Impl;
|
struct Impl;
|
||||||
Impl * m_impl;
|
Impl *m_impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sword25
|
} // End of namespace Sword25
|
||||||
|
|
|
@ -53,7 +53,9 @@ BS_ResourceManager::~BS_ResourceManager() {
|
||||||
BS_LOG_WARNINGLN("Resource \"%s\" was not released.", (*Iter)->GetFileName().c_str());
|
BS_LOG_WARNINGLN("Resource \"%s\" was not released.", (*Iter)->GetFileName().c_str());
|
||||||
|
|
||||||
// Set the lock count to zero
|
// Set the lock count to zero
|
||||||
while ((*Iter)->GetLockCount() > 0) { (*Iter)->Release(); };
|
while ((*Iter)->GetLockCount() > 0) {
|
||||||
|
(*Iter)->Release();
|
||||||
|
};
|
||||||
|
|
||||||
// Delete the resource
|
// Delete the resource
|
||||||
delete(*Iter);
|
delete(*Iter);
|
||||||
|
@ -74,7 +76,7 @@ BS_Resource *BS_ResourceManager::GetResourceByOrdinal(int Ord) const {
|
||||||
|
|
||||||
// Liste durchlaufen und die Resource mit dem gewünschten Index zurückgeben.
|
// Liste durchlaufen und die Resource mit dem gewünschten Index zurückgeben.
|
||||||
int CurOrd = 0;
|
int CurOrd = 0;
|
||||||
Common::List<BS_Resource*>::const_iterator Iter = m_Resources.begin();
|
Common::List<BS_Resource *>::const_iterator Iter = m_Resources.begin();
|
||||||
for (; Iter != m_Resources.end(); ++Iter, ++CurOrd) {
|
for (; Iter != m_Resources.end(); ++Iter, ++CurOrd) {
|
||||||
if (CurOrd == Ord)
|
if (CurOrd == Ord)
|
||||||
return (*Iter);
|
return (*Iter);
|
||||||
|
@ -174,7 +176,7 @@ BS_Resource *BS_ResourceManager::RequestResource(const Common::String &FileName)
|
||||||
* @param ForceReload Indicates whether the file should be reloaded if it's already in the cache.
|
* @param ForceReload Indicates whether the file should be reloaded if it's already in the cache.
|
||||||
* This is useful for files that may have changed in the interim
|
* This is useful for files that may have changed in the interim
|
||||||
*/
|
*/
|
||||||
bool BS_ResourceManager::PrecacheResource(const Common::String& FileName, bool ForceReload) {
|
bool BS_ResourceManager::PrecacheResource(const Common::String &FileName, bool ForceReload) {
|
||||||
// Get the absolute path to the file
|
// Get the absolute path to the file
|
||||||
Common::String UniqueFileName = GetUniqueFileName(FileName);
|
Common::String UniqueFileName = GetUniqueFileName(FileName);
|
||||||
if (UniqueFileName == "")
|
if (UniqueFileName == "")
|
||||||
|
@ -252,7 +254,7 @@ BS_Resource *BS_ResourceManager::LoadResource(const Common::String &FileName) {
|
||||||
* Returns the full path of a given resource filename.
|
* Returns the full path of a given resource filename.
|
||||||
* It will return an empty string if a path could not be created.
|
* It will return an empty string if a path could not be created.
|
||||||
*/
|
*/
|
||||||
Common::String BS_ResourceManager::GetUniqueFileName(const Common::String& FileName) const {
|
Common::String BS_ResourceManager::GetUniqueFileName(const Common::String &FileName) const {
|
||||||
// Get a pointer to the package manager
|
// Get a pointer to the package manager
|
||||||
BS_PackageManager *pPackage = (BS_PackageManager *)m_KernelPtr->GetService("package");
|
BS_PackageManager *pPackage = (BS_PackageManager *)m_KernelPtr->GetService("package");
|
||||||
if (!pPackage) {
|
if (!pPackage) {
|
||||||
|
@ -281,7 +283,7 @@ Common::List<BS_Resource *>::iterator BS_ResourceManager::DeleteResource(BS_Reso
|
||||||
Common::List<BS_Resource *>::iterator Result = m_Resources.erase(pResource->_Iterator);
|
Common::List<BS_Resource *>::iterator Result = m_Resources.erase(pResource->_Iterator);
|
||||||
|
|
||||||
// Delete the resource
|
// Delete the resource
|
||||||
delete (pDummy);
|
delete(pDummy);
|
||||||
|
|
||||||
// Return the iterator
|
// Return the iterator
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -292,14 +294,13 @@ Common::List<BS_Resource *>::iterator BS_ResourceManager::DeleteResource(BS_Reso
|
||||||
* @param UniqueFileName The absolute path and filename
|
* @param UniqueFileName The absolute path and filename
|
||||||
* Gibt einen Pointer auf die angeforderte Resource zurück, oder NULL, wenn die Resourcen nicht geladen ist.
|
* Gibt einen Pointer auf die angeforderte Resource zurück, oder NULL, wenn die Resourcen nicht geladen ist.
|
||||||
*/
|
*/
|
||||||
BS_Resource * BS_ResourceManager::GetResource(const Common::String &UniqueFileName) const {
|
BS_Resource *BS_ResourceManager::GetResource(const Common::String &UniqueFileName) const {
|
||||||
// Determine whether the resource is already loaded
|
// Determine whether the resource is already loaded
|
||||||
const Common::List<BS_Resource *>& HashBucket = m_ResourceHashTable[
|
const Common::List<BS_Resource *>& HashBucket = m_ResourceHashTable[
|
||||||
BS_String::GetHash(UniqueFileName) % HASH_TABLE_BUCKETS];
|
BS_String::GetHash(UniqueFileName) % HASH_TABLE_BUCKETS];
|
||||||
{
|
{
|
||||||
Common::List<BS_Resource*>::const_iterator Iter = HashBucket.begin();
|
Common::List<BS_Resource *>::const_iterator Iter = HashBucket.begin();
|
||||||
for (; Iter != HashBucket.end(); ++Iter)
|
for (; Iter != HashBucket.end(); ++Iter) {
|
||||||
{
|
|
||||||
// Wenn die Resource gefunden wurde wird sie zurückgegeben.
|
// Wenn die Resource gefunden wurde wird sie zurückgegeben.
|
||||||
if ((*Iter)->GetFileName() == UniqueFileName)
|
if ((*Iter)->GetFileName() == UniqueFileName)
|
||||||
return *Iter;
|
return *Iter;
|
||||||
|
|
|
@ -48,7 +48,7 @@ class BS_Resource;
|
||||||
class BS_Kernel;
|
class BS_Kernel;
|
||||||
|
|
||||||
class BS_ResourceManager {
|
class BS_ResourceManager {
|
||||||
friend class BS_Kernel;
|
friend class BS_Kernel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -63,12 +63,14 @@ public:
|
||||||
* @param ForceReload Indicates whether the file should be reloaded if it's already in the cache.
|
* @param ForceReload Indicates whether the file should be reloaded if it's already in the cache.
|
||||||
* This is useful for files that may have changed in the interim
|
* This is useful for files that may have changed in the interim
|
||||||
*/
|
*/
|
||||||
bool PrecacheResource(const Common::String& FileName, bool ForceReload = false);
|
bool PrecacheResource(const Common::String &FileName, bool ForceReload = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of loaded resources
|
* Returns the number of loaded resources
|
||||||
*/
|
*/
|
||||||
int GetResourceCount() const { return static_cast<int>(m_Resources.size()); }
|
int GetResourceCount() const {
|
||||||
|
return static_cast<int>(m_Resources.size());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a resource by it's ordinal index. Returns NULL if any error occurs
|
* Returns a resource by it's ordinal index. Returns NULL if any error occurs
|
||||||
|
@ -82,7 +84,7 @@ public:
|
||||||
* BS_ResourceService, and thus helps all resource services in the ResourceManager list
|
* BS_ResourceService, and thus helps all resource services in the ResourceManager list
|
||||||
* @param pService Which service
|
* @param pService Which service
|
||||||
*/
|
*/
|
||||||
bool RegisterResourceService(BS_ResourceService* pService);
|
bool RegisterResourceService(BS_ResourceService *pService);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Releases all resources that are not locked.
|
* Releases all resources that are not locked.
|
||||||
|
@ -92,7 +94,9 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns the maximum memory the kernel has used
|
* Returns the maximum memory the kernel has used
|
||||||
*/
|
*/
|
||||||
int GetMaxMemoryUsage() const { return m_MaxMemoryUsage; }
|
int GetMaxMemoryUsage() const {
|
||||||
|
return m_MaxMemoryUsage;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the maximum amount of memory the engine is allowed to use.
|
* Specifies the maximum amount of memory the engine is allowed to use.
|
||||||
|
@ -106,13 +110,17 @@ public:
|
||||||
* Specifies whether a warning is written to the log when a cache miss occurs.
|
* Specifies whether a warning is written to the log when a cache miss occurs.
|
||||||
* THe default value is "false".
|
* THe default value is "false".
|
||||||
*/
|
*/
|
||||||
bool IsLogCacheMiss() const { return m_LogCacheMiss; }
|
bool IsLogCacheMiss() const {
|
||||||
|
return m_LogCacheMiss;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether warnings are written to the log if a cache miss occurs.
|
* Sets whether warnings are written to the log if a cache miss occurs.
|
||||||
* @param Flag If "true", then future warnings will be logged
|
* @param Flag If "true", then future warnings will be logged
|
||||||
*/
|
*/
|
||||||
void SetLogCacheMiss(bool Flag) { m_LogCacheMiss = Flag; }
|
void SetLogCacheMiss(bool Flag) {
|
||||||
|
m_LogCacheMiss = Flag;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes the names of all currently locked resources to the log file
|
* Writes the names of all currently locked resources to the log file
|
||||||
|
@ -124,15 +132,14 @@ private:
|
||||||
* Creates a new resource manager
|
* Creates a new resource manager
|
||||||
* Only the BS_Kernel class can generate copies this class. Thus, the constructor is private
|
* Only the BS_Kernel class can generate copies this class. Thus, the constructor is private
|
||||||
*/
|
*/
|
||||||
BS_ResourceManager(BS_Kernel* pKernel) :
|
BS_ResourceManager(BS_Kernel *pKernel) :
|
||||||
m_KernelPtr(pKernel),
|
m_KernelPtr(pKernel),
|
||||||
m_MaxMemoryUsage(100000000),
|
m_MaxMemoryUsage(100000000),
|
||||||
m_LogCacheMiss(false)
|
m_LogCacheMiss(false)
|
||||||
{};
|
{};
|
||||||
virtual ~BS_ResourceManager();
|
virtual ~BS_ResourceManager();
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
|
||||||
HASH_TABLE_BUCKETS = 256
|
HASH_TABLE_BUCKETS = 256
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,7 +166,7 @@ private:
|
||||||
/**
|
/**
|
||||||
* Deletes a resource, removes it from the lists, and updates m_UsedMemory
|
* Deletes a resource, removes it from the lists, and updates m_UsedMemory
|
||||||
*/
|
*/
|
||||||
Common::List<BS_Resource*>::iterator DeleteResource(BS_Resource *pResource);
|
Common::List<BS_Resource *>::iterator DeleteResource(BS_Resource *pResource);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a pointer to a loaded resource. If any error occurs, NULL will be returned.
|
* Returns a pointer to a loaded resource. If any error occurs, NULL will be returned.
|
||||||
|
@ -173,7 +180,7 @@ private:
|
||||||
*/
|
*/
|
||||||
void DeleteResourcesIfNecessary();
|
void DeleteResourcesIfNecessary();
|
||||||
|
|
||||||
BS_Kernel * m_KernelPtr;
|
BS_Kernel *m_KernelPtr;
|
||||||
unsigned int m_MaxMemoryUsage;
|
unsigned int m_MaxMemoryUsage;
|
||||||
Common::Array<BS_ResourceService *> m_ResourceServices;
|
Common::Array<BS_ResourceService *> m_ResourceServices;
|
||||||
Common::List<BS_Resource *> m_Resources;
|
Common::List<BS_Resource *> m_Resources;
|
||||||
|
|
|
@ -45,7 +45,7 @@ class BS_Kernel;
|
||||||
class BS_ResourceManager;
|
class BS_ResourceManager;
|
||||||
|
|
||||||
class BS_Resource {
|
class BS_Resource {
|
||||||
friend class BS_ResourceManager;
|
friend class BS_ResourceManager;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum RESOURCE_TYPES {
|
enum RESOURCE_TYPES {
|
||||||
|
@ -62,7 +62,9 @@ public:
|
||||||
* Prevents the resource from being released.
|
* Prevents the resource from being released.
|
||||||
* @remarks This method allows a resource to be locked multiple times.
|
* @remarks This method allows a resource to be locked multiple times.
|
||||||
**/
|
**/
|
||||||
void AddReference() { ++_RefCount; }
|
void AddReference() {
|
||||||
|
++_RefCount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels a previous lock
|
* Cancels a previous lock
|
||||||
|
@ -75,22 +77,30 @@ public:
|
||||||
* Returns the current lock count for the resource
|
* Returns the current lock count for the resource
|
||||||
* @return The current lock count
|
* @return The current lock count
|
||||||
**/
|
**/
|
||||||
int GetLockCount() const { return _RefCount; }
|
int GetLockCount() const {
|
||||||
|
return _RefCount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the absolute path of the given resource
|
* Returns the absolute path of the given resource
|
||||||
*/
|
*/
|
||||||
const Common::String &GetFileName() const { return _FileName; }
|
const Common::String &GetFileName() const {
|
||||||
|
return _FileName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the hash of the filename of a resource
|
* Returns the hash of the filename of a resource
|
||||||
*/
|
*/
|
||||||
unsigned int GetFileNameHash() const { return _FileNameHash; }
|
unsigned int GetFileNameHash() const {
|
||||||
|
return _FileNameHash;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a resource's type
|
* Returns a resource's type
|
||||||
*/
|
*/
|
||||||
unsigned int GetType() const { return _Type; }
|
unsigned int GetType() const {
|
||||||
|
return _Type;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~BS_Resource() {};
|
virtual ~BS_Resource() {};
|
||||||
|
|
|
@ -47,9 +47,8 @@ class BS_Resource;
|
||||||
|
|
||||||
class BS_ResourceService : public BS_Service {
|
class BS_ResourceService : public BS_Service {
|
||||||
public:
|
public:
|
||||||
BS_ResourceService(BS_Kernel* pKernel) : BS_Service(pKernel)
|
BS_ResourceService(BS_Kernel *pKernel) : BS_Service(pKernel) {
|
||||||
{
|
BS_ResourceManager *pResource = pKernel->GetResourceManager();
|
||||||
BS_ResourceManager* pResource = pKernel->GetResourceManager();
|
|
||||||
pResource->RegisterResourceService(this);
|
pResource->RegisterResourceService(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +66,7 @@ public:
|
||||||
* @param FileName Dateiname
|
* @param FileName Dateiname
|
||||||
* @return Returns true if the resource can be loaded.
|
* @return Returns true if the resource can be loaded.
|
||||||
*/
|
*/
|
||||||
virtual bool CanLoadResource(const Common::String& FileName) = 0;
|
virtual bool CanLoadResource(const Common::String &FileName) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Alternative methods for classes BS_ResourceService
|
// Alternative methods for classes BS_ResourceService
|
||||||
|
@ -89,7 +88,9 @@ private:
|
||||||
if (*Pattern == '*') {
|
if (*Pattern == '*') {
|
||||||
// Use a copy of the pattern pointer so as not to destroy the current state
|
// Use a copy of the pattern pointer so as not to destroy the current state
|
||||||
const char *PatternCopy = Pattern;
|
const char *PatternCopy = Pattern;
|
||||||
while (*PatternCopy == '*') { PatternCopy++; }
|
while (*PatternCopy == '*') {
|
||||||
|
PatternCopy++;
|
||||||
|
}
|
||||||
if (!*PatternCopy) return true;
|
if (!*PatternCopy) return true;
|
||||||
}
|
}
|
||||||
// 2. The string is over, but the patern is not -> FALSE
|
// 2. The string is over, but the patern is not -> FALSE
|
||||||
|
|
|
@ -57,12 +57,14 @@ class BS_Kernel;
|
||||||
|
|
||||||
class BS_Service {
|
class BS_Service {
|
||||||
private:
|
private:
|
||||||
BS_Kernel * _pKernel;
|
BS_Kernel *_pKernel;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BS_Service(BS_Kernel *pKernel) : _pKernel(pKernel) {};
|
BS_Service(BS_Kernel *pKernel) : _pKernel(pKernel) {};
|
||||||
|
|
||||||
BS_Kernel* GetKernel() const { return _pKernel; }
|
BS_Kernel *GetKernel() const {
|
||||||
|
return _pKernel;
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~BS_Service() {};
|
virtual ~BS_Service() {};
|
||||||
|
|
|
@ -52,7 +52,9 @@ inline bool ToInt(const Common::String &Str, int &Result) {
|
||||||
Common::String::const_iterator Iter = Str.begin();
|
Common::String::const_iterator Iter = Str.begin();
|
||||||
|
|
||||||
// Skip whitespaces
|
// Skip whitespaces
|
||||||
while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; }
|
while (*Iter && (*Iter == ' ' || *Iter == '\t')) {
|
||||||
|
++Iter;
|
||||||
|
}
|
||||||
if (Iter == Str.end()) return false;
|
if (Iter == Str.end()) return false;
|
||||||
|
|
||||||
// Read sign, if available
|
// Read sign, if available
|
||||||
|
@ -60,19 +62,22 @@ inline bool ToInt(const Common::String &Str, int &Result) {
|
||||||
if (*Iter == '-') {
|
if (*Iter == '-') {
|
||||||
IsNegative = true;
|
IsNegative = true;
|
||||||
++Iter;
|
++Iter;
|
||||||
}
|
} else if (*Iter == '+')
|
||||||
else if (*Iter == '+')
|
|
||||||
++Iter;
|
++Iter;
|
||||||
|
|
||||||
// Skip whitespaces
|
// Skip whitespaces
|
||||||
while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; }
|
while (*Iter && (*Iter == ' ' || *Iter == '\t')) {
|
||||||
if (Iter ==Str.end()) return false;
|
++Iter;
|
||||||
|
}
|
||||||
|
if (Iter == Str.end()) return false;
|
||||||
|
|
||||||
// Convert string to integer
|
// Convert string to integer
|
||||||
Result = 0;
|
Result = 0;
|
||||||
while (Iter != Str.end()) {
|
while (Iter != Str.end()) {
|
||||||
if (*Iter < '0' || *Iter > '9') {
|
if (*Iter < '0' || *Iter > '9') {
|
||||||
while (*Iter && (*Iter == ' ' || *Iter == '\t')) { ++Iter; }
|
while (*Iter && (*Iter == ' ' || *Iter == '\t')) {
|
||||||
|
++Iter;
|
||||||
|
}
|
||||||
if (Iter != Str.end()) return false;
|
if (Iter != Str.end()) return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ namespace Sword25 {
|
||||||
// Erstellt ein Fenster des GUI des aktuellen Betriebssystems
|
// Erstellt ein Fenster des GUI des aktuellen Betriebssystems
|
||||||
BS_Window *BS_Window::CreateBSWindow(int X, int Y, int Width, int Height, bool Visible) {
|
BS_Window *BS_Window::CreateBSWindow(int X, int Y, int Width, int Height, bool Visible) {
|
||||||
// Fenster erstellen
|
// Fenster erstellen
|
||||||
BS_Window *pWindow = (BS_Window*) new BS_ScummVMWindow(X, Y, Width, Height, Visible);
|
BS_Window *pWindow = (BS_Window *) new BS_ScummVMWindow(X, Y, Width, Height, Visible);
|
||||||
|
|
||||||
// Falls das Fenster erfolgreich initialisiert wurde, wird ein Pointer auf das Fensterobjekt
|
// Falls das Fenster erfolgreich initialisiert wurde, wird ein Pointer auf das Fensterobjekt
|
||||||
// zurückgegeben
|
// zurückgegeben
|
||||||
|
|
|
@ -63,7 +63,7 @@ protected:
|
||||||
bool _CloseWanted;
|
bool _CloseWanted;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~BS_Window(){};
|
virtual ~BS_Window() {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the visibility of the window.
|
* Returns the visibility of the window.
|
||||||
|
|
|
@ -67,11 +67,9 @@ namespace Sword25 {
|
||||||
static void *my_checkudata(lua_State *L, int ud, const char *tname) {
|
static void *my_checkudata(lua_State *L, int ud, const char *tname) {
|
||||||
int top = lua_gettop(L);
|
int top = lua_gettop(L);
|
||||||
|
|
||||||
void * p = lua_touserdata(L, ud);
|
void *p = lua_touserdata(L, ud);
|
||||||
if (p != NULL) /* value is a userdata? */
|
if (p != NULL) { /* value is a userdata? */
|
||||||
{
|
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
|
||||||
if (lua_getmetatable(L, ud)) /* does it have a metatable? */
|
|
||||||
{
|
|
||||||
// lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
|
// lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
|
||||||
BS_LuaBindhelper::GetMetatable(L, tname);
|
BS_LuaBindhelper::GetMetatable(L, tname);
|
||||||
/* does it have the correct mt? */
|
/* does it have the correct mt? */
|
||||||
|
@ -89,7 +87,7 @@ static void *my_checkudata(lua_State *L, int ud, const char *tname) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void NewUintUserData(lua_State *L, unsigned int Value) {
|
static void NewUintUserData(lua_State *L, unsigned int Value) {
|
||||||
void * UserData = lua_newuserdata(L, sizeof(Value));
|
void *UserData = lua_newuserdata(L, sizeof(Value));
|
||||||
memcpy(UserData, &Value, sizeof(Value));
|
memcpy(UserData, &Value, sizeof(Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,8 +155,7 @@ static void TablePolygonToPolygon(lua_State *L, BS_Polygon &Polygon) {
|
||||||
Vertecies.reserve(VertexCount);
|
Vertecies.reserve(VertexCount);
|
||||||
|
|
||||||
// Create Vertecies
|
// Create Vertecies
|
||||||
for (int i = 0; i < VertexCount; i++)
|
for (int i = 0; i < VertexCount; i++) {
|
||||||
{
|
|
||||||
// X Value
|
// X Value
|
||||||
lua_rawgeti(L, -1, (i * 2) + 1);
|
lua_rawgeti(L, -1, (i * 2) + 1);
|
||||||
int X = static_cast<int>(lua_tonumber(L, -1));
|
int X = static_cast<int>(lua_tonumber(L, -1));
|
||||||
|
@ -220,7 +217,7 @@ static unsigned int TableRegionToRegion(lua_State *L, const char *ClassName) {
|
||||||
int FirstElementType = lua_type(L, -1);
|
int FirstElementType = lua_type(L, -1);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
switch(FirstElementType) {
|
switch (FirstElementType) {
|
||||||
case LUA_TNUMBER: {
|
case LUA_TNUMBER: {
|
||||||
BS_Polygon Polygon;
|
BS_Polygon Polygon;
|
||||||
TablePolygonToPolygon(L, Polygon);
|
TablePolygonToPolygon(L, Polygon);
|
||||||
|
@ -268,8 +265,7 @@ static unsigned int TableRegionToRegion(lua_State *L, const char *ClassName) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static void NewUserdataRegion(lua_State *L, const char *ClassName)
|
static void NewUserdataRegion(lua_State *L, const char *ClassName) {
|
||||||
{
|
|
||||||
// Region due to the Lua code to create
|
// Region due to the Lua code to create
|
||||||
// Any errors that occur will be intercepted to the luaL_error
|
// Any errors that occur will be intercepted to the luaL_error
|
||||||
unsigned int RegionHandle = TableRegionToRegion(L, ClassName);
|
unsigned int RegionHandle = TableRegionToRegion(L, ClassName);
|
||||||
|
@ -308,7 +304,7 @@ static const luaL_reg GEO_FUNCTIONS[] = {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static BS_Region * CheckRegion(lua_State *L) {
|
static BS_Region *CheckRegion(lua_State *L) {
|
||||||
// The first parameter must be of type 'userdata', and the Metatable class Geo.Region or Geo.WalkRegion
|
// The first parameter must be of type 'userdata', and the Metatable class Geo.Region or Geo.WalkRegion
|
||||||
unsigned int *RegionHandlePtr;
|
unsigned int *RegionHandlePtr;
|
||||||
if ((RegionHandlePtr = reinterpret_cast<unsigned int *>(my_checkudata(L, 1, REGION_CLASS_NAME))) != 0 ||
|
if ((RegionHandlePtr = reinterpret_cast<unsigned int *>(my_checkudata(L, 1, REGION_CLASS_NAME))) != 0 ||
|
||||||
|
@ -325,7 +321,7 @@ static BS_Region * CheckRegion(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_IsValid(lua_State *L) {
|
static int R_IsValid(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
|
|
||||||
lua_pushbooleancpp(L, pR->IsValid());
|
lua_pushbooleancpp(L, pR->IsValid());
|
||||||
|
@ -335,7 +331,7 @@ static int R_IsValid(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_GetX(lua_State *L) {
|
static int R_GetX(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
|
|
||||||
lua_pushnumber(L, pR->GetPosX());
|
lua_pushnumber(L, pR->GetPosX());
|
||||||
|
@ -345,7 +341,7 @@ static int R_GetX(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_GetY(lua_State *L) {
|
static int R_GetY(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
|
|
||||||
lua_pushnumber(L, pR->GetPosY());
|
lua_pushnumber(L, pR->GetPosY());
|
||||||
|
@ -355,7 +351,7 @@ static int R_GetY(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_GetPos(lua_State *L) {
|
static int R_GetPos(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
|
|
||||||
BS_Vertex::VertexToLuaVertex(L, pR->GetPosition());
|
BS_Vertex::VertexToLuaVertex(L, pR->GetPosition());
|
||||||
|
@ -365,7 +361,7 @@ static int R_GetPos(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_IsPointInRegion(lua_State *L) {
|
static int R_IsPointInRegion(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
|
|
||||||
BS_Vertex Vertex;
|
BS_Vertex Vertex;
|
||||||
|
@ -377,7 +373,7 @@ static int R_IsPointInRegion(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_SetPos(lua_State *L) {
|
static int R_SetPos(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
|
|
||||||
BS_Vertex Vertex;
|
BS_Vertex Vertex;
|
||||||
|
@ -390,7 +386,7 @@ static int R_SetPos(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_SetX(lua_State *L) {
|
static int R_SetX(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
|
|
||||||
pR->SetPosX(static_cast<int>(luaL_checknumber(L, 2)));
|
pR->SetPosX(static_cast<int>(luaL_checknumber(L, 2)));
|
||||||
|
@ -401,7 +397,7 @@ static int R_SetX(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_SetY(lua_State *L) {
|
static int R_SetY(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
|
|
||||||
pR->SetPosY(static_cast<int>(luaL_checknumber(L, 2)));
|
pR->SetPosY(static_cast<int>(luaL_checknumber(L, 2)));
|
||||||
|
@ -432,7 +428,7 @@ static void DrawRegion(const BS_Region &Region, unsigned int Color, const BS_Ver
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_Draw(lua_State *L) {
|
static int R_Draw(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
|
|
||||||
switch (lua_gettop(L)) {
|
switch (lua_gettop(L)) {
|
||||||
|
@ -457,7 +453,7 @@ static int R_Draw(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_GetCentroid(lua_State *L) {
|
static int R_GetCentroid(lua_State *L) {
|
||||||
BS_Region * RPtr = CheckRegion(L);
|
BS_Region *RPtr = CheckRegion(L);
|
||||||
BS_ASSERT(RPtr);
|
BS_ASSERT(RPtr);
|
||||||
|
|
||||||
BS_Vertex::VertexToLuaVertex(L, RPtr->GetCentroid());
|
BS_Vertex::VertexToLuaVertex(L, RPtr->GetCentroid());
|
||||||
|
@ -468,7 +464,7 @@ static int R_GetCentroid(lua_State *L) {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
static int R_Delete(lua_State *L) {
|
static int R_Delete(lua_State *L) {
|
||||||
BS_Region * pR = CheckRegion(L);
|
BS_Region *pR = CheckRegion(L);
|
||||||
BS_ASSERT(pR);
|
BS_ASSERT(pR);
|
||||||
delete pR;
|
delete pR;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -540,9 +536,9 @@ static const luaL_reg WALKREGION_METHODS[] = {
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Geometry::_RegisterScriptBindings() {
|
bool BS_Geometry::_RegisterScriptBindings() {
|
||||||
BS_Kernel * pKernel = BS_Kernel::GetInstance();
|
BS_Kernel *pKernel = BS_Kernel::GetInstance();
|
||||||
BS_ASSERT(pKernel);
|
BS_ASSERT(pKernel);
|
||||||
BS_ScriptEngine * pScript = static_cast<BS_ScriptEngine *>(pKernel->GetService("script"));
|
BS_ScriptEngine *pScript = static_cast<BS_ScriptEngine *>(pKernel->GetService("script"));
|
||||||
BS_ASSERT(pScript);
|
BS_ASSERT(pScript);
|
||||||
lua_State *L = static_cast< lua_State *>(pScript->GetScriptObject());
|
lua_State *L = static_cast< lua_State *>(pScript->GetScriptObject());
|
||||||
BS_ASSERT(L);
|
BS_ASSERT(L);
|
||||||
|
|
|
@ -140,7 +140,7 @@ public:
|
||||||
|
|
||||||
if (Class1 == ON || Class2 == ON || Class3 == ON || Class4 == ON) return false;
|
if (Class1 == ON || Class2 == ON || Class3 == ON || Class4 == ON) return false;
|
||||||
|
|
||||||
return ((Class1 == LEFT) ^ (Class2 == LEFT)) && ((Class3 == LEFT) ^ (Class4 == LEFT));
|
return ((Class1 == LEFT) ^(Class2 == LEFT)) && ((Class3 == LEFT) ^(Class4 == LEFT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -407,7 +407,7 @@ bool BS_Polygon::IsPointInPolygon(const BS_Vertex &Point, bool EdgesBelongToPoly
|
||||||
}
|
}
|
||||||
|
|
||||||
// The point is on an adge, if the number of left and right intersections have the same even numbers
|
// The point is on an adge, if the number of left and right intersections have the same even numbers
|
||||||
if ((Rcross % 2 ) != (Lcross % 2 )) return EdgesBelongToPolygon;
|
if ((Rcross % 2) != (Lcross % 2)) return EdgesBelongToPolygon;
|
||||||
|
|
||||||
// The point is strictly inside the polygon if and only if the number of overlaps is odd
|
// The point is strictly inside the polygon if and only if the number of overlaps is odd
|
||||||
if ((Rcross % 2) == 1) return true;
|
if ((Rcross % 2) == 1) return true;
|
||||||
|
|
|
@ -54,9 +54,13 @@ public:
|
||||||
BS_Rect(int16 w, int16 h) : Common::Rect(w, h) {}
|
BS_Rect(int16 w, int16 h) : Common::Rect(w, h) {}
|
||||||
BS_Rect(int16 x1, int16 y1, int16 x2, int16 y2) : Common::Rect(x1, y1, x2, y2) {}
|
BS_Rect(int16 x1, int16 y1, int16 x2, int16 y2) : Common::Rect(x1, y1, x2, y2) {}
|
||||||
|
|
||||||
void Move(int DeltaX, int DeltaY) { translate(DeltaX, DeltaY); }
|
void Move(int DeltaX, int DeltaY) {
|
||||||
|
translate(DeltaX, DeltaY);
|
||||||
|
}
|
||||||
|
|
||||||
bool DoesIntersect(const BS_Rect &Rect_) const { return intersects(Rect_); }
|
bool DoesIntersect(const BS_Rect &Rect_) const {
|
||||||
|
return intersects(Rect_);
|
||||||
|
}
|
||||||
|
|
||||||
bool Intersect(const BS_Rect &Rect_, BS_Rect &Result) const {
|
bool Intersect(const BS_Rect &Rect_, BS_Rect &Result) const {
|
||||||
Result = Rect_;
|
Result = Rect_;
|
||||||
|
@ -70,23 +74,41 @@ public:
|
||||||
Result.extend(*this);
|
Result.extend(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetWidth() const { return width(); }
|
int GetWidth() const {
|
||||||
|
return width();
|
||||||
|
}
|
||||||
|
|
||||||
int GetHeight() const { return height(); }
|
int GetHeight() const {
|
||||||
|
return height();
|
||||||
|
}
|
||||||
|
|
||||||
int GetArea() const { return width() * height(); }
|
int GetArea() const {
|
||||||
|
return width() * height();
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const BS_Rect &rhs) const { return equals(rhs); }
|
bool operator==(const BS_Rect &rhs) const {
|
||||||
|
return equals(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
bool operator!= (const BS_Rect &rhs) const { return !equals(rhs); }
|
bool operator!= (const BS_Rect &rhs) const {
|
||||||
|
return !equals(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
bool IsValid() const { return isValidRect(); }
|
bool IsValid() const {
|
||||||
|
return isValidRect();
|
||||||
|
}
|
||||||
|
|
||||||
bool IsPointInRect(const BS_Vertex &Vertex) const { return contains(Vertex.X, Vertex.Y); }
|
bool IsPointInRect(const BS_Vertex &Vertex) const {
|
||||||
|
return contains(Vertex.X, Vertex.Y);
|
||||||
|
}
|
||||||
|
|
||||||
bool IsPointInRect(int X, int Y) const { return contains(X, Y); }
|
bool IsPointInRect(int X, int Y) const {
|
||||||
|
return contains(X, Y);
|
||||||
|
}
|
||||||
|
|
||||||
bool ContainsRect(const BS_Rect &OtherRect) const { return contains(OtherRect); }
|
bool ContainsRect(const BS_Rect &OtherRect) const {
|
||||||
|
return contains(OtherRect);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace Sword25
|
} // End of namespace Sword25
|
||||||
|
|
|
@ -60,7 +60,7 @@ BS_Region::BS_Region(BS_InputPersistenceBlock &Reader, unsigned int Handle) : m_
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_Region::Create(REGION_TYPE Type) {
|
unsigned int BS_Region::Create(REGION_TYPE Type) {
|
||||||
BS_Region * RegionPtr = NULL;
|
BS_Region *RegionPtr = NULL;
|
||||||
switch (Type) {
|
switch (Type) {
|
||||||
case RT_REGION:
|
case RT_REGION:
|
||||||
RegionPtr = new BS_Region();
|
RegionPtr = new BS_Region();
|
||||||
|
@ -79,7 +79,7 @@ unsigned int BS_Region::Create(REGION_TYPE Type) {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
unsigned int BS_Region::Create(BS_InputPersistenceBlock & Reader, unsigned int Handle) {
|
unsigned int BS_Region::Create(BS_InputPersistenceBlock &Reader, unsigned int Handle) {
|
||||||
// Read type
|
// Read type
|
||||||
unsigned int Type;
|
unsigned int Type;
|
||||||
Reader.Read(Type);
|
Reader.Read(Type);
|
||||||
|
@ -105,7 +105,7 @@ BS_Region::~BS_Region() {
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BS_Region::Init(const BS_Polygon& Contour, const Common::Array<BS_Polygon> *pHoles) {
|
bool BS_Region::Init(const BS_Polygon &Contour, const Common::Array<BS_Polygon> *pHoles) {
|
||||||
// Reset object state
|
// Reset object state
|
||||||
m_Valid = false;
|
m_Valid = false;
|
||||||
m_Position = BS_Vertex(0, 0);
|
m_Position = BS_Vertex(0, 0);
|
||||||
|
@ -125,7 +125,7 @@ bool BS_Region::Init(const BS_Polygon& Contour, const Common::Array<BS_Polygon>
|
||||||
|
|
||||||
// Place the hole polygons in the following positions
|
// Place the hole polygons in the following positions
|
||||||
if (pHoles) {
|
if (pHoles) {
|
||||||
for (unsigned int i = 0; i< pHoles->size(); ++i) {
|
for (unsigned int i = 0; i < pHoles->size(); ++i) {
|
||||||
m_Polygons.push_back(BS_Polygon());
|
m_Polygons.push_back(BS_Polygon());
|
||||||
m_Polygons[i + 1].Init((*pHoles)[i].VertexCount, (*pHoles)[i].Vertecies);
|
m_Polygons[i + 1].Init((*pHoles)[i].VertexCount, (*pHoles)[i].Vertecies);
|
||||||
m_Polygons[i + 1].EnsureCWOrder();
|
m_Polygons[i + 1].EnsureCWOrder();
|
||||||
|
@ -201,7 +201,7 @@ bool BS_Region::IsPointInRegion(int X, int Y) const {
|
||||||
if (m_Polygons[0].IsPointInPolygon(X, Y, true)) {
|
if (m_Polygons[0].IsPointInPolygon(X, Y, true)) {
|
||||||
// Test whether the point is in a hole
|
// Test whether the point is in a hole
|
||||||
for (unsigned int i = 1; i < m_Polygons.size(); i++) {
|
for (unsigned int i = 1; i < m_Polygons.size(); i++) {
|
||||||
if (m_Polygons[i].IsPointInPolygon(X,Y, false))
|
if (m_Polygons[i].IsPointInPolygon(X, Y, false))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ BS_Vertex BS_Region::FindClosestRegionPoint(const BS_Vertex &Point) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const BS_Polygon & Polygon = m_Polygons[PolygonIdx];
|
const BS_Polygon &Polygon = m_Polygons[PolygonIdx];
|
||||||
|
|
||||||
BS_ASSERT(Polygon.VertexCount > 1);
|
BS_ASSERT(Polygon.VertexCount > 1);
|
||||||
|
|
||||||
|
|
|
@ -94,22 +94,30 @@ public:
|
||||||
* @return Returns true if the object is in a valid state, otherwise false.
|
* @return Returns true if the object is in a valid state, otherwise false.
|
||||||
* @remark Invalid objects can be made valid by calling Init with a valid state.
|
* @remark Invalid objects can be made valid by calling Init with a valid state.
|
||||||
*/
|
*/
|
||||||
bool IsValid() const { return m_Valid; }
|
bool IsValid() const {
|
||||||
|
return m_Valid;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the position of the region
|
* Returns the position of the region
|
||||||
*/
|
*/
|
||||||
const BS_Vertex &GetPosition() const { return m_Position; }
|
const BS_Vertex &GetPosition() const {
|
||||||
|
return m_Position;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the X position of the region
|
* Returns the X position of the region
|
||||||
*/
|
*/
|
||||||
int GetPosX() const { return m_Position.X; }
|
int GetPosX() const {
|
||||||
|
return m_Position.X;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Y position of the region
|
* Returns the Y position of the region
|
||||||
*/
|
*/
|
||||||
int GetPosY() const { return m_Position.Y; }
|
int GetPosY() const {
|
||||||
|
return m_Position.Y;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether a point is inside the region
|
* Indicates whether a point is inside the region
|
||||||
|
@ -129,12 +137,16 @@ public:
|
||||||
/**
|
/**
|
||||||
* Returns the countour of the region
|
* Returns the countour of the region
|
||||||
*/
|
*/
|
||||||
const BS_Polygon &GetContour() const { return m_Polygons[0]; }
|
const BS_Polygon &GetContour() const {
|
||||||
|
return m_Polygons[0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the number of polygons in the hole region
|
* Returns the number of polygons in the hole region
|
||||||
*/
|
*/
|
||||||
int GetHoleCount() const { return static_cast<int>(m_Polygons.size() - 1); }
|
int GetHoleCount() const {
|
||||||
|
return static_cast<int>(m_Polygons.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a specific hole polygon in the region
|
* Returns a specific hole polygon in the region
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue