summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorOsama El Hariri <osama@localhost.localdomain>2019-10-06 17:19:13 +0300
committerOsama El Hariri <osama@localhost.localdomain>2019-10-06 18:04:49 +0300
commit90ea3787ecc7ba62b637fc1f176976dd2346fdb1 (patch)
treeaea45062ac13d30704d402c5fc77c85fc0f51254 /editor
parent1d9233c3882afe888b9396f7f2aac917d4dcac4d (diff)
Add angle to ruler tool
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index b7d36ce75a..7055abd643 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -2708,6 +2708,7 @@ void CanvasItemEditor::_draw_ruler_tool() {
font_secondary_color.a = 0.5;
float text_height = font->get_height();
const float text_width = 76;
+ const float angle_text_width = 54;
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);
@@ -2715,14 +2716,38 @@ void CanvasItemEditor::_draw_ruler_tool() {
viewport->draw_string(font, text_pos, vformat("%.2f px", length_vector.length()), font_color);
if (draw_secondary_lines) {
+ int horizontal_axis_angle = round(180 * atan2(length_vector.y, length_vector.x) / Math_PI);
+ int vertictal_axis_angle = 90 - horizontal_axis_angle;
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("%.2f px", length_vector.y), font_secondary_color);
+ Point2 v_angle_text_pos = Point2();
+ v_angle_text_pos.x = CLAMP(begin.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width);
+ v_angle_text_pos.y = begin.y < end.y ? MIN(text_pos2.y - 2 * text_height, begin.y - text_height * 0.5) : MAX(text_pos2.y + text_height * 3, begin.y + text_height * 1.5);
+ viewport->draw_string(font, v_angle_text_pos, vformat("%d deg", vertictal_axis_angle), 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("%.2f px", length_vector.x), font_secondary_color);
+
+ Point2 h_angle_text_pos = Point2();
+ h_angle_text_pos.x = CLAMP(end.x - angle_text_width / 2, angle_text_width / 2, viewport->get_rect().size.x - angle_text_width);
+ if (begin.y < end.y) {
+ h_angle_text_pos.y = end.y + text_height * 1.5;
+ if (ABS(text_pos2.x - h_angle_text_pos.x) < text_width) {
+ int height_multiplier = 1.5 + (int)is_snap_active;
+ h_angle_text_pos.y = MAX(text_pos.y + height_multiplier * text_height, MAX(end.y + text_height * 1.5, text_pos2.y + height_multiplier * text_height));
+ }
+ } else {
+ h_angle_text_pos.y = end.y - text_height * 0.5;
+ if (ABS(text_pos2.x - h_angle_text_pos.x) < text_width) {
+ int height_multiplier = 1 + (int)is_snap_active;
+ h_angle_text_pos.y = MIN(text_pos.y - height_multiplier * text_height, MIN(end.y - text_height * 0.5, text_pos2.y - height_multiplier * text_height));
+ }
+ }
+ viewport->draw_string(font, h_angle_text_pos, vformat("%d deg", horizontal_axis_angle), font_secondary_color);
}
if (is_snap_active) {