diff options
Diffstat (limited to 'scene/resources')
-rw-r--r-- | scene/resources/environment.cpp | 2 | ||||
-rw-r--r-- | scene/resources/font.cpp | 105 | ||||
-rw-r--r-- | scene/resources/font.h | 16 | ||||
-rw-r--r-- | scene/resources/material.cpp | 6 | ||||
-rw-r--r-- | scene/resources/packed_scene.cpp | 10 | ||||
-rw-r--r-- | scene/resources/packed_scene.h | 1 | ||||
-rw-r--r-- | scene/resources/resource_format_text.cpp | 1 | ||||
-rw-r--r-- | scene/resources/sky_material.cpp | 2 | ||||
-rw-r--r-- | scene/resources/style_box.cpp | 10 | ||||
-rw-r--r-- | scene/resources/style_box.h | 1 | ||||
-rw-r--r-- | scene/resources/surface_tool.cpp | 2 | ||||
-rw-r--r-- | scene/resources/text_line.cpp | 24 | ||||
-rw-r--r-- | scene/resources/text_line.h | 2 | ||||
-rw-r--r-- | scene/resources/text_paragraph.cpp | 57 | ||||
-rw-r--r-- | scene/resources/text_paragraph.h | 2 | ||||
-rw-r--r-- | scene/resources/theme.cpp | 48 | ||||
-rw-r--r-- | scene/resources/theme.h | 8 |
17 files changed, 173 insertions, 124 deletions
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index 2ed5953b8f..1eb78a3679 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -591,7 +591,7 @@ void Environment::set_glow_level(int p_level, float p_intensity) { } float Environment::get_glow_level(int p_level) const { - ERR_FAIL_INDEX_V(p_level, RS::MAX_GLOW_LEVELS, false); + ERR_FAIL_INDEX_V(p_level, RS::MAX_GLOW_LEVELS, 0.0); return glow_levels[p_level]; } diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index da35137a09..7c17610df7 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -472,6 +472,32 @@ void Font::_data_changed() { bool Font::_set(const StringName &p_name, const Variant &p_value) { String str = p_name; +#ifndef DISABLE_DEPRECATED + if (str == "font_data") { // Compatibility, DynamicFont main data + Ref<FontData> fd = p_value; + if (fd.is_valid()) { + add_data(fd); + return true; + } + return false; + } else if (str.begins_with("fallback/")) { // Compatibility, DynamicFont fallback data + Ref<FontData> fd = p_value; + if (fd.is_valid()) { + add_data(fd); + return true; + } + return false; + } else if (str == "fallback") { // Compatibility, BitmapFont fallback + Ref<Font> f = p_value; + if (f.is_valid()) { + for (int i = 0; i < f->get_data_count(); i++) { + add_data(f->get_data(i)); + } + return true; + } + return false; + } +#endif /* DISABLE_DEPRECATED */ if (str.begins_with("data/")) { int idx = str.get_slicec('/', 1).to_int(); Ref<FontData> fd = p_value; @@ -595,41 +621,41 @@ Dictionary Font::get_feature_list() const { float Font::get_height(int p_size) const { float ret = 0.f; for (int i = 0; i < data.size(); i++) { - ret += data[i]->get_height(p_size); + ret = MAX(ret, data[i]->get_height(p_size)); } - return (ret / data.size()) + spacing_top + spacing_bottom; + return ret + spacing_top + spacing_bottom; } float Font::get_ascent(int p_size) const { float ret = 0.f; for (int i = 0; i < data.size(); i++) { - ret += data[i]->get_ascent(p_size); + ret = MAX(ret, data[i]->get_ascent(p_size)); } - return (ret / data.size()) + spacing_top; + return ret + spacing_top; } float Font::get_descent(int p_size) const { float ret = 0.f; for (int i = 0; i < data.size(); i++) { - ret += data[i]->get_descent(p_size); + ret = MAX(ret, data[i]->get_descent(p_size)); } - return (ret / data.size()) + spacing_bottom; + return ret + spacing_bottom; } float Font::get_underline_position(int p_size) const { float ret = 0.f; for (int i = 0; i < data.size(); i++) { - ret += data[i]->get_underline_position(p_size); + ret = MAX(ret, data[i]->get_underline_position(p_size)); } - return (ret / data.size()); + return ret; } float Font::get_underline_thickness(int p_size) const { float ret = 0.f; for (int i = 0; i < data.size(); i++) { - ret += data[i]->get_underline_thickness(p_size); + ret = MAX(ret, data[i]->get_underline_thickness(p_size)); } - return (ret / data.size()); + return ret; } int Font::get_spacing(int p_type) const { @@ -899,6 +925,23 @@ RES ResourceFormatLoaderFont::load(const String &p_path, const String &p_origina return dfont; } +void ResourceFormatLoaderFont::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { +#ifndef DISABLE_DEPRECATED + if (p_type == "DynacmicFontData") { + p_extensions->push_back("ttf"); + p_extensions->push_back("otf"); + p_extensions->push_back("woff"); + return; + } + if (p_type == "BitmapFont") { // BitmapFont (*.font, *fnt) is handled by ResourceFormatLoaderCompatFont + return; + } +#endif /* DISABLE_DEPRECATED */ + if (p_type == "" || handles_type(p_type)) { + get_recognized_extensions(p_extensions); + } +} + void ResourceFormatLoaderFont::get_recognized_extensions(List<String> *p_extensions) const { p_extensions->push_back("ttf"); p_extensions->push_back("otf"); @@ -918,3 +961,45 @@ String ResourceFormatLoaderFont::get_resource_type(const String &p_path) const { } return ""; } + +#ifndef DISABLE_DEPRECATED + +RES ResourceFormatLoaderCompatFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { + if (r_error) { + *r_error = ERR_FILE_CANT_OPEN; + } + + Ref<FontData> dfont; + dfont.instance(); + dfont->load_resource(p_path); + + Ref<Font> font; + font.instance(); + font->add_data(dfont); + + if (r_error) { + *r_error = OK; + } + + return font; +} + +void ResourceFormatLoaderCompatFont::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { + if (p_type == "BitmapFont") { + p_extensions->push_back("font"); + p_extensions->push_back("fnt"); + } +} + +void ResourceFormatLoaderCompatFont::get_recognized_extensions(List<String> *p_extensions) const { +} + +bool ResourceFormatLoaderCompatFont::handles_type(const String &p_type) const { + return (p_type == "Font"); +} + +String ResourceFormatLoaderCompatFont::get_resource_type(const String &p_path) const { + return ""; +} + +#endif /* DISABLE_DEPRECATED */ diff --git a/scene/resources/font.h b/scene/resources/font.h index 226979c4a0..bc82a6fabf 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -198,9 +198,23 @@ VARIANT_ENUM_CAST(Font::SpacingType); class ResourceFormatLoaderFont : public ResourceFormatLoader { public: virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; virtual bool handles_type(const String &p_type) const; virtual String get_resource_type(const String &p_path) const; }; -#endif +#ifndef DISABLE_DEPRECATED + +class ResourceFormatLoaderCompatFont : public ResourceFormatLoader { +public: + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); + virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual bool handles_type(const String &p_type) const; + virtual String get_resource_type(const String &p_path) const; +}; + +#endif /* DISABLE_DEPRECATED */ + +#endif /* FONT_H */ diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index 35c967ce27..6e08af23f5 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -2417,10 +2417,10 @@ void BaseMaterial3D::_bind_methods() { ADD_GROUP("Height", "heightmap_"); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "heightmap_enabled"), "set_feature", "get_feature", FEATURE_HEIGHT_MAPPING); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "heightmap_scale", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_heightmap_scale", "get_heightmap_scale"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "heightmap_scale", PROPERTY_HINT_RANGE, "-16,16,0.001"), "set_heightmap_scale", "get_heightmap_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "heightmap_deep_parallax"), "set_heightmap_deep_parallax", "is_heightmap_deep_parallax_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "heightmap_min_layers", PROPERTY_HINT_RANGE, "1,32,1"), "set_heightmap_deep_parallax_min_layers", "get_heightmap_deep_parallax_min_layers"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "heightmap_max_layers", PROPERTY_HINT_RANGE, "1,32,1"), "set_heightmap_deep_parallax_max_layers", "get_heightmap_deep_parallax_max_layers"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "heightmap_min_layers", PROPERTY_HINT_RANGE, "1,64,1"), "set_heightmap_deep_parallax_min_layers", "get_heightmap_deep_parallax_min_layers"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "heightmap_max_layers", PROPERTY_HINT_RANGE, "1,64,1"), "set_heightmap_deep_parallax_max_layers", "get_heightmap_deep_parallax_max_layers"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "heightmap_flip_tangent"), "set_heightmap_deep_parallax_flip_tangent", "get_heightmap_deep_parallax_flip_tangent"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "heightmap_flip_binormal"), "set_heightmap_deep_parallax_flip_binormal", "get_heightmap_deep_parallax_flip_binormal"); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "heightmap_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture", TEXTURE_HEIGHTMAP); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 5ce253f970..09674f3465 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -1481,16 +1481,6 @@ int SceneState::add_name(const StringName &p_name) { return names.size() - 1; } -int SceneState::find_name(const StringName &p_name) const { - for (int i = 0; i < names.size(); i++) { - if (names[i] == p_name) { - return i; - } - } - - return -1; -} - int SceneState::add_value(const Variant &p_value) { variants.push_back(p_value); return variants.size() - 1; diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index b8b3f84ecc..fce3891507 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -172,7 +172,6 @@ public: //build API int add_name(const StringName &p_name); - int find_name(const StringName &p_name) const; int add_value(const Variant &p_value); int add_node_path(const NodePath &p_path); int add_node(int p_parent, int p_owner, int p_type, int p_name, int p_instance, int p_index); diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index cf8be8fe15..58645dbe65 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -704,7 +704,6 @@ ResourceLoaderText::ResourceLoaderText() { resources_total = 0; resource_current = 0; - use_sub_threads = false; progress = nullptr; lines = false; diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp index 69e8e0b5bd..05bb13a1e0 100644 --- a/scene/resources/sky_material.cpp +++ b/scene/resources/sky_material.cpp @@ -568,7 +568,7 @@ PhysicalSkyMaterial::PhysicalSkyMaterial() { code += "\tCOLOR = pow(color, vec3(1.0 / (1.2 + (1.2 * sun_fade))));\n"; code += "\tCOLOR *= exposure;\n"; code += "\t// Make optional, eliminates banding\n"; - code += "\tCOLOR += (hash(EYEDIR * 1741.9782) * 0.08 - 0.04) * 0.008 * dither_strength;\n"; + code += "\tCOLOR += (hash(EYEDIR * 1741.9782) * 0.08 - 0.04) * 0.016 * dither_strength;\n"; code += "}\n"; shader = RS::get_singleton()->shader_create(); diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index a8bf44c5c0..14197c6c68 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -404,16 +404,6 @@ void StyleBoxFlat::set_corner_radius_individual(const int radius_top_left, const emit_changed(); } -int StyleBoxFlat::get_corner_radius_min() const { - int smallest = corner_radius[0]; - for (int i = 1; i < 4; i++) { - if (smallest > corner_radius[i]) { - smallest = corner_radius[i]; - } - } - return smallest; -} - void StyleBoxFlat::set_corner_radius(const Corner p_corner, const int radius) { ERR_FAIL_INDEX((int)p_corner, 4); corner_radius[p_corner] = radius; diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h index a1237776c6..7dd806e840 100644 --- a/scene/resources/style_box.h +++ b/scene/resources/style_box.h @@ -184,7 +184,6 @@ public: //CORNER void set_corner_radius_all(int radius); void set_corner_radius_individual(const int radius_top_left, const int radius_top_right, const int radius_botton_right, const int radius_bottom_left); - int get_corner_radius_min() const; void set_corner_radius(Corner p_corner, const int radius); int get_corner_radius(Corner p_corner) const; diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 3166067573..7899627048 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -74,7 +74,7 @@ bool SurfaceTool::Vertex::operator==(const Vertex &p_vertex) const { } } - for (int i = 0; i < RS::ARRAY_CUSTOM_MAX; i++) { + for (int i = 0; i < RS::ARRAY_CUSTOM_COUNT; i++) { if (custom[i] != p_vertex.custom[i]) { return false; } diff --git a/scene/resources/text_line.cpp b/scene/resources/text_line.cpp index 5a419bb232..cc9b6758b6 100644 --- a/scene/resources/text_line.cpp +++ b/scene/resources/text_line.cpp @@ -113,6 +113,8 @@ RID TextLine::get_rid() const { void TextLine::clear() { TS->shaped_text_clear(rid); + spacing_top = 0; + spacing_bottom = 0; } void TextLine::set_preserve_invalid(bool p_enabled) { @@ -166,6 +168,8 @@ void TextLine::set_bidi_override(const Vector<Vector2i> &p_override) { bool TextLine::add_string(const String &p_text, const Ref<Font> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { bool res = TS->shaped_text_add_string(rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language); + spacing_top = p_fonts->get_spacing(Font::SPACING_TOP); + spacing_bottom = p_fonts->get_spacing(Font::SPACING_BOTTOM); dirty = true; return res; } @@ -233,17 +237,21 @@ float TextLine::get_width() const { Size2 TextLine::get_size() const { const_cast<TextLine *>(this)->_shape(); - return TS->shaped_text_get_size(rid); + if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) { + return Size2(TS->shaped_text_get_size(rid).x, TS->shaped_text_get_size(rid).y + spacing_top + spacing_bottom); + } else { + return Size2(TS->shaped_text_get_size(rid).x + spacing_top + spacing_bottom, TS->shaped_text_get_size(rid).y); + } } float TextLine::get_line_ascent() const { const_cast<TextLine *>(this)->_shape(); - return TS->shaped_text_get_ascent(rid); + return TS->shaped_text_get_ascent(rid) + spacing_top; } float TextLine::get_line_descent() const { const_cast<TextLine *>(this)->_shape(); - return TS->shaped_text_get_descent(rid); + return TS->shaped_text_get_descent(rid) + spacing_bottom; } float TextLine::get_line_width() const { @@ -291,10 +299,10 @@ void TextLine::draw(RID p_canvas, const Vector2 &p_pos, const Color &p_color) co float clip_l; if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) { - ofs.y += TS->shaped_text_get_ascent(rid); + ofs.y += TS->shaped_text_get_ascent(rid) + spacing_top; clip_l = MAX(0, p_pos.x - ofs.x); } else { - ofs.x += TS->shaped_text_get_ascent(rid); + ofs.x += TS->shaped_text_get_ascent(rid) + spacing_top; clip_l = MAX(0, p_pos.y - ofs.y); } return TS->shaped_text_draw(rid, p_canvas, ofs, clip_l, clip_l + width, p_color); @@ -330,10 +338,10 @@ void TextLine::draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outline_si float clip_l; if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) { - ofs.y += TS->shaped_text_get_ascent(rid); + ofs.y += TS->shaped_text_get_ascent(rid) + spacing_top; clip_l = MAX(0, p_pos.x - ofs.x); } else { - ofs.x += TS->shaped_text_get_ascent(rid); + ofs.x += TS->shaped_text_get_ascent(rid) + spacing_top; clip_l = MAX(0, p_pos.y - ofs.y); } return TS->shaped_text_draw_outline(rid, p_canvas, ofs, clip_l, clip_l + width, p_outline_size, p_color); @@ -347,6 +355,8 @@ int TextLine::hit_test(float p_coords) const { TextLine::TextLine(const String &p_text, const Ref<Font> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language, TextServer::Direction p_direction, TextServer::Orientation p_orientation) { rid = TS->create_shaped_text(p_direction, p_orientation); + spacing_top = p_fonts->get_spacing(Font::SPACING_TOP); + spacing_bottom = p_fonts->get_spacing(Font::SPACING_BOTTOM); TS->shaped_text_add_string(rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language); } diff --git a/scene/resources/text_line.h b/scene/resources/text_line.h index ffa06cc5c1..6ed3558bd9 100644 --- a/scene/resources/text_line.h +++ b/scene/resources/text_line.h @@ -40,6 +40,8 @@ class TextLine : public Reference { GDCLASS(TextLine, Reference); RID rid; + int spacing_top = 0; + int spacing_bottom = 0; bool dirty = true; diff --git a/scene/resources/text_paragraph.cpp b/scene/resources/text_paragraph.cpp index d4f96ff9e8..fd6dd071eb 100644 --- a/scene/resources/text_paragraph.cpp +++ b/scene/resources/text_paragraph.cpp @@ -140,6 +140,8 @@ RID TextParagraph::get_line_rid(int p_line) const { } void TextParagraph::clear() { + spacing_top = 0; + spacing_bottom = 0; for (int i = 0; i < lines.size(); i++) { TS->free(lines[i]); } @@ -187,6 +189,8 @@ TextServer::Orientation TextParagraph::get_orientation() const { bool TextParagraph::add_string(const String &p_text, const Ref<Font> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language) { bool res = TS->shaped_text_add_string(rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language); + spacing_top = p_fonts->get_spacing(Font::SPACING_TOP); + spacing_bottom = p_fonts->get_spacing(Font::SPACING_BOTTOM); dirty_lines = true; return res; } @@ -260,7 +264,11 @@ float TextParagraph::get_width() const { Size2 TextParagraph::get_non_wraped_size() const { const_cast<TextParagraph *>(this)->_shape_lines(); - return TS->shaped_text_get_size(rid); + if (TS->shaped_text_get_orientation(rid) == TextServer::ORIENTATION_HORIZONTAL) { + return Size2(TS->shaped_text_get_size(rid).x, TS->shaped_text_get_size(rid).y + spacing_top + spacing_bottom); + } else { + return Size2(TS->shaped_text_get_size(rid).x + spacing_top + spacing_bottom, TS->shaped_text_get_size(rid).y); + } } Size2 TextParagraph::get_size() const { @@ -270,9 +278,9 @@ Size2 TextParagraph::get_size() const { Size2 lsize = TS->shaped_text_get_size(lines[i]); if (TS->shaped_text_get_orientation(lines[i]) == TextServer::ORIENTATION_HORIZONTAL) { size.x = MAX(size.x, lsize.x); - size.y += lsize.y; + size.y += lsize.y + spacing_top + spacing_bottom; } else { - size.x += lsize.x; + size.x += lsize.x + spacing_top + spacing_bottom; size.y = MAX(size.y, lsize.y); } } @@ -297,9 +305,9 @@ Rect2 TextParagraph::get_line_object_rect(int p_line, Variant p_key) const { for (int i = 0; i < p_line; i++) { Size2 lsize = TS->shaped_text_get_size(lines[i]); if (TS->shaped_text_get_orientation(lines[i]) == TextServer::ORIENTATION_HORIZONTAL) { - xrect.position.y += lsize.y; + xrect.position.y += lsize.y + spacing_top + spacing_bottom; } else { - xrect.position.x += lsize.x; + xrect.position.x += lsize.x + spacing_top + spacing_bottom; } } return xrect; @@ -308,7 +316,11 @@ Rect2 TextParagraph::get_line_object_rect(int p_line, Variant p_key) const { Size2 TextParagraph::get_line_size(int p_line) const { const_cast<TextParagraph *>(this)->_shape_lines(); ERR_FAIL_COND_V(p_line < 0 || p_line >= lines.size(), Size2()); - return TS->shaped_text_get_size(lines[p_line]); + if (TS->shaped_text_get_orientation(lines[p_line]) == TextServer::ORIENTATION_HORIZONTAL) { + return Size2(TS->shaped_text_get_size(lines[p_line]).x, TS->shaped_text_get_size(lines[p_line]).y + spacing_top + spacing_bottom); + } else { + return Size2(TS->shaped_text_get_size(lines[p_line]).x + spacing_top + spacing_bottom, TS->shaped_text_get_size(lines[p_line]).y); + } } Vector2i TextParagraph::get_line_range(int p_line) const { @@ -320,13 +332,13 @@ Vector2i TextParagraph::get_line_range(int p_line) const { float TextParagraph::get_line_ascent(int p_line) const { const_cast<TextParagraph *>(this)->_shape_lines(); ERR_FAIL_COND_V(p_line < 0 || p_line >= lines.size(), 0.f); - return TS->shaped_text_get_ascent(lines[p_line]); + return TS->shaped_text_get_ascent(lines[p_line]) + spacing_top; } float TextParagraph::get_line_descent(int p_line) const { const_cast<TextParagraph *>(this)->_shape_lines(); ERR_FAIL_COND_V(p_line < 0 || p_line >= lines.size(), 0.f); - return TS->shaped_text_get_descent(lines[p_line]); + return TS->shaped_text_get_descent(lines[p_line]) + spacing_bottom; } float TextParagraph::get_line_width(int p_line) const { @@ -353,10 +365,10 @@ void TextParagraph::draw(RID p_canvas, const Vector2 &p_pos, const Color &p_colo for (int i = 0; i < lines.size(); i++) { if (TS->shaped_text_get_orientation(lines[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x = p_pos.x; - ofs.y += TS->shaped_text_get_ascent(lines[i]); + ofs.y += TS->shaped_text_get_ascent(lines[i]) + spacing_top; } else { ofs.y = p_pos.y; - ofs.x += TS->shaped_text_get_ascent(lines[i]); + ofs.x += TS->shaped_text_get_ascent(lines[i]) + spacing_top; } float length = TS->shaped_text_get_width(lines[i]); if (width > 0) { @@ -389,10 +401,10 @@ void TextParagraph::draw(RID p_canvas, const Vector2 &p_pos, const Color &p_colo TS->shaped_text_draw(lines[i], p_canvas, ofs, clip_l, clip_l + width, p_color); if (TS->shaped_text_get_orientation(lines[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x = p_pos.x; - ofs.y += TS->shaped_text_get_descent(lines[i]); + ofs.y += TS->shaped_text_get_descent(lines[i]) + spacing_bottom; } else { ofs.y = p_pos.y; - ofs.x += TS->shaped_text_get_descent(lines[i]); + ofs.x += TS->shaped_text_get_descent(lines[i]) + spacing_bottom; } } } @@ -403,10 +415,10 @@ void TextParagraph::draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outli for (int i = 0; i < lines.size(); i++) { if (TS->shaped_text_get_orientation(lines[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x = p_pos.x; - ofs.y += TS->shaped_text_get_ascent(lines[i]); + ofs.y += TS->shaped_text_get_ascent(lines[i]) + spacing_top; } else { ofs.y = p_pos.y; - ofs.x += TS->shaped_text_get_ascent(lines[i]); + ofs.x += TS->shaped_text_get_ascent(lines[i]) + spacing_top; } float length = TS->shaped_text_get_width(lines[i]); if (width > 0) { @@ -439,10 +451,10 @@ void TextParagraph::draw_outline(RID p_canvas, const Vector2 &p_pos, int p_outli TS->shaped_text_draw_outline(lines[i], p_canvas, ofs, clip_l, clip_l + width, p_outline_size, p_color); if (TS->shaped_text_get_orientation(lines[i]) == TextServer::ORIENTATION_HORIZONTAL) { ofs.x = p_pos.x; - ofs.y += TS->shaped_text_get_descent(lines[i]); + ofs.y += TS->shaped_text_get_descent(lines[i]) + spacing_bottom; } else { ofs.y = p_pos.y; - ofs.x += TS->shaped_text_get_descent(lines[i]); + ofs.x += TS->shaped_text_get_descent(lines[i]) + spacing_bottom; } } } @@ -462,10 +474,12 @@ int TextParagraph::hit_test(const Point2 &p_coords) const { if ((p_coords.y >= ofs.y) && (p_coords.y <= ofs.y + TS->shaped_text_get_size(lines[i]).y)) { return TS->shaped_text_hit_test_position(lines[i], p_coords.x); } + ofs.y += TS->shaped_text_get_size(lines[i]).y + spacing_bottom + spacing_top; } else { if ((p_coords.x >= ofs.x) && (p_coords.x <= ofs.x + TS->shaped_text_get_size(lines[i]).x)) { return TS->shaped_text_hit_test_position(lines[i], p_coords.y); } + ofs.y += TS->shaped_text_get_size(lines[i]).x + spacing_bottom + spacing_top; } } return TS->shaped_text_get_range(rid).y; @@ -477,9 +491,9 @@ void TextParagraph::draw_line(RID p_canvas, const Vector2 &p_pos, int p_line, co Vector2 ofs = p_pos; if (TS->shaped_text_get_orientation(lines[p_line]) == TextServer::ORIENTATION_HORIZONTAL) { - ofs.y += TS->shaped_text_get_ascent(lines[p_line]); + ofs.y += TS->shaped_text_get_ascent(lines[p_line]) + spacing_top; } else { - ofs.x += TS->shaped_text_get_ascent(lines[p_line]); + ofs.x += TS->shaped_text_get_ascent(lines[p_line]) + spacing_top; } return TS->shaped_text_draw(lines[p_line], p_canvas, ofs, -1, -1, p_color); } @@ -490,9 +504,9 @@ void TextParagraph::draw_line_outline(RID p_canvas, const Vector2 &p_pos, int p_ Vector2 ofs = p_pos; if (TS->shaped_text_get_orientation(lines[p_line]) == TextServer::ORIENTATION_HORIZONTAL) { - ofs.y += TS->shaped_text_get_ascent(lines[p_line]); + ofs.y += TS->shaped_text_get_ascent(lines[p_line]) + spacing_top; } else { - ofs.x += TS->shaped_text_get_ascent(lines[p_line]); + ofs.x += TS->shaped_text_get_ascent(lines[p_line]) + spacing_top; } return TS->shaped_text_draw_outline(lines[p_line], p_canvas, ofs, -1, -1, p_outline_size, p_color); } @@ -500,8 +514,9 @@ void TextParagraph::draw_line_outline(RID p_canvas, const Vector2 &p_pos, int p_ TextParagraph::TextParagraph(const String &p_text, const Ref<Font> &p_fonts, int p_size, const Dictionary &p_opentype_features, const String &p_language, float p_width, TextServer::Direction p_direction, TextServer::Orientation p_orientation) { rid = TS->create_shaped_text(p_direction, p_orientation); TS->shaped_text_add_string(rid, p_text, p_fonts->get_rids(), p_size, p_opentype_features, p_language); + spacing_top = p_fonts->get_spacing(Font::SPACING_TOP); + spacing_bottom = p_fonts->get_spacing(Font::SPACING_BOTTOM); width = p_width; - dirty_lines = true; } TextParagraph::TextParagraph() { diff --git a/scene/resources/text_paragraph.h b/scene/resources/text_paragraph.h index 587bb6bfc1..f7f49e9058 100644 --- a/scene/resources/text_paragraph.h +++ b/scene/resources/text_paragraph.h @@ -41,6 +41,8 @@ class TextParagraph : public Reference { RID rid; Vector<RID> lines; + int spacing_top = 0; + int spacing_bottom = 0; bool dirty_lines = true; diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index d130470275..6a752d32e7 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -421,52 +421,6 @@ void Theme::get_icon_list(StringName p_node_type, List<StringName> *p_list) cons } } -void Theme::set_shader(const StringName &p_name, const StringName &p_node_type, const Ref<Shader> &p_shader) { - bool new_value = !shader_map.has(p_node_type) || !shader_map[p_node_type].has(p_name); - - shader_map[p_node_type][p_name] = p_shader; - - if (new_value) { - _change_notify(); - emit_changed(); - } -} - -Ref<Shader> Theme::get_shader(const StringName &p_name, const StringName &p_node_type) const { - if (shader_map.has(p_node_type) && shader_map[p_node_type].has(p_name) && shader_map[p_node_type][p_name].is_valid()) { - return shader_map[p_node_type][p_name]; - } else { - return nullptr; - } -} - -bool Theme::has_shader(const StringName &p_name, const StringName &p_node_type) const { - return (shader_map.has(p_node_type) && shader_map[p_node_type].has(p_name) && shader_map[p_node_type][p_name].is_valid()); -} - -void Theme::clear_shader(const StringName &p_name, const StringName &p_node_type) { - ERR_FAIL_COND(!shader_map.has(p_node_type)); - ERR_FAIL_COND(!shader_map[p_node_type].has(p_name)); - - shader_map[p_node_type].erase(p_name); - _change_notify(); - emit_changed(); -} - -void Theme::get_shader_list(const StringName &p_node_type, List<StringName> *p_list) const { - ERR_FAIL_NULL(p_list); - - if (!shader_map.has(p_node_type)) { - return; - } - - const StringName *key = nullptr; - - while ((key = shader_map[p_node_type].next(key))) { - p_list->push_back(*key); - } -} - void Theme::set_stylebox(const StringName &p_name, const StringName &p_node_type, const Ref<StyleBox> &p_style) { //ERR_FAIL_COND(p_style.is_null()); @@ -782,7 +736,6 @@ void Theme::clear() { icon_map.clear(); style_map.clear(); font_map.clear(); - shader_map.clear(); color_map.clear(); constant_map.clear(); @@ -837,7 +790,6 @@ void Theme::copy_theme(const Ref<Theme> &p_other) { color_map = p_other->color_map; constant_map = p_other->constant_map; - shader_map = p_other->shader_map; _change_notify(); emit_changed(); diff --git a/scene/resources/theme.h b/scene/resources/theme.h index 4175e19112..6ac47e8931 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -34,7 +34,6 @@ #include "core/io/resource.h" #include "core/io/resource_loader.h" #include "scene/resources/font.h" -#include "scene/resources/shader.h" #include "scene/resources/style_box.h" #include "scene/resources/texture.h" @@ -48,7 +47,6 @@ class Theme : public Resource { HashMap<StringName, HashMap<StringName, Ref<StyleBox>>> style_map; HashMap<StringName, HashMap<StringName, Ref<Font>>> font_map; HashMap<StringName, HashMap<StringName, int>> font_size_map; - HashMap<StringName, HashMap<StringName, Ref<Shader>>> shader_map; HashMap<StringName, HashMap<StringName, Color>> color_map; HashMap<StringName, HashMap<StringName, int>> constant_map; @@ -102,12 +100,6 @@ public: void clear_icon(const StringName &p_name, const StringName &p_node_type); void get_icon_list(StringName p_node_type, List<StringName> *p_list) const; - void set_shader(const StringName &p_name, const StringName &p_node_type, const Ref<Shader> &p_shader); - Ref<Shader> get_shader(const StringName &p_name, const StringName &p_node_type) const; - bool has_shader(const StringName &p_name, const StringName &p_node_type) const; - void clear_shader(const StringName &p_name, const StringName &p_node_type); - void get_shader_list(const StringName &p_node_type, List<StringName> *p_list) const; - void set_stylebox(const StringName &p_name, const StringName &p_node_type, const Ref<StyleBox> &p_style); Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_node_type) const; bool has_stylebox(const StringName &p_name, const StringName &p_node_type) const; |