Thread Tools Display Modes
07-04-12, 10:44 AM   #1
Aglaea
A Defias Bandit
Join Date: Jul 2012
Posts: 3
Looking for a SIMPLE tutorial to make a 'window'

I am looking for a simple tutorial that shows me how to make a simple window with a background in a colour of choice, some lines of text and that is movable. May be in Lua or FrameXML, but please motivate your choice. So far, tutorials and code examples I see are just overdone and give much more than this. For me this makes it confusing to get this done.
  Reply With Quote
07-04-12, 11:15 AM   #2
jeffy162
A Pyroguard Emberseer
 
jeffy162's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 2,364
It might help if you post your use for this "simple window".

That would go a long way to getting the help you are asking for without having to go through a long, drawn-out process to get you an example (or links to API's) for your code.
__________________
Ahhhh, the vagueries of the aging mind. Wait.... What was I saying?


Carbonite <----- GitHub main module (Maps ONLY) download link. The other modules are also available on GitHub.
Carbonite-CLASSIC<----- GitHub link to Carbonite Classic. Thanks to ircdirk for this!
  Reply With Quote
07-04-12, 11:30 AM   #3
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Code:
-- (1)
local f = CreateFrame("Frame", "YourFrameName", UIParent)
f:SetSize(400, 400)
f:SetPoint("CENTER")

-- (2)
f:SetBackdrop({
	bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
	edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
	edgeSize = 1,
})
f:SetBackdropColor(0, 0, 0, .5)
f:SetBackdropBorderColor(0, 0, 0)

-- (3)
f:EnableMouse(true)
f:SetMovable(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:SetScript("OnHide", f.StopMovingOrSizing)

-- (4)
local close = CreateFrame("Button", "YourCloseButtonName", f, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", f, "TOPRIGHT")
close:SetScript("OnClick", function()
	f:Hide()
end)

-- (5)
local text = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
text:SetPoint("CENTER")
text:SetText("Hello World!")
(1) http://www.wowwiki.com/API_CreateFrame
(2) http://www.wowwiki.com/API_Frame_SetBackdrop
(3) http://www.wowwiki.com/Making_Draggable_Frames
(4) http://wowprogramming.com/docs/widgets/Button/
(5) http://www.wowwiki.com/API_Frame_CreateFontString

Last edited by Haleth : 07-05-12 at 03:54 AM. Reason: Updated with Phanx's fix
  Reply With Quote
07-04-12, 02:56 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Haleth View Post
Code:
-- (3)
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
Should be:
Code:
-- (3)
f:EnableMouse(true)
f:SetMovable(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:SetScript("OnHide", f.StopMovingOrSizing)
The first three lines are needed to actually make the frame movable and tell it which mouse buttons may be used to move it; otherwise the drag scripts will be ignored.

The last line is basically a safety check to make sure that if you're dragging the frame and the UI gets hidden for some reason (eg. pressing Alt+Z) the frame doesn't get stuck to the mouse cursor.

Originally Posted by Haleth View Post
[code]
-- (4)
local close = CreateFrame("Button", "YourCloseButtonName", f, "UIPanelCloseButton")
close:SetPoint("TOPRIGHT", f, "TOPRIGHT")
close:SetScript("OnClick", function()
f:Hide()
end)
I'd recommend not giving the button a global name, and attaching it to the parent frame as a table member to make it easily accessible through code without cluttering up the global namespace:

Code:
local close = CreateFrame("Button", nil, f, "UIPanelCloseButton")
f.closeButton = close
Similarly, you should also attach the text object the same way:

Code:
-- (5)
local text = f:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
f.text = text
Other than that, you'll have to be more specific about how you want the frame to look an act if you want more specific suggestions or examples. What kind of information do you want it to show? Is it meant to be displayed all the time (a small status window) or only sometimes (a togglable panel)? Will it show only short pieces of text (like character stats) or longer pieces of text (like paragraphs)? Will it need to have other objects on top of it, like status bars, icons, or buttons?
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-04-12, 02:59 PM   #5
Haleth
This Space For Rent
 
Haleth's Avatar
Featured
Join Date: Sep 2008
Posts: 1,173
Ah, right. My mistakes there, I just put that together quickly

I name the close button because Blizzard does the same with theirs, but you're probably right that it's better as a table element.
  Reply With Quote
07-04-12, 03:01 PM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,951
Phanx,

I thought certain functions only worked on controls if they had a name ? Or have I misunderstood that. I have given all my controls names based on that understanding.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-04-12, 04:04 PM   #7
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
There are a few templates which require names in the global table simply because their inner workings use them exclusively. Beyond that, though, you're relatively safe using nil.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Looking for a SIMPLE tutorial to make a 'window'


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