Package tripleplay.ui.util
Class Scale9
java.lang.Object
tripleplay.ui.util.Scale9
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
Modifier and TypeClassDescriptionstatic class
A horizontal or vertical axis, broken up into 3 chunks. -
Field Summary
Modifier and TypeFieldDescriptionfinal Scale9.Axis
The axes of the 3x3 grid.final Scale9.Axis
The axes of the 3x3 grid. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Scale9.Axis
clamp
(Scale9.Axis axis, float length) Ensures that theAxis
passed in does not exceed the length given.
-
Field Details
-
xaxis
The axes of the 3x3 grid. -
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
Creates a new scale to render the given scale onto a target of the given width and height.
-
-
Method Details
-
clamp
Ensures that theAxis
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.
-