The API is no longer being updated here until further notice. |
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
: number - Left (or minX) edge of the scaled/cropped image, as a fraction of the image's width from the left.right
: number - Right (or maxX) edge of the scaled/cropped image, as a fraction of the image's width from the left.top
: number - Top (or minY) edge of the scaled/cropped image, as a fraction of the image's height from the top.bottom
: number - 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
: number - Upper left corner X position, as a fraction of the image's width from the left.ULy
: number - Upper left corner Y position, as a fraction of the image's height from the top.LLx
: number - Lower left corner X position, as a fraction of the image's width from the left.LLy
: number - Lower left corner Y position, as a fraction of the image's height from the top.URx
: number - Upper right corner X position, as a fraction of the image's width from the left.URy
: number - Upper right corner Y position, as a fraction of the image's height from the top.LRx
: number - Lower right corner X position, as a fraction of the image's width from the left.LRy
: number - 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.
- Texture:SetTexture 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)
Affine Transformations[]
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)
See also TextureBase:SetRotation