コード例 #1
0
ファイル: Labeller.java プロジェクト: jdeolive/jeo-android
  void render(LineLabel label) {
    tx.reset(canvas);

    String txt = label.getText();

    Paint p = label.get(Paint.class, Paint.class);

    List<LineSegment> path = label.getPath();
    for (int i = 0; i < txt.length(); i++) {
      LineSegment line = path.get(i);

      PointF p0 = tx.getWorldToCanvas().map(line.p0);
      PointF p1 = tx.getWorldToCanvas().map(line.p1);

      double theta = Math.atan((p1.y - p0.y) / (p1.x - p0.x));

      Matrix m = canvas.getMatrix();
      Matrix n = new Matrix(canvas.getMatrix());
      n.preRotate((float) Math.toDegrees(theta), p0.x, p0.y);

      // Paint debug = new Paint();
      // debug.setColor(Color.RED);
      // canvas.drawLine(p0.x, p0.y, p1.x, p1.y, debug);

      canvas.setMatrix(n);
      canvas.drawText(txt, i, i + 1, p0.x, p0.y, p);
      canvas.setMatrix(m);
    }

    tx.apply(canvas);
    // canvas.drawTextOnPath(l.text, l.getPath(), 0, 0, l.get(Paint.class,Paint.class));
  }
コード例 #2
0
  /**
   * fill a path with the paint, and record the dirty area.
   *
   * @param state the current graphics state
   * @param g the graphics into which to draw
   * @param s the path to fill
   */
  public RectF fill(final PDFRenderer state, final Canvas g, final Path s) {
    g.drawPath(s, mainPaint);

    final RectF bounds = new RectF();
    final RectF result = new RectF();
    s.computeBounds(bounds, false);
    g.getMatrix().mapRect(result, bounds);
    return bounds;
  }
コード例 #3
0
  protected void drawMyLocation(
      final Canvas canvas,
      final MapView mapView,
      final Location lastFix,
      final GeoPoint myLocation) {

    final Projection pj = mapView.getProjection();
    pj.toMapPixels(mMyLocation, mMapCoords);

    if (mDrawAccuracyEnabled) {
      final float radius = pj.metersToEquatorPixels(lastFix.getAccuracy());

      mCirclePaint.setAlpha(50);
      mCirclePaint.setStyle(Style.FILL);
      canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, mCirclePaint);

      mCirclePaint.setAlpha(150);
      mCirclePaint.setStyle(Style.STROKE);
      canvas.drawCircle(mMapCoords.x, mMapCoords.y, radius, mCirclePaint);
    }

    canvas.getMatrix(mMatrix);
    mMatrix.getValues(mMatrixValues);

    if (DEBUGMODE) {
      final float tx = (-mMatrixValues[Matrix.MTRANS_X] + 20) / mMatrixValues[Matrix.MSCALE_X];
      final float ty = (-mMatrixValues[Matrix.MTRANS_Y] + 90) / mMatrixValues[Matrix.MSCALE_Y];
      canvas.drawText("Lat: " + lastFix.getLatitude(), tx, ty + 5, mPaint);
      canvas.drawText("Lon: " + lastFix.getLongitude(), tx, ty + 20, mPaint);
      canvas.drawText("Cog: " + lastFix.getBearing(), tx, ty + 35, mPaint);
      canvas.drawText("Acc: " + lastFix.getAccuracy(), tx, ty + 50, mPaint);
      canvas.drawText("Kts: " + lastFix.getSpeed() / 1.94384449, tx, ty + 65, mPaint);
    }

    // TODO: read from compass if available for bearing
    if (lastFix.hasBearing()) {
      /*
       * Rotate the direction-Arrow according to the bearing we are driving. And draw it
       * to the canvas.
       */
      directionRotater.setRotate(
          lastFix.getBearing(), DIRECTION_ARROW_CENTER_X, DIRECTION_ARROW_CENTER_Y);

      directionRotater.postTranslate(-DIRECTION_ARROW_CENTER_X, -DIRECTION_ARROW_CENTER_Y);
      directionRotater.postScale(
          1 / mMatrixValues[Matrix.MSCALE_X], 1 / mMatrixValues[Matrix.MSCALE_Y]);
      directionRotater.postTranslate(mMapCoords.x, mMapCoords.y);
      canvas.drawBitmap(DIRECTION_ARROW, directionRotater, mPaint);
    } else {
      directionRotater.setTranslate(-NULLDIRECTION_ICON_CENTER_X, -NULLDIRECTION_ICON_CENTER_Y);
      directionRotater.postScale(
          1 / mMatrixValues[Matrix.MSCALE_X], 1 / mMatrixValues[Matrix.MSCALE_Y]);
      directionRotater.postTranslate(mMapCoords.x, mMapCoords.y);
      canvas.drawBitmap(NULLDIRECTION_ICON, directionRotater, mPaint);
    }
  }
