Advertisement
moonlightcheese

wat

Mar 27th, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1.     private boolean onTouchOrHoverEvent(MotionEvent event, boolean isTouch) {
  2.         PaintMode mode = PaintMode.Draw;
  3.         if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0) {
  4.             // Splat paint when the middle mouse button or second stylus button is pressed.
  5.             mode = PaintMode.Splat;
  6.         } else if (isTouch || (buttonState & MotionEvent.BUTTON_PRIMARY) != 0) {
  7.             // Draw paint when touching or if the primary button is pressed.
  8.             mode = PaintMode.Draw;
  9.         } else {
  10.             // Otherwise, do not paint anything.
  11.             return false;
  12.         }
  13.        
  14.         final int action = event.getActionMasked();
  15.         if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE) {
  16.             final int N = event.getHistorySize();
  17.             final int P = event.getPointerCount();
  18.             for (int i = 0; i < N; i++) {
  19.                 for (int j = 0; j < P; j++) {
  20.                     paint(getPaintModeForTool(event.getToolType(j), mode),
  21.                             event.getHistoricalX(j, i),
  22.                             event.getHistoricalY(j, i),
  23.                             event.getHistoricalPressure(j, i),
  24.                             event.getHistoricalTouchMajor(j, i),
  25.                             event.getHistoricalTouchMinor(j, i),
  26.                             event.getHistoricalOrientation(j, i),
  27.                             event.getHistoricalAxisValue(MotionEvent.AXIS_DISTANCE, j, i),
  28.                             event.getHistoricalAxisValue(MotionEvent.AXIS_TILT, j, i));
  29.                 }
  30.             }
  31.         }
  32.        
  33.         return true;
  34.     }
  35.  
  36.     private void paint(PaintMode mode, float x, float y, float pressure,
  37.             float major, float minor, float orientation,
  38.             float distance, float tilt) {
  39.         if (mBitmap != null) {
  40.             if (major <= 0 || minor <= 0) {
  41.                 // If size is not available, use a default value.
  42.                 major = minor = 16;
  43.             }
  44.  
  45.             switch (mode) {
  46.                 case Draw:
  47.                     mPaint.setColor(COLORS[mColorIndex]);
  48.                     mPaint.setAlpha(Math.min((int)(pressure * 128), 255));
  49.                     drawOval(mCanvas, x, y, major, minor, orientation, mPaint);
  50.                     break;
  51.  
  52.                 case Erase:
  53.                     mPaint.setColor(BACKGROUND_COLOR);
  54.                     mPaint.setAlpha(Math.min((int)(pressure * 128), 255));
  55.                     drawOval(mCanvas, x, y, major, minor, orientation, mPaint);
  56.                     break;
  57.  
  58.                 case Splat:
  59.                     mPaint.setColor(COLORS[mColorIndex]);
  60.                     mPaint.setAlpha(64);
  61.                     drawSplat(mCanvas, x, y, orientation, distance, tilt, mPaint);
  62.                     break;
  63.             }
  64.         }
  65.         mFadeSteps = 0;
  66.         invalidate();
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement