Serenity Operating System
at hosted 69 lines 2.6 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#pragma once 28 29#include <AK/Function.h> 30#include <AK/StdLibExtras.h> 31#include <LibGUI/Frame.h> 32 33class GlyphMapWidget final : public GUI::Frame { 34 C_OBJECT(GlyphMapWidget) 35public: 36 virtual ~GlyphMapWidget() override; 37 38 u8 selected_glyph() const { return m_selected_glyph; } 39 void set_selected_glyph(u8); 40 41 int rows() const { return ceil_div(m_glyph_count, m_columns); } 42 int columns() const { return m_columns; } 43 44 int preferred_width() const; 45 int preferred_height() const; 46 47 Gfx::Font& font() { return *m_font; } 48 const Gfx::Font& font() const { return *m_font; } 49 50 void update_glyph(u8); 51 52 Function<void(u8)> on_glyph_selected; 53 54private: 55 explicit GlyphMapWidget(Gfx::Font&); 56 virtual bool accepts_focus() const override { return true; } 57 virtual void paint_event(GUI::PaintEvent&) override; 58 virtual void mousedown_event(GUI::MouseEvent&) override; 59 virtual void keydown_event(GUI::KeyEvent&) override; 60 61 Gfx::Rect get_outer_rect(u8 glyph) const; 62 63 RefPtr<Gfx::Font> m_font; 64 int m_glyph_count { 256 }; 65 int m_columns { 32 }; 66 int m_horizontal_spacing { 2 }; 67 int m_vertical_spacing { 2 }; 68 u8 m_selected_glyph { 0 }; 69};