Skip to content

Commit

Permalink
Only show reference cross in TextureProgressBar when the node is sele…
Browse files Browse the repository at this point in the history
…cted

This reduces visual obstruction in the editor.

Additionally, the cross' width no longer scales with zoom, improving
visibility at high zoom levels.
  • Loading branch information
Calinou committed Nov 25, 2024
1 parent 0c45ace commit f86048a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions scene/gui/texture_progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

#include "core/config/engine.h"

#ifdef TOOLS_ENABLED
#include "editor/editor_node.h"
#endif

void TextureProgressBar::set_under_texture(const Ref<Texture2D> &p_texture) {
_set_texture(&under, p_texture);
}
Expand Down Expand Up @@ -535,8 +539,9 @@ void TextureProgressBar::_notification(int p_what) {
}
}

// Draw a reference cross.
if (Engine::get_singleton()->is_editor_hint()) {
#ifdef TOOLS_ENABLED
// Draw a reference cross when the node is selected in the editor.
if (Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton()->get_editor_selection()->is_selected(this)) {
Point2 p;

if (nine_patch_stretch) {
Expand All @@ -548,9 +553,11 @@ 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);
// Draw the cross with a shadow for each line, for better visibility on mixed backgrounds.
draw_line(p - Point2(8, 0), p + Point2(8, 0), Color(0.9, 0.5, 0.5));
draw_line(p - Point2(0, 8), p + Point2(0, 8), Color(0.9, 0.5, 0.5));
}
#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 @@ -742,4 +749,8 @@ void TextureProgressBar::_bind_methods() {

TextureProgressBar::TextureProgressBar() {
set_mouse_filter(MOUSE_FILTER_PASS);

#ifdef TOOLS_ENABLED
EditorNode::get_singleton()->get_editor_selection()->connect(SNAME("selection_changed"), callable_mp((CanvasItem *)this, &CanvasItem::queue_redraw));
#endif
}

0 comments on commit f86048a

Please sign in to comment.