History

add touch event radius

ZappoMan committed 12 years ago

Commit 120807f1 parent 02e6a333 files · +23 −1Browse files

Showing the changes to libraries/script-engine/src/EventTypes.cpp (1 of 3 files). Show all

Unified · Split

libraries/script-engine/src/EventTypes.cpp+21−1
@@ -323,7 +323,8 @@ TouchEvent::TouchEvent() : · 322 unmodified lines
323323 isControl(false),
324324 isMeta(false),
325325 isAlt(false),
326− points()
326+ points(),
327+ radius(0)
327328 {
328329 };
329330
@@ -345,9 +346,27 @@ TouchEvent::TouchEvent(const QTouchEvent& event) { · 15 unmodified lines
345346 }
346347 touchAvgX /= (float)(numTouches);
347348 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();
348354 }
349355 x = touchAvgX;
350356 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+
351370
352371 isPressed = event.touchPointStates().testFlag(Qt::TouchPointPressed);
353372 isMoved = event.touchPointStates().testFlag(Qt::TouchPointMoved);
@@ -382,6 +401,7 @@ QScriptValue touchEventToScriptValue(QScriptEngine* engine, const TouchEvent& ev · 28 unmodified lines
382401 index++;
383402 }
384403 obj.setProperty("points", pointsObj);
404+ obj.setProperty("radius", event.radius);
385405 return obj;
386406 }
387407

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t