Android Open Source - candymem Base Text






From Project

Back to project page candymem.

License

The source code is released under:

GNU General Public License

If you think the Android project candymem 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

package se.tube42.lib.item;
/*  w w  w  .j ava  2s.c om*/
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.*;

import se.tube42.lib.tweeny.*;
import se.tube42.lib.ks.*;
import se.tube42.lib.scene.*;

public class BaseText extends BaseItem
{

    private String text;
    private BitmapFont font;
    private float alignv, alignh;
    private int mw;

    public BaseText(BitmapFont font)
    {
        this.font = font;
        setText("");
        setAlignment(0, 0);
        setMaxWidth(0);
    }

    public void setMaxWidth(int mw)
    {
        this.mw = mw;
        calcBounds();
    }

    public void setText(String text)
    {
        this.text = text;
        calcBounds();
    }

    public String getText()
    {
        return text;
    }

    public BitmapFont getFont()
    {
        return font;
    }

    public void setAlignment(float ah, float av)
    {
        alignh = ah;
        alignv = av;
        calcBounds();
    }

    public void calcBounds()
    {
        if(text != null) {
            BitmapFont.TextBounds tb;
            if(mw > 0) {
                tb = font.getWrappedBounds(text, mw);
            } else {
                tb = font.getBounds(text);
            }
            h = tb.height;
            w = tb.width;
        } else {
            w = h = 1;
        }
    }

    // --------------------------------------------

    public void draw(SpriteBatch sb)
    {
        if(this.text != null) {
            draw_text(sb,
                      getX() + alignh * w,
                      getY() + alignv * h
                      );
        }
    }

    protected void draw_text(SpriteBatch sb, float x, float y)
    {
        font.setColor( cr, cg, cb, getAlpha());
        if(mw > 0) {
            font.drawWrapped(sb, text, x, y, mw);
        } else {
            font.draw(sb, text, x, y);
        }
    }

    public boolean hit(float x, float y)
    {
        // special hit function for text that uses alignments
        final float x0 = getX() + alignh * w;
        final float y0 = getY() + alignh * h;
        final float x1 = x0 + w;
        final float y1 = y0 + h;
        return x >= x0 && x <= x1 && y >= y0 && y <= y1;
    }

}




Java Source Code List

com.badlogic.gdx.backends.lwjgl.LwjglApplication.java
se.tube42.kidsmem.KidsMemoryApp.java
se.tube42.kidsmem.SystemHandler.java
se.tube42.kidsmem.android.MainActivity.java
se.tube42.kidsmem.data.Assets.java
se.tube42.kidsmem.data.Constants.java
se.tube42.kidsmem.data.Settings.java
se.tube42.kidsmem.data.UI.java
se.tube42.kidsmem.data.World.java
se.tube42.kidsmem.desktop.DesktopMain.java
se.tube42.kidsmem.item.Button.java
se.tube42.kidsmem.item.FireworkItem.java
se.tube42.kidsmem.item.GameStat.java
se.tube42.kidsmem.item.TileSprite.java
se.tube42.kidsmem.item.TopBar.java
se.tube42.kidsmem.logic.AssetHelper.java
se.tube42.kidsmem.logic.GameHelper.java
se.tube42.kidsmem.logic.SettingsHelper.java
se.tube42.kidsmem.logic.SizeHelper.java
se.tube42.kidsmem.scene.BackgroundScene.java
se.tube42.kidsmem.scene.GameScene.java
se.tube42.kidsmem.scene.MenuScene.java
se.tube42.kidsmem.service.ServiceProvider.java
se.tube42.lib.item.BaseItem.java
se.tube42.lib.item.BaseText.java
se.tube42.lib.item.ParticleItem.java
se.tube42.lib.item.PatchItem.java
se.tube42.lib.item.SpriteItem.java
se.tube42.lib.scene.LayerList.java
se.tube42.lib.scene.Layer.java
se.tube42.lib.scene.SceneManager.java
se.tube42.lib.scene.Scene.java
se.tube42.lib.service.AssetService.java
se.tube42.lib.service.JobService.java
se.tube42.lib.service.RandomService.java
se.tube42.lib.service.StorageService.java
se.tube42.lib.util.BaseApp.java
se.tube42.lib.util.UIC.java