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.
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
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
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:p
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
am getting an error when ever i release the tooltip with the latest version
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
tooltip.callbacks = CBH:New(tooltip)
becomes
tooltip.callbacks = tooltip.callbacks or CBH:New(tooltip, "SetCallback", "UnSetCallback", "UnSetAllCallback" or false)
also line 111-114 instead of
tooltip.RegisterCallback(tooltip, ...
we can simply do
tooltip:RegisterCallback(...
then we fix the error on line 128 by replacing
tooltip.UnRegisterAllCallbacks()
with
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
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
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.
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). :D
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'm not sure about this one not too sure about the inner workings of CBH so if it keeps the references to the tips internally anyways you are just increasing the overhead since you now are sticking multiple CBH handlers on one tip.
you may want to check with the CBH authors or do some testing
this is all theory so i have no clue :P but from what i can tell CBH is supposed to be added and never removed :P
i'm not sure about this one not too sure about the inner workings of CBH so if it keeps the references to the tips internally anyways you are just increasing the overhead since you now are sticking multiple CBH handlers on one tip.
you may want to check with the CBH authors or do some testing
this is all theory so i have no clue :P but from what i can tell CBH is supposed to be added and never removed :P
It doesn't. CallbackHandler:New() returns a reference to a local variable registry, which I assign to tooltip.callbacks, so nilling that out effectively removes the queue. However, looking at CBH's code, I also need to nil out the functions which CBH sets on the tooltip - in this case, SetCallback, UnSetCallback, and UnSetAllCallbacks - and all will be well.
So myAddon:someMethodName("OnMouseDown") is called when the callback is triggered.
The first argument of SetCallback is not the emitter but the listener. It can also be a arbitrary string (which can be reused later to remove the callback).
So, I'd better store the CBH registry in a "internal" table using tooltip keys, so registered listeners move along with the tooltip key and not the tooltip frame.
So myAddon:someMethodName("OnMouseDown") is called when the callback is triggered.
The first argument of SetCallback is not the emitter but the listener. It can also be a arbitrary string (which can be reused later to remove the callback).
So, I'd better store the CBH registry in a "internal" table using tooltip keys, so registered listeners move along with the tooltip key and not the tooltip frame.
I'll add that to the Getting Started documentation - very nice functionality.
alright switched YssDrop to the new version (release version still uses old one but you can have a look at the alpha if you need something to test with) http://www.wowace.com/projects/yssdrop/
apart from the initial problems everything should be fine now haven't had any problems with it since i pushed the alpha to YssDrop will convert it to release when i get home
I'm about to push a new release of LibQTip-1.0 and LibQTipClick-1.1, so you might want to hold off. I've fixed some memory leaks and added two new optional arguments to SetCell() (padding and max width of the cell, with text wrapping if it exceeds it) and had to update LQTC to work properly with it.
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.
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
It should be:
Ok, I only fucked up once. All of the other examples were fine. Fixed.
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)
Thanks :)
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
I'll update the documentation. I wasn't completely comfortable with the syntax the other way, either. Thanks for the catch!
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:p
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 becomes
also line 111-114 instead of we can simply do
then we fix the error on line 128 by replacing with
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
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.
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). :D
i'm not sure about this one not too sure about the inner workings of CBH so if it keeps the references to the tips internally anyways you are just increasing the overhead since you now are sticking multiple CBH handlers on one tip.
you may want to check with the CBH authors or do some testing
this is all theory so i have no clue :P but from what i can tell CBH is supposed to be added and never removed :P
It doesn't. CallbackHandler:New() returns a reference to a local variable registry, which I assign to tooltip.callbacks, so nilling that out effectively removes the queue. However, looking at CBH's code, I also need to nil out the functions which CBH sets on the tooltip - in this case, SetCallback, UnSetCallback, and UnSetAllCallbacks - and all will be well.
So myAddon:someMethodName("OnMouseDown") is called when the callback is triggered.
The first argument of SetCallback is not the emitter but the listener. It can also be a arbitrary string (which can be reused later to remove the callback).
So, I'd better store the CBH registry in a "internal" table using tooltip keys, so registered listeners move along with the tooltip key and not the tooltip frame.
I'll add that to the Getting Started documentation - very nice functionality.
@gagou: I've added (to LibQTip) optional parameters to SetCell() for padding and max_width. I'll be adding these to the API docs now.