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:com.xemplar.games.android.nerdshooter.screens.ui.Button.java

License:Open Source License

public Button(BitmapFont font, TextureRegion tex, float x, float y, float width, float height) {
    super(font, "", x, y, width, height);

    Pixmap map = tex.getTexture().getTextureData().consumePixmap();

    this.font = font;
    this.tex = tex;

    array_pressed = new float[] { 0.5F, 0.5F, 0.5F, 1.0F };
    array_not_pressed = new float[] { 0.5F, 0.5F, 0.5F, 1.0F };

    System.out.println("Is Null : " + this.tex == null);

    Pixmap pix_not_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888);
    pix_not_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height);
    tex_not_pressed = new Texture(pix_not_pressed);

    Pixmap pix_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888);
    pix_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height);
    tex_pressed = new Texture(pix_pressed);

    map.dispose();// w w w  . j a v a  2s .c o  m
}

From source file:com.xemplar.games.android.nerdshooter.screens.ui.Button.java

License:Open Source License

public Button(BitmapFont font, TextureRegion tex, float[] colors, float x, float y, float width, float height) {
    super(font, "", x, y, width, height);

    Pixmap map = tex.getTexture().getTextureData().consumePixmap();

    this.tex = tex;

    array_pressed = colors;/*from   ww  w  .java  2s . c o m*/
    array_not_pressed = colors;

    Pixmap pix_not_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888);
    pix_not_pressed.setColor(colors[0], colors[1], colors[2], colors[3]);
    pix_not_pressed.fill();
    pix_not_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height);
    tex_not_pressed = new Texture(pix_not_pressed);

    Pixmap pix_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888);
    pix_pressed.setColor(colors[0], colors[1], colors[2], colors[3]);
    pix_pressed.fill();
    pix_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height);
    tex_pressed = new Texture(pix_pressed);

    map.dispose();
}

From source file:com.xemplar.games.android.nerdshooter.screens.ui.Button.java

License:Open Source License

public Button(BitmapFont font, TextureRegion tex, float[] colors, float[] pressedColors, float x, float y,
        float width, float height) {
    super(font, "", x, y, width, height);

    Pixmap map = tex.getTexture().getTextureData().consumePixmap();

    this.tex = tex;

    array_pressed = colors;//from w  w w  .ja  v  a2 s.  c om
    array_not_pressed = pressedColors;

    Pixmap pix_not_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888);
    pix_not_pressed.setColor(colors[0], colors[1], colors[2], colors[3]);
    pix_not_pressed.fill();
    pix_not_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height);
    tex_not_pressed = new Texture(pix_not_pressed);

    Pixmap pix_pressed = new Pixmap((int) width, (int) height, Pixmap.Format.RGBA8888);
    pix_pressed.setColor(pressedColors[0], pressedColors[1], pressedColors[2], pressedColors[3]);
    pix_pressed.fill();
    pix_pressed.drawPixmap(map, 0, 0, map.getWidth(), map.getHeight(), 0, 0, (int) width, (int) height);
    tex_pressed = new Texture(pix_pressed);

    map.dispose();
}

From source file:darkyenus.resourcepacker.util.FreeTypePacker.java

License:Apache License

