From 28a48c048dad0d1b4d4a65ed3d91aac5702e7015 Mon Sep 17 00:00:00 2001 From: Penwywern Date: Fri, 7 Jul 2023 03:22:09 +0200 Subject: [PATCH] UI: Fix rotation handle find angle The angle at which the rotation handle is drawn is independant from the sceneitem's flip. As such, this changes `FindHandleAtPos` to use the rotation angle of the item, free of its flip, instead of doing post-rotation corrections. This fixes a bug where when the item was horizontally flipped, the handle was not "found" at its drawn location. --- UI/window-basic-preview.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/UI/window-basic-preview.cpp b/UI/window-basic-preview.cpp index 8ddb0f44b..340034fec 100644 --- a/UI/window-basic-preview.cpp +++ b/UI/window-basic-preview.cpp @@ -390,24 +390,23 @@ static bool FindHandleAtPos(obs_scene_t * /* scene */, obs_sceneitem_t *item, TestHandle(0.5f, 1.0f, ItemHandle::BottomCenter); TestHandle(1.0f, 1.0f, ItemHandle::BottomRight); + vec2 scale; + obs_sceneitem_get_scale(item, &scale); vec2 rotHandleOffset; vec2_set(&rotHandleOffset, 0.0f, HANDLE_RADIUS * data.radius * 1.5 - data.radius); - RotatePos(&rotHandleOffset, atan2(transform.x.y, transform.x.x)); + float angle = + atan2(scale.x < 0.0f ? transform.x.y * -1.0f : transform.x.y, + scale.x < 0.0f ? transform.x.x * -1.0f : transform.x.x); + RotatePos(&rotHandleOffset, angle); RotatePos(&rotHandleOffset, RAD(data.angleOffset)); - vec2 scale; - obs_sceneitem_get_scale(item, &scale); bool invert = scale.y < 0.0f; vec3 handlePos = GetTransformedPos(0.5f, invert ? 1.0f : 0.0f, transform); vec3_transform(&handlePos, &handlePos, &data.parent_xform); handlePos.x -= rotHandleOffset.x; - - if (scale.x < 0.0f) - handlePos.y += rotHandleOffset.y; - else - handlePos.y -= rotHandleOffset.y; + handlePos.y -= rotHandleOffset.y; float dist = vec3_dist(&handlePos, &pos3); if (dist < data.radius) {