1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:38:10 +00:00

WindowServer: Add a WSButton class and make the window close buttons use it.

This commit is contained in:
Andreas Kling 2019-04-05 18:40:36 +02:00
parent 9fbac66a91
commit 3155a2e128
5 changed files with 112 additions and 50 deletions

View file

@ -0,0 +1,31 @@
#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)
{
StylePainter::paint_button(painter, m_rect, ButtonStyle::Normal, m_pressed);
auto x_location = m_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();
}
}