2018-10-11 01:48:09 +02:00
|
|
|
#include "Button.h"
|
|
|
|
|
#include "Painter.h"
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
|
|
Button::Button(Widget* parent)
|
|
|
|
|
: Widget(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Button::~Button()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Button::setCaption(String&& caption)
|
|
|
|
|
{
|
|
|
|
|
if (caption == m_caption)
|
|
|
|
|
return;
|
|
|
|
|
m_caption = std::move(caption);
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Button::onPaint(PaintEvent&)
|
|
|
|
|
{
|
|
|
|
|
Painter painter(*this);
|
2018-10-12 14:15:14 +02:00
|
|
|
painter.fillRect(rect(), backgroundColor());
|
2018-10-11 01:48:09 +02:00
|
|
|
if (!caption().isEmpty()) {
|
2018-10-12 14:15:14 +02:00
|
|
|
painter.drawText(rect(), caption(), Painter::TextAlignment::Center, Color(0, 0, 0));
|
2018-10-11 01:48:09 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Button::onMouseDown(MouseEvent& event)
|
|
|
|
|
{
|
|
|
|
|
printf("Button::onMouseDown: x=%d, y=%d, button=%u\n", event.x(), event.y(), (unsigned)event.button());
|
|
|
|
|
|
|
|
|
|
setBackgroundColor(Color(0xff, 0xc0, 0xc0));
|
|
|
|
|
update();
|
|
|
|
|
Widget::onMouseDown(event);
|
|
|
|
|
}
|
|
|
|
|
|