Is it possible to set the bounds for a mouse click to something different (smaller) than the bounds for drawing a component? I’d like to be able to have a knob of button with a glow or highlight outside the button/knob/slider click area. Do I have to relegate that glow/highlight to the parent of my button/knob/slider, or is there a way to have different bounds for drawing versus clicking? Currently, I have artwork for the components that has a transparent area around the actual component, and draw my glow/highlight there, but that allows users to click on the glowing/highlighted area to operate the control, which is not what I really want in some cases. It looks like I need a parent component that is larger than the control that contains the control itself, and have that parent redraw the highlight/glow as needed. Is that correct?
You can check also in MouseEvent
what are mouse coordinates and do nothing when they are outside required area.
1 Like
Override hitTest
, this gives you a circular area where the knob/slider/button reacts to the mouse:
bool hitTest(int x, int y) override
{
x = x - cX;
y = y - cY;
auto dist = sqrt(x * x + y * y);
return (dist < limit);
}
and I add another method
void setHitArea(const int x, const int y, const float max)
{
cX = x;
cY = y;
limit = max;
}
2 Likes
N.B. point has nice methods for that:
Point<float> centre;
float limit = 0;
void setHitArea (Point<float> p, const float max)
{
centre = p;
limit = max;
}
bool hitTest(int x, int y) override
{
return centre.getDistanceFrom ({x, y}) < limit;
}
2 Likes
Great responses, friends! Will implement that hit test stuff for sure! Exactly what I needed.