Custom slider mouseevent handling

Trying to create a slider with custom mouseevent handling (drag only works while over the slider, initial mouseDown doesn’t need to happen inside the slider) My custom slider class inherits from slider, and I have tried two approaches:
1, overriding mouseMove & checking isMouseDown(), but isMouseDown() never returns true if the initial mouseDown doesn’t happen inside this component (per the docs)
2. overriding mouseDrag & checking isMouseOver(), but isMouseOver() never returns true for me if the initial mouseDown happens outside this component (also, per the docs)

Is there a better pattern to use here? Is it even advisable to inherit from slider directly?

IsMouseButtonDownAnywhere() also doesn’t seem to work for this purpose, unsure why

Solved this problem by implementing mouseDrag at the parent component’s level and sending mouseDrags registered by its children to it (do not want to setInterceptMouseClicks(true,false) because I would like to preserve child’s other functionality)

Child mouseDrag:

void mouseDrag(const MouseEvent& e) override {
getParentComponent()->mouseDrag(e.getEventRelativeTo(getParentComponent()));
}

Parent mouseDrag:

void ProbCurveEditorComponent::mouseDrag(const MouseEvent& e)
{
int sliderOver = jlimit(0, processor.mp.numSliders - 1, (int) floor(e.position.x / (getWidth() / ((double)processor.mp.numSliders))));
sliders[sliderOver]->setValue(((double) getHeight() - (double) e.position.y) / ((double) getHeight()));
}

the children are overridden sliders stored in the sliders array, I calculate the index of the slider the mouseEvent is over & manipulate the slider my mouse is currently over, regardless of which slider the gesture began over. Now I can do this in a single gesture:

curveEditorSingleDrag

Would still like to know if it’s possible to do this in the scope of the child, however?

1 Like

I looked into this today and this thread was helpful, thanks!

Would still like to know if it’s possible to do this in the scope of the child, however?

From what I could tell, the mouse events are infrequent enough (at least on macos) that it wouldn’t be possible to implement at the child level. In fact, I had to implement interpolation, otherwise when the mouse moved moves quickly, a chunk of sliders would be skipped over between events.

Since I don’t care about other events on the children, I set the parent component to setInterceptsMouseClicks(true, false) However, I also had to set slider->setInterceptsMouseClicks(false, false) on each child, otherwise sometimes the child would capture the event.

For interpolation, I store a lastPosition member variable and iterate linearly over any sliders between the last drag event position and the current drag event position.

Did you not have to do any interpolation to get the nice fluid behavior in your image? Looks good!