/** * update the canvas with latest changes to model drawing. Zoom is managed. Changes performed by * tool are managed. */ @Override protected void onDraw(Canvas canvas) { dLogger.start(); Rect bounds = mModel.getBounds(); Rect dummyBounds = new Rect(); if (bounds != null && canvas.getClipBounds(dummyBounds)) { // Draw current path in a scratch buffer Rect tmp = (Rect) new Rect(mWindowRect); // TODO restore code to manage part of change only. // mCoordinateMapper.fromReference(bounds); // find out what part of the canvas is impacted. tmp.intersect(mWindowRect); // We don't update outside of the screen Rect srcRect = mCoordinateMapper.toReference(tmp); Log.i( "onDraw", "refreshing partial area " + tmp + " from " + srcRect + " clip bounds were " + dummyBounds); mModel.renderTentativeUpdates(mTool, srcRect); // update the impacted part from the corresponding input part. mModel.copyRendered(canvas, srcRect, tmp); } else { Rect srcRect = mCoordinateMapper.toReference(mWindowRect); Log.i("onDraw", "refreshing whole area" + mWindowRect + " from " + srcRect); mModel.copyReference(canvas, srcRect, mWindowRect); } // canvas.drawPath(mPath, mPaint); //TODO all drawing should be performed in reference bitmap dLogger.end(); }
/** * Main method that handles low level touch events and calls the specific methods touch_up, * touch_down, touch_move. */ @Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); float referenceCoords[] = mCoordinateMapper.toReferenceRounded(x, y); mTouchLogger.onTouchEvent(event); // mScaleDetector.onTouchEvent(event); mScrollDetector.onTouchEvent(event); if (!gestureInProgress) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTool.touch_start(referenceCoords[0], referenceCoords[1]); break; case MotionEvent.ACTION_MOVE: mTool.touch_move(referenceCoords[0], referenceCoords[1]); break; case MotionEvent.ACTION_UP: mTool.touch_up(); break; default: Log.w("View", "unrecognized action" + event.getAction()); } if (mModel.getBounds() != null) { invalidate(mCoordinateMapper.fromReference(mModel.getBounds())); // mBounds = null; // invalidate operation is destructive, so the pointer should not be kept } else { invalidate(); } } return true; }