Thread Tools Display Modes
06-21-21, 04:54 AM   #1
SegFault
A Defias Bandit
Join Date: Jun 2021
Posts: 3
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...
  Reply With Quote
06-21-21, 10:21 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
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.
__________________
  Reply With Quote
06-21-21, 01:24 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
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.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-21-21 at 03:22 PM.
  Reply With Quote
07-02-21, 03:50 AM   #4
SegFault
A Defias Bandit
Join Date: Jun 2021
Posts: 3
Originally Posted by Fizzlemizz View Post
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.
  Reply With Quote
07-02-21, 07:37 AM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Originally Posted by SegFault View Post
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)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-02-21 at 08:54 AM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Drawing a square (basic noob question)

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