Component::setMouseMoveDistanceTrigger


#1

As in subject, I have components that triggers repaint on mouse move, but they are complex and slow to repaint.
I’m getting a lot of mouse move which lead to no change in repaint, as the mouse hasn’t moved enough.

This is a 2 liner (in Component::handleMouseMove)
if (e.getPosition().getDistanceFrom(lastPos) > moveTriggerThreshold) { mouseMove(e); lastPos = e.getPosition(); }

And the method:
void setMouseMoveDistanceTrigger(const int thresholdInPixels) { moveTriggerThreshold = thresholdInPixels; }

Currently, I’m doing this in my components, but it’s a lot of repeated code, and I think it might be better if centralized.


#2

I’m always reluctant to add any more data members to the Component class, and that sounds far too niche to justify the extra bloat. (I certainly can’t think of any situation where I’d ever have needed it). Surely it’d be ideally done as a simple class, e.g.

class RepainterWhenMouseMoved : public MouseListener { RepainterWhenMouseMoved (Component* comp, int distance); void mouseMoved (const MouseEvent&); };