mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:37:43 +00:00
LibGUI+FontEditor: Move GlyphMapWidget to LibGUI
This will allow us to use this in other apps, such as the upcoming Character Map. :^)
This commit is contained in:
parent
dd17df76e9
commit
8175cd0a28
6 changed files with 28 additions and 21 deletions
|
@ -13,7 +13,6 @@ set(SOURCES
|
|||
FontEditor.cpp
|
||||
FontEditorWindowGML.h
|
||||
GlyphEditorWidget.cpp
|
||||
GlyphMapWidget.cpp
|
||||
main.cpp
|
||||
NewFontDialog.cpp
|
||||
NewFontDialogPage1GML.h
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -42,6 +42,7 @@ set(SOURCES
|
|||
FontPicker.cpp
|
||||
FontPickerDialogGML.h
|
||||
Frame.cpp
|
||||
GlyphMapWidget.cpp
|
||||
GMLAutocompleteProvider.cpp
|
||||
GMLFormatter.cpp
|
||||
GMLLexer.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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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 };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue