1/**************************************************************************/
2/* text_line.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef TEXT_LINE_H
32#define TEXT_LINE_H
33
34#include "scene/resources/font.h"
35#include "servers/text_server.h"
36
37/*************************************************************************/
38
39class TextLine : public RefCounted {
40 GDCLASS(TextLine, RefCounted);
41
42private:
43 RID rid;
44
45 bool dirty = true;
46
47 float width = -1.0;
48 BitField<TextServer::JustificationFlag> flags = TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA;
49 HorizontalAlignment alignment = HORIZONTAL_ALIGNMENT_LEFT;
50 TextServer::OverrunBehavior overrun_behavior = TextServer::OVERRUN_TRIM_ELLIPSIS;
51
52 Vector<float> tab_stops;
53
54protected:
55 static void _bind_methods();
56
57 void _shape();
58
59public:
60 RID get_rid() const;
61
62 void clear();
63
64 void set_direction(TextServer::Direction p_direction);
65 TextServer::Direction get_direction() const;
66
67 void set_bidi_override(const Array &p_override);
68
69 void set_orientation(TextServer::Orientation p_orientation);
70 TextServer::Orientation get_orientation() const;
71
72 void set_preserve_invalid(bool p_enabled);
73 bool get_preserve_invalid() const;
74
75 void set_preserve_control(bool p_enabled);
76 bool get_preserve_control() const;
77
78 bool add_string(const String &p_text, const Ref<Font> &p_font, int p_font_size, const String &p_language = "", const Variant &p_meta = Variant());
79 bool add_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, int p_length = 1, float p_baseline = 0.0);
80 bool resize_object(Variant p_key, const Size2 &p_size, InlineAlignment p_inline_align = INLINE_ALIGNMENT_CENTER, float p_baseline = 0.0);
81
82 void set_horizontal_alignment(HorizontalAlignment p_alignment);
83 HorizontalAlignment get_horizontal_alignment() const;
84
85 void tab_align(const Vector<float> &p_tab_stops);
86
87 void set_flags(BitField<TextServer::JustificationFlag> p_flags);
88 BitField<TextServer::JustificationFlag> get_flags() const;
89
90 void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior);
91 TextServer::OverrunBehavior get_text_overrun_behavior() const;
92
93 void set_width(float p_width);
94 float get_width() const;
95
96 Array get_objects() const;
97 Rect2 get_object_rect(Variant p_key) const;
98
99 Size2 get_size() const;
100
101 float get_line_ascent() const;
102 float get_line_descent() const;
103 float get_line_width() const;
104 float get_line_underline_position() const;
105 float get_line_underline_thickness() const;
106
107 void draw(RID p_canvas, const Vector2 &p_pos, const Color &p_color = Color(1, 1, 1)) const;
108 void draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outline_size = 1, const Color &p_color = Color(1, 1, 1)) const;
109
110 int hit_test(float p_coords) const;
111
112 TextLine(const String &p_text, const Ref<Font> &p_font, int p_font_size, const String &p_language = "", TextServer::Direction p_direction = TextServer::DIRECTION_AUTO, TextServer::Orientation p_orientation = TextServer::ORIENTATION_HORIZONTAL);
113 TextLine();
114 ~TextLine();
115};
116
117#endif // TEXT_LINE_H
118