Package transientlibs.preui.objects.gui.elements

Source Code of transientlibs.preui.objects.gui.elements.TransientGDXImage

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.preui.objects.gui.elements;

import transientlibs.preui.objects.gui.interfaces.IColour;
import transientlibs.preui.objects.gui.interfaces.IImage;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.TextureData;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import transientlibs.slick2d.util.Log;

/**
*
* @author kibertoad
*/
@Deprecated
public class TransientGDXImage implements IImage {

        public TextureRegion image;
        public AtlasRegion atlasRegion;
                   
        public final void loadFromFile (String fileName) {
            Texture texture = new Texture(Gdx.files.internal(fileName));

            image = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight());
            //image.flip(false, true);
        }

       
    public TransientGDXImage(TextureRegion setImage, AtlasRegion setAtlasRegion) {
        this.image = setImage;
        atlasRegion = setAtlasRegion;
    }
       
       
    public TransientGDXImage(TextureRegion setImage) {
        this.image = setImage;
    }

    public TransientGDXImage() {
    }

    public TransientGDXImage(String fromFile) {
        loadFromFile(fromFile);
    }
   
   
       
       
       
       
       
    public static TransientGDXImage load(String fileName) {
        Log.info("Load from file: "+fileName);
            Texture texture = new Texture(Gdx.files.internal(fileName));
            TransientGDXImage newImage = new TransientGDXImage();
           
            newImage.image = new TextureRegion(texture, 0, 0, texture.getWidth(), texture.getHeight());       
            //newImage.image.flip(false, true);
            return newImage;
    }
       
   
  public static TextureRegion load (String name, int width, int height) {
    Texture texture = new Texture(Gdx.files.internal(name));
    TextureRegion region = new TextureRegion(texture, 0, 0, width, height);
    //region.flip(false, true);
    return region;
  }    
   
       
  private static TextureRegion[][] split (String name, int width, int height) {
    return split(name, width, height, false);
  }

  private static TextureRegion[][] split (String name, int width, int height, boolean flipX) {
    Texture texture = new Texture(Gdx.files.internal(name));
    int xSlices = texture.getWidth() / width;
    int ySlices = texture.getHeight() / height;
    TextureRegion[][] res = new TextureRegion[xSlices][ySlices];
    for (int x = 0; x < xSlices; x++) {
      for (int y = 0; y < ySlices; y++) {
        res[x][y] = new TextureRegion(texture, x * width, y * height, width, height);
        res[x][y].flip(flipX, true);
      }
    }
    return res;
  }

      

    @Override
    public void draw() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void draw(int onX, int onY) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void drawPart(float onX, float onY, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public int getHeight() {
        return image.getRegionHeight();
    }

    @Override
    public int getWidth() {
        return image.getRegionWidth();
    }

    @Override
    public IColour getColour(int onX, int onY) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
   
    @Override
    public boolean isTransparent(int x, int y){
        TextureData data = image.getTexture().getTextureData();
        if (!data.isPrepared()){
            data.prepare();
        }
        int pixel = data.consumePixmap().getPixel(x, y);
        pixel &= 0x000000ff;
        return pixel == 0;
    }

    @Override
    public AtlasRegion getAtlasRegion() {
        return atlasRegion;
        //return atlasRegion;
    }

    @Override
    public String getName() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public IImage getSubImage(int i, int tileSizeX, int i0, int tileSizeY) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public TextureRegion getTextureRegion() {
        return image;
    }

    @Override
    public void draw(SpriteBatch spriteBatch, int onX, int onY) {
        spriteBatch.draw(image, onX, onY);
    }

   
   
   
   
}
TOP

Related Classes of transientlibs.preui.objects.gui.elements.TransientGDXImage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.