Add path rendering.
This commit is contained in:
parent
f2ab532005
commit
97afa782a0
39 changed files with 1148 additions and 131 deletions
|
@ -3,12 +3,15 @@
|
|||
#include "TextNode.h"
|
||||
#include "GeometryNode.h"
|
||||
#include "TransformNode.h"
|
||||
#include "ThemeManager.h"
|
||||
#include "PaintEvent.h"
|
||||
#include "IconNode.h"
|
||||
|
||||
#include "FontTokens.h"
|
||||
#include "ThemeManager.h"
|
||||
#include "MediaResourceManager.h"
|
||||
|
||||
#include "PaintEvent.h"
|
||||
#include "MouseEvent.h"
|
||||
|
||||
#include "FileLogger.h"
|
||||
|
||||
Button::Button(ButtonData::Component component)
|
||||
|
@ -48,6 +51,15 @@ void Button::setLabel(const std::string& text)
|
|||
}
|
||||
}
|
||||
|
||||
void Button::setSvgIcon(Resource::Icon::Svg icon)
|
||||
{
|
||||
if (icon != mIcon)
|
||||
{
|
||||
mIcon = icon;
|
||||
mContentDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Button::setState(ButtonData::State state)
|
||||
{
|
||||
if (mStyle.mState != state)
|
||||
|
@ -170,6 +182,10 @@ void Button::doPaint(const PaintEvent* event)
|
|||
{
|
||||
updateBackground(event);
|
||||
updateLabel(event);
|
||||
|
||||
updateIcon(event);
|
||||
|
||||
mContentDirty = false;
|
||||
}
|
||||
|
||||
void Button::updateLabel(const PaintEvent* event)
|
||||
|
@ -204,7 +220,6 @@ void Button::updateLabel(const PaintEvent* event)
|
|||
if (mContentDirty)
|
||||
{
|
||||
mTextNode->setContent(mLabel);
|
||||
mContentDirty = false;
|
||||
}
|
||||
|
||||
if (mVisibilityDirty)
|
||||
|
@ -212,3 +227,40 @@ void Button::updateLabel(const PaintEvent* event)
|
|||
mTextNode->setIsVisible(mVisible);
|
||||
}
|
||||
}
|
||||
|
||||
void Button::updateIcon(const PaintEvent* event)
|
||||
{
|
||||
if (!mIconNode && mIcon != Resource::Icon::Svg::NONE)
|
||||
{
|
||||
mIconNode = std::make_unique<IconNode>(mLocation);
|
||||
mIconNode->setName(mName + "_IconNode");
|
||||
mIconNode->setContent(IconNode::IconType::Svg, MediaResourceManager::getSvgIconNode(mIcon));
|
||||
mRootNode->addChild(mIconNode.get());
|
||||
}
|
||||
|
||||
if (!mIconNode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mIconNode->setLocation(mLocation);
|
||||
}
|
||||
|
||||
if (mMaterialDirty)
|
||||
{
|
||||
auto icon_fill = event->getThemesManager()->getColor(mIconColor);
|
||||
icon_fill.setAlpha(mIconOpacity);
|
||||
}
|
||||
|
||||
if (mContentDirty)
|
||||
{
|
||||
mIconNode->setContent(IconNode::IconType::Svg, MediaResourceManager::getSvgIconNode(mIcon));
|
||||
}
|
||||
|
||||
if (mVisibilityDirty)
|
||||
{
|
||||
mIconNode->setIsVisible(mVisible);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "Widget.h"
|
||||
#include "Color.h"
|
||||
|
||||
#include "MediaResources.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
|
@ -23,6 +25,8 @@ public:
|
|||
|
||||
static std::unique_ptr<Button> Create(ButtonData::Component component = ButtonData::Component::Elevated);
|
||||
|
||||
void setSvgIcon(Resource::Icon::Svg icon);
|
||||
|
||||
void setLabel(const std::string& text);
|
||||
|
||||
void setEnabled(bool isEnabled);
|
||||
|
@ -40,6 +44,7 @@ protected:
|
|||
void setLabelTextTypescale(Theme::Sys::Typescale typescale);
|
||||
|
||||
void updateLabel(const PaintEvent* event);
|
||||
void updateIcon(const PaintEvent* event);
|
||||
|
||||
void setState(ButtonData::State state);
|
||||
void resetState();
|
||||
|
@ -52,14 +57,16 @@ private:
|
|||
Theme::Sys::Color mLabelTextColor;
|
||||
Theme::Sys::Typescale mLabelTextTypescale;
|
||||
float mLabelOpacity{ 1.0 };
|
||||
|
||||
clickFunc mClickFunc;
|
||||
|
||||
std::unique_ptr<TextNode> mTextNode;
|
||||
bool mContentDirty{true};
|
||||
|
||||
Resource::Icon::Svg mIcon{ Resource::Icon::Svg::NONE};
|
||||
Theme::Sys::Color mIconColor;
|
||||
float mIconOpacity{ 1.0 };
|
||||
std::unique_ptr<IconNode> mIconNode;
|
||||
|
||||
bool mContentDirty{ true };
|
||||
|
||||
clickFunc mClickFunc;
|
||||
bool mEnabled{ true };
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#include "IconNode.h"
|
||||
|
||||
IconNode::IconNode(const Point& loc)
|
||||
: AbstractVisualNode(loc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IconNode::setContent(IconType type, std::unique_ptr<AbstractVisualNode> content)
|
||||
{
|
||||
mType = type;
|
||||
mContent = std::move(content);
|
||||
mContentDirty = true;
|
||||
}
|
|
@ -2,8 +2,23 @@
|
|||
|
||||
#include "AbstractVisualNode.h"
|
||||
|
||||
class IconNode
|
||||
class IconNode : public AbstractVisualNode
|
||||
{
|
||||
public:
|
||||
|
||||
enum class IconType
|
||||
{
|
||||
Image,
|
||||
Svg
|
||||
};
|
||||
|
||||
IconNode(const Point& loc);
|
||||
|
||||
void setContent(IconType type, std::unique_ptr<AbstractVisualNode>);
|
||||
|
||||
private:
|
||||
std::unique_ptr<AbstractVisualNode> mContent;
|
||||
IconType mType{ IconType::Svg };
|
||||
bool mContentDirty{ true };
|
||||
|
||||
};
|
|
@ -0,0 +1,33 @@
|
|||
#include "MediaResourceManager.h"
|
||||
|
||||
#include "SvgReader.h"
|
||||
#include "SvgDocument.h"
|
||||
#include "SvgNode.h"
|
||||
|
||||
const Path MediaResourceManager::mResourceLocation = "C:\\dev\\MediaResources";
|
||||
|
||||
Path MediaResourceManager::getSvgIconPath(Resource::Icon::Svg icon)
|
||||
{
|
||||
return mResourceLocation / MediaResources::getPath(icon);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractVisualNode> MediaResourceManager::getSvgIconNode(Resource::Icon::Svg icon)
|
||||
{
|
||||
const auto path = getSvgIconPath(icon);
|
||||
|
||||
if (path.empty())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SvgReader svg_reader;
|
||||
auto svg_doc = svg_reader.read(path);
|
||||
if (!svg_doc)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto svg_node = std::make_unique<SvgNode>(Point(0.0, 0.0));
|
||||
svg_node->setContent(std::move(svg_doc));
|
||||
return std::move(svg_node);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
#pragma once
|
||||
|
||||
#include "MediaResources.h"
|
||||
#include "AbstractVisualNode.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
||||
class MediaResourceManager
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<AbstractVisualNode> getSvgIconNode(Resource::Icon::Svg icon);
|
||||
|
||||
static Path getSvgIconPath(Resource::Icon::Svg icon);
|
||||
|
||||
private:
|
||||
static const Path mResourceLocation;
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
#include "MediaResources.h"
|
||||
|
||||
Path MediaResources::getPath(Resource::Icon::Svg icon)
|
||||
{
|
||||
switch (icon)
|
||||
{
|
||||
case Resource::Icon::Svg::HOME_MEDIUM:
|
||||
return "svg/home_medium.svg";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
using Path = std::filesystem::path;
|
||||
|
||||
namespace Resource
|
||||
{
|
||||
namespace Icon
|
||||
{
|
||||
enum class Svg
|
||||
{
|
||||
NONE,
|
||||
HOME_MEDIUM
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class MediaResources
|
||||
{
|
||||
public:
|
||||
static Path getPath(Resource::Icon::Svg icon);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue