Пример #1
0
  @Override
  public void draw(Canvas canvas) {

    Color currColor = canvas.getColor();

    canvas.setColor(Color.GREEN);
    int width = mRect.widht() * mHealth / mMaxHelth;
    glPushMatrix();
    glTranslated(mX, mY, 0);
    glBegin(GL_QUADS);
    glVertex2d(1, 1);
    glVertex2d(width, 1);
    glVertex2d(width, mRect.height() - 1);
    glVertex2d(1, mRect.height() - 1);
    glEnd();
    glTranslated(0, 0, 0);
    glPopMatrix();
    canvas.setColor(currColor);

    canvas.setColor(Color.RED);
    glPushMatrix();
    glTranslated(mX, mY, 0);
    glBegin(GL_QUADS);
    glVertex2d(1, 1);
    glVertex2d(mRect.widht() - 1, 1);
    glVertex2d(mRect.widht() - 1, mRect.height() - 1);
    glVertex2d(1, mRect.height() - 1);
    glEnd();
    glTranslated(0, 0, 0);
    glPopMatrix();
    canvas.setColor(currColor);

    super.draw(canvas);
  }
Пример #2
0
 @Override
 public void draw(Canvas canvas) {
   Color currColor = canvas.getColor();
   canvas.setColor(mColor);
   int centerX = mX + mRadius;
   int centerY = mY + mRadius;
   double twicePi = 2.0 * Math.PI;
   glPushMatrix();
   glBegin(GL_TRIANGLE_FAN); // BEGIN ROUND
   glVertex2f(centerX, centerY); // center of circle
   for (int i = 0; i <= ROUND_DRAWING_ACCURACY; i++) {
     glVertex2f(
         (float) (centerX + (mRadius * Math.cos(i * twicePi / ROUND_DRAWING_ACCURACY))),
         (float) (centerY + (mRadius * Math.sin(i * twicePi / ROUND_DRAWING_ACCURACY))));
   }
   glEnd(); // END
   glPopMatrix();
   canvas.setColor(currColor);
 }