From a2eb42a9c0d3edaebfaaf9a587c5fded825d58f7 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 9 Sep 2022 11:40:46 -0400 Subject: [PATCH] LibGUI: Add an emoji category filter for SerenityOS custom emojis Most of the emoji are 7x10px (or close to that). But some are larger, on the order of 128x128px. The icon used for the SerenityOS category is one such large emoji, and must be scaled down to an appropriate size for rendering. --- Userland/Libraries/LibGUI/EmojiInputDialog.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp index b9a4f2d4ee..37eb764ca4 100644 --- a/Userland/Libraries/LibGUI/EmojiInputDialog.cpp +++ b/Userland/Libraries/LibGUI/EmojiInputDialog.cpp @@ -42,8 +42,22 @@ static constexpr auto s_emoji_groups = Array { EmojiCateogry { Unicode::EmojiGroup::Objects, "/res/emoji/U+1F4E6.png"sv }, EmojiCateogry { Unicode::EmojiGroup::Symbols, "/res/emoji/U+2764.png"sv }, EmojiCateogry { Unicode::EmojiGroup::Flags, "/res/emoji/U+1F6A9.png"sv }, + EmojiCateogry { Unicode::EmojiGroup::SerenityOS, "/res/emoji/U+10CD0B.png"sv }, }; +static void resize_bitmap_if_needed(NonnullRefPtr& bitmap) +{ + constexpr int max_icon_size = 12; + + if ((bitmap->width() > max_icon_size) || (bitmap->height() > max_icon_size)) { + auto x_ratio = static_cast(max_icon_size) / static_cast(bitmap->width()); + auto y_ratio = static_cast(max_icon_size) / static_cast(bitmap->height()); + auto ratio = min(x_ratio, y_ratio); + + bitmap = bitmap->scaled(ratio, ratio).release_value_but_fixme_should_propagate_errors(); + } +} + EmojiInputDialog::EmojiInputDialog(Window* parent_window) : Dialog(parent_window) , m_category_action_group(make()) @@ -70,7 +84,9 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window) for (auto const& category : s_emoji_groups) { auto name = Unicode::emoji_group_to_string(category.group); auto tooltip = name.replace("&"sv, "&&"sv, ReplaceMode::FirstOnly); + auto bitmap = Gfx::Bitmap::try_load_from_file(category.emoji).release_value_but_fixme_should_propagate_errors(); + resize_bitmap_if_needed(bitmap); auto set_filter_action = Action::create_checkable( tooltip, bitmap, [this, group = category.group](auto& action) {