summaryrefslogtreecommitdiff
path: root/Libraries/LibGfx
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-10-27 21:17:50 +0100
committerAndreas Kling <kling@serenityos.org>2020-10-27 21:25:40 +0100
commit3ec19ae4b6de72a7725668e281b1130d09654959 (patch)
treeabe1d97284bffebfd8f7704ffb4b44d13488f8db /Libraries/LibGfx
parentea14c67e29a423b875ef754a1ed503bb0ba09985 (diff)
downloadserenity-3ec19ae4b6de72a7725668e281b1130d09654959.zip
LibGUI+LibGfx+WindowServer: Auto-generate disabled action icons :^)
This patch adds a simple filter that makes button and menu item icons have that "'90s disabled" look when disabled. It's pretty awesome.
Diffstat (limited to 'Libraries/LibGfx')
-rw-r--r--Libraries/LibGfx/Painter.cpp16
-rw-r--r--Libraries/LibGfx/Painter.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp
index 38655da1ec..63015774ad 100644
--- a/Libraries/LibGfx/Painter.cpp
+++ b/Libraries/LibGfx/Painter.cpp
@@ -37,6 +37,7 @@
#include <AK/Utf32View.h>
#include <AK/Utf8View.h>
#include <LibGfx/CharacterBitmap.h>
+#include <LibGfx/Palette.h>
#include <LibGfx/Path.h>
#include <math.h>
#include <stdio.h>
@@ -1612,4 +1613,19 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule)
#endif
}
+void Painter::blit_disabled(const IntPoint& location, const Gfx::Bitmap& bitmap, const IntRect& rect, const Palette& palette)
+{
+ auto bright_color = palette.threed_highlight();
+ auto dark_color = palette.threed_shadow1();
+ blit_filtered(location.translated(1, 1), bitmap, rect, [&](auto) {
+ return bright_color;
+ });
+ blit_filtered(location, bitmap, rect, [&](Color src) {
+ int gray = src.to_grayscale().red();
+ if (gray > 160)
+ return bright_color;
+ return dark_color;
+ });
+}
+
}
diff --git a/Libraries/LibGfx/Painter.h b/Libraries/LibGfx/Painter.h
index d2b71cb74a..8ae33fc207 100644
--- a/Libraries/LibGfx/Painter.h
+++ b/Libraries/LibGfx/Painter.h
@@ -76,6 +76,7 @@ public:
void draw_tiled_bitmap(const IntRect& dst_rect, const Gfx::Bitmap&);
void blit_offset(const IntPoint&, const Gfx::Bitmap&, const IntRect& src_rect, const IntPoint&);
void blit_scaled(const IntRect&, const Gfx::Bitmap&, const IntRect&, float, float);
+ void blit_disabled(const IntPoint&, const Gfx::Bitmap&, const IntRect&, const Palette&);
void draw_text(const IntRect&, const StringView&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
void draw_text(const IntRect&, const StringView&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);
void draw_text(const IntRect&, const Utf32View&, const Font&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None);