Clean project structure.

This commit is contained in:
jmsgrogan 2023-01-17 10:13:25 +00:00
parent 78a4fa99ff
commit 947bf937fd
496 changed files with 206 additions and 137 deletions

View file

@ -0,0 +1,110 @@
#include "Button.h"
#include "TextNode.h"
#include "GeometryNode.h"
#include "TransformNode.h"
#include "MouseEvent.h"
#include "FileLogger.h"
Button::Button()
: Widget(),
mLabel(),
mCachedColor(255, 255, 255),
mClickedColor(Color(180, 180, 180)),
mClickFunc()
{
mName = "Button";
}
Button::~Button()
{
}
std::unique_ptr<Button> Button::Create()
{
return std::make_unique<Button>();
}
void Button::setOnClickFunction(clickFunc func)
{
mClickFunc = func;
}
void Button::setLabel(const std::string& text)
{
if (text != mLabel)
{
mLabel = text;
mContentDirty = true;
}
}
void Button::onMyMouseEvent(const MouseEvent* event)
{
MLOG_INFO("Widget mouse event");
if(event->getAction() == MouseEvent::Action::Pressed)
{
mCachedColor = mBackgroundColor;
setBackgroundColor(mClickedColor);
if(mClickFunc)
{
mClickFunc(this);
}
}
else if(event->getAction() == MouseEvent::Action::Released)
{
setBackgroundColor(mCachedColor);
}
}
bool Button::isDirty() const
{
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);
mTextNode->setName(mName + "_TextNode");
mTextNode->setContent(mLabel);
mTextNode->setWidth(mSize.mWidth);
mTextNode->setHeight(mSize.mHeight);
mRootNode->addChild(mTextNode.get());
}
if (mTransformDirty)
{
mTextNode->setLocation(middle);
mTextNode->setWidth(mSize.mWidth);
mTextNode->setHeight(mSize.mHeight);
}
if (mMaterialDirty)
{
mTextNode->setFillColor(mBackgroundColor);
}
if (mContentDirty)
{
mTextNode->setContent(mLabel);
mContentDirty = false;
}
if (mVisibilityDirty)
{
mTextNode->setIsVisible(mVisible);
}
}