Move windows to uptr. Add simple text editing.

This commit is contained in:
jmsgrogan 2020-06-20 16:34:10 +01:00
parent 2bcc7b3d83
commit b99708e7d3
55 changed files with 1257 additions and 994 deletions

View file

@ -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;
}