Android Open Source - Gloomy-Dungeons-3D Numeric Sprite






From Project

Back to project page Gloomy-Dungeons-3D.

License

The source code is released under:

MIT License

If you think the Android project Gloomy-Dungeons-3D listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2008 The Android Open Source Project
 */*from w  w  w  . j a v  a  2s.c  om*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package zame.libs;

import android.graphics.Paint;
import javax.microedition.khronos.opengles.GL10;

public class NumericSprite
{
  public NumericSprite()
  {
    mLabelMaker = null;

    mDigits[0] = 0;
    mDigitsCount = 1;
  }

  public void initialize(GL10 gl, Paint paint)
  {
    int height = roundUpPower2((int)paint.getFontSpacing());
    final float interDigitGaps = 9 * 1.0f;
    int width = roundUpPower2((int)(interDigitGaps + paint.measureText(sStrike)));

    mLabelMaker = new LabelMaker(true, width, height);
    mLabelMaker.initialize(gl);
    mLabelMaker.beginAdding(gl);

    for (int i = 0; i < 10; i++)
    {
      String digit = sStrike.substring(i, i+1);
      mLabelId[i] = mLabelMaker.add(gl, digit, paint);
      mWidth[i] = (int)Math.ceil(mLabelMaker.getWidth(i));
    }

    mLabelMaker.endAdding(gl);
  }

  public void shutdown(GL10 gl)
  {
    mLabelMaker.shutdown(gl);
    mLabelMaker = null;
  }

  /**
   * Find the smallest power of two >= the input value.
   * (Doesn't work for negative numbers.)
   */
  private int roundUpPower2(int x)
  {
    x = x - 1;
    x = x | (x >> 1);
    x = x | (x >> 2);
    x = x | (x >> 4);
    x = x | (x >> 8);
    x = x | (x >>16);

    return x + 1;
  }

  public void setValue(int value)
  {
    mDigitsCount = 0;

    do
    {
      mDigits[mDigitsCount++] = value % 10;
      value /= 10;
    } while ((value > 0) && (mDigitsCount < sMaxDigits));
  }

  public void draw(GL10 gl, float x, float y, float viewWidth, float viewHeight)
  {
    mLabelMaker.beginDrawing(gl, viewWidth, viewHeight);

    for (int pos = mDigitsCount-1; pos >= 0; pos--)
    {
      mLabelMaker.draw(gl, x, y, mLabelId[mDigits[pos]]);
      x += mWidth[mDigits[pos]];
    }

    mLabelMaker.endDrawing(gl);
  }

  public float width()
  {
    float width = 0.0f;

    for (int i = 0; i < mDigitsCount; i++) {
      width += mWidth[mDigits[i]];
    }

    return width;
  }

  private int[] mDigits = new int[sMaxDigits];
  private int mDigitsCount = 0;

  private LabelMaker mLabelMaker;
  private int[] mWidth = new int[10];
  private int[] mLabelId = new int[10];

  private final static String sStrike = "0123456789";
  private final static int sMaxDigits = 10;
}




Java Source Code List

zame.game.AppConfig.java
zame.game.AppConfig.java
zame.game.Common.java
zame.game.ConfigZeemote.java
zame.game.ConfigZeemote.java
zame.game.Config.java
zame.game.GameActivityZeemoteHelper.java
zame.game.GameActivityZeemoteHelper.java
zame.game.GameActivity.java
zame.game.GamePreferencesActivity.java
zame.game.GamePreferencesActivity.java
zame.game.MenuActivityHelper.java
zame.game.MenuActivityHelper.java
zame.game.MenuActivity.java
zame.game.Renderer.java
zame.game.SoundManager.java
zame.game.ZameApplicationAnalyticsHelper.java
zame.game.ZameApplicationAnalyticsHelper.java
zame.game.ZameApplication.java
zame.game.ZameGame.java
zame.game.ZameJniRenderer.java
zame.game.engine.Action.java
zame.game.engine.AutoWall.java
zame.game.engine.Controls.java
zame.game.engine.Door.java
zame.game.engine.GameHelper.java
zame.game.engine.GameHelper.java
zame.game.engine.Game.java
zame.game.engine.Labels.java
zame.game.engine.LevelConfig.java
zame.game.engine.LevelRenderer.java
zame.game.engine.Level.java
zame.game.engine.Mark.java
zame.game.engine.Monster.java
zame.game.engine.Overlay.java
zame.game.engine.PortalTracer.java
zame.game.engine.State.java
zame.game.engine.Stats.java
zame.game.engine.TextureLoader.java
zame.game.engine.Weapons.java
zame.game.views.EndLevelView.java
zame.game.views.GameOverView.java
zame.game.views.GameView.java
zame.game.views.IZameView.java
zame.game.views.MenuViewHelper.java
zame.game.views.MenuViewHelper.java
zame.game.views.MenuView.java
zame.game.views.PreLevelView.java
zame.game.views.ZameGameView.java
zame.libs.FrameLayout.java
zame.libs.GLSurfaceView21.java
zame.libs.Grid.java
zame.libs.KeyMapPreference.java
zame.libs.LabelMaker.java
zame.libs.ListPreference.java
zame.libs.NumericSprite.java
zame.libs.SeekBarPreference.java
zame.promo.PromoView.java