1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:07:45 +00:00

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.
This commit is contained in:
Andreas Kling 2019-02-07 23:13:47 +01:00
parent 71b9ec1ae0
commit 887b4a7a1a
29 changed files with 293 additions and 11 deletions

View file

@ -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);
}
}
}

View file

@ -3,6 +3,7 @@
#include "GWidget.h"
#include <AK/AKString.h>
#include <AK/Function.h>
#include <SharedGraphics/GraphicsBitmap.h>
class GButton final : public GWidget {
public:
@ -12,6 +13,10 @@ public:
String caption() const { return m_caption; }
void set_caption(String&&);
void set_icon(RetainPtr<GraphicsBitmap>&& icon) { m_icon = move(icon); }
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
GraphicsBitmap* icon() { return m_icon.ptr(); }
Function<void(GButton&)> on_click;
private:
@ -23,6 +28,7 @@ private:
virtual const char* class_name() const override { return "GButton"; }
String m_caption;
RetainPtr<GraphicsBitmap> m_icon;
bool m_being_pressed { false };
bool m_tracking_cursor { false };
};