There is another method that we widely use that is not related to any math at all and can handle extremely complex embedded controls of any shape whatsoever. Just use the screen image of the control with all the color-coded parts (as shown in the figure below) that the user could click.
When they move their mouse, just look at the color of the pixel under the mouse on our screen image, and this definitely indicates which button / control they are crossed out - white for not above it, and any color series for different parts.
Color mask
// pseudo code
function MouseOverControl(LocalMousePos:TPoint):ControlID; begin //sanity check Result:=IDNull; if (LocalMouse.X < 0) or (LocalMouse.X > ControlWidth) or (LocalMouse.Y < 0) or (LocalMouse.Y > ControlHeight) then exit; case OffScreenControlMask.Canvas.Pixels[LocalMousePos.X,LocalMousePos.Y] of clwhite:exit; clRed:result:=ControlIDOne; clGreen:result:=ControlIDTwo; clBlue:result:=ControlIDThree; ... etc end; end;
NOTE. The attached Color Mask image represents five identical rotary controls, divided into quadrants with a central button (and since they all use the same colors, we have constants for each color and we determine which of the five mice is simple XPosition) along with an additional irregular controls on the right and dials or rectangular buttons at the bottom.
Byte player
source share