1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 15:38:12 +00:00

LibGUI+FontEditor: Allow system emoji to be toggled in GlyphMapWidget

And remove their red backgrounds when visible to not be confused with
deletion highlights.
This commit is contained in:
thankyouverycool 2022-08-14 16:00:26 -04:00 committed by Andreas Kling
parent c974e644ec
commit d9fb838cf6
4 changed files with 32 additions and 5 deletions

View file

@ -222,15 +222,24 @@ ErrorOr<void> MainWidget::create_actions()
m_show_statusbar_action->set_checked(show_statusbar);
m_show_statusbar_action->set_status_tip("Show or hide the status bar");
bool highlight_modifications = Config::read_bool("FontEditor"sv, "Display"sv, "HighlightModifications"sv, true);
bool highlight_modifications = Config::read_bool("FontEditor"sv, "GlyphMap"sv, "HighlightModifications"sv, true);
set_highlight_modifications(highlight_modifications);
m_highlight_modifications_action = GUI::Action::create_checkable("&Highlight Modifications", { Mod_Ctrl, Key_H }, [&](auto& action) {
set_highlight_modifications(action.is_checked());
Config::write_bool("FontEditor"sv, "Display"sv, "HighlightModifications"sv, action.is_checked());
Config::write_bool("FontEditor"sv, "GlyphMap"sv, "HighlightModifications"sv, action.is_checked());
});
m_highlight_modifications_action->set_checked(highlight_modifications);
m_highlight_modifications_action->set_status_tip("Show or hide highlights on modified glyphs. (Green = New, Blue = Modified, Red = Deleted)");
bool show_system_emoji = Config::read_bool("FontEditor"sv, "GlyphMap"sv, "ShowSystemEmoji"sv, true);
set_show_system_emoji(show_system_emoji);
m_show_system_emoji_action = GUI::Action::create_checkable("System &Emoji", { Mod_Ctrl, Key_E }, [&](auto& action) {
set_show_system_emoji(action.is_checked());
Config::write_bool("FontEditor"sv, "GlyphMap"sv, "ShowSystemEmoji"sv, action.is_checked());
});
m_show_system_emoji_action->set_checked(show_system_emoji);
m_show_system_emoji_action->set_status_tip("Show or hide system emoji");
m_go_to_glyph_action = GUI::Action::create("&Go to Glyph...", { Mod_Ctrl, Key_G }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-to.png"sv)), [&](auto&) {
String input;
if (GUI::InputBox::show(window(), input, "Hexadecimal:"sv, "Go to glyph"sv) == GUI::InputBox::ExecResult::OK && !input.is_empty()) {
@ -684,6 +693,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
TRY(view_menu->try_add_action(*m_open_preview_action));
TRY(view_menu->try_add_separator());
TRY(view_menu->try_add_action(*m_highlight_modifications_action));
TRY(view_menu->try_add_action(*m_show_system_emoji_action));
TRY(view_menu->try_add_separator());
auto scale_menu = TRY(view_menu->try_add_submenu("&Scale"));
TRY(scale_menu->try_add_action(*m_scale_five_action));
@ -748,6 +758,11 @@ void MainWidget::set_highlight_modifications(bool highlight_modifications)
m_glyph_map_widget->set_highlight_modifications(highlight_modifications);
}
void MainWidget::set_show_system_emoji(bool show)
{
m_glyph_map_widget->set_show_system_emoji(show);
}
ErrorOr<void> MainWidget::open_file(String const& path)
{
auto unmasked_font = TRY(TRY(Gfx::BitmapFont::try_load_from_file(path))->unmasked_character_set());

View file

@ -55,6 +55,7 @@ public:
void set_show_statusbar(bool);
void set_highlight_modifications(bool);
void set_show_system_emoji(bool);
private:
MainWidget();
@ -118,6 +119,7 @@ private:
RefPtr<GUI::Action> m_show_toolbar_action;
RefPtr<GUI::Action> m_show_statusbar_action;
RefPtr<GUI::Action> m_highlight_modifications_action;
RefPtr<GUI::Action> m_show_system_emoji_action;
GUI::ActionGroup m_glyph_editor_scale_actions;
RefPtr<GUI::Action> m_scale_five_action;

View file

@ -144,7 +144,7 @@ void GlyphMapWidget::paint_event(PaintEvent& event)
painter.fill_rect(outer_rect, is_focused() ? palette().selection() : palette().inactive_selection());
if (font().contains_glyph(glyph))
painter.draw_glyph(inner_rect.location(), glyph, is_focused() ? palette().selection_text() : palette().inactive_selection_text());
else if (auto* emoji = Gfx::Emoji::emoji_for_code_point(glyph))
else if (auto* emoji = Gfx::Emoji::emoji_for_code_point(glyph); emoji && m_show_system_emoji)
painter.draw_emoji(inner_rect.location(), *emoji, font());
} else if (font().contains_glyph(glyph)) {
if (m_highlight_modifications && m_modified_glyphs.contains(glyph)) {
@ -165,8 +165,7 @@ void GlyphMapWidget::paint_event(PaintEvent& event)
painter.fill_rect(outer_rect, palette().base());
}
painter.draw_glyph(inner_rect.location(), glyph, palette().base_text());
} else if (auto* emoji = Gfx::Emoji::emoji_for_code_point(glyph)) {
painter.fill_rect(outer_rect, Gfx::Color { 255, 150, 150 });
} else if (auto* emoji = Gfx::Emoji::emoji_for_code_point(glyph); emoji && m_show_system_emoji) {
painter.draw_emoji(inner_rect.location(), *emoji, font());
} else {
if (m_highlight_modifications && m_original_font->contains_glyph(glyph)) {
@ -436,6 +435,14 @@ void GlyphMapWidget::set_highlight_modifications(bool highlight_modifications)
update();
}
void GlyphMapWidget::set_show_system_emoji(bool show)
{
if (m_show_system_emoji == show)
return;
m_show_system_emoji = show;
update();
}
void GlyphMapWidget::set_glyph_modified(u32 glyph, bool modified)
{
if (modified)

View file

@ -63,6 +63,8 @@ public:
void update_glyph(int);
void set_highlight_modifications(bool);
void set_show_system_emoji(bool);
void set_glyph_modified(u32 glyph, bool modified);
bool glyph_is_modified(u32 glyph);
@ -105,6 +107,7 @@ private:
int m_visible_glyphs { 0 };
bool m_in_drag_select { false };
bool m_highlight_modifications { false };
bool m_show_system_emoji { false };
HashTable<u32> m_modified_glyphs;
Unicode::CodePointRange m_active_range { 0x0000, 0x10FFFF };
RefPtr<Core::Timer> m_automatic_selection_scroll_timer;