Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new prop image-individual-animation #508

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/framework/ui/uiwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ enum FlagProp : uint32_t
PropImageFixedRatio = 1 << 19,
PropImageRepeated = 1 << 20,
PropImageSmooth = 1 << 21,
PropImageAutoResize = 1 << 22
PropImageAutoResize = 1 << 22,
propImageIndividualAnimation = 1 << 23
};

// @bindclass
Expand Down Expand Up @@ -462,6 +463,8 @@ class UIWidget : public LuaObject
Rect m_imageRect;
Color m_imageColor{ Color::white };
Point m_iconOffset;
Timer m_imageAnimatorTimer;
uint32_t m_currentFrame{ 0 };

EdgeGroup<int> m_imageBorder;

Expand All @@ -480,6 +483,7 @@ class UIWidget : public LuaObject
void setImageRepeated(bool repeated) { setProp(PropImageRepeated, repeated); updateImageCache(); }
void setImageSmooth(bool smooth) { setProp(PropImageSmooth, smooth); }
void setImageAutoResize(bool autoResize) { setProp(PropImageAutoResize, autoResize); }
void setImageIndividualAnimation(bool v) { setProp(propImageIndividualAnimation, v); }
void setImageBorderTop(int border) { m_imageBorder.top = border; configureBorderImage(); }
void setImageBorderRight(int border) { m_imageBorder.right = border; configureBorderImage(); }
void setImageBorderBottom(int border) { m_imageBorder.bottom = border; configureBorderImage(); }
Expand All @@ -499,6 +503,7 @@ class UIWidget : public LuaObject
bool isImageFixedRatio() { return hasProp(PropImageFixedRatio); }
bool isImageSmooth() { return hasProp(PropImageSmooth); }
bool isImageAutoResize() { return hasProp(PropImageAutoResize); }
bool isImageIndividualAnimation() { return hasProp(propImageIndividualAnimation); }
int getImageBorderTop() { return m_imageBorder.top; }
int getImageBorderRight() { return m_imageBorder.right; }
int getImageBorderBottom() { return m_imageBorder.bottom; }
Expand Down
5 changes: 5 additions & 0 deletions src/framework/ui/uiwidgetimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode)
setImageBorder(node->value<int>());
else if (node->tag() == "image-auto-resize")
setImageAutoResize(node->value<bool>());
else if (node->tag() == "image-individual-animation")
setImageIndividualAnimation(node->value<bool>());
}
}

Expand Down Expand Up @@ -164,6 +166,9 @@ void UIWidget::drawImage(const Rect& screenCoords)
//m_imageTexture->setSmooth(m_imageSmooth);
const bool useRepeated = hasProp(PropImageBordered) || hasProp(PropImageRepeated);
for (const auto& [dest, src] : m_imageCoordsCache) {
const auto& texture = m_imageTexture->isAnimatedTexture() && isImageIndividualAnimation() ?
std::static_pointer_cast<AnimatedTexture>(m_imageTexture)->get(m_currentFrame, m_imageAnimatorTimer) : m_imageTexture;

if (useRepeated)
g_drawPool.addTexturedRepeatedRect(dest, m_imageTexture, src, m_imageColor);
else
Expand Down