congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
NinePatch
Code IndexAdd Tabnine to your IDE (free)

How to use
NinePatch
in
com.badlogic.gdx.graphics.g2d

Best Java code snippets using com.badlogic.gdx.graphics.g2d.NinePatch (Showing top 20 results out of 315)

origin: libgdx/libgdx

static NinePatch newDegenerateNinePatch () {
  final int patchSize = 8;
  final int pixmapSize = patchSize * 3;
  TextureRegion tr = newPatchPix(patchSize, pixmapSize);
  return new NinePatch(tr);
}
origin: libgdx/libgdx

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);
}
origin: libgdx/libgdx

/** Construct a degenerate "nine" patch with only a center component. */
public NinePatch (Texture texture, Color color) {
  this(texture);
  setColor(color);
}
origin: libgdx/libgdx

/** 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;
}
origin: libgdx/libgdx

/** 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());
}
origin: libgdx/libgdx

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)
origin: libgdx/libgdx

@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();
}
origin: libgdx/libgdx

  np1.draw(b, x, y, pwidth, pheight);
    final int pwidth2 = screenWidth - XGAP - x2;
    np2.draw(b, x2, y, pwidth2, pheight);
oldColor.set(np.getColor());
filterColor.set(0.3f, 0.3f, 0.3f, 1.0f);
np.setColor(filterColor);
np.draw(b, x, y, 100, 30);
np.setColor(oldColor);
origin: peakgames/libgdx-stagebuilder

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()));
origin: peakgames/libgdx-stagebuilder

  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;
  }
}
origin: peakgames/libgdx-stagebuilder

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);
origin: libgdx/libgdx

/** Returns the bottom padding if set, else returns {@link #getBottomHeight()}. */
public float getPadBottom () {
  if (padBottom == -1) return getBottomHeight();
  return padBottom;
}
origin: libgdx/libgdx

/** Returns the right padding if set, else returns {@link #getRightWidth()}. */
public float getPadRight () {
  if (padRight == -1) return getRightWidth();
  return padRight;
}
origin: libgdx/libgdx

/** Returns the left padding if set, else returns {@link #getLeftWidth()}. */
public float getPadLeft () {
  if (padLeft == -1) return getLeftWidth();
  return padLeft;
}
origin: libgdx/libgdx

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);
origin: libgdx/libgdx

/** 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());
}
origin: libgdx/libgdx

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)
origin: libgdx/libgdx

/** 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;
}
origin: libgdx/libgdx

/** Returns the bottom padding if set, else returns {@link #getBottomHeight()}. */
public float getPadBottom () {
  if (padBottom == -1) return getBottomHeight();
  return padBottom;
}
origin: libgdx/libgdx

/** Returns the right padding if set, else returns {@link #getRightWidth()}. */
public float getPadRight () {
  if (padRight == -1) return getRightWidth();
  return padRight;
}
com.badlogic.gdx.graphics.g2dNinePatch

Javadoc

A 3x3 grid of texture regions. Any of the regions may be omitted. Padding may be set as a hint on how to inset content on top of the ninepatch (by default the eight "edge" textures of the nine-patch define the padding). When drawn the eight "edge" patches will not be scaled, only the interior patch will be scaled.

NOTE: This class expects a "post-processed" nine-patch, and not a raw ".9.png" texture. That is, the textures given to this class should not include the meta-data pixels from a ".9.png" that describe the layout of the ninepatch over the interior of the graphic. That information should be passed into the constructor either implicitly as the size of the individual patch textures, or via the left, right, top, bottom parameters to #NinePatch(Texture,int,int,int,int)or #NinePatch(TextureRegion,int,int,int,int).

A correctly created TextureAtlas is one way to generate a post-processed nine-patch from a ".9.png" file.

Most used methods

  • <init>
    Construct a nine patch from the given nine texture regions. The provided patches must be consistentl
  • draw
  • setColor
    Copy given color. The color will be blended with the batch color, then combined with the texture col
  • getBottomHeight
  • getRightWidth
  • getTotalHeight
  • getTotalWidth
  • add
  • getLeftWidth
  • getPadBottom
    Returns the bottom padding if set, else returns #getBottomHeight().
  • getPadLeft
    Returns the left padding if set, else returns #getLeftWidth().
  • getPadRight
    Returns the right padding if set, else returns #getRightWidth().
  • getPadLeft,
  • getPadRight,
  • getPadTop,
  • getTexture,
  • getTopHeight,
  • load,
  • prepareVertices,
  • set,
  • setPadding,
  • getColor

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSharedPreferences (Context)
  • getSystemService (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now