Example usage for com.badlogic.gdx.graphics.g2d NinePatch NinePatch

List of usage examples for com.badlogic.gdx.graphics.g2d NinePatch NinePatch

Introduction

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

Prototype

public NinePatch(NinePatch ninePatch) 

Source Link

Usage

From source file:com.game.libgdx.roguelikeengine.PopupInfoText.java

License:Open Source License

public PopupInfoText(int x, int y, String file, int xsize, int ysize) {
    this.x = x;// w  w w  . java  2 s  . c  o  m
    this.y = y;
    this.width = xsize;
    this.height = ysize;
    this.background = new NinePatch(new Texture(Gdx.files.internal(file)));
}

From source file:com.tumblr.oddlydrawn.nahlc.Assets.java

License:Apache License

public void initMainMenu() {
    atlas = new TextureAtlas(Gdx.files.internal(PACKED_ATLAS_PATH));
    boxPatch = new NinePatch(atlas.createPatch(BOX_REGION));
    titleSprite = new Sprite(atlas.findRegion(TITLE_REGION));
}

From source file:com.tumblr.oddlydrawn.nahlc.Assets.java

License:Apache License

public void initSetupScreen() {
    atlas = new TextureAtlas(Gdx.files.internal(SETUP_PACKED_ATLAS_PATH));
    checkedSprite = new AtlasRegion(atlas.findRegion(CHECKED_REGION));
    uncheckedSprite = new AtlasRegion(atlas.findRegion(UNCHECKED_REGION));
    selectedSprite = new AtlasRegion(atlas.findRegion(SELECTED_REGION));
    unselectedSprite = new AtlasRegion(atlas.findRegion(UNSELECTED_REGION));
    boxPatch = new NinePatch(atlas.createPatch(BOX_REGION));
}

From source file:com.tumblr.oddlydrawn.nahlc.Assets.java

License:Apache License

public void initGame() {
    atlas = new TextureAtlas(Gdx.files.internal(PACKED_ATLAS_PATH));
    blocksAtlas = atlas.findRegion(BLOCKS_ATLAS_REGION);
    leftSprite = new Sprite(atlas.findRegion(LEFT_ATLAS_REGION));
    rightSprite = new Sprite(atlas.findRegion(RIGHT_ATLAS_REGION));
    downSprite = new Sprite(atlas.findRegion(DOWN_ATLAS_REGION));
    rotateLeftSprite = new Sprite(atlas.findRegion(ROTATE_LEFT_ATLAS_REGION));
    rotateRightSprite = new Sprite(atlas.findRegion(ROTATE_RIGHT_ATLAS_REGION));
    dropDownSprite = new Sprite(atlas.findRegion(DROP_DOWN_REGION));
    pauseSprite = new Sprite(atlas.findRegion(PAUSE_REGION));
    pauseNoticeSprite = new Sprite(atlas.findRegion(PAUSE_NOTICE_REGION));
    boxPatch = new NinePatch(atlas.createPatch(BOX_REGION));
    mainMenuSprite = new Sprite(atlas.findRegion(MAIN_MENU_REGION));
    newGameSprite = new Sprite(atlas.findRegion(NEW_GAME_REGION));

    downSprite.flip(false, true);/*from   w  w w .jav  a2  s.  co m*/
    rotateLeftSprite.flip(false, true);
    rotateRightSprite.flip(false, true);
    dropDownSprite.flip(false, true);
    pauseNoticeSprite.flip(false, true);
    mainMenuSprite.flip(false, true);
    newGameSprite.flip(false, true);

    leftSprite.setPosition(10, 342);
    rightSprite.setPosition(leftSprite.getX() + 79, 342);
    downSprite.setPosition(49, 406);
    rotateLeftSprite.setPosition(172, 342);
    rotateRightSprite.setPosition(246, 342);
    dropDownSprite.setPosition(217, 416);
    pauseSprite.setPosition(262, 280);
    pauseNoticeSprite.setPosition(48, 160);

    // Floater.NUM_TYPES + 1 because there are 7 block shape types, the 8th is empty.
    textureRegions = new TextureRegion[MAX_NUMBER_COLOR][Floater.NUM_TYPES + 1];

    // There are 7 types of shapes, + 1 is the empty background shape to use.
    for (y = 0; y < Floater.NUM_TYPES + 1; y++) {
        // Makes sure we only get the number of block sets that were created.
        for (x = 0; x < MAX_NUMBER_COLOR; x++) {
            // Converts from int to pixels.
            tmpX = x * BLOCK_WIDTH;
            tmpY = y * BLOCK_HEIGHT;
            // Sets one TextureRegion for each element in the array, correct color in correct place including background.
            textureRegions[x][y] = new TextureRegion(blocksAtlas, tmpX, tmpY, BLOCK_WIDTH, BLOCK_HEIGHT);
        }
    }
}

From source file:com.tumblr.oddlydrawn.nahlc.Assets.java

License:Apache License

public void initGameOver() {
    atlas = new TextureAtlas(Gdx.files.internal(PACKED_ATLAS_PATH));
    boxPatch = new NinePatch(atlas.createPatch(BOX_REGION));
    mainMenuSprite = new Sprite(atlas.findRegion(MAIN_MENU_REGION));
    newGameSprite = new Sprite(atlas.findRegion(NEW_GAME_REGION));
    newRecordSprite = new Sprite(atlas.findRegion(NEW_RECORD_LARGE_REGION));
    gameOverSprite = new Sprite(atlas.findRegion(GAME_OVER_REGION));
}

From source file:com.tumblr.oddlydrawn.nahlc.screens.MainMenuScreen.java

License:Apache License

public MainMenuScreen(Game g) {
    game = g;/*from  www  .j a v  a2s . c o  m*/
    assets = new Assets();
    assets.initMainMenu();
    stage = new Stage(new StretchViewport(Renderer.WIDTH, Renderer.HEIGHT));
    Gdx.input.setInputProcessor(stage);
    skin = new Skin();

    skin.add("default", new BitmapFont(Gdx.files.internal("data/fonts/deja.fnt")));

    skin.add("patch", new NinePatch(assets.getBoxPatch()));

    Image boxPatchImage = new Image(assets.getBoxPatch());
    boxPatchImage.setSize(Renderer.WIDTH - 40, Renderer.HEIGHT - 40);
    boxPatchImage.setPosition(20, 22);
    stage.addActor(boxPatchImage);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = skin.getFont("default");
    textButtonStyle.up = new NinePatchDrawable(assets.getBoxPatch());
    skin.add("default", textButtonStyle);

    table = new Table();
    table.setFillParent(true);
    table.setPosition(0, 0);
    stage.addActor(table);
    table.debug();
    table.debugTable();

    Image titleImage = new Image(assets.getTitleSprite());
    table.add(titleImage).padBottom(200f);
    table.row();

    TextButton newGameButton = new TextButton("New Game", skin);
    table.add(newGameButton).padBottom(20f);
    table.row();

    TextButton licenseButton = new TextButton("License", skin);
    table.add(licenseButton).padBottom(10f);
    table.row();

    newGameButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            dispose();
            game.setScreen(new SetupScreen(game));
        }
    });

    licenseButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            dispose();
            game.setScreen(new LicenseScreen(game));
        }
    });
}

From source file:com.tumblr.oddlydrawn.stupidworm.Assets.java

License:Apache License

public void initMainMenu() {
    atlas = new TextureAtlas(Gdx.files.internal(TEXTURE_ATLAS_LOC));

    checked = atlas.findRegion(CHECKED_REGION_STRING);
    unchecked = atlas.findRegion(UNCHECKED_REGION_STRING);
    background = atlas.findRegion(BACKGROUN_REGION_STRING);
    knob = atlas.findRegion(KNOB_REGION_STRING);

    titleSprite = atlas.createSprite(TITLE_REGION_STRING);

    levelOnePreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_ONE_REGION_STRING));
    levelTwoPreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_TWO_REGION_STRING));
    levelThreePreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_THREE_REGION_STRING));
    levelFourPreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_FOUR_REGION_STRING));
    levelFivePreviewRegion = new TextureRegion(atlas.findRegion(LEVEL_FIVE_REGION_STRING));

    patchBox = new NinePatch(atlas.createPatch(PATCH_BOX_REGION_STRING));

    finePrint = new BitmapFont(Gdx.files.internal(FINE_PRINT));
    font = new BitmapFont(Gdx.files.internal(FONT_LOC));
}

