1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-09 13:14:02 +02:00

Handle 2 fingers gesture as rclick via SDL

This commit is contained in:
Andrii Danylchenko 2023-01-07 10:15:32 +02:00
parent 9f0eb055f9
commit 7ccfcf51e9

View File

@ -206,6 +206,24 @@ void CGuiHandler::handleEvents()
}
}
bool multifinger = false;
int lastFingerCount;
void convertTouch(SDL_Event * current)
{
int rLogicalWidth, rLogicalHeight;
SDL_RenderGetLogicalSize(mainRenderer, &rLogicalWidth, &rLogicalHeight);
int adjustedMouseY = (int)(current->tfinger.y * rLogicalHeight);
int adjustedMouseX = (int)(current->tfinger.x * rLogicalWidth);
current->button.x = adjustedMouseX;
current->motion.x = adjustedMouseX;
current->button.y = adjustedMouseY;
current->motion.y = adjustedMouseY;
}
void CGuiHandler::handleCurrentEvent()
{
if(current->type == SDL_KEYDOWN || current->type == SDL_KEYUP)
@ -338,8 +356,13 @@ void CGuiHandler::handleCurrentEvent()
it->textEdited(current->edit);
}
}
//todo: muiltitouch
else if(current->type == SDL_MOUSEBUTTONUP)
{
if(multifinger && lastFingerCount >= 1)
{
multifinger = false;
}
else
{
switch(current->button.button)
{
@ -354,6 +377,33 @@ void CGuiHandler::handleCurrentEvent()
break;
}
}
}
else if(current->type == SDL_FINGERDOWN)
{
lastFingerCount = SDL_GetNumTouchFingers(current->tfinger.touchId);
multifinger = lastFingerCount > 1;
if(lastFingerCount == 2)
{
convertTouch(current);
handleMouseMotion();
handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, true);
}
}
else if(current->type == SDL_FINGERUP)
{
lastFingerCount = SDL_GetNumTouchFingers(current->tfinger.touchId);
if(multifinger)
{
multifinger = false;
convertTouch(current);
handleMouseMotion();
handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, false);
}
}
current = nullptr;
} //event end