WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Help with SetTexCoord() (https://www.wowinterface.com/forums/showthread.php?t=48832)

Duugu 01-19-14 09:42 AM

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. :(

Resike 01-19-14 11:54 AM

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.

semlar 01-19-14 04:12 PM

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)

Duugu 01-20-14 12:32 AM

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. :D

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.

Resike 01-20-14 11:24 AM

You should check this thread:

http://www.wowinterface.com/forums/s...t=36679&page=2

Duugu 01-21-14 12:42 AM

Quote:

Originally Posted by Resike (Post 289896)

Thank you. But ... hm ... it's about rotating textures. I'm a bit lost. :/ Could you please be more specific? Which part of it?

Resike 01-21-14 05:29 AM

Quote:

Originally Posted by Duugu (Post 289914)
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.

Duugu 01-21-14 06:57 AM

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?

Resike 01-21-14 07:06 AM

There is an alpha change one, but i'm not sure thats gonna help you. :)

Duugu 01-21-14 07:18 AM

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. :D
Would be better than nothing if everything else fails. I'l keep that in mind. Thank you.


All times are GMT -6. The time now is 11:37 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI