WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Drawing a square (basic noob question) (https://www.wowinterface.com/forums/showthread.php?t=58803)

SegFault 06-21-21 04:54 AM

Drawing a square (basic noob question)
 
Hi,

I'm trying to draw a red square. I've searched for over an hour and it seems the "backdrop" api was changed in 9.0

Anyway, here is my code:

Code:

function HelloWorld()
  print("Hello, World!");
 
  local p = CreateFrame("Frame", nil, self, BackdropTemplateMixin and "BackdropTemplate")
  p:SetWidth(100)
  p:SetHeight(100)
  p:SetBackdrop({backdropColor=CreateColor(1,0,0,1)})
  p:SetBackdropColor(1,0,0,1)
  p:SetPoint("TOPLEFT", 100, -100)
  p:Show()
end

I got some of the code from this thread: https://www.wowinterface.com/forums/...d.php?p=336419

This displays nothing however.

I'd appreciate if someone could please point me in the right direction...

Xrystal 06-21-21 10:21 AM

It might be that you have to use the full set of options with SetBackdrop. Take a look at https://wowpedia.fandom.com/wiki/API_Frame_SetBackdrop where it gives you a more complete example.

Fizzlemizz 06-21-21 01:24 PM

If you just want a coloured square, it might be easier to use a texture:
Lua Code:
  1. local p = CreateFrame("Frame", nil, UIParent)
  2. p:SetWidth(100)
  3. p:SetHeight(100)
  4. p:SetPoint("TOPLEFT", 100, -100)
  5. p.Texture = p:CreateTexture()
  6. p.Texture:SetAllPoints()
  7. p.Texture:SetColorTexture(1, 0, 0)
UIParent is the frame that hides when you Alt-Z. Using that as the parent of your top level frame(s) will hide all your frames also.

SegFault 07-02-21 03:50 AM

Quote:

Originally Posted by Fizzlemizz (Post 339435)
If you just want a coloured square, it might be easier to use a texture:
Lua Code:
  1. local p = CreateFrame("Frame", nil, UIParent)
  2. p:SetWidth(100)
  3. p:SetHeight(100)
  4. p:SetPoint("TOPLEFT", 100, -100)
  5. p.Texture = p:CreateTexture()
  6. p.Texture:SetAllPoints()
  7. p.Texture:SetColorTexture(1, 0, 0)
UIParent is the frame that hides when you Alt-Z. Using that as the parent of your top level frame(s) will hide all your frames also.

Thank you very much, I ended up doing this.

Although I didn't call SetAllPoints. What does it do? It seems to work fine without that call.

Fizzlemizz 07-02-21 07:37 AM

Quote:

Originally Posted by SegFault (Post 339510)
What does it do?

It anchors the texture to the same points as the parent frame. The same as

Lua Code:
  1. p.Texture:SetPoint("TOPLEFT", p)
  2. p.Texture:SetPoint("BOTTOMRIGHT", p)


All times are GMT -6. The time now is 08:23 AM.

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