44 lines
811 B
C++
44 lines
811 B
C++
#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);
|
|
}
|
|
}
|