summaryrefslogtreecommitdiff
path: root/LibGUI/GButton.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-02-07 23:13:47 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-02-07 23:17:06 +0100
commit887b4a7a1a7d27d6c5bf12024e730fa06b2ab03e (patch)
tree08f30532b6f16c33ef34b325011162e2b0892bba /LibGUI/GButton.cpp
parent71b9ec1ae00db9206506dca95930db24c989d530 (diff)
downloadserenity-887b4a7a1a7d27d6c5bf12024e730fa06b2ab03e.zip
Start working on a simple Launcher app.
Let GButton have an optional icon (GraphicsBitmap) that gets rendered in the middle of the button if present. Also add GraphicsBitmap::load_from_file() which allows mmap'ed RGBA32 files. I wrote a little program to take "raw" files from GIMP and swizzle them into the correct byte order.
Diffstat (limited to 'LibGUI/GButton.cpp')
-rw-r--r--LibGUI/GButton.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/LibGUI/GButton.cpp b/LibGUI/GButton.cpp
index b94a863f75..2309ee0be0 100644
--- a/LibGUI/GButton.cpp
+++ b/LibGUI/GButton.cpp
@@ -55,11 +55,19 @@ void GButton::paint_event(GPaintEvent&)
painter.draw_line({ 2, height() - 3 }, { width() - 2, height() - 3 }, shadow_color);
}
- if (!caption().is_empty()) {
- auto text_rect = rect();
- if (m_being_pressed)
- text_rect.move_by(1, 1);
- painter.draw_text(text_rect, caption(), Painter::TextAlignment::Center, Color::Black);
+ if (!caption().is_empty() || m_icon) {
+ auto content_rect = rect();
+ auto icon_location = m_icon ? content_rect.center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)) : Point();
+ if (m_being_pressed) {
+ content_rect.move_by(1, 1);
+ icon_location.move_by(1, 1);
+ }
+ if (m_icon) {
+ painter.blit_with_alpha(icon_location, *m_icon, m_icon->rect());
+ painter.draw_text(content_rect, caption(), Painter::TextAlignment::Center, Color::Black);
+ } else {
+ painter.draw_text(content_rect, caption(), Painter::TextAlignment::Center, Color::Black);
+ }
}
}