コード例 #4
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    viewMatrix = canvas.getMatrix();

    canvas.concat(mapRelView);
    for (PanZoomDisplay display : displays) {
      if (display.isEnabled()) {
        display.draw(canvas);
      }
    }

    canvas.setMatrix(viewMatrix);
  }
コード例 #5
0
    @Override
    public Bitmap getTexture(int n) {
      final int textw = TEXTURE_WIDTH;
      final int texth = TEXTURE_HEIGHT;
      final int px = PIXEL_BORDER;

      Bitmap bitmap = Bitmap.createBitmap(textw, texth, Bitmap.Config.ARGB_8888);
      Canvas canvas = new Canvas(bitmap);

      int w = textw;
      int h = texth;

      SoftReference<Bitmap> thumb = null;

      final OpenPath mPath = mPathItems[n];
      mPaint.setColor(0x40808080);

      canvas.drawARGB(0, 0, 0, 0);
      mPaint.setColor(0xffffffff);
      mPaint.setAntiAlias(true);

      if (mPathItems != null
          && (thumb = ThumbnailCreator.generateThumb(mPath, textw, texth, getApplicationContext()))
              != null
          && thumb.get() != null) {
        Bitmap b = thumb.get();
        w = b.getWidth();
        h = b.getHeight();
        // canvas.drawRect(2, 2, w - 2, h - 2, mPaint);
        // canvas.drawRect(px, px, textw - px, texth, mBlackPaint);
        Matrix matrix = canvas.getMatrix();
        matrix.setRectToRect(new RectF(0, 0, w, h), new RectF(0, 0, w, h), ScaleToFit.START);
        canvas.drawBitmap(b, matrix, null);
      } else {
        canvas.drawRect(2, 2, w - 2, h - 2, mPaint);
        mPaint.setTextSize(100.0f);
        if (mPath == null) canvas.drawText("" + n, 2, h - 10, mPaint);
        else {
          mPaint.setTextSize(30f);
          canvas.drawText(mPath.getName(), 2, h - 10, mPaint);
        }
        canvas.drawBitmap(mGlossyOverlay, null, new Rect(px, px, textw - px, texth - px), mPaint);
      }
      return bitmap;
    }
