Daniel Sapoundjiev on
  Position change checking for integer values

Position change checking for integer values

You are still the same!

Where it comes from

We receive notifications from mouse or touchpad that mouse move is occured. But sometimes the position is the same as the previous. And the event for the change comes constantly, no matter if there is a change. This happens only on few computers in my practice. A few laptops. And till now the problem is not revealed.

How we act

It will be good to know if position is changed. We can store the last position and check if the new position is the same. We need to check only one time if position is changed. For that only one class is needed, with one method. The method will accept the new position as arguments and will return true if there is a difference between the new position. Also the method will store the new position as old position.

Cause this method will be invoked on every mouse move, it is better to not create object from this class every time. And the old value will be lost if it is created every time. Also the method must not be static. Cause a few listeners can user it.

This CBL will not automatically attach to something for now! It wil be called manually from source.

Be aware

When the method isChanged is called for first time there is no old value. So this is a special case. It can return always true, aways false or just have some init values for old position to compare to.

Back CBLs menu
Back to main menu