Thread Tools Display Modes
01-19-14, 09:42 AM   #1
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Help with SetTexCoord()

Today I'm asking you for some help with SetTexCoord().
I'm trying to transform icon textures into a 'trapezoid' form. Unfortunately the results are somewhat unexpected.

Let's consider the following code:

Lua Code:
  1. tFrame = CreateFrame("Frame", UIParent)
  2. tFrame:SetPoint("CENTER", UIParent, "CENTER")
  3. tFrame:SetHeight(100)
  4. tFrame:SetWidth(100)
  5. tFrame:Show()
  6.        
  7. tTex = tFrame:CreateTexture(nil,"OVERLAY")
  8. tTex:SetTexture("Interface\\icons\\ability_ambush")
  9. tTex:SetPoint("CENTER", tFrame, "CENTER")
  10. tTex:SetTexCoord(0,0, -0.25,1, 1,0, 1.25, 1)
  11. tTex:Show()

For your overview:
Texture coordinates are
ULx/y: 0/0 URx/y: 1/0
LLx/y: 0/1 LRx/y: 1/1
And the SetTexCoord parameters are ULx/y, LLx/y, URx/y, LRx/y

The result of the code above should be like the one on the right side (I've made this one with Photoshop ... just to show what I'm expecting) in this image:



But the result is like the left one. Almost like expected ... but somewhat 'distorted' in the lower left corner. :/

I can't see where this 'distortion' comes from. Does anyone has an idea?

btw: If you test my code above the actual result will be like this:

This is as expected and is not related to my problem. I've replace the icon texture by a copy of it with a single transparent pixel at all borders. That's all.

Edit
Tried it with a more 'specific' texture. The left one is original, the right one is transformed. Weird.

Last edited by Duugu : 01-19-14 at 10:01 AM.
  Reply With Quote
01-19-14, 11:54 AM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
God that red grid on that green background just killed my eyes. Anyway i also played around with this, and ended up with it's cant be done properly.



As you can see whitin my awesome photoshop skills i think blizazrds settexcord function can't handle properly when you edit all the 4 corner's coordinates. Most likely because it's doesn't start the torsion from the image's center, but it's topleft and bottomright coords.

Last edited by Resike : 01-19-14 at 12:00 PM.
  Reply With Quote
01-19-14, 04:12 PM   #3
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
Not that it eliminates the distortion, but you can get a result closer to your example by fiddling with the numbers and changing the height..
Lua Code:
  1. local tx = UIParent:CreateTexture(nil, 'BACKGROUND')
  2. tx:SetSize(80, 80)
  3. tx:SetPoint('CENTER')
  4. tx:SetTexture(0,0.8,0.2,0.5)
  5.  
  6. local icon = UIParent:CreateTexture(nil, 'OVERLAY')
  7. icon:SetTexture('interface/icons/ability_ambush', true)
  8. icon:SetPoint('CENTER', tx)
  9. icon:SetSize(80, 120)
  10. icon:SetTexCoord(0, -0.25, -0.25, 1.25, 1, -0.25, 1.25, 1.25)
  Reply With Quote
01-20-14, 12:32 AM   #4
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Thank you semlar. I've actually never heard of or used region:SetSize(). oO
That definitely helps a lot.

Today I came up with a complete different way to show undistorted textures of this shape. But be warned .... it's kind of a bad hack. If you are of a sensitive mind then you shouldn't read further.

Nevertheless ... here it is:
Lua Code:
  1. tFrame = CreateFrame("Frame", UIParent)
  2. tFrame:SetPoint("CENTER", UIParent, "CENTER")
  3. tFrame:SetHeight(200)
  4. tFrame:SetWidth(200)
  5. tFrame:Show()
  6. tTex = tFrame:CreateTexture("t0","OVERLAY")
  7. tTex:SetTexture("Interface\\icons\\ability_ambush")
  8. tTex:SetHeight(1)
  9. tTex:SetWidth(tFrame:GetWidth())
  10. tTex:SetPoint("TOP", tFrame, "TOP", 0, 0)
  11. tTex:SetTexCoord(0, 1, 0, 1 / tFrame:GetHeight())
  12. tTex:Show()    
  13. for x = 1, tFrame:GetHeight() do
  14.         tTex = tFrame:CreateTexture("t"..x,"OVERLAY")
  15.         tTex:SetTexture("Interface\\icons\\ability_ambush")
  16.         tTex:SetHeight(1)
  17.         tTex:SetWidth(tFrame:GetWidth())
  18.         tTex:SetPoint("TOP", _G["t"..(x - 1)], "BOTTOM")
  19.         tTex:SetTexCoord(-((1 / tFrame:GetHeight()) * x), 1 + (1 / tFrame:GetHeight()) * x, (1 / tFrame:GetHeight()) * x, ((1 / tFrame:GetHeight()) * x) + (1 / tFrame:GetHeight()))
  20.         tTex:Show()    
  21. end

