Quantcast

Initial work towards LibQTip replacements. Let's not obliterate the default tooltip any longer. You can't expect other addons to play nice.

Scott Sibley [07-03-11 - 09:42]
Initial work towards LibQTip replacements. Let's not obliterate the default tooltip any longer. You can't expect other addons to play nice.
Filename
Modules/Appearance/Appearance.lua
Modules/Fade/Fade.lua
Modules/Position/Position.lua
Modules/UnitTooltip/UnitTooltip.lua
StarTip.lua
diff --git a/Modules/Appearance/Appearance.lua b/Modules/Appearance/Appearance.lua
index 5aaec13..418506a 100644
--- a/Modules/Appearance/Appearance.lua
+++ b/Modules/Appearance/Appearance.lua
@@ -397,7 +397,7 @@ function mod:OnEnable()
 	local cright = self.db.profile.clampRight
 	local ctop = self.db.profile.clampTop
 	local cbottom = self.db.profile.clampBottom
-	GameTooltip:SetClampRectInsets(cleft, cright, ctop, cbottom)
+	StarTip.tooltipMain:SetClampRectInsets(cleft, cright, ctop, cbottom)
 end

 function mod:OnDisable()
diff --git a/Modules/Fade/Fade.lua b/Modules/Fade/Fade.lua
index edfa14e..6614b5c 100644
--- a/Modules/Fade/Fade.lua
+++ b/Modules/Fade/Fade.lua
@@ -106,8 +106,10 @@ local checkExistence = function()
 		end
 		if kind == 2 then
 			GameTooltip:FadeOut()
+			StarTip.tooltipMain:Hide()
 		else
 			GameTooltip:Hide()
+			StarTip.tooltipMain:Hide()
 		end
 	end
 end
@@ -196,4 +198,4 @@ end

 function mod:SetUnit()
 	self.isUnit = true
-end
\ No newline at end of file
+end
diff --git a/Modules/Position/Position.lua b/Modules/Position/Position.lua
index 07d8815..dacb464 100644
--- a/Modules/Position/Position.lua
+++ b/Modules/Position/Position.lua
@@ -332,14 +332,31 @@ function mod:GetOptions()
 	return options
 end

+local getIndex = function(owner)
+	local index
+	if UnitExists("mouseover") then
+		if InCombatLockdown() then
+			index = self.db.profile.inCombat
+		elseif owner == UIParent then
+			index = self.db.profile.anchor
+		else
+			index = self.db.profile.unitFrames
+		end
+	else
+		index = self.db.profile.other
+	end
+	return index
+end
+
 local isSpell
 local isItem
 local lastSpell

 local updateFrame = CreateFrame("Frame")
-local oldX, oldY
-local currentAnchor
-local xoffset, yoffset
+local fakeUpdateFrame = CreateFrame("Frame")
+local oldX, oldY = -1, -1
+local currentAnchor = "BOTTOM"
+local xoffset, yoffset = 0, 0
 local active
 local positionTooltip = function()
 	if not active or isSpell or isItem then return end
@@ -355,22 +372,35 @@ local positionTooltip = function()
 	oldX, oldY = x, y
 end

