Thread Tools Display Modes
04-30-09, 12:20 PM   #1
Barjack
A Black Drake
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 89
Smile Providing mouseover highlighting

So, thought I'd ask people's thoughts on good ways to provide mouseover highlighting for various frames.

To start with, initially I was using the HIGHLIGHT layer of the unitframe itself. The problem with this was that any frames created on top of the unitframe (like, say, a health bar) would cover it, and I couldn't figure out a way to push the highlight texture higher up without SetFrameLevel. This seemed pretty hackish though and I noticed that if I tried to SetFrameLevel the unitframe itself I was getting taint issues. I guess maybe that function is protected to stop people stacking frames in the same visual space and using the frame level to determine which one is clicked? I'm no expert on this or anything, so I don't really know. Presumably just using SetFrameLevel on the health bars would be okay, but it's still pretty ugly.

So moving on to attempting a more "manual" solution, I'm currently just manually creating a new frame to hold the highlight texture. Code is as follows:
Code:
  ---- Highlight
  self.HighlightFrame = CreateFrame("Frame", nil, self)
  self.Highlight = self.HighlightFrame:CreateTexture(nil, "OVERLAY")
  self.Highlight:SetPoint("TOPLEFT", self.Health)
  self.Highlight:SetPoint("BOTTOMRIGHT", self.Power)
  self.Highlight:SetAlpha(0.6)
  self.Highlight:SetBlendMode('ADD')
  self.Highlight:SetTexture(texHighlight)
  
  self.Highlight:Hide()
  self:EnableMouse()
  local oldOnEnter = self:GetScript("OnEnter")
  local oldOnLeave = self:GetScript("OnLeave")
  self:SetScript("OnEnter", function(self, ...) self.Highlight:Show(); oldOnEnter(self, ...) end)
  self:SetScript("OnLeave", function(self, ...) self.Highlight:Hide(); oldOnLeave(self, ...) end)
I guess I should have expected it (I didn't), but of course there were already OnEnter and OnLeave scripts, so unless I wanted to lose tooltips and whatever other code may be there I had to call the old functions too. But of course, now they're being called from a non-secure context... I'm not sure if this matters, but I'm a little wary all the same considering my earlier taint problems.

I don't know if it even makes sense to try hooking the original functions instead, in order to keep it untainted, but even if it did make sense I don't know how to do that considering hooksecurefunc takes a string argument and all I know how to get is a reference.

But even more generally, I was wondering if anybody had experience doing this themselves and what techniques etc. they used. Thoughts/opinions/etc. welcome.

Last edited by Barjack : 04-30-09 at 12:29 PM.
  Reply With Quote
04-30-09, 04:23 PM   #2
Gotai
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 5
You can use frame:HookScript("scripttype", function) to securely hook an already existing script:

Code:
  self:HookScript("OnEnter", function(self, ...) self.Highlight:Show() end)
  Reply With Quote
04-30-09, 08:29 PM   #3
Barjack
A Black Drake
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 89
Originally Posted by Gotai View Post
You can use frame:HookScript("scripttype", function) to securely hook an already existing script:

Code:
  self:HookScript("OnEnter", function(self, ...) self.Highlight:Show() end)
Aha, that's just about perfect then. Thanks a lot.
  Reply With Quote
05-01-09, 05:34 AM   #4
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
I do it a bit simpler in my raid layout.

http://github.com/p3lim/ouf_mini/blo...8/oUF_Mini.lua

You can add the show/hide directly into a function, because you set the scripts yourself anyways.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Providing mouseover highlighting


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

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