Inconsistent getDistanceFromDragStartX


#1

Hello, I just have this simple piece of code:

void ComponentXYZ::mouseDrag(const MouseEvent &e) { DBG(e.getDistanceFromDragStartX()); }

While dragging I can see the distance in the console. However on mouseUp() (There isn’t any code on mouseUp) it seems that the value changes a bit (usually ±1) without move the mouse at all. This happens aproximately the 25% of times you do it: when you stop dragging there is some extra distance added.

ie: You start dragging and you stop the mouse at ‘596’. Don’t move the mouse and release the mouse button and the value will be ‘597’ or similar.

Is this a bug? what could i do?


#2

I think the most likely explanation is that you did actually move the mouse.

But even if the OS is sending coordinates that vary slightly, so what? It’s a mouse, you’ve got to expect it to wobble around a bit!


#3

I’m not using a mouse but the laptop’s touchpad with two buttons (left&right) close to it, so it’s impossible move the cursor if you released the touchpad. The problem is that I made a custom scrollbar (not inherited) and one pixel can means a lot. So after move the scroll bar and place it in the desired position I release the touchpad (until now everything is fine) and after that I release the left button and the scrollbar moves 1 extra pixels, what’s a bigger value for the scrolbar values (1 pixel could means a value of 50 or more!).

btw I’m on WinXP Home SP3 and Visual C++ 2010 Express


#4

Wow. That sounds like a major design flaw. How would I use it with my graphics tablet, where it’s impossible to lift the pen without moving at least 5-10 pixels?

The OS supplies the position, and I’m pretty sure that my code doesn’t randomly add or subtract 1 from it. Maybe your mouse driver is deliberately nudging the value to force a mouse cursor update or something weird.


#5

Well, i made it the best I can :slight_smile:

Think in juce’s scrollbar, when I said “one pixel can means a lot”, I wanted to mean rangelimit between 0 and 1e8, where the screen only have around 1e3 pixels, then 1 real pixel would be 100.000!

Anyway tomorrow I’m going to test a simple component with MouseDrag overwritten as I show above in a couple of PCs too see if I have the same effect, to make sure it’s a driver related problem.

Thanks