-local getIndex = function(owner)
-	local index
-	if UnitExists("mouseover") then
-		if InCombatLockdown() then
-			index = self.db.profile.inCombat
-		elseif owner == UIParent then
-			index = self.db.profile.anchor
-		else
-			index = self.db.profile.unitFrames
-		end
-	else
-		index = self.db.profile.other
+local oldX, oldY
+local positionMainTooltip = function()
+	local index = getIndex(UIParent)
+	local currentAnchor = StarTip.opposites[StarTip.anchors[index]:sub(8)]
+	local x, y = GetCursorPosition()
+	local tooltip = StarTip.tooltipMain
+	local effScale = tooltip:GetEffectiveScale()
+	local height = tooltip:GetHeight() or 0
+	local width = tooltip:GetWidth() or 0
+	local screenWidth = UIParent:GetWidth() * effScale
+	local screenHeight = UIParent:GetHeight() * effScale
+	local myOffsetX, myOffsetY = 0, 0
+	if x + width / 2 + xoffset > screenWidth then
+		myOffsetX = (screenWidth - (x + width / 2 + xoffset)) * effScale
+	end
+	if y + height + yoffset > screenHeight then
+		myOffsetY = (screenHeight - (y + height + yoffset) + 1) * effScale
+	end
+	if x - width / 2 < 0 then
+		myOffsetX = (x - width / 2 + 1) * -1 * effScale
+	end
+	if x ~= oldX or y ~= oldY then
+		tooltip:ClearAllPoints()
+		tooltip:SetPoint(currentAnchor, UIParent, "BOTTOMLEFT",
+			(x + xoffset + myOffsetX) / effScale, (y + yoffset + myOffsetY) / effScale + 5)
 	end
-	return index
 end

+
 local setOffsets = function(owner)
 	if owner == UIParent then
 		if UnitExists("mouseover") then
@@ -414,8 +444,10 @@ local function delayAnchor()
 		oldX, oldY = 0, 0
 		currentAnchor = StarTip.opposites[StarTip.anchors[index]:sub(8)]
 		updateFrame:SetScript("OnUpdate", positionTooltip)
+		fakeUpdateFrame:SetScript("OnUPdate", positionMainTooltip)
 		active = true
 		positionTooltip()
+		positionMainTooltip()
 	else
 		if updateFrame:GetScript("OnUpdate") then updateFrame:SetScript("OnUpdate", nil) end
 		this:SetPoint(StarTip.anchors[index], UIParent, StarTip.anchors[index], xoffset, yoffset)
@@ -492,4 +524,5 @@ function mod:SetUnit()
 	isSpell = false
 	isItem = false
 	updateFrame:SetScript("OnUpdate", positionTooltip)
-end
\ No newline at end of file
+	fakeUpdateFrame:SetScript("OnUpdate", positionMainTooltip)
+end
diff --git a/Modules/UnitTooltip/UnitTooltip.lua b/Modules/UnitTooltip/UnitTooltip.lua
index 2a7ebe7..4870b7b 100644
--- a/Modules/UnitTooltip/UnitTooltip.lua
+++ b/Modules/UnitTooltip/UnitTooltip.lua
@@ -863,13 +863,22 @@ do
             table.wipe(widgetsToDraw)
             return
         end
+        for k, v in pairs(lines) do
+
+            tinsert(widgetsToDraw, v.leftObj)
+            tinsert(widgetsToDraw, v.rightObj)
+        end
         for i, widget in ipairs(widgetsToDraw) do
-            if not widget.fontString then break end
-            local fontString = widget.fontString
-            fontString:SetText(widget.buffer)
+            local font = LSM:Fetch("font", fontsList[appearance.db.profile.font])
+            local justification = "LEFT"
+            if widget.x == 2 then
+                justification = "RIGHT"
+            end
+	if(widget.y) then
+            StarTip.tooltipMain:SetCell(widget.y, widget.x, widget.buffer, GameTooltipText, justification)
+	end

-            font = LSM:Fetch("font", fontsList[appearance.db.profile.font])
-            local filename, fontHeight, flags = fontString:GetFont()
+--[[
             if widget.config.outlined and widget.config.outlined > 1 then
                 if widget.config.outlined == 2 then
                     fontString:SetFont(filename, fontHeight, "OUTLINED")
@@ -877,10 +886,12 @@ do
                     fontString:SetFont(filename, fontHeight, "THICKOUTLINED")
                 end
             end
+]]
         end
         table.wipe(widgetsToDraw)
         if UnitExists(StarTip.unit) then
             GameTooltip:Show()
+            StarTip.tooltipMain:Show()
         end
     end
 end