From source file:com.tumblr.oddlydrawn.stupidworm.screens.LicenseScreen.java

License:Apache License

public LicenseScreen(Game g) {
    game = g;/*from w  ww . j a  v  a 2 s  .  c o m*/
    stage = new Stage();
    skin = new Skin();
    batch = new SpriteBatch();
    FileHandle handle;
    handle = Gdx.files.internal(LICENSE_LOC);
    licenseString = handle.readString();

    atlas = new TextureAtlas(Gdx.files.internal(TEXTURE_ATLAS_LOC));

    NinePatch patchBox;
    patchBox = new NinePatch(atlas.createPatch(PATCH_BOX_REGION_STRING));

    Gdx.input.setInputProcessor(stage);
    stage.setViewport(new StretchViewport(WIDTH, HEIGHT));
    Table table = new Table();
    table.setFillParent(true);
    stage.addActor(table);

    Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
    pixmap.setColor(Color.LIGHT_GRAY);
    pixmap.fill();

    // The following defines the defaults for Scene2D's skin
    skin.add("grey", new Texture(pixmap));
    skin.add("default", new BitmapFont(Gdx.files.internal(FONT_LOC)));

    LabelStyle labelStyle = new LabelStyle();
    labelStyle.font = skin.getFont("default");
    skin.add("default", labelStyle);

    ScrollPaneStyle scrollPaneStyle = new ScrollPaneStyle();
    skin.add("default", scrollPaneStyle);

    ButtonStyle buttonStyle = new ButtonStyle();
    skin.add("default", buttonStyle);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = skin.getFont("default");
    textButtonStyle.up = new NinePatchDrawable(patchBox);
    skin.add("default", textButtonStyle);

    // Creates Actors (the entire LICENSE text file) for Scene2D
    Label license = new Label(licenseString, skin);
    ScrollPane scrollPane = new ScrollPane(license, skin);
    scrollPane.setFlickScroll(true);
    table.add(scrollPane);

    // Creates the padding between the text and the button.
    table.row();
    // Label padding = new Label(LABEL_PADDING, skin);
    // table.add(padding);

    // Creates the 'Okay' button
    table.row();
    TextButton okay = new TextButton("Okay", skin);
    table.add(okay);
    okay.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            dispose();
            game.setScreen(new MainMenuScreen(game));
        }
    });

    // Adds padding on top and on the bottom of the table.
    table.padTop(TABLE_PADDING);
    table.padBottom(TABLE_PADDING);
    table.pack();
}

From source file:org.shadebob.skineditor.dialog.DrawablePickerDialog.java

License:Apache License

