Skip to content

Commit cd46dfd

Browse files
committed
Visual feedback update for viewport rotation gizmo.
Adjusted highlight behavior for positive axes and added negative axis labels.
1 parent fc523ec commit cd46dfd

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

editor/plugins/node_3d_editor_plugin.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,13 @@ void ViewportRotationControl::_draw_axis(const Axis2D &p_axis) {
343343
const Color axis_color = axis_colors[direction];
344344
const double min_alpha = 0.35;
345345
const double alpha = focused ? 1.0 : Math::remap((p_axis.z_axis + 1.0) / 2.0, 0, 0.5, min_alpha, 1.0);
346-
const Color c = focused ? Color(axis_color.lightened(0.75), 1.0) : Color(axis_color, alpha);
346+
const Color c = focused ? Color(axis_color.lightened(0.25), 1.0) : Color(axis_color, alpha);
347+
348+
// Highlight positive axis text when hovered.
349+
const Color c_positive_axis = focused ? Color(1.0, 1.0, 1.0, alpha) : Color(0.0, 0.0, 0.0, alpha * 0.6);
350+
351+
// Highlight negative axis text when hovered, but hide when not focused.
352+
const Color c_negative_axis = focused ? Color(1.0, 1.0, 1.0, alpha) : Color(axis_color, 0);
347353

348354
if (positive) {
349355
// Draw axis lines for the positive axes.
@@ -361,11 +367,22 @@ void ViewportRotationControl::_draw_axis(const Axis2D &p_axis) {
361367
const int font_size = get_theme_font_size(SNAME("rotation_control_size"), EditorStringName(EditorFonts));
362368
const Size2 char_size = font->get_char_size(axis_name[0], font_size);
363369
const Vector2 char_offset = Vector2(-char_size.width / 2.0, char_size.height * 0.25);
364-
draw_char(font, p_axis.screen_point + char_offset, axis_name, font_size, Color(0.0, 0.0, 0.0, alpha * 0.6));
370+
draw_char(font, p_axis.screen_point + char_offset, axis_name, font_size, c_positive_axis);
365371
} else {
366372
// Draw an outline around the negative axes.
367373
draw_circle(p_axis.screen_point, AXIS_CIRCLE_RADIUS, c, true, -1.0, true);
368374
draw_circle(p_axis.screen_point, AXIS_CIRCLE_RADIUS * 0.8, c.darkened(0.4), true, -1.0, true);
375+
376+
// Draw the text for the negative axes.
377+
const String axis_name = direction == 0 ? "-X" : (direction == 1 ? "-Y" : "-Z");
378+
const Ref<Font> &font = get_theme_font(SNAME("rotation_control"), EditorStringName(EditorFonts));
379+
const int font_size = get_theme_font_size(SNAME("rotation_control_size"), EditorStringName(EditorFonts));
380+
const Size2 string_size = font->get_string_size(axis_name, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, font_size);
381+
const float font_ascent = font->get_ascent(font_size);
382+
const float font_descent = font->get_descent(font_size);
383+
const float string_height = font_ascent + font_descent;
384+
const Vector2 offset(-string_size.width / 2.0, string_height * 0.25);
385+
draw_string(font, p_axis.screen_point + offset, axis_name, HORIZONTAL_ALIGNMENT_LEFT, -1.0f, font_size, c_negative_axis);
369386
}
370387
}
371388

0 commit comments

Comments
 (0)