It just comprises the full texture of a lot of single line textures. Should be easy to write a SetTexture wrapper function to set and handle those 'textures'.

Unfortunately it raises new problems. I'm rotating the parent frame of the textures, and as we know the animation thingi is a great mess. It can't handle textures that are not anchored to the center of the parent widget.

And yes, I know, creating 200 textures to show a single one is a big waste of ressources.

Last edited by Duugu : 01-20-14 at 12:41 AM.
  Reply With Quote
01-20-14, 11:24 AM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
You should check this thread:

http://www.wowinterface.com/forums/s...t=36679&page=2
  Reply With Quote
01-21-14, 12:42 AM   #6
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by Resike View Post
Thank you. But ... hm ... it's about rotating textures. I'm a bit lost. :/ Could you please be more specific? Which part of it?

Last edited by Duugu : 01-21-14 at 12:45 AM.
  Reply With Quote
01-21-14, 05:29 AM   #7
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Duugu View Post
Thank you. But ... hm ... it's about rotating textures. I'm a bit lost. :/ Could you please be more specific? Which part of it?
Lua Code:
  1. local rotateme = function(texture,width,height,scale,anchorframe,framelevel,texr,texg,texb,alpha,duration,side,blendmode,point,pointx,pointy)
  2.  
  3.     local h = CreateFrame("Frame",nil,anchorframe)
  4.     h:SetHeight(height)
  5.     h:SetWidth(width)            
  6.     h:SetPoint(point,pointx,pointy)
  7.     h:SetScale(scale)
  8.     h:SetFrameLevel(framelevel)
  9.  
  10.     local t = h:CreateTexture()
  11.     t:SetAllPoints(h)
  12.     t:SetTexture("Interface\\AddOns\\yourTextures\\"..texture)
  13.     t:SetBlendMode(blendmode)
  14.     t:SetVertexColor(texr,texg,texb,alpha)
  15.     h.t = t
  16.    
  17.     local ag = h:CreateAnimationGroup()
  18.     h.ag = ag
  19.    
  20.     local a1 = h.ag:CreateAnimation("Rotation")
  21.     a1:SetDegrees(6)
  22.     a1:SetDuration(1)
  23.     h.ag.a1 = a1
  24.    
  25.     h.ag:SetLooping("REPEAT")  --repeat this OVER AND OVER?!
  26.  
  27.     return h
  28.  
  29.   end
  30.  
  31.   local f = rotateme(...)
  32.   f.ag:Play()
  33.  
  34.   --adjust values
  35.   --f.ag.a1:SetDegrees(20)
  36.   --f.a1:SetDuration(10)
  37.   --f.ag:SetLooping("REPEAT")

If i get this right this means you can rotate frames instead of textures with animationgroups, means you don't have to rotate your textures one by one, just rotate the frame and tada. I havn't tested this tho.
  Reply With Quote
01-21-14, 06:57 AM   #8
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Ah. Ok. Now I got it.

In fact I do rotate the frame itself (the Default Blizzard ActionButton frames to be exact) via animation groups. It must be the frame that is rotated. The texture is not enough. It's an action button and it clickable. Rotating the texture only would create a really bad user experience with clicking the buttons.
But, as I sayed, the animation feature has bugs. Some child objects are not rotated or not as expected (framestring), some are rotated to somewhere (everthing that is not anchored to the center of the parent object), and so on. It's a great mess.

Additionally to rotating the button frame I would like to change the shape of the (already rotated) button textures. That's what I'm using SetTexCoord for and what's not working as intended.
I'm almost sure there are no other animation types than rotate, scale and linear transform. Or did I missed something? Is there an animation type for custom tranformations?

Last edited by Duugu : 01-21-14 at 07:11 AM.
  Reply With Quote
01-21-14, 07:06 AM   #9
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
There is an alpha change one, but i'm not sure thats gonna help you.
  Reply With Quote
01-21-14, 07:18 AM   #10
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Uhm. Actually that could be helpful.

I could use it to mask parts of the button texture. The texture would just be cropped instead of deformed. But at least it has a trapeziod shape.
Would be better than nothing if everything else fails. I'l keep that in mind. Thank you.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Help with SetTexCoord()

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