1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 19:15:08 +00:00
serenity/Servers/WindowServer/WSButton.cpp
Andreas Kling 0d60c56b51 WindowServer: Make WSWindowFrame and WSButton deal in relative coordinates.
This was a bit painful to get right. The code is a lot more pleasant to
deal with now that all coordinates are relative to their local system
instead of being absolute screen coordinates.
2019-04-05 21:33:34 +02:00

33 lines
938 B
C++

#include <WindowServer/WSButton.h>
#include <WindowServer/WSMessage.h>
#include <SharedGraphics/Painter.h>
#include <SharedGraphics/StylePainter.h>
#include <SharedGraphics/CharacterBitmap.h>
WSButton::WSButton(Retained<CharacterBitmap>&& bitmap, Function<void()>&& on_click_handler)
: on_click(move(on_click_handler))
, m_bitmap(move(bitmap))
{
}
WSButton::~WSButton()
{
}
void WSButton::paint(Painter& painter)
{
PainterStateSaver saver(painter);
painter.translate(relative_rect().location());
StylePainter::paint_button(painter, rect(), ButtonStyle::Normal, m_pressed);
auto x_location = rect().center();
x_location.move_by(-(m_bitmap->width() / 2), -(m_bitmap->height() / 2));
painter.draw_bitmap(x_location, *m_bitmap, Color::Black);
}
void WSButton::on_mouse_event(const WSMouseEvent& event)
{
if (event.type() == WSMessage::MouseDown) {
if (on_click)
on_click();
}
}