Thread Tools Display Modes
08-08-11, 03:55 PM   #1
lerb
A Frostmaul Preserver
 
lerb's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 264
Button highlighting

Hey everyone, need a little help with a button here.

I am using a modified version of aMail, an addon that simply displays a button on your mail window, showing amount of items and gold in the box, and loots it all once you click it. Exactly what I want.

However, I want to skin that button. The code I'm using atm is;

Code:
local button = CreateFrame('Button', 'aMailButton', InboxFrame)
button:SetPoint('BOTTOM', InboxFrame, 'BOTTOM', -10, 84)
button:SetSize(148, 28)
button:SetBackdrop({
	bgFile = LeUI.media.blank,
        insets = {top = 0, left = 0, bottom = 0, right = 0},
})
button:SetBackdropColor(unpack(LeUI.media.backdropcolor))
Using this, the button looks like this;



What I want, is a hovering function. When i hover it, it changes bgtexture, or something. Is this possible without too much hassle? If i have to create some textures that won't be a problem, i just don't know where to begin with the code.

Last edited by lerb : 08-08-11 at 03:56 PM. Reason: Wrong code
  Reply With Quote
08-08-11, 04:05 PM   #2
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
If it's just one button, don't bother with extra textures. Use lua, it lets you do more.

Do something like this:

Code:
button:SetScript("OnEnter", function(self)
	self:SetBackdropColor(r, g, b)
end)

button:SetScript("OnLeave", function(self)
	self:SetBackdropColor(unpack(LeUI.media.backdropcolor))
end)
Replace r, g, b with your own colours.

Also since you're going to be using your colours twice now, it's probably a good idea to assign a local value to your backdrop colour that you can refer to so you don't have to unpack a global table twice. No big deal, but everything counts.
  Reply With Quote
08-08-11, 04:25 PM   #3
lerb
A Frostmaul Preserver
 
lerb's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 264
Thanks for the quick reply Haleth! Here's what I ended up with after your solution;
Code:
local button = CreateFrame('Button', 'aMailButton', InboxFrame)
button:SetPoint('BOTTOM', InboxFrame, 'BOTTOM', -10, 84)
button:SetSize(148, 28)
button:SetBackdrop({
	bgFile = LeUI.media.blank,
        insets = {top = 0, left = 0, bottom = 0, right = 0},
})

button:SetScript("OnEnter", function(self)
	self:SetBackdropColor(unpack(LeUI.media.hover))
end)

button:SetScript("OnLeave", function(self)
	self:SetBackdropColor(unpack(LeUI.media.backdropcolor))
end)
..and it works perfectly fine, except for one thing. When I open the mailbox, only the first time after I log on, the button is white. Only the BG, not the border. I'm guessing i could fix this with a similar function to those you posted, but is there a "OnLogon" event or similar? Or is there a much easier, and probably more obvious solution? As I said, I'm new to this.

Also, I'm not sure how to set a local value to the background color, but this is how I did it. I have a Media.lua that handles most of that stuff. Is this how you meant?
  Reply With Quote
08-08-11, 04:37 PM   #4
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
You seem to have forgotten to set the backdrop color the first time as soon as the frame is created, like you did in your first example.

As for the local stuff, I tend to screw this up and just go with trial and error but try this:

Code:
local r, g, b = unpack(LeUI.media.backdropcolor)
And then just refer to r, g, b afterwards instead of your table.
  Reply With Quote
08-08-11, 04:43 PM   #5
lerb
A Frostmaul Preserver
 
lerb's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 264
Ah.. That makes sense once you think about it Works like a charm now, went on and added it to my chattabs aswell and they're awesome now

And yeah, i get the local thingy now, thanks! But what does it do, without sounding stupid? If i have, say, 100 buttons and i use..

Code:
button:SetScript("OnEnter", function(self)
	self:SetBackdropColor(unpack(LeUI.media.hover))
end)
..on every one of them, is that gonna make it "heavier" than using..

Code:
local hovering = unpack(LeUI.media.backdropcolor)

....

button:SetScript("OnEnter", function(self)
	self:SetBackdropColor(hovering)
end)
..on those 100 buttons?

I'm sorry, I just feel like the more I ask, the more I learn
  Reply With Quote
08-08-11, 04:57 PM   #6
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
What it effectively does is import the global table into your addon, which makes referring to it slightly faster.

Theoretically, yes, it's more efficient. In practice, the difference will be tiny, unless you're playing WoW on a TI-82. I like coding es efficiently as possible even when the result is barely noticeable though. Consider it an OCD thing.
  Reply With Quote
08-08-11, 05:12 PM   #7
lerb
A Frostmaul Preserver
 
lerb's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 264
Haha, alright fair enough. Gotta say it makes the lua file look cleaner too. Love clean looking lua files <3

Thanks for all the help, I will return with more questions for sure!

Last edited by lerb : 08-08-11 at 05:12 PM. Reason: Typo
  Reply With Quote
08-09-11, 03:03 AM   #8
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Originally Posted by lerb View Post
Code:
local hovering = unpack(LeUI.media.backdropcolor)

....

button:SetScript("OnEnter", function(self)
	self:SetBackdropColor(hovering)
end)
If you're creating things with a high frequency try to use predefined functions.

Code:
local function buttonOnEnter(self)
   self:SetBackdropColor(hovering)
end

....

button:SetScript("OnEnter", buttonOnEnter)
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Button 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