Convert visual layers to scene nodes.
This commit is contained in:
parent
798cb365d7
commit
3e53bd9e00
64 changed files with 863 additions and 551 deletions
|
@ -2,7 +2,8 @@
|
|||
|
||||
#include "TextNode.h"
|
||||
#include "GeometryNode.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "TransformNode.h"
|
||||
|
||||
#include "MouseEvent.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -32,7 +33,7 @@ void Button::setLabel(const std::string& text)
|
|||
if (text != mLabel)
|
||||
{
|
||||
mLabel = text;
|
||||
mDirty = true;
|
||||
mContentDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,36 +54,36 @@ void Button::onMyMouseEvent(const MouseEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void Button::onPaintEvent(const PaintEvent* event)
|
||||
bool Button::isDirty() const
|
||||
{
|
||||
if (!needsUpdate())
|
||||
{
|
||||
return;
|
||||
}
|
||||
mLayers.clear();
|
||||
|
||||
if (mDirty)
|
||||
{
|
||||
mMyLayers.clear();
|
||||
if(!mVisible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
addBackground(event);
|
||||
|
||||
if(!mLabel.empty())
|
||||
{
|
||||
unsigned fontOffset = unsigned(mLabel.size()) * 4;
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset, mLocation.GetY() + mSize.mHeight/2 + 4);
|
||||
|
||||
auto textLayer = VisualLayer::Create();
|
||||
auto node = TextNode::Create(mLabel, middle);
|
||||
node->setFillColor(mBackgroundColor);
|
||||
textLayer->setTextNode(std::move(node));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
mDirty = false;
|
||||
addMyLayers();
|
||||
}
|
||||
|
||||
return Widget::isDirty() || mContentDirty;
|
||||
}
|
||||
|
||||
void Button::doPaint(const PaintEvent* event)
|
||||
{
|
||||
updateBackground(event);
|
||||
updateLabel(event);
|
||||
}
|
||||
|
||||
void Button::updateLabel(const PaintEvent* event)
|
||||
{
|
||||
unsigned fontOffset = unsigned(mLabel.size()) * 4;
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset, mLocation.GetY() + mSize.mHeight/2 + 4);
|
||||
|
||||
if (!mTextNode)
|
||||
{
|
||||
mTextNode = TextNode::Create(mLabel, middle);
|
||||
mRootNode->addChild(mTextNode.get());
|
||||
}
|
||||
|
||||
if (mMaterialDirty)
|
||||
{
|
||||
mTextNode->setFillColor(mBackgroundColor);
|
||||
}
|
||||
|
||||
if (mContentDirty)
|
||||
{
|
||||
mTextNode->setContent(mLabel);
|
||||
mContentDirty = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue