Quantcast

Add tooltip offset (still beta sorta)

Repooc [09-03-13 - 05:30]
Add tooltip offset (still beta sorta)
Filename
ElvUI_SLE/modules/load_modules.xml
ElvUI_SLE/modules/tooltip/load_tooltip.xml
ElvUI_SLE/modules/tooltip/options.lua
ElvUI_SLE/modules/tooltip/tooltip.lua
diff --git a/ElvUI_SLE/modules/load_modules.xml b/ElvUI_SLE/modules/load_modules.xml
index af684c1..4e0b990 100755
--- a/ElvUI_SLE/modules/load_modules.xml
+++ b/ElvUI_SLE/modules/load_modules.xml
@@ -15,6 +15,7 @@
 	<Include file='marks\load_marks.xml'/>
 	<Include file='minimap\load_minimap.xml'/>
 	<Include file='raidutility\load_raidutility.xml'/>
+	<Include file='tooltip\load_tooltip.xml'/>
 	<Include file='uibuttons\load_uibuttons.xml'/>
 	<Include file='unitframes\load_unitframes.xml'/>
 </Ui>
\ No newline at end of file
diff --git a/ElvUI_SLE/modules/tooltip/load_tooltip.xml b/ElvUI_SLE/modules/tooltip/load_tooltip.xml
new file mode 100644
index 0000000..63a0632
--- /dev/null
+++ b/ElvUI_SLE/modules/tooltip/load_tooltip.xml
@@ -0,0 +1,4 @@
+<Ui xmlns="http://www.blizzard.com/wow/ui/">
+	<Script file='tooltip.lua'/>
+	<Script file='options.lua'/>
+</Ui>
\ No newline at end of file
diff --git a/ElvUI_SLE/modules/tooltip/options.lua b/ElvUI_SLE/modules/tooltip/options.lua
new file mode 100644
index 0000000..d6bc196
--- /dev/null
+++ b/ElvUI_SLE/modules/tooltip/options.lua
@@ -0,0 +1,59 @@
+local E, L, V, P, G = unpack(ElvUI);
+
+local function configTable()
+	--if not E.Options.args.sle.args.tooltip then E.Options.args.sle.args.tooltip = {} end
+	E.Options.args.sle.args.tooltip = {
+		order = 95,
+		type = "group",
+		get = function(info) return E.db.tooltip[ info[#info] ] end,
+		name = L["Tooltip"],
+		args = {
+			header = {
+				order = 1,
+				type = "header",
+				name = L["Tooltip"],
+			},
+			intro = {
+				order = 2,
+				type = 'description',
+				name = "Tooltip description",
+			},
+			offset = {
+				type = "group",
+				name = "Cursor offset for game tooltip",
+				order = 4,
+				guiInline = true,
+				disabled = function() return not E.private.tooltip.enable end,
+				args = {
+					mouseOffsetX = {
+						order = 31,
+						type = 'range',
+						name = 'Tooltip X-offset',
+						desc = 'Offset the tooltip on the X-axis.',
+						min = -200, max = 200, step = 1,
+						set = function(info, value) E.db.tooltip[ info[#info] ] = value end,
+					},
+					mouseOffsetY = {
+						order = 32,
+						type = 'range',
+						name = 'Tooltip Y-offset',
+						desc = 'Offset the tooltip on the Y-axis.',
+						min = -200, max = 200, step = 1,
+						set = function(info, value) E.db.tooltip[ info[#info] ] = value end,
+					},
+					--overrideCombat = {
+						--order = 33,
+						--type = 'toggle',
+						--name = 'Override Combat Hide',
+						--desc = 'When enabled, Combat Hide will get overridden when Shift is pressed. Note: You have to mouseover the unit again for the tooltip to show.',
+						--set = function(info, value)
+						--E.db.tooltip[ info[#info] ] = value
+						--end,
+					--},
+				},
+			},
+		},
+	}
+end
+
+table.insert(E.SLEConfigs, configTable)
\ No newline at end of file
diff --git a/ElvUI_SLE/modules/tooltip/tooltip.lua b/ElvUI_SLE/modules/tooltip/tooltip.lua
new file mode 100644
index 0000000..af9d22e
--- /dev/null
+++ b/ElvUI_SLE/modules/tooltip/tooltip.lua
@@ -0,0 +1,90 @@
+local E, L, V, P, G, _ = unpack(ElvUI); --Import: Engine, Locales, PrivateDB, ProfileDB, GlobalDB
+--local TTOS = E:NewModule('TooltipOffset', 'AceEvent-3.0')
+local TT = E:GetModule('Tooltip');
+
+--local _G = getfenv(0)
+--local GameTooltip, GameTooltipStatusBar = _G["GameTooltip"], _G["GameTooltipStatusBar"]
+
+--Defaults
+P['tooltip']['mouseOffsetX'] = 0
+P['tooltip']['mouseOffsetY'] = 0
+P['tooltip']['overrideCombat'] = false
+
+--Functions to hook
+TT.GameTooltip_SetDefaultAnchorSLE = TT.GameTooltip_SetDefaultAnchor
+function TT:GameTooltip_SetDefaultAnchor(tt, parent)
+	TT:GameTooltip_SetDefaultAnchorSLE(tt, parent)
+	if E.private["tooltip"].enable ~= true then return end
+	if(tt:GetAnchorType() ~= "ANCHOR_NONE") then return end
+	if InCombatLockdown() and self.db.visibility.combat then
+		tt:Hide()
+		return
+	end
+
+	if(parent) then
+		if(self.db.cursorAnchor) then
+			--tt:SetOwner(parent, "ANCHOR_CURSOR")
+			TTOS:AnchorFrameToMouse(tt);
+			return
+		end
+	end
+end
+
+--[[
+function TTOS:GameTooltip_OnUpdate(tt)
+	if (tt.needRefresh and tt:GetAnchorType() == 'ANCHOR_CURSOR' and E.db.tooltip.anchor ~= 'CURSOR') then
+		tt:SetBackdropColor(unpack(E["media"].backdropfadecolor))
+		tt:SetBackdropBorderColor(unpack(E["media"].bordercolor))
+		tt.needRefresh = nil
+	elseif tt.forceRefresh then
+		tt.forceRefresh = nil
+	else
+		TTOS:AnchorFrameToMouse(tt)
+	end
+end
+]]
+
+function TT:AnchorFrameToMouse(frame)
+	if frame:GetAnchorType() ~= "ANCHOR_CURSOR" then return end
+	--if (E.db.tooltip.onlyMod and not (IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown())) then return end
+	local x, y = GetCursorPosition();
+	local scale = frame:GetEffectiveScale();
+	frame:ClearAllPoints();
+	frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", (x/scale + E.db.tooltip.mouseOffsetX), (y/scale + E.db.tooltip.mouseOffsetY));
+end
+
+function TT:AddonName_OnUpdate(self, elapsed)
+  TT:AnchorFrameToMouse(self);
+end
+
+--function TTOS:MODIFIER_STATE_CHANGED(event, key)
+	--if InCombatLockdown() and E.db.tooltip.combathide and not (E.db.tooltip.overrideCombat and IsShiftKeyDown()) then
+	--		GameTooltip:Hide()
+	--end
+--end
+
+--Hooking
+--local TTFrame = CreateFrame('Frame', 'TTOS')
+--TTFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
+--TTFrame:RegisterEvent("MODIFIER_STATE_CHANGED")
+--TTFrame:SetScript("OnEvent",function(self, event)
+ --   if event == "PLAYER_ENTERING_WORLD" then
+		--hooksecurefunc(TT, "GameTooltip_SetDefaultAnchor", TT.GameTooltip_SetDefaultAnchor)
+		--hooksecurefunc(TT, "GameTooltip_OnUpdate", TTOS.GameTooltip_OnUpdate)
+		--TTFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")
+	--end
+	--if event == "MODIFIER_STATE_CHANGED" then
+		--TTOS:MODIFIER_STATE_CHANGED()
+	--end
+--end)
+--TTOSFrame:SetScript("OnUpdate", function(self)
+--	hooksecurefunc(TT, "GameTooltip_SetDefaultAnchor", TTOS.GameTooltip_SetDefaultAnchor)
+--end)
+
+TT.InitializeSLE = TT.Initialize
+function TT:Initialize()
+	TT:InitializeSLE()
+	self:HookScript(GameTooltip, "OnUpdate", "AddonName_OnUpdate");
+end
+
+--E:RegisterModule(TTOS:GetName())
\ No newline at end of file