iOS: fix bug when reporting the screen position of touch events
The way we reported screen position (and normalized position) for touch events was just wrong. The old implementation did not take into account that a view could be anything else than a direct child of the window, which fails for many cases (e.g when using QGLWidgets). Nor did it take into account the status bar, which made it hard to push small buttons since the touch would always be slightly offset. This patch calculates the screen pos by converting the touch pos to window pos, and then subtract the application frame (that contains the size of the status bar). Change-Id: Ib7f5f6dcea3a611e1ed75d57fb4a4718564752f0 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@digia.com>
This commit is contained in:
parent
2b02d9b064
commit
c30a7ecce1
@ -150,6 +150,8 @@
|
|||||||
|
|
||||||
- (void)updateTouchList:(NSSet *)touches withState:(Qt::TouchPointState)state
|
- (void)updateTouchList:(NSSet *)touches withState:(Qt::TouchPointState)state
|
||||||
{
|
{
|
||||||
|
QRect applicationRect = fromCGRect(self.window.screen.applicationFrame);
|
||||||
|
|
||||||
foreach (UITouch *uiTouch, m_activeTouches.keys()) {
|
foreach (UITouch *uiTouch, m_activeTouches.keys()) {
|
||||||
QWindowSystemInterface::TouchPoint &touchPoint = m_activeTouches[uiTouch];
|
QWindowSystemInterface::TouchPoint &touchPoint = m_activeTouches[uiTouch];
|
||||||
if (![touches containsObject:uiTouch]) {
|
if (![touches containsObject:uiTouch]) {
|
||||||
@ -158,14 +160,12 @@
|
|||||||
touchPoint.state = state;
|
touchPoint.state = state;
|
||||||
touchPoint.pressure = (state == Qt::TouchPointReleased) ? 0.0 : 1.0;
|
touchPoint.pressure = (state == Qt::TouchPointReleased) ? 0.0 : 1.0;
|
||||||
|
|
||||||
// Set position
|
// Find the touch position relative to the window. Then calculate the screen
|
||||||
QRect viewGeometry = fromCGRect(self.frame);
|
// position by subtracting the position of the applicationRect (since UIWindow
|
||||||
QPoint touchViewLocation = fromCGPoint([uiTouch locationInView:self]);
|
// does not take that into account when reporting its own frame):
|
||||||
QPoint touchScreenLocation = touchViewLocation + viewGeometry.topLeft();
|
QPoint touchPos = fromCGPoint([uiTouch locationInView:nil]);
|
||||||
touchPoint.area = QRectF(touchScreenLocation , QSize(0, 0));
|
touchPoint.area = QRectF(touchPos - applicationRect.topLeft(), QSize(0, 0));
|
||||||
|
touchPoint.normalPosition = QPointF(touchPos.x() / applicationRect.width(), touchPos.y() / applicationRect.height());
|
||||||
CGSize fullscreenSize = self.window.rootViewController.view.bounds.size;
|
|
||||||
touchPoint.normalPosition = QPointF(touchScreenLocation.x() / fullscreenSize.width, touchScreenLocation.y() / fullscreenSize.height);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user