void updateTableActor() {
    tableDrawables.clear();//from ww w.  j  a v  a 2s.c o m

    Iterator<String> keys = styleNamesMap.keys().iterator();
    int count = 0;
    while (keys.hasNext()) {
        final String styleName = keys.next();
        Button buttonItem = new Button(game.skin);
        Image img = null;
        if (styleNamesMap.get(styleName) instanceof Drawable) {
            img = new Image((Drawable) styleNamesMap.get(styleName));
        } else {
            img = new Image((TextureRegion) styleNamesMap.get(styleName));
        }
        if (zoom == true) {
            buttonItem.add(img).expand().fill().pad(5);
        } else {
            buttonItem.add(img).expand().pad(5);
        }
        String objectType = styleNamesMap.get(styleName).getClass().getSimpleName();
        objectType = objectType.replace("Drawable", "");
        buttonItem.row();
        buttonItem.add(styleName).getActor().setEllipsis(true);
        buttonItem.row();
        buttonItem.add(objectType, "title").getActor().setEllipsis(true);
        buttonItem.row();
        buttonItem.setClip(true);

        buttonItem.addListener(new TextTooltip(styleName, game.skin));
        buttonItem.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                super.clicked(event, x, y);
                if (field == null) {
                    return;
                }
                try {
                    // Since we have reloaded everything we have to get
                    // field back

                    // game.screenMain.paneOptions.refreshSelection();
                    if (styleNamesMap.get(styleName) instanceof Drawable) {
                        field.set(game.screenMain.paneOptions.currentStyleObj, styleNamesMap.get(styleName));
                    } else {
                        boolean ninepatch = false;
                        FileHandle test = new FileHandle("projects/" + game.screenMain.getcurrentProject()
                                + "/assets/" + styleName + ".9.png");
                        if (test.exists() == true) {
                            ninepatch = true;
                        }
                        if (ninepatch) {
                            game.skinProject.add(styleName, new NinePatchDrawable(
                                    new NinePatch((TextureRegion) styleNamesMap.get(styleName))));
                            field.set(game.screenMain.paneOptions.currentStyleObj,
                                    game.skinProject.getDrawable(styleName));
                        } else {
                            game.skinProject.add(styleName, new SpriteDrawable(
                                    new Sprite((TextureRegion) styleNamesMap.get(styleName))));
                            field.set(game.screenMain.paneOptions.currentStyleObj,
                                    game.skinProject.getDrawable(styleName));
                        }
                    }

                    game.screenMain.changeSkin();
                    hide();
                    game.screenMain.panePreview.refresh();
                    game.screenMain.paneOptions.updateSelectedTableFields();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        tableDrawables.add(buttonItem).width(140).height(160).pad(5);
        if (count == 5) {
            count = 0;
            tableDrawables.row();
            continue;
        }
        count++;
    }
}

From source file:org.shadebob.skineditor.DrawablePickerDialog.java

License:Apache License

/**
 * /*w w  w.  j a  v  a2 s.co  m*/
 */
public void updateTable() {

    tableDrawables.clear();

    Iterator<String> keys = items.keys().iterator();
    int count = 0;

    while (keys.hasNext()) {

        final String key = keys.next();
        if (key.startsWith("widgets/")) {
            continue;
        }

        Button buttonItem = new Button(game.skin);

        Image img = null;
        if (items.get(key) instanceof Drawable) {
            img = new Image((Drawable) items.get(key));
        } else {
            img = new Image((TextureRegion) items.get(key));

        }

        if (zoom == true) {
            buttonItem.add(img).expand().fill().pad(5);
        } else {
            buttonItem.add(img).expand().pad(5);
        }

        buttonItem.addListener(new ChangeListener() {

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

                if (field == null) {
                    return;
                }

                try {
                    // Since we have reloaded everything we have to get
                    // field back

                    // game.screenMain.paneOptions.refreshSelection();
                    if (items.get(key) instanceof Drawable) {
                        field.set(game.screenMain.paneOptions.currentStyle, items.get(key));
                    } else {

                        boolean ninepatch = false;
                        FileHandle test = new FileHandle("projects/" + game.screenMain.getcurrentProject()
                                + "/assets/" + key + ".9.png");
                        if (test.exists() == true) {
                            ninepatch = true;
                        }

                        if (ninepatch == true) {
                            game.skinProject.add(key,
                                    new NinePatchDrawable(new NinePatch((TextureRegion) items.get(key))));
                            field.set(game.screenMain.paneOptions.currentStyle,
                                    game.skinProject.getDrawable(key));

                        } else {
                            game.skinProject.add(key,
                                    new SpriteDrawable(new Sprite((TextureRegion) items.get(key))));
                            field.set(game.screenMain.paneOptions.currentStyle,
                                    game.skinProject.getDrawable(key));

                        }
                    }

                    game.screenMain.saveToSkin();
                    hide();
                    game.screenMain.panePreview.refresh();
                    game.screenMain.paneOptions.updateSelectedTableFields();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

        });

        String objectType = items.get(key).getClass().getSimpleName();
        objectType = objectType.replace("Drawable", "");

        buttonItem.row();
        buttonItem.add(new Label(key, game.skin));
        buttonItem.row();
        buttonItem.add(new Label(objectType, game.skin, "title"));
        buttonItem.row();
        buttonItem.setClip(true);
        tableDrawables.add(buttonItem).width(160).height(184).pad(5);

        if (count == 4) {
            count = 0;
            tableDrawables.row();
            continue;
        }

        count++;
    }

}