Move windows to uptr. Add simple text editing.
This commit is contained in:
parent
2bcc7b3d83
commit
b99708e7d3
55 changed files with 1257 additions and 994 deletions
|
@ -2,43 +2,42 @@
|
|||
#include <iostream>
|
||||
|
||||
Button::Button()
|
||||
: Widget(),
|
||||
mLabel()
|
||||
: Widget(),
|
||||
mLabel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<Button> Button::Create()
|
||||
std::unique_ptr<Button> Button::Create()
|
||||
{
|
||||
return std::make_shared<Button>();
|
||||
return std::make_unique<Button>();
|
||||
}
|
||||
|
||||
void Button::SetLabel(const std::string& text)
|
||||
{
|
||||
mLabel = text;
|
||||
mLabel = text;
|
||||
}
|
||||
|
||||
void Button::OnMyMouseEvent(MouseEventPtr event)
|
||||
void Button::OnMyMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
if(event->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
std::cout << "Clicked !!" << std::endl;
|
||||
SetBackgroundColor(Color::Create(0, 255, 0));
|
||||
}
|
||||
if(event->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
std::cout << "Clicked !!" << std::endl;
|
||||
SetBackgroundColor(Color::Create(0, 255, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void Button::OnPaintEvent(PaintEventPtr event)
|
||||
void Button::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
AddBackground(event);
|
||||
|
||||
if(!mLabel.empty())
|
||||
{
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
||||
mLocation.GetY() + mHeight/2);
|
||||
auto text = TextElement::Create(mLabel, middle);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
textLayer->SetText(text);
|
||||
mLayers.push_back(textLayer);
|
||||
}
|
||||
mMyLayers.clear();
|
||||
AddBackground(event);
|
||||
if(!mLabel.empty())
|
||||
{
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
||||
mLocation.GetY() + mHeight/2);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
textLayer->SetText(TextElement::Create(mLabel, middle));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
CopyMyLayers();
|
||||
}
|
||||
|
|
|
@ -5,20 +5,20 @@
|
|||
class Button : public Widget
|
||||
{
|
||||
private:
|
||||
std::string mLabel;
|
||||
std::string mLabel;
|
||||
|
||||
public:
|
||||
Button();
|
||||
Button();
|
||||
|
||||
void SetLabel(const std::string& text);
|
||||
static std::unique_ptr<Button> Create();
|
||||
|
||||
static std::shared_ptr<Button> Create();
|
||||
void SetLabel(const std::string& text);
|
||||
|
||||
void OnPaintEvent(PaintEventPtr event);
|
||||
void OnPaintEvent(const PaintEvent* event) override;
|
||||
|
||||
protected:
|
||||
|
||||
void OnMyMouseEvent(MouseEventPtr event);
|
||||
void OnMyMouseEvent(const MouseEvent* event) override;
|
||||
};
|
||||
|
||||
using ButtonPtr = std::shared_ptr<Button>;
|
||||
using ButtonUPtr = std::unique_ptr<Button>;
|
||||
|
|
|
@ -1,33 +1,34 @@
|
|||
#include "HorizontalSpacer.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
HorizontalSpacer::HorizontalSpacer()
|
||||
: Widget()
|
||||
: Widget()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<HorizontalSpacer> HorizontalSpacer::Create()
|
||||
std::unique_ptr<HorizontalSpacer> HorizontalSpacer::Create()
|
||||
{
|
||||
return std::make_shared<HorizontalSpacer>();
|
||||
return std::make_unique<HorizontalSpacer>();
|
||||
}
|
||||
|
||||
void HorizontalSpacer::AddChildLayers(PaintEventPtr event)
|
||||
void HorizontalSpacer::AddChildLayers(const PaintEvent* event)
|
||||
{
|
||||
unsigned delta = mHeight / mChildren.size();
|
||||
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
||||
{
|
||||
auto child = mChildren[idx];
|
||||
child->SetSize(mWidth, delta);
|
||||
child->SetLocation(DiscretePoint(mLocation.GetX(), mLocation.GetY() + delta*idx));
|
||||
child->OnPaintEvent(event);
|
||||
auto layers = child->GetLayers();
|
||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
}
|
||||
mLayers.clear();
|
||||
unsigned delta = mHeight / mChildren.size();
|
||||
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
||||
{
|
||||
auto& child = mChildren[idx];
|
||||
child->SetSize(mWidth, delta);
|
||||
child->SetLocation(DiscretePoint(mLocation.GetX(), mLocation.GetY() + delta*idx));
|
||||
child->OnPaintEvent(event);
|
||||
auto layers = child->GetLayers();
|
||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalSpacer::OnPaintEvent(PaintEventPtr event)
|
||||
void HorizontalSpacer::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
|
||||
AddChildLayers(event);
|
||||
AddChildLayers(event);
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@ class HorizontalSpacer : public Widget
|
|||
{
|
||||
|
||||
public:
|
||||
HorizontalSpacer();
|
||||
HorizontalSpacer();
|
||||
|
||||
static std::shared_ptr<HorizontalSpacer> Create();
|
||||
static std::unique_ptr<HorizontalSpacer> Create();
|
||||
|
||||
void AddChildLayers(PaintEventPtr event) override;
|
||||
void AddChildLayers(const PaintEvent* event) override;
|
||||
|
||||
void OnPaintEvent(PaintEventPtr event) override;
|
||||
void OnPaintEvent(const PaintEvent* event) override;
|
||||
};
|
||||
|
||||
using HorizontalSpacerPtr = std::shared_ptr<HorizontalSpacer>;
|
||||
using HorizontalSpacerUPtr = std::unique_ptr<HorizontalSpacer>;
|
||||
|
|
|
@ -2,34 +2,34 @@
|
|||
#include "TextElement.h"
|
||||
|
||||
Label::Label()
|
||||
: Widget(),
|
||||
mLabel()
|
||||
: Widget(),
|
||||
mLabel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<Label> Label::Create()
|
||||
std::unique_ptr<Label> Label::Create()
|
||||
{
|
||||
return std::make_shared<Label>();
|
||||
return std::make_unique<Label>();
|
||||
}
|
||||
|
||||
void Label::SetLabel(const std::string& text)
|
||||
{
|
||||
mLabel = text;
|
||||
mLabel = text;
|
||||
}
|
||||
|
||||
void Label::OnPaintEvent(PaintEventPtr event)
|
||||
void Label::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mLayers.clear();
|
||||
AddBackground(event);
|
||||
mMyLayers.clear();
|
||||
AddBackground(event);
|
||||
|
||||
if(!mLabel.empty())
|
||||
{
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
||||
mLocation.GetY() + mHeight/2);
|
||||
auto text = TextElement::Create(mLabel, middle);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
textLayer->SetText(text);
|
||||
mLayers.push_back(textLayer);
|
||||
}
|
||||
if(!mLabel.empty())
|
||||
{
|
||||
auto middle = DiscretePoint(mLocation.GetX() + mWidth/2,
|
||||
mLocation.GetY() + mHeight/2);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
textLayer->SetText(TextElement::Create(mLabel, middle));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
CopyMyLayers();
|
||||
}
|
||||
|
|
|
@ -6,17 +6,17 @@ class Label : public Widget
|
|||
{
|
||||
private:
|
||||
|
||||
std::string mLabel;
|
||||
std::string mLabel;
|
||||
|
||||
public:
|
||||
|
||||
Label();
|
||||
Label();
|
||||
|
||||
void SetLabel(const std::string& text);
|
||||
static std::unique_ptr<Label> Create();
|
||||
|
||||
static std::shared_ptr<Label> Create();
|
||||
void SetLabel(const std::string& text);
|
||||
|
||||
void OnPaintEvent(PaintEventPtr event);
|
||||
void OnPaintEvent(const PaintEvent* event) override;
|
||||
};
|
||||
|
||||
using LabelPtr = std::shared_ptr<Label>;
|
||||
using LabelUPtr = std::unique_ptr<Label>;
|
||||
|
|
97
src/ui_elements/widgets/TextBox.cpp
Normal file
97
src/ui_elements/widgets/TextBox.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include "TextBox.h"
|
||||
#include "TextElement.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
TextBox::TextBox()
|
||||
: Widget(),
|
||||
mContent(),
|
||||
mCaps(false)
|
||||
{
|
||||
mBackgroundColor = Color::Create(200, 200, 200);
|
||||
}
|
||||
|
||||
std::unique_ptr<TextBox> TextBox::Create()
|
||||
{
|
||||
return std::make_unique<TextBox>();
|
||||
}
|
||||
|
||||
void TextBox::SetContent(const std::string& text)
|
||||
{
|
||||
mContent = text;
|
||||
}
|
||||
|
||||
std::string TextBox::GetContent() const
|
||||
{
|
||||
return mContent;
|
||||
}
|
||||
|
||||
void TextBox::AppendContent(const std::string& text)
|
||||
{
|
||||
mContent += text;
|
||||
}
|
||||
|
||||
bool TextBox::OnMyKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
if(!event) return false;
|
||||
|
||||
const auto keyString = event->GetKeyString();
|
||||
if (keyString == "KEY_RETURN")
|
||||
{
|
||||
AppendContent("\n");
|
||||
}
|
||||
else if (keyString == "KEY_BACK")
|
||||
{
|
||||
mContent = mContent.substr(0, mContent.size()-1);
|
||||
}
|
||||
else if (keyString == "KEY_SPACE")
|
||||
{
|
||||
AppendContent(" ");
|
||||
}
|
||||
else if (keyString == "KEY_CAPS")
|
||||
{
|
||||
mCaps = !mCaps;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mCaps && !keyString.empty())
|
||||
{
|
||||
const char c = std::toupper(keyString[0]);
|
||||
AppendContent(std::string(&c));
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendContent(keyString);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextBox::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mMyLayers.clear();
|
||||
AddBackground(event);
|
||||
|
||||
double offset = 0;
|
||||
if(!mContent.empty())
|
||||
{
|
||||
std::stringstream stream(mContent);
|
||||
std::string segment;
|
||||
std::vector<std::string> seglist;
|
||||
while(std::getline(stream, segment, '\n'))
|
||||
{
|
||||
seglist.push_back(segment);
|
||||
}
|
||||
for(const auto& line : seglist)
|
||||
{
|
||||
auto loc = DiscretePoint(mLocation.GetX() + mWidth/10,
|
||||
mLocation.GetY() + mHeight/10 + offset);
|
||||
auto textLayer = VisualLayer::Create();
|
||||
textLayer->SetText(TextElement::Create(line, loc));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
offset += 15;
|
||||
}
|
||||
}
|
||||
CopyMyLayers();
|
||||
}
|
29
src/ui_elements/widgets/TextBox.h
Normal file
29
src/ui_elements/widgets/TextBox.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class TextBox : public Widget
|
||||
{
|
||||
private:
|
||||
|
||||
std::string mContent;
|
||||
bool mCaps;
|
||||
|
||||
public:
|
||||
|
||||
TextBox();
|
||||
|
||||
static std::unique_ptr<TextBox> Create();
|
||||
|
||||
void SetContent(const std::string& text);
|
||||
|
||||
std::string GetContent() const;
|
||||
|
||||
void AppendContent(const std::string& text);
|
||||
|
||||
void OnPaintEvent(const PaintEvent* event) override;
|
||||
|
||||
bool OnMyKeyboardEvent(const KeyboardEvent* event) override;
|
||||
};
|
||||
|
||||
using TextBoxUPtr = std::unique_ptr<TextBox>;
|
|
@ -1,13 +1,16 @@
|
|||
#include "RectangleElement.h"
|
||||
#include "Widget.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
Widget::Widget()
|
||||
: mLocation(DiscretePoint(0, 0)),
|
||||
mWidth(100),
|
||||
mHeight(100),
|
||||
mLayers(),
|
||||
mChildren(),
|
||||
mBackgroundColor(Color::Create(200, 0, 0))
|
||||
: mLocation(DiscretePoint(0, 0)),
|
||||
mWidth(100),
|
||||
mHeight(100),
|
||||
mMyLayers(),
|
||||
mLayers(),
|
||||
mChildren(),
|
||||
mBackgroundColor(Color::Create(200, 0, 0))
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -17,118 +20,148 @@ Widget::~Widget()
|
|||
|
||||
}
|
||||
|
||||
void Widget::AddWidget(WidgetPtr widget)
|
||||
std::unique_ptr<Widget> Widget::Create()
|
||||
{
|
||||
mChildren.push_back(widget);
|
||||
return std::make_unique<Widget>();
|
||||
}
|
||||
|
||||
void Widget::SetSize(unsigned width, unsigned height)
|
||||
void Widget::AddWidget(WidgetUPtr widget)
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
mChildren.push_back(std::move(widget));
|
||||
}
|
||||
|
||||
std::shared_ptr<Widget> Widget::Create()
|
||||
unsigned Widget::GetWidth() const
|
||||
{
|
||||
return std::make_shared<Widget>();
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
DiscretePoint Widget::GetLocation()
|
||||
unsigned Widget::GetHeight() const
|
||||
{
|
||||
return mLocation;
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
std::vector<VisualLayerPtr> Widget::GetLayers()
|
||||
DiscretePoint Widget::GetLocation() const
|
||||
{
|
||||
return mLayers;
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
void Widget::AddChildLayers(PaintEventPtr event)
|
||||
std::vector<VisualLayer*> Widget::GetLayers() const
|
||||
{
|
||||
for(std::size_t idx=0; idx<mChildren.size(); idx++)
|
||||
{
|
||||
auto child = mChildren[idx];
|
||||
child->SetSize(mWidth, mHeight);
|
||||
child->SetLocation(mLocation);
|
||||
child->OnPaintEvent(event);
|
||||
auto layers = child->GetLayers();
|
||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
}
|
||||
return mLayers;
|
||||
}
|
||||
|
||||
void Widget::OnPaintEvent(PaintEventPtr event)
|
||||
void Widget::CopyMyLayers()
|
||||
{
|
||||
mLayers.clear();
|
||||
|
||||
AddBackground(event);
|
||||
AddChildLayers(event);
|
||||
mLayers.clear();
|
||||
mLayers.reserve(mMyLayers.size());
|
||||
auto getRaw = [](const VisualLayerUPtr& uptr){return uptr.get();};
|
||||
std::transform(mMyLayers.begin(), mMyLayers.end(), std::back_inserter(mLayers), getRaw);
|
||||
}
|
||||
|
||||
bool Widget::Contains(const DiscretePoint& loc)
|
||||
void Widget::AddChildLayers(const PaintEvent* event)
|
||||
{
|
||||
if(loc.GetX() < mLocation.GetX()) return false;
|
||||
if(loc.GetX() > mLocation.GetX() + mWidth) return false;
|
||||
if(loc.GetY() > mLocation.GetY() + mHeight) return false;
|
||||
if(loc.GetY() < mLocation.GetY()) return false;
|
||||
return true;
|
||||
for(auto& child: mChildren)
|
||||
{
|
||||
child->SetSize(mWidth, mHeight);
|
||||
child->SetLocation(mLocation);
|
||||
child->OnPaintEvent(event);
|
||||
const auto layers = child->GetLayers();
|
||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
}
|
||||
}
|
||||
|
||||
bool Widget::OnMouseEvent(MouseEventPtr event)
|
||||
void Widget::OnPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
bool inChild = false;
|
||||
for(const auto& child : mChildren)
|
||||
{
|
||||
if(child->OnMouseEvent(event))
|
||||
{
|
||||
inChild = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!inChild)
|
||||
{
|
||||
if(Contains(event->GetClientLocation()))
|
||||
{
|
||||
OnMyMouseEvent(event);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
mMyLayers.clear();
|
||||
AddBackground(event);
|
||||
CopyMyLayers();
|
||||
AddChildLayers(event);
|
||||
}
|
||||
|
||||
void Widget::OnMyMouseEvent(MouseEventPtr event)
|
||||
bool Widget::Contains(const DiscretePoint& loc) const
|
||||
{
|
||||
if(loc.GetX() < mLocation.GetX()) return false;
|
||||
if(loc.GetX() > mLocation.GetX() + mWidth) return false;
|
||||
if(loc.GetY() > mLocation.GetY() + mHeight) return false;
|
||||
if(loc.GetY() < mLocation.GetY()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Widget::OnKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
bool inChild = false;
|
||||
for(const auto& child : mChildren)
|
||||
{
|
||||
if(child->OnKeyboardEvent(event))
|
||||
{
|
||||
inChild = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!inChild)
|
||||
{
|
||||
return OnMyKeyboardEvent(event);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Widget::OnMyKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Widget::OnMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
bool inChild = false;
|
||||
for(const auto& child : mChildren)
|
||||
{
|
||||
if(child->OnMouseEvent(event))
|
||||
{
|
||||
inChild = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!inChild)
|
||||
{
|
||||
if(Contains(event->GetClientLocation()))
|
||||
{
|
||||
OnMyMouseEvent(event);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Widget::OnMyMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Widget::AddBackground(PaintEventPtr event)
|
||||
void Widget::AddBackground(const PaintEvent* event)
|
||||
{
|
||||
auto shape = RectangleElement::Create(mLocation, mWidth, mHeight);
|
||||
shape->SetFillColor(mBackgroundColor);
|
||||
auto shapeLayer = VisualLayer::Create();
|
||||
shapeLayer->SetShape(shape);
|
||||
mLayers.push_back(shapeLayer);
|
||||
auto shape = RectangleElement::Create(mLocation, mWidth, mHeight);
|
||||
shape->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
auto shapeLayer = VisualLayer::Create();
|
||||
shapeLayer->SetShape(std::move(shape));
|
||||
mMyLayers.push_back(std::move(shapeLayer));
|
||||
}
|
||||
|
||||
void Widget::SetBackgroundColor(ColorPtr color)
|
||||
void Widget::SetBackgroundColor(ColorUPtr color)
|
||||
{
|
||||
mBackgroundColor = color;
|
||||
mBackgroundColor = std::move(color);
|
||||
}
|
||||
|
||||
void Widget::SetLocation(const DiscretePoint& loc)
|
||||
{
|
||||
mLocation = loc;
|
||||
mLocation = loc;
|
||||
}
|
||||
|
||||
unsigned Widget::GetWidth()
|
||||
void Widget::SetSize(unsigned width, unsigned height)
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned Widget::GetHeight()
|
||||
{
|
||||
return mHeight;
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
|
|
@ -8,55 +8,63 @@
|
|||
#include "PaintEvent.h"
|
||||
#include "Color.h"
|
||||
#include "MouseEvent.h"
|
||||
#include "KeyboardEvent.h"
|
||||
|
||||
class Widget
|
||||
{
|
||||
protected:
|
||||
|
||||
DiscretePoint mLocation;
|
||||
unsigned mWidth;
|
||||
unsigned mHeight;
|
||||
std::vector<VisualLayerPtr> mLayers;
|
||||
std::vector<std::shared_ptr<Widget> > mChildren;
|
||||
ColorPtr mBackgroundColor;
|
||||
DiscretePoint mLocation;
|
||||
unsigned mWidth;
|
||||
unsigned mHeight;
|
||||
std::vector<VisualLayerUPtr> mMyLayers;
|
||||
std::vector<VisualLayer*> mLayers;
|
||||
std::vector<std::unique_ptr<Widget> > mChildren;
|
||||
ColorUPtr mBackgroundColor;
|
||||
|
||||
public:
|
||||
|
||||
Widget();
|
||||
Widget();
|
||||
|
||||
virtual ~Widget();
|
||||
virtual ~Widget();
|
||||
|
||||
void AddWidget(std::shared_ptr<Widget> widget);
|
||||
static std::unique_ptr<Widget> Create();
|
||||
|
||||
void SetBackgroundColor(ColorPtr color);
|
||||
void AddWidget(std::unique_ptr<Widget> widget);
|
||||
|
||||
void SetSize(unsigned mWidth, unsigned mHeight);
|
||||
unsigned GetWidth() const;
|
||||
|
||||
DiscretePoint GetLocation();
|
||||
unsigned GetHeight() const;
|
||||
|
||||
void SetLocation(const DiscretePoint& loc);
|
||||
std::vector<VisualLayer*> GetLayers() const;
|
||||
|
||||
unsigned GetWidth();
|
||||
DiscretePoint GetLocation() const;
|
||||
|
||||
unsigned GetHeight();
|
||||
virtual void OnPaintEvent(const PaintEvent* event);
|
||||
|
||||
std::vector<VisualLayerPtr> GetLayers();
|
||||
virtual bool OnMouseEvent(const MouseEvent* event);
|
||||
|
||||
static std::shared_ptr<Widget> Create();
|
||||
virtual bool OnKeyboardEvent(const KeyboardEvent* event);
|
||||
|
||||
virtual void OnPaintEvent(PaintEventPtr event);
|
||||
bool Contains(const DiscretePoint& loc) const;
|
||||
|
||||
virtual bool OnMouseEvent(MouseEventPtr event);
|
||||
void SetBackgroundColor(ColorUPtr color);
|
||||
|
||||
bool Contains(const DiscretePoint& loc);
|
||||
void SetSize(unsigned mWidth, unsigned mHeight);
|
||||
|
||||
void SetLocation(const DiscretePoint& loc);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void OnMyMouseEvent(MouseEventPtr event);
|
||||
virtual bool OnMyKeyboardEvent(const KeyboardEvent* event);
|
||||
|
||||
virtual void AddChildLayers(PaintEventPtr event);
|
||||
virtual void OnMyMouseEvent(const MouseEvent* event);
|
||||
|
||||
virtual void AddBackground(PaintEventPtr event);
|
||||
virtual void AddChildLayers(const PaintEvent* event);
|
||||
|
||||
virtual void AddBackground(const PaintEvent* event);
|
||||
|
||||
void CopyMyLayers();
|
||||
};
|
||||
|
||||
using WidgetPtr = std::shared_ptr<Widget>;
|
||||
using WidgetUPtr = std::unique_ptr<Widget>;
|
||||
|
|
|
@ -1,36 +1,39 @@
|
|||
#include "GeometryElement.h"
|
||||
|
||||
GeometryElement::GeometryElement()
|
||||
: mFillColor(Color::Create(255, 255, 255)),
|
||||
mStrokeColor(Color::Create(0, 0, 0)),
|
||||
mStrokeThickness(1),
|
||||
mType(Type::Path)
|
||||
: mFillColor(Color::Create(255, 255, 255)),
|
||||
mStrokeColor(Color::Create(0, 0, 0)),
|
||||
mStrokeThickness(1),
|
||||
mType(Type::Path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ColorPtr GeometryElement::GetFillColor()
|
||||
Color* GeometryElement::GetFillColor() const
|
||||
{
|
||||
return mFillColor;
|
||||
return mFillColor.get();
|
||||
}
|
||||
ColorPtr GeometryElement::GetStrokeColor()
|
||||
Color* GeometryElement::GetStrokeColor() const
|
||||
{
|
||||
return mStrokeColor;
|
||||
}
|
||||
unsigned GeometryElement::GetStrokeThickness()
|
||||
{
|
||||
return mStrokeThickness;
|
||||
return mStrokeColor.get();
|
||||
}
|
||||
|
||||
void GeometryElement::SetFillColor(ColorPtr color)
|
||||
unsigned GeometryElement::GetStrokeThickness() const
|
||||
{
|
||||
mFillColor = color;
|
||||
return mStrokeThickness;
|
||||
}
|
||||
void GeometryElement::SetStrokeColor(ColorPtr color)
|
||||
|
||||
void GeometryElement::SetFillColor(ColorUPtr color)
|
||||
{
|
||||
mStrokeColor = color;
|
||||
mFillColor = std::move(color);
|
||||
}
|
||||
|
||||
void GeometryElement::SetStrokeColor(ColorUPtr color)
|
||||
{
|
||||
mStrokeColor = std::move(color);
|
||||
}
|
||||
|
||||
void GeometryElement::SetStrokeThickness(unsigned thickness)
|
||||
{
|
||||
mStrokeThickness = thickness;
|
||||
mStrokeThickness = thickness;
|
||||
}
|
||||
|
|
|
@ -5,35 +5,33 @@
|
|||
class GeometryElement
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Type
|
||||
{
|
||||
Path,
|
||||
Rectangle,
|
||||
Circle,
|
||||
Arc
|
||||
};
|
||||
enum class Type
|
||||
{
|
||||
Path,
|
||||
Rectangle,
|
||||
Circle,
|
||||
Arc
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
ColorPtr mFillColor;
|
||||
ColorPtr mStrokeColor;
|
||||
unsigned mStrokeThickness;
|
||||
Type mType;
|
||||
ColorUPtr mFillColor;
|
||||
ColorUPtr mStrokeColor;
|
||||
unsigned mStrokeThickness;
|
||||
Type mType;
|
||||
|
||||
public:
|
||||
|
||||
GeometryElement();
|
||||
virtual ~GeometryElement() = default;
|
||||
GeometryElement();
|
||||
virtual ~GeometryElement() = default;
|
||||
|
||||
ColorPtr GetFillColor();
|
||||
ColorPtr GetStrokeColor();
|
||||
unsigned GetStrokeThickness();
|
||||
virtual Type GetType() = 0;
|
||||
Color* GetFillColor() const;
|
||||
Color* GetStrokeColor() const;
|
||||
unsigned GetStrokeThickness() const;
|
||||
virtual Type GetType() = 0;
|
||||
|
||||
void SetFillColor(ColorPtr color);
|
||||
void SetStrokeColor(ColorPtr color);
|
||||
void SetStrokeThickness(unsigned thickness);
|
||||
void SetFillColor(ColorUPtr color);
|
||||
void SetStrokeColor(ColorUPtr color);
|
||||
void SetStrokeThickness(unsigned thickness);
|
||||
};
|
||||
|
||||
using GeometryElementPtr = std::shared_ptr<GeometryElement>;
|
||||
using GeometryElementUPtr = std::unique_ptr<GeometryElement>;
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
#include "RectangleElement.h"
|
||||
|
||||
RectangleElement::RectangleElement(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height)
|
||||
: mLocation(loc),
|
||||
mWidth(width),
|
||||
mHeight(height)
|
||||
unsigned width, unsigned height)
|
||||
: mLocation(loc),
|
||||
mWidth(width),
|
||||
mHeight(height)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<RectangleElement> RectangleElement::Create(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height)
|
||||
std::unique_ptr<RectangleElement> RectangleElement::Create(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height)
|
||||
{
|
||||
return std::make_shared<RectangleElement>(loc, width, height);
|
||||
return std::make_unique<RectangleElement>(loc, width, height);
|
||||
}
|
||||
|
||||
GeometryElement::Type RectangleElement::GetType()
|
||||
{
|
||||
return GeometryElement::Type::Rectangle;
|
||||
return GeometryElement::Type::Rectangle;
|
||||
}
|
||||
|
||||
DiscretePoint RectangleElement::GetLocation()
|
||||
DiscretePoint RectangleElement::GetLocation() const
|
||||
{
|
||||
return mLocation;
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
unsigned RectangleElement::GetWidth()
|
||||
unsigned RectangleElement::GetWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned RectangleElement::GetHeight()
|
||||
unsigned RectangleElement::GetHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
return mHeight;
|
||||
}
|
||||
|
|
|
@ -7,23 +7,22 @@
|
|||
|
||||
class RectangleElement : public GeometryElement
|
||||
{
|
||||
DiscretePoint mLocation;
|
||||
unsigned mWidth;
|
||||
unsigned mHeight;
|
||||
DiscretePoint mLocation;
|
||||
unsigned mWidth;
|
||||
unsigned mHeight;
|
||||
|
||||
public:
|
||||
|
||||
RectangleElement(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height);
|
||||
static std::shared_ptr<RectangleElement> Create(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height);
|
||||
GeometryElement::Type GetType() override;
|
||||
RectangleElement(const DiscretePoint& loc, unsigned width, unsigned height);
|
||||
static std::unique_ptr<RectangleElement> Create(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height);
|
||||
GeometryElement::Type GetType() override;
|
||||
|
||||
DiscretePoint GetLocation();
|
||||
unsigned GetWidth();
|
||||
unsigned GetHeight();
|
||||
DiscretePoint GetLocation() const;
|
||||
unsigned GetWidth() const;
|
||||
unsigned GetHeight() const;
|
||||
};
|
||||
|
||||
using RectangleElementPtr = std::shared_ptr<RectangleElement>;
|
||||
using RectangleElementUPtr = std::unique_ptr<RectangleElement>;
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#include "TextElement.h"
|
||||
|
||||
TextElement::TextElement(const std::string& content, const DiscretePoint& loc)
|
||||
: mContent(content),
|
||||
mLocation(loc),
|
||||
mFontLabel("fixed")
|
||||
: mContent(content),
|
||||
mLocation(loc),
|
||||
mFontLabel("fixed")
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -13,27 +13,27 @@ TextElement::~TextElement()
|
|||
|
||||
}
|
||||
|
||||
std::shared_ptr<TextElement> TextElement::Create(const std::string& content, const DiscretePoint& loc)
|
||||
std::unique_ptr<TextElement> TextElement::Create(const std::string& content, const DiscretePoint& loc)
|
||||
{
|
||||
return std::make_shared<TextElement>(content, loc);
|
||||
return std::make_unique<TextElement>(content, loc);
|
||||
}
|
||||
|
||||
DiscretePoint TextElement::GetLocation()
|
||||
DiscretePoint TextElement::GetLocation() const
|
||||
{
|
||||
return mLocation;
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
std::string TextElement::GetFontLabel() const
|
||||
{
|
||||
return mFontLabel;
|
||||
}
|
||||
|
||||
std::string TextElement::GetContent() const
|
||||
{
|
||||
return mContent;
|
||||
}
|
||||
|
||||
void TextElement::SetContent(const std::string& content)
|
||||
{
|
||||
mContent = content;
|
||||
}
|
||||
|
||||
std::string TextElement::GetFontLabel()
|
||||
{
|
||||
return mFontLabel;
|
||||
}
|
||||
|
||||
std::string TextElement::GetContent()
|
||||
{
|
||||
return mContent;
|
||||
mContent = content;
|
||||
}
|
||||
|
|
|
@ -7,25 +7,25 @@
|
|||
|
||||
class TextElement
|
||||
{
|
||||
std::string mContent;
|
||||
DiscretePoint mLocation;
|
||||
std::string mFontLabel;
|
||||
std::string mContent;
|
||||
DiscretePoint mLocation;
|
||||
std::string mFontLabel;
|
||||
|
||||
public:
|
||||
|
||||
TextElement(const std::string& content, const DiscretePoint& loc);
|
||||
TextElement(const std::string& content, const DiscretePoint& loc);
|
||||
|
||||
~TextElement();
|
||||
~TextElement();
|
||||
|
||||
static std::shared_ptr<TextElement> Create(const std::string& content, const DiscretePoint& loc);
|
||||
static std::unique_ptr<TextElement> Create(const std::string& content, const DiscretePoint& loc);
|
||||
|
||||
DiscretePoint GetLocation();
|
||||
DiscretePoint GetLocation() const;
|
||||
|
||||
std::string GetContent();
|
||||
std::string GetContent() const;
|
||||
|
||||
void SetContent(const std::string& content);
|
||||
std::string GetFontLabel() const;
|
||||
|
||||
std::string GetFontLabel();
|
||||
void SetContent(const std::string& content);
|
||||
};
|
||||
|
||||
using TextElementPtr = std::shared_ptr<TextElement>;
|
||||
using TextElementUPtr = std::unique_ptr<TextElement>;
|
||||
|
|
|
@ -1,38 +1,43 @@
|
|||
#include "VisualLayer.h"
|
||||
|
||||
VisualLayer::VisualLayer()
|
||||
: mShape(),
|
||||
mText()
|
||||
: mShape(),
|
||||
mText()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<VisualLayer> VisualLayer::Create()
|
||||
std::unique_ptr<VisualLayer> VisualLayer::Create()
|
||||
{
|
||||
return std::make_shared<VisualLayer>();
|
||||
return std::make_unique<VisualLayer>();
|
||||
}
|
||||
|
||||
void VisualLayer::SetShape(GeometryElementPtr shape)
|
||||
bool VisualLayer::HasShape() const
|
||||
{
|
||||
mShape = shape;
|
||||
return bool(mShape);
|
||||
}
|
||||
void VisualLayer::SetText(TextElementPtr text)
|
||||
|
||||
bool VisualLayer::HasText() const
|
||||
{
|
||||
mText = text;
|
||||
return bool(mText);
|
||||
}
|
||||
bool VisualLayer::HasShape()
|
||||
|
||||
GeometryElement* VisualLayer::GetShape() const
|
||||
{
|
||||
return bool(mShape);
|
||||
return mShape.get();
|
||||
}
|
||||
bool VisualLayer::HasText()
|
||||
|
||||
TextElement* VisualLayer::GetText() const
|
||||
{
|
||||
return bool(mText);
|
||||
return mText.get();
|
||||
}
|
||||
GeometryElementPtr VisualLayer::GetShape()
|
||||
|
||||
void VisualLayer::SetShape(GeometryElementUPtr shape)
|
||||
{
|
||||
return mShape;
|
||||
mShape = std::move(shape);
|
||||
}
|
||||
TextElementPtr VisualLayer::GetText()
|
||||
|
||||
void VisualLayer::SetText(TextElementUPtr text)
|
||||
{
|
||||
return mText;
|
||||
mText = std::move(text);
|
||||
}
|
||||
|
|
|
@ -6,21 +6,20 @@
|
|||
|
||||
class VisualLayer
|
||||
{
|
||||
GeometryElementPtr mShape;
|
||||
TextElementPtr mText;
|
||||
GeometryElementUPtr mShape;
|
||||
TextElementUPtr mText;
|
||||
|
||||
public:
|
||||
|
||||
VisualLayer();
|
||||
VisualLayer();
|
||||
|
||||
static std::shared_ptr<VisualLayer> Create();
|
||||
|
||||
void SetShape(GeometryElementPtr shape);
|
||||
void SetText(TextElementPtr text);
|
||||
bool HasShape();
|
||||
bool HasText();
|
||||
GeometryElementPtr GetShape();
|
||||
TextElementPtr GetText();
|
||||
static std::unique_ptr<VisualLayer> Create();
|
||||
|
||||
GeometryElement* GetShape() const;
|
||||
TextElement* GetText() const;
|
||||
bool HasShape() const;
|
||||
bool HasText() const;
|
||||
void SetShape(GeometryElementUPtr shape);
|
||||
void SetText(TextElementUPtr text);
|
||||
};
|
||||
using VisualLayerPtr = std::shared_ptr<VisualLayer>;
|
||||
using VisualLayerUPtr = std::unique_ptr<VisualLayer>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue