From 19bc199f302db45e229fb463b1ca1636d7614873 Mon Sep 17 00:00:00 2001 From: Beq Date: Tue, 20 Oct 2020 00:13:00 +0100 Subject: [PATCH] FIRE-30414 - make joystick control work when resized and non-square --- indra/newview/lljoystickbutton.cpp | 50 +++++++++++++++++++++--------- indra/newview/lljoystickbutton.h | 6 ++-- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/indra/newview/lljoystickbutton.cpp b/indra/newview/lljoystickbutton.cpp index e4cef236bd..cacd63624a 100644 --- a/indra/newview/lljoystickbutton.cpp +++ b/indra/newview/lljoystickbutton.cpp @@ -55,7 +55,7 @@ static LLDefaultChildRegistry::Register r6("joystick_quat" const F32 NUDGE_TIME = 0.25f; // in seconds const F32 ORBIT_NUDGE_RATE = 0.05f; // fraction of normal speed -const S32 CENTER_DOT_RADIUS = 7; +//const S32 CENTER_DOT_RADIUS = 7; // FIRE-30414 Camera control arrows not clickable // // Public Methods @@ -145,20 +145,35 @@ bool LLJoystick::pointInCircle(S32 x, S32 y) const return in_circle; } -bool LLJoystick::pointInCenterDot(S32 x, S32 y, S32 radius) const +// FIRE-30414 Camera control arrows not clickable +// bool LLJoystick::pointInCenterDot(S32 x, S32 y, S32 radius) const +// { +// if (this->getLocalRect().getHeight() != this->getLocalRect().getWidth()) +// { +// LL_WARNS() << "Joystick shape is not square" << LL_ENDL; +// return true; +// } + +// S32 center = this->getLocalRect().getHeight() / 2; + +// bool in_center_circle = (x - center) * (x - center) + (y - center) * (y - center) <= radius * radius; + +// return in_center_circle; +// } +bool LLJoystick::pointInCenterDot(S32 x, S32 y) const { - if (this->getLocalRect().getHeight() != this->getLocalRect().getWidth()) - { - LL_WARNS() << "Joystick shape is not square" << LL_ENDL; - return true; - } + constexpr auto center_dot_scale{0.15};// based on current images. + S32 center_dot_x_rad = this->getLocalRect().getWidth()/2*center_dot_scale; + S32 center_dot_y_rad = this->getLocalRect().getHeight()/2*center_dot_scale; + auto a{this->getLocalRect().getCenterX()}; + auto b{this->getLocalRect().getCenterY()}; + // point inside ellipse if result 1 or less. + auto result = ((((x - a)*(x - a)) / (center_dot_x_rad*center_dot_x_rad)) + +(((y - b)*(y - b)) / (center_dot_y_rad*center_dot_y_rad))); - S32 center = this->getLocalRect().getHeight() / 2; - - bool in_center_circle = (x - center) * (x - center) + (y - center) * (y - center) <= radius * radius; - - return in_center_circle; + return result<=1?true:false; } +// BOOL LLJoystick::handleMouseDown(S32 x, S32 y, MASK mask) { @@ -455,8 +470,10 @@ BOOL LLJoystickCameraRotate::handleMouseDown(S32 x, S32 y, MASK mask) S32 dx = x - horiz_center; S32 dy = y - vert_center; - - if (pointInCenterDot(x, y, CENTER_DOT_RADIUS)) + // FIRE-30414 + // if (pointInCenterDot(x, y, CENTER_DOT_RADIUS)) + if (pointInCenterDot(x, y)) + // { mInitialOffset.mX = 0; mInitialOffset.mY = 0; @@ -506,7 +523,10 @@ BOOL LLJoystickCameraRotate::handleMouseUp(S32 x, S32 y, MASK mask) BOOL LLJoystickCameraRotate::handleHover(S32 x, S32 y, MASK mask) { - if (!pointInCenterDot(x, y, CENTER_DOT_RADIUS)) + // FIRE-30414 + // if (!pointInCenterDot(x, y, CENTER_DOT_RADIUS)) + if (!pointInCenterDot(x, y)) + // { mInCenter = FALSE; } diff --git a/indra/newview/lljoystickbutton.h b/indra/newview/lljoystickbutton.h index b7fdf63e58..0647cba0e4 100644 --- a/indra/newview/lljoystickbutton.h +++ b/indra/newview/lljoystickbutton.h @@ -81,8 +81,10 @@ public: * circle. Make sure to change method according to shape other than square. */ bool pointInCircle(S32 x, S32 y) const; - bool pointInCenterDot(S32 x, S32 y, S32 radius) const; - + // FIRE-30414 Camera control arrows not clickable + // bool pointInCenterDot(S32 x, S32 y, S32 radius) const; + bool pointInCenterDot(S32 x, S32 y) const; + // static std::string nameFromQuadrant(const EJoystickQuadrant quadrant); static EJoystickQuadrant quadrantFromName(const std::string& name); static EJoystickQuadrant selectQuadrant(LLXMLNodePtr node);