Cleaning for mesh addition.
This commit is contained in:
parent
8e0ce22b57
commit
402f381d10
67 changed files with 655 additions and 456 deletions
|
@ -1,7 +1,7 @@
|
|||
#include "Button.h"
|
||||
|
||||
#include "TextElement.h"
|
||||
#include "GeometryElement.h"
|
||||
#include "TextNode.h"
|
||||
#include "GeometryNode.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "MouseEvent.h"
|
||||
|
||||
|
@ -11,9 +11,10 @@ Button::Button()
|
|||
: Widget(),
|
||||
mLabel(),
|
||||
mCachedColor(255, 255, 255),
|
||||
mClickedColor(Color(180, 180, 180)),
|
||||
mClickFunc()
|
||||
{
|
||||
mClickedColor = Color::Create(180, 180, 180);
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<Button> Button::Create()
|
||||
|
@ -39,8 +40,8 @@ void Button::onMyMouseEvent(const MouseEvent* event)
|
|||
{
|
||||
if(event->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
mCachedColor = *mBackgroundColor;
|
||||
setBackgroundColor(Color::Create(*mClickedColor));
|
||||
mCachedColor = mBackgroundColor;
|
||||
setBackgroundColor(mClickedColor);
|
||||
if(mClickFunc)
|
||||
{
|
||||
mClickFunc(this);
|
||||
|
@ -48,7 +49,7 @@ void Button::onMyMouseEvent(const MouseEvent* event)
|
|||
}
|
||||
else if(event->GetAction() == MouseEvent::Action::Released)
|
||||
{
|
||||
setBackgroundColor(Color::Create(mCachedColor));
|
||||
setBackgroundColor(mCachedColor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,9 +75,9 @@ void Button::onPaintEvent(const PaintEvent* event)
|
|||
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 textElement = TextElement::Create(mLabel, middle);
|
||||
textElement->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
textLayer->SetText(std::move(textElement));
|
||||
auto textElement = TextNode::Create(mLabel, middle);
|
||||
textElement->setFillColor(mBackgroundColor);
|
||||
textLayer->setText(std::move(textElement));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
mDirty = false;
|
||||
|
|
|
@ -31,7 +31,7 @@ private:
|
|||
std::string mLabel;
|
||||
clickFunc mClickFunc;
|
||||
Color mCachedColor;
|
||||
ColorUPtr mClickedColor;
|
||||
Color mClickedColor;
|
||||
};
|
||||
|
||||
using ButtonUPtr = std::unique_ptr<Button>;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "Label.h"
|
||||
|
||||
#include "TextElement.h"
|
||||
#include "GeometryElement.h"
|
||||
#include "TextNode.h"
|
||||
#include "GeometryNode.h"
|
||||
#include "VisualLayer.h"
|
||||
|
||||
Label::Label()
|
||||
|
@ -44,12 +44,11 @@ void Label::onPaintEvent(const PaintEvent* 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 middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset, mLocation.GetY() + mSize.mHeight/2 + 4);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
auto textElement = TextElement::Create(mLabel, middle);
|
||||
textElement->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
textLayer->SetText(std::move(textElement));
|
||||
auto textElement = TextNode::Create(mLabel, middle);
|
||||
textElement->setFillColor(mBackgroundColor);
|
||||
textLayer->setText(std::move(textElement));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
addMyLayers();
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
class Label : public Widget
|
||||
{
|
||||
private:
|
||||
|
||||
std::string mLabel;
|
||||
|
||||
public:
|
||||
|
||||
|
@ -19,6 +16,10 @@ public:
|
|||
void setLabel(const std::string& text);
|
||||
|
||||
void onPaintEvent(const PaintEvent* event) override;
|
||||
|
||||
private:
|
||||
std::string mLabel;
|
||||
|
||||
};
|
||||
|
||||
using LabelUPtr = std::unique_ptr<Label>;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "TextBox.h"
|
||||
|
||||
#include "TextElement.h"
|
||||
#include "TextNode.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "GeometryElement.h"
|
||||
#include "GeometryNode.h"
|
||||
#include "KeyboardEvent.h"
|
||||
|
||||
#include <sstream>
|
||||
|
@ -12,7 +12,7 @@ TextBox::TextBox()
|
|||
mContent(),
|
||||
mCaps(false)
|
||||
{
|
||||
mBackgroundColor = Color::Create(250, 250, 250);
|
||||
mBackgroundColor = Color(250, 250, 250);
|
||||
mPadding = {10, 0, 10, 0};
|
||||
}
|
||||
|
||||
|
@ -21,17 +21,17 @@ std::unique_ptr<TextBox> TextBox::Create()
|
|||
return std::make_unique<TextBox>();
|
||||
}
|
||||
|
||||
void TextBox::SetContent(const std::string& text)
|
||||
void TextBox::setContent(const std::string& text)
|
||||
{
|
||||
mContent = text;
|
||||
}
|
||||
|
||||
std::string TextBox::GetContent() const
|
||||
std::string TextBox::getContent() const
|
||||
{
|
||||
return mContent;
|
||||
}
|
||||
|
||||
void TextBox::AppendContent(const std::string& text)
|
||||
void TextBox::appendContent(const std::string& text)
|
||||
{
|
||||
mContent += text;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
|
|||
const auto keyString = event->GetKeyString();
|
||||
if (keyString == "KEY_RETURN")
|
||||
{
|
||||
AppendContent("\n");
|
||||
appendContent("\n");
|
||||
}
|
||||
else if (keyString == "KEY_BACK")
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
|
|||
}
|
||||
else if (keyString == "KEY_SPACE")
|
||||
{
|
||||
AppendContent(" ");
|
||||
appendContent(" ");
|
||||
}
|
||||
else if (keyString == "KEY_CAPS")
|
||||
{
|
||||
|
@ -62,11 +62,11 @@ bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
|
|||
if (mCaps && !keyString.empty())
|
||||
{
|
||||
const char c = std::toupper(keyString[0]);
|
||||
AppendContent(std::string(&c));
|
||||
appendContent(std::string(&c));
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendContent(keyString);
|
||||
appendContent(keyString);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -92,9 +92,9 @@ void TextBox::onPaintEvent(const PaintEvent* event)
|
|||
auto loc = DiscretePoint(mLocation.GetX() + mPadding.mLeft,
|
||||
mLocation.GetY() + mPadding.mTop + unsigned(offset));
|
||||
auto textLayer = VisualLayer::Create();
|
||||
auto textElement = TextElement::Create(line, loc);
|
||||
textElement->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
textLayer->SetText(std::move(textElement));
|
||||
auto textElement = TextNode::Create(line, loc);
|
||||
textElement->setFillColor(mBackgroundColor);
|
||||
textLayer->setText(std::move(textElement));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
offset += 20;
|
||||
}
|
||||
|
|
|
@ -6,26 +6,24 @@
|
|||
|
||||
class TextBox : public Widget
|
||||
{
|
||||
private:
|
||||
|
||||
std::string mContent;
|
||||
bool mCaps;
|
||||
|
||||
public:
|
||||
|
||||
TextBox();
|
||||
|
||||
static std::unique_ptr<TextBox> Create();
|
||||
|
||||
void SetContent(const std::string& text);
|
||||
void setContent(const std::string& text);
|
||||
|
||||
std::string GetContent() const;
|
||||
std::string getContent() const;
|
||||
|
||||
void AppendContent(const std::string& text);
|
||||
void appendContent(const std::string& text);
|
||||
|
||||
void onPaintEvent(const PaintEvent* event) override;
|
||||
|
||||
bool onMyKeyboardEvent(const KeyboardEvent* event) override;
|
||||
|
||||
private:
|
||||
std::string mContent;
|
||||
bool mCaps;
|
||||
};
|
||||
|
||||
using TextBoxUPtr = std::unique_ptr<TextBox>;
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#include "Widget.h"
|
||||
|
||||
#include "RectangleElement.h"
|
||||
#include "RectangleNode.h"
|
||||
#include "MouseEvent.h"
|
||||
#include "KeyboardEvent.h"
|
||||
#include "PaintEvent.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "TextElement.h"
|
||||
#include "TextNode.h"
|
||||
#include "Color.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
|
||||
Widget::Widget()
|
||||
: mLocation(DiscretePoint(0, 0)),
|
||||
|
@ -21,8 +20,8 @@ Widget::Widget()
|
|||
mLayers(),
|
||||
mChildren(),
|
||||
mBorderThickness(0),
|
||||
mBackgroundColor(Color::Create(255, 255, 255)),
|
||||
mBorderColor(Color::Create(0, 0, 0)),
|
||||
mBackgroundColor(Color(255, 255, 255)),
|
||||
mBorderColor(Color(0, 0, 0)),
|
||||
mVisible(true)
|
||||
{
|
||||
|
||||
|
@ -48,7 +47,7 @@ Widget::BoundedSize Widget::getSize() const
|
|||
return mSize;
|
||||
}
|
||||
|
||||
DiscretePoint Widget::getLocation() const
|
||||
const DiscretePoint& Widget::getLocation() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
@ -105,7 +104,7 @@ void Widget::setBounds(unsigned width, unsigned height)
|
|||
mSize.mHeight = height;
|
||||
}
|
||||
|
||||
void Widget::setBackgroundColor(ColorUPtr color)
|
||||
void Widget::setBackgroundColor(const Color& color)
|
||||
{
|
||||
if (mBackgroundColor != color)
|
||||
{
|
||||
|
@ -273,16 +272,10 @@ void Widget::addBackground(const PaintEvent* event)
|
|||
unsigned locY = mLocation.GetY() + mMargin.mTop;
|
||||
unsigned deltaX = mSize.mWidth - mMargin.mLeft - mMargin.mRight;
|
||||
unsigned deltaY = mSize.mHeight - mMargin.mTop - mMargin.mBottom;
|
||||
auto shape = RectangleElement::Create(DiscretePoint(locX, locY), deltaX, deltaY);
|
||||
|
||||
std::cout << "Adding shape at : " << locX << " | " << locY << std::endl;
|
||||
std::cout << "Has dimensions : " << deltaX << " | " << deltaY << std::endl;
|
||||
|
||||
auto color = Color::Create(*mBackgroundColor);
|
||||
|
||||
std::cout << "Has color : " << color->GetR() << " | " << color->GetG() << " | " << color->GetB() << " | " << color->GetAlpha() << std::endl;
|
||||
shape->SetFillColor(std::move(color));
|
||||
auto shape = RectangleNode::Create(DiscretePoint(locX, locY), deltaX, deltaY);
|
||||
shape->setFillColor(mBackgroundColor);
|
||||
auto shapeLayer = VisualLayer::Create();
|
||||
shapeLayer->SetShape(std::move(shape));
|
||||
shapeLayer->setShape(std::move(shape));
|
||||
mMyLayers.push_back(std::move(shapeLayer));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "DiscretePoint.h"
|
||||
#include "Color.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
@ -10,7 +11,6 @@ class KeyboardEvent;
|
|||
class PaintEvent;
|
||||
|
||||
class VisualLayer;
|
||||
class Color;
|
||||
|
||||
class Widget
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ public:
|
|||
|
||||
std::vector<VisualLayer*> getLayers() const;
|
||||
|
||||
DiscretePoint getLocation() const;
|
||||
const DiscretePoint& getLocation() const;
|
||||
|
||||
virtual void onPaintEvent(const PaintEvent* event);
|
||||
|
||||
|
@ -83,7 +83,7 @@ public:
|
|||
|
||||
bool contains(const DiscretePoint& loc) const;
|
||||
|
||||
void setBackgroundColor(std::unique_ptr<Color> color);
|
||||
void setBackgroundColor(const Color& color);
|
||||
|
||||
void setBounds(unsigned width, unsigned height);
|
||||
|
||||
|
@ -123,8 +123,8 @@ protected:
|
|||
std::vector<VisualLayer*> mLayers;
|
||||
std::vector<std::unique_ptr<Widget> > mChildren;
|
||||
unsigned mBorderThickness{0};
|
||||
std::unique_ptr<Color> mBackgroundColor;
|
||||
std::unique_ptr<Color> mBorderColor;
|
||||
Color mBackgroundColor;
|
||||
Color mBorderColor;
|
||||
bool mVisible{false};
|
||||
bool mDirty{true};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue