I booted up Alleg today for the first time in probably a couple of years, and this issue was bugging the hell out of me.
Enough that I downloaded the source code and took a peek.
Bear in mind my experience with C++ and unmanaged languages is somewhere between minimal and non-existent. Although I do know a thing or two about C# and other managed languages.
So please correct me if I'm getting the wrong idea somewhere.
The problem is that in the click handling code, the IsDoubleClick() function is returning True for a single click. Which is preventing a bunch of single click code from running, and breaking buttons.
Whenever you perform a click, it stores the time this most recent click was made.
Whenever you move the mouse it clears this last click time.
If a second click is performed within 0.25 seconds of the previous click time, then it should count as a double click.
Simple enough.
The Time class stores a DWORD (unsigned long, which apparently in c++ is the same as an unsigned int? Odd, but whatever). Which can range from 0 to 4,294,967,295.
We assign the current time using the WINAPI timeGetTime() function, which returns the number of milliseconds since windows was started. Apparently wrapping back around to 0 when it goes past the limit (which takes just under 50 days). In my case it's currently around 2,229,916,287 (it seems that the hybrid shutdown used on modern windows machines doesn't reset it).
Maybe this means something time related breaks once every 50 days, but that's not a huge problem.
Now in the Time class we also have a bunch of overloaded operators for comparing different times together. Here's the one for checking whether your time is greater than another time.
Code: Select all
inline bool operator > (const Time t) const
{
return ((int)(m_dwTime - t.m_dwTime) > 0);
}
That's subtracting an unsigned int from an unsigned int, then casting it to a signed int.
If the result of the subtraction is greater than 2,147,483,647 then it's going to result in a negative number.
This means that if windows was last started more than 25 days ago, every click is a double click (unless you very carefully do not move the mouse between mouse down and mouse up). Whoops

.