/** @return null if glyph was not found. */
CharacterData createGlyph(int codePoint, int glyphIndex, FreeTypeFontParameter parameter,
        FreeType.Stroker stroker) {//w  w  w  .j a  v  a  2 s  .c o  m
    if (!face.loadGlyph(glyphIndex, parameter.loadingFlags))
        return null;

    FreeType.GlyphSlot slot = face.getGlyph();
    FreeType.Glyph mainGlyph = slot.getGlyph();
    try {
        mainGlyph.toBitmap(parameter.mono ? FreeType.FT_RENDER_MODE_MONO : FreeType.FT_RENDER_MODE_NORMAL);
    } catch (GdxRuntimeException e) {
        mainGlyph.dispose();
        Gdx.app.log("FreeTypeFontGenerator", "Couldn't render char: " + codePoint);
        return null;
    }
    FreeType.Bitmap mainBitmap = mainGlyph.getBitmap();
    Pixmap mainPixmap = mainBitmap.getPixmap(Pixmap.Format.RGBA8888, parameter.color, parameter.gamma);

    if (mainBitmap.getWidth() != 0 && mainBitmap.getRows() != 0) {
        int offsetX, offsetY;
        if (parameter.borderWidth > 0) {
            // execute stroker; this generates a glyph "extended" along the outline
            int top = mainGlyph.getTop(), left = mainGlyph.getLeft();
            FreeType.Glyph borderGlyph = slot.getGlyph();
            borderGlyph.strokeBorder(stroker, false);
            borderGlyph
                    .toBitmap(parameter.mono ? FreeType.FT_RENDER_MODE_MONO : FreeType.FT_RENDER_MODE_NORMAL);
            offsetX = left - borderGlyph.getLeft();
            offsetY = -(top - borderGlyph.getTop());

            // Render border (pixmap is bigger than main).
            FreeType.Bitmap borderBitmap = borderGlyph.getBitmap();
            Pixmap borderPixmap = borderBitmap.getPixmap(Pixmap.Format.RGBA8888, parameter.borderColor,
                    parameter.borderGamma);

            // Draw main glyph on top of border.
            for (int i = 0, n = parameter.renderCount; i < n; i++)
                borderPixmap.drawPixmap(mainPixmap, offsetX, offsetY);

            mainPixmap.dispose();
            mainGlyph.dispose();
            mainPixmap = borderPixmap;
            mainGlyph = borderGlyph;
        }

        if (parameter.shadowOffsetX != 0 || parameter.shadowOffsetY != 0) {
            int mainW = mainPixmap.getWidth(), mainH = mainPixmap.getHeight();
            int shadowOffsetX = Math.max(parameter.shadowOffsetX, 0),
                    shadowOffsetY = Math.max(parameter.shadowOffsetY, 0);
            int shadowW = mainW + Math.abs(parameter.shadowOffsetX),
                    shadowH = mainH + Math.abs(parameter.shadowOffsetY);
            Pixmap shadowPixmap = new Pixmap(shadowW, shadowH, mainPixmap.getFormat());

            Color shadowColor = parameter.shadowColor;
            byte r = (byte) (shadowColor.r * 255), g = (byte) (shadowColor.g * 255),
                    b = (byte) (shadowColor.b * 255);
            float a = shadowColor.a;

            ByteBuffer mainPixels = mainPixmap.getPixels();
            ByteBuffer shadowPixels = shadowPixmap.getPixels();
            for (int y = 0; y < mainH; y++) {
                int shadowRow = shadowW * (y + shadowOffsetY) + shadowOffsetX;
                for (int x = 0; x < mainW; x++) {
                    int mainPixel = (mainW * y + x) * 4;
                    byte mainA = mainPixels.get(mainPixel + 3);
                    if (mainA == 0)
                        continue;
                    int shadowPixel = (shadowRow + x) * 4;
                    shadowPixels.put(shadowPixel, r);
                    shadowPixels.put(shadowPixel + 1, g);
                    shadowPixels.put(shadowPixel + 2, b);
                    shadowPixels.put(shadowPixel + 3, (byte) ((mainA & 0xff) * a));
                }
            }

            // Draw main glyph (with any border) on top of shadow.
            for (int i = 0, n = parameter.renderCount; i < n; i++)
                shadowPixmap.drawPixmap(mainPixmap, Math.max(-parameter.shadowOffsetX, 0),
                        Math.max(-parameter.shadowOffsetY, 0));
            mainPixmap.dispose();
            mainPixmap = shadowPixmap;
        } else if (parameter.borderWidth == 0) {
            // No shadow and no border, draw glyph additional times.
            for (int i = 0, n = parameter.renderCount - 1; i < n; i++)
                mainPixmap.drawPixmap(mainPixmap, 0, 0);
        }
    }

    final CharacterData data = new CharacterData(glyphIndex, codePoint);
    data.pixmap = mainPixmap;
    data.advanceX = FreeType.toInt(slot.getAdvanceX());
    data.offsetX = mainGlyph.getLeft();
    data.offsetY = mainGlyph.getTop();

    mainGlyph.dispose();

    return data;
}

