More window cleaning
This commit is contained in:
parent
6adc441e6f
commit
53c98a227d
29 changed files with 422 additions and 261 deletions
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
|
||||
Widget::Widget()
|
||||
: mLocation(DiscretePoint(0, 0)),
|
||||
|
@ -37,52 +38,102 @@ std::unique_ptr<Widget> Widget::Create()
|
|||
return std::make_unique<Widget>();
|
||||
}
|
||||
|
||||
void Widget::AddWidget(WidgetUPtr widget)
|
||||
void Widget::addWidget(WidgetUPtr widget)
|
||||
{
|
||||
mChildren.push_back(std::move(widget));
|
||||
}
|
||||
|
||||
Widget::BoundedSize Widget::GetSize() const
|
||||
Widget::BoundedSize Widget::getSize() const
|
||||
{
|
||||
return mSize;
|
||||
}
|
||||
|
||||
DiscretePoint Widget::GetLocation() const
|
||||
DiscretePoint Widget::getLocation() const
|
||||
{
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
std::vector<VisualLayer*> Widget::GetLayers() const
|
||||
std::vector<VisualLayer*> Widget::getLayers() const
|
||||
{
|
||||
return mLayers;
|
||||
}
|
||||
|
||||
void Widget::SetSize(const BoundedSize& size)
|
||||
void Widget::setSize(const BoundedSize& size)
|
||||
{
|
||||
mSize = size;
|
||||
if (size != mSize)
|
||||
{
|
||||
mSize = size;
|
||||
mDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::SetMargin(unsigned margin)
|
||||
void Widget::setMargin(unsigned margin)
|
||||
{
|
||||
mMargin = {margin, margin, margin, margin};
|
||||
setMargin({margin, margin, margin, margin});
|
||||
}
|
||||
|
||||
void Widget::SetMargin(const BoundaryOffset& margin)
|
||||
void Widget::setMargin(const BoundaryOffset& margin)
|
||||
{
|
||||
mMargin = margin;
|
||||
if (margin != mMargin)
|
||||
{
|
||||
mMargin = margin;
|
||||
mDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::SetPadding(unsigned padding)
|
||||
void Widget::setPadding(unsigned padding)
|
||||
{
|
||||
mPadding = {padding, padding, padding, padding};
|
||||
setPadding({padding, padding, padding, padding});
|
||||
}
|
||||
|
||||
void Widget::SetPadding(const BoundaryOffset& padding)
|
||||
void Widget::setPadding(const BoundaryOffset& padding)
|
||||
{
|
||||
mPadding = padding;
|
||||
if (padding != mPadding)
|
||||
{
|
||||
mPadding = padding;
|
||||
mDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::CopyMyLayers()
|
||||
void Widget::setBounds(unsigned width, unsigned height)
|
||||
{
|
||||
if (width != mSize.mWidth || height != mSize.mHeight)
|
||||
{
|
||||
mDirty = true;
|
||||
}
|
||||
mSize.mWidth = width;
|
||||
mSize.mHeight = height;
|
||||
}
|
||||
|
||||
void Widget::setBackgroundColor(ColorUPtr color)
|
||||
{
|
||||
if (mBackgroundColor != color)
|
||||
{
|
||||
mBackgroundColor = std::move(color);
|
||||
mDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::setLocation(const DiscretePoint& loc)
|
||||
{
|
||||
if (mLocation != loc)
|
||||
{
|
||||
mLocation = loc;
|
||||
mDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::setVisible(bool visible)
|
||||
{
|
||||
if (mVisible != visible)
|
||||
{
|
||||
mDirty = true;
|
||||
}
|
||||
mVisible = visible;
|
||||
|
||||
}
|
||||
|
||||
void Widget::addMyLayers()
|
||||
{
|
||||
mLayers.clear();
|
||||
mLayers.reserve(mMyLayers.size());
|
||||
|
@ -90,73 +141,107 @@ void Widget::CopyMyLayers()
|
|||
std::transform(mMyLayers.begin(), mMyLayers.end(), std::back_inserter(mLayers), getRaw);
|
||||
}
|
||||
|
||||
void Widget::SetBounds(unsigned width, unsigned height)
|
||||
{
|
||||
mSize.mWidth = width;
|
||||
mSize.mHeight = height;
|
||||
}
|
||||
|
||||
void Widget::AddChildLayers(const PaintEvent* event)
|
||||
void Widget::addChildLayers(const PaintEvent* event)
|
||||
{
|
||||
for(auto& child: mChildren)
|
||||
{
|
||||
child->SetBounds(mSize.mWidth, mSize.mHeight);
|
||||
child->SetLocation(mLocation);
|
||||
child->OnPaintEvent(event);
|
||||
const auto layers = child->GetLayers();
|
||||
child->setBounds(mSize.mWidth, mSize.mHeight);
|
||||
child->setLocation(mLocation);
|
||||
child->onPaintEvent(event);
|
||||
const auto layers = child->getLayers();
|
||||
mLayers.insert(mLayers.end(), layers.begin(), layers.end());
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::OnPaintEvent(const PaintEvent* event)
|
||||
bool Widget::needsUpdate() const
|
||||
{
|
||||
mMyLayers.clear();
|
||||
mLayers.clear();
|
||||
|
||||
if(!mVisible)return;
|
||||
AddBackground(event);
|
||||
CopyMyLayers();
|
||||
AddChildLayers(event);
|
||||
if (mDirty)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
for(auto& child: mChildren)
|
||||
{
|
||||
if (child->needsUpdate())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Widget::Contains(const DiscretePoint& loc) const
|
||||
void Widget::onPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
if(loc.GetX() < mLocation.GetX()) return false;
|
||||
if(loc.GetX() > mLocation.GetX() + mSize.mWidth) return false;
|
||||
if(loc.GetY() > mLocation.GetY() + mSize.mHeight) return false;
|
||||
if(loc.GetY() < mLocation.GetY()) return false;
|
||||
if (!needsUpdate())
|
||||
{
|
||||
return;
|
||||
}
|
||||
mLayers.clear();
|
||||
|
||||
if (mDirty)
|
||||
{
|
||||
mMyLayers.clear();
|
||||
if(!mVisible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
addBackground(event);
|
||||
mDirty = false;
|
||||
}
|
||||
addMyLayers();
|
||||
addChildLayers(event);
|
||||
}
|
||||
|
||||
bool Widget::contains(const DiscretePoint& loc) const
|
||||
{
|
||||
if(loc.GetX() < mLocation.GetX())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(loc.GetX() > mLocation.GetX() + mSize.mWidth)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(loc.GetY() > mLocation.GetY() + mSize.mHeight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(loc.GetY() < mLocation.GetY())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Widget::OnKeyboardEvent(const KeyboardEvent* event)
|
||||
bool Widget::onKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
bool inChild = false;
|
||||
for(const auto& child : mChildren)
|
||||
{
|
||||
if(child->OnKeyboardEvent(event))
|
||||
if(child->onKeyboardEvent(event))
|
||||
{
|
||||
inChild = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!inChild)
|
||||
{
|
||||
return OnMyKeyboardEvent(event);
|
||||
return onMyKeyboardEvent(event);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Widget::OnMyKeyboardEvent(const KeyboardEvent* event)
|
||||
bool Widget::onMyKeyboardEvent(const KeyboardEvent* event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Widget::OnMouseEvent(const MouseEvent* event)
|
||||
bool Widget::onMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
bool inChild = false;
|
||||
for(const auto& child : mChildren)
|
||||
{
|
||||
if(child->OnMouseEvent(event))
|
||||
if(child->onMouseEvent(event))
|
||||
{
|
||||
inChild = true;
|
||||
break;
|
||||
|
@ -164,9 +249,9 @@ bool Widget::OnMouseEvent(const MouseEvent* event)
|
|||
}
|
||||
if(!inChild)
|
||||
{
|
||||
if(Contains(event->GetClientLocation()))
|
||||
if(contains(event->GetClientLocation()))
|
||||
{
|
||||
OnMyMouseEvent(event);
|
||||
onMyMouseEvent(event);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -177,36 +262,27 @@ bool Widget::OnMouseEvent(const MouseEvent* event)
|
|||
return true;
|
||||
}
|
||||
|
||||
void Widget::OnMyMouseEvent(const MouseEvent* event)
|
||||
void Widget::onMyMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Widget::AddBackground(const PaintEvent* event)
|
||||
void Widget::addBackground(const PaintEvent* event)
|
||||
{
|
||||
unsigned locX = mLocation.GetX() + mMargin.mLeft;
|
||||
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);
|
||||
shape->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
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 shapeLayer = VisualLayer::Create();
|
||||
shapeLayer->SetShape(std::move(shape));
|
||||
mMyLayers.push_back(std::move(shapeLayer));
|
||||
}
|
||||
|
||||
void Widget::SetBackgroundColor(ColorUPtr color)
|
||||
{
|
||||
mBackgroundColor = std::move(color);
|
||||
}
|
||||
|
||||
void Widget::SetLocation(const DiscretePoint& loc)
|
||||
{
|
||||
mLocation = loc;
|
||||
}
|
||||
|
||||
void Widget::SetVisible(bool visible)
|
||||
{
|
||||
mVisible = visible;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue