Thread Tools Display Modes
01-15-16, 02:52 PM   #1
TheSecretSquirrel
A Murloc Raider
Join Date: Jan 2016
Posts: 9
Question Buttons and alpha

How do I change the alpha for a button, if I use... example:SetNormalTexture and then change the alpha to, say 0.5 and the example:SetHighlightTexture to 1 - so that the button becomes more visible when highlighted - If someone could also throw in how to make the button unhide another frame, that would be helpful too

Thanks in advance

Squirrel

Last edited by TheSecretSquirrel : 01-15-16 at 04:10 PM.
  Reply With Quote
01-15-16, 04:15 PM   #2
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
:SetNormalTexture, :SetHighlightTexture, etc takes a texture as argument, not the alpha value. If you want to manipulate the alpha values of your button textures, you'll either have to provide your own textures or get the textures from the button object and then change them.
Lua Code:
  1. local normal = button:GetNormalTexture()
  2. normal:SetAlpha(0.5)

If you want to change the button's alpha value when you mouse over it, you should just do something like this:
Lua Code:
  1. button:SetScript("OnEnter", function(self) self:SetAlpha(1) end)
  2. button:SetScript("OnLeave", function(self) self:SetAlpha(0.5) end)

Hiding / showing another frame is simple:
Lua Code:
  1. -- on click
  2. button:SetScript("OnClick", function(self) otherFrame:Show() end)
  3. -- on mouse over
  4. button:SetScript("OnEnter", function(self) otherFrame:Show() end)
  5. button:SetScript("OnLeave", function(self) otherFrame:Hide() end)
__________________

Last edited by MunkDev : 01-15-16 at 04:23 PM.
  Reply With Quote
01-15-16, 04:23 PM   #3
TheSecretSquirrel
A Murloc Raider
Join Date: Jan 2016
Posts: 9
Thanks so much, was trying to alter the 'wowwiki' guide on buttons (OnClick), but nothing (until now) was working!
  Reply With Quote
01-15-16, 04:40 PM   #4
TheSecretSquirrel
A Murloc Raider
Join Date: Jan 2016
Posts: 9
Another quick question - If I was to click the button again, how would I make the frame hide?
  Reply With Quote
01-15-16, 05:11 PM   #5
Yukyuk
A Chromatic Dragonspawn
 
Yukyuk's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2015
Posts: 179
This is (more or less) my defaulft lua to show/hide a frame.


Code:
-------------------------------------------------------------------------------
--  Toggle the user interface 
-------------------------------------------------------------------------------
function frame_UI()
    if frame:IsVisible() then
       frame:Hide()
    else
       frame:Show()
    end
end
__________________
Better to fail then never have tried at all.
  Reply With Quote
01-15-16, 05:49 PM   #6
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
Another approach for toggling frame visibility.
Lua Code:
  1. frame:SetShown(not frame:IsVisible())
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote
01-15-16, 07:27 PM   #7
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Someone really ought to make a better guide for beginners to start coding addons. It seems a lot of people turn to outdated sources that promote XML for arbitrary frames and bloating of the global environment.
__________________
  Reply With Quote
01-16-16, 04:37 AM   #8
TheSecretSquirrel
A Murloc Raider
Join Date: Jan 2016
Posts: 9
I've tried both suggestions above, neither are working (I'm assuming I'm "plugging" them in wrong).

The code with my button:
Code:
--
local MenuButton = CreateFrame("Button","MenuButton",UIParent)
MenuButton:SetNormalTexture("Interface\\AddOns\\UI\\Textures\\MenuBar.tga")
MenuButton:SetPoint("Bottomleft",0,0)
MenuButton:SetWidth(32)
MenuButton:SetHeight(32)
local MenuButtonNormal = MenuButton:GetNormalTexture() -- Might not need this?
MenuButton:SetScript("OnClick", function(self) MenuBackgroundFrame:Show() end)
MenuButton:SetScript("OnEnter", function(self) self:SetAlpha(1) end)
MenuButton:SetScript("OnLeave", function(self) self:SetAlpha(0.5) end)
--
Never mind - I've fixed it by doing the following:
Code:
--
local MenuButton = CreateFrame("Button","MenuButton",UIParent)
MenuButton:SetNormalTexture("Interface\\AddOns\\UI\\Textures\\MenuBar.tga")
MenuButton:SetPoint("Bottomleft",0,0)
MenuButton:SetWidth(32)
MenuButton:SetHeight(32)
MenuButton:SetScript("OnClick", function(self) if MenuBackgroundFrame:IsVisible() then MenuBackgroundFrame:Hide() else MenuBackgroundFrame:Show() end end)
MenuButton:SetScript("OnEnter", function(self) self:SetAlpha(1) end)
MenuButton:SetScript("OnLeave", function(self) self:SetAlpha(0.5) end)
--

Last edited by TheSecretSquirrel : 01-16-16 at 04:54 AM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Buttons and alpha


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