GlyphMapWidget.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Vector.h>
  9. #include <LibGUI/AbstractScrollableWidget.h>
  10. #include <LibGUI/TextRange.h>
  11. #include <LibGfx/BitmapFont.h>
  12. namespace GUI {
  13. class GlyphMapWidget final : public AbstractScrollableWidget {
  14. C_OBJECT(GlyphMapWidget)
  15. public:
  16. virtual ~GlyphMapWidget() override;
  17. class Selection {
  18. public:
  19. Selection() = default;
  20. Selection(int start, int size)
  21. : m_start(start)
  22. , m_size(size)
  23. {
  24. }
  25. int size() const { return m_size; }
  26. void set_size(int i) { m_size = i; }
  27. int start() const { return m_start; }
  28. void set_start(int i) { m_start = i; }
  29. Selection normalized() const;
  30. bool contains(int) const;
  31. void resize_by(int i);
  32. void extend_to(int);
  33. private:
  34. int m_start { 0 };
  35. int m_size { 1 };
  36. };
  37. Selection selection() const { return m_selection; }
  38. int active_glyph() const { return m_active_glyph; }
  39. enum class ShouldResetSelection {
  40. Yes,
  41. No
  42. };
  43. void set_active_glyph(int, ShouldResetSelection = ShouldResetSelection::Yes);
  44. void clear_selection() { m_selection.set_size(0); }
  45. void scroll_to_glyph(int);
  46. void update_glyph(int);
  47. int rows() const { return m_rows; }
  48. int columns() const { return m_columns; }
  49. Function<void(int)> on_active_glyph_changed;
  50. private:
  51. GlyphMapWidget();
  52. virtual void paint_event(PaintEvent&) override;
  53. virtual void mousedown_event(MouseEvent&) override;
  54. virtual void keydown_event(KeyEvent&) override;
  55. virtual void resize_event(ResizeEvent&) override;
  56. virtual void did_change_font() override;
  57. Gfx::IntRect get_outer_rect(int glyph) const;
  58. void cut_glyph(int glyph);
  59. void copy_glyph(int glyph);
  60. void paste_glyph(int glyph);
  61. void delete_glyph(int glyph);
  62. int m_glyph_count { 0x110000 };
  63. int m_columns { 0 };
  64. int m_rows { 0 };
  65. int m_horizontal_spacing { 2 };
  66. int m_vertical_spacing { 2 };
  67. Selection m_selection;
  68. int m_active_glyph { 0 };
  69. int m_visible_glyphs { 0 };
  70. };
  71. }