API TextureBase SetTexCoord

Sets the coordinates for cropping or transforming the texture.
 TextureBase:SetTexCoord(left, right, top, bottom)
 TextureBase:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy)
==Arguments==
Coordinates of the four (transformed) image edges.
:left  : - Left (or minX) edge of the scaled/cropped image, as a fraction of the image's width from the left.
:right : - Right (or maxX) edge of the scaled/cropped image, as a fraction of the image's width from the left.
:top   : - Top (or minY) edge of the scaled/cropped image, as a fraction of the image's height from the top.
:bottom: - Bottom (or maxY) edge of the scaled/cropped image, as a fraction of the image's height from the top.
Coordinates of the four (transformed) image corners.
:ULx: - Upper left corner X position, as a fraction of the image's width from the left.
:ULy: - Upper left corner Y position, as a fraction of the image's height from the top.
:LLx: - Lower left corner X position, as a fraction of the image's width from the left.
:LLy: - Lower left corner Y position, as a fraction of the image's height from the top.
:URx: - Upper right corner X position, as a fraction of the image's width from the left.
:URy: - Upper right corner Y position, as a fraction of the image's height from the top.
:LRx: - Lower right corner X position, as a fraction of the image's width from the left.
:LRy: - Lower right corner Y position, as a fraction of the image's height from the top.
==Details==
* The four-coordinate version of this function is well-suited to cropping textures. The eight-coordinate version can perform affine transformations, i.e. scaling, translating, shearing and rotating the source image.
* The coordinates used by this function are normalized and vertically reversed compared to traditional WoW frame rectangles: (0,0) is the top-left corner of the image; (1,1) is the bottom right corner.
* You may supply coordinates outside the [0, 1] range; the behavior varies depending on the texture displayed by the texture widget, as well as whether tiling is enabled.
** Interface\ICONS textures are loaded into composite textures by the client; you cannot tile them, and other icons may appear outside the [0,1] coordinate region.
** When tiling is enabled, the image is repeated outside the [0,1] texture coordinates.
** When tiling is disabled, the outermost pixels of the source image are repeated indefinitely outside the [0,1] texture coordinates.
* does not clear the transformation. Call texture:SetTexCoord(0, 1, 0, 1) to display the original image if necessary.
==Example==
local tex = UIParent:CreateTexture()
tex:SetPoint("CENTER")
tex:SetTexture("interface/icons/inv_mushroom_11")
tex:SetTexCoord(0, 0.5, 0.5, 1)
API_TextureBase_SetTexCoord_01.png|crop bottomleft(0, 0.5, 0.5, 1)
API_TextureBase_SetTexCoord_02.png|flip vertically(0, 1, 1, 0)
===Affine Transformations===
:Reference: SetTexCoord Transformations, Wikipedia: Affine transformation
local function setCoords(tex, A, B, C, D, E, F)
	local det = A*E - B*D
	local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy
	ULx, ULy = ( B*F - C*E ) / det, ( -(A*F) + C*D ) / det
	LLx, LLy = ( -B + B*F - C*E ) / det, ( A - A*F + C*D ) / det
	URx, URy = ( E + B*F - C*E ) / det, ( -D - A*F + C*D ) / det
	LRx, LRy = ( E - B + B*F - C*E ) / det, ( -D + A -(A*F) + C*D ) / det
	-- -0, 0, 0.5, 0.866, 0.866, -0.5, 1.366, 0.366
	tex:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy)
end
local tex = UIParent:CreateTexture()
tex:SetPoint("CENTER")
tex:SetTexture("interface/icons/inv_mushroom_11")
local r = math.pi/6
setCoords(tex, math.cos(r), -math.sin(r), 0, math.sin(r), math.cos(r), 0)
API_TextureBase_SetTexCoord_03.png|rotate by 30 degrees(π/6)
See also