mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-03 00:46:55 +02:00
Handle 2 fingers gesture as rclick via SDL
This commit is contained in:
@ -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()
|
void CGuiHandler::handleCurrentEvent()
|
||||||
{
|
{
|
||||||
if(current->type == SDL_KEYDOWN || current->type == SDL_KEYUP)
|
if(current->type == SDL_KEYDOWN || current->type == SDL_KEYUP)
|
||||||
@ -338,8 +356,13 @@ void CGuiHandler::handleCurrentEvent()
|
|||||||
it->textEdited(current->edit);
|
it->textEdited(current->edit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//todo: muiltitouch
|
|
||||||
else if(current->type == SDL_MOUSEBUTTONUP)
|
else if(current->type == SDL_MOUSEBUTTONUP)
|
||||||
|
{
|
||||||
|
if(multifinger && lastFingerCount >= 1)
|
||||||
|
{
|
||||||
|
multifinger = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
switch(current->button.button)
|
switch(current->button.button)
|
||||||
{
|
{
|
||||||
@ -354,6 +377,33 @@ void CGuiHandler::handleCurrentEvent()
|
|||||||
break;
|
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;
|
current = nullptr;
|
||||||
} //event end
|
} //event end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user