@@ -919,8 +930,17 @@ function mod:CreateLines()
     self:ClearLines()
     lines = setmetatable(llines, {__call=function(self)
             local lineNum = 0
-            GameTooltip:ClearLines()
+            StarTip.tooltipMain:Clear()
+            --GameTooltip:ClearLines()
             for i, v in ipairs(self) do
+                if v.leftObj then
+                    v.leftObj.x = nil
+                    v.leftObj.y = nil
+                end
+                if v.rightObj then
+                    v.rightObj.x = nil
+                    v.rightObj.y = nil
+                end
                 local left, right = '', ''
                 environment.unit = StarTip.unit
                 v.config.unit = StarTip.unit
@@ -945,31 +965,48 @@ function mod:CreateLines()
                 end

                 if type(left) == "string" and type(right) == "string" then
-                    StarTip.addingLine = true
                     lineNum = lineNum + 1
                     if v.right then
-                        GameTooltip:AddDoubleLine(' ', ' ', mod.db.profile.color.r, mod.db.profile.color.g, mod.db.profile.color.b, mod.db.profile.color.r, mod.db.profile.color.g, mod.db.profile.color.b)
-                        v.leftObj.fontString = mod.leftLines[lineNum]
-                        v.rightObj.fontString = mod.rightLines[lineNum]
+                        --GameTooltip:AddDoubleLine(' ', ' ', mod.db.profile.color.r, mod.db.profile.color.g, mod.db.profile.color.b, mod.db.profile.color.r, mod.db.profile.color.g, mod.db.profile.color.b)
+			local y, x
+                        if lineNum == 1 then
+                            y, x = StarTip.tooltipMain:AddHeader('', '')
+                        else
+                            y, x = StarTip.tooltipMain:AddLine('', '')
+                        end
+                        --v.leftObj.fontString = mod.leftLines[lineNum]
+                        --v.rightObj.fontString = mod.rightLines[lineNum]
+			--v.leftObj.fontString = StarTip.qtipLines[y][1]
+			--v.rightObj.fontString = StarTip.qtipLines[y][2]
+			v.leftObj.y = y
+			v.leftObj.x = 1
+			v.rightObj.y = y
+			v.rightObj.x = 2
                     else
-                        GameTooltip:AddLine(' ', mod.db.profile.color.r, mod.db.profile.color.g, mod.db.profile.color.b, v.wordwrap)
-                        v.leftObj.fontString = mod.leftLines[lineNum]
+                        local y, x
+                        if lineNum == 1 then
+                            y, x = StarTip.tooltipMain:AddHeader('')
+                        else
+                            y, x = StarTip.tooltipMain:AddLine('')
+                        end
+                        v.leftObj.y = y
+                        v.leftObj.x = 1
+                        --GameTooltip:AddLine(' ', mod.db.profile.color.r, mod.db.profile.color.g, mod.db.profile.color.b, v.wordwrap)
+                        --v.leftObj.fontString = mod.leftLines[lineNum]
                     end
                     if v.rightObj then
-                        v.rightObj.config.unit = StarTip.unit
                         v.rightObj:Start()
                     end
                     if v.leftObj then
-                        v.leftObj.config.unit = StarTip.unit
                         v.leftObj:Start()
                     end
-                    StarTip.addingLine = false
                     v.lineNum = lineNum
                 end
             end
             mod.NUM_LINES = lineNum
             draw()
-            GameTooltip:Show()
+            --GameTooltip:Show()
+            StarTip.tooltipMain:Show()
     end})
 end

diff --git a/StarTip.lua b/StarTip.lua
index e3ec04c..2af6e0e 100644
--- a/StarTip.lua
+++ b/StarTip.lua
@@ -7,6 +7,9 @@ local LDB = LibStub:GetLibrary("LibDataBroker-1.1")
 local AceConfigDialog = LibStub("AceConfigDialog-3.0")
 local L = LibStub("AceLocale-3.0"):GetLocale("StarTip")
 StarTip.L = L
