Go Back   WowAce Forums > Addon Chat > Libraries
Libraries Threads for new libraries and mixins.

Reply
 
Thread Tools
Old 05-20-2009   #1
Torhal
Moderator
 
Torhal's Avatar
 
Join Date: Feb 2008
Location: Alabama
Posts: 2,195
Send a message via ICQ to Torhal
Default LibQTipClick-1.1

I have abandoned LibQTipClick-1.0 due to the fact that it was never developed past the proof-of-concept stage, yet started to get some use by addons. To that effect, I am releasing LibQTipClick-1.1 which addresses that fact - and the result is not backward-compatible.

New features:
* The OnMouseDown() handler recognizes which mouse button is pressed.
* The OnMouseUp() handler has been added.
* The :SetNormalCell() function has been added.
* The library has its own methods for the occasion when the default OnEnter() and OnLeave() are replaced.
* Much better documentation.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author/Maintainer of Archy, Ackis Recipe List, Revelation, Spamalyzer, Volumizer, and many other AddOns.

Last edited by Torhal; 05-20-2009 at 08:01 AM.
Torhal is offline   Reply With Quote
Old 05-20-2009   #2
yssaril
Hero Member
 
yssaril's Avatar
 
Join Date: Sep 2006
Posts: 777
Default Re: LibQTipClick-1.1

something is wrong with the new version

following your example using QTC:SetCallback(tooltip, "OnMouseDown", MouseHandler)

throws a string expected error since the first part of that should be "OnMouseDown" instead of tooltip.

