widget position

How can I position a widget in a specific area (just above the red line in the image)? I’ve already made progress setting the location of the widget on the screen by taking the location of an actor in the world. Now I’m trying to make the widget only stay on a specific line like a spline like in the image.

I guess you want to achieve a function where the UI can only move within the range of the elliptical red line, right? Then you need to know the formula for an elliptical curve and set the widget’s coordinates inside the ellipse.

I couldn’t find anything about how to make an elliptical curve or anything like that … would it be something done with onpaint?

What I mean is that if you want to have an elliptical picture on a canvas panel, it can absolutely be achieved with an image. However, if you want to ensure that a certain widget stays within the ellipse, this is guaranteed by an algorithm. The formula for an ellipse is x^2/a^2 + y^2/b^2 = 1, where a and b are the lengths of the major and minor axes, respectively, as shown in the diagram below.

When you know a certain X, you can naturally calculate the value of Y, which has two possible values, one positive and one negative. Assuming the mouse’s coordinate position on the canvas is now (X1,Y1), which exceeds the boundary of the ellipse, you can substitute X1 into the ellipse equation to calculate the values of Y2 and −Y2. If the value of Y1 satisfies the condition −Y2≤Y1≤Y2, then it proves that Y1 is within the ellipse. If not, the position of the control is limited to the value of Y2. This ensures that your control can only move within the ellipse.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.