Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
Line 1: Line 1:
 
== Notes on GameTooltip methods ==
 
== Notes on GameTooltip methods ==
   
Tooltips are notoriously difficult to handle in WoW UI code, as the interaction of GameTooltip methods can be quite complicated. See [[Tooltip Pseudo Code]] for a Lua-ish pseudo code representation of every GameTooltip method. Here are some notes:
+
Tooltips are notoriously difficult to handle in WoW UI code, as the interaction of GameTooltip methods can be quite complicated. See [[Tooltip Pseudo Code]] for a Lua-ish pseudo code representation of every GameTooltip method, for an indepth analysis. Here is a list of the most important, trickier points about tooltips:
   
  +
''(Entries in bold are significant behaviour changes in patch 1.10 compared to 1.9)''
* '''SetOwner must be called at least once in the life of a tooltip before it can be filled with data''' (This is new in 1.10).
 
  +
* SetOwner clears tooltip contents and hides the tooltip
 
  +
* Unlike other UI objects, a tooltip has both a parent ''and'' an owner, the two are completely independent.
* SetX with valid data causes Show to be called
 
* SetX with invalid data (e.g. empty bag slot) doesn't alter the tooltip (e.g. doesn't clear it)
+
* '''You must call SetOwner at least once in the lifetime of a tooltip before you can use it.'''
* Show causes the size of the tooltip to be reevaluated
+
* SetOwner clears tooltip contents and hides the tooltip, making it ready for a SetX call.
  +
* If ANCHOR_NONE is used in SetOwner, and you call SetX without setting the anchors manually first, a spurious TOPLEFT anchor is set to UIParent.
* Show causes the anchors of the tooltip to be reset to the one specified in SetOwner, unless it was ANCHOR_NONE
 
 
* SetX with valid data causes Show to be called.
* Hide does not clear the contents of the tooltip
 
  +
* SetX with invalid data may or may not clear the tooltip's contents. (e.g. SetBagItem/SetInventorySlot with empty slot leaves tooltip unchanged, but SetAction with empty slot clears its contents).
* After a Hide, calling Show (or SetX) doesn't redisplay the tooltip, SetOwner must be called first
 
  +
* Show (and therefore SetX) causes the size of the tooltip to be reevaluated.
* The contents of a hidden tooltip can be altered using SetX
 
 
* Show (and therefore SetX) causes the anchors of the tooltip to be reset to the one specified in SetOwner, unless it was ANCHOR_NONE.
* AddLine, AddDoubleLine don't call Show, have to call it manually
 
  +
* ''' Hide clears the contents of the tooltip and invalidates it. After a Hide, SetOwner must be called again. '''
* AppendText does call Show
 
 
* '' The contents of a hidden tooltip can not be altered using SetX. '''
* ClearLines clears lines by setting all TextLeftX fontstrings to hidden and nil text, and all TextRightX fontstrings to hidden (but leaves text of those intact)
 
 
* AddLine, AddDoubleLine don't call Show, have to call it manually.
* Calling Show on a tooltip with no lines (e.g. immediately after ClearLines) calls Hide
 
 
* AppendText does call Show.
 
* ClearLines clears lines by setting all TextLeftX fontstrings to hidden and nil text, and all TextRightX fontstrings to hidden (but leaves text of those intact).
 
* ''' Calling Show on a tooltip with zero lines (e.g. immediately after ClearLines) calls Hide, and therefore makes the tooltip unusable. '''
 
* ''' Hiding the parent of the tooltip clears and invalidates the tooltip. SetOwner must be called again. '''
  +
* ''' Showing the parent of the tooltip causes Show to be called on the tooltip. '''
  +
* ''' A tooltip that has a parent="<parentname>" specified in its XML definition can't call SetOwner in the tooltip's <OnLoad> handler. ''' (unconfirmed, seems to be true in some cases, so best avoid it)
   
 
== Blizzard's GameTooltip ==
 
== Blizzard's GameTooltip ==

Revision as of 21:03, 30 March 2006

Notes on GameTooltip methods

Tooltips are notoriously difficult to handle in WoW UI code, as the interaction of GameTooltip methods can be quite complicated. See Tooltip Pseudo Code for a Lua-ish pseudo code representation of every GameTooltip method, for an indepth analysis. Here is a list of the most important, trickier points about tooltips:

(Entries in bold are significant behaviour changes in patch 1.10 compared to 1.9)

  • Unlike other UI objects, a tooltip has both a parent and an owner, the two are completely independent.
  • You must call SetOwner at least once in the lifetime of a tooltip before you can use it.
  • SetOwner clears tooltip contents and hides the tooltip, making it ready for a SetX call.
  • If ANCHOR_NONE is used in SetOwner, and you call SetX without setting the anchors manually first, a spurious TOPLEFT anchor is set to UIParent.
  • SetX with valid data causes Show to be called.
  • SetX with invalid data may or may not clear the tooltip's contents. (e.g. SetBagItem/SetInventorySlot with empty slot leaves tooltip unchanged, but SetAction with empty slot clears its contents).
  • Show (and therefore SetX) causes the size of the tooltip to be reevaluated.
  • Show (and therefore SetX) causes the anchors of the tooltip to be reset to the one specified in SetOwner, unless it was ANCHOR_NONE.
  • Hide clears the contents of the tooltip and invalidates it. After a Hide, SetOwner must be called again.
  • The contents of a hidden tooltip can not be altered using SetX. '
  • AddLine, AddDoubleLine don't call Show, have to call it manually.
  • AppendText does call Show.
  • ClearLines clears lines by setting all TextLeftX fontstrings to hidden and nil text, and all TextRightX fontstrings to hidden (but leaves text of those intact).
  • Calling Show on a tooltip with zero lines (e.g. immediately after ClearLines) calls Hide, and therefore makes the tooltip unusable.
  • Hiding the parent of the tooltip clears and invalidates the tooltip. SetOwner must be called again.
  • Showing the parent of the tooltip causes Show to be called on the tooltip.
  • A tooltip that has a parent="<parentname>" specified in its XML definition can't call SetOwner in the tooltip's <OnLoad> handler. (unconfirmed, seems to be true in some cases, so best avoid it)

Blizzard's GameTooltip

The default Blizzard interface code defines a GameTooltip object called GameTooltip (confusing, ey). This is used as the game's main tooltip. It consists of a number of lines, to determine how many there are, you can call the GameTooltip:NumLines() function.

GameTooltipTextLeft<num>

Each line of text from the game tooltip is represented by one of these objects, replace <num> with the appropriate line number (from 1 to the number of lines returned from GameTooltip:NumLines()). To obtain the text of a line call the GameTooltipTextLeft<num>:GetText() function.

Example: Looping through all tooltip lines

for i=1,GameTooltip:NumLines() do
   local mytext = getglobal("GameTooltipTextLeft" .. i)
   local text = mytext:GetText()
end

Notes

The tooltip displayed when the mouse is hovering over players and/or NPCs on the minimap is such that all the units being displayed are actually only on the first tooltip line. So, if the tooltip showed 4 players, the names are all in the first tooltip line, delimited by "\n".

GameTooltipTextRight<num>

Some tooltips have both left- and right-aligned sections. In order to get at the right-aligned section, use one of these objects instead of a GameTooltipTextLeft. Otherwise, the functionality is identical.