/** Set the position and scale of the dragged/stretched image. */ public boolean setPositionAndScale( Img img, PositionAndScale newImgPosAndScale, PointInfo touchPoint) { currTouchPoint.set(touchPoint); boolean ok = img.setPos(newImgPosAndScale); if (ok) invalidate(); return ok; }
/** * Select an object for dragging. Called whenever an object is found to be under the point * (non-null is returned by getDraggableObjectAtPoint()) and a drag operation is starting. Called * with null when drag op ends. */ public void selectObject(Img img, PointInfo touchPoint) { currTouchPoint.set(touchPoint); if (img != null) { // Move image to the top of the stack when selected mImages.remove(img); mImages.add(img); } else { // Called with img == null when drag stops. } invalidate(); }
/*----------------------setPositionAndScale--------------------------------------------------------------------*/ public boolean setPositionAndScale(KiwiGLSurfaceView obj, PositionAndScale pos, PointInfo info) { Log.d(TAG, "setPositionAndScale"); if (this.mLastTouchInfo == null) { this.mLastTouchInfo = new PointInfo(); this.mLastTouchInfo.set(info); return true; } this.mCurrentTouchInfo.set(info); boolean isMulti = mLastTouchInfo.isMultiTouch(); float dx = mCurrentTouchInfo.getX() - mLastTouchInfo.getX(); float dy = mCurrentTouchInfo.getY() - mLastTouchInfo.getY(); float x1 = mCurrentTouchInfo.getX(); float y1 = mCurrentTouchInfo.getY(); float x0 = x1 - dx; float y0 = y1 + dy; float scale = 1.0f; float angle = 0.0f; if (isMulti && mLastTouchInfo.getMultiTouchDiameter() != 0.0f) { scale = mCurrentTouchInfo.getMultiTouchDiameter() / mLastTouchInfo.getMultiTouchDiameter(); } if (isMulti) { angle = mCurrentTouchInfo.getMultiTouchAngle() - mLastTouchInfo.getMultiTouchAngle(); } MyRunnable myrun = new MyRunnable(); myrun.dx = dx; myrun.dy = dy; myrun.x0 = x0; myrun.y0 = y0; myrun.x1 = x1; myrun.y1 = y1; myrun.scale = scale; myrun.angle = angle; myrun.isMulti = isMulti; this.queueEvent(myrun); mLastTouchInfo.set(mCurrentTouchInfo); return true; }
/** @param touchPoint */ private void touchPointChanged(PointInfo touchPoint) { mCurrTouchPoint.set(touchPoint); invalidate(); }