Show mouse position when clicking ruler tool

(cherry picked from commit 0f7d7c9ffb)
This commit is contained in:
kobewi 2021-11-07 00:00:52 +01:00 committed by Rémi Verschelde
parent ad5cb8ef5e
commit eef08ea3e0
No known key found for this signature in database
GPG key ID: C3336907360768E1

View file

@ -3109,14 +3109,6 @@ void CanvasItemEditor::_draw_ruler_tool() {
Point2 corner = Point2(begin.x, end.y);
Vector2 length_vector = (begin - end).abs() / zoom;
bool draw_secondary_lines = !(Math::is_equal_approx(begin.y, corner.y) || Math::is_equal_approx(end.x, corner.x));
viewport->draw_line(begin, end, ruler_primary_color, Math::round(EDSCALE * 3), true);
if (draw_secondary_lines) {
viewport->draw_line(begin, corner, ruler_secondary_color, Math::round(EDSCALE));
viewport->draw_line(corner, end, ruler_secondary_color, Math::round(EDSCALE));
}
Ref<Font> font = get_font("bold", "EditorFonts");
Color font_color = get_color("font_color", "Editor");
Color font_secondary_color = font_color;
@ -3128,8 +3120,24 @@ void CanvasItemEditor::_draw_ruler_tool() {
Point2 text_pos = (begin + end) / 2 - Vector2(text_width / 2, text_height / 2);
text_pos.x = CLAMP(text_pos.x, text_width / 2, viewport->get_rect().size.x - text_width * 1.5);
text_pos.y = CLAMP(text_pos.y, text_height * 1.5, viewport->get_rect().size.y - text_height * 1.5);
if (begin.is_equal_approx(end)) {
viewport->draw_string(font, text_pos, (String)ruler_tool_origin, font_color);
Ref<Texture> position_icon = get_icon("EditorPosition", "EditorIcons");
viewport->draw_texture(get_icon("EditorPosition", "EditorIcons"), (ruler_tool_origin - view_offset) * zoom - position_icon->get_size() / 2);
return;
}
viewport->draw_string(font, text_pos, vformat("%.1f px", length_vector.length()), font_color);
bool draw_secondary_lines = !(Math::is_equal_approx(begin.y, corner.y) || Math::is_equal_approx(end.x, corner.x));
viewport->draw_line(begin, end, ruler_primary_color, Math::round(EDSCALE * 3));
if (draw_secondary_lines) {
viewport->draw_line(begin, corner, ruler_secondary_color, Math::round(EDSCALE));
viewport->draw_line(corner, end, ruler_secondary_color, Math::round(EDSCALE));
}
if (draw_secondary_lines) {
const float horizontal_angle_rad = atan2(length_vector.y, length_vector.x);
const float vertical_angle_rad = Math_PI / 2.0 - horizontal_angle_rad;