Joystick behaviour according to spec: Movement starts on joystick, rotation starts from anywhere else

This commit is contained in:
Cristian Luis Duarte 2018-03-10 01:30:44 -03:00
parent b24e574315
commit 67ae6aee33
2 changed files with 58 additions and 25 deletions

View file

@ -240,40 +240,70 @@ void TouchscreenVirtualPadDevice::touchUpdateEvent(const QTouchEvent* event) {
const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints(); const QList<QTouchEvent::TouchPoint>& tPoints = event->touchPoints();
bool moveTouchFound = false; bool moveTouchFound = false;
bool viewTouchFound = false; bool viewTouchFound = false;
int idxMoveStartingPointCandidate = -1;
int idxViewStartingPointCandidate = -1;
bool thisPointConsumed = false;
glm::vec2 thisPoint; glm::vec2 thisPoint;
for (int i = 0; i < _touchPointCount; ++i) { for (int i = 0; i < _touchPointCount; ++i) {
thisPoint.x = tPoints[i].pos().x(); thisPoint.x = tPoints[i].pos().x();
thisPoint.y = tPoints[i].pos().y(); thisPoint.y = tPoints[i].pos().y();
// movew touch and the first one detected counts thisPointConsumed = false;
if (thisPoint.x < _screenWidthCenter && !moveTouchFound) {
if (_moveHasValidTouch) { if (!moveTouchFound && _moveHasValidTouch && _moveCurrentTouchId == tPoints[i].id()) {
// valid if it's an ongoing touch // valid if it's an ongoing touch
moveTouchFound = true; moveTouchFound = true;
moveTouchUpdate(thisPoint); moveTouchUpdate(thisPoint);
} else if (moveTouchBeginIsValid(thisPoint)) { thisPointConsumed = true;
// starting point should be valid }
moveTouchFound = true;
moveTouchBegin(thisPoint); if (thisPointConsumed) continue;
} // if it wasn't even a valid starting point, it won't count as a valid movement touch
} else if (thisPoint.x >= _screenWidthCenter) { // right side if (!viewTouchFound && _viewHasValidTouch && _viewCurrentTouchId == tPoints[i].id()) {
if (!viewTouchFound) { // valid if it's an ongoing touch
viewTouchFound = true; viewTouchFound = true;
if (!_viewHasValidTouch) {
viewTouchBegin(thisPoint);
} else {
// as we don't have a stick on the right side, there is no condition to process right touch
viewTouchUpdate(thisPoint); viewTouchUpdate(thisPoint);
thisPointConsumed = true;
} }
if (thisPointConsumed) continue;
if (!moveTouchFound && idxMoveStartingPointCandidate==-1 && moveTouchBeginIsValid(thisPoint)) {
idxMoveStartingPointCandidate = i;
thisPointConsumed = true;
} }
if (thisPointConsumed) continue;
if (!viewTouchFound && idxViewStartingPointCandidate==-1 && viewTouchBeginIsValid(thisPoint)) {
idxViewStartingPointCandidate = i;
thisPointConsumed = true;
} }
} }
if (!moveTouchFound) { if (!moveTouchFound) {
if (idxMoveStartingPointCandidate!=-1) {
_moveCurrentTouchId = tPoints[idxMoveStartingPointCandidate].id();
moveTouchBegin(thisPoint);
} else {
moveTouchEnd(); moveTouchEnd();
} }
}
if (!viewTouchFound) { if (!viewTouchFound) {
if (idxViewStartingPointCandidate!=-1) {
_viewCurrentTouchId = tPoints[idxViewStartingPointCandidate].id();
viewTouchBegin(thisPoint);
} else {
viewTouchEnd(); viewTouchEnd();
} }
} }
}
bool TouchscreenVirtualPadDevice::viewTouchBeginIsValid(glm::vec2 touchPoint) {
return !moveTouchBeginIsValid(touchPoint);
}
bool TouchscreenVirtualPadDevice::moveTouchBeginIsValid(glm::vec2 touchPoint) { bool TouchscreenVirtualPadDevice::moveTouchBeginIsValid(glm::vec2 touchPoint) {
if (_fixedPosition) { if (_fixedPosition) {

View file

@ -71,10 +71,12 @@ protected:
bool _moveHasValidTouch; bool _moveHasValidTouch;
glm::vec2 _moveRefTouchPoint; glm::vec2 _moveRefTouchPoint;
glm::vec2 _moveCurrentTouchPoint; glm::vec2 _moveCurrentTouchPoint;
int _moveCurrentTouchId;
bool _viewHasValidTouch; bool _viewHasValidTouch;
glm::vec2 _viewRefTouchPoint; glm::vec2 _viewRefTouchPoint;
glm::vec2 _viewCurrentTouchPoint; glm::vec2 _viewCurrentTouchPoint;
int _viewCurrentTouchId;
int _touchPointCount; int _touchPointCount;
int _screenWidthCenter; int _screenWidthCenter;
@ -94,6 +96,7 @@ protected:
void viewTouchBegin(glm::vec2 touchPoint); void viewTouchBegin(glm::vec2 touchPoint);
void viewTouchUpdate(glm::vec2 touchPoint); void viewTouchUpdate(glm::vec2 touchPoint);
void viewTouchEnd(); void viewTouchEnd();
bool viewTouchBeginIsValid(glm::vec2 touchPoint);
void setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force = false); void setupFixedCenter(VirtualPad::Manager& virtualPadManager, bool force = false);