From 3d5db96060c439438bc17142cee04aad42e1014b Mon Sep 17 00:00:00 2001 From: arkology <43543909+arkology@users.noreply.github.com> Date: Sat, 14 Sep 2024 12:48:29 +0300 Subject: [PATCH] TextureProgressBar crosshair as Marker2D --- scene/gui/texture_progress_bar.cpp | 28 ++++++++++++++++++++++------ scene/gui/texture_progress_bar.h | 8 ++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/scene/gui/texture_progress_bar.cpp b/scene/gui/texture_progress_bar.cpp index 24c68e0188e1..0ec33521da92 100644 --- a/scene/gui/texture_progress_bar.cpp +++ b/scene/gui/texture_progress_bar.cpp @@ -534,9 +534,9 @@ void TextureProgressBar::_notification(int p_what) { draw_polygon(points, colors, uvs, progress); } } - - // Draw a reference cross. - if (Engine::get_singleton()->is_editor_hint()) { +#ifdef TOOLS_ENABLED + // Change position of the reference cross node. + if (Engine::get_singleton()->is_editor_hint() && reference_cross_marker && reference_cross_marker-is_visible()) { Point2 p; if (nine_patch_stretch) { @@ -547,10 +547,10 @@ void TextureProgressBar::_notification(int p_what) { p *= get_relative_center(); p += progress_offset; - p = p.floor(); - draw_line(p - Point2(8, 0), p + Point2(8, 0), Color(0.9, 0.5, 0.5), 2); - draw_line(p - Point2(0, 8), p + Point2(0, 8), Color(0.9, 0.5, 0.5), 2); + + reference_cross_marker->set_position(p); } +#endif } break; case FILL_BILINEAR_LEFT_AND_RIGHT: { Rect2 region = Rect2(progress_offset + Point2(s.x / 2 - s.x * get_as_ratio() / 2, 0), Size2(s.x * get_as_ratio(), s.y)); @@ -599,6 +599,14 @@ void TextureProgressBar::set_fill_mode(int p_fill) { } mode = (FillMode)p_fill; + +#ifdef TOOLS_ENABLED + // Change the reference cross visibility depending on fill mode. + if (Engine::get_singleton()->is_editor_hint() && reference_cross_marker && reference_cross_marker->is_valid()) { + reference_cross_marker->set_visible((mode == FILL_CLOCKWISE) || (mode == FILL_COUNTER_CLOCKWISE) || (mode == FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE)); + } +#endif + queue_redraw(); notify_property_list_changed(); } @@ -742,4 +750,12 @@ void TextureProgressBar::_bind_methods() { TextureProgressBar::TextureProgressBar() { set_mouse_filter(MOUSE_FILTER_PASS); + +#ifdef TOOLS_ENABLED + // Add `Marker2D` node as the reference cross for radial modes. + if (Engine::get_singleton()->is_editor_hint()) { + reference_cross_marker = memnew(Marker2D); + add_child(reference_cross_marker, false, INTERNAL_MODE_FRONT); + } +#endif } diff --git a/scene/gui/texture_progress_bar.h b/scene/gui/texture_progress_bar.h index d890ce6e3600..fd6a10c98c9d 100644 --- a/scene/gui/texture_progress_bar.h +++ b/scene/gui/texture_progress_bar.h @@ -33,6 +33,10 @@ #include "scene/gui/range.h" +#ifdef TOOLS_ENABLED +#include "scene/2d/marker_2d.h" +#endif + class TextureProgressBar : public Range { GDCLASS(TextureProgressBar, Range); @@ -114,6 +118,10 @@ class TextureProgressBar : public Range { Color tint_progress = Color(1, 1, 1); Color tint_over = Color(1, 1, 1); +#ifdef TOOLS_ENABLED + Marker2D *reference_cross_marker = nullptr; +#endif + void _set_texture(Ref *p_destination, const Ref &p_texture); void _texture_changed(); Point2 unit_val_to_uv(float val);