Showing the changes to libraries/script-engine/src/EventTypes.cpp (1 of 3 files). Show all
Unified · Split
| @@ -323,7 +323,8 @@ TouchEvent::TouchEvent() : · 322 unmodified lines | ||
| 323 | 323 | isControl(false), |
| 324 | 324 | isMeta(false), |
| 325 | 325 | isAlt(false), |
| 326 | − points() | |
| 326 | + points(), | |
| 327 | + radius(0) | |
| 327 | 328 | { |
| 328 | 329 | }; |
| 329 | 330 | |
| @@ -345,9 +346,27 @@ TouchEvent::TouchEvent(const QTouchEvent& event) { · 15 unmodified lines | ||
| 345 | 346 | } |
| 346 | 347 | touchAvgX /= (float)(numTouches); |
| 347 | 348 | touchAvgY /= (float)(numTouches); |
| 349 | + } else { | |
| 350 | + // I'm not sure this should ever happen, why would Qt send us a touch event for only one point? | |
| 351 | + // maybe this happens in the case of a multi-touch where all but the last finger is released? | |
| 352 | + touchAvgX = tPoints[0].pos().x(); | |
| 353 | + touchAvgY = tPoints[0].pos().y(); | |
| 348 | 354 | } |
| 349 | 355 | x = touchAvgX; |
| 350 | 356 | y = touchAvgY; |
| 357 | + | |
| 358 | + // after calculating the center point (average touch point), determine the maximum radius | |
| 359 | + float maxRadius = 0.0f; | |
| 360 | + glm::vec2 center(x,y); | |
| 361 | + for (int i = 0; i < numTouches; ++i) { | |
| 362 | + glm::vec2 touchPoint(tPoints[i].pos().x(), tPoints[i].pos().y()); | |
| 363 | + float thisRadius = glm::distance(center,touchPoint); | |
| 364 | + if (thisRadius > maxRadius) { | |
| 365 | + maxRadius = thisRadius; | |
| 366 | + } | |
| 367 | + } | |
| 368 | + radius = maxRadius; | |
| 369 | + | |
| 351 | 370 | |
| 352 | 371 | isPressed = event.touchPointStates().testFlag(Qt::TouchPointPressed); |
| 353 | 372 | isMoved = event.touchPointStates().testFlag(Qt::TouchPointMoved); |
| @@ -382,6 +401,7 @@ QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& ev · 28 unmodified lines | ||
| 382 | 401 | index++; |
| 383 | 402 | } |
| 384 | 403 | obj.setProperty("points", pointsObj); |
| 404 | + obj.setProperty("radius", event.radius); | |
| 385 | 405 | return obj; |
| 386 | 406 | } |
| 387 | 407 | |