Clean up use of transforms in scene graph.
This commit is contained in:
parent
3915a40c96
commit
f26ee2ebc4
37 changed files with 238 additions and 242 deletions
|
@ -203,9 +203,14 @@ bool Button::isDirty() const
|
|||
|
||||
void Button::doPaint(const PaintEvent* event)
|
||||
{
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mRootNode->setTransform(Transform(mLocation));
|
||||
mTransformDirty = false;
|
||||
}
|
||||
|
||||
updateBackground(event);
|
||||
updateLabel(event);
|
||||
|
||||
updateIcon(event);
|
||||
|
||||
mContentDirty = false;
|
||||
|
@ -215,17 +220,12 @@ void Button::updateLabel(const PaintEvent* event)
|
|||
{
|
||||
if (!mTextNode)
|
||||
{
|
||||
mTextNode = TextNode::Create(mLabel, mLocation);
|
||||
mTextNode = TextNode::Create(mLabel, Transform({ mSize.mWidth /2.0, mSize.mHeight / 2.0 }));
|
||||
mTextNode->setName(mName + "_TextNode");
|
||||
mTextNode->setContent(mLabel);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
}
|
||||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mTextNode->setLocation(mLocation);
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
}
|
||||
|
||||
if (mMaterialDirty)
|
||||
|
@ -255,14 +255,14 @@ void Button::updateIcon(const PaintEvent* event)
|
|||
{
|
||||
if (!mIconNode && mIcon != Resource::Icon::Svg::NONE)
|
||||
{
|
||||
mIconNode = std::make_unique<IconNode>(mLocation);
|
||||
mIconNode = std::make_unique<IconNode>(Transform());
|
||||
mIconNode->setName(mName + "_IconNode");
|
||||
mIconNode->setContent(IconNode::IconType::Svg, MediaResourceManager::getSvgIconNode(mIcon));
|
||||
mIconNode->setSvgContent(MediaResourceManager::getSvgIconNode(mIcon));
|
||||
mRootNode->addChild(mIconNode.get());
|
||||
}
|
||||
else if (mContentDirty && mIcon != Resource::Icon::Svg::NONE)
|
||||
{
|
||||
mIconNode->setContent(IconNode::IconType::Svg, MediaResourceManager::getSvgIconNode(mIcon));
|
||||
mIconNode->setSvgContent(MediaResourceManager::getSvgIconNode(mIcon));
|
||||
}
|
||||
|
||||
if (!mIconNode)
|
||||
|
@ -270,11 +270,6 @@ void Button::updateIcon(const PaintEvent* event)
|
|||
return;
|
||||
}
|
||||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mIconNode->setLocation(mLocation);
|
||||
}
|
||||
|
||||
if (mMaterialDirty)
|
||||
{
|
||||
auto icon_fill = event->getThemesManager()->getColor(mIconColor);
|
||||
|
|
|
@ -46,7 +46,7 @@ void Label::updateLabel(const PaintEvent* event)
|
|||
|
||||
if (!mTextNode)
|
||||
{
|
||||
mTextNode = TextNode::Create(mLabel, middle);
|
||||
mTextNode = TextNode::Create(mLabel, Transform());
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
|
@ -57,13 +57,6 @@ void Label::updateLabel(const PaintEvent* event)
|
|||
mTextNode->setFillColor(event->getThemesManager()->getColor(mBackground));
|
||||
}
|
||||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mTextNode->setLocation(middle);
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
}
|
||||
|
||||
if (mContentDirty)
|
||||
{
|
||||
mTextNode->setContent(mLabel);
|
||||
|
|
|
@ -86,11 +86,9 @@ void TextBox::doPaint(const PaintEvent* event)
|
|||
|
||||
void TextBox::updateLabel(const PaintEvent* event)
|
||||
{
|
||||
auto loc = DiscretePoint(mLocation.getX() + mPadding.mLeft, mLocation.getY() + mPadding.mTop + unsigned(0));
|
||||
|
||||
if (!mTextNode)
|
||||
{
|
||||
mTextNode = TextNode::Create(mContent, loc);
|
||||
mTextNode = TextNode::Create(mContent, Transform());
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
|
@ -103,7 +101,6 @@ void TextBox::updateLabel(const PaintEvent* event)
|
|||
|
||||
if (mTransformDirty)
|
||||
{
|
||||
mTextNode->setLocation(loc);
|
||||
mTextNode->setWidth(mSize.mWidth);
|
||||
mTextNode->setHeight(mSize.mHeight);
|
||||
}
|
||||
|
|
|
@ -2,12 +2,22 @@
|
|||
|
||||
#include "SvgNode.h"
|
||||
|
||||
IconNode::IconNode(const Point& loc)
|
||||
: AbstractVisualNode(loc)
|
||||
IconNode::IconNode(const Transform& transform)
|
||||
: AbstractVisualNode(transform)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
unsigned IconNode::getContentWidth() const
|
||||
{
|
||||
return mSvgContent->getContentWidth();
|
||||
}
|
||||
|
||||
unsigned IconNode::getContentHeight() const
|
||||
{
|
||||
return mSvgContent->getContentHeight();
|
||||
}
|
||||
|
||||
void IconNode::setSvgContent(std::unique_ptr<SvgNode> svg_node)
|
||||
{
|
||||
mChildren.clear();
|
||||
|
@ -29,27 +39,10 @@ void IconNode::setFillColor(const Color& color)
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
mSvgContent->setStrokeColor(color);
|
||||
}
|
||||
}
|
|
@ -14,13 +14,11 @@ public:
|
|||
Svg
|
||||
};
|
||||
|
||||
IconNode(const Point& loc);
|
||||
IconNode(const Transform& transform = {});
|
||||
|
||||
void setLocation(const Point& loc) override;
|
||||
unsigned getContentWidth() const;
|
||||
|
||||
void setWidth(unsigned width);
|
||||
|
||||
void setHeight(unsigned height);
|
||||
unsigned getContentHeight() const;
|
||||
|
||||
void setFillColor(const Color& color);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ Path MediaResourceManager::getSvgIconPath(Resource::Icon::Svg icon)
|
|||
return mResourceLocation / MediaResources::getPath(icon);
|
||||
}
|
||||
|
||||
std::unique_ptr<AbstractVisualNode> MediaResourceManager::getSvgIconNode(Resource::Icon::Svg icon)
|
||||
std::unique_ptr<SvgNode> MediaResourceManager::getSvgIconNode(Resource::Icon::Svg icon)
|
||||
{
|
||||
const auto path = getSvgIconPath(icon);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "MediaResources.h"
|
||||
#include "AbstractVisualNode.h"
|
||||
#include "SvgNode.h"
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
|
@ -10,7 +10,7 @@ using Path = std::filesystem::path;
|
|||
class MediaResourceManager
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<AbstractVisualNode> getSvgIconNode(Resource::Icon::Svg icon);
|
||||
static std::unique_ptr<SvgNode> getSvgIconNode(Resource::Icon::Svg icon);
|
||||
|
||||
static Path getSvgIconPath(Resource::Icon::Svg icon);
|
||||
|
||||
|
|
|
@ -317,9 +317,9 @@ void Widget::createOrUpdateGeometry()
|
|||
const auto deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom;
|
||||
if (!mBackgroundNode)
|
||||
{
|
||||
const auto locX = mLocation.getX() + mMargin.mLeft;
|
||||
const auto locY = mLocation.getY() + mMargin.mTop;
|
||||
mBackgroundNode = std::make_unique<RectangleNode>(DiscretePoint(locX, locY), deltaX, deltaY);
|
||||
Point margin_offset(mMargin.mLeft, mMargin.mTop);
|
||||
|
||||
mBackgroundNode = std::make_unique<RectangleNode>(Transform(margin_offset), deltaX, deltaY);
|
||||
mBackgroundNode->setRadius(mRadius);
|
||||
|
||||
mBackgroundNode->setName(mName + "_BackgroundNode");
|
||||
|
@ -335,9 +335,7 @@ void Widget::createOrUpdateGeometry()
|
|||
|
||||
void Widget::updateTransform()
|
||||
{
|
||||
const auto locX = mLocation.getX() + mMargin.mLeft;
|
||||
const auto locY = mLocation.getY() + mMargin.mTop;
|
||||
mBackgroundNode->setLocation(DiscretePoint(locX, locY));
|
||||
mRootNode->setTransform({ mLocation });
|
||||
}
|
||||
|
||||
void Widget::updateMaterial(const PaintEvent* event)
|
||||
|
@ -401,25 +399,30 @@ mt::Window* Widget::getTopLevelWindow() const
|
|||
return mWindow;
|
||||
}
|
||||
|
||||
std::cout << "I am " << getName() << std::endl;
|
||||
|
||||
auto lastParent = mParent;
|
||||
auto nextParent = mParent;
|
||||
while(nextParent)
|
||||
{
|
||||
auto temp = lastParent;
|
||||
lastParent = nextParent;
|
||||
nextParent = lastParent->getParent();
|
||||
std::cout << "Checking if " << lastParent->getName() << std::endl;
|
||||
nextParent = temp->getParent();
|
||||
if (nextParent)
|
||||
{
|
||||
std::cout << "Next is " << nextParent->getName() << std::endl;
|
||||
//std::cout << "Next is " << nextParent->getName() << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "no next" << std::endl;
|
||||
//std::cout << "no next" << std::endl;
|
||||
}
|
||||
}
|
||||
return lastParent->getTopLevelWindow();
|
||||
if (lastParent)
|
||||
{
|
||||
return lastParent->getTopLevelWindow();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Widget* Widget::getParent() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue