2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-01-09 13:15:23 -03:00
|
|
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
2022-02-26 14:50:04 -03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-04-03 10:23:13 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-03-19 11:44:44 -03:00
|
|
|
#include <LibCore/Timer.h>
|
2021-05-03 15:31:58 -03:00
|
|
|
#include <LibGUI/AbstractScrollableWidget.h>
|
2022-01-04 14:24:06 -03:00
|
|
|
#include <LibGUI/TextRange.h>
|
2022-04-09 04:28:38 -03:00
|
|
|
#include <LibGfx/Font/BitmapFont.h>
|
2022-02-13 15:46:45 -03:00
|
|
|
#include <LibUnicode/CharacterTypes.h>
|
2019-04-03 10:23:13 -03:00
|
|
|
|
2022-01-09 13:15:23 -03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
|
|
class GlyphMapWidget final : public AbstractScrollableWidget {
|
2019-09-21 14:39:37 -03:00
|
|
|
C_OBJECT(GlyphMapWidget)
|
2019-04-03 10:23:13 -03:00
|
|
|
public:
|
2022-02-26 14:50:04 -03:00
|
|
|
virtual ~GlyphMapWidget() override = default;
|
2019-04-03 10:23:13 -03:00
|
|
|
|
2022-07-27 12:46:21 -03:00
|
|
|
void set_font(Gfx::Font const&);
|
|
|
|
|
|
2022-01-04 14:24:06 -03:00
|
|
|
class Selection {
|
|
|
|
|
public:
|
|
|
|
|
Selection() = default;
|
|
|
|
|
Selection(int start, int size)
|
|
|
|
|
: m_start(start)
|
|
|
|
|
, m_size(size)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int size() const { return m_size; }
|
|
|
|
|
void set_size(int i) { m_size = i; }
|
|
|
|
|
int start() const { return m_start; }
|
|
|
|
|
void set_start(int i) { m_start = i; }
|
|
|
|
|
|
|
|
|
|
Selection normalized() const;
|
|
|
|
|
bool contains(int) const;
|
|
|
|
|
void resize_by(int i);
|
|
|
|
|
void extend_to(int);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_start { 0 };
|
|
|
|
|
int m_size { 1 };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Selection selection() const { return m_selection; }
|
|
|
|
|
int active_glyph() const { return m_active_glyph; }
|
|
|
|
|
|
|
|
|
|
enum class ShouldResetSelection {
|
|
|
|
|
Yes,
|
|
|
|
|
No
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-13 15:46:45 -03:00
|
|
|
void set_active_range(Unicode::CodePointRange);
|
2022-01-04 14:24:06 -03:00
|
|
|
void set_active_glyph(int, ShouldResetSelection = ShouldResetSelection::Yes);
|
2022-03-18 21:34:58 -03:00
|
|
|
void set_selection(int start, int size, Optional<u32> active_glyph = {});
|
2022-01-04 14:24:06 -03:00
|
|
|
void clear_selection() { m_selection.set_size(0); }
|
2021-11-29 12:52:50 -03:00
|
|
|
void scroll_to_glyph(int);
|
|
|
|
|
void update_glyph(int);
|
2019-04-03 10:23:13 -03:00
|
|
|
|
2022-07-27 12:46:21 -03:00
|
|
|
void set_highlight_modifications(bool);
|
|
|
|
|
void set_glyph_modified(u32 glyph, bool modified);
|
|
|
|
|
bool glyph_is_modified(u32 glyph);
|
|
|
|
|
|
2022-01-11 17:50:59 -03:00
|
|
|
void select_previous_existing_glyph();
|
|
|
|
|
void select_next_existing_glyph();
|
|
|
|
|
|
2021-04-06 12:58:08 -03:00
|
|
|
int rows() const { return m_rows; }
|
2020-02-23 08:14:02 -03:00
|
|
|
int columns() const { return m_columns; }
|
2019-04-03 10:23:13 -03:00
|
|
|
|
2022-01-04 14:24:06 -03:00
|
|
|
Function<void(int)> on_active_glyph_changed;
|
2022-01-11 17:10:32 -03:00
|
|
|
Function<void(int)> on_glyph_double_clicked;
|
2022-03-19 14:29:55 -03:00
|
|
|
Function<void(ContextMenuEvent&)> on_context_menu_request;
|
2019-04-03 10:23:13 -03:00
|
|
|
|
|
|
|
|
private:
|
2021-04-06 12:58:08 -03:00
|
|
|
GlyphMapWidget();
|
2022-01-09 13:15:23 -03:00
|
|
|
virtual void paint_event(PaintEvent&) override;
|
|
|
|
|
virtual void mousedown_event(MouseEvent&) override;
|
2022-01-09 15:15:02 -03:00
|
|
|
virtual void mouseup_event(GUI::MouseEvent&) override;
|
|
|
|
|
virtual void mousemove_event(GUI::MouseEvent&) override;
|
2022-01-11 17:10:32 -03:00
|
|
|
virtual void doubleclick_event(MouseEvent&) override;
|
2022-01-09 13:15:23 -03:00
|
|
|
virtual void keydown_event(KeyEvent&) override;
|
|
|
|
|
virtual void resize_event(ResizeEvent&) override;
|
2022-01-09 14:29:06 -03:00
|
|
|
virtual void did_change_font() override;
|
2022-03-19 14:29:55 -03:00
|
|
|
virtual void context_menu_event(ContextMenuEvent&) override;
|
2019-04-03 10:23:13 -03:00
|
|
|
|
2020-06-10 05:57:59 -03:00
|
|
|
Gfx::IntRect get_outer_rect(int glyph) const;
|
2022-01-11 17:10:32 -03:00
|
|
|
Optional<int> glyph_at_position(Gfx::IntPoint) const;
|
2022-03-01 17:17:57 -03:00
|
|
|
int glyph_at_position_clamped(Gfx::IntPoint) const;
|
2019-04-03 10:23:13 -03:00
|
|
|
|
2022-01-09 14:42:57 -03:00
|
|
|
void recalculate_content_size();
|
2022-01-04 14:24:06 -03:00
|
|
|
|
2022-07-27 12:46:21 -03:00
|
|
|
RefPtr<Gfx::Font> m_original_font;
|
2021-09-09 08:41:08 -03:00
|
|
|
int m_glyph_count { 0x110000 };
|
2021-11-29 12:52:50 -03:00
|
|
|
int m_columns { 0 };
|
|
|
|
|
int m_rows { 0 };
|
2019-04-03 10:23:13 -03:00
|
|
|
int m_horizontal_spacing { 2 };
|
|
|
|
|
int m_vertical_spacing { 2 };
|
2022-01-04 14:24:06 -03:00
|
|
|
Selection m_selection;
|
|
|
|
|
int m_active_glyph { 0 };
|
2021-09-09 08:41:08 -03:00
|
|
|
int m_visible_glyphs { 0 };
|
2022-01-09 15:15:02 -03:00
|
|
|
bool m_in_drag_select { false };
|
2022-07-27 12:46:21 -03:00
|
|
|
bool m_highlight_modifications { false };
|
|
|
|
|
HashTable<u32> m_modified_glyphs;
|
2022-02-13 15:46:45 -03:00
|
|
|
Unicode::CodePointRange m_active_range { 0x0000, 0x10FFFF };
|
2022-03-19 11:44:44 -03:00
|
|
|
RefPtr<Core::Timer> m_automatic_selection_scroll_timer;
|
|
|
|
|
Gfx::IntPoint m_last_mousemove_position;
|
2019-04-03 10:23:13 -03:00
|
|
|
};
|
2022-01-09 13:15:23 -03:00
|
|
|
|
|
|
|
|
}
|