Example usage for com.badlogic.gdx.graphics Pixmap Pixmap

List of usage examples for com.badlogic.gdx.graphics Pixmap Pixmap

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Pixmap Pixmap.

Prototype

public Pixmap(byte[] encodedData, int offset, int len) 

Source Link

Document

Creates a new Pixmap instance from the given encoded image data.

Usage

From source file:name.herve.bastod.gui.screen.game.OverlayManager.java

License:Open Source License

public void renderGrid() {
    if (grid == null) {
        Dimension dimG = engine.getGridDimension();
        Dimension dimB = engine.getBoardDimension();
        int sqs = engine.getGridSquareSize();

        Blending bck = Pixmap.getBlending();
        Pixmap.setBlending(Blending.None);

        Pixmap p = new Pixmap(dimB.getW() + 1, dimB.getH() + 1, Pixmap.Format.RGBA8888);
        Color c = Color.WHITE.cpy();
        c.a = 0.2f;/*ww  w. j  av a2  s.  c o  m*/
        p.setColor(c);

        for (int x = 0; x <= dimG.getW(); x++) {
            int bx = x * sqs;
            p.drawLine(bx, 0, bx, dimB.getH() - 1);
        }
        for (int y = 0; y <= dimG.getH(); y++) {
            int by = y * sqs;
            p.drawLine(0, by, dimB.getW() - 1, by);
        }

        grid = new Texture(p);
        p.dispose();

        Pixmap.setBlending(bck);
    }

    batchBegin();
    draw(grid, Engine._SP_SIDE, Engine._SP_BOTTOM);
    batchEnd();
}

From source file:name.herve.bastod.gui.screen.game.OverlayManager.java

License:Open Source License

public void renderUnitOverlay(Unit selected) {
    if (selected != null) {
        if (selected instanceof Tower) {
            int shotRange = (int) (((Tower) selected).getRangeOnBoard());
            String k = selected.getPlayer().getColor() + "-" + shotRange;

            if (!towerRanges.containsKey(k)) {
                int gfxSize = shotRange * 2;

                Blending bck = Pixmap.getBlending();
                Pixmap.setBlending(Blending.None);

                Pixmap p = new Pixmap(gfxSize, gfxSize, Pixmap.Format.RGBA8888);
                Color c = GUIResources.getInstance().getColor(selected.getPlayer().getColor()).cpy();
                c.a = 0.2f;//  w  w w. j a  v  a2s.co  m
                p.setColor(c);
                p.fillCircle(shotRange, shotRange, shotRange);
                Texture t = new Texture(p);
                p.dispose();
                Pixmap.setBlending(bck);
                towerRanges.put(k, t);
            }

            batchBegin();
            draw(towerRanges.get(k), Engine._SP_SIDE + selected.getPositionOnBoard().getX() - shotRange,
                    Engine._SP_BOTTOM + selected.getPositionOnBoard().getY() - shotRange);
            batchEnd();
        }
    }
}

From source file:name.herve.bastod.gui.screen.game.SpriteManager.java

License:Open Source License

private Texture initArmorLeft(int step, Color c) {
    Blending bck = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);/*from w  w w  . j a  v  a  2  s.  c  o m*/

    int sqs = engine.getGridSquareSize();

    Pixmap p = new Pixmap(sqs, sqs + 4, Pixmap.Format.RGBA8888);
    p.setColor(c);

    //p.drawRectangle(0, 0, sqs, 3);

    int w = step * sqs / armorLeftStep;
    p.fillRectangle(0, 0, w, 3);

    Texture t = new Texture(p);
    p.dispose();
    Pixmap.setBlending(bck);

    return t;
}

From source file:name.herve.bastod.gui.screen.game.SpriteManager.java

License:Open Source License

