WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Assign atlas texture to button in lua? (https://www.wowinterface.com/forums/showthread.php?t=57888)

LudiusMaximus 03-26-20 04:30 AM

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!

Vrul 03-26-20 05:12 AM

There are methods for button objects that seem they would achieve this (never used them myself):
SetNormalAtlas
SetPushedAtlas
SetDisabledAtlas
SetHighlightAtlas

LudiusMaximus 03-26-20 05:26 AM

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?

Vrul 03-26-20 05:39 AM

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)


LudiusMaximus 03-26-20 06:40 AM

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")
--???


Vrul 03-26-20 07:06 AM

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)


LudiusMaximus 03-26-20 07:14 AM

Ah, now I get it! Thank you very much!


All times are GMT -6. The time now is 03:19 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI