Showing the changes to libraries/script-engine/src/EventTypes.cpp (1 of 5 files). Show all
Unified · Split
| @@ -323,14 +323,16 @@ TouchEvent::TouchEvent() : · 322 unmodified lines | ||
| 323 | 323 | isControl(false), |
| 324 | 324 | isMeta(false), |
| 325 | 325 | isAlt(false), |
| 326 | + touchPoints(0), | |
| 326 | 327 | points(), |
| 327 | 328 | radius(0.0f), |
| 328 | 329 | isPinching(false), |
| 329 | 330 | isPinchOpening(false), |
| 330 | 331 | angles(), |
| 331 | 332 | angle(0.0f), |
| 332 | − rotatingClockwise(false), | |
| 333 | − rotatingCounterClockwise(false) | |
| 333 | + deltaAngle(0.0f), | |
| 334 | + isRotating(false), | |
| 335 | + rotating("none") | |
| 334 | 336 | { |
| 335 | 337 | }; |
| 336 | 338 | |
| @@ -359,9 +361,9 @@ void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) { · 22 unmodified lines | ||
| 359 | 361 | const QList<QTouchEvent::TouchPoint>& tPoints = event.touchPoints(); |
| 360 | 362 | float touchAvgX = 0.0f; |
| 361 | 363 | float touchAvgY = 0.0f; |
| 362 | − int numTouches = tPoints.count(); | |
| 363 | − if (numTouches > 1) { | |
| 364 | − for (int i = 0; i < numTouches; ++i) { | |
| 364 | + touchPoints = tPoints.count(); | |
| 365 | + if (touchPoints > 1) { | |
| 366 | + for (int i = 0; i < touchPoints; ++i) { | |
| 365 | 367 | touchAvgX += tPoints[i].pos().x(); |
| 366 | 368 | touchAvgY += tPoints[i].pos().y(); |
| 367 | 369 | |
| @@ -369,8 +371,8 @@ void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) { · 1 unmodified line | ||
| 369 | 371 | glm::vec2 thisPoint(tPoints[i].pos().x(), tPoints[i].pos().y()); |
| 370 | 372 | points << thisPoint; |
| 371 | 373 | } |
| 372 | − touchAvgX /= (float)(numTouches); | |
| 373 | − touchAvgY /= (float)(numTouches); | |
| 374 | + touchAvgX /= (float)(touchPoints); | |
| 375 | + touchAvgY /= (float)(touchPoints); | |
| 374 | 376 | } else { |
| 375 | 377 | // I'm not sure this should ever happen, why would Qt send us a touch event for only one point? |
| 376 | 378 | // maybe this happens in the case of a multi-touch where all but the last finger is released? |
| @@ -384,7 +386,7 @@ void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) { · 7 unmodified lines | ||
| 384 | 386 | // also calculate the rotation angle for each point |
| 385 | 387 | float maxRadius = 0.0f; |
| 386 | 388 | glm::vec2 center(x,y); |
| 387 | − for (int i = 0; i < numTouches; ++i) { | |
| 389 | + for (int i = 0; i < touchPoints; ++i) { | |
| 388 | 390 | glm::vec2 touchPoint(tPoints[i].pos().x(), tPoints[i].pos().y()); |
| 389 | 391 | float thisRadius = glm::distance(center,touchPoint); |
| 390 | 392 | if (thisRadius > maxRadius) { |
| @@ -397,13 +399,12 @@ void TouchEvent::initWithQTouchEvent(const QTouchEvent& event) { · 6 unmodified lines | ||
| 397 | 399 | } |
| 398 | 400 | radius = maxRadius; |
| 399 | 401 | |
| 400 | − // after calculating the center point (average touch point), determine the maximum radius | |
| 402 | + // after calculating the angles for each touch point, determine the average angle | |
| 401 | 403 | float totalAngle = 0.0f; |
| 402 | − for (int i = 0; i < numTouches; ++i) { | |
| 404 | + for (int i = 0; i < touchPoints; ++i) { | |
| 403 | 405 | totalAngle += angles[i]; |
| 404 | 406 | } |
| 405 | − angle = totalAngle/numTouches; | |
| 406 | − | |
| 407 | + angle = totalAngle/(float)touchPoints; | |
| 407 | 408 | |
| 408 | 409 | isPressed = event.touchPointStates().testFlag(Qt::TouchPointPressed); |
| 409 | 410 | isMoved = event.touchPointStates().testFlag(Qt::TouchPointMoved); |
| @@ -431,15 +432,16 @@ void TouchEvent::calculateMetaAttributes(const TouchEvent& other) { · 21 unmodified lines | ||
| 431 | 432 | } |
| 432 | 433 | |
| 433 | 434 | // determine if the points are rotating... |
| 435 | + deltaAngle = angle - other.angle; | |
| 434 | 436 | if (other.angle < angle) { |
| 435 | − rotatingClockwise = true; | |
| 436 | − rotatingCounterClockwise = false; | |
| 437 | + isRotating = true; | |
| 438 | + rotating = "clockwise"; | |
| 437 | 439 | } else if (other.angle > angle) { |
| 438 | − rotatingClockwise = false; | |
| 439 | − rotatingCounterClockwise = true; | |
| 440 | + isRotating = true; | |
| 441 | + rotating = "counterClockwise"; | |
| 440 | 442 | } else { |
| 441 | − rotatingClockwise = false; | |
| 442 | − rotatingCounterClockwise = false; | |
| 443 | + isRotating = false; | |
| 444 | + rotating = "none"; | |
| 443 | 445 | } |
| 444 | 446 | } |
| 445 | 447 | |
| @@ -456,6 +458,7 @@ QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& ev · 10 unmodified lines | ||
| 456 | 458 | obj.setProperty("isMeta", event.isMeta); |
| 457 | 459 | obj.setProperty("isControl", event.isControl); |
| 458 | 460 | obj.setProperty("isAlt", event.isAlt); |
| 461 | + obj.setProperty("touchPoints", event.touchPoints); | |
| 459 | 462 | |
| 460 | 463 | QScriptValue pointsObj = engine->newArray(); |
| 461 | 464 | int index = 0; |
| @@ -470,6 +473,7 @@ QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& ev · 8 unmodified lines | ||
| 470 | 473 | obj.setProperty("isPinchOpening", event.isPinchOpening); |
| 471 | 474 | |
| 472 | 475 | obj.setProperty("angle", event.angle); |
| 476 | + obj.setProperty("deltaAngle", event.deltaAngle); | |
| 473 | 477 | QScriptValue anglesObj = engine->newArray(); |
| 474 | 478 | index = 0; |
| 475 | 479 | foreach (float angle, event.angles) { |
| @@ -478,8 +482,8 @@ QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& ev · 2 unmodified lines | ||
| 478 | 482 | } |
| 479 | 483 | obj.setProperty("angles", anglesObj); |
| 480 | 484 | |
| 481 | − obj.setProperty("rotatingClockwise", event.rotatingClockwise); | |
| 482 | − obj.setProperty("rotatingCounterClockwise", event.rotatingCounterClockwise); | |
| 485 | + obj.setProperty("isRotating", event.isRotating); | |
| 486 | + obj.setProperty("rotating", event.rotating); | |
| 483 | 487 | return obj; |
| 484 | 488 | } |
| 485 | 489 | |