com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable Java Examples

The following examples show how to use com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DialogImageFont.java    From skin-composer with MIT License 6 votes vote down vote up
private void loadSettings(FileHandle file) {
    var imagePath = ((TextField) findActor("imagepath")).getText();
    var targetPath = ((TextField) findActor("targetpath")).getText();
    
    json.setOutputType(JsonWriter.OutputType.json);
    settings = json.fromJson(ImageFontSettings.class, file.readString("utf-8"));
    refreshTable();
    previewStyle.fontColor = settings.previewColor;
    previewStyle.background = ((NinePatchDrawable) previewStyle.background).tint(settings.previewBackgroundColor);
    previewStyle.focusedBackground = ((NinePatchDrawable) previewStyle.focusedBackground).tint(settings.previewBackgroundColor);
    
    if (targetPath != null && !targetPath.equals("")) {
        processSaveFile(targetPath);
    }
    
    if (imagePath != null && !imagePath.equals("")) {
        processSourceFile(Gdx.files.absolute(imagePath), false);
    }
}
 
Example #2
Source File: CocoStudioUIEditor.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
public Drawable findDrawable(ObjectData option, String name) {

        if (option.isScale9Enable()) {// 九宫格支持
            TextureRegion textureRegion = findTextureRegion(option, name);
            NinePatch np = new NinePatch(textureRegion,
                option.getScale9OriginX(),
                textureRegion.getRegionWidth() - option.getScale9Width() - option.getScale9OriginX(),
                option.getScale9OriginY(),
                textureRegion.getRegionHeight() - option.getScale9Height() - option.getScale9OriginY());

            np.setColor(getColor(option.getCColor(), option.getAlpha()));
            return new NinePatchDrawable(np);
        }

        TextureRegion tr = findTextureRegion(option, name);

        if (tr == null) {
            return null;
        }

        return new TextureRegionDrawable(tr);
    }
 
Example #3
Source File: CCButtonTest.java    From cocos-ui-libgdx with Apache License 2.0 6 votes vote down vote up
@Test
@NeedGL
public void shouldParseSingleButtonWithImages() throws Exception {
    FileHandle defaultFont = Gdx.files.internal("share/MLFZS.ttf");

    CocoStudioUIEditor editor = new CocoStudioUIEditor(
        Gdx.files.internal("single-button/MainScene.json"), null, null, defaultFont, null);

    Group group = editor.createGroup();
    Actor actor = group.findActor("Button_1");

    assertThat(actor, not(nullValue()));
    assertThat(actor, instanceOf(ImageButton.class));
    ImageButton imageButton = (ImageButton) actor;
    assertThat(imageButton.getScaleX(), is(1.7958f));
    assertThat(imageButton.getScaleY(), is(1.8041f));
    ImageButton.ImageButtonStyle style = imageButton.getStyle();
    assertThat(style.imageDisabled, instanceOf(NinePatchDrawable.class));
    assertThat(style.up, instanceOf(NinePatchDrawable.class));
    assertThat(style.down, instanceOf(NinePatchDrawable.class));
}
 
Example #4
Source File: PageGroup.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
public PageGroup(Skin skin, PageModel page) {
    this.page = page;
    setTransform(false);

    borderFrame = new NinePatchDrawable(skin.getPatch("custom/white_frame")).tint(Color.BLACK);

    setSize(page.getWidth(), page.getHeight());
    setTouchable(Touchable.disabled);

    addActor(new RegionSpotlight(skin));
}
 
Example #5
Source File: Skin.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
/** Returns a copy of the specified drawable. */
public Drawable newDrawable(Drawable drawable) {
	if (drawable instanceof TextureRegionDrawable)
		return new TextureRegionDrawable((TextureRegionDrawable) drawable);
	if (drawable instanceof NinePatchDrawable)
		return new NinePatchDrawable((NinePatchDrawable) drawable);
	if (drawable instanceof SpriteDrawable)
		return new SpriteDrawable((SpriteDrawable) drawable);
	throw new GdxRuntimeException("Unable to copy, unknown drawable type: " + drawable.getClass());
}
 
