summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-01-09 17:29:06 +0000
committerAndreas Kling <kling@serenityos.org>2022-01-16 11:17:03 +0100
commit21a24c36a8210ae64cf804dc8bd063f77006b55a (patch)
treefc8eedd1983c37b9f66899e1a1854807c3a81bd1
parent8175cd0a28e78f71c494796c69faac7574d3910f (diff)
downloadserenity-21a24c36a8210ae64cf804dc8bd063f77006b55a.zip
LibGUI: Make GlyphMapWidget work with vector fonts
This basically just meant replacing the `m_font` field with the one inherited from Widget.
-rw-r--r--Userland/Applications/FontEditor/FontEditor.cpp2
-rw-r--r--Userland/Libraries/LibGUI/GlyphMapWidget.cpp29
-rw-r--r--Userland/Libraries/LibGUI/GlyphMapWidget.h7
3 files changed, 15 insertions, 23 deletions
diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp
index a0f07053b1..53c28fb9a5 100644
--- a/Userland/Applications/FontEditor/FontEditor.cpp
+++ b/Userland/Applications/FontEditor/FontEditor.cpp
@@ -488,7 +488,7 @@ void FontEditorWidget::initialize(String const& path, RefPtr<Gfx::BitmapFont>&&
m_path = path;
m_edited_font = edited_font;
- m_glyph_map_widget->initialize(*m_edited_font);
+ m_glyph_map_widget->set_font(*m_edited_font);
m_glyph_editor_widget->initialize(*m_edited_font);
did_resize_glyph_editor();
diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
index 2ac8e91709..32e78b1450 100644
--- a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
+++ b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
@@ -12,6 +12,8 @@
#include <LibGfx/Emoji.h>
#include <LibGfx/Palette.h>
+REGISTER_WIDGET(GUI, GlyphMapWidget);
+
namespace GUI {
GlyphMapWidget::Selection GlyphMapWidget::Selection::normalized() const
@@ -49,26 +51,15 @@ GlyphMapWidget::GlyphMapWidget()
{
set_focus_policy(FocusPolicy::StrongFocus);
horizontal_scrollbar().set_visible(false);
+ did_change_font();
}
GlyphMapWidget::~GlyphMapWidget()
{
}
-void GlyphMapWidget::initialize(Gfx::BitmapFont& mutable_font)
-{
- if (m_font == mutable_font)
- return;
- m_font = mutable_font;
- vertical_scrollbar().set_step(font().glyph_height() + m_vertical_spacing);
- set_active_glyph('A');
-}
-
void GlyphMapWidget::resize_event(ResizeEvent& event)
{
- if (!m_font)
- return;
-
int event_width = event.size().width() - vertical_scrollbar().width() - (frame_thickness() * 2) - m_horizontal_spacing;
int event_height = event.size().height() - (frame_thickness() * 2);
m_visible_glyphs = (event_width * event_height) / (font().max_glyph_width() * font().glyph_height());
@@ -139,16 +130,16 @@ void GlyphMapWidget::paint_event(PaintEvent& event)
font().glyph_height());
if (m_selection.contains(glyph)) {
painter.fill_rect(outer_rect, is_focused() ? palette().selection() : palette().inactive_selection());
- if (m_font->contains_raw_glyph(glyph))
+ 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))
- painter.draw_emoji(inner_rect.location(), *emoji, *m_font);
- } else if (m_font->contains_raw_glyph(glyph)) {
+ painter.draw_emoji(inner_rect.location(), *emoji, font());
+ } else if (font().contains_glyph(glyph)) {
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 });
- painter.draw_emoji(inner_rect.location(), *emoji, *m_font);
+ painter.draw_emoji(inner_rect.location(), *emoji, font());
}
}
painter.draw_focus_rect(get_outer_rect(m_active_glyph), Gfx::Color::Black);
@@ -252,6 +243,12 @@ void GlyphMapWidget::keydown_event(KeyEvent& event)
}
}
+void GlyphMapWidget::did_change_font()
+{
+ vertical_scrollbar().set_step(font().glyph_height() + m_vertical_spacing);
+ set_active_glyph('A');
+}
+
void GlyphMapWidget::scroll_to_glyph(int glyph)
{
int row = glyph / columns();
diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.h b/Userland/Libraries/LibGUI/GlyphMapWidget.h
index dbc25e08ec..e5c82eb8e1 100644
--- a/Userland/Libraries/LibGUI/GlyphMapWidget.h
+++ b/Userland/Libraries/LibGUI/GlyphMapWidget.h
@@ -19,8 +19,6 @@ class GlyphMapWidget final : public AbstractScrollableWidget {
public:
virtual ~GlyphMapWidget() override;
- void initialize(Gfx::BitmapFont&);
-
class Selection {
public:
Selection() = default;
@@ -61,9 +59,6 @@ public:
int rows() const { return m_rows; }
int columns() const { return m_columns; }
- Gfx::BitmapFont& font() { return *m_font; }
- Gfx::BitmapFont const& font() const { return *m_font; }
-
Function<void(int)> on_active_glyph_changed;
private:
@@ -72,6 +67,7 @@ private:
virtual void mousedown_event(MouseEvent&) override;
virtual void keydown_event(KeyEvent&) override;
virtual void resize_event(ResizeEvent&) override;
+ virtual void did_change_font() override;
Gfx::IntRect get_outer_rect(int glyph) const;
@@ -80,7 +76,6 @@ private:
void paste_glyph(int glyph);
void delete_glyph(int glyph);
- RefPtr<Gfx::BitmapFont> m_font;
int m_glyph_count { 0x110000 };
int m_columns { 0 };
int m_rows { 0 };