From 10e11ec87f3e7ef2940fa363e851da87e3140e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Wed, 20 Aug 2025 20:46:38 +0300 Subject: [PATCH] Rename SVGTexture to DPITexture. --- .../{SVGTexture.xml => DPITexture.xml} | 14 +-- doc/classes/ProjectSettings.xml | 2 +- doc/classes/ResourceImporterSVG.xml | 8 +- doc/classes/Viewport.xml | 2 +- editor/import/resource_importer_svg.cpp | 30 ++--- editor/themes/editor_icons.cpp | 16 +-- editor/themes/editor_theme_manager.cpp | 4 +- .../4.4-stable.expected | 2 +- scene/main/viewport.cpp | 6 +- scene/register_scene_types.cpp | 4 +- .../{svg_texture.cpp => dpi_texture.cpp} | 106 +++++++++--------- .../{svg_texture.h => dpi_texture.h} | 14 +-- scene/theme/default_theme.cpp | 6 +- 13 files changed, 107 insertions(+), 107 deletions(-) rename doc/classes/{SVGTexture.xml => DPITexture.xml} (73%) rename scene/resources/{svg_texture.cpp => dpi_texture.cpp} (77%) rename scene/resources/{svg_texture.h => dpi_texture.h} (93%) diff --git a/doc/classes/SVGTexture.xml b/doc/classes/DPITexture.xml similarity index 73% rename from doc/classes/SVGTexture.xml rename to doc/classes/DPITexture.xml index 4ef6637ae3f..c7c803c164a 100644 --- a/doc/classes/SVGTexture.xml +++ b/doc/classes/DPITexture.xml @@ -1,22 +1,22 @@ - + - A scalable [Texture2D] based on an SVG image. + An automatically scalable [Texture2D] based on an SVG image. - A scalable [Texture2D] based on an SVG image. [SVGTexture]s are automatically re-rasterized to match font oversampling. + An automatically scalable [Texture2D] based on an SVG image. [DPITexture]s are used to automatically re-rasterize icons and other texture based UI theme elements to match viewport scale and font oversampling. See also [member ProjectSettings.display/window/stretch/mode] ("canvas_items" mode) and [member Viewport.oversampling_override]. - + - Creates a new [SVGTexture] and initializes it by allocating and setting the SVG data from string. + Creates a new [DPITexture] and initializes it by allocating and setting the SVG data from string. @@ -48,10 +48,10 @@ - SVG texture scale. [code]1.0[/code] is the original SVG size. Higher values result in a larger image. + Texture scale. [code]1.0[/code] is the original SVG size. Higher values result in a larger image. - If set, remaps SVG texture colors according to [Color]-[Color] map. + If set, remaps texture colors according to [Color]-[Color] map. diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index 1a91d12d693..e8afba61e01 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -1194,7 +1194,7 @@ Maximum undo/redo history size for [TextEdit] fields. - If set to [code]true[/code] and [member display/window/stretch/mode] is set to [b]"canvas_items"[/b], font and [SVGTexture] oversampling is enabled in the main window. Use [member Viewport.oversampling] to control oversampling in other viewports and windows. + If set to [code]true[/code] and [member display/window/stretch/mode] is set to [b]"canvas_items"[/b], font and [DPITexture] oversampling is enabled in the main window. Use [member Viewport.oversampling] to control oversampling in other viewports and windows. Path to a custom [Theme] resource file to use for the project ([code].theme[/code] or generic [code].tres[/code]/[code].res[/code] extension). diff --git a/doc/classes/ResourceImporterSVG.xml b/doc/classes/ResourceImporterSVG.xml index 625fb2b9177..0eb87330d24 100644 --- a/doc/classes/ResourceImporterSVG.xml +++ b/doc/classes/ResourceImporterSVG.xml @@ -1,19 +1,19 @@ - Imports an SVG file as a scalable texture for use in 2D or 3D rendering. + Imports an SVG file as an automatically scalable texture for use in UI elements and 2D rendering. - This importer imports [SVGTexture] resources. See also [ResourceImporterTexture] and [ResourceImporterImage]. + This importer imports [DPITexture] resources. See also [ResourceImporterTexture] and [ResourceImporterImage]. - SVG texture scale. [code]1.0[/code] is the original SVG size. Higher values result in a larger image. + Texture scale. [code]1.0[/code] is the original SVG size. Higher values result in a larger image. - If set, remaps SVG texture colors according to [Color]-[Color] map. + If set, remaps texture colors according to [Color]-[Color] map. If [code]true[/code], uses lossless compression for the SVG source. diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 5183cd53ff6..58608a3299a 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -376,7 +376,7 @@ See also [member ProjectSettings.rendering/anti_aliasing/quality/msaa_3d] and [method RenderingServer.viewport_set_msaa_3d]. - If [code]true[/code] and one of the following conditions is true: [member SubViewport.size_2d_override_stretch] and [member SubViewport.size_2d_override] are set, [member Window.content_scale_factor] is set and scaling is enabled, [member oversampling_override] is set, font and [SVGTexture] oversampling is enabled. + If [code]true[/code] and one of the following conditions are true: [member SubViewport.size_2d_override_stretch] and [member SubViewport.size_2d_override] are set, [member Window.content_scale_factor] is set and scaling is enabled, [member oversampling_override] is set, font and [DPITexture] oversampling are enabled. If greater than zero, this value is used as the font oversampling factor, otherwise oversampling is equal to viewport scale. diff --git a/editor/import/resource_importer_svg.cpp b/editor/import/resource_importer_svg.cpp index 8a9f34f1e64..dfe29c5afca 100644 --- a/editor/import/resource_importer_svg.cpp +++ b/editor/import/resource_importer_svg.cpp @@ -31,14 +31,14 @@ #include "resource_importer_svg.h" #include "core/io/file_access.h" -#include "scene/resources/svg_texture.h" +#include "scene/resources/dpi_texture.h" String ResourceImporterSVG::get_importer_name() const { return "svg"; } String ResourceImporterSVG::get_visible_name() const { - return "SVGTexture"; + return "DPITexture"; } void ResourceImporterSVG::get_recognized_extensions(List *p_extensions) const { @@ -46,11 +46,11 @@ void ResourceImporterSVG::get_recognized_extensions(List *p_extensions) } String ResourceImporterSVG::get_save_extension() const { - return "svgtex"; + return "dpitex"; } String ResourceImporterSVG::get_resource_type() const { - return "SVGTexture"; + return "DPITexture"; } bool ResourceImporterSVG::get_option_visibility(const String &p_path, const String &p_option, const HashMap &p_options) const { @@ -73,8 +73,8 @@ void ResourceImporterSVG::get_import_options(const String &p_path, List &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { - Ref svg_tex; - svg_tex.instantiate(); + Ref dpi_tex; + dpi_tex.instantiate(); String source = FileAccess::get_file_as_string(p_source_file); ERR_FAIL_COND_V_MSG(source.is_empty(), ERR_CANT_OPEN, vformat("Cannot open file from path \"%s\".", p_source_file)); @@ -83,22 +83,22 @@ Error ResourceImporterSVG::import(ResourceUID::ID p_source_id, const String &p_s double saturation = p_options["saturation"]; Dictionary color_map = p_options["color_map"]; - svg_tex->set_base_scale(base_scale); - svg_tex->set_saturation(saturation); - svg_tex->set_color_map(color_map); - svg_tex->set_source(source); + dpi_tex->set_base_scale(base_scale); + dpi_tex->set_saturation(saturation); + dpi_tex->set_color_map(color_map); + dpi_tex->set_source(source); - ERR_FAIL_COND_V_MSG(svg_tex->get_rid().is_null(), ERR_CANT_OPEN, vformat("Failed loading SVG, unsupported or invalid SVG data in \"%s\".", p_source_file)); + ERR_FAIL_COND_V_MSG(dpi_tex->get_rid().is_null(), ERR_CANT_OPEN, vformat("Failed loading SVG, unsupported or invalid SVG data in \"%s\".", p_source_file)); int flg = 0; if ((bool)p_options["compress"]) { flg |= ResourceSaver::SaverFlags::FLAG_COMPRESS; } - print_verbose("Saving to: " + p_save_path + ".svgtex"); - Error err = ResourceSaver::save(svg_tex, p_save_path + ".svgtex", flg); - ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Cannot save SVG texture to file \"%s.svgtex\".", p_save_path)); - print_verbose("Done saving to: " + p_save_path + ".svgtex"); + print_verbose("Saving to: " + p_save_path + ".dpitex"); + Error err = ResourceSaver::save(dpi_tex, p_save_path + ".dpitex", flg); + ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Cannot save DPI texture to file \"%s.dpitex\".", p_save_path)); + print_verbose("Done saving to: " + p_save_path + ".dpitex"); return OK; } diff --git a/editor/themes/editor_icons.cpp b/editor/themes/editor_icons.cpp index 8e63768e40f..5aa1ca5232e 100644 --- a/editor/themes/editor_icons.cpp +++ b/editor/themes/editor_icons.cpp @@ -34,8 +34,8 @@ #include "editor/themes/editor_color_map.h" #include "editor/themes/editor_icons.gen.h" #include "editor/themes/editor_scale.h" +#include "scene/resources/dpi_texture.h" #include "scene/resources/image_texture.h" -#include "scene/resources/svg_texture.h" #include "modules/svg/image_loader_svg.h" @@ -48,8 +48,8 @@ void editor_configure_icons(bool p_dark_theme) { } // See also `generate_icon()` in `scene/theme/default_theme.cpp`. -Ref editor_generate_icon(int p_index, float p_scale, float p_saturation, const Dictionary &p_convert_colors = Dictionary()) { - return SVGTexture::create_from_string(editor_icons_sources[p_index], p_scale, p_saturation, p_convert_colors); +Ref editor_generate_icon(int p_index, float p_scale, float p_saturation, const Dictionary &p_convert_colors = Dictionary()) { + return DPITexture::create_from_string(editor_icons_sources[p_index], p_scale, p_saturation, p_convert_colors); } float get_gizmo_handle_scale(const String &p_gizmo_handle_name, float p_gizmo_handle_scale) { @@ -154,14 +154,14 @@ void editor_register_icons(const Ref &p_theme, bool p_dark_theme, float p saturation = 1.0; } - Ref icon_dark = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map_dark); - Ref icon_light = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map_light); + Ref icon_dark = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map_dark); + Ref icon_light = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), saturation, color_conversion_map_light); p_theme->set_icon(editor_icon_name + "Dark", EditorStringName(EditorIcons), icon_dark); p_theme->set_icon(editor_icon_name + "Light", EditorStringName(EditorIcons), icon_light); p_theme->set_icon(editor_icon_name, EditorStringName(EditorIcons), p_dark_theme ? icon_dark : icon_light); } else { - Ref icon; + Ref icon; if (accent_color_icons.has(editor_icon_name)) { icon = editor_generate_icon(i, get_gizmo_handle_scale(editor_icon_name, p_gizmo_handle_scale), 1.0, accent_color_map); } else { @@ -188,7 +188,7 @@ void editor_register_icons(const Ref &p_theme, bool p_dark_theme, float p const float scale = (float)p_thumb_size / 64.0 * EDSCALE; for (int i = 0; i < editor_bg_thumbs_count; i++) { const int index = editor_bg_thumbs_indices[i]; - Ref icon; + Ref icon; if (accent_color_icons.has(editor_icons_names[index])) { icon = editor_generate_icon(index, scale, 1.0, accent_color_map); @@ -211,7 +211,7 @@ void editor_register_icons(const Ref &p_theme, bool p_dark_theme, float p const float scale = (float)p_thumb_size / 32.0 * EDSCALE; for (int i = 0; i < editor_md_thumbs_count; i++) { const int index = editor_md_thumbs_indices[i]; - Ref icon; + Ref icon; if (accent_color_icons.has(editor_icons_names[index])) { icon = editor_generate_icon(index, scale, 1.0, accent_color_map); diff --git a/editor/themes/editor_theme_manager.cpp b/editor/themes/editor_theme_manager.cpp index 750e96c198f..5a86c3e4110 100644 --- a/editor/themes/editor_theme_manager.cpp +++ b/editor/themes/editor_theme_manager.cpp @@ -41,11 +41,11 @@ #include "editor/themes/editor_scale.h" #include "editor/themes/editor_theme.h" #include "scene/gui/graph_edit.h" +#include "scene/resources/dpi_texture.h" #include "scene/resources/image_texture.h" #include "scene/resources/style_box_flat.h" #include "scene/resources/style_box_line.h" #include "scene/resources/style_box_texture.h" -#include "scene/resources/svg_texture.h" #include "scene/resources/texture.h" // Theme configuration. @@ -1726,7 +1726,7 @@ void EditorThemeManager::_populate_standard_styles(const Ref &p_the p_theme->set_constant("port_h_offset", "GraphNode", 1); p_theme->set_constant("separation", "GraphNode", 1 * EDSCALE); - Ref port_icon = p_theme->get_icon(SNAME("GuiGraphNodePort"), EditorStringName(EditorIcons)); + Ref port_icon = p_theme->get_icon(SNAME("GuiGraphNodePort"), EditorStringName(EditorIcons)); // The true size is 24x24 This is necessary for sharp port icons at high zoom levels in GraphEdit (up to ~200%). port_icon->set_size_override(Size2(12, 12)); p_theme->set_icon("port", "GraphNode", port_icon); diff --git a/misc/extension_api_validation/4.4-stable.expected b/misc/extension_api_validation/4.4-stable.expected index c7136ebcd40..5f220c9df12 100644 --- a/misc/extension_api_validation/4.4-stable.expected +++ b/misc/extension_api_validation/4.4-stable.expected @@ -327,4 +327,4 @@ GH-108825 --------- Validate extension JSON: Error: Field 'classes/EditorExportPlatformExtension/methods/_get_option_icon/return_value': type changed value in new API, from "ImageTexture" to "Texture2D". -Return type changed to allow returning both ImageTexture and SVGTexture. Compatibility method registered. +Return type changed to allow returning both ImageTexture and DPITexture. Compatibility method registered. diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 448c1a15d86..3ad22fc98b3 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -43,8 +43,8 @@ #include "scene/gui/subviewport_container.h" #include "scene/main/canvas_layer.h" #include "scene/main/window.h" +#include "scene/resources/dpi_texture.h" #include "scene/resources/mesh.h" -#include "scene/resources/svg_texture.h" #include "scene/resources/text_line.h" #include "scene/resources/world_2d.h" #include "servers/audio_server.h" @@ -1090,8 +1090,8 @@ bool Viewport::_set_size(const Size2i &p_size, const Size2 &p_size_2d_override, TS->reference_oversampling_level(new_font_oversampling); TS->unreference_oversampling_level(font_oversampling); - SVGTexture::reference_scaling_level(new_font_oversampling); - SVGTexture::unreference_scaling_level(font_oversampling); + DPITexture::reference_scaling_level(new_font_oversampling); + DPITexture::unreference_scaling_level(font_oversampling); } size = new_size; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index d288aa5e13f..cce67d2c7e8 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -134,6 +134,7 @@ #if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED) #include "scene/resources/navigation_mesh.h" #endif // !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED) +#include "scene/resources/dpi_texture.h" #include "scene/resources/packed_scene.h" #include "scene/resources/particle_process_material.h" #include "scene/resources/placeholder_textures.h" @@ -147,7 +148,6 @@ #include "scene/resources/style_box_line.h" #include "scene/resources/style_box_texture.h" #include "scene/resources/surface_tool.h" -#include "scene/resources/svg_texture.h" #include "scene/resources/syntax_highlighter.h" #include "scene/resources/text_line.h" #include "scene/resources/text_paragraph.h" @@ -1039,7 +1039,7 @@ void register_scene_types() { GDREGISTER_CLASS(PlaceholderTexture2DArray); GDREGISTER_CLASS(PlaceholderCubemap); GDREGISTER_CLASS(PlaceholderCubemapArray); - GDREGISTER_CLASS(SVGTexture); + GDREGISTER_CLASS(DPITexture); #ifndef DISABLE_DEPRECATED GDREGISTER_CLASS(AnimatedTexture); #endif diff --git a/scene/resources/svg_texture.cpp b/scene/resources/dpi_texture.cpp similarity index 77% rename from scene/resources/svg_texture.cpp rename to scene/resources/dpi_texture.cpp index 7f16439df02..8a8b916e174 100644 --- a/scene/resources/svg_texture.cpp +++ b/scene/resources/dpi_texture.cpp @@ -1,5 +1,5 @@ /**************************************************************************/ -/* svg_texture.cpp */ +/* dpi_texture.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ -#include "svg_texture.h" +#include "dpi_texture.h" #include "core/io/image_loader.h" #include "scene/main/canvas_item.h" @@ -41,10 +41,10 @@ #include "modules/svg/image_loader_svg.h" #endif -Mutex SVGTexture::mutex; -HashMap SVGTexture::scaling_levels; +Mutex DPITexture::mutex; +HashMap DPITexture::scaling_levels; -void SVGTexture::reference_scaling_level(double p_scale) { +void DPITexture::reference_scaling_level(double p_scale) { uint32_t oversampling = CLAMP(p_scale, 0.1, 100.0) * 64; if (oversampling == 64) { return; @@ -61,7 +61,7 @@ void SVGTexture::reference_scaling_level(double p_scale) { } } -void SVGTexture::unreference_scaling_level(double p_scale) { +void DPITexture::unreference_scaling_level(double p_scale) { uint32_t oversampling = CLAMP(p_scale, 0.1, 100.0) * 64; if (oversampling == 64) { return; @@ -73,7 +73,7 @@ void SVGTexture::unreference_scaling_level(double p_scale) { if (sl) { sl->refcount--; if (sl->refcount == 0) { - for (SVGTexture *tx : sl->textures) { + for (DPITexture *tx : sl->textures) { tx->_remove_scale(scale); } sl->textures.clear(); @@ -82,17 +82,17 @@ void SVGTexture::unreference_scaling_level(double p_scale) { } } -Ref SVGTexture::create_from_string(const String &p_source, float p_scale, float p_saturation, const Dictionary &p_color_map) { - Ref svg_texture; - svg_texture.instantiate(); - svg_texture->set_source(p_source); - svg_texture->set_base_scale(p_scale); - svg_texture->set_saturation(p_saturation); - svg_texture->set_color_map(p_color_map); - return svg_texture; +Ref DPITexture::create_from_string(const String &p_source, float p_scale, float p_saturation, const Dictionary &p_color_map) { + Ref dpi_texture; + dpi_texture.instantiate(); + dpi_texture->set_source(p_source); + dpi_texture->set_base_scale(p_scale); + dpi_texture->set_saturation(p_saturation); + dpi_texture->set_color_map(p_color_map); + return dpi_texture; } -void SVGTexture::set_source(const String &p_source) { +void DPITexture::set_source(const String &p_source) { if (source == p_source) { return; } @@ -100,11 +100,11 @@ void SVGTexture::set_source(const String &p_source) { _update_texture(); } -String SVGTexture::get_source() const { +String DPITexture::get_source() const { return source; } -void SVGTexture::set_base_scale(float p_scale) { +void DPITexture::set_base_scale(float p_scale) { if (base_scale == p_scale) { return; } @@ -114,11 +114,11 @@ void SVGTexture::set_base_scale(float p_scale) { _update_texture(); } -float SVGTexture::get_base_scale() const { +float DPITexture::get_base_scale() const { return base_scale; } -void SVGTexture::set_saturation(float p_saturation) { +void DPITexture::set_saturation(float p_saturation) { if (saturation == p_saturation) { return; } @@ -127,11 +127,11 @@ void SVGTexture::set_saturation(float p_saturation) { _update_texture(); } -float SVGTexture::get_saturation() const { +float DPITexture::get_saturation() const { return saturation; } -void SVGTexture::set_color_map(const Dictionary &p_color_map) { +void DPITexture::set_color_map(const Dictionary &p_color_map) { if (color_map == p_color_map) { return; } @@ -143,11 +143,11 @@ void SVGTexture::set_color_map(const Dictionary &p_color_map) { _update_texture(); } -Dictionary SVGTexture::get_color_map() const { +Dictionary DPITexture::get_color_map() const { return color_map; } -void SVGTexture::_remove_scale(double p_scale) { +void DPITexture::_remove_scale(double p_scale) { if (Math::is_equal_approx(p_scale, 1.0)) { return; } @@ -161,7 +161,7 @@ void SVGTexture::_remove_scale(double p_scale) { } } -RID SVGTexture::_ensure_scale(double p_scale) const { +RID DPITexture::_ensure_scale(double p_scale) const { uint32_t oversampling = CLAMP(p_scale, 0.1, 100.0) * 64; if (oversampling == 64) { if (base_texture.is_null()) { @@ -179,14 +179,14 @@ RID SVGTexture::_ensure_scale(double p_scale) const { MutexLock lock(mutex); ScalingLevel *sl = scaling_levels.getptr(scale); ERR_FAIL_NULL_V_MSG(sl, RID(), "Invalid scaling level"); - sl->textures.insert(const_cast(this)); + sl->textures.insert(const_cast(this)); RID new_rid = _load_at_scale(scale, false); texture_cache[scale] = new_rid; return new_rid; } -RID SVGTexture::_load_at_scale(double p_scale, bool p_set_size) const { +RID DPITexture::_load_at_scale(double p_scale, bool p_set_size) const { Ref img; img.instantiate(); #ifdef MODULE_SVG_ENABLED @@ -227,7 +227,7 @@ RID SVGTexture::_load_at_scale(double p_scale, bool p_set_size) const { return rid; } -void SVGTexture::_clear() { +void DPITexture::_clear() { for (KeyValue &tx : texture_cache) { if (tx.value.is_valid()) { RenderingServer::get_singleton()->free(tx.value); @@ -241,12 +241,12 @@ void SVGTexture::_clear() { alpha_cache.unref(); } -void SVGTexture::_update_texture() { +void DPITexture::_update_texture() { _clear(); emit_changed(); } -Ref SVGTexture::get_image() const { +Ref DPITexture::get_image() const { RID rid = _ensure_scale(1.0); if (rid.is_valid()) { return RenderingServer::get_singleton()->texture_2d_get(rid); @@ -255,25 +255,25 @@ Ref SVGTexture::get_image() const { } } -int SVGTexture::get_width() const { +int DPITexture::get_width() const { _ensure_scale(1.0); return size.x; } -int SVGTexture::get_height() const { +int DPITexture::get_height() const { _ensure_scale(1.0); return size.y; } -RID SVGTexture::get_rid() const { +RID DPITexture::get_rid() const { return _ensure_scale(1.0); } -bool SVGTexture::has_alpha() const { +bool DPITexture::has_alpha() const { return true; } -RID SVGTexture::get_scaled_rid() const { +RID DPITexture::get_scaled_rid() const { double scale = 1.0; CanvasItem *ci = CanvasItem::get_current_item_drawn(); if (ci) { @@ -285,19 +285,19 @@ RID SVGTexture::get_scaled_rid() const { return _ensure_scale(scale); } -void SVGTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose) const { +void DPITexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose) const { RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, Rect2(p_pos, size), get_scaled_rid(), false, p_modulate, p_transpose); } -void SVGTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose) const { +void DPITexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose) const { RenderingServer::get_singleton()->canvas_item_add_texture_rect(p_canvas_item, p_rect, get_scaled_rid(), p_tile, p_modulate, p_transpose); } -void SVGTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, bool p_clip_uv) const { +void DPITexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, bool p_clip_uv) const { RenderingServer::get_singleton()->canvas_item_add_texture_rect_region(p_canvas_item, p_rect, get_scaled_rid(), p_src_rect, p_modulate, p_transpose, p_clip_uv); } -bool SVGTexture::is_pixel_opaque(int p_x, int p_y) const { +bool DPITexture::is_pixel_opaque(int p_x, int p_y) const { if (alpha_cache.is_null()) { Ref img = get_image(); if (img.is_valid()) { @@ -325,7 +325,7 @@ bool SVGTexture::is_pixel_opaque(int p_x, int p_y) const { return true; } -void SVGTexture::set_size_override(const Size2i &p_size) { +void DPITexture::set_size_override(const Size2i &p_size) { if (size_override == p_size) { return; } @@ -352,19 +352,19 @@ void SVGTexture::set_size_override(const Size2i &p_size) { emit_changed(); } -void SVGTexture::_bind_methods() { - ClassDB::bind_static_method("SVGTexture", D_METHOD("create_from_string", "source", "scale", "saturation", "color_map"), &SVGTexture::create_from_string, DEFVAL(1.0), DEFVAL(1.0), DEFVAL(Dictionary())); +void DPITexture::_bind_methods() { + ClassDB::bind_static_method("DPITexture", D_METHOD("create_from_string", "source", "scale", "saturation", "color_map"), &DPITexture::create_from_string, DEFVAL(1.0), DEFVAL(1.0), DEFVAL(Dictionary())); - ClassDB::bind_method(D_METHOD("set_source", "source"), &SVGTexture::set_source); - ClassDB::bind_method(D_METHOD("get_source"), &SVGTexture::get_source); - ClassDB::bind_method(D_METHOD("set_base_scale", "base_scale"), &SVGTexture::set_base_scale); - ClassDB::bind_method(D_METHOD("get_base_scale"), &SVGTexture::get_base_scale); - ClassDB::bind_method(D_METHOD("set_saturation", "saturation"), &SVGTexture::set_saturation); - ClassDB::bind_method(D_METHOD("get_saturation"), &SVGTexture::get_saturation); - ClassDB::bind_method(D_METHOD("set_color_map", "color_map"), &SVGTexture::set_color_map); - ClassDB::bind_method(D_METHOD("get_color_map"), &SVGTexture::get_color_map); - ClassDB::bind_method(D_METHOD("set_size_override", "size"), &SVGTexture::set_size_override); - ClassDB::bind_method(D_METHOD("get_scaled_rid"), &SVGTexture::get_scaled_rid); + ClassDB::bind_method(D_METHOD("set_source", "source"), &DPITexture::set_source); + ClassDB::bind_method(D_METHOD("get_source"), &DPITexture::get_source); + ClassDB::bind_method(D_METHOD("set_base_scale", "base_scale"), &DPITexture::set_base_scale); + ClassDB::bind_method(D_METHOD("get_base_scale"), &DPITexture::get_base_scale); + ClassDB::bind_method(D_METHOD("set_saturation", "saturation"), &DPITexture::set_saturation); + ClassDB::bind_method(D_METHOD("get_saturation"), &DPITexture::get_saturation); + ClassDB::bind_method(D_METHOD("set_color_map", "color_map"), &DPITexture::set_color_map); + ClassDB::bind_method(D_METHOD("get_color_map"), &DPITexture::get_color_map); + ClassDB::bind_method(D_METHOD("set_size_override", "size"), &DPITexture::set_size_override); + ClassDB::bind_method(D_METHOD("get_scaled_rid"), &DPITexture::get_scaled_rid); ADD_PROPERTY(PropertyInfo(Variant::STRING, "_source", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_STORAGE), "set_source", "get_source"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "base_scale", PROPERTY_HINT_RANGE, "0.01,10.0,0.01"), "set_base_scale", "get_base_scale"); @@ -372,7 +372,7 @@ void SVGTexture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "color_map", PROPERTY_HINT_DICTIONARY_TYPE, "Color;Color"), "set_color_map", "get_color_map"); } -SVGTexture::~SVGTexture() { +DPITexture::~DPITexture() { _clear(); MutexLock lock(mutex); diff --git a/scene/resources/svg_texture.h b/scene/resources/dpi_texture.h similarity index 93% rename from scene/resources/svg_texture.h rename to scene/resources/dpi_texture.h index d9a615da723..93750bb445b 100644 --- a/scene/resources/svg_texture.h +++ b/scene/resources/dpi_texture.h @@ -1,5 +1,5 @@ /**************************************************************************/ -/* svg_texture.h */ +/* dpi_texture.h */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -35,9 +35,9 @@ class BitMap; -class SVGTexture : public Texture2D { - GDCLASS(SVGTexture, Texture2D); - RES_BASE_EXTENSION("svgtex"); +class DPITexture : public Texture2D { + GDCLASS(DPITexture, Texture2D); + RES_BASE_EXTENSION("dpitex"); String source; float base_scale = 1.0; @@ -46,7 +46,7 @@ class SVGTexture : public Texture2D { Size2 size_override; struct ScalingLevel { - HashSet textures; + HashSet textures; int32_t refcount = 1; }; static Mutex mutex; @@ -69,7 +69,7 @@ protected: static void _bind_methods(); public: - static Ref create_from_string(const String &p_source, float p_scale = 1.0, float p_saturation = 1.0, const Dictionary &p_color_map = Dictionary()); + static Ref create_from_string(const String &p_source, float p_scale = 1.0, float p_saturation = 1.0, const Dictionary &p_color_map = Dictionary()); void set_source(const String &p_source); String get_source() const; @@ -102,5 +102,5 @@ public: static void reference_scaling_level(double p_scale); static void unreference_scaling_level(double p_scale); - ~SVGTexture(); + ~DPITexture(); }; diff --git a/scene/theme/default_theme.cpp b/scene/theme/default_theme.cpp index a74e79e6b57..96f066dcf68 100644 --- a/scene/theme/default_theme.cpp +++ b/scene/theme/default_theme.cpp @@ -31,12 +31,12 @@ #include "default_theme.h" #include "core/io/image.h" +#include "scene/resources/dpi_texture.h" #include "scene/resources/font.h" #include "scene/resources/gradient_texture.h" #include "scene/resources/image_texture.h" #include "scene/resources/style_box_flat.h" #include "scene/resources/style_box_line.h" -#include "scene/resources/svg_texture.h" #include "scene/resources/theme.h" #include "scene/scene_string_names.h" #include "scene/theme/default_theme_icons.gen.h" @@ -79,8 +79,8 @@ static Ref sb_expand(Ref p_sbox, float p_left, float } // See also `editor_generate_icon()` in `editor/themes/editor_icons.cpp`. -static Ref generate_icon(int p_index) { - return SVGTexture::create_from_string(default_theme_icons_sources[p_index], scale); +static Ref generate_icon(int p_index) { + return DPITexture::create_from_string(default_theme_icons_sources[p_index], scale); } static Ref make_empty_stylebox(float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_bottom = -1) {