+local LQT = LibStub:GetLibrary("LibQTip-1.0")
+StarTip.LQT = LQT
+

 local LibCore = LibStub("LibScriptableLCDCoreLite-1.0")
 local LibTimer = LibStub("LibScriptableUtilsTimer-1.0")
@@ -26,6 +29,7 @@ environment._G = _G
 environment.L = L


+
 local LDB = LibStub("LibDataBroker-1.1"):NewDataObject("StarTip", {
 	type = "data source",
 	text = "StarTip",
@@ -437,6 +441,7 @@ function StarTip:OnInitialize()
 	local leftGameTooltipStrings, rightGameTooltipStrings = {}, {}
 	self.leftLines = {}
 	self.rightLines = {}
+	self.qtipLines = {}
 	for i = 1, 50 do
 		GameTooltip:AddDoubleLine(' ', ' ')
 		self.leftLines[i] = _G["GameTooltipTextLeft" .. i]
@@ -461,6 +466,35 @@ function StarTip:SetupTimers()
 	end
 end

+StarTip.cellProvider, StarTip.cellPrototype = LQT:CreateCellProvider()
+
+function StarTip.cellPrototype:InitializeCell()
+	self.fontString = self:CreateFontString()
+	self.fontString:SetAllPoints(self)
+	self.fontString:SetFontObject(GameTooltipText)
+	self.r, self.g, self.b = 1, 1, 1
+	local x, y = self:GetPosition()
+	if not StarTip.qtipLines[y] then
+		StarTip.qtipLines[y] = {}
+	end
+	StarTip.qtipLines[y][x] = self.fontString
+end
+
+function StarTip.cellPrototype:SetupCell(tooltip, value, justification, font, r, g, b)
+	local fs = self.fontString
+	fs:SetFontObject(font or tooltip:GetFont())
+	fs:SetJustifyH(justification)
+	fs:SetText(tostring(value))
+	self.r, self.g, self.b = r or self.r, g or self.g, b or self.b
+	fs:SetTextColor(self.r, self.g, self.b)
+	fs:Show()
+	return fs:GetStringWidth(), fs:GetStringHeight()
+end
+
+function StarTip.cellPrototype:ReleaseCell()
+	self.r, self.g, self.b = 1, 1, 1
+end
+
 function StarTip:OnEnable()
 	if self.db.profile.minimap.hide then
 		LibDBIcon:Hide("StarTipLDB")
@@ -468,6 +502,12 @@ function StarTip:OnEnable()
 		LibDBIcon:Show("StarTipLDB")
 	end

+
+	StarTip.tooltipMain = LQT:Acquire("StarTipQTipMain", 2)
+	--StarTip.tooltipMain:SetDefaultProvider(StarTip.cellProvider)
+	StarTip.tooltipMain:SetParent(UIParent)
+	_G["StarTipQTipMain"] = StarTip.tooltipMain
+
 	GameTooltip:HookScript("OnTooltipSetUnit", self.OnTooltipSetUnit)
 	GameTooltip:HookScript("OnTooltipSetItem", self.OnTooltipSetItem)
 	GameTooltip:HookScript("OnTooltipSetSpell", self.OnTooltipSetSpell)
@@ -664,6 +704,8 @@ function StarTip.OnTooltipSetUnit(...)
 	end
 	StarTip.justSetUnit = nil
 	--checkTooltipAlphaFrame:SetScript("OnUpdate", checkTooltipAlpha)
+	GameTooltip:Hide()
+	StarTip.tooltipMain:Show()
 end

 function StarTip.OnTooltipSetItem(self, ...)
@@ -705,6 +747,7 @@ function StarTip:GameTooltipHide(...)
 	end
 	]]

+	self.tooltipMain:Hide()
 	if hide then
 		StarTip.hooks[GameTooltip].Hide(...)
 	end