More window cleaning
This commit is contained in:
parent
6adc441e6f
commit
53c98a227d
29 changed files with 422 additions and 261 deletions
|
@ -21,22 +21,26 @@ std::unique_ptr<Button> Button::Create()
|
|||
return std::make_unique<Button>();
|
||||
}
|
||||
|
||||
void Button::SetOnClickFunction(clickFunc func)
|
||||
void Button::setOnClickFunction(clickFunc func)
|
||||
{
|
||||
mClickFunc = func;
|
||||
}
|
||||
|
||||
void Button::SetLabel(const std::string& text)
|
||||
void Button::setLabel(const std::string& text)
|
||||
{
|
||||
mLabel = text;
|
||||
if (text != mLabel)
|
||||
{
|
||||
mLabel = text;
|
||||
mDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Button::OnMyMouseEvent(const MouseEvent* event)
|
||||
void Button::onMyMouseEvent(const MouseEvent* event)
|
||||
{
|
||||
if(event->GetAction() == MouseEvent::Action::Pressed)
|
||||
{
|
||||
mCachedColor = *mBackgroundColor;
|
||||
SetBackgroundColor(Color::Create(*mClickedColor));
|
||||
setBackgroundColor(Color::Create(*mClickedColor));
|
||||
if(mClickFunc)
|
||||
{
|
||||
mClickFunc(this);
|
||||
|
@ -44,24 +48,39 @@ void Button::OnMyMouseEvent(const MouseEvent* event)
|
|||
}
|
||||
else if(event->GetAction() == MouseEvent::Action::Released)
|
||||
{
|
||||
SetBackgroundColor(Color::Create(mCachedColor));
|
||||
setBackgroundColor(Color::Create(mCachedColor));
|
||||
}
|
||||
}
|
||||
|
||||
void Button::OnPaintEvent(const PaintEvent* event)
|
||||
void Button::onPaintEvent(const PaintEvent* event)
|
||||
{
|
||||
mMyLayers.clear();
|
||||
AddBackground(event);
|
||||
if(!mLabel.empty())
|
||||
if (!needsUpdate())
|
||||
{
|
||||
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));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
return;
|
||||
}
|
||||
CopyMyLayers();
|
||||
mLayers.clear();
|
||||
|
||||
if (mDirty)
|
||||
{
|
||||
mMyLayers.clear();
|
||||
if(!mVisible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
addBackground(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 textLayer = VisualLayer::Create();
|
||||
auto textElement = TextElement::Create(mLabel, middle);
|
||||
textElement->SetFillColor(Color::Create(*mBackgroundColor));
|
||||
textLayer->SetText(std::move(textElement));
|
||||
mMyLayers.push_back(std::move(textLayer));
|
||||
}
|
||||
mDirty = false;
|
||||
addMyLayers();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue