Skip to content

Commit eea3bd1

Browse files
authored
Merge pull request #209 from AyaneStorm/pr-fix-camera-floater
fix clicking outside camera joystick_rotate triggered rotation with non-square shape
2 parents c5f429d + a61b754 commit eea3bd1

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

indra/newview/lljoystickbutton.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,32 @@ void LLJoystick::updateSlop()
134134

135135
bool LLJoystick::pointInCircle(S32 x, S32 y) const
136136
{
137-
if(this->getLocalRect().getHeight() != this->getLocalRect().getWidth())
138-
{
139-
LL_DEBUGS() << "Joystick shape is not square"<<LL_ENDL;
140-
return true;
141-
}
142-
//center is x and y coordinates of center of joystick circle, and also its radius
143-
int center = this->getLocalRect().getHeight()/2;
144-
bool in_circle = (x - center) * (x - center) + (y - center) * (y - center) <= center * center;
145-
146-
return in_circle;
137+
// <FS:Chanayane> Fix joystick accepting clicks outside its circular shape when non-square
138+
// Original code assumed a square widget; if not square it accepted all clicks as a fallback,
139+
// causing camera rotation to trigger anywhere in the bounding rect.
140+
// Replaced with an ellipse test so non-square widgets are handled correctly.
141+
//if(this->getLocalRect().getHeight() != this->getLocalRect().getWidth())
142+
//{
143+
// LL_DEBUGS() << "Joystick shape is not square"<<LL_ENDL;
144+
// return true;
145+
//}
146+
////center is x and y coordinates of center of joystick circle, and also its radius
147+
//int center = this->getLocalRect().getHeight()/2;
148+
//bool in_circle = (x - center) * (x - center) + (y - center) * (y - center) <= center * center;
149+
//return in_circle;
150+
151+
// Point-in-ellipse test: (dx/a)^2 + (dy/b)^2 <= 1
152+
// where a and b are the horizontal and vertical semi-axes (half width/height).
153+
F32 a = this->getLocalRect().getWidth() / 2.f;
154+
F32 b = this->getLocalRect().getHeight() / 2.f;
155+
if (a == 0.f || b == 0.f)
156+
{
157+
return false;
158+
}
159+
F32 dx = x - a;
160+
F32 dy = y - b;
161+
return (dx * dx) / (a * a) + (dy * dy) / (b * b) <= 1.f;
162+
// </FS:Chanayane>
147163
}
148164

149165
// <FS:Beq> FIRE-30414 Camera control arrows not clickable

0 commit comments

Comments
 (0)