From c815fa7f474b3b74f1f973c03325265aaa149eac Mon Sep 17 00:00:00 2001 From: thankyouverycool <66646555+thankyouverycool@users.noreply.github.com> Date: Wed, 29 Jul 2020 16:22:05 -0400 Subject: [PATCH] Services: Convert WindowFrame button bitmaps to themable PNGs Custom buttons can now be set using TitleButtonIcons under the Paths group in themes. WindowFrame recognizes window-close.png, window-minimize.png, window-maximize.png and window-restore.png filenames. --- Services/WindowServer/Button.cpp | 15 +-- Services/WindowServer/Button.h | 9 +- Services/WindowServer/WindowFrame.cpp | 140 ++++++++++-------------- Services/WindowServer/WindowFrame.h | 2 + Services/WindowServer/WindowManager.cpp | 1 + 5 files changed, 75 insertions(+), 92 deletions(-) diff --git a/Services/WindowServer/Button.cpp b/Services/WindowServer/Button.cpp index 5dd45093dd..e87e64a558 100644 --- a/Services/WindowServer/Button.cpp +++ b/Services/WindowServer/Button.cpp @@ -33,10 +33,9 @@ namespace WindowServer { -Button::Button(WindowFrame& frame, NonnullRefPtr&& bitmap, Function&& on_click_handler) +Button::Button(WindowFrame& frame, Function&& on_click_handler) : on_click(move(on_click_handler)) , m_frame(frame) - , m_bitmap(move(bitmap)) { } @@ -50,11 +49,13 @@ void Button::paint(Gfx::Painter& painter) Gfx::PainterStateSaver saver(painter); painter.translate(relative_rect().location()); Gfx::StylePainter::paint_button(painter, rect(), palette, Gfx::ButtonStyle::Normal, m_pressed, m_hovered); - auto x_location = rect().center(); - x_location.move_by(-(m_bitmap->width() / 2), -(m_bitmap->height() / 2)); - if (m_pressed) - x_location.move_by(1, 1); - painter.draw_bitmap(x_location, *m_bitmap, palette.button_text()); + + if (m_icon) { + auto icon_location = rect().center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)); + if (m_pressed) + painter.translate(1, 1); + painter.blit(icon_location, *m_icon, m_icon->rect()); + } } void Button::on_mouse_event(const MouseEvent& event) diff --git a/Services/WindowServer/Button.h b/Services/WindowServer/Button.h index 0002e92f88..7a2d6b82e9 100644 --- a/Services/WindowServer/Button.h +++ b/Services/WindowServer/Button.h @@ -27,10 +27,9 @@ #pragma once #include -#include #include -#include #include +#include namespace WindowServer { @@ -39,7 +38,7 @@ class WindowFrame; class Button : public Weakable