Initial commit.
This commit is contained in:
commit
59c6161fdb
134 changed files with 4751 additions and 0 deletions
44
src/ui_elements/widgets/Button.cpp
Normal file
44
src/ui_elements/widgets/Button.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#include "Button.h"
|
||||
#include <iostream>
|
||||
|
||||
Button::Button()
|
||||
: Widget(),
|
||||
mLabel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<Button> Button::Create()
|
||||
{
|
||||
return std::make_shared<Button>();
|
||||
}
|
||||
|
||||
void Button::SetLabel(const std::string& text)
|
||||
{
|
||||
mLabel = text;
|
||||
}
|
||||
|
||||
void Button::OnMyMouseEvent(MouseEventPtr event)
|
||||
{
|
||||
if(event->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
std::cout << "Clicked !!" << std::endl;
|
||||
SetBackgroundColor(Color::Create(0, 255, 0));
|
||||
}
|
||||
}
|
||||
|
||||
void Button::OnPaintEvent(PaintEventPtr 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);
|
||||
}
|
||||
}
|
24
src/ui_elements/widgets/Button.h
Normal file
24
src/ui_elements/widgets/Button.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class Button : public Widget
|
||||
{
|
||||
private:
|
||||
std::string mLabel;
|
||||
|
||||
public:
|
||||
Button();
|
||||
|
||||
void SetLabel(const std::string& text);
|
||||
|
||||
static std::shared_ptr<Button> Create();
|
||||
|
||||
void OnPaintEvent(PaintEventPtr event);
|
||||
|
||||
protected:
|
||||
|
||||
void OnMyMouseEvent(MouseEventPtr event);
|
||||
};
|
||||
|
||||
using ButtonPtr = std::shared_ptr<Button>;
|
33
src/ui_elements/widgets/HorizontalSpacer.cpp
Normal file
33
src/ui_elements/widgets/HorizontalSpacer.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include "HorizontalSpacer.h"
|
||||
|
||||
HorizontalSpacer::HorizontalSpacer()
|
||||
: Widget()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<HorizontalSpacer> HorizontalSpacer::Create()
|
||||
{
|
||||
return std::make_shared<HorizontalSpacer>();
|
||||
}
|
||||
|
||||
void HorizontalSpacer::AddChildLayers(PaintEventPtr 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());
|
||||
}
|
||||
}
|
||||
|
||||
void HorizontalSpacer::OnPaintEvent(PaintEventPtr event)
|
||||
{
|
||||
mLayers.clear();
|
||||
|
||||
AddChildLayers(event);
|
||||
}
|
18
src/ui_elements/widgets/HorizontalSpacer.h
Normal file
18
src/ui_elements/widgets/HorizontalSpacer.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class HorizontalSpacer : public Widget
|
||||
{
|
||||
|
||||
public:
|
||||
HorizontalSpacer();
|
||||
|
||||
static std::shared_ptr<HorizontalSpacer> Create();
|
||||
|
||||
void AddChildLayers(PaintEventPtr event) override;
|
||||
|
||||
void OnPaintEvent(PaintEventPtr event) override;
|
||||
};
|
||||
|
||||
using HorizontalSpacerPtr = std::shared_ptr<HorizontalSpacer>;
|
35
src/ui_elements/widgets/Label.cpp
Normal file
35
src/ui_elements/widgets/Label.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "Label.h"
|
||||
#include "TextElement.h"
|
||||
|
||||
Label::Label()
|
||||
: Widget(),
|
||||
mLabel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<Label> Label::Create()
|
||||
{
|
||||
return std::make_shared<Label>();
|
||||
}
|
||||
|
||||
void Label::SetLabel(const std::string& text)
|
||||
{
|
||||
mLabel = text;
|
||||
}
|
||||
|
||||
void Label::OnPaintEvent(PaintEventPtr 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);
|
||||
}
|
||||
}
|
22
src/ui_elements/widgets/Label.h
Normal file
22
src/ui_elements/widgets/Label.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "Widget.h"
|
||||
|
||||
class Label : public Widget
|
||||
{
|
||||
private:
|
||||
|
||||
std::string mLabel;
|
||||
|
||||
public:
|
||||
|
||||
Label();
|
||||
|
||||
void SetLabel(const std::string& text);
|
||||
|
||||
static std::shared_ptr<Label> Create();
|
||||
|
||||
void OnPaintEvent(PaintEventPtr event);
|
||||
};
|
||||
|
||||
using LabelPtr = std::shared_ptr<Label>;
|
134
src/ui_elements/widgets/Widget.cpp
Normal file
134
src/ui_elements/widgets/Widget.cpp
Normal file
|
@ -0,0 +1,134 @@
|
|||
#include "RectangleElement.h"
|
||||
#include "Widget.h"
|
||||
|
||||
Widget::Widget()
|
||||
: mLocation(DiscretePoint(0, 0)),
|
||||
mWidth(100),
|
||||
mHeight(100),
|
||||
mLayers(),
|
||||
mChildren(),
|
||||
mBackgroundColor(Color::Create(200, 0, 0))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Widget::~Widget()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Widget::AddWidget(WidgetPtr widget)
|
||||
{
|
||||
mChildren.push_back(widget);
|
||||
}
|
||||
|
||||
void Widget::SetSize(unsigned width, unsigned height)
|
||||
{
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
std::shared_ptr<Widget> Widget::Create()
|
||||
{
|
||||
return std::make_shared<Widget>();
|
||||
}
|
||||
|
||||
DiscretePoint Widget::GetLocation()
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
std::vector<VisualLayerPtr> Widget::GetLayers()
|
||||
{
|
||||
return mLayers;
|
||||
}
|
||||
|
||||
void Widget::AddChildLayers(PaintEventPtr event)
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::OnPaintEvent(PaintEventPtr event)
|
||||
{
|
||||
mLayers.clear();
|
||||
|
||||
AddBackground(event);
|
||||
AddChildLayers(event);
|
||||
}
|
||||
|
||||
bool Widget::Contains(const DiscretePoint& loc)
|
||||
{
|
||||
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::OnMouseEvent(MouseEventPtr 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(MouseEventPtr event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Widget::AddBackground(PaintEventPtr event)
|
||||
{
|
||||
auto shape = RectangleElement::Create(mLocation, mWidth, mHeight);
|
||||
shape->SetFillColor(mBackgroundColor);
|
||||
auto shapeLayer = VisualLayer::Create();
|
||||
shapeLayer->SetShape(shape);
|
||||
mLayers.push_back(shapeLayer);
|
||||
}
|
||||
|
||||
void Widget::SetBackgroundColor(ColorPtr color)
|
||||
{
|
||||
mBackgroundColor = color;
|
||||
}
|
||||
|
||||
void Widget::SetLocation(const DiscretePoint& loc)
|
||||
{
|
||||
mLocation = loc;
|
||||
}
|
||||
|
||||
unsigned Widget::GetWidth()
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned Widget::GetHeight()
|
||||
{
|
||||
return mHeight;
|
||||
}
|
62
src/ui_elements/widgets/Widget.h
Normal file
62
src/ui_elements/widgets/Widget.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "DiscretePoint.h"
|
||||
#include "VisualLayer.h"
|
||||
#include "PaintEvent.h"
|
||||
#include "Color.h"
|
||||
#include "MouseEvent.h"
|
||||
|
||||
class Widget
|
||||
{
|
||||
protected:
|
||||
|
||||
DiscretePoint mLocation;
|
||||
unsigned mWidth;
|
||||
unsigned mHeight;
|
||||
std::vector<VisualLayerPtr> mLayers;
|
||||
std::vector<std::shared_ptr<Widget> > mChildren;
|
||||
ColorPtr mBackgroundColor;
|
||||
|
||||
public:
|
||||
|
||||
Widget();
|
||||
|
||||
virtual ~Widget();
|
||||
|
||||
void AddWidget(std::shared_ptr<Widget> widget);
|
||||
|
||||
void SetBackgroundColor(ColorPtr color);
|
||||
|
||||
void SetSize(unsigned mWidth, unsigned mHeight);
|
||||
|
||||
DiscretePoint GetLocation();
|
||||
|
||||
void SetLocation(const DiscretePoint& loc);
|
||||
|
||||
unsigned GetWidth();
|
||||
|
||||
unsigned GetHeight();
|
||||
|
||||
std::vector<VisualLayerPtr> GetLayers();
|
||||
|
||||
static std::shared_ptr<Widget> Create();
|
||||
|
||||
virtual void OnPaintEvent(PaintEventPtr event);
|
||||
|
||||
virtual bool OnMouseEvent(MouseEventPtr event);
|
||||
|
||||
bool Contains(const DiscretePoint& loc);
|
||||
|
||||
protected:
|
||||
|
||||
virtual void OnMyMouseEvent(MouseEventPtr event);
|
||||
|
||||
virtual void AddChildLayers(PaintEventPtr event);
|
||||
|
||||
virtual void AddBackground(PaintEventPtr event);
|
||||
};
|
||||
|
||||
using WidgetPtr = std::shared_ptr<Widget>;
|
36
src/ui_elements/widgets/elements/GeometryElement.cpp
Normal file
36
src/ui_elements/widgets/elements/GeometryElement.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "GeometryElement.h"
|
||||
|
||||
GeometryElement::GeometryElement()
|
||||
: mFillColor(Color::Create(255, 255, 255)),
|
||||
mStrokeColor(Color::Create(0, 0, 0)),
|
||||
mStrokeThickness(1),
|
||||
mType(Type::Path)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ColorPtr GeometryElement::GetFillColor()
|
||||
{
|
||||
return mFillColor;
|
||||
}
|
||||
ColorPtr GeometryElement::GetStrokeColor()
|
||||
{
|
||||
return mStrokeColor;
|
||||
}
|
||||
unsigned GeometryElement::GetStrokeThickness()
|
||||
{
|
||||
return mStrokeThickness;
|
||||
}
|
||||
|
||||
void GeometryElement::SetFillColor(ColorPtr color)
|
||||
{
|
||||
mFillColor = color;
|
||||
}
|
||||
void GeometryElement::SetStrokeColor(ColorPtr color)
|
||||
{
|
||||
mStrokeColor = color;
|
||||
}
|
||||
void GeometryElement::SetStrokeThickness(unsigned thickness)
|
||||
{
|
||||
mStrokeThickness = thickness;
|
||||
}
|
39
src/ui_elements/widgets/elements/GeometryElement.h
Normal file
39
src/ui_elements/widgets/elements/GeometryElement.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include "Color.h"
|
||||
|
||||
class GeometryElement
|
||||
{
|
||||
public:
|
||||
|
||||
enum class Type
|
||||
{
|
||||
Path,
|
||||
Rectangle,
|
||||
Circle,
|
||||
Arc
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
ColorPtr mFillColor;
|
||||
ColorPtr mStrokeColor;
|
||||
unsigned mStrokeThickness;
|
||||
Type mType;
|
||||
|
||||
public:
|
||||
|
||||
GeometryElement();
|
||||
virtual ~GeometryElement() = default;
|
||||
|
||||
ColorPtr GetFillColor();
|
||||
ColorPtr GetStrokeColor();
|
||||
unsigned GetStrokeThickness();
|
||||
virtual Type GetType() = 0;
|
||||
|
||||
void SetFillColor(ColorPtr color);
|
||||
void SetStrokeColor(ColorPtr color);
|
||||
void SetStrokeThickness(unsigned thickness);
|
||||
};
|
||||
|
||||
using GeometryElementPtr = std::shared_ptr<GeometryElement>;
|
36
src/ui_elements/widgets/elements/RectangleElement.cpp
Normal file
36
src/ui_elements/widgets/elements/RectangleElement.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "RectangleElement.h"
|
||||
|
||||
RectangleElement::RectangleElement(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height)
|
||||
: mLocation(loc),
|
||||
mWidth(width),
|
||||
mHeight(height)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<RectangleElement> RectangleElement::Create(const DiscretePoint& loc,
|
||||
unsigned width, unsigned height)
|
||||
{
|
||||
return std::make_shared<RectangleElement>(loc, width, height);
|
||||
}
|
||||
|
||||
GeometryElement::Type RectangleElement::GetType()
|
||||
{
|
||||
return GeometryElement::Type::Rectangle;
|
||||
}
|
||||
|
||||
DiscretePoint RectangleElement::GetLocation()
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
unsigned RectangleElement::GetWidth()
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
unsigned RectangleElement::GetHeight()
|
||||
{
|
||||
return mHeight;
|
||||
}
|
29
src/ui_elements/widgets/elements/RectangleElement.h
Normal file
29
src/ui_elements/widgets/elements/RectangleElement.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "GeometryElement.h"
|
||||
#include "DiscretePoint.h"
|
||||
|
||||
class RectangleElement : public GeometryElement
|
||||
{
|
||||
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;
|
||||
|
||||
DiscretePoint GetLocation();
|
||||
unsigned GetWidth();
|
||||
unsigned GetHeight();
|
||||
};
|
||||
|
||||
using RectangleElementPtr = std::shared_ptr<RectangleElement>;
|
||||
|
||||
|
39
src/ui_elements/widgets/elements/TextElement.cpp
Normal file
39
src/ui_elements/widgets/elements/TextElement.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include "TextElement.h"
|
||||
|
||||
TextElement::TextElement(const std::string& content, const DiscretePoint& loc)
|
||||
: mContent(content),
|
||||
mLocation(loc),
|
||||
mFontLabel("fixed")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TextElement::~TextElement()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<TextElement> TextElement::Create(const std::string& content, const DiscretePoint& loc)
|
||||
{
|
||||
return std::make_shared<TextElement>(content, loc);
|
||||
}
|
||||
|
||||
DiscretePoint TextElement::GetLocation()
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
void TextElement::SetContent(const std::string& content)
|
||||
{
|
||||
mContent = content;
|
||||
}
|
||||
|
||||
std::string TextElement::GetFontLabel()
|
||||
{
|
||||
return mFontLabel;
|
||||
}
|
||||
|
||||
std::string TextElement::GetContent()
|
||||
{
|
||||
return mContent;
|
||||
}
|
31
src/ui_elements/widgets/elements/TextElement.h
Normal file
31
src/ui_elements/widgets/elements/TextElement.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "DiscretePoint.h"
|
||||
|
||||
class TextElement
|
||||
{
|
||||
std::string mContent;
|
||||
DiscretePoint mLocation;
|
||||
std::string mFontLabel;
|
||||
|
||||
public:
|
||||
|
||||
TextElement(const std::string& content, const DiscretePoint& loc);
|
||||
|
||||
~TextElement();
|
||||
|
||||
static std::shared_ptr<TextElement> Create(const std::string& content, const DiscretePoint& loc);
|
||||
|
||||
DiscretePoint GetLocation();
|
||||
|
||||
std::string GetContent();
|
||||
|
||||
void SetContent(const std::string& content);
|
||||
|
||||
std::string GetFontLabel();
|
||||
};
|
||||
|
||||
using TextElementPtr = std::shared_ptr<TextElement>;
|
38
src/ui_elements/widgets/elements/VisualLayer.cpp
Normal file
38
src/ui_elements/widgets/elements/VisualLayer.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#include "VisualLayer.h"
|
||||
|
||||
VisualLayer::VisualLayer()
|
||||
: mShape(),
|
||||
mText()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<VisualLayer> VisualLayer::Create()
|
||||
{
|
||||
return std::make_shared<VisualLayer>();
|
||||
}
|
||||
|
||||
void VisualLayer::SetShape(GeometryElementPtr shape)
|
||||
{
|
||||
mShape = shape;
|
||||
}
|
||||
void VisualLayer::SetText(TextElementPtr text)
|
||||
{
|
||||
mText = text;
|
||||
}
|
||||
bool VisualLayer::HasShape()
|
||||
{
|
||||
return bool(mShape);
|
||||
}
|
||||
bool VisualLayer::HasText()
|
||||
{
|
||||
return bool(mText);
|
||||
}
|
||||
GeometryElementPtr VisualLayer::GetShape()
|
||||
{
|
||||
return mShape;
|
||||
}
|
||||
TextElementPtr VisualLayer::GetText()
|
||||
{
|
||||
return mText;
|
||||
}
|
26
src/ui_elements/widgets/elements/VisualLayer.h
Normal file
26
src/ui_elements/widgets/elements/VisualLayer.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
#include "GeometryElement.h"
|
||||
#include "TextElement.h"
|
||||
|
||||
class VisualLayer
|
||||
{
|
||||
GeometryElementPtr mShape;
|
||||
TextElementPtr mText;
|
||||
|
||||
public:
|
||||
|
||||
VisualLayer();
|
||||
|
||||
static std::shared_ptr<VisualLayer> Create();
|
||||
|
||||
void SetShape(GeometryElementPtr shape);
|
||||
void SetText(TextElementPtr text);
|
||||
bool HasShape();
|
||||
bool HasText();
|
||||
GeometryElementPtr GetShape();
|
||||
TextElementPtr GetText();
|
||||
|
||||
};
|
||||
using VisualLayerPtr = std::shared_ptr<VisualLayer>;
|
Loading…
Add table
Add a link
Reference in a new issue