From source file:de.bitbrain.craft.graphics.GraphicsFactory.java

License:Open Source License

public static Texture createTexture(int width, int height, Color color) {
    Pixmap map = new Pixmap(width, height, Format.RGBA8888);
    map.setColor(color);//from   w  w  w  .  j a v  a2  s. co m
    map.fill();
    Texture texture = new Texture(map);
    map.dispose();
    return texture;
}

From source file:de.gebatzens.meteva.GScout.java

License:Open Source License

@Override
public void create() {

    //For testing
    trace = false;//  www .j a  va2s.com

    if (trace)
        tracei.beginTrace("initmeteva");
    batch = new SpriteBatch();
    atlas = new TextureAtlas(Gdx.files.internal("all.pack"));
    sbg = new SpaceBackground();
    sbg.initBackground();
    settings = new Settings();
    settings.load();
    highscoren = new Highscore();
    highscoren.load(false);
    highscoref = new Highscore();
    highscoref.load(true);
    mprof = new MarketProfile();
    mprof.load();
    mprof.reset();
    Gdx.app.setLogLevel(Application.LOG_ERROR);

    manager = new AssetManager();
    locale = Locale.getDefault();
    bundle = I18NBundle.createBundle(Gdx.files.internal("lang/bundle"), locale);
    Gdx.app.debug("Meteva", "using locale " + locale);

    for (int i = 0; i < 4; i++) {
        meteorExpl[i] = Gdx.audio.newSound(Gdx.files.internal("sounds/expl" + (i + 1) + ".ogg"));
    }
    playerExpl = Gdx.audio.newSound(Gdx.files.internal("sounds/raumschiffexpl.ogg"));
    laser = Gdx.audio.newSound(Gdx.files.internal("sounds/laser.ogg"));
    rush = Gdx.audio.newMusic(Gdx.files.internal("sounds/rush.mp3"));
    rush.setLooping(true);
    if (settings.musicEnabled())
        rush.play();

    Texture tex = new Texture(Gdx.files.internal("survivant.png"));
    tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    survivant = new BitmapFont(Gdx.files.internal("survivant.fnt"), new TextureRegion(tex), false);
    fontShader = new ShaderProgram(Gdx.files.internal("font.vert"), Gdx.files.internal("font.frag"));

    if (!fontShader.isCompiled()) {
        Gdx.app.error("fontShader", "compilation failed:\n" + fontShader.getLog());
    }

    Pixmap p = new Pixmap(1, 1, Format.RGBA8888);
    p.setColor(Color.WHITE);
    p.drawPixel(0, 0);
    whiteTexture = new Texture(p);
    p.dispose();

    //   camera = new OrthographicCamera(1920, 1080);
    //   camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    //   camera.setToOrtho(true);

    InputMultiplexer im = new InputMultiplexer();
    im.addProcessor(this);

    GestureDetector gd = new GestureDetector(this);
    im.addProcessor(gd);

    Gdx.input.setInputProcessor(im);

    width = Gdx.graphics.getWidth();
    height = Gdx.graphics.getHeight();

    musicb = new SoundButton(GScout.width * 0.022f, GScout.height * 0.02f, GScout.getRegion("ton"),
            GScout.getRegion("tonaus"), GScout.width * 0.065f);
    musicb.activated = !settings.musicEnabled();
    soundb = new SoundButton(GScout.width * 0.022f + 0.07f * GScout.width, GScout.height * 0.02f,
            GScout.getRegion("spielton"), GScout.getRegion("spieltonaus"), GScout.width * 0.065f);
    soundb.activated = !settings.soundsEnabled();

    state = new MainState();
    state.init();

    if (trace)
        tracei.endTrace();

}

From source file:de.longri.cachebox3.develop.tools.skin_editor.actors.OptionsPane.java

License:Apache License

/**
 *
 *//*www. j a va 2 s .com*/