コード例 #6
0
  /**
   * Draw a marker on each of our items. populate() must have been called first.<br>
   * <br>
   * The marker will be drawn twice for each Item in the Overlay--once in the shadow phase, skewed
   * and darkened, then again in the non-shadow phase. The bottom-center of the marker will be
   * aligned with the geographical coordinates of the Item.<br>
   * <br>
   * The order of drawing may be changed by overriding the getIndexToDraw(int) method. An item may
   * provide an alternate marker via its OverlayItem.getMarker(int) method. If that method returns
   * null, the default marker is used.<br>
   * <br>
   * The focused item is always drawn last, which puts it visually on top of the other items.<br>
   *
   * @param c the Canvas upon which to draw. Note that this may already have a transformation
   *     applied, so be sure to leave it the way you found it
   * @param mapView the MapView that requested the draw. Use MapView.getProjection() to convert
   *     between on-screen pixels and latitude/longitude pairs
   * @param shadow if true, draw the shadow layer. If false, draw the overlay contents.
   */
  @Override
  protected void draw(Canvas canvas, MapView mapView, boolean shadow) {

    if (shadow) {
      return;
    }

    if (mPendingFocusChangedEvent && mOnFocusChangeListener != null)
      mOnFocusChangeListener.onFocusChanged(this, mFocusedItem);
    mPendingFocusChangedEvent = false;

    final Projection pj = mapView.getProjection();
    final int size = this.mInternalItemList.size() - 1;

    canvas.getMatrix(mMatrix);
    mMatrix.getValues(mMatrixValues);

    scaleX =
        (float)
            Math.sqrt(
                mMatrixValues[Matrix.MSCALE_X] * mMatrixValues[Matrix.MSCALE_X]
                    + mMatrixValues[Matrix.MSKEW_Y] * mMatrixValues[Matrix.MSKEW_Y]);
    scaleY =
        (float)
            Math.sqrt(
                mMatrixValues[Matrix.MSCALE_Y] * mMatrixValues[Matrix.MSCALE_Y]
                    + mMatrixValues[Matrix.MSKEW_X] * mMatrixValues[Matrix.MSKEW_X]);
    /* Draw in backward cycle, so the items with the least index are on the front. */
    for (int i = size; i >= 0; i--) {
      final Item item = getItem(i);
      if (item == null) {
        continue;
      }

      pj.toPixels(item.getPoint(), mCurScreenCoords);

      onDrawItem(canvas, item, mCurScreenCoords, mapView.getMapOrientation());
    }
  }
コード例 #7
0
ファイル: PieChart.java プロジェクト: knennigtri/LifeWheel
    @Override
    protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);

      if (Build.VERSION.SDK_INT < 11) {
        mTransform.set(canvas.getMatrix());
        mTransform.preRotate(mRotation, mPivot.x, mPivot.y);
        canvas.setMatrix(mTransform);
      }

      for (Item it : mData) {
        mPiePaint.setShader(it.mItemShader);
        cSlicePaint.setShader(it.cSliceShader);
        //                Log.d(TAG, "mBounds: " +mBounds);
        canvas.drawArc(mBounds, 360 - it.mEndAngle, it.mEndAngle - it.mStartAngle, true, mPiePaint);
        Log.d(TAG, "Item Being Built: " + it.mLabel);
        Log.d(TAG, "RectF: " + it.cSliceBounds);
        Log.d(TAG, "StartAngle> " + it.mStartAngle + " EndAngle> " + it.mEndAngle);
        canvas.drawArc(
            it.cSliceBounds, 360 - it.mEndAngle, it.mEndAngle - it.mStartAngle, true, cSlicePaint);
        //                Log.d(TAG, "StartAngle> "+it.mStartAngle+" EndAngle> "+it.mEndAngle);
      }
    }
コード例 #8
0
  @Override
  protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);

    if (mSelectedView != null) {
      getGlobalVisibleRect(mSelectedRect);

      int offsetTop = mSelectedRect.top;
      int offsetLeft = mSelectedRect.left;

      mSelectedView.getGlobalVisibleRect(mSelectedRect);

      if (offsetTop > 0 || offsetLeft > 0) {
        int saveCount = canvas.save();
        Matrix matrix = canvas.getMatrix();
        matrix.postTranslate(offsetLeft, offsetTop);
        canvas.setMatrix(matrix);
        canvas.drawRect(mSelectedRect, mPaint);
        canvas.restoreToCount(saveCount);
      } else {
        canvas.drawRect(mSelectedRect, mPaint);
      }
    }
  }
コード例 #9
0
 public void setCanvas(Canvas canvas) {
   mCanvas = canvas;
   canvas.getMatrix(mMatrix);
 }
