| 1 | /** | 
|---|
| 2 | * Copyright (c) 2006-2023 LOVE Development Team | 
|---|
| 3 | * | 
|---|
| 4 | * This software is provided 'as-is', without any express or implied | 
|---|
| 5 | * warranty.  In no event will the authors be held liable for any damages | 
|---|
| 6 | * arising from the use of this software. | 
|---|
| 7 | * | 
|---|
| 8 | * Permission is granted to anyone to use this software for any purpose, | 
|---|
| 9 | * including commercial applications, and to alter it and redistribute it | 
|---|
| 10 | * freely, subject to the following restrictions: | 
|---|
| 11 | * | 
|---|
| 12 | * 1. The origin of this software must not be misrepresented; you must not | 
|---|
| 13 | *    claim that you wrote the original software. If you use this software | 
|---|
| 14 | *    in a product, an acknowledgment in the product documentation would be | 
|---|
| 15 | *    appreciated but is not required. | 
|---|
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be | 
|---|
| 17 | *    misrepresented as being the original software. | 
|---|
| 18 | * 3. This notice may not be removed or altered from any source distribution. | 
|---|
| 19 | **/ | 
|---|
| 20 |  | 
|---|
| 21 | #pragma once | 
|---|
| 22 |  | 
|---|
| 23 | // LOVE | 
|---|
| 24 | #include "common/config.h" | 
|---|
| 25 | #include "Drawable.h" | 
|---|
| 26 | #include "Font.h" | 
|---|
| 27 | #include "Buffer.h" | 
|---|
| 28 |  | 
|---|
| 29 | namespace love | 
|---|
| 30 | { | 
|---|
| 31 | namespace graphics | 
|---|
| 32 | { | 
|---|
| 33 |  | 
|---|
| 34 | class Graphics; | 
|---|
| 35 |  | 
|---|
| 36 | class Text : public Drawable | 
|---|
| 37 | { | 
|---|
| 38 | public: | 
|---|
| 39 |  | 
|---|
| 40 | static love::Type type; | 
|---|
| 41 |  | 
|---|
| 42 | Text(Font *font, const std::vector<Font::ColoredString> &text = {}); | 
|---|
| 43 | virtual ~Text(); | 
|---|
| 44 |  | 
|---|
| 45 | void set(const std::vector<Font::ColoredString> &text); | 
|---|
| 46 | void set(const std::vector<Font::ColoredString> &text, float wrap, Font::AlignMode align); | 
|---|
| 47 |  | 
|---|
| 48 | int add(const std::vector<Font::ColoredString> &text, const Matrix4 &m); | 
|---|
| 49 | int addf(const std::vector<Font::ColoredString> &text, float wrap, Font::AlignMode align, const Matrix4 &m); | 
|---|
| 50 |  | 
|---|
| 51 | void clear(); | 
|---|
| 52 |  | 
|---|
| 53 | void setFont(Font *f); | 
|---|
| 54 | Font *getFont() const; | 
|---|
| 55 |  | 
|---|
| 56 | /** | 
|---|
| 57 | * Gets the width of the currently set text. | 
|---|
| 58 | **/ | 
|---|
| 59 | int getWidth(int index = 0) const; | 
|---|
| 60 |  | 
|---|
| 61 | /** | 
|---|
| 62 | * Gets the height of the currently set text. | 
|---|
| 63 | **/ | 
|---|
| 64 | int getHeight(int index = 0) const; | 
|---|
| 65 |  | 
|---|
| 66 | // Implements Drawable. | 
|---|
| 67 | void draw(love::graphics::Graphics *gfx, const Matrix4 &m) override; | 
|---|
| 68 |  | 
|---|
| 69 | private: | 
|---|
| 70 |  | 
|---|
| 71 | struct TextData | 
|---|
| 72 | { | 
|---|
| 73 | Font::ColoredCodepoints codepoints; | 
|---|
| 74 | float wrap; | 
|---|
| 75 | Font::AlignMode align; | 
|---|
| 76 | Font::TextInfo text_info; | 
|---|
| 77 | bool use_matrix; | 
|---|
| 78 | bool append_vertices; | 
|---|
| 79 | Matrix4 matrix; | 
|---|
| 80 | }; | 
|---|
| 81 |  | 
|---|
| 82 | void uploadVertices(const std::vector<Font::GlyphVertex> &vertices, size_t vertoffset); | 
|---|
| 83 | void regenerateVertices(); | 
|---|
| 84 | void addTextData(const TextData &s); | 
|---|
| 85 |  | 
|---|
| 86 | StrongRef<Font> font; | 
|---|
| 87 |  | 
|---|
| 88 | vertex::Attributes vertexAttributes; | 
|---|
| 89 | vertex::BufferBindings vertexBuffers; | 
|---|
| 90 |  | 
|---|
| 91 | Buffer *vertex_buffer; | 
|---|
| 92 |  | 
|---|
| 93 | std::vector<Font::DrawCommand> draw_commands; | 
|---|
| 94 |  | 
|---|
| 95 | std::vector<TextData> text_data; | 
|---|
| 96 |  | 
|---|
| 97 | size_t vert_offset; | 
|---|
| 98 |  | 
|---|
| 99 | // Used so we know when the font's texture cache is invalidated. | 
|---|
| 100 | uint32 texture_cache_id; | 
|---|
| 101 |  | 
|---|
| 102 | }; // Text | 
|---|
| 103 |  | 
|---|
| 104 | } // graphics | 
|---|
| 105 | } // love | 
|---|
| 106 |  | 
|---|