Merge pull request #599 from jrassa/image-video-component-theme-cleanup

Image video component theme cleanup
This commit is contained in:
Tomas Jakobsson 2019-09-07 19:28:36 +02:00 committed by GitHub
commit eda3fe9c3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 61 deletions

View file

@ -405,20 +405,14 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
{ {
using namespace ThemeFlags; using namespace ThemeFlags;
GuiComponent::applyTheme(theme, view, element, (properties ^ SIZE) | ((properties & (SIZE | POSITION)) ? ORIGIN : 0));
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "image"); const ThemeData::ThemeElement* elem = theme->getElement(view, element, "image");
if(!elem) if(!elem)
{
return; return;
}
Vector2f scale = getParent() ? getParent()->getSize() : Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); Vector2f scale = getParent() ? getParent()->getSize() : Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
if(properties & POSITION && elem->has("pos"))
{
Vector2f denormalized = elem->get<Vector2f>("pos") * scale;
setPosition(Vector3f(denormalized.x(), denormalized.y(), 0));
}
if(properties & ThemeFlags::SIZE) if(properties & ThemeFlags::SIZE)
{ {
if(elem->has("size")) if(elem->has("size"))
@ -429,13 +423,8 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
setMinSize(elem->get<Vector2f>("minSize") * scale); setMinSize(elem->get<Vector2f>("minSize") * scale);
} }
// position + size also implies origin if(elem->has("default"))
if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin"))
setOrigin(elem->get<Vector2f>("origin"));
if(elem->has("default")) {
setDefaultImage(elem->get<std::string>("default")); setDefaultImage(elem->get<std::string>("default"));
}
if(properties & PATH && elem->has("path")) if(properties & PATH && elem->has("path"))
{ {
@ -457,23 +446,6 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
if (elem->has("gradientType")) if (elem->has("gradientType"))
setColorGradientHorizontal(!(elem->get<std::string>("gradientType").compare("horizontal"))); setColorGradientHorizontal(!(elem->get<std::string>("gradientType").compare("horizontal")));
} }
if(properties & ThemeFlags::ROTATION) {
if(elem->has("rotation"))
setRotationDegrees(elem->get<float>("rotation"));
if(elem->has("rotationOrigin"))
setRotationOrigin(elem->get<Vector2f>("rotationOrigin"));
}
if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
setZIndex(elem->get<float>("zIndex"));
else
setZIndex(getDefaultZIndex());
if(properties & ThemeFlags::VISIBLE && elem->has("visible"))
setVisible(elem->get<bool>("visible"));
else
setVisible(true);
} }
std::vector<HelpPrompt> ImageComponent::getHelpPrompts() std::vector<HelpPrompt> ImageComponent::getHelpPrompts()

View file

@ -90,6 +90,11 @@ void VideoComponent::onOriginChanged()
// Update the embeded static image // Update the embeded static image
mStaticImage.setOrigin(mOrigin); mStaticImage.setOrigin(mOrigin);
} }
void VideoComponent::onPositionChanged()
{
// Update the embeded static image
mStaticImage.setPosition(mPosition);
}
void VideoComponent::onSizeChanged() void VideoComponent::onSizeChanged()
{ {
@ -175,21 +180,14 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
{ {
using namespace ThemeFlags; using namespace ThemeFlags;
GuiComponent::applyTheme(theme, view, element, (properties ^ SIZE) | ((properties & (SIZE | POSITION)) ? ORIGIN : 0));
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "video"); const ThemeData::ThemeElement* elem = theme->getElement(view, element, "video");
if(!elem) if(!elem)
{
return; return;
}
Vector2f scale = getParent() ? getParent()->getSize() : Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); Vector2f scale = getParent() ? getParent()->getSize() : Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight());
if ((properties & POSITION) && elem->has("pos"))
{
Vector2f denormalized = elem->get<Vector2f>("pos") * scale;
setPosition(Vector3f(denormalized.x(), denormalized.y(), 0));
mStaticImage.setPosition(Vector3f(denormalized.x(), denormalized.y(), 0));
}
if(properties & ThemeFlags::SIZE) if(properties & ThemeFlags::SIZE)
{ {
if(elem->has("size")) if(elem->has("size"))
@ -198,10 +196,6 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
setMaxSize(elem->get<Vector2f>("maxSize") * scale); setMaxSize(elem->get<Vector2f>("maxSize") * scale);
} }
// position + size also implies origin
if (((properties & ORIGIN) || ((properties & POSITION) && (properties & ThemeFlags::SIZE))) && elem->has("origin"))
setOrigin(elem->get<Vector2f>("origin"));
if(elem->has("default")) if(elem->has("default"))
mConfig.defaultVideoPath = elem->get<std::string>("default"); mConfig.defaultVideoPath = elem->get<std::string>("default");
@ -213,23 +207,6 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const s
if (elem->has("showSnapshotDelay")) if (elem->has("showSnapshotDelay"))
mConfig.showSnapshotDelay = elem->get<bool>("showSnapshotDelay"); mConfig.showSnapshotDelay = elem->get<bool>("showSnapshotDelay");
if(properties & ThemeFlags::ROTATION) {
if(elem->has("rotation"))
setRotationDegrees(elem->get<float>("rotation"));
if(elem->has("rotationOrigin"))
setRotationOrigin(elem->get<Vector2f>("rotationOrigin"));
}
if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex"))
setZIndex(elem->get<float>("zIndex"));
else
setZIndex(getDefaultZIndex());
if(properties & ThemeFlags::VISIBLE && elem->has("visible"))
setVisible(elem->get<bool>("visible"));
else
setVisible(true);
} }
std::vector<HelpPrompt> VideoComponent::getHelpPrompts() std::vector<HelpPrompt> VideoComponent::getHelpPrompts()

View file

@ -45,6 +45,7 @@ public:
virtual void topWindow(bool isTop) override; virtual void topWindow(bool isTop) override;
void onOriginChanged() override; void onOriginChanged() override;
void onPositionChanged() override;
void onSizeChanged() override; void onSizeChanged() override;
void setOpacity(unsigned char opacity) override; void setOpacity(unsigned char opacity) override;