mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Merge pull request #1434 from vcmi/sdl-2-finger-touch
Handle 2 fingers gesture as rclick via SDL
This commit is contained in:
@@ -206,6 +206,21 @@ void CGuiHandler::handleEvents()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,22 +353,52 @@ 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)
|
||||||
{
|
{
|
||||||
switch(current->button.button)
|
if(!multifinger)
|
||||||
{
|
{
|
||||||
case SDL_BUTTON_LEFT:
|
switch(current->button.button)
|
||||||
handleMouseButtonClick(lclickable, EIntObjMouseBtnType::LEFT, false);
|
{
|
||||||
break;
|
case SDL_BUTTON_LEFT:
|
||||||
case SDL_BUTTON_RIGHT:
|
handleMouseButtonClick(lclickable, EIntObjMouseBtnType::LEFT, false);
|
||||||
handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, false);
|
break;
|
||||||
break;
|
case SDL_BUTTON_RIGHT:
|
||||||
case SDL_BUTTON_MIDDLE:
|
handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, false);
|
||||||
handleMouseButtonClick(mclickable, EIntObjMouseBtnType::MIDDLE, false);
|
break;
|
||||||
break;
|
case SDL_BUTTON_MIDDLE:
|
||||||
|
handleMouseButtonClick(mclickable, EIntObjMouseBtnType::MIDDLE, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifndef VCMI_IOS
|
||||||
|
else if(current->type == SDL_FINGERDOWN)
|
||||||
|
{
|
||||||
|
auto fingerCount = SDL_GetNumTouchFingers(current->tfinger.touchId);
|
||||||
|
|
||||||
|
multifinger = fingerCount > 1;
|
||||||
|
|
||||||
|
if(fingerCount == 2)
|
||||||
|
{
|
||||||
|
convertTouch(current);
|
||||||
|
handleMouseMotion();
|
||||||
|
handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(current->type == SDL_FINGERUP)
|
||||||
|
{
|
||||||
|
auto fingerCount = SDL_GetNumTouchFingers(current->tfinger.touchId);
|
||||||
|
|
||||||
|
if(multifinger)
|
||||||
|
{
|
||||||
|
convertTouch(current);
|
||||||
|
handleMouseMotion();
|
||||||
|
handleMouseButtonClick(rclickable, EIntObjMouseBtnType::RIGHT, false);
|
||||||
|
multifinger = fingerCount != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //VCMI_IOS
|
||||||
|
|
||||||
current = nullptr;
|
current = nullptr;
|
||||||
} //event end
|
} //event end
|
||||||
|
|
||||||
@@ -481,7 +526,8 @@ void CGuiHandler::renderFrame()
|
|||||||
|
|
||||||
|
|
||||||
CGuiHandler::CGuiHandler()
|
CGuiHandler::CGuiHandler()
|
||||||
: lastClick(-500, -500),lastClickTime(0), defActionsDef(0), captureChildren(false)
|
: lastClick(-500, -500),lastClickTime(0), defActionsDef(0), captureChildren(false),
|
||||||
|
multifinger(false)
|
||||||
{
|
{
|
||||||
continueEventHandling = true;
|
continueEventHandling = true;
|
||||||
curInt = nullptr;
|
curInt = nullptr;
|
||||||
|
@@ -101,6 +101,7 @@ public:
|
|||||||
|
|
||||||
Point lastClick;
|
Point lastClick;
|
||||||
unsigned lastClickTime;
|
unsigned lastClickTime;
|
||||||
|
bool multifinger;
|
||||||
|
|
||||||
ui8 defActionsDef; //default auto actions
|
ui8 defActionsDef; //default auto actions
|
||||||
bool captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
|
bool captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
|
||||||
|
@@ -180,7 +180,7 @@ void CTerrainRect::mouseMoved(const SDL_MouseMotionEvent & sEvent)
|
|||||||
void CTerrainRect::handleSwipeMove(const SDL_MouseMotionEvent & sEvent)
|
void CTerrainRect::handleSwipeMove(const SDL_MouseMotionEvent & sEvent)
|
||||||
{
|
{
|
||||||
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
|
#if defined(VCMI_ANDROID) || defined(VCMI_IOS)
|
||||||
if(sEvent.state == 0) // any "button" is enough on mobile
|
if(sEvent.state == 0 || GH.multifinger) // any "button" is enough on mobile
|
||||||
#else
|
#else
|
||||||
if((sEvent.state & SDL_BUTTON_MMASK) == 0) // swipe only works with middle mouse on other platforms
|
if((sEvent.state & SDL_BUTTON_MMASK) == 0) // swipe only works with middle mouse on other platforms
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user