private void renderPath(Mobile m) {
    if (!pathTextures.containsKey(m)) {
        Dimension dimB = engine.getBoardDimension();

        Blending bck = Pixmap.getBlending();
        Pixmap.setBlending(Blending.None);

        Pixmap p = new Pixmap(dimB.getW() + 1, dimB.getH() + 1, Pixmap.Format.RGBA8888);

        Color c = Color.GREEN.cpy();
        p.setColor(c);//w w  w .j a  va 2  s .  com
        Vector current = m.getPlayer().getStartPositionOnBoard();
        for (Vector next : m.getUnsmoothedPath()) {
            p.drawLine(current.getXInt(), dimB.getH() - current.getYInt(), next.getXInt(),
                    dimB.getH() - next.getYInt());
            current = next;
        }

        c = Color.YELLOW.cpy();
        p.setColor(c);
        current = m.getPlayer().getStartPositionOnBoard();
        for (Vector next : m.getPath()) {
            p.drawLine(current.getXInt(), dimB.getH() - current.getYInt(), next.getXInt(),
                    dimB.getH() - next.getYInt());
            current = next;
        }

        pathTextures.put(m, new Texture(p));
        p.dispose();
        Pixmap.setBlending(bck);
    }

    draw(pathTextures.get(m), Engine._SP_SIDE, Engine._SP_BOTTOM);

    // tPath.dispose();
}

From source file:name.herve.bastod.guifwk.AbstractComponent.java

License:Open Source License

@Override
public void start() {
    super.start();
    lastUpdateTime = 0;/*from w  w w  . j  av  a 2 s .  com*/

    Blending bck = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);

    Pixmap p = new Pixmap(getWidth(), getHeight(), Pixmap.Format.RGBA8888);
    Color c1 = Color.BLACK.cpy();
    c1.a = 0.8f;
    p.setColor(c1);
    p.fillRectangle(0, 0, getWidth(), getHeight());

    //      p.setColor(Color.WHITE);
    //      int step = 8;
    //      for (int d = 0; d < w; d += step) {
    //         p.drawLine(x + d, h, 0, h - d);
    //         p.drawLine(x + d, h - w, w, h - d);
    //         p.drawLine(x + d, h, w, h - w + d);
    //         p.drawLine(x + d, h - w, 0, h - w + d);
    //      }

    disabled = new Texture(p);
    p.dispose();
    Pixmap.setBlending(bck);

}

From source file:net.ijbrown.snowdroid.TexReader.java

License:Open Source License

public Pixmap read(ByteBuffer fileDataBuffer) {
    Pixmap pixmap = null;/*from  ww  w.  j  a v a2  s .  com*/
    int finalw = fileDataBuffer.getLEShort(0);
    int finalh = fileDataBuffer.getLEShort(2);
    int sourcew = finalw;
    int sourceh = finalh;
    PalEntry[] pixels = null;

    int curIdx = 0x80;
    GIFTag gifTag = new GIFTag();
    gifTag.parse(fileDataBuffer, curIdx);

    // This is basically heuristics
    if (gifTag.nloop == 4) {

        int palw = fileDataBuffer.getLEShort(curIdx + 0x30);
        int palh = fileDataBuffer.getLEShort(curIdx + 0x34);

        curIdx += 0x50;
        GIFTag gifTag2 = new GIFTag();
        gifTag2.parse(fileDataBuffer, curIdx);

        // 8 bit palletised
        PalEntry[] palette = PalEntry.readPalette(fileDataBuffer, curIdx + 0x10, palw, palh);

        palette = PalEntry.unswizzlePalette(palette);

        int palLen = palw * palh * 4;
        curIdx += (palLen + 0x10);

        GIFTag gifTag50 = new GIFTag();
        gifTag50.parse(fileDataBuffer, curIdx);
        curIdx += 0x20;

        int dbw = (sourcew / 2 + 0x07) & ~0x07;
        int dbh = (sourceh / 2 + 0x07) & ~0x07;

        int endIndex = fileDataBuffer.len;

        // The following should be a loop, there are repeating sections
        while (curIdx < endIndex - 0x10) {
            GIFTag gifTag3 = new GIFTag();
            gifTag3.parse(fileDataBuffer, curIdx);

            int dimOffset = 0x10;

            int thisRrw = fileDataBuffer.getLEShort(curIdx + dimOffset);
            int thisRrh = fileDataBuffer.getLEShort(curIdx + dimOffset + 4);

            int startx = fileDataBuffer.getLEShort(curIdx + dimOffset + 20);
            int starty = fileDataBuffer.getLEShort(curIdx + dimOffset + 22);

            curIdx += gifTag.nloop * 0x10 + 0x10;
            pixels = readPixels32(pixels, fileDataBuffer, palette, curIdx, startx, starty, thisRrw, thisRrh,
                    dbw, dbh);
            curIdx += thisRrw * thisRrh * 4;
        }

        if (palLen != 64) {
            pixels = unswizzle8bpp(pixels, dbw * 2, dbh * 2);
            sourcew = dbw * 2;
            sourceh = dbh * 2;
        } else {
            sourcew = dbw;
            sourceh = dbh;
        }

    } else if (gifTag.nloop == 3) {
        GIFTag gifTag2 = new GIFTag();
        gifTag2.parse(fileDataBuffer, 0xC0);
        System.out.println(gifTag2.toString());

        if (gifTag2.flg == 2) {
            // image mode
            pixels = readPixels32(pixels, fileDataBuffer, 0xD0, finalw, finalh);
        }
    }
    if (finalw != 0 && pixels != null) {
        pixmap = new Pixmap(finalw, finalh, Pixmap.Format.RGBA8888);

        for (int y = 0; y < sourceh; ++y) {
            for (int x = 0; x < sourcew; ++x) {
                PalEntry pixel = pixels[y * sourcew + x];
                if (pixel != null) {
                    pixmap.drawPixel(x, y, pixel.rgba());
                }
            }
        }
    }
    return pixmap;
}

