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 00bacb9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 16 additions & 3 deletions scene/gui/texture_progress_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ void TextureProgressBar::_notification(int p_what) {
}
}

// Draw a reference cross.
// Change position of the reference cross node.
if (Engine::get_singleton()->is_editor_hint()) {
Point2 p;

Expand All @@ -548,8 +548,8 @@ 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);

crosshair_marker->set_position(p);
}
} break;
case FILL_BILINEAR_LEFT_AND_RIGHT: {
Expand Down Expand Up @@ -599,6 +599,14 @@ void TextureProgressBar::set_fill_mode(int p_fill) {
}

mode = (FillMode)p_fill;

// Change the reference cross visibility depending on fill mode.
if (Engine::get_singleton()->is_editor_hint() && ((mode == FILL_CLOCKWISE) || (mode == FILL_COUNTER_CLOCKWISE) || (mode == FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE))) {
crosshair_marker->set_visible(true);
} else {
crosshair_marker->set_visible(false);
}

queue_redraw();
notify_property_list_changed();
}
Expand Down Expand Up @@ -742,4 +750,9 @@ void TextureProgressBar::_bind_methods() {

TextureProgressBar::TextureProgressBar() {
set_mouse_filter(MOUSE_FILTER_PASS);
if (Engine::get_singleton()->is_editor_hint()) {
crosshair_marker = memnew(Marker2D);
crosshair_marker->set_visible(false);
}
add_child(crosshair_marker, false, INTERNAL_MODE_FRONT);
}
3 changes: 3 additions & 0 deletions scene/gui/texture_progress_bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#ifndef TEXTURE_PROGRESS_BAR_H
#define TEXTURE_PROGRESS_BAR_H

#include "scene/2d/marker_2d.h"
#include "scene/gui/range.h"

class TextureProgressBar : public Range {
Expand Down Expand Up @@ -114,6 +115,8 @@ class TextureProgressBar : public Range {
Color tint_progress = Color(1, 1, 1);
Color tint_over = Color(1, 1, 1);

Marker2D *crosshair_marker = nullptr;

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 00bacb9

Please sign in to comment.