2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-04-03 16:23:13 +03:00
|
|
|
#pragma once
|
|
|
|
|
2022-01-04 20:24:06 +03:00
|
|
|
#include <AK/Vector.h>
|
2021-05-03 21:31:58 +03:00
|
|
|
#include <LibGUI/AbstractScrollableWidget.h>
|
2022-01-04 20:24:06 +03:00
|
|
|
#include <LibGUI/TextRange.h>
|
2020-12-31 16:01:59 +03:00
|
|
|
#include <LibGfx/BitmapFont.h>
|
2019-04-03 16:23:13 +03:00
|
|
|
|
2021-05-03 21:31:58 +03:00
|
|
|
class GlyphMapWidget final : public GUI::AbstractScrollableWidget {
|
2019-09-21 20:39:37 +03:00
|
|
|
C_OBJECT(GlyphMapWidget)
|
2019-04-03 16:23:13 +03:00
|
|
|
public:
|
|
|
|
virtual ~GlyphMapWidget() override;
|
|
|
|
|
2021-04-06 18:58:08 +03:00
|
|
|
void initialize(Gfx::BitmapFont&);
|
|
|
|
|
2022-01-04 20: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
|
|
|
|
};
|
|
|
|
|
|
|
|
void set_active_glyph(int, ShouldResetSelection = ShouldResetSelection::Yes);
|
|
|
|
void clear_selection() { m_selection.set_size(0); }
|
2021-11-29 18:52:50 +03:00
|
|
|
void scroll_to_glyph(int);
|
|
|
|
void update_glyph(int);
|
2019-04-03 16:23:13 +03:00
|
|
|
|
2021-04-06 18:58:08 +03:00
|
|
|
int rows() const { return m_rows; }
|
2020-02-23 14:14:02 +03:00
|
|
|
int columns() const { return m_columns; }
|
2019-04-03 16:23:13 +03:00
|
|
|
|
2020-12-31 16:01:59 +03:00
|
|
|
Gfx::BitmapFont& font() { return *m_font; }
|
2021-11-29 20:06:10 +03:00
|
|
|
Gfx::BitmapFont const& font() const { return *m_font; }
|
2019-04-03 16:23:13 +03:00
|
|
|
|
2022-01-04 20:24:06 +03:00
|
|
|
Function<void(int)> on_active_glyph_changed;
|
2019-04-03 16:23:13 +03:00
|
|
|
|
|
|
|
private:
|
2021-04-06 18:58:08 +03:00
|
|
|
GlyphMapWidget();
|
2020-02-02 17:07:41 +03:00
|
|
|
virtual void paint_event(GUI::PaintEvent&) override;
|
|
|
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
2020-02-23 14:14:02 +03:00
|
|
|
virtual void keydown_event(GUI::KeyEvent&) override;
|
2021-04-06 18:58:08 +03:00
|
|
|
virtual void resize_event(GUI::ResizeEvent&) override;
|
2019-04-03 16:23:13 +03:00
|
|
|
|
2020-06-10 11:57:59 +03:00
|
|
|
Gfx::IntRect get_outer_rect(int glyph) const;
|
2019-04-03 16:23:13 +03:00
|
|
|
|
2022-01-04 20:24:06 +03:00
|
|
|
void cut_glyph(int glyph);
|
|
|
|
void copy_glyph(int glyph);
|
|
|
|
void paste_glyph(int glyph);
|
|
|
|
void delete_glyph(int glyph);
|
|
|
|
|
2020-12-31 16:01:59 +03:00
|
|
|
RefPtr<Gfx::BitmapFont> m_font;
|
2021-09-09 14:41:08 +03:00
|
|
|
int m_glyph_count { 0x110000 };
|
2021-11-29 18:52:50 +03:00
|
|
|
int m_columns { 0 };
|
|
|
|
int m_rows { 0 };
|
2019-04-03 16:23:13 +03:00
|
|
|
int m_horizontal_spacing { 2 };
|
|
|
|
int m_vertical_spacing { 2 };
|
2022-01-04 20:24:06 +03:00
|
|
|
Selection m_selection;
|
|
|
|
int m_active_glyph { 0 };
|
2021-09-09 14:41:08 +03:00
|
|
|
int m_visible_glyphs { 0 };
|
2019-04-03 16:23:13 +03:00
|
|
|
};
|