From source file:net.mwplay.cocostudio.ui.parser.group.CCPanel.java

License:Apache License

@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {
    Table table = new Table();

    Size size = widget.getSize();/*from w ww .  j a  va 2s  .  c  om*/
    if (widget.getComboBoxIndex() == 0) { // 

    } else if (widget.getComboBoxIndex() == 1 && widget.getBackColorAlpha() != 0) {// ?
        Pixmap pixmap = new Pixmap((int) size.getX(), (int) size.getY(), Format.RGBA8888);

        pixmap.setColor(editor.getColor(widget.getSingleColor(), widget.getBackColorAlpha()));

        pixmap.fill();

        Drawable d = new TextureRegionDrawable(new TextureRegion(new Texture(pixmap)));
        table.setBackground(d);
        pixmap.dispose();
    }

    if (widget.getFileData() != null) {// Panel?!!.
        Drawable tr = editor.findDrawable(widget, widget.getFileData());
        if (tr != null) {
            Image bg = new Image(tr);
            bg.setPosition((size.getX() - bg.getWidth()) / 2, (size.getY() - bg.getHeight()) / 2);
            // bg.setFillParent(true);
            bg.setTouchable(Touchable.disabled);

            table.addActor(bg);
        }
    }

    table.setClip(widget.isClipAble());

    return table;
}

From source file:net.mwplay.cocostudio.ui.parser.group.CCScrollView.java

License:Apache License

@Override
public Actor parse(CocoStudioUIEditor editor, ObjectData widget) {
    ScrollPaneStyle style = new ScrollPaneStyle();

    if (widget.getFileData() != null) {

        style.background = editor.findDrawable(widget, widget.getFileData());
    }//ww  w. j a  va2  s .  c o  m

    ScrollPane scrollPane = new ScrollPane(null, style);

    if ("Vertical_Horizontal".equals(widget.getScrollDirectionType())) {
        scrollPane.setForceScroll(true, true);
    } else if ("Horizontal".equals(widget.getScrollDirectionType())) {
        scrollPane.setForceScroll(true, false);
    } else if ("Vertical".equals(widget.getScrollDirectionType())) {
        scrollPane.setForceScroll(false, true);
    }

    scrollPane.setClamp(widget.isClipAble());
    scrollPane.setFlickScroll(widget.isIsBounceEnabled());

    Table table = new Table();
    table.setSize(widget.getInnerNodeSize().getWidth(), widget.getInnerNodeSize().getHeight());

    if (widget.getComboBoxIndex() == 0) {// 

    } else if (widget.getComboBoxIndex() == 1) {// ?

        Pixmap pixmap = new Pixmap((int) table.getWidth(), (int) table.getHeight(), Format.RGBA8888);
        Color color = editor.getColor(widget.getSingleColor(), widget.getBackColorAlpha());

        pixmap.setColor(color);

        pixmap.fill();

        Drawable drawable = new TextureRegionDrawable(new TextureRegion(new Texture(pixmap)));

        table.setBackground(drawable);
        pixmap.dispose();

    }
    scrollPane.setWidget(table);
    return scrollPane;
}

