static NinePatch newDegenerateNinePatch () { final int patchSize = 8; final int pixmapSize = patchSize * 3; TextureRegion tr = newPatchPix(patchSize, pixmapSize); return new NinePatch(tr); }
public void draw (Batch batch, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) { patch.draw(batch, x, y, originX, originY, width, height, scaleX, scaleY, rotation); }
/** Construct a degenerate "nine" patch with only a center component. */ public NinePatch (Texture texture, Color color) { this(texture); setColor(color); }
/** 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; }
/** Sets this drawable's ninepatch and set the min width, min height, top height, right width, bottom height, and left width to * the patch's padding. */ public void setPatch (NinePatch patch) { this.patch = patch; setMinWidth(patch.getTotalWidth()); setMinHeight(patch.getTotalHeight()); setTopHeight(patch.getPadTop()); setRightWidth(patch.getPadRight()); setBottomHeight(patch.getPadBottom()); setLeftWidth(patch.getPadLeft()); }
if (patches == null || patches.length != 9) throw new IllegalArgumentException("NinePatch needs nine TextureRegions"); load(patches); float leftWidth = getLeftWidth(); if ((patches[TOP_LEFT] != null && patches[TOP_LEFT].getRegionWidth() != leftWidth) || (patches[MIDDLE_LEFT] != null && patches[MIDDLE_LEFT].getRegionWidth() != leftWidth) float rightWidth = getRightWidth(); if ((patches[TOP_RIGHT] != null && patches[TOP_RIGHT].getRegionWidth() != rightWidth) || (patches[MIDDLE_RIGHT] != null && patches[MIDDLE_RIGHT].getRegionWidth() != rightWidth) float bottomHeight = getBottomHeight(); if ((patches[BOTTOM_LEFT] != null && patches[BOTTOM_LEFT].getRegionHeight() != bottomHeight) || (patches[BOTTOM_CENTER] != null && patches[BOTTOM_CENTER].getRegionHeight() != bottomHeight) float topHeight = getTopHeight(); if ((patches[TOP_LEFT] != null && patches[TOP_LEFT].getRegionHeight() != topHeight) || (patches[TOP_CENTER] != null && patches[TOP_CENTER].getRegionHeight() != topHeight)
@Override public void create () { TestPatch tp; // Create all the NinePatches to test ninePatches.add(new TestPatch("default")); tp = new TestPatch("20px width"); int bWidth = 20; tp.ninePatch.setLeftWidth(bWidth); tp.ninePatch.setRightWidth(bWidth); tp.ninePatch.setTopHeight(bWidth); tp.ninePatch.setBottomHeight(bWidth); ninePatches.add(tp); tp = new TestPatch("fat left"); tp.ninePatch.setLeftWidth(3 * tp.ninePatch.getRightWidth()); ninePatches.add(tp); tp = new TestPatch("fat top"); tp.ninePatch.setTopHeight(3 * tp.ninePatch.getBottomHeight()); ninePatches.add(tp); tp = new TestPatch("degenerate", newDegenerateNinePatch()); ninePatches.add(tp); tp = new TestPatch("upper-left quad", newULQuadPatch()); ninePatches.add(tp); tp = new TestPatch("no middle row", newMidlessPatch()); ninePatches.add(tp); b = new SpriteBatch(); }
if (imageModel.getNinepatchOffset() == 0) { patch = new NinePatch(new TextureRegion(assets.getTexture(getLocalizedString(imageModel.getTextureSrc()))), imageModel.getNinepatchOffsetLeft(), imageModel.getNinepatchOffsetRight(), imageModel.getNinepatchOffsetTop(), imageModel.getNinepatchOffsetBottom()); } else { patch = new NinePatch(new TextureRegion(assets.getTexture(getLocalizedString(imageModel.getTextureSrc()))), imageModel.getNinepatchOffset(), imageModel.getNinepatchOffset(), imageModel.getNinepatchOffset(), imageModel.getNinepatchOffset()); patch.getTexture().setFilter(Texture.TextureFilter.valueOf(imageModel.getMinFilter()), Texture.TextureFilter.valueOf(imageModel.getMagFilter()));
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; } }
selectBox.getScrollPane().setScrollingDisabled(selectBoxModel.isHorizontalScrollDisabled(), selectBoxModel.isVerticalScrollDisabled()); selectBox.setBounds(selectBoxModel.getX(), selectBoxModel.getY(), selectionBackgroundDrawable.getPatch().getTotalWidth(), selectionBackgroundDrawable.getPatch().getTotalHeight()); normalizeModelSize(selectBoxModel, parent, selectionBackgroundDrawable.getPatch().getTotalWidth(), selectionBackgroundDrawable.getPatch().getTotalHeight()); setBasicProperties(selectBoxModel, selectBox);
/** Returns the bottom padding if set, else returns {@link #getBottomHeight()}. */ public float getPadBottom () { if (padBottom == -1) return getBottomHeight(); return padBottom; }
/** Returns the right padding if set, else returns {@link #getRightWidth()}. */ public float getPadRight () { if (padRight == -1) return getRightWidth(); return padRight; }
/** Returns the left padding if set, else returns {@link #getLeftWidth()}. */ public float getPadLeft () { if (padLeft == -1) return getLeftWidth(); return padLeft; }
bottomLeft = add(patches[BOTTOM_LEFT], color, false, false); leftWidth = patches[BOTTOM_LEFT].getRegionWidth(); bottomHeight = patches[BOTTOM_LEFT].getRegionHeight(); bottomCenter = add(patches[BOTTOM_CENTER], color, true, false); middleWidth = Math.max(middleWidth, patches[BOTTOM_CENTER].getRegionWidth()); bottomHeight = Math.max(bottomHeight, patches[BOTTOM_CENTER].getRegionHeight()); bottomRight = add(patches[BOTTOM_RIGHT], color, false, false); rightWidth = Math.max(rightWidth, patches[BOTTOM_RIGHT].getRegionWidth()); bottomHeight = Math.max(bottomHeight, patches[BOTTOM_RIGHT].getRegionHeight()); middleLeft = add(patches[MIDDLE_LEFT], color, false, true); leftWidth = Math.max(leftWidth, patches[MIDDLE_LEFT].getRegionWidth()); middleHeight = Math.max(middleHeight, patches[MIDDLE_LEFT].getRegionHeight()); middleCenter = add(patches[MIDDLE_CENTER], color, true, true); middleWidth = Math.max(middleWidth, patches[MIDDLE_CENTER].getRegionWidth()); middleHeight = Math.max(middleHeight, patches[MIDDLE_CENTER].getRegionHeight()); middleRight = add(patches[MIDDLE_RIGHT], color, false, true); rightWidth = Math.max(rightWidth, patches[MIDDLE_RIGHT].getRegionWidth()); middleHeight = Math.max(middleHeight, patches[MIDDLE_RIGHT].getRegionHeight()); topLeft = add(patches[TOP_LEFT], color, false, false); leftWidth = Math.max(leftWidth, patches[TOP_LEFT].getRegionWidth()); topHeight = Math.max(topHeight, patches[TOP_LEFT].getRegionHeight()); topCenter = add(patches[TOP_CENTER], color, true, false);
/** Sets this drawable's ninepatch and set the min width, min height, top height, right width, bottom height, and left width to * the patch's padding. */ public void setPatch (NinePatch patch) { this.patch = patch; setMinWidth(patch.getTotalWidth()); setMinHeight(patch.getTotalHeight()); setTopHeight(patch.getPadTop()); setRightWidth(patch.getPadRight()); setBottomHeight(patch.getPadBottom()); setLeftWidth(patch.getPadLeft()); }
if (patches == null || patches.length != 9) throw new IllegalArgumentException("NinePatch needs nine TextureRegions"); load(patches); float leftWidth = getLeftWidth(); if ((patches[TOP_LEFT] != null && patches[TOP_LEFT].getRegionWidth() != leftWidth) || (patches[MIDDLE_LEFT] != null && patches[MIDDLE_LEFT].getRegionWidth() != leftWidth) float rightWidth = getRightWidth(); if ((patches[TOP_RIGHT] != null && patches[TOP_RIGHT].getRegionWidth() != rightWidth) || (patches[MIDDLE_RIGHT] != null && patches[MIDDLE_RIGHT].getRegionWidth() != rightWidth) float bottomHeight = getBottomHeight(); if ((patches[BOTTOM_LEFT] != null && patches[BOTTOM_LEFT].getRegionHeight() != bottomHeight) || (patches[BOTTOM_CENTER] != null && patches[BOTTOM_CENTER].getRegionHeight() != bottomHeight) float topHeight = getTopHeight(); if ((patches[TOP_LEFT] != null && patches[TOP_LEFT].getRegionHeight() != topHeight) || (patches[TOP_CENTER] != null && patches[TOP_CENTER].getRegionHeight() != topHeight)
/** 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; }
/** Returns the bottom padding if set, else returns {@link #getBottomHeight()}. */ public float getPadBottom () { if (padBottom == -1) return getBottomHeight(); return padBottom; }
/** Returns the right padding if set, else returns {@link #getRightWidth()}. */ public float getPadRight () { if (padRight == -1) return getRightWidth(); return padRight; }