private void updateTableFields(final String style) {

    ImageButton button = (ImageButton) game.screenMain.barWidgets.group.getChecked();
    String widget = button.getUserObject().toString();

    Gdx.app.log("OptionsPane", "Update fields table for widget: " + widget + ", style: " + style);
    tableFields.clear();
    tableFields.add(new Label("Name", game.skin, "title")).left().width(170);
    tableFields.add(new Label("Value", game.skin, "title")).left().width(60).padRight(50);
    tableFields.row();

    Field[] fields = ClassReflection.getFields(currentStyle.getClass());
    for (final Field field : fields) {
        try {

            Actor actor = null;

            // field type
            String name = field.getType().getSimpleName();
            Object obj = field.get(currentStyle);

            if (name.equals("Drawable")) {

                /**
                 * Handle Drawable object
                 */

                Drawable drawable = (Drawable) field.get(currentStyle);
                String resourceName = "";
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(
                        game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"),
                        game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));

                if (drawable != null) {
                    resourceName = game.skinProject.resolveObjectName(Drawable.class, drawable);
                    if (resourceName == null) {
                        resourceName = game.skinProject.resolveObjectName(TextureRegion.class, drawable);
                    }
                    buttonStyle.imageUp = drawable;
                } else {
                    buttonStyle.up = game.skin.getDrawable("default-rect");
                    buttonStyle.checked = game.skin.getDrawable("default-rect");
                }

                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showDrawableDialog(field, false);

                    }

                });

            } else if (name.equals("Bitmap")) {

                /**
                 * Handle Bitmap object
                 */

                Bitmap bitmap = (Bitmap) field.get(currentStyle);
                byte[] bytes = null;
                if (bitmap != null)
                    bytes = bitmap.getPngEncodedData();
                Drawable drawable = bitmap != null
                        ? new TextureRegionDrawable(
                                new TextureRegion(new Texture(new Pixmap(bytes, 0, bytes.length))))
                        : null;

                String resourceName = "";
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(
                        game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"),
                        game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));

                if (drawable != null) {
                    resourceName = ((GetName) bitmap).getName();
                    buttonStyle.imageUp = drawable;
                } else {
                    buttonStyle.up = game.skin.getDrawable("default-rect");
                    buttonStyle.checked = game.skin.getDrawable("default-rect");
                }

                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showDrawableDialog(field, true);

                    }

                });

            } else if (name.equals("Color")) {

                /**
                 * Handle Color object
                 */
                Color color = (Color) field.get(currentStyle);
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(
                        game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"),
                        game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));

                String resourceName = "";
                if (color != null) {

                    if (color instanceof SkinColor) {
                        resourceName = ((SkinColor) color).skinName;
                    } else {
                        resourceName = game.skinProject.resolveObjectName(SkinColor.class, color);
                    }

                    resourceName += " (" + color.toString() + ")";

                    // Create drawable on the fly
                    Pixmap pixmap = new Pixmap(18, 18, Pixmap.Format.RGBA8888);
                    pixmap.setColor(color);
                    pixmap.fill();
                    pixmap.setColor(Color.BLACK);
                    pixmap.drawRectangle(0, 0, 18, 18);
                    Texture texture = new Texture(pixmap);
                    buttonStyle.imageUp = new SpriteDrawable(new Sprite(texture));
                    pixmap.dispose();
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }

                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showColorPickerDialog(field);

                    }

                });

            } else if (name.equals("BitmapFont")) {

                /**
                 * Handle BitmapFont object
                 */

                BitmapFont font = (BitmapFont) field.get(currentStyle);
                String resourceName = "";
                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(
                        game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"),
                        game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));

                if (font != null) {
                    resourceName = game.skinProject.resolveObjectName(BitmapFont.class, font);
                    buttonStyle.font = font;
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }

                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);

                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showFontPickerDialog(field);

                    }

                });

            } else if (name.equals("float")) {

                /**
                 * Handle Float object
                 */

                Float value = (Float) field.get(currentStyle);
                String resourceName = "";

                ImageTextButton.ImageTextButtonStyle buttonStyle = new ImageTextButton.ImageTextButtonStyle(
                        game.skin.getDrawable("default-round"), game.skin.getDrawable("default-round-down"),
                        game.skin.getDrawable("default-round"), game.skin.getFont("default-font"));

                if ((value != null) && (value != 0)) {
                    resourceName = String.valueOf(value);
                } else {
                    buttonStyle.up = game.skinProject.getDrawable("default-rect");
                    buttonStyle.checked = game.skinProject.getDrawable("default-rect");
                }

                actor = new ImageTextButton(resourceName, buttonStyle);
                ((ImageTextButton) actor).setClip(true);
                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {
                        showFloatInputDialog(field);

                    }

                });

            } else if (name.equals("ListStyle")) {

                /**
                 * Handle ListStyle object
                 */
                ListStyle listStyle = (ListStyle) field.get(currentStyle);

                actor = new SelectBox<String>(game.skin, "default");
                Array<String> items = new Array<String>();

                final ObjectMap<String, ListStyle> values = game.skinProject.getAll(ListStyle.class);
                Iterator<String> it = values.keys().iterator();
                String selection = null;

                while (it.hasNext()) {
                    String key = it.next();
                    items.add(key);

                    if (listStyle == values.get(key)) {
                        selection = key;
                    }
                }

                ((SelectBox) actor).setItems(items);

                if (selection != null) {
                    ((SelectBox) actor).setSelected(selection);
                }

                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {

                        String selection = (String) ((SelectBox) actor).getSelected();
                        try {
                            field.set(currentStyle, values.get(selection));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        game.screenMain.saveToSkin();
                        refresh(true);
                        game.screenMain.paneOptions.updateSelectedTableFields();
                        game.screenMain.panePreview.refresh();
                    }

                });

            } else if (name.equals("ScrollPaneStyle")) {

                /**
                 * Handle ListStyle object
                 */
                ScrollPaneStyle scrollStyle = (ScrollPaneStyle) field.get(currentStyle);

                actor = new SelectBox<String>(game.skin, "default");
                Array<String> items = new Array<String>();

                final ObjectMap<String, ScrollPaneStyle> values = game.skinProject
                        .getAll(ScrollPaneStyle.class);
                Iterator<String> it = values.keys().iterator();
                String selection = null;

                while (it.hasNext()) {
                    String key = it.next();
                    items.add(key);

                    if (scrollStyle == values.get(key)) {
                        selection = key;
                    }
                }

                ((SelectBox) actor).setItems(items);

                if (selection != null) {
                    ((SelectBox) actor).setSelected(selection);
                }

                actor.addListener(new ChangeListener() {

                    @Override
                    public void changed(ChangeEvent event, Actor actor) {

                        String selection = (String) ((SelectBox) actor).getSelected();
                        try {
                            field.set(currentStyle, values.get(selection));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        game.screenMain.saveToSkin();
                        refresh(true);
                        game.screenMain.paneOptions.updateSelectedTableFields();
                        game.screenMain.panePreview.refresh();
                    }

                });

            } else {

                Gdx.app.log("OptionsPane", "Unknown type: " + name);
                if (!(currentStyle instanceof AbstractIconStyle)) {
                    actor = new Label("Unknown Type", game.skin);
                }
            }

            if (actor != null) {

                // field name

                // White required
                // Grey optional
                if (game.opt.isFieldOptional(currentStyle.getClass(), field.getName())) {

                    tableFields.add(new Label(field.getName(), game.skin, "optional")).left();

                } else {
                    tableFields.add(new Label(field.getName(), game.skin, "default")).left();

                }

                tableFields.add(actor).left().height(64).padRight(24).expandX().fillX();
                tableFields.row();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        //send changes to PreviewPane
        previewPane.selectedStyleChanged();
    }

}

