Issue with draggable texture... - WoWInterface
Thread Tools Display Modes
10-17-15, 04:42 PM   #1
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
  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
  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.
  23.         --Get the scale of the size of the frame to the size of the screen.
  24.         widthScale = widthScale / screenWidth
  25.         heightScale = heightScale / screenHeight
  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
  32.         --Offset the current texture coordinates by the offset.
  33.         TWM_frame.texture:SetTexCoord(x1 - offsetX, x2 - offsetX, y1 + offsetY, y2 + offsetY)
  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>
  48.     </Frame>
  49.  </Ui>

  Reply With Quote
10-17-15, 08:52 PM   #2
Fishing Trainer
Seerah's Avatar
WoWInterface Super Mod
Join Date: Oct 2006
Posts: 10,800

"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-17-15, 08:58 PM   #3
A Wyrmkin Dreamwalker
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Yes OnUpdate.

The frame isnt draggable the texture is.

Edit: Well it is but so is the texture. And the code there is for dragging the texture.

Last edited by TULOA : 10-18-15 at 12:11 AM.
  Reply With Quote
10-18-15, 12:44 AM   #4
A Wyrmkin Dreamwalker
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Ok so I made an observation playing with adding another layer leaving that map as a background and a test...

Apparently something is broken with the pictures themselves... Can I use anything other than TGAs for textures I wonder otherwise what is wrong with these TGAs that certain(Or All) pixels along the border of the image extend forever?

I have included links to the files: (Remove if an issue.)


The above are the files themselves... I dont have any program or know of many that can validate TGAs to find errors.
If anyone does I would love to have it so I can rectify this issue as it appears to be file related.
I hand made the Crest from a JPG into a TGA using Paint.NET

Edit: When using the crest as a layer I only have a few points at the bottom causing issues.
  Reply With Quote
10-18-15, 12:52 AM   #5
A Wyrmkin Dreamwalker
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Ok so this problem in case it helps anyone out is just an issue with the files themselves...

When I edited the AlteracValley TGA to have a 1px empty border around it instead of the image filling the whole of the dimensions it worked without the lines. So I am not sure why the image did that however in the first place.

I hope there is a way to get some form of data validator or something to do a better job with TGA images.
  Reply With Quote
10-18-15, 04:34 AM   #6
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
It only happens if the texture doesn't have at least a 1pixel invisible border AND you made some transition on the texture itself (rotate/textcoord/mirror/etc).

It's not the image is broken, but the transition effect is not suitable for such borderless images.

Last edited by Resike : 10-18-15 at 04:37 AM.
  Reply With Quote
10-18-15, 05:39 AM   #7
A Pyroguard Emberseer
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,059
When you set tiling to false (the second argument of SetTexture), it repeats the edge pixel when you set texture coordinates outside the bounds of the image itself. If tiling is set to true then it starts drawing the texture again, neither of which is what you want.

Since you're using your own image here, the simplest solution is to put a transparent border around it so the part that's repeated isn't visible.

If you weren't able to modify the image, you could set the height and width of the texture instead of setting your coordinates outside the boundaries.

In other words, if you have 100px on the side of your texture that are being repeated, you need to dynamically set the width of the texture to be 100px shorter in addition to adjusting your coordinates to avoid drawing outside the lines.

On a related note, instead of screwing with the texture coordinates just to drag an image around, you could just use standard frame dragging techniques and slap it in a scroll frame to clip it.
  Reply With Quote
10-18-15, 09:53 AM   #8
A Wyrmkin Dreamwalker
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Ok yea I wasnt aware there had to be at least 1px on the border of the image. It really isnt stated anywhere which is surprising to me.

I suppose with tiling it wouldnt matter but it applies to smaller images too. Anyways I'm just glad it turned out to be something easy to notice because these are the kinds of issues otherwise that dont get fixed because its next to impossible to track.

Thanks guys for the input. I am sure someone else will find it useful some day.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Issue with draggable texture...

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off