summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/windows/cutinwindow.cpp42
-rw-r--r--src/gui/windows/cutinwindow.h8
-rw-r--r--src/resources/sprite/animatedsprite.cpp16
-rw-r--r--src/resources/sprite/animatedsprite.h7
4 files changed, 51 insertions, 22 deletions
diff --git a/src/gui/windows/cutinwindow.cpp b/src/gui/windows/cutinwindow.cpp
index 910c6d562..d1c63e8f5 100644
--- a/src/gui/windows/cutinwindow.cpp
+++ b/src/gui/windows/cutinwindow.cpp
@@ -24,8 +24,12 @@
#include "configuration.h"
-#include "resources/image.h"
-#include "resources/resourcemanager.h"
+#include "const/utils/timer.h"
+
+#include "resources/sprite/animatedsprite.h"
+
+#include "utils/delete2.h"
+#include "utils/timer.h"
#include "debug.h"
@@ -48,16 +52,7 @@ CutInWindow::CutInWindow() :
CutInWindow::~CutInWindow()
{
- deleteImage();
-}
-
-void CutInWindow::deleteImage()
-{
- if (mImage)
- {
- mImage->decRef();
- mImage = nullptr;
- }
+ delete2(mImage);
}
void CutInWindow::draw(Graphics *graphics)
@@ -75,35 +70,37 @@ void CutInWindow::safeDraw(Graphics *graphics)
void CutInWindow::draw2(Graphics *const graphics)
{
if (mImage)
- graphics->drawImage(mImage, mPadding, mTitleBarHeight);
+ mImage->drawRaw(graphics, mPadding, mTitleBarHeight);
}
void CutInWindow::show(const std::string &name,
const CutIn cutin)
{
- deleteImage();
+ delete2(mImage);
if (name.empty())
{
setVisible(Visible_false);
}
else
{
- mImage = resourceManager->getImage(
+ mImage = AnimatedSprite::load(
std::string(paths.getStringValue("cutInsDir")).append(
"/").append(
name).append(
- ".png"));
+ ".xml"));
if (mImage)
{
+ mImage->update(1);
const bool showTitle = (cutin == CutIn::MovableClose);
if (showTitle)
mTitleBarHeight = mOldTitleBarHeight;
else
mTitleBarHeight = mPadding;
- const int width = mImage->mBounds.w + 2 * mPadding;
- const int height = mImage->mBounds.h + mTitleBarHeight
+ const int width = mImage->getWidth() + 2 * mPadding;
+ const int height = mImage->getHeight() + mTitleBarHeight
+ mPadding;
+ logger->log("detected sizes: %d, %d", mImage->getWidth(), mImage->getHeight());
const int screenWidth = mainGraphics->mWidth;
const int screenHeight = mainGraphics->mHeight;
@@ -141,3 +138,12 @@ void CutInWindow::show(const std::string &name,
}
}
}
+
+void CutInWindow::logic()
+{
+ if (mImage)
+ {
+ const int time = tick_time * MILLISECONDS_IN_A_TICK;
+ mImage->update(time);
+ }
+}
diff --git a/src/gui/windows/cutinwindow.h b/src/gui/windows/cutinwindow.h
index 2892f8548..f708242bd 100644
--- a/src/gui/windows/cutinwindow.h
+++ b/src/gui/windows/cutinwindow.h
@@ -27,7 +27,7 @@
#include "enums/cutin.h"
-class Image;
+class AnimatedSprite;
class CutInWindow final : public Window
{
@@ -47,10 +47,10 @@ class CutInWindow final : public Window
void show(const std::string &name,
const CutIn cutin);
- private:
- void deleteImage();
+ void logic() override final;
- Image *mImage;
+ private:
+ AnimatedSprite *mImage;
int mOldTitleBarHeight;
};
diff --git a/src/resources/sprite/animatedsprite.cpp b/src/resources/sprite/animatedsprite.cpp
index 216d94106..5210ce626 100644
--- a/src/resources/sprite/animatedsprite.cpp
+++ b/src/resources/sprite/animatedsprite.cpp
@@ -330,6 +330,22 @@ void AnimatedSprite::draw(Graphics *restrict const graphics,
posX + mFrame->offsetX, posY + mFrame->offsetY);
}
+void AnimatedSprite::drawRaw(Graphics *restrict const graphics,
+ const int posX,
+ const int posY) const restrict2
+{
+ if (!mFrame || !mFrame->image)
+ return;
+
+ Image *restrict const image = mFrame->image;
+ if (image->getAlpha() != mAlpha)
+ image->setAlpha(mAlpha);
+
+ graphics->drawImage(image,
+ posX,
+ posY);
+}
+
bool AnimatedSprite::setSpriteDirection(const SpriteDirection::Type direction)
restrict2
{
diff --git a/src/resources/sprite/animatedsprite.h b/src/resources/sprite/animatedsprite.h
index 53423b77a..2a40df1e9 100644
--- a/src/resources/sprite/animatedsprite.h
+++ b/src/resources/sprite/animatedsprite.h
@@ -73,6 +73,10 @@ class AnimatedSprite final : public Sprite
const int posX,
const int posY) const restrict2 override final A_NONNULL(2);
+ void drawRaw(Graphics *restrict const graphics,
+ const int posX,
+ const int posY) const restrict2 A_NONNULL(2);
+
int getWidth() const restrict2 override final A_WARN_UNUSED;
int getHeight() const restrict2 override final A_WARN_UNUSED;
@@ -116,6 +120,9 @@ class AnimatedSprite final : public Sprite
void setLastTime(const int time) noexcept
{ mLastTime = time; }
+ const Frame *getFrame() const restrict2
+ { return mFrame; }
+
#ifdef UNITTESTS
SpriteDef *getSprite() restrict2
{ return mSprite; }