From source file:de.longri.cachebox3.develop.tools.skin_editor.actors.PreviewPane.java

License:Apache License

private Image getImageFromBitmapName(String bitmapName, float previewScaleFactor) throws IOException {

    ScaledSvg scaledSvg = game.skinProject.get(bitmapName, ScaledSvg.class);
    FileHandle fileHandle = game.skinProject.skinFolder.child(scaledSvg.path);
    Bitmap loadedBitmap = PlatformConnector.getSvg(bitmapName, fileHandle.read(),
            PlatformConnector.SvgScaleType.DPI_SCALED,
            scaledSvg.scale / previewScaleFactor / CB.getScaledFloat(1));

    byte[] data = loadedBitmap.getPngEncodedData();
    Pixmap pixmap = new Pixmap(data, 0, data.length);
    Texture texture = new Texture(pixmap);
    TextureRegion textureRegion = new TextureRegion(texture);
    Image image = new Image(textureRegion);
    return image;
}

From source file:de.longri.cachebox3.develop.tools.skin_editor.ColorPickerDialog.java

License:Apache License

/**
 * Refresh table content with colors from the skin
 *///from w w w  . j  ava  2 s.  c om
public void updateTable() {

    tableColors.clear();
    tableColors.add(new Label("Color Name", game.skin, "title")).left().width(170);
    tableColors.add(new Label("Value", game.skin, "title")).colspan(2).left().width(60).padRight(50);

    tableColors.row();

    Iterator<String> it = colors.keys().iterator();
    while (it.hasNext()) {
        final String key = it.next();
        final Color color = colors.get(key);

        tableColors.add(key).left();

        // Create drawable on the fly
        Pixmap pixmap = new Pixmap(18, 18, Pixmap.Format.RGBA8888);
        pixmap.setColor(color);
        pixmap.fill();
        pixmap.setColor(Color.BLACK);
        pixmap.drawRectangle(0, 0, 18, 18);
        Texture texture = new Texture(pixmap);
        pixmap.dispose();
        tableColors.add(new Image(texture));
        tableColors.add(color.toString()).left();

        TextButton buttonSelect = new TextButton("Select", game.skin);
        buttonSelect.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                try {
                    field.set(game.screenMain.paneOptions.currentStyle, color);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                hide();
                game.screenMain.panePreview.refresh();
                game.screenMain.paneOptions.updateSelectedTableFields();
                game.screenMain.saveToSkin();

            }

        });

        TextButton buttonRemove = new TextButton("Remove", game.skin);
        buttonRemove.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {

                Dialog dlg = new Dialog("Delete Style", game.skin) {

                    @Override
                    protected void result(Object object) {
                        if ((Boolean) object == false) {
                            return;
                        }

                        colors.remove(key);
                        // update table
                        updateTable();
                        game.screenMain.saveToSkin();

                    }

                };

                dlg.pad(20);
                dlg.getContentTable().add("You are sure you want to delete this color?");
                dlg.button("OK", true);
                dlg.button("Cancel", false);
                dlg.key(com.badlogic.gdx.Input.Keys.ENTER, true);
                dlg.key(com.badlogic.gdx.Input.Keys.ESCAPE, false);
                dlg.show(game.screenMain.stage);

            }

        });

        if (field != null) {
            tableColors.add(buttonSelect).padRight(5);
        }
        tableColors.add(buttonRemove);
        tableColors.row();
    }

}

From source file:de.longri.cachebox3.develop.tools.skin_editor.SvgFileIconProvider.java

License:Open Source License

private Drawable getSvgImageIcon(FileChooser.FileItem item) {
    FileHandle fileHandle = item.getFile();
    Bitmap bitmap = null;/*from  w w  w . j av a 2  s  .c  o  m*/
    try {
        bitmap = PlatformConnector.getSvg("", fileHandle.read(),
                PlatformConnector.SvgScaleType.SCALED_TO_WIDTH_OR_HEIGHT, CB.getScaledFloat(100));
    } catch (IOException e) {
        return getImageIcon(item);
    }

    byte[] bytes = bitmap.getPngEncodedData();
    Drawable drawable = new TextureRegionDrawable(
            new TextureRegion(new Texture(new Pixmap(bytes, 0, bytes.length))));
    return drawable;
}