mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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.
This commit is contained in:
parent
ea14c67e29
commit
3ec19ae4b6
Notes:
sideshowbarker
2024-07-19 01:41:06 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/3ec19ae4b6d
5 changed files with 23 additions and 3 deletions
|
@ -78,7 +78,7 @@ void Button::paint_event(PaintEvent& event)
|
|||
else
|
||||
painter.blit(icon_location, *m_icon, m_icon->rect());
|
||||
} else {
|
||||
painter.blit_dimmed(icon_location, *m_icon, m_icon->rect());
|
||||
painter.blit_disabled(icon_location, *m_icon, m_icon->rect(), palette());
|
||||
}
|
||||
}
|
||||
auto& font = is_checked() ? Gfx::Font::default_bold_font() : this->font();
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -153,7 +153,7 @@ void TaskbarButton::paint_event(GUI::PaintEvent& event)
|
|||
else
|
||||
painter.blit(icon_location, icon, icon.rect());
|
||||
} else {
|
||||
painter.blit_dimmed(icon_location, icon, icon.rect());
|
||||
painter.blit_disabled(icon_location, icon, icon.rect(), palette());
|
||||
}
|
||||
|
||||
if (!has_progress)
|
||||
|
|
|
@ -255,7 +255,10 @@ void Menu::draw()
|
|||
});
|
||||
icon_rect.move_by(-1, -1);
|
||||
}
|
||||
painter.blit(icon_rect.location(), *item.icon(), item.icon()->rect());
|
||||
if (item.is_enabled())
|
||||
painter.blit(icon_rect.location(), *item.icon(), item.icon()->rect());
|
||||
else
|
||||
painter.blit_disabled(icon_rect.location(), *item.icon(), item.icon()->rect(), palette);
|
||||
}
|
||||
auto& previous_font = painter.font();
|
||||
if (item.is_default())
|
||||
|
|
Loading…
Reference in a new issue