It may just be the way things work but who knows...
I have a texture on a frame one can drag. It will be a bigger image in the future but for now its the height and width of the frame. On drag one can move the texture by the offset of the mouse's coordinates.
Question is why is there lines going to infinity of each edge of the square texture. It also doesnt show anything under that layer of the image. Hiding the image shows the background and the side frame border but I can deal with that later. I just want to figure out the edges of the texture.
Also in advance I am not worried at this time with globals and such as I personally deal with them last.
Lua Code:
function TWM_OnLoad()
TWM.running = false
--Create the Texture
local TWMtex = TWM_frame:CreateTexture(nil, "OVERLAY") --Moving Texture
local TWMtex2 = TWM_frame:CreateTexture(nil, "Background") --Background for drag testing.
TWMtex:SetTexture("Interface\\Addons\\TWM\\Maps\\AlteracValley.tga", false)
TWMtex2:SetTexture("Interface\\Addons\\TWM\\Maps\\AlteracValley.tga", false)
TWMtex:SetAllPoints(TWM_frame)
TWMtex2:SetAllPoints(TWM_frame)
TWM_frame.texture = TWMtex
TWM_frame.texture2 = TWMtex2
end
function TWM_OnUpdate(self, elapsed)
--Only running while Left Mouse Button is down.
if TWM.running then
local mouseX,mouseY = GetCursorPosition()
local screenWidth,screenHeight = GetScreenWidth(), GetScreenHeight()
local offsetX,offsetY = 0
widthScale, heightScale. = TWM_frame:GetSize() --Get Width and Height for scale.
--Get the scale of the size of the frame to the size of the screen.
widthScale = widthScale / screenWidth
heightScale = heightScale / screenHeight
--Calculate the offset of the mouse cursor and convert it to (Hopefully) frame
--coordinates while allowing the texture to go out of the frame.
offsetX = ((mouseX- TWM.mouseStartX) / screenWidth) / widthScale
offsetY = ((mouseY- TWM.mouseStartY) / screenHeight) / heightScale
--Offset the current texture coordinates by the offset.
TWM_frame.texture:SetTexCoord(x1 - offsetX, x2 - offsetX, y1 + offsetY, y2 + offsetY)
--For debug: Print the current x,y offset and the starting Upper Left point of the texture.
print(offsetX, offsetY, x1, y1)
else
--Keep track of the mouse for when the user starts to drag on the texture.
TWM.mouseStartX,TWM.mouseStartY = GetCursorPosition();
--Get Texture Coordinates.
x1,y1, _, _, _, _, x2, y2 = TWM_frame.texture:GetTexCoord()
end
end
The XML does the initial frame creation for a reason I no longer remember as I have been away for a while...
XML Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Script file="TWM.lua" />
<Frame name="TWM_frame" parent="UIParent" toplevel="true" enableMouse="true" movable="true">
<Size>
<AbsDimension x="300" y="300" />
</Size>
<TitleRegion>
<Size x="300" y="10"/>
<Anchors><Anchor point="TOP"/></Anchors>
</TitleRegion>
<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background"
edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
<BackgroundInsets>
<AbsInset left="-10" right="-10" top="-10" bottom="-10"/>
</BackgroundInsets>
<TileSize>
<AbsValue val="32"/>
</TileSize>
<EdgeSize>
<AbsValue val="32"/>
</EdgeSize>
</Backdrop>
<Scripts>
<OnLoad>
TWM_OnLoad();
</OnLoad>
<OnMouseDown>
if button == "LeftButton" then
TWM.running = true;
print(TWM.running);
elseif button == "RightButton" then
self:Hide()
end
</OnMouseDown>
<OnMouseUp>
if button == "LeftButton" then
TWM.running = false;
print(TWM.running);
end
</OnMouseUp>
<OnUpdate>
TWM_OnUpdate(self, elapsed);
</OnUpdate>
</Scripts>
<Anchors><Anchor point="CENTER" relativeTo="UIParent"/></Anchors>
</Frame>
</Ui>