コード例 #10
0
    protected void onDraw(Canvas canvas) {
      Matrix m = canvas.getMatrix();

      // Draw a circle around the center.
      Log.d(DEBUG_TAG, "Matrix: " + translate.toShortString());
      Log.d(DEBUG_TAG, "Canvas: " + m.toShortString());

      float[] mtx = new float[9];
      translate.getValues(mtx);

      float x_offset = mtx[Matrix.MTRANS_X];
      float y_offset = mtx[Matrix.MTRANS_Y];

      if (!bowling) {
        // calculateVelocityVector(x_offset, y_offset);
      }

      newCalculateVelocityVector(x_offset, y_offset);

      Paint paint = new Paint();
      paint.setColor(Color.BLUE);
      canvas.drawCircle(center_x, center_y, 10, paint);
      paint.setStyle(Paint.Style.STROKE);
      canvas.drawCircle(center_x, center_y, 100, paint);

      int textLocation = 20;
      if (bowling) {
        canvas.drawText("Let's Bowl!", 0, textLocation, paint);
        textLocation += 20;
      }

      // This renders the motor speeds on the background.
      //			String speedText = "" + speedLeft + ", " + speedRight;
      //			canvas.drawText(speedText, 0, textLocation, paint);
      //			textLocation += 20;
      //			canvas.drawText("" + velocity, 0, textLocation, paint);
      //			textLocation += 20;

      // LinearGradient  Cool bowling alley effect.
      //			int w = getWidth();
      //		    int h = getHeight();
      //			Paint p = new Paint(Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG);
      //			Path pth = new Path();
      //			pth.moveTo(w*0.27f,0);
      //		    pth.lineTo(w*0.73f,0);
      //		    pth.lineTo(w*0.92f,h);
      //		    pth.lineTo(w*0.08f,h);
      //		    pth.lineTo(w*0.27f,0);
      //		    p.setColor(0xff800000);
      //		    p.setShader(new LinearGradient(0,0,0,h,0xff000000,0xffffffff,Shader.TileMode.CLAMP));
      //		    canvas.drawPath(pth,p);

      int leftSideOfRightGauge = getWidth() - 5 - 1;
      int rightSideOfRightGauge = getWidth() - 1;
      int topOfGauge = center_y - 100;
      int bottomOfGauge = center_y + 100;

      drawGauge(canvas, leftSideOfRightGauge, rightSideOfRightGauge, topOfGauge, bottomOfGauge);
      drawGauge(canvas, 0, 5, topOfGauge, bottomOfGauge);

      // Simple gauge
      //			top = center_y - (100 * speedLeft);
      //			canvas.drawRect(0, top, 5, bottom, paint);

      Paint black = new Paint();
      black.setColor(Color.BLACK);

      // Show speed indicators for the left and right motors
      float top = center_y - (100 * speedLeft);
      if (speedLeft == 0) {
        canvas.drawRect(1, bottomOfGauge, 5, center_y + 1, black);
        canvas.drawRect(1, topOfGauge + 1, 5, center_y, black);
      } else if (speedLeft > 0) {
        canvas.drawRect(1, topOfGauge + 1, 5, top + 1, black);
        canvas.drawRect(1, bottomOfGauge, 5, center_y + 1, black);
      } else {
        canvas.drawRect(1, bottomOfGauge, 5, top + 1, black);
        canvas.drawRect(1, topOfGauge + 1, 5, center_y, black);
      }

      // Right motor gauge.  Paint black over the part we don't want to show.
      top = center_y - (100 * speedRight);
      if (speedRight == 0) {
        canvas.drawRect(
            leftSideOfRightGauge + 1, bottomOfGauge, rightSideOfRightGauge, center_y + 1, black);
        canvas.drawRect(
            leftSideOfRightGauge + 1, topOfGauge + 1, rightSideOfRightGauge, center_y, black);
      } else if (speedRight > 0) {
        canvas.drawRect(
            leftSideOfRightGauge + 1, topOfGauge + 1, rightSideOfRightGauge, top + 1, black);
        canvas.drawRect(
            leftSideOfRightGauge + 1, bottomOfGauge, rightSideOfRightGauge, center_y + 1, black);
      } else {
        canvas.drawRect(
            leftSideOfRightGauge + 1, bottomOfGauge, rightSideOfRightGauge, top + 1, black);
        canvas.drawRect(
            leftSideOfRightGauge + 1, topOfGauge + 1, rightSideOfRightGauge, center_y, black);
      }

      canvas.drawBitmap(droid, translate, null);
    }