Class Scale9

java.lang.Object
tripleplay.ui.util.Scale9

public class Scale9 extends Object
Facilitates the rendering of "scale-9" images, that is, images that are designed as a 3x3 grid such that each of the 9 pieces is fixed or stretched in one or both directions to fit a designated area. The corners are drawn without scaling, the top and bottom center pieces are scaled horizontally, the left and right center pieces are scaled vertically, and the center piece is scaled both horizontally and vertically.

By default, the cells are assumed to be of equal size (hence scale-9 image dimensions are normally a multiple of 3). By using xaxis and yaxis, this partitioning can be controlled directly.

Here's a diagram showing the stretching and axes, H = horizontally stretched, V = vertically stretched, U = unstretched.


                         xaxis

                0          1          2
           ---------------------------------
           |          |          |          |
        0  |    U     |    H     |    U     |
           |          |          |          |
           ---------------------------------
           |          |          |          |
 yaxis  1  |    V     |   H&V    |    V     |
           |          |          |          |
           ---------------------------------
           |          |          |          |
        2  |    U     |    H     |    U     |
           |          |          |          |
           ---------------------------------
 

Example 1: the horizontal middle of an image is a single pixel. This code will do that and automatically grow the left and right columns:

     Scale9 s9 = ...;
     s9.xaxis.resize(1, 1);

Example 2: there are no top and bottom rows. This code will stretch all of the image vertically, but keep the left and right third of the image fixed horizontally:

     Scale9 s9 = ...;
     s9.yaxis.resize(0, 0).resize(2, 0);
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A horizontal or vertical axis, broken up into 3 chunks.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The axes of the 3x3 grid.
    The axes of the 3x3 grid.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Scale9(float width, float height)
    Creates a new scale to match the given width and height.
    Scale9(float width, float height, Scale9 source)
    Creates a new scale to render the given scale onto a target of the given width and height.
  • Method Summary

    Modifier and Type
    Method
    Description
    clamp(Scale9.Axis axis, float length)
    Ensures that the Axis passed in does not exceed the length given.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • xaxis

      public final Scale9.Axis xaxis
      The axes of the 3x3 grid.
    • yaxis

      public final Scale9.Axis yaxis
      The axes of the 3x3 grid.
  • Constructor Details

    • Scale9

      public Scale9(float width, float height)
      Creates a new scale to match the given width and height. Each horizontal and vertical sequence is divided equally between the given values.
    • Scale9

      public Scale9(float width, float height, Scale9 source)
      Creates a new scale to render the given scale onto a target of the given width and height.
  • Method Details

    • clamp

      public static Scale9.Axis clamp(Scale9.Axis axis, float length)
      Ensures that the Axis passed in does not exceed the length given. An equal chunk will be removed from the outer chunks if it is too long. The given axis is modified and returned.