From 3b07bfeb932bfeaa6020e44db6a05f71a9afe3d3 Mon Sep 17 00:00:00 2001 From: John Rassa Date: Fri, 30 Aug 2019 21:57:32 -0400 Subject: [PATCH] cleanup duplicate theme code in Image/Video components --- es-core/src/components/ImageComponent.cpp | 34 ++------------------- es-core/src/components/VideoComponent.cpp | 37 +++++------------------ es-core/src/components/VideoComponent.h | 1 + 3 files changed, 11 insertions(+), 61 deletions(-) diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index 8f78aaac5..6ffeb0747 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -401,20 +401,14 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, const s { using namespace ThemeFlags; + GuiComponent::applyTheme(theme, view, element, (properties ^ SIZE) | ((properties & (SIZE | POSITION)) ? ORIGIN : 0)); + const ThemeData::ThemeElement* elem = theme->getElement(view, element, "image"); if(!elem) - { return; - } Vector2f scale = getParent() ? getParent()->getSize() : Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); - if(properties & POSITION && elem->has("pos")) - { - Vector2f denormalized = elem->get("pos") * scale; - setPosition(Vector3f(denormalized.x(), denormalized.y(), 0)); - } - if(properties & ThemeFlags::SIZE) { if(elem->has("size")) @@ -425,13 +419,8 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, const s setMinSize(elem->get("minSize") * scale); } - // position + size also implies origin - if((properties & ORIGIN || (properties & POSITION && properties & ThemeFlags::SIZE)) && elem->has("origin")) - setOrigin(elem->get("origin")); - - if(elem->has("default")) { + if(elem->has("default")) setDefaultImage(elem->get("default")); - } if(properties & PATH && elem->has("path")) { @@ -453,23 +442,6 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, const s if (elem->has("gradientType")) setColorGradientHorizontal(!(elem->get("gradientType").compare("horizontal"))); } - - if(properties & ThemeFlags::ROTATION) { - if(elem->has("rotation")) - setRotationDegrees(elem->get("rotation")); - if(elem->has("rotationOrigin")) - setRotationOrigin(elem->get("rotationOrigin")); - } - - if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex")) - setZIndex(elem->get("zIndex")); - else - setZIndex(getDefaultZIndex()); - - if(properties & ThemeFlags::VISIBLE && elem->has("visible")) - setVisible(elem->get("visible")); - else - setVisible(true); } std::vector ImageComponent::getHelpPrompts() diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index 0bd73c9c0..af3f4d168 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -90,6 +90,11 @@ void VideoComponent::onOriginChanged() // Update the embeded static image mStaticImage.setOrigin(mOrigin); } +void VideoComponent::onPositionChanged() +{ + // Update the embeded static image + mStaticImage.setPosition(mPosition); +} void VideoComponent::onSizeChanged() { @@ -175,21 +180,14 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, const s { using namespace ThemeFlags; + GuiComponent::applyTheme(theme, view, element, (properties ^ SIZE) | ((properties & (SIZE | POSITION)) ? ORIGIN : 0)); + const ThemeData::ThemeElement* elem = theme->getElement(view, element, "video"); if(!elem) - { return; - } Vector2f scale = getParent() ? getParent()->getSize() : Vector2f((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); - if ((properties & POSITION) && elem->has("pos")) - { - Vector2f denormalized = elem->get("pos") * scale; - setPosition(Vector3f(denormalized.x(), denormalized.y(), 0)); - mStaticImage.setPosition(Vector3f(denormalized.x(), denormalized.y(), 0)); - } - if(properties & ThemeFlags::SIZE) { if(elem->has("size")) @@ -198,10 +196,6 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, const s setMaxSize(elem->get("maxSize") * scale); } - // position + size also implies origin - if (((properties & ORIGIN) || ((properties & POSITION) && (properties & ThemeFlags::SIZE))) && elem->has("origin")) - setOrigin(elem->get("origin")); - if(elem->has("default")) mConfig.defaultVideoPath = elem->get("default"); @@ -213,23 +207,6 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, const s if (elem->has("showSnapshotDelay")) mConfig.showSnapshotDelay = elem->get("showSnapshotDelay"); - - if(properties & ThemeFlags::ROTATION) { - if(elem->has("rotation")) - setRotationDegrees(elem->get("rotation")); - if(elem->has("rotationOrigin")) - setRotationOrigin(elem->get("rotationOrigin")); - } - - if(properties & ThemeFlags::Z_INDEX && elem->has("zIndex")) - setZIndex(elem->get("zIndex")); - else - setZIndex(getDefaultZIndex()); - - if(properties & ThemeFlags::VISIBLE && elem->has("visible")) - setVisible(elem->get("visible")); - else - setVisible(true); } std::vector VideoComponent::getHelpPrompts() diff --git a/es-core/src/components/VideoComponent.h b/es-core/src/components/VideoComponent.h index 8d8207b1c..8513129f9 100644 --- a/es-core/src/components/VideoComponent.h +++ b/es-core/src/components/VideoComponent.h @@ -45,6 +45,7 @@ public: virtual void topWindow(bool isTop) override; void onOriginChanged() override; + void onPositionChanged() override; void onSizeChanged() override; void setOpacity(unsigned char opacity) override;