@Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int count = mPagesCount;
    if (count == 0) {
      return;
    }
    float cx = canvas.getWidth() >> 1;
    float cy = canvas.getHeight() >> 1;
    int totalCount = 2 * count - 1;
    int halfCount = totalCount / 2;
    float itemWithOffset = mIndicatorElementSize + mIndicatorElementSpacing;
    float halfItemWithOffset = mIndicatorElementSize / 2 + mIndicatorElementSpacing;
    float halfSize = mIndicatorElementSize / 2f;
    float halfSpacing = mIndicatorElementSpacing / 2f;
    float startX = cx - halfCount * (mIndicatorElementSize + mIndicatorElementSpacing);
    float top = cy - halfSize;
    float bottom = cy + halfSize;
    // if we have odd elements - need to set indicators in center
    if (totalCount % 2 != 0) {
      startX -= halfSize + halfSpacing;
    }

    int i;
    for (i = 0; i < totalCount; i++) {
      // skip empty spaces
      if (i % 2 != 0) {
        continue;
      }
      float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * i;
      float right = left + mIndicatorElementSize;
      mElementBounds.set(left, top, right, bottom);
      mRenderer.draw(canvas, mElementBounds, mIndicatorPaint, false);
    }

    // multiply on 2 because there are spaces between elements
    float activeItemOffset = (mSelectedPosition + mScrolledOffset) * 2;
    float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * activeItemOffset;
    float right = left + mIndicatorElementSize;
    mElementBounds.set(left, top, right, bottom);

    canvas.clipRect(mClipBounds);

    canvas.save();
    canvas.rotate(ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY());
    mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true);
    canvas.restore();

    if (mIsInfiniteScroll && mSelectedPosition == mPagesCount - 1) { // isInfinite && isEnd
      activeItemOffset = (1f - mScrolledOffset) * 2;
      left = mClipBounds.left - itemWithOffset * activeItemOffset + halfItemWithOffset;
      right = left + mIndicatorElementSize;
      mElementBounds.set(left, top, right, bottom);
      canvas.save();
      canvas.rotate(
          ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY());
      mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true);
      canvas.restore();
    }
  }
Exemple #2
0
  /**
   * Draws everything onto the main panel.
   *
   * @param page Graphics component to draw on
   */
  public void paintComponent(Graphics page) {
    super.paintComponent(page);
    setForeground(Color.cyan);

    renderer.draw(page, this, offX, offY);

    //        hero.draw(this, page, offX, offY);

    for (Entity effect : effects) {
      effect.draw(this, page, offX, offY);
      /*if (effect instanceof Burst) {
          Burst pop = (Burst) effect;
          pop.draw(this, page, offX, offY);
      }*/
    }

    // Draw hero position information
    Rectangle r = hero.getBounds();
    page.drawString("Position: x = " + (r.x + (r.width >> 1)), SCORE_PLACE_X, SCORE_PLACE_Y);
    final int tab = 100;
    final int lineHeight = 20;
    page.drawString("y = " + (r.y + (r.height >> 1)), SCORE_PLACE_X + tab, SCORE_PLACE_Y);
    page.drawString("Frame: " + frame, SCORE_PLACE_X, SCORE_PLACE_Y + lineHeight);

    if (!running) {
      page.drawString("Game over :(", WIDTH / 2, HEIGHT / 2);
    }
  }
Exemple #3
0
  private void loop() {
    Timer timer = new Timer();

    while (!renderer.shouldClose()) {
      while (timer.shouldUpdateGame()) {
        timer.update();
        update();
      }

      renderer.draw();
    }
  }
 @Override
 public void draw(Canvas canvas) {
   super.draw(canvas);
   if (mClients == null) return;
   boolean redraw = false;
   for (Renderer renderer : mClients) {
     renderer.draw(canvas);
     redraw = redraw || ((OverlayRenderer) renderer).isVisible();
   }
   if (redraw) {
     invalidate();
   }
 }
Exemple #5
0
 public void draw(Renderer r) {
   r.draw(this);
 }