if i remove the tooltip arg and just use QTC:SetCallback("OnMouseDown", MouseHandler)
i get the "No function defined." message printed in my chat but everything works as expected (though i am not sure that this will work with multible addons using QTC since it seams to me that i am registering this for every event not just for my tooltip
yssaril is offline   Reply With Quote
Old 05-20-2009   #3
Torhal
Moderator
 
Torhal's Avatar
 
Join Date: Feb 2008
Location: Alabama
Posts: 2,195
Send a message via ICQ to Torhal
Default Re: LibQTipClick-1.1

If I used a colon in my example, I fucked up.

It should be:

Code:
QTC.SetCallback(tooltip, "OnMouseDown", MouseHandler)
Ok, I only fucked up once. All of the other examples were fine. Fixed.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author/Maintainer of Archy, Ackis Recipe List, Revelation, Spamalyzer, Volumizer, and many other AddOns.

Last edited by Torhal; 05-20-2009 at 07:09 AM.
Torhal is offline   Reply With Quote
Old 05-20-2009   #4
yssaril
Hero Member
 
yssaril's Avatar
 
Join Date: Sep 2006
Posts: 777
Default Re: LibQTipClick-1.1

kk that makes sense

also another documentation fix:

it should be QTC.OnLeave(event, cell, arg)
instead of QTC.OnLeave(cell)
if you want the highlighting back (same goes for the OnEnter function)
yssaril is offline   Reply With Quote
Old 05-20-2009   #5
Torhal
Moderator
 
Torhal's Avatar
 
Join Date: Feb 2008
Location: Alabama
Posts: 2,195
Send a message via ICQ to Torhal
Default Re: LibQTipClick-1.1

Bah!

Thanks
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author/Maintainer of Archy, Ackis Recipe List, Revelation, Spamalyzer, Volumizer, and many other AddOns.
Torhal is offline   Reply With Quote
Old 05-20-2009   #6
yssaril
Hero Member
 
yssaril's Avatar
 
Join Date: Sep 2006
Posts: 777
Default Re: LibQTipClick-1.1

alright did some more testing and found a big problem if you have more than one QTC and they register call backs then they will all receive them so addon A with tooltip A will receive callbacks from Addon B with tooltip B and vica versa

also why are you using the callbacks for internal events? why not simply put your code directly in the events then you don't have the overhead of the callback and everything works like it should when others register for callbacks

one solution would be to register callbacks per tooltip not on the lib you would then keep the tooltips stored in QTC instead of releasing them to QT

Last edited by yssaril; 05-20-2009 at 07:56 AM. Reason: idea :P
yssaril is offline   Reply With Quote
Old 05-20-2009   #7
Torhal
Moderator
 
Torhal's Avatar
 
Join Date: Feb 2008
Location: Alabama
Posts: 2,195
Send a message via ICQ to Torhal
Default Re: LibQTipClick-1.1

Ok, try it now, with the old SetCallback method:

Code:
tooltip:SetCallback("OnMouseDown", MouseHandler)
I'll update the documentation. I wasn't completely comfortable with the syntax the other way, either. Thanks for the catch!
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author/Maintainer of Archy, Ackis Recipe List, Revelation, Spamalyzer, Volumizer, and many other AddOns.
Torhal is offline   Reply With Quote
Old 05-20-2009   #8
gagou
Senior Member
 
Join Date: Jul 2006
Location: France
Posts: 416
Default Re: LibQTipClick-1.1

now that LibQTipClick support recognition of the mouse pressed with the OnMouseDown handler I will look into using LibQTipClick instead of a custom provider.

But there are still two things that will require a custom cell provider for tomQuest2, maybe they can be part of LibQTip or LibQTipClick:
* add custom left / right cell padding
* maximum cell width after which the content of the cell will be splitted into multiple lines

I think that both features are great to enhance the appearance of the tooltip and might be usefull

Code:
local cProvider, cPrototype, basecCellPrototype = LibQTip:CreateCellProvider(LibQTip.LabelProvider)
function cPrototype:InitializeCell()
    self.fontString = self:CreateFontString()
    self.fontString:SetFontObject(GameTooltipText)
end

function cPrototype:SetupCell(tooltip, value, justification, font, maxWidth, indent)
    indent = indent or 0
    local width, height = basecCellPrototype.SetupCell(self, tooltip, value, justification, font)
    local fs = self.fontString
    fs:SetPoint("TOPLEFT", self, "TOPLEFT", indent, 0)
    fs:SetPoint("BOTTOMRIGHT", self, "BOTTOMRIGHT", 0, 0)
    width = width + indent
    if width > maxWidth then
        fs:SetWidth(maxWidth)
        height = fs:GetHeight()
        width = maxWidth
    end
    fs:Show()
    return width, height
end

function cPrototype:ReleaseCell() 
    self:ClearAllPoints()
end
gagou is offline   Reply With Quote
Old 05-20-2009   #9
yssaril
Hero Member
 
yssaril's Avatar
 
Join Date: Sep 2006
Posts: 777
Default Re: LibQTipClick-1.1

am getting an error when ever i release the tooltip with the latest version
Quote:
LibQTipClick-1.1-1 (LibQTipClick-1.1):128: attempt to call field 'UnRegisterAllCallbacks' (a nil value)
so i went ahead and looked around the code some and changed some things
the SetCallback i simply removed since it is just a wrapper and we can change the register functions via CBH directly so
Code:
tooltip.callbacks = CBH:New(tooltip)
becomes
Code:
tooltip.callbacks = tooltip.callbacks or CBH:New(tooltip, "SetCallback", "UnSetCallback", "UnSetAllCallback" or false)
also line 111-114 instead of
Code:
tooltip.RegisterCallback(tooltip, ...
we can simply do
Code:
tooltip:RegisterCallback(...
then we fix the error on line 128 by replacing
Code:
tooltip.UnRegisterAllCallbacks()
with
Code:
tooltip:UnSetAllCallback(tooltip)
also i don't think it is neccessary to nil out the CBH reference i think we should be fine by leaving them in the tooltip and if we see the tooltip again then we just use the preexisting handler instead of needing to add a new one

here is what my total code came out to be
Code:
local MAJOR = "LibQTipClick-1.1"
local MINOR =  1
assert(LibStub, MAJOR.." requires LibStub")

local lib, oldminor = LibStub:NewLibrary(MAJOR, MINOR)

if not lib then return end -- No upgrade needed

local QTip = LibStub:GetLibrary("LibQTip-1.0")
assert(QTip, MAJOR.." requires LibQTip-1.0")

local CBH = LibStub:GetLibrary("CallbackHandler-1.0")
assert(CBH, MAJOR.." requires CallbackHandler-1.0")

-------------------------------------------------------------------------------
-- Local variables
-------------------------------------------------------------------------------
lib.LabelProvider, lib.LabelPrototype, lib.BaseProvider = QTip:CreateCellProvider(QTip.LabelProvider)
local cell_provider, cell_prototype, cell_base = lib.LabelProvider, lib.LabelPrototype, lib.BaseProvider

-------------------------------------------------------------------------------
-- Public library API
-------------------------------------------------------------------------------
function lib.OnEnter(event, cell, arg)
	if not cell.highlight then
		cell.highlight = cell:CreateTexture(nil, "BACKGROUND")
		cell.highlight:Hide()
	end
	cell.highlight:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
	cell.highlight:SetBlendMode("ADD")
	cell.highlight:SetAllPoints(cell)
	cell.highlight:Show()
end

function lib.OnLeave(event, cell, arg)
	if cell.highlight then
		cell.highlight:ClearAllPoints()
		cell.highlight:Hide()
	end
end

function lib.OnMouseDown(event, cell, arg, button) PlaySound("igMainMenuOpen") end
function lib.OnMouseUp(event, cell, arg, button)  end

local function Cell_OnEnter(cell) cell.callbacks:Fire("OnEnter", cell, cell.arg) end
local function Cell_OnLeave(cell) cell.callbacks:Fire("OnLeave", cell, cell.arg) end
local function Cell_OnMouseDown(cell, button) cell.callbacks:Fire("OnMouseDown", cell, cell.arg, button) end
local function Cell_OnMouseUp(cell, button) cell.callbacks:Fire("OnMouseUp", cell, cell.arg, button) end

function cell_prototype:InitializeCell() cell_base.InitializeCell(self) end

function cell_prototype:SetupCell(tooltip, value, justification, font, arg, ...)
	local width, height = cell_base.SetupCell(self, tooltip, value, justification, font, arg, ...)
	self:EnableMouse(true)
	self.arg = arg
	self.callbacks = tooltip.callbacks
	self:SetScript("OnEnter", Cell_OnEnter)
	self:SetScript("OnLeave", Cell_OnLeave)
	self:SetScript("OnMouseDown", Cell_OnMouseDown)
	self:SetScript("OnMouseUp", Cell_OnMouseUp)

	return width, height
end

function cell_prototype:ReleaseCell()
	self:EnableMouse(false)
	self:SetScript("OnEnter", nil)
	self:SetScript("OnLeave", nil)
	self:SetScript("OnMouseDown", nil)
	self:SetScript("OnMouseUp", nil)
	self.arg = nil
	self.callbacks = nil
end

-------------------------------------------------------------------------------
-- LibQTip wrapper API
-------------------------------------------------------------------------------
local function AddNormalLine(tooltip, ...)
	local oldProvider = tooltip:GetDefaultProvider()
	tooltip:SetDefaultProvider(QTip.LabelProvider)
	local lineNum, colNum = tooltip:AddLine(...)
	tooltip:SetDefaultProvider(oldProvider)
	return lineNum, colNum
end

local function AddNormalHeader(tooltip, ...)
	local oldProvider = tooltip:GetDefaultProvider()
	tooltip:SetDefaultProvider(QTip.LabelProvider)
	local lineNum, colNum = tooltip:AddHeader(...)
	tooltip:SetDefaultProvider(oldProvider)
	return lineNum, colNum
end

local function SetNormalCell(tooltip, ...)
	local oldProvider = tooltip:GetDefaultProvider()
	tooltip:SetDefaultProvider(QTip.LabelProvider)
	local lineNum, colNum = tooltip:SetCell(...)
	tooltip:SetDefaultProvider(oldProvider)
	return lineNum, colNum
end

function lib:Acquire(key, ...)
	local tooltip = QTip:Acquire(key, ...)
	tooltip:EnableMouse(true)

	tooltip.callbacks = tooltip.callbacks or CBH:New(tooltip, "SetCallback", "UnSetCallback", "UnSetAllCallback" or false)
	tooltip:SetCallback("OnEnter", self.OnEnter)
	tooltip:SetCallback("OnLeave", self.OnLeave)
	tooltip:SetCallback("OnMouseDown", self.OnMouseDown)
	tooltip:SetCallback("OnMouseUp", self.OnMouseUp)

	tooltip.AddNormalLine = AddNormalLine
	tooltip.AddNormalHeader = AddNormalHeader
	tooltip.SetNormalCell = SetNormalCell
	tooltip:SetDefaultProvider(cell_provider)
	return tooltip
end

function lib:IsAcquired(key) return QTip:IsAcquired(key) end

function lib:Release(tooltip)
	tooltip:EnableMouse(false)
	tooltip:UnSetAllCallback(tooltip)
	QTip:Release(tooltip)
end

function lib:IterateTooltips() return QTip:IterateTooltips() end
function lib:CreateCellProvider(baseProvider) return QTip:CreateCellProvider(baseProvider) end
yssaril is offline   Reply With Quote
Old 05-20-2009   #10
Torhal
Moderator
 
Torhal's Avatar
 
Join Date: Feb 2008
Location: Alabama
Posts: 2,195
Send a message via ICQ to Torhal
Default Re: LibQTipClick-1.1

Quote:
Originally Posted by yssaril View Post
the SetCallback i simply removed since it is just a wrapper and we can change the register functions via CBH directly
Good. This was my first time using CBH, and the sparse documentation and all of the real-world examples I'd seen led me to do it that way. I didn't like the wrapper, as it added some overhead, but it was the only way I knew to make it look "clean" at 3 in the morning when doing a quick changeover from a lib-wide callback handler to a tooltip-wide handler. Now I see that I could have avoided that and kept the colon-notation since tooltip is passed as the first arg.

Quote:
Originally Posted by yssaril View Post
also i don't think it is neccessary to nil out the CBH reference i think we should be fine by leaving them in the tooltip and if we see the tooltip again then we just use the preexisting handler instead of needing to add a new one
The problem with that approach is that when you release your tooltip, you may not acquire the same one again. Having a callback table on every tooltip your addon touches will lead to a gradual and unnecessary memory growth.

I'll change the CallbackHandler usage to mirror the rest of your suggestions, but I'm making the unset-all be UnSetAllCallbacks (added the "s" on the end).
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author/Maintainer of Archy, Ackis Recipe List, Revelation, Spamalyzer, Volumizer, and many other AddOns.

Last edited by Torhal; 05-20-2009 at 11:56 PM.
Torhal is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:51 AM.