Skip to content

Commit

Permalink
TextureProgressBar crosshair as Marker2D
Browse files Browse the repository at this point in the history
  • Loading branch information
arkology committed Nov 23, 2024
1 parent fd4c29a commit 3d5db96
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
28 changes: 22 additions & 6 deletions scene/gui/texture_progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
Expand Down Expand Up @@ -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()) {

Check failure on line 605 in scene/gui/texture_progress_bar.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

'class Marker2D' has no member named 'is_valid'

Check failure on line 605 in scene/gui/texture_progress_bar.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

'class Marker2D' has no member named 'is_valid'

Check failure on line 605 in scene/gui/texture_progress_bar.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

no member named 'is_valid' in 'Marker2D'

Check failure on line 605 in scene/gui/texture_progress_bar.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'is_valid': is not a member of 'Marker2D'

Check failure on line 605 in scene/gui/texture_progress_bar.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

no member named 'is_valid' in 'Marker2D'
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();
}
Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions scene/gui/texture_progress_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<Texture2D> *p_destination, const Ref<Texture2D> &p_texture);
void _texture_changed();
Point2 unit_val_to_uv(float val);
Expand Down

0 comments on commit 3d5db96

Please sign in to comment.