Thread Tools Display Modes
03-21-13, 04:37 AM   #1
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
font color from tooltip

So i would like to know font color from a given tooltip line
cant find anything useful in lua documentation for that

And if its possible, that color would be same for all or could be changed by some addons already?
  Reply With Quote
03-21-13, 02:05 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If the text is colored using inline color codes:

Code:
-- turns "|cffff0000" into 255, 0, 0 for example
local r, g, b = GameTooltipTextLeft1:GetText():match("|cff(%x%x)(%x%x)(%x%x)")
r, g, b = tonumber(r, 16), tonumber(g, 16), tonumber(b, 16)
If it's colored using the SetTextColor API:

Code:
local r, g, b = GameTooltipTextLeft1:GetTextColor()
__________________
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
03-21-13, 05:40 PM   #3
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
Thanks, maybe i dont need compare strings and can get all i want from color
  Reply With Quote
03-21-13, 05:45 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
When the text is using inline color codes, GetTextColor will still return the default color (usually white), so you still need to use string matching to determine whether there are inline color codes overriding the deafult color.
__________________
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
03-21-13, 06:23 PM   #5
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
some things i dont get here
basically i want scan dropped item and know if they are thunderforged, elite etc.
that info is in 2nd tooltip line, so knowing that line is green (if item is normal, there is item level in that line written in different color) is better than comparing strings from all languages.

but when i do print(GameTooltipTextLeft2:GetText()) its coming in white, but still got green from GameTooltipTextLeft2:GetTextColor(), well greenish, gets me g 0.99999779462814
when doing it with itemLevel line, print "pass" correct color

well, i wrote something and need wait for debug till wednesday probably
  Reply With Quote
03-21-13, 08:39 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
SetTextColor only affects the individual font string object it's called on. The text and the color are not intriniscally connected, so if you take the text from that font string object, and display it on another font string object, or pass it to a function -- like print() -- you only get the text, not the color or alignment or size or any other properties of the original font string object.

If you got a color when print()-ing the item level line, that means that the item level line uses inline color codes (eg. "|cffffd000Item Level: 496|r") which override the text color set on the font object.

Also, based on what you described, you will need to use string matching on the actual text content, as that green text can be "Heroic" -- or it can be "Raid Finder", or it could be something else. Fortunately, you don't need to do any of the work translating the string; you can just use the pre-defined Blizzard global strings. For example:

Code:
if GameTooltipTextLeft2:GetText() == ITEM_HEROIC then
    -- text is "Heroic" in an English client, "Heroisch" in a German client, etc.
end
Finally, the values returned by GetTextColor can be a bit odd. If you need to match them to detect something, you can "fix" them via rounding to the nearest 100th, like so:

Code:
local r, g, b = GameTooltipTextLeft2:GetTextColor()
r = floor(r * 100 + 0.5) / 100
g = floor(g * 100 + 0.5) / 100
g = floor(b * 100 + 0.5) / 100
__________________
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.

Last edited by Phanx : 03-21-13 at 08:42 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » font color from tooltip


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