From source file:net.mwplay.cocostudio.ui.particleutil.CCParticleActor.java

License:Apache License

public void initWithDictionary(ObjectMap<String, Object> dictionary, String dir, Texture texture) {
    //int maxParticles = Integer.parseInt((String) dictionary.get("maxParticles"));

    int maxParticles = (int) Float.parseFloat((String) dictionary.get("maxParticles"));
    this.initWithTotalParticles(maxParticles);

    _positionType = PositionTypeGrouped;

    m_fAngle = Float.parseFloat((String) dictionary.get("angle"));
    m_fAngleVar = Float.parseFloat((String) dictionary.get("angleVariance"));

    // duration/*from   www  .  j  av a  2 s .c  o  m*/
    _duration = Float.parseFloat((String) dictionary.get("duration"));

    blendSrc = Integer.parseInt((String) dictionary.get("blendFuncSource"));
    blendDst = Integer.parseInt((String) dictionary.get("blendFuncDestination"));

    m_tStartColor.r = Float.parseFloat((String) dictionary.get("startColorRed"));
    m_tStartColor.g = Float.parseFloat((String) dictionary.get("startColorGreen"));
    m_tStartColor.b = Float.parseFloat((String) dictionary.get("startColorBlue"));
    m_tStartColor.a = Float.parseFloat((String) dictionary.get("startColorAlpha"));

    m_tStartColorVar.r = Float.parseFloat((String) dictionary.get("startColorVarianceRed"));
    m_tStartColorVar.g = Float.parseFloat((String) dictionary.get("startColorVarianceGreen"));
    m_tStartColorVar.b = Float.parseFloat((String) dictionary.get("startColorVarianceBlue"));
    m_tStartColorVar.a = Float.parseFloat((String) dictionary.get("startColorVarianceAlpha"));

    m_tEndColor.r = Float.parseFloat((String) dictionary.get("finishColorRed"));
    m_tEndColor.g = Float.parseFloat((String) dictionary.get("finishColorGreen"));
    m_tEndColor.b = Float.parseFloat((String) dictionary.get("finishColorBlue"));
    m_tEndColor.a = Float.parseFloat((String) dictionary.get("finishColorAlpha"));

    m_tEndColorVar.r = Float.parseFloat((String) dictionary.get("finishColorVarianceRed"));
    m_tEndColorVar.g = Float.parseFloat((String) dictionary.get("finishColorVarianceGreen"));
    m_tEndColorVar.b = Float.parseFloat((String) dictionary.get("finishColorVarianceBlue"));
    m_tEndColorVar.a = Float.parseFloat((String) dictionary.get("finishColorVarianceAlpha"));

    // particle size
    m_fStartSize = Float.parseFloat((String) dictionary.get("startParticleSize"));
    m_fStartSizeVar = Float.parseFloat((String) dictionary.get("startParticleSizeVariance"));
    _endSize = Float.parseFloat((String) dictionary.get("finishParticleSize"));
    _endSizeVar = Float.parseFloat((String) dictionary.get("finishParticleSizeVariance"));

    // position
    float x = Float.parseFloat((String) dictionary.get("sourcePositionx"));
    float y = Float.parseFloat((String) dictionary.get("sourcePositiony"));

    //        m_tSourcePosition.x = x;
    //        m_tSourcePosition.y = y;
    this.setPosition(x, y);

    m_tPosVar.x = Float.parseFloat((String) dictionary.get("sourcePositionVariancex"));
    m_tPosVar.y = Float.parseFloat((String) dictionary.get("sourcePositionVariancey"));

    // Spinning
    m_fStartSpin = Float.parseFloat((String) dictionary.get("rotationStart"));
    m_fStartSpinVar = Float.parseFloat((String) dictionary.get("rotationStartVariance"));
    m_fEndSpin = Float.parseFloat((String) dictionary.get("rotationEnd"));
    m_fEndSpinVar = Float.parseFloat((String) dictionary.get("rotationEndVariance"));

    float em = Float.parseFloat((String) dictionary.get("emitterType"));
    _emitterMode = (int) em;

    if (_emitterMode == ParticleModeGravity) {
        // gravity
        modeA.gravity.x = Float.parseFloat((String) dictionary.get("gravityx"));
        modeA.gravity.y = Float.parseFloat((String) dictionary.get("gravityy"));
        // speed
        modeA.speed = Float.parseFloat((String) dictionary.get("speed"));
        modeA.speedVar = Float.parseFloat((String) dictionary.get("speedVariance"));
        // radial acceleration
        modeA.radialAccel = Float.parseFloat((String) dictionary.get("radialAcceleration"));
        modeA.radialAccelVar = Float.parseFloat((String) dictionary.get("radialAccelVariance"));
        // tangential acceleration
        modeA.tangentialAccel = Float.parseFloat((String) dictionary.get("tangentialAcceleration"));
        modeA.tangentialAccelVar = Float.parseFloat((String) dictionary.get("tangentialAccelVariance"));
        // rotation is dir
        modeA.rotationIsDir = Boolean.parseBoolean((String) dictionary.get("rotationIsDir"));
    } else if (_emitterMode == ParticleModeRadius) {
        modeB.startRadius = Float.parseFloat((String) dictionary.get("maxRadius"));
        modeB.startRadiusVar = Float.parseFloat((String) dictionary.get("maxRadiusVariance"));
        modeB.endRadius = Float.parseFloat((String) dictionary.get("minRadius"));
        modeB.endRadiusVar = 0.0f;
        modeB.rotatePerSecond = Float.parseFloat((String) dictionary.get("rotatePerSecond"));
        modeB.rotatePerSecondVar = Float.parseFloat((String) dictionary.get("rotatePerSecondVariance"));
    } else {
        throw new IllegalArgumentException("Invalid emitterType in config file");
    }
    // life span
    m_fLife = Float.parseFloat((String) dictionary.get("particleLifespan"));
    m_fLifeVar = Float.parseFloat((String) dictionary.get("particleLifespanVariance"));
    // emission Rate
    _emissionRate = _totalParticles / m_fLife;
    if (texture != null) {
        ownesTexture = false;
        m_pTexture = texture;
    } else {
        ownesTexture = true;
        String textureName = (String) dictionary.get("textureFileName");
        FileHandle handle;
        if ("".equals(dir)) {
            handle = Gdx.files.internal(textureName);
        } else {
            handle = Gdx.files.internal(dir + "/" + textureName);
        }
        if (handle.exists() && !handle.isDirectory()) {
            m_pTexture = new Texture(handle);
        } else {
            String textureData = new String(((String) dictionary.get("textureImageData")).getBytes(),
                    Charset.forName("UTF-8"));
            int dataLen = textureData.length();
            if (dataLen > 0) {
                byte[] decodeData = Base64Coder.decode(textureData);
                byte[] imageData = LyU.unGzip(decodeData);
                Pixmap image = new Pixmap(imageData, 0, imageData.length);
                m_pTexture = new Texture(image);
                image.dispose();
            }
        }
    }
}

From source file:net.mwplay.cocostudio.ui.particleutil.CCParticleActor.java

License:Apache License

public static Texture getDefaultTexture() {
    Pixmap pImage = new Pixmap(__firePngData, 0, __firePngData.length);
    Texture texture = new Texture(pImage);
    pImage.dispose();//from  w  ww. jav a 2  s.co m
    return texture;
}