summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-01-09 16:15:23 +0000
committerAndreas Kling <kling@serenityos.org>2022-01-16 11:17:03 +0100
commit8175cd0a28e78f71c494796c69faac7574d3910f (patch)
tree9639ad578c5d1b94148f7da8308dfa3666023245
parentdd17df76e9d02b2969b1c4771134a30a4a844e31 (diff)
downloadserenity-8175cd0a28e78f71c494796c69faac7574d3910f.zip
LibGUI+FontEditor: Move GlyphMapWidget to LibGUI
This will allow us to use this in other apps, such as the upcoming Character Map. :^)
-rw-r--r--Userland/Applications/FontEditor/CMakeLists.txt1
-rw-r--r--Userland/Applications/FontEditor/FontEditor.cpp3
-rw-r--r--Userland/Applications/FontEditor/FontEditor.h4
-rw-r--r--Userland/Libraries/LibGUI/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibGUI/GlyphMapWidget.cpp (renamed from Userland/Applications/FontEditor/GlyphMapWidget.cpp)25
-rw-r--r--Userland/Libraries/LibGUI/GlyphMapWidget.h (renamed from Userland/Applications/FontEditor/GlyphMapWidget.h)15
6 files changed, 28 insertions, 21 deletions
diff --git a/Userland/Applications/FontEditor/CMakeLists.txt b/Userland/Applications/FontEditor/CMakeLists.txt
index 82e01123d1..31ee3f79c6 100644
--- a/Userland/Applications/FontEditor/CMakeLists.txt
+++ b/Userland/Applications/FontEditor/CMakeLists.txt
@@ -13,7 +13,6 @@ set(SOURCES
FontEditor.cpp
FontEditorWindowGML.h
GlyphEditorWidget.cpp
- GlyphMapWidget.cpp
main.cpp
NewFontDialog.cpp
NewFontDialogPage1GML.h
diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp
index 6ac1691282..a0f07053b1 100644
--- a/Userland/Applications/FontEditor/FontEditor.cpp
+++ b/Userland/Applications/FontEditor/FontEditor.cpp
@@ -6,7 +6,6 @@
#include "FontEditor.h"
#include "GlyphEditorWidget.h"
-#include "GlyphMapWidget.h"
#include "NewFontDialog.h"
#include <AK/StringBuilder.h>
#include <AK/UnicodeUtils.h>
@@ -135,7 +134,7 @@ FontEditorWidget::FontEditorWidget()
m_font_metadata_groupbox = *find_descendant_of_type_named<GUI::GroupBox>("font_metadata_groupbox");
m_glyph_editor_widget = m_glyph_editor_container->add<GlyphEditorWidget>();
- m_glyph_map_widget = glyph_map_container.add<GlyphMapWidget>();
+ m_glyph_map_widget = glyph_map_container.add<GUI::GlyphMapWidget>();
m_new_action = GUI::Action::create("&New Font...", { Mod_Ctrl, Key_N }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-font.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
if (!request_close())
diff --git a/Userland/Applications/FontEditor/FontEditor.h b/Userland/Applications/FontEditor/FontEditor.h
index 24efcc0f3c..8b6af595b8 100644
--- a/Userland/Applications/FontEditor/FontEditor.h
+++ b/Userland/Applications/FontEditor/FontEditor.h
@@ -9,12 +9,12 @@
#include "UndoGlyph.h"
#include <LibConfig/Listener.h>
#include <LibGUI/ActionGroup.h>
+#include <LibGUI/GlyphMapWidget.h>
#include <LibGUI/UndoStack.h>
#include <LibGUI/Widget.h>
#include <LibGfx/BitmapFont.h>
class GlyphEditorWidget;
-class GlyphMapWidget;
class FontEditorWidget final
: public GUI::Widget
@@ -62,7 +62,7 @@ private:
RefPtr<Gfx::BitmapFont> m_edited_font;
- RefPtr<GlyphMapWidget> m_glyph_map_widget;
+ RefPtr<GUI::GlyphMapWidget> m_glyph_map_widget;
RefPtr<GlyphEditorWidget> m_glyph_editor_widget;
RefPtr<GUI::Action> m_new_action;
diff --git a/Userland/Libraries/LibGUI/CMakeLists.txt b/Userland/Libraries/LibGUI/CMakeLists.txt
index a0d06444e6..39cdc7c448 100644
--- a/Userland/Libraries/LibGUI/CMakeLists.txt
+++ b/Userland/Libraries/LibGUI/CMakeLists.txt
@@ -42,6 +42,7 @@ set(SOURCES
FontPicker.cpp
FontPickerDialogGML.h
Frame.cpp
+ GlyphMapWidget.cpp
GMLAutocompleteProvider.cpp
GMLFormatter.cpp
GMLLexer.cpp
diff --git a/Userland/Applications/FontEditor/GlyphMapWidget.cpp b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
index 91c518752a..2ac8e91709 100644
--- a/Userland/Applications/FontEditor/GlyphMapWidget.cpp
+++ b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
@@ -1,18 +1,19 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Mustafa Quraish <mustafa@serenityos.org>
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "GlyphMapWidget.h"
-#include <AK/MemoryStream.h>
-#include <LibGUI/Clipboard.h>
#include <LibGUI/Painter.h>
#include <LibGfx/BitmapFont.h>
#include <LibGfx/Emoji.h>
#include <LibGfx/Palette.h>
+namespace GUI {
+
GlyphMapWidget::Selection GlyphMapWidget::Selection::normalized() const
{
if (m_size > 0)
@@ -46,7 +47,7 @@ void GlyphMapWidget::Selection::extend_to(int glyph)
GlyphMapWidget::GlyphMapWidget()
{
- set_focus_policy(GUI::FocusPolicy::StrongFocus);
+ set_focus_policy(FocusPolicy::StrongFocus);
horizontal_scrollbar().set_visible(false);
}
@@ -63,7 +64,7 @@ void GlyphMapWidget::initialize(Gfx::BitmapFont& mutable_font)
set_active_glyph('A');
}
-void GlyphMapWidget::resize_event(GUI::ResizeEvent& event)
+void GlyphMapWidget::resize_event(ResizeEvent& event)
{
if (!m_font)
return;
@@ -115,11 +116,11 @@ void GlyphMapWidget::update_glyph(int glyph)
update(get_outer_rect(glyph));
}
-void GlyphMapWidget::paint_event(GUI::PaintEvent& event)
+void GlyphMapWidget::paint_event(PaintEvent& event)
{
- GUI::Frame::paint_event(event);
+ Frame::paint_event(event);
- GUI::Painter painter(*this);
+ Painter painter(*this);
painter.add_clip_rect(widget_inner_rect());
painter.add_clip_rect(event.rect());
@@ -153,9 +154,9 @@ void GlyphMapWidget::paint_event(GUI::PaintEvent& event)
painter.draw_focus_rect(get_outer_rect(m_active_glyph), Gfx::Color::Black);
}
-void GlyphMapWidget::mousedown_event(GUI::MouseEvent& event)
+void GlyphMapWidget::mousedown_event(MouseEvent& event)
{
- GUI::Frame::mousedown_event(event);
+ Frame::mousedown_event(event);
Gfx::IntPoint map_offset { frame_thickness() - horizontal_scrollbar().value(), frame_thickness() - vertical_scrollbar().value() };
auto map_position = event.position() - map_offset;
@@ -173,9 +174,9 @@ void GlyphMapWidget::mousedown_event(GUI::MouseEvent& event)
}
}
-void GlyphMapWidget::keydown_event(GUI::KeyEvent& event)
+void GlyphMapWidget::keydown_event(KeyEvent& event)
{
- GUI::Frame::keydown_event(event);
+ Frame::keydown_event(event);
if (!event.ctrl() && !event.shift()) {
m_selection.set_size(1);
@@ -263,3 +264,5 @@ void GlyphMapWidget::scroll_to_glyph(int glyph)
};
scroll_into_view(scroll_rect, true, true);
}
+
+}
diff --git a/Userland/Applications/FontEditor/GlyphMapWidget.h b/Userland/Libraries/LibGUI/GlyphMapWidget.h
index d6bfc5fcc7..dbc25e08ec 100644
--- a/Userland/Applications/FontEditor/GlyphMapWidget.h
+++ b/Userland/Libraries/LibGUI/GlyphMapWidget.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -11,7 +12,9 @@
#include <LibGUI/TextRange.h>
#include <LibGfx/BitmapFont.h>
-class GlyphMapWidget final : public GUI::AbstractScrollableWidget {
+namespace GUI {
+
+class GlyphMapWidget final : public AbstractScrollableWidget {
C_OBJECT(GlyphMapWidget)
public:
virtual ~GlyphMapWidget() override;
@@ -65,10 +68,10 @@ public:
private:
GlyphMapWidget();
- virtual void paint_event(GUI::PaintEvent&) override;
- virtual void mousedown_event(GUI::MouseEvent&) override;
- virtual void keydown_event(GUI::KeyEvent&) override;
- virtual void resize_event(GUI::ResizeEvent&) override;
+ virtual void paint_event(PaintEvent&) override;
+ virtual void mousedown_event(MouseEvent&) override;
+ virtual void keydown_event(KeyEvent&) override;
+ virtual void resize_event(ResizeEvent&) override;
Gfx::IntRect get_outer_rect(int glyph) const;
@@ -87,3 +90,5 @@ private:
int m_active_glyph { 0 };
int m_visible_glyphs { 0 };
};
+
+}