package net.shadowfacts.cacao.util /** * Helper class that represents a texture that can be divided into nine pieces (4 corners, 4 edges, and the center) * and can be drawn at any size by combining and repeating those pieces. * * It also provides convenience [Texture] objects that represent the different patches. * * @author shadowfacts * @param texture The base [Texture] object. * @param cornerWidth The width of each corner (and therefore the width of the vertical edges). * @param cornerHeight The height of each corner (and therefore the height of the horizontal edges.) * @param centerWidth The width of the center patch. * @param centerHeight The height of the center patch. */ data class NinePatchTexture(val texture: Texture, val cornerWidth: Int, val cornerHeight: Int, val centerWidth: Int, val centerHeight: Int) { // Corners val topLeft by lazy { texture } val topRight by lazy { Texture(texture.location, texture.u + cornerWidth + centerWidth, texture.v, texture.width, texture.height) } val bottomLeft by lazy { Texture(texture.location, texture.u, texture.v + cornerHeight + centerHeight, texture.width, texture.height) } val bottomRight by lazy { Texture(texture.location, topRight.u, bottomLeft.v, texture.width, texture.height) } // Edges val topMiddle by lazy { Texture(texture.location, texture.u + cornerWidth, texture.v, texture.width, texture.height) } val bottomMiddle by lazy { Texture(texture.location, topMiddle.u, bottomLeft.v, texture.width, texture.height) } val leftMiddle by lazy { Texture(texture.location, texture.u, texture.v + cornerHeight, texture.width, texture.height) } val rightMiddle by lazy { Texture(texture.location, topRight.u, leftMiddle.v, texture.width, texture.height) } // Center val center by lazy { Texture(texture.location, texture.u + cornerWidth, texture.v + cornerHeight, texture.width, texture.height) } }