Thread Tools Display Modes
04-30-14, 02:37 PM   #1
Malakahh
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 30
SetPortraitToTexture and SetTexCoord

Hi

I'm in the process of creating a casting bar, and I'm currently working with the icon of the spell currently being cast.

The icon I plan to use is the one returned by UnitCastingInfo(). This icon however, is square with a border, I want a circular icon.

I have tried using SetPortraitToTexture() and it does indeed make it fit inside a circle, this however leaves some of the border present in the icon image still visible, so I thought, hey, let's crop these out using SetTexCoord()! This does remove the border, however, the image is no longer circular. This has the same effect no matter the call order of these two.

This is the relevant code (from my OnEvent handler)
Lua Code:
  1. if event == "UNIT_SPELLCAST_START" then
  2.     local name, _, _, texture, startTime, endTime = UnitCastingInfo(this.unit)
  3.  
  4.     if not name then
  5.         this.Hide()
  6.         return
  7.     end
  8.  
  9.     SetPortraitToTexture(centerContentTexture, texture)
  10.     centerContentTexture:SetTexCoord(0.1, 0.9, 0.1, 0.9)
  11.  
  12.     this.casting = 1
  13.     this.startTime = startTime
  14.     this.endTime = endTime
  15.  
  16.     this.Show()
  17. end

An an example of what this looks like:


I don't know how to achieve what I want, a circular image where no pieces of the border are left. Any help is greatly appreciated =)

*EDIT*
So, 2 minutes after posting this, I realized that it was actually circular, my numbers in SetTexCoord() where just wrong. So it has now removed some of the border, while maintaining being circular. I can't get it perfect though, which is unfortunate, but this leaves me to think that I'm going about this the wrong way. Is there a way to crop the picture, and use this cropped instance with SetPortraitToTexture()?

Last edited by Malakahh : 04-30-14 at 02:46 PM.
  Reply With Quote
04-30-14, 03:30 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If SetTexCoord works with SetTextureToPortrait, what exactly is the problem? Just adjust your coordinates. The traditional coords used to trim the borders off of spell icons are 0.07, 0.93, 0.07, 0.93 but if you want to be really safe you can use 0.1, 0.9, 0.1, 0.9 instead.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
04-30-14, 04:21 PM   #3
Malakahh
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 30
Thanks for the fast reply =)

Using the coords you suggested it looks very similar to the picture in the first post


As you can see, it's still outside the inner circle texture.
Fiddling with the coords a bit more, I got the following result, using the following coords: 0.03, 0.97, 0.03, 0.97. However, here it is inside the inner circle texture, but there a black bars on the edges, as it appears only the corners are round.


I've attached the entire file as it is currently (it does have dependencies I haven't attached, these however have nothing to do with the inner content).

As for SetTexCoords working with SetTextureToPortrait:
It is a bit hard to describe. It seems as if the rounding done by SetTextureToPortrait is in relation to the size of the original texture, and so is the work done by SetTexCoords, giving the result of only rounded corners, not a perfect circle. This is the case no matter the order in which SetTextureToPortrait and SetTexCoords are called. This can be seen in the first picture in this reply.

What I would want is to call SetTexCoords to crop the borders of the pictures, and taking the result hereof and marking a circle out of it. This does not appear to be how these two functions work though.
Attached Files
File Type: lua CastingOrb.lua (5.0 KB, 226 views)
  Reply With Quote
04-30-14, 04:25 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
I would just create a small black circular border to cover the edge of your texture.
  Reply With Quote
04-30-14, 07:22 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by semlar View Post
I would just create a small black circular border to cover the edge of your texture.
This is usually how this is done. The edges of the icon then hide behind the border.
__________________
"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
05-01-14, 01:49 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yeah, that's even what Blizzard does, for example, in the talent frame. The circular border hides the built-in border on the icon texture.

Your other option would be to actually make circular versions of every spell icon -- see the Cold Icons packages for instructions on how to batch-process them in Photoshop -- but that seems like a lot of effort, not to mention a rather huge download package, for a simple cast bar.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
05-01-14, 02:28 AM   #7
Malakahh
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 30
Thanks for the input guys =)

Hiding it behind a border seems to me like fixing the symptoms, rather than fixing the problem, but it is a simple solution!
  Reply With Quote
05-02-14, 08:26 PM   #8
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
Originally Posted by Phanx View Post
Yeah, that's even what Blizzard does, for example, in the talent frame. The circular border hides the built-in border on the icon texture.

Your other option would be to actually make circular versions of every spell icon -- see the Cold Icons packages for instructions on how to batch-process them in Photoshop -- but that seems like a lot of effort, not to mention a rather huge download package, for a simple cast bar.
There's also the additional caveat that SetPortraitToTexture requires the image to be BLP format. I almost lost my mind one evening over that little tidbit.

EDIT: This is what I get for skimming - you specified circular, which makes my above text pointless.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » SetPortraitToTexture and 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