forked from Mirrors/openclonk
SDL: Fix mouse button handling
- The right mouse button didn't work at all. - The left mouse button stopped working when clicking multiple times without moving the cursor.liquid_container
parent
392b7bab72
commit
f505b31032
|
@ -31,45 +31,20 @@
|
|||
|
||||
static void sdlToC4MCBtn(const SDL_MouseButtonEvent &e, int32_t& button, DWORD& flags)
|
||||
{
|
||||
C4TimeMilliseconds lastLeftClick = C4TimeMilliseconds::Now();
|
||||
C4TimeMilliseconds lastRightClick = C4TimeMilliseconds::Now();
|
||||
static int32_t lastX, lastY;
|
||||
|
||||
static const int clickDist = 2;
|
||||
static const int clickDelay = 400;
|
||||
|
||||
button = C4MC_Button_None;
|
||||
flags = 0;
|
||||
flags = SDL_GetModState();
|
||||
|
||||
switch (e.button)
|
||||
{
|
||||
case SDL_BUTTON_LEFT:
|
||||
if (e.state == SDL_PRESSED)
|
||||
if (C4TimeMilliseconds::Now() - lastLeftClick < clickDelay && abs(lastX-e.x) <= clickDist && abs(lastY-e.y) <= clickDist)
|
||||
{
|
||||
lastLeftClick = 0;
|
||||
button = C4MC_Button_LeftDouble;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastLeftClick = C4TimeMilliseconds::Now();
|
||||
button = C4MC_Button_LeftDown;
|
||||
}
|
||||
button = e.clicks == 2 ? C4MC_Button_LeftDouble : C4MC_Button_LeftDown;
|
||||
else
|
||||
button = C4MC_Button_LeftUp;
|
||||
break;
|
||||
case SDL_BUTTON_RIGHT:
|
||||
if (e.state == SDL_PRESSED)
|
||||
if (C4TimeMilliseconds::Now() - lastRightClick < clickDelay)
|
||||
{
|
||||
lastRightClick = 0;
|
||||
button = C4MC_Button_RightDouble;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastRightClick = C4TimeMilliseconds::Now();
|
||||
button = C4MC_Button_RightDown;
|
||||
}
|
||||
button = e.clicks == 2 ? C4MC_Button_RightDouble : C4MC_Button_RightDown;
|
||||
else
|
||||
button = C4MC_Button_RightUp;
|
||||
break;
|
||||
|
@ -80,8 +55,6 @@ static void sdlToC4MCBtn(const SDL_MouseButtonEvent &e, int32_t& button, DWORD&
|
|||
button = C4MC_Button_MiddleUp;
|
||||
break;
|
||||
}
|
||||
lastX = e.x;
|
||||
lastY = e.y;
|
||||
}
|
||||
|
||||
/* C4AbstractApp */
|
||||
|
|
Loading…
Reference in New Issue