Example #6
Source File: MainMenuInterface.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
private void setUpSkin() {
	Pixmap pixmap = new Pixmap(1, 1, Format.RGBA8888);
	pixmap.setColor(Color.LIGHT_GRAY);
	pixmap.fill();
	skin.add("grey", new Texture(pixmap));
	titleSprite.setX(TITLE_SPRITE_POS_X);
	titleSprite.setY(TITLE_SPRITE_POS_Y);

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

	CheckBoxStyle checkBoxStyle = new CheckBoxStyle();
	checkBoxStyle.checkboxOff = skin.newDrawable("grey", Color.LIGHT_GRAY);
	checkBoxStyle.checkboxOn = skin.newDrawable("grey", Color.LIGHT_GRAY);
	checkBoxStyle.font = skin.getFont("default");
	checkBoxStyle.checkboxOff = new TextureRegionDrawable(unchecked);
	checkBoxStyle.checkboxOn = new TextureRegionDrawable(checked);
	skin.add("default", checkBoxStyle);

	SliderStyle sliderStyle = new SliderStyle();
	sliderStyle.background = new TextureRegionDrawable(background);
	sliderStyle.knob = new TextureRegionDrawable(knob);
	skin.add("default-horizontal", sliderStyle);

	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);
}
 
Example #7
Source File: NinePatchEditorDialog.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
private void updatePreviewNinePatch() {
    int[] patches = model.readPatchValues();
    NinePatch ninePatch = new NinePatch(model.texture, patches[0], patches[1], patches[2], patches[3]);
    previewImage.setDrawable(new NinePatchDrawable(ninePatch));
}
 
Example #8
Source File: ContentGrid.java    From gdx-texture-packer-gui with Apache License 2.0 4 votes vote down vote up
public ContentGrid(Skin skin, Color primaryColor, GridValues values) {
    super(skin, primaryColor, values);
    contentAreaDrawable = ((NinePatchDrawable)skin.getDrawable("white"))
            .tint(new Color(primaryColor.r, primaryColor.g, primaryColor.b, 0.25f));
}
 
Example #9
Source File: NinePatchEditorDialog.java    From gdx-skineditor with Apache License 2.0 2 votes vote down vote up
public void refreshPreview() {

		Gdx.app.log("NinePatchEditorDialog","refresh preview.");

		Pixmap pixmapImage = new Pixmap(Gdx.files.internal(textSourceImage.getText()));
		
		Pixmap pixmap = new Pixmap((int) (pixmapImage.getWidth()+2), (int) (pixmapImage.getHeight()+2), Pixmap.Format.RGBA8888);
		pixmap.drawPixmap(pixmapImage,1,1);

		pixmap.setColor(Color.BLACK);
		
		// Range left
		int h = pixmapImage.getHeight()+1;
		pixmap.drawLine(0, (int) (h * rangeLeft.rangeStart),0, (int) (h * rangeLeft.rangeStop));
		

		// Range top
		int w = pixmapImage.getWidth()+1;
		pixmap.drawLine((int) (w * rangeTop.rangeStart), 0,(int) (w * rangeTop.rangeStop), 0);

		// Range right
		h = pixmapImage.getHeight()+1;
		pixmap.drawLine(pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStart),pixmapImage.getWidth()+1, (int) (h * rangeRight.rangeStop));

		// Range bottom
		w = pixmapImage.getWidth()+1;
		pixmap.drawLine((int) (w * rangeBottom.rangeStart), pixmap.getHeight()-1,(int) (w * rangeBottom.rangeStop), pixmap.getHeight()-1);
		
		
		PixmapIO.writePNG(tmpFile, pixmap);
		
		pixmapImage.dispose();
		pixmap.dispose();

		FileHandle fh = new FileHandle(System.getProperty("java.io.tmpdir")).child("skin_ninepatch");
		TexturePacker.Settings settings = new TexturePacker.Settings();
		TexturePacker.process(settings, fh.path(), fh.path(), "pack");

		TextureAtlas ta = new TextureAtlas(fh.child("pack.atlas"));
		NinePatch np = ta.createPatch("button");
		NinePatchDrawable drawable = new NinePatchDrawable(np);
		reviewTablePreview();	
		buttonPreview1.getStyle().up = drawable;
		

	}