/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include "Drawable.hpp" #include "Texture.hpp" #include "VertexBuffer.hpp" #include "Text/FontAtlas.hpp" namespace OpenVulkano::Scene { class FontAtlas; class IFontAtlasGenerator; struct TextConfig { Math::Vector4uc textColor = { 255, 255, 255, 255 }; Math::Vector4uc backgroundColor = { 0, 255, 0, 0 }; bool minimalSpacingBetweenMultipleLines = true; }; struct TextGlyphVertex { std::array position; std::array uv; Math::Vector4uc color = { 255, 255, 255, 255 }; Math::Vector4uc background = {}; }; class TextDrawable : public Drawable { VertexBuffer m_vertexBuffer; std::shared_ptr m_atlasData; Math::AABB2f m_bbox; std::string m_text; size_t m_symbolCount = 0; TextConfig m_cfg; uint32_t GetFallbackGlyph() const; float GetHeightBetweenLines(const std::string& text) const; bool IsSpecialCharacter(uint32_t c) const; public: TextDrawable(const TextConfig& config = TextConfig()); TextDrawable(const std::shared_ptr& atlasData, const TextConfig& config = TextConfig()); void GenerateText(const std::string& text, const Math::Vector2f& pos = Math::Vector2f(0.f), float scale = 1.0f); void SetConfig(const TextConfig& cfg) { m_cfg = cfg; } void SetAtlasData(const std::shared_ptr& atlasData); [[nodiscard]] Math::AABB2f& GetBoundingBox() { return m_bbox; } [[nodiscard]] TextConfig& GetConfig() { return m_cfg; } [[nodiscard]] const std::string& GetText() const { return m_text; } [[nodiscard]] const std::shared_ptr& GetAtlasData() { return m_atlasData; } [[nodiscard]] VertexBuffer* GetVertexBuffer() { return &m_vertexBuffer; } [[nodiscard]] Texture* GetTexture() const { return m_atlasData->GetTexture(); } [[nodiscard]] size_t GetSymbolCount() const { return m_symbolCount; } [[nodiscard]] static Shader MakeDefaultShader(FontAtlasType type); [[nodiscard]] static Shader* GetDefaultShader(FontAtlasType type); }; }