Quantcast
Assign atlas texture to button in lua? - WoWInterface
Thread Tools Display Modes
03-26-20, 04:30 AM   #1
LudiusMaximus
A Chromatic Dragonspawn
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 194
Assign atlas texture to button in lua?

I found that the equivalent to xml

Code:
<Button name="myButton">
  <NormalTexture file="Interface\Buttons\UI-SpellbookIcon-PrevPage-Up"/>
  <PushedTexture file="Interface\Buttons\UI-SpellbookIcon-PrevPage-Down"/>
  <DisabledTexture file="Interface\Buttons\UI-SpellbookIcon-PrevPage-Disabled"/>
  <HighlightTexture file="Interface\Buttons\UI-Common-MouseHilight" alphaMode="ADD"/>
</Button>
can be achieved in lua as follows:

Code:
local myButton= CreateFrame("Button", "myButton", myParentFrame)
myButton:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Up")
myButton:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Down")
myButton:SetDisabledTexture("Interface\\Buttons\\UI-SpellbookIcon-PrevPage-Disabled")
myButton:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight", "ADD")

But how do I achieve a texture defined as "atlas" in lua?

Code:
<NormalTexture atlas="QuestCollapse-Show-Up"/>
<PushedTexture atlas="QuestCollapse-Show-Down"/>
I tried

Code:
local texture = myButton:CreateTexture()
texture:SetAtlas("QuestCollapse-Show-Up")
myButton:SetNormalTexture(texture)
but this did no show any texture.

What am I missing? Thanks!
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
03-26-20, 05:12 AM   #2
Vrul
An Onyxian Warder
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 354
There are methods for button objects that seem they would achieve this (never used them myself):
SetNormalAtlas
SetPushedAtlas
SetDisabledAtlas
SetHighlightAtlas
  Reply With Quote
03-26-20, 05:26 AM   #3
LudiusMaximus
A Chromatic Dragonspawn
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 194
Ah cool! Thanks! There is odly nothing about these functions online...

Can anyone tell me why the Atlas texture is apparently always somewhat larger than the Texture texture?

Code:
local myButton = CreateFrame("Button", nil, myParent)
myButton:SetNormalAtlas("QuestCollapse-Show-Up")
myButton:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down")
myButton:SetSize(25, 25)
How could I make them the same size?
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
03-26-20, 05:39 AM   #4
Vrul
An Onyxian Warder
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 354
I'd say mess with SetTexCoord until it looks ok:
Code:
local myButton = CreateFrame("Button", nil, myParent)
myButton:SetNormalAtlas("QuestCollapse-Show-Up")
myButton:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down")
myButton:GetPushedTexture():SetTexCoord(0.1, 0.9, 0.1, 0.9)
myButton:SetSize(25, 25)
  Reply With Quote
03-26-20, 06:40 AM   #5
LudiusMaximus
A Chromatic Dragonspawn
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 194
OK, that's an idea.

But let me ask differently.

How can I achieve that the highlight Texture texture is shown as big as the normal Atlas texture?

XML:
Code:
<NormalTexture atlas="QuestCollapse-Show-Up"/>
<PushedTexture atlas="QuestCollapse-Show-Down"/>
<HighlightTexture file="Interface\Buttons\UI-Common-MouseHilight" alphaMode="ADD" setAllPoints="true">
  <Size x="48" y="48"/>
  <Anchors>
    <Anchor point="CENTER"/>
  </Anchors>
</HighlightTexture>

Lua:
Code:
myButton:SetNormalAtlas("QuestCollapse-Show-Up")
myButton:SetPushedAtlas("QuestCollapse-Show-Down")
myButton:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight", "ADD")
--???
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote
03-26-20, 07:06 AM   #6
Vrul
An Onyxian Warder
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 354
Same deal, adjust SetTexCoord arguments until it looks ok:
Code:
local myButton = CreateFrame("Button", nil, UIParent)
myButton:SetNormalAtlas("QuestCollapse-Show-Up")
myButton:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-NextPage-Down")
myButton:GetPushedTexture():SetTexCoord(0.1, 0.9, 0.1, 0.9)
myButton:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight", "ADD")
myButton:GetHighlightTexture():SetTexCoord(0.15, 0.85, 0.15, 0.85)
myButton:SetSize(25, 25)
  Reply With Quote
03-26-20, 07:14 AM   #7
LudiusMaximus
A Chromatic Dragonspawn
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 194
Ah, now I get it! Thank you very much!
__________________
~ Be the change you want to see in the world... of warcraft interface! ~
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Assign atlas texture to button in lua?

Thread Tools
Display Modes

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