Debian Codegraph @

scene/3d/label_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* label_3d.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 #pragma once
32
33 #include "scene/3d/visual_instance_3d.h"
34 #include "scene/resources/font.h"
35
36 #include "servers/text/text_server.h"
37
38 class Label3D : public GeometryInstance3D {
39 GDCLASS(Label3D, GeometryInstance3D);
40
41 public:
42 enum DrawFlags {
43 FLAG_SHADED,
44 FLAG_DOUBLE_SIDED,
45 FLAG_DISABLE_DEPTH_TEST,
46 FLAG_FIXED_SIZE,
47 FLAG_MAX
48 };
49
50 enum AlphaCutMode {
51 ALPHA_CUT_DISABLED,
52 ALPHA_CUT_DISCARD,
53 ALPHA_CUT_OPAQUE_PREPASS,
54 ALPHA_CUT_HASH,
55 ALPHA_CUT_MAX
56 };
57
58 private:
59 real_t pixel_size = 0.005;
60 bool flags[FLAG_MAX] = {};
61 AlphaCutMode alpha_cut = ALPHA_CUT_DISABLED;
62 float alpha_scissor_threshold = 0.5;
63 float alpha_hash_scale = 1.0;
64 StandardMaterial3D::AlphaAntiAliasing alpha_antialiasing_mode = StandardMaterial3D::ALPHA_ANTIALIASING_OFF;
65 float alpha_antialiasing_edge = 0.0f;
66
67 AABB aabb;
68
69 mutable Ref<TriangleMesh> triangle_mesh;
70 RID mesh;
71 struct SurfaceData {
72 PackedVector3Array mesh_vertices;
73 PackedVector3Array mesh_normals;
74 PackedFloat32Array mesh_tangents;
75 PackedColorArray mesh_colors;
76 PackedVector2Array mesh_uvs;
77 PackedInt32Array indices;
78 int offset = 0;
79 float z_shift = 0.0;
80 RID material;
81 };
82
83 struct SurfaceKey {
84 uint64_t texture_id;
85 int32_t priority;
86 int32_t outline_size;
87
88 bool operator==(const SurfaceKey &p_b) const {
89 return (texture_id == p_b.texture_id) && (priority == p_b.priority) && (outline_size == p_b.outline_size);
90 }
91
92 SurfaceKey(uint64_t p_texture_id, int p_priority, int p_outline_size) {
93 texture_id = p_texture_id;
94 priority = p_priority;
95 outline_size = p_outline_size;
96 }
97 };
98
99 struct SurfaceKeyHasher {
100 _FORCE_INLINE_ static uint32_t hash(const SurfaceKey &p_a) {
101 return hash_murmur3_buffer(&p_a, sizeof(SurfaceKey));
102 }
103 };
104
105 HashMap<SurfaceKey, SurfaceData, SurfaceKeyHasher> surfaces;
106
107 HorizontalAlignment horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER;
108 VerticalAlignment vertical_alignment = VERTICAL_ALIGNMENT_CENTER;
109 String text;
110 String xl_text;
111 bool uppercase = false;
112
113 TextServer::AutowrapMode autowrap_mode = TextServer::AUTOWRAP_OFF;
114 BitField<TextServer::LineBreakFlag> autowrap_flags_trim = TextServer::BREAK_TRIM_START_EDGE_SPACES | TextServer::BREAK_TRIM_END_EDGE_SPACES;
115 BitField<TextServer::JustificationFlag> jst_flags = TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_SKIP_LAST_LINE | TextServer::JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE;
116 float width = 500.0;
117
118 int font_size = 32;
119 Ref<Font> font_override;
120 mutable Ref<Font> theme_font;
121 Color modulate = Color(1, 1, 1, 1);
122 Point2 lbl_offset;
123 int outline_render_priority = -1;
124 int render_priority = 0;
125
126 int outline_size = 12;
127 Color outline_modulate = Color(0, 0, 0, 1);
128
129 float line_spacing = 0.f;
130
131 String language;
132 TextServer::Direction text_direction = TextServer::DIRECTION_AUTO;
133 TextServer::StructuredTextParser st_parser = TextServer::STRUCTURED_TEXT_DEFAULT;
134 Array st_args;
135
136 RID text_rid;
137 Vector<RID> lines_rid;
138
139 StandardMaterial3D::BillboardMode billboard_mode = StandardMaterial3D::BILLBOARD_DISABLED;
140 StandardMaterial3D::TextureFilter texture_filter = StandardMaterial3D::TEXTURE_FILTER_LINEAR_WITH_MIPMAPS;
141
142 bool pending_update = false;
143
144 bool dirty_lines = true;
145 bool dirty_font = true;
146 bool dirty_text = true;
147
148 void _generate_glyph_surfaces(const Glyph &p_glyph, Vector2 &r_offset, const Color &p_modulate, int p_priority = 0, int p_outline_size = 0);
149
150 protected:
151 GDVIRTUAL2RC(TypedArray<Vector3i>, _structured_text_parser, Array, String)
152
153 void _notification(int p_what);
154
155 static void _bind_methods();
156
157 void _validate_property(PropertyInfo &p_property) const;
158
159 void _im_update();
160 void _font_changed();
161 void _queue_update();
162
163 void _shape();
164
165 public:
166 void set_horizontal_alignment(HorizontalAlignment p_alignment);
167 HorizontalAlignment get_horizontal_alignment() const;
168
169 void set_vertical_alignment(VerticalAlignment p_alignment);
170 VerticalAlignment get_vertical_alignment() const;
171
172 void set_render_priority(int p_priority);
173 int get_render_priority() const;
174
175 void set_outline_render_priority(int p_priority);
176 int get_outline_render_priority() const;
177
178 void set_text(const String &p_string);
179 String get_text() const;
180
181 void set_text_direction(TextServer::Direction p_text_direction);
182 TextServer::Direction get_text_direction() const;
183
184 void set_language(const String &p_language);
185 String get_language() const;
186
187 void set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser);
188 TextServer::StructuredTextParser get_structured_text_bidi_override() const;
189
190 void set_structured_text_bidi_override_options(const Array &p_args);
191 Array get_structured_text_bidi_override_options() const;
192
193 void set_uppercase(bool p_uppercase);
194 bool is_uppercase() const;
195
196 void set_font(const Ref<Font> &p_font);
197 Ref<Font> get_font() const;
198 Ref<Font> _get_font_or_default() const;
199
200 void set_font_size(int p_size);
201 int get_font_size() const;
202
203 void set_outline_size(int p_size);
204 int get_outline_size() const;
205
206 void set_line_spacing(float p_size);
207 float get_line_spacing() const;
208
209 void set_modulate(const Color &p_color);
210 Color get_modulate() const;
211
212 void set_outline_modulate(const Color &p_color);
213 Color get_outline_modulate() const;
214
215 void set_autowrap_mode(TextServer::AutowrapMode p_mode);
216 TextServer::AutowrapMode get_autowrap_mode() const;
217
218 void set_autowrap_trim_flags(BitField<TextServer::LineBreakFlag> p_flags);
219 BitField<TextServer::LineBreakFlag> get_autowrap_trim_flags() const;
220
221 void set_justification_flags(BitField<TextServer::JustificationFlag> p_flags);
222 BitField<TextServer::JustificationFlag> get_justification_flags() const;
223
224 void set_width(float p_width);
225 float get_width() const;
226
227 void set_pixel_size(real_t p_amount);
228 real_t get_pixel_size() const;
229
230 void set_offset(const Point2 &p_offset);
231 Point2 get_offset() const;
232
233 void set_draw_flag(DrawFlags p_flag, bool p_enable);
234 bool get_draw_flag(DrawFlags p_flag) const;
235
236 void set_alpha_cut_mode(AlphaCutMode p_mode);
237 AlphaCutMode get_alpha_cut_mode() const;
238
239 void set_alpha_scissor_threshold(float p_threshold);
240 float get_alpha_scissor_threshold() const;
241
242 void set_alpha_hash_scale(float p_hash_scale);
243 float get_alpha_hash_scale() const;
244
245 void set_alpha_antialiasing(BaseMaterial3D::AlphaAntiAliasing p_alpha_aa);
246 BaseMaterial3D::AlphaAntiAliasing get_alpha_antialiasing() const;
247
248 void set_alpha_antialiasing_edge(float p_edge);
249 float get_alpha_antialiasing_edge() const;
250
251 void set_billboard_mode(StandardMaterial3D::BillboardMode p_mode);
252 StandardMaterial3D::BillboardMode get_billboard_mode() const;
253
254 void set_texture_filter(StandardMaterial3D::TextureFilter p_filter);
255 StandardMaterial3D::TextureFilter get_texture_filter() const;
256
257 virtual AABB get_aabb() const override;
258 virtual Ref<TriangleMesh> generate_triangle_mesh() const override;
259
260 Label3D();
261 ~Label3D();
262 };
263
264 VARIANT_ENUM_CAST(Label3D::DrawFlags);
265 VARIANT_ENUM_CAST(Label3D::AlphaCutMode);