static NinePatch newDegenerateNinePatch () { final int patchSize = 8; final int pixmapSize = patchSize * 3; TextureRegion tr = newPatchPix(patchSize, pixmapSize); return new NinePatch(tr); }
static NinePatch newULQuadPatch () { final int patchSize = 8; final int pixmapSize = patchSize * 2; TextureRegion tr = newPatchPix(patchSize, pixmapSize); return new NinePatch(tr, patchSize, 0, patchSize, 0); }
static NinePatch newNinePatch () { final int patchSize = 8; final int pixmapSize = patchSize * 3; TextureRegion tr = newPatchPix(patchSize, pixmapSize); return new NinePatch(tr, patchSize, patchSize, patchSize, patchSize); }
/** Returns the first region found with the specified name as a {@link NinePatch}. The region must have been packed with * ninepatch splits. This method uses string comparison to find the region and constructs a new ninepatch, so the result should * be cached rather than calling this method multiple times. * @return The ninepatch, or null. */ public NinePatch createPatch (String name) { for (int i = 0, n = regions.size; i < n; i++) { AtlasRegion region = regions.get(i); if (region.name.equals(name)) { int[] splits = region.splits; if (splits == null) throw new IllegalArgumentException("Region does not have ninepatch splits: " + name); NinePatch patch = new NinePatch(region, splits[0], splits[1], splits[2], splits[3]); if (region.pads != null) patch.setPadding(region.pads[0], region.pads[1], region.pads[2], region.pads[3]); return patch; } } return null; }
/** Creates a new drawable that renders the same as this drawable tinted the specified color. */ public NinePatchDrawable tint (Color tint) { NinePatchDrawable drawable = new NinePatchDrawable(this); drawable.patch = new NinePatch(drawable.getPatch(), tint); return drawable; } }
/** Returns the first region found with the specified name as a {@link NinePatch}. The region must have been packed with * ninepatch splits. This method uses string comparison to find the region and constructs a new ninepatch, so the result should * be cached rather than calling this method multiple times. * @return The ninepatch, or null. */ public NinePatch createPatch (String name) { for (int i = 0, n = regions.size; i < n; i++) { AtlasRegion region = regions.get(i); if (region.name.equals(name)) { int[] splits = region.splits; if (splits == null) throw new IllegalArgumentException("Region does not have ninepatch splits: " + name); NinePatch patch = new NinePatch(region, splits[0], splits[1], splits[2], splits[3]); if (region.pads != null) patch.setPadding(region.pads[0], region.pads[1], region.pads[2], region.pads[3]); return patch; } } return null; }
/** Creates a new drawable that renders the same as this drawable tinted the specified color. */ public NinePatchDrawable tint (Color tint) { NinePatchDrawable drawable = new NinePatchDrawable(this); drawable.patch = new NinePatch(drawable.getPatch(), tint); return drawable; } }
/** Returns a registered ninepatch. If no ninepatch is found but a region exists with the name, a ninepatch is created from the * region and stored in the skin. If the region is an {@link AtlasRegion} then the {@link AtlasRegion#splits} are used, * otherwise the ninepatch will have the region as the center patch. */ public NinePatch getPatch (String name) { NinePatch patch = optional(name, NinePatch.class); if (patch != null) return patch; try { TextureRegion region = getRegion(name); if (region instanceof AtlasRegion) { int[] splits = ((AtlasRegion)region).splits; if (splits != null) { patch = new NinePatch(region, splits[0], splits[1], splits[2], splits[3]); int[] pads = ((AtlasRegion)region).pads; if (pads != null) patch.setPadding(pads[0], pads[1], pads[2], pads[3]); } } if (patch == null) patch = new NinePatch(region); add(name, patch, NinePatch.class); return patch; } catch (GdxRuntimeException ex) { throw new GdxRuntimeException("No NinePatch, TextureRegion, or Texture registered with name: " + name); } }
/** Returns a registered ninepatch. If no ninepatch is found but a region exists with the name, a ninepatch is created from the * region and stored in the skin. If the region is an {@link AtlasRegion} then the {@link AtlasRegion#splits} are used, * otherwise the ninepatch will have the region as the center patch. */ public NinePatch getPatch (String name) { NinePatch patch = optional(name, NinePatch.class); if (patch != null) return patch; try { TextureRegion region = getRegion(name); if (region instanceof AtlasRegion) { int[] splits = ((AtlasRegion)region).splits; if (splits != null) { patch = new NinePatch(region, splits[0], splits[1], splits[2], splits[3]); int[] pads = ((AtlasRegion)region).pads; if (pads != null) patch.setPadding(pads[0], pads[1], pads[2], pads[3]); } } if (patch == null) patch = new NinePatch(region); add(name, patch, NinePatch.class); return patch; } catch (GdxRuntimeException ex) { throw new GdxRuntimeException("No NinePatch, TextureRegion, or Texture registered with name: " + name); } }
static NinePatch newMidlessPatch () { final int patchSize = 8; final int fullPatchHeight = patchSize * 2; final int fullPatchWidth = patchSize * 3; final int pixmapDim = MathUtils.nextPowerOfTwo(Math.max(fullPatchWidth, fullPatchHeight)); Pixmap testPatch = new Pixmap(pixmapDim, pixmapDim, Pixmap.Format.RGBA8888); testPatch.setColor(1, 1, 1, 0); testPatch.fill(); for (int x = 0; x < fullPatchWidth; x += patchSize) { for (int y = 0; y < fullPatchHeight; y += patchSize) { testPatch.setColor(x / (float)fullPatchWidth, y / (float)fullPatchHeight, 1.0f, 1.0f); testPatch.fillRectangle(x, y, patchSize, patchSize); } } return new NinePatch(new TextureRegion(new Texture(testPatch), fullPatchWidth, fullPatchHeight), patchSize, patchSize, patchSize, patchSize); }
/** * 获取九宫图 */ public NinePatch getNinePatch(String name, int left, int right, int top, int bottom) { return new NinePatch(getTextureRegion(name), left, right, top, bottom); }
public PlatformAssets(TextureAtlas atlas) { AtlasRegion region = atlas.findRegion(Constants.PLATFORM_SPRITE); int edge = Constants.PLATFORM_EDGE; platformNinePatch = new NinePatch(region, edge, edge, edge, edge); } }
/** Returns the first region found with the specified name as a {@link NinePatch}. The region must have been packed with * ninepatch splits. This method uses string comparison to find the region and constructs a new ninepatch, so the result should * be cached rather than calling this method multiple times. * @return The ninepatch, or null. */ public NinePatch createPatch (String name) { for (int i = 0, n = regions.size; i < n; i++) { AtlasRegion region = regions.get(i); if (region.name.equals(name)) { int[] splits = region.splits; if (splits == null) throw new IllegalArgumentException("Region does not have ninepatch splits: " + name); NinePatch patch = new NinePatch(region, splits[0], splits[1], splits[2], splits[3]); if (region.pads != null) patch.setPadding(region.pads[0], region.pads[1], region.pads[2], region.pads[3]); return patch; } } return null; }
/** Creates a new drawable that renders the same as this drawable tinted the specified color. */ public NinePatchDrawable tint (Color tint) { NinePatchDrawable drawable = new NinePatchDrawable(this); drawable.patch = new NinePatch(drawable.getPatch(), tint); return drawable; } }
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)); }
@Override public void create() { batch = new SpriteBatch(); viewport = new FitViewport(WORLD_SIZE, WORLD_SIZE); // TODO: Load the platform texture (Look for the file in android/assets) platformTexture = new Texture("platform.png"); // TODO: Initialize the NinePatch using the texture and the EDGE constant platformNinePatch = new NinePatch(platformTexture, EDGE, EDGE, EDGE, EDGE); }
public Drawable getRectLineDrawable(Color color, Color out, int w, int h) { Pixmap pixmap = new Pixmap(w, h, Format.RGBA8888); pixmap.setColor(color); pixmap.fill(); pixmap.setColor(out); pixmap.drawRectangle(0, 0, w, h); Texture colorPoint = new Texture(pixmap); colorPoint.setFilter(filter, filter); pixmap.dispose(); NinePatchDrawable nine = new NinePatchDrawable(new NinePatch(colorPoint, 2, 2, 2, 2)); return nine; }
public static NinePatchDrawable createNinePatchDrawableFromAtlas(ResolutionHelper resolutionHelper, String imageName, TextureAtlas textureAtlas, int patchOffsetLeft, int patchOffsetRight, int patchOffsetTop, int patchOffsetBottom) { NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(); TextureRegion region = textureAtlas.findRegion(imageName); NinePatch patch = new NinePatch(region, patchOffsetLeft, patchOffsetRight, patchOffsetTop, patchOffsetBottom); patch.scale(resolutionHelper.getSizeMultiplier(), resolutionHelper.getSizeMultiplier()); ninePatchDrawable.setPatch(patch); return ninePatchDrawable; } }
private static NinePatch get9(String fname, int wpad, int hpad, int woff, int hoff, int left, int right, int top, int bottom) { final Texture t = new Texture(Gdx.files.internal(fname)); t.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); final int width = t.getWidth() - wpad; final int height = t.getHeight() - hpad; return new NinePatch(new TextureRegion(t, woff, hoff, width, height), left, right, top, bottom); }
private void prepareNinepatch(AssetsInterface assets, float sizeMult) { TextureAtlas atlas = assets.getTextureAtlas(this.atlasName); TextureAtlas.AtlasRegion ninePatchTexture = atlas.findRegion(progressImageFrame); NinePatch patch = new NinePatch(ninePatchTexture, this.ninePatchLeft, this.ninePatchRight, 0, 0); NinePatchDrawable ninePatchDrawable = new NinePatchDrawable(patch); ninePatchDrawable.setMinWidth(ninePatchDrawable.getMinWidth() * sizeMult); ninePatchDrawable.setMinHeight(ninePatchDrawable.getMinHeight() * sizeMult); TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle(ninePatchDrawable, ninePatchDrawable, ninePatchDrawable, assets.getFont(this.fontName)); this.progressBarNinePatch = new TextButton("", textButtonStyle); this.progressBarNinePatch.setWidth(ninePatchTexture.originalWidth); this.progressBarOriginalWidth = ninePatchTexture.originalWidth; this.progressBarNinePatch.setX(this.progressImagePaddingLeft); }