void MotionEvent::transform(const SkMatrix* matrix) { float oldXOffset = mXOffset; float oldYOffset = mYOffset; // The tricky part of this implementation is to preserve the value of // rawX and rawY. So we apply the transformation to the first point // then derive an appropriate new X/Y offset that will preserve rawX and rawY. SkPoint point; float rawX = getRawX(0); float rawY = getRawY(0); matrix->mapXY(SkFloatToScalar(rawX + oldXOffset), SkFloatToScalar(rawY + oldYOffset), & point); float newX = SkScalarToFloat(point.fX); float newY = SkScalarToFloat(point.fY); float newXOffset = newX - rawX; float newYOffset = newY - rawY; mXOffset = newXOffset; mYOffset = newYOffset; // Apply the transformation to all samples. size_t numSamples = mSamplePointerCoords.size(); for (size_t i = 0; i < numSamples; i++) { PointerCoords& c = mSamplePointerCoords.editItemAt(i); float x = c.getAxisValue(AMOTION_EVENT_AXIS_X) + oldXOffset; float y = c.getAxisValue(AMOTION_EVENT_AXIS_Y) + oldYOffset; matrix->mapXY(SkFloatToScalar(x), SkFloatToScalar(y), &point); c.setAxisValue(AMOTION_EVENT_AXIS_X, SkScalarToFloat(point.fX) - newXOffset); c.setAxisValue(AMOTION_EVENT_AXIS_Y, SkScalarToFloat(point.fY) - newYOffset); float orientation = c.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION); c.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, transformAngle(matrix, orientation)); } }
void MotionEvent::transform(const float matrix[9]) { // The tricky part of this implementation is to preserve the value of // rawX and rawY. So we apply the transformation to the first point // then derive an appropriate new X/Y offset that will preserve rawX // and rawY for that point. float oldXOffset = mXOffset; float oldYOffset = mYOffset; float newX, newY; float rawX = getRawX(0); float rawY = getRawY(0); transformPoint(matrix, rawX + oldXOffset, rawY + oldYOffset, &newX, &newY); mXOffset = newX - rawX; mYOffset = newY - rawY; // Determine how the origin is transformed by the matrix so that we // can transform orientation vectors. float originX, originY; transformPoint(matrix, 0, 0, &originX, &originY); // Apply the transformation to all samples. size_t numSamples = mSamplePointerCoords.size(); for (size_t i = 0; i < numSamples; i++) { PointerCoords& c = mSamplePointerCoords.editItemAt(i); float x = c.getAxisValue(AMOTION_EVENT_AXIS_X) + oldXOffset; float y = c.getAxisValue(AMOTION_EVENT_AXIS_Y) + oldYOffset; transformPoint(matrix, x, y, &x, &y); c.setAxisValue(AMOTION_EVENT_AXIS_X, x - mXOffset); c.setAxisValue(AMOTION_EVENT_AXIS_Y, y - mYOffset); float orientation = c.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION); c.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, transformAngle(matrix, orientation, originX, originY)); } }