mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:27:43 +00:00
LibGUI: Make GlyphMapWidget work with vector fonts
This basically just meant replacing the `m_font` field with the one inherited from Widget.
This commit is contained in:
parent
8175cd0a28
commit
21a24c36a8
3 changed files with 15 additions and 23 deletions
|
@ -488,7 +488,7 @@ void FontEditorWidget::initialize(String const& path, RefPtr<Gfx::BitmapFont>&&
|
||||||
m_path = path;
|
m_path = path;
|
||||||
m_edited_font = edited_font;
|
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);
|
m_glyph_editor_widget->initialize(*m_edited_font);
|
||||||
did_resize_glyph_editor();
|
did_resize_glyph_editor();
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#include <LibGfx/Emoji.h>
|
#include <LibGfx/Emoji.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
|
|
||||||
|
REGISTER_WIDGET(GUI, GlyphMapWidget);
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
GlyphMapWidget::Selection GlyphMapWidget::Selection::normalized() const
|
GlyphMapWidget::Selection GlyphMapWidget::Selection::normalized() const
|
||||||
|
@ -49,26 +51,15 @@ GlyphMapWidget::GlyphMapWidget()
|
||||||
{
|
{
|
||||||
set_focus_policy(FocusPolicy::StrongFocus);
|
set_focus_policy(FocusPolicy::StrongFocus);
|
||||||
horizontal_scrollbar().set_visible(false);
|
horizontal_scrollbar().set_visible(false);
|
||||||
|
did_change_font();
|
||||||
}
|
}
|
||||||
|
|
||||||
GlyphMapWidget::~GlyphMapWidget()
|
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)
|
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_width = event.size().width() - vertical_scrollbar().width() - (frame_thickness() * 2) - m_horizontal_spacing;
|
||||||
int event_height = event.size().height() - (frame_thickness() * 2);
|
int event_height = event.size().height() - (frame_thickness() * 2);
|
||||||
m_visible_glyphs = (event_width * event_height) / (font().max_glyph_width() * font().glyph_height());
|
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());
|
font().glyph_height());
|
||||||
if (m_selection.contains(glyph)) {
|
if (m_selection.contains(glyph)) {
|
||||||
painter.fill_rect(outer_rect, is_focused() ? palette().selection() : palette().inactive_selection());
|
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());
|
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))
|
||||||
painter.draw_emoji(inner_rect.location(), *emoji, *m_font);
|
painter.draw_emoji(inner_rect.location(), *emoji, font());
|
||||||
} else if (m_font->contains_raw_glyph(glyph)) {
|
} else if (font().contains_glyph(glyph)) {
|
||||||
painter.fill_rect(outer_rect, palette().base());
|
painter.fill_rect(outer_rect, palette().base());
|
||||||
painter.draw_glyph(inner_rect.location(), glyph, palette().base_text());
|
painter.draw_glyph(inner_rect.location(), glyph, palette().base_text());
|
||||||
} else if (auto* emoji = Gfx::Emoji::emoji_for_code_point(glyph)) {
|
} else if (auto* emoji = Gfx::Emoji::emoji_for_code_point(glyph)) {
|
||||||
painter.fill_rect(outer_rect, Gfx::Color { 255, 150, 150 });
|
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);
|
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)
|
void GlyphMapWidget::scroll_to_glyph(int glyph)
|
||||||
{
|
{
|
||||||
int row = glyph / columns();
|
int row = glyph / columns();
|
||||||
|
|
|
@ -19,8 +19,6 @@ class GlyphMapWidget final : public AbstractScrollableWidget {
|
||||||
public:
|
public:
|
||||||
virtual ~GlyphMapWidget() override;
|
virtual ~GlyphMapWidget() override;
|
||||||
|
|
||||||
void initialize(Gfx::BitmapFont&);
|
|
||||||
|
|
||||||
class Selection {
|
class Selection {
|
||||||
public:
|
public:
|
||||||
Selection() = default;
|
Selection() = default;
|
||||||
|
@ -61,9 +59,6 @@ public:
|
||||||
int rows() const { return m_rows; }
|
int rows() const { return m_rows; }
|
||||||
int columns() const { return m_columns; }
|
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;
|
Function<void(int)> on_active_glyph_changed;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -72,6 +67,7 @@ private:
|
||||||
virtual void mousedown_event(MouseEvent&) override;
|
virtual void mousedown_event(MouseEvent&) override;
|
||||||
virtual void keydown_event(KeyEvent&) override;
|
virtual void keydown_event(KeyEvent&) override;
|
||||||
virtual void resize_event(ResizeEvent&) override;
|
virtual void resize_event(ResizeEvent&) override;
|
||||||
|
virtual void did_change_font() override;
|
||||||
|
|
||||||
Gfx::IntRect get_outer_rect(int glyph) const;
|
Gfx::IntRect get_outer_rect(int glyph) const;
|
||||||
|
|
||||||
|
@ -80,7 +76,6 @@ private:
|
||||||
void paste_glyph(int glyph);
|
void paste_glyph(int glyph);
|
||||||
void delete_glyph(int glyph);
|
void delete_glyph(int glyph);
|
||||||
|
|
||||||
RefPtr<Gfx::BitmapFont> m_font;
|
|
||||||
int m_glyph_count { 0x110000 };
|
int m_glyph_count { 0x110000 };
|
||||||
int m_columns { 0 };
|
int m_columns { 0 };
|
||||||
int m_rows { 0 };
|
int m_rows { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue