summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
authorvolzhs <volzhs@gmail.com>2019-10-25 04:19:11 +0900
committervolzhs <volzhs@gmail.com>2019-10-25 05:19:13 +0900
commit4beeb0fc0f9f5c51c91d3d90cc745dd21c483de4 (patch)
tree87f48bab8e9f5a2226e0ea4e2960a6f585af2918 /editor/plugins
parent982774e639ad4c98aa9459cd029c505b01fee4a8 (diff)
Fix ruler origin is moving with zoom
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index f9a7b7caf1..84372a6f93 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -2274,7 +2274,7 @@ bool CanvasItemEditor::_gui_input_ruler_tool(const Ref<InputEvent> &p_event) {
Point2 previous_origin = ruler_tool_origin;
if (!ruler_tool_active)
- ruler_tool_origin = snap_point(viewport->get_local_mouse_position() / zoom + view_offset) * zoom;
+ ruler_tool_origin = snap_point(viewport->get_local_mouse_position() / zoom + view_offset);
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT) {
if (b->is_pressed()) {
@@ -2694,12 +2694,12 @@ void CanvasItemEditor::_draw_ruler_tool() {
Color ruler_secondary_color = ruler_primary_color;
ruler_secondary_color.a = 0.5;
- Point2 begin = ruler_tool_origin - view_offset * zoom;
+ Point2 begin = (ruler_tool_origin - view_offset) * zoom;
Point2 end = snap_point(viewport->get_local_mouse_position() / zoom + view_offset) * zoom - view_offset * zoom;
Point2 corner = Point2(begin.x, end.y);
Vector2 length_vector = (begin - end).abs() / zoom;
- bool draw_secondary_lines = (begin.y != corner.y && end.x != corner.x);
+ 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) {
@@ -2796,11 +2796,11 @@ void CanvasItemEditor::_draw_ruler_tool() {
Point2 text_pos2 = text_pos;
text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2);
- viewport->draw_string(font, text_pos2, vformat("%d units", (int)(length_vector.y / grid_step.y)), font_secondary_color);
+ viewport->draw_string(font, text_pos2, vformat("%d units", roundf(length_vector.y / grid_step.y)), font_secondary_color);
text_pos2 = text_pos;
text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y + text_height / 2) : MAX(text_pos.y + text_height * 2, end.y + text_height / 2);
- viewport->draw_string(font, text_pos2, vformat("%d units", (int)(length_vector.x / grid_step.x)), font_secondary_color);
+ viewport->draw_string(font, text_pos2, vformat("%d units", roundf(length_vector.x / grid_step.x)), font_secondary_color);
} else {
viewport->draw_string(font, text_pos, vformat("%d units", roundf((length_vector / grid_step).length())), font_color);
}
@@ -2809,7 +2809,7 @@ void CanvasItemEditor::_draw_ruler_tool() {
if (is_snap_active) {
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);
+ viewport->draw_texture(get_icon("EditorPosition", "EditorIcons"), (ruler_tool_origin - view_offset) * zoom - position_icon->get_size() / 2);
}
}
}