1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +00:00

WindowServer: Support hover icons for title buttons

This allows adding "-hover.png" variants of the title button icons.
This can be useful for themes which use the TitleButtonsIconOnly
flag, which otherwise don't have a way of showing the hover state.
This commit is contained in:
MacDue 2022-05-02 21:34:33 +01:00 committed by Linus Groh
parent 2cf36a1ca2
commit 44c0672d59
3 changed files with 43 additions and 22 deletions

View file

@ -31,13 +31,18 @@ void Button::paint(Screen& screen, Gfx::Painter& painter)
if (m_style == Style::Normal)
Gfx::StylePainter::paint_button(painter, rect(), palette, Gfx::ButtonStyle::Normal, m_pressed, m_hovered);
if (m_icon) {
auto& bitmap = m_icon->bitmap(screen.scale_factor());
auto paint_icon = [&](auto& multiscale_bitmap) {
auto& bitmap = multiscale_bitmap->bitmap(screen.scale_factor());
auto icon_location = rect().center().translated(-(bitmap.width() / 2), -(bitmap.height() / 2));
if (m_pressed)
painter.translate(1, 1);
painter.blit(icon_location, bitmap, bitmap.rect());
}
};
if (m_icon.hover_bitmap && m_hovered)
paint_icon(m_icon.hover_bitmap);
else if (m_icon.bitmap)
paint_icon(m_icon.bitmap);
}
void Button::on_mouse_event(MouseEvent const& event)