View Single Post
10-17-15, 04:42 PM   #1
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Issue with draggable texture...

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:
  1. function TWM_OnLoad()
  2.     TWM.running = false
  3.    
  4.     --Create the Texture
  5.     local TWMtex = TWM_frame:CreateTexture(nil, "OVERLAY") --Moving Texture
  6.     local TWMtex2 = TWM_frame:CreateTexture(nil, "Background") --Background for drag testing.
  7.     TWMtex:SetTexture("Interface\\Addons\\TWM\\Maps\\AlteracValley.tga", false)
  8.     TWMtex2:SetTexture("Interface\\Addons\\TWM\\Maps\\AlteracValley.tga", false)
  9.     TWMtex:SetAllPoints(TWM_frame)
  10.     TWMtex2:SetAllPoints(TWM_frame)
  11.     TWM_frame.texture = TWMtex
  12.     TWM_frame.texture2 = TWMtex2
  13. end
  14.  
  15. function TWM_OnUpdate(self, elapsed)
  16.     --Only running while Left Mouse Button is down.
  17.     if TWM.running then
  18.         local mouseX,mouseY = GetCursorPosition()
  19.         local screenWidth,screenHeight = GetScreenWidth(), GetScreenHeight()
  20.         local offsetX,offsetY = 0
  21.         widthScale, heightScale. = TWM_frame:GetSize() --Get Width and Height for scale.
  22.        
  23.         --Get the scale of the size of the frame to the size of the screen.
  24.         widthScale = widthScale / screenWidth
  25.         heightScale = heightScale / screenHeight
  26.        
  27.         --Calculate the offset of the mouse cursor and convert it to (Hopefully) frame
  28.         --coordinates while allowing the texture to go out of the frame.
  29.         offsetX = ((mouseX- TWM.mouseStartX) / screenWidth) / widthScale
  30.         offsetY = ((mouseY- TWM.mouseStartY) / screenHeight) / heightScale
  31.        
  32.         --Offset the current texture coordinates by the offset.
  33.         TWM_frame.texture:SetTexCoord(x1 - offsetX, x2 - offsetX, y1 + offsetY, y2 + offsetY)
  34.        
  35.         --For debug: Print the current x,y offset and the starting Upper Left point of the texture.
  36.         print(offsetX, offsetY, x1, y1)
  37.     else
  38.         --Keep track of the mouse for when the user starts to drag on the texture.
  39.         TWM.mouseStartX,TWM.mouseStartY = GetCursorPosition();
  40.         --Get Texture Coordinates.
  41.         x1,y1, _, _, _, _, x2, y2 = TWM_frame.texture:GetTexCoord()
  42.     end
  43. 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:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/"
  2.       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  3.     <Script file="TWM.lua" />
  4.     <Frame name="TWM_frame" parent="UIParent" toplevel="true" enableMouse="true" movable="true">
  5.         <Size>
  6.             <AbsDimension x="300" y="300" />
  7.         </Size>
  8.         <TitleRegion>
  9.             <Size x="300" y="10"/>
  10.             <Anchors><Anchor point="TOP"/></Anchors>
  11.         </TitleRegion>
  12.         <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background"
  13.            edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
  14.             <BackgroundInsets>
  15.                 <AbsInset left="-10" right="-10" top="-10" bottom="-10"/>
  16.             </BackgroundInsets>
  17.             <TileSize>
  18.                 <AbsValue val="32"/>
  19.             </TileSize>
  20.             <EdgeSize>
  21.                 <AbsValue val="32"/>
  22.             </EdgeSize>
  23.         </Backdrop>
  24.         <Scripts>
  25.             <OnLoad>
  26.                 TWM_OnLoad();
  27.             </OnLoad>
  28.             <OnMouseDown>
  29.                 if button == "LeftButton" then
  30.                     TWM.running = true;
  31.                     print(TWM.running);
  32.                 elseif button == "RightButton" then
  33.                     self:Hide()
  34.                 end
  35.             </OnMouseDown>
  36.             <OnMouseUp>
  37.                 if button == "LeftButton" then
  38.                     TWM.running = false;
  39.                     print(TWM.running);
  40.                 end
  41.             </OnMouseUp>
  42.             <OnUpdate>
  43.                 TWM_OnUpdate(self, elapsed);
  44.             </OnUpdate>
  45.         </Scripts>
  46.         <Anchors><Anchor point="CENTER" relativeTo="UIParent"/></Anchors>
  47.        
  48.     </Frame>
  49.  </Ui>

  Reply With Quote