Start cleaning icon.
This commit is contained in:
parent
97afa782a0
commit
3915a40c96
10 changed files with 172 additions and 33 deletions
|
@ -41,7 +41,7 @@ public:
|
|||
|
||||
void setName(const std::string& name);
|
||||
|
||||
void setLocation(const Point& loc);
|
||||
virtual void setLocation(const Point& loc);
|
||||
|
||||
virtual void update(SceneInfo* sceneInfo);
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "SvgShapeElements.h"
|
||||
|
||||
SvgNode::SvgNode(const Point& location)
|
||||
: AbstractVisualNode(location)
|
||||
: MaterialNode(location)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,25 @@ void SvgNode::setContent(std::unique_ptr<SvgDocument> doc)
|
|||
mContentDirty = true;
|
||||
|
||||
mChildren.clear();
|
||||
mManagedChildren.clear();
|
||||
mGeometryNodes.clear();
|
||||
}
|
||||
|
||||
void SvgNode::setWidth(unsigned width)
|
||||
{
|
||||
if (mWidth != width)
|
||||
{
|
||||
mWidth = width;
|
||||
mTransformIsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SvgNode::setHeight(unsigned height)
|
||||
{
|
||||
if (mHeight != height)
|
||||
{
|
||||
mHeight = height;
|
||||
mTransformIsDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SvgNode::updateTransform()
|
||||
|
@ -37,25 +55,23 @@ void SvgNode::createOrUpdateGeometry(SceneInfo* sceneInfo)
|
|||
|
||||
for (const auto& svg_element : mContent->getRoot()->getChildren())
|
||||
{
|
||||
std::unique_ptr<AbstractVisualNode> node;
|
||||
std::unique_ptr<GeometryNode> geom_node;
|
||||
|
||||
if (svg_element->getTagName() == "circle")
|
||||
{
|
||||
onCircle(svg_element.get(), node);
|
||||
onCircle(svg_element.get(), geom_node);
|
||||
}
|
||||
else if (svg_element->getTagName() == "path")
|
||||
{
|
||||
onPath(svg_element.get(), node);
|
||||
onPath(svg_element.get(), geom_node);
|
||||
}
|
||||
|
||||
if (!node)
|
||||
AbstractVisualNode* raw_node{ nullptr };
|
||||
if (geom_node)
|
||||
{
|
||||
continue;
|
||||
raw_node = geom_node.get();
|
||||
mGeometryNodes.push_back(std::move(geom_node));
|
||||
}
|
||||
|
||||
auto raw_node = node.get();
|
||||
mManagedChildren.push_back(std::move(node));
|
||||
|
||||
addChild(raw_node);
|
||||
}
|
||||
}
|
||||
|
@ -73,9 +89,43 @@ void SvgNode::update(SceneInfo* sceneInfo)
|
|||
updateTransform();
|
||||
mTransformIsDirty = false;
|
||||
}
|
||||
|
||||
if (mMaterialIsDirty)
|
||||
{
|
||||
if (mHasFillColor)
|
||||
{
|
||||
for (const auto& geom_node : mGeometryNodes)
|
||||
{
|
||||
geom_node->setFillColor(mFillColor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const auto& geom_node : mGeometryNodes)
|
||||
{
|
||||
geom_node->setHasFillColor(false);
|
||||
}
|
||||
}
|
||||
|
||||
void SvgNode::onCircle(XmlElement* element, std::unique_ptr<AbstractVisualNode>& node)
|
||||
if (mHasStrokeColor)
|
||||
{
|
||||
for (const auto& geom_node : mGeometryNodes)
|
||||
{
|
||||
geom_node->setStrokeColor(mStrokeColor);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const auto& geom_node : mGeometryNodes)
|
||||
{
|
||||
geom_node->setHasStrokeColor(false);
|
||||
}
|
||||
}
|
||||
mMaterialIsDirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
void SvgNode::onCircle(XmlElement* element, std::unique_ptr<GeometryNode>& node)
|
||||
{
|
||||
auto svg_circle = dynamic_cast<SvgCircle*>(element);
|
||||
auto loc = svg_circle->getLocation();
|
||||
|
@ -100,7 +150,7 @@ void SvgNode::onCircle(XmlElement* element, std::unique_ptr<AbstractVisualNode>&
|
|||
node = std::move(circle_node);
|
||||
}
|
||||
|
||||
void SvgNode::onPath(XmlElement* element, std::unique_ptr<AbstractVisualNode>& node)
|
||||
void SvgNode::onPath(XmlElement* element, std::unique_ptr<GeometryNode>& node)
|
||||
{
|
||||
auto svg_path = dynamic_cast<SvgPath*>(element);
|
||||
|
||||
|
|
|
@ -1,28 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include "AbstractVisualNode.h"
|
||||
#include "MaterialNode.h"
|
||||
#include "GeometryNode.h"
|
||||
#include "SvgDocument.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class SvgNode : public AbstractVisualNode
|
||||
class SvgNode : public MaterialNode
|
||||
{
|
||||
public:
|
||||
SvgNode(const Point& location);
|
||||
|
||||
void setContent(std::unique_ptr<SvgDocument> doc);
|
||||
|
||||
void setWidth(unsigned width);
|
||||
void setHeight(unsigned height);
|
||||
|
||||
void update(SceneInfo* sceneInfo);
|
||||
private:
|
||||
void createOrUpdateGeometry(SceneInfo* sceneInfo);
|
||||
void updateTransform();
|
||||
|
||||
void onCircle(XmlElement* element, std::unique_ptr<AbstractVisualNode>& node);
|
||||
void onPath(XmlElement* element, std::unique_ptr<AbstractVisualNode>& node);
|
||||
void onCircle(XmlElement* element, std::unique_ptr<GeometryNode>& node);
|
||||
void onPath(XmlElement* element, std::unique_ptr<GeometryNode>& node);
|
||||
|
||||
unsigned mWidth{ 0 };
|
||||
unsigned mHeight{ 0 };
|
||||
|
||||
bool mContentDirty{ true };
|
||||
|
||||
std::vector<std::unique_ptr<AbstractVisualNode> > mManagedChildren;
|
||||
std::vector<std::unique_ptr<GeometryNode> > mGeometryNodes;
|
||||
std::unique_ptr<SvgDocument> mContent;
|
||||
};
|
||||
|
|
|
@ -21,6 +21,8 @@ Button::Button(ButtonData::Component component)
|
|||
{
|
||||
mStyle.mComponent = component;
|
||||
mName = "Button";
|
||||
setWidth(150);
|
||||
setMaxWidth(150);
|
||||
|
||||
setHeight(mStyle.getContainerHeight());
|
||||
setMaxHeight(mStyle.getContainerHeight());
|
||||
|
@ -95,6 +97,9 @@ void Button::updateState()
|
|||
setLabelTextColor(mStyle.getLabelTextColor());
|
||||
setLabelTextOpacity(mStyle.getLabelOpacity());
|
||||
setLabelTextTypescale(mStyle.getLabelTypescale());
|
||||
|
||||
setIconColor(mStyle.getIconColor());
|
||||
//setIconOpacity()
|
||||
}
|
||||
|
||||
void Button::setLabelTextColor(Theme::Sys::Color color)
|
||||
|
@ -124,6 +129,24 @@ void Button::setLabelTextTypescale(Theme::Sys::Typescale typescale)
|
|||
}
|
||||
}
|
||||
|
||||
void Button::setIconColor(Theme::Sys::Color color)
|
||||
{
|
||||
if (mIconColor != color)
|
||||
{
|
||||
mIconColor = color;
|
||||
mMaterialDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Button::setIconOpacity(float opacity)
|
||||
{
|
||||
if (mIconOpacity!= opacity)
|
||||
{
|
||||
mIconOpacity = opacity;
|
||||
mMaterialDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Button::onMyMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
if (!mEnabled)
|
||||
|
@ -237,6 +260,10 @@ void Button::updateIcon(const PaintEvent* event)
|
|||
mIconNode->setContent(IconNode::IconType::Svg, MediaResourceManager::getSvgIconNode(mIcon));
|
||||
mRootNode->addChild(mIconNode.get());
|
||||
}
|
||||
else if (mContentDirty && mIcon != Resource::Icon::Svg::NONE)
|
||||
{
|
||||
mIconNode->setContent(IconNode::IconType::Svg, MediaResourceManager::getSvgIconNode(mIcon));
|
||||
}
|
||||
|
||||
if (!mIconNode)
|
||||
{
|
||||
|
@ -252,11 +279,7 @@ void Button::updateIcon(const PaintEvent* event)
|
|||
{
|
||||
auto icon_fill = event->getThemesManager()->getColor(mIconColor);
|
||||
icon_fill.setAlpha(mIconOpacity);
|
||||
}
|
||||
|
||||
if (mContentDirty)
|
||||
{
|
||||
mIconNode->setContent(IconNode::IconType::Svg, MediaResourceManager::getSvgIconNode(mIcon));
|
||||
mIconNode->setFillColor(icon_fill);
|
||||
}
|
||||
|
||||
if (mVisibilityDirty)
|
||||
|
|
|
@ -43,6 +43,9 @@ protected:
|
|||
void setLabelTextOpacity(float opacity);
|
||||
void setLabelTextTypescale(Theme::Sys::Typescale typescale);
|
||||
|
||||
void setIconColor(Theme::Sys::Color color);
|
||||
void setIconOpacity(float opacity);
|
||||
|
||||
void updateLabel(const PaintEvent* event);
|
||||
void updateIcon(const PaintEvent* event);
|
||||
|
||||
|
|
|
@ -1,14 +1,55 @@
|
|||
#include "IconNode.h"
|
||||
|
||||
#include "SvgNode.h"
|
||||
|
||||
IconNode::IconNode(const Point& loc)
|
||||
: AbstractVisualNode(loc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IconNode::setContent(IconType type, std::unique_ptr<AbstractVisualNode> content)
|
||||
void IconNode::setSvgContent(std::unique_ptr<SvgNode> svg_node)
|
||||
{
|
||||
mType = type;
|
||||
mContent = std::move(content);
|
||||
mChildren.clear();
|
||||
|
||||
mType = IconType::Svg;
|
||||
|
||||
mSvgContent = std::move(svg_node);
|
||||
mContentDirty = true;
|
||||
|
||||
addChild(mSvgContent.get());
|
||||
}
|
||||
|
||||
void IconNode::setFillColor(const Color& color)
|
||||
{
|
||||
if (mType == IconType::Svg)
|
||||
{
|
||||
mSvgContent->setFillColor(color);
|
||||
mSvgContent->setHasStrokeColor(false);
|
||||
}
|
||||
}
|
||||
|
||||
void IconNode::setWidth(unsigned width)
|
||||
{
|
||||
if (mType == IconType::Svg)
|
||||
{
|
||||
mSvgContent->setWidth(width);
|
||||
}
|
||||
}
|
||||
|
||||
void IconNode::setHeight(unsigned height)
|
||||
{
|
||||
if (mType == IconType::Svg)
|
||||
{
|
||||
mSvgContent->setFillColor(height);
|
||||
mSvgContent->setHasStrokeColor(false);
|
||||
}
|
||||
}
|
||||
|
||||
void IconNode::setOutlineColor(const Color& color)
|
||||
{
|
||||
if (mType == IconType::Svg)
|
||||
{
|
||||
dynamic_cast<SvgNode*>(mContent.get())->setStrokeColor(color);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "AbstractVisualNode.h"
|
||||
|
||||
#include "SvgNode.h"
|
||||
|
||||
class IconNode : public AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
|
@ -14,10 +16,21 @@ public:
|
|||
|
||||
IconNode(const Point& loc);
|
||||
|
||||
void setContent(IconType type, std::unique_ptr<AbstractVisualNode>);
|
||||
void setLocation(const Point& loc) override;
|
||||
|
||||
void setWidth(unsigned width);
|
||||
|
||||
void setHeight(unsigned height);
|
||||
|
||||
void setFillColor(const Color& color);
|
||||
|
||||
void setOutlineColor(const Color& color);
|
||||
|
||||
void setSvgContent(std::unique_ptr<SvgNode> svg_node);
|
||||
|
||||
private:
|
||||
std::unique_ptr<AbstractVisualNode> mContent;
|
||||
std::unique_ptr<SvgNode> mSvgContent;
|
||||
|
||||
IconType mType{ IconType::Svg };
|
||||
bool mContentDirty{ true };
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ unsigned FontTokens::getSize(Theme::Sys::Typescale typescale)
|
|||
switch (typescale)
|
||||
{
|
||||
case Theme::Sys::Typescale::Label_Large:
|
||||
return static_cast<unsigned>(57/3);
|
||||
return static_cast<unsigned>(57/3.5);
|
||||
default:
|
||||
return 57;
|
||||
}
|
||||
|
|
|
@ -23,18 +23,20 @@ TEST_CASE(TestButton_Elevated, "ui_controls")
|
|||
enabled_button->setLabel("Enabled");
|
||||
enabled_button->setSvgIcon(Resource::Icon::Svg::HOME_MEDIUM);
|
||||
|
||||
/*
|
||||
|
||||
auto disabled_button = Button::Create(ButtonData::Component::Elevated);
|
||||
disabled_button->setEnabled(false);
|
||||
disabled_button->setLabel("Disabled");
|
||||
disabled_button->setSvgIcon(Resource::Icon::Svg::HOME_MEDIUM);
|
||||
|
||||
/*
|
||||
auto pressed_button = Button::Create(ButtonData::Component::Elevated);
|
||||
pressed_button->setLabel("Pressed");
|
||||
|
||||
*/
|
||||
|
||||
spacer.addWidget(std::move(enabled_button));
|
||||
//spacer.addWidget(std::move(disabled_button));
|
||||
spacer.addWidget(std::move(disabled_button));
|
||||
//spacer.addWidget(std::move(pressed_button));
|
||||
|
||||
auto node = spacer.getRootNode();
|
||||
|
|
Loading…
Reference in a new issue