Difference between revisions of "Writing CEGUI scripts"
(→Load a layout: Changed loadLayout() to loadWindowLayout()) |
|||
Line 55: | Line 55: | ||
CEGUI.System:getSingleton():getGUISheet():addChildWindow(w) | CEGUI.System:getSingleton():getGUISheet():addChildWindow(w) | ||
Loads a XML layout and adds the returned window to the active GUISheet. | Loads a XML layout and adds the returned window to the active GUISheet. | ||
+ | |||
+ | |||
+ | == Menubar with popup == | ||
+ | -- do the menubar | ||
+ | local bar = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/Menubar","the_menu_bar") | ||
+ | bar:setSize(CEGUI.Size:new_local(1,0.1)) | ||
+ | CEGUI.System:getSingleton():getGUISheet():addChildWindow(bar) | ||
+ | |||
+ | -- add a menuitem to the bar | ||
+ | local item = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/MenubarItem","the_menu_bar_item") | ||
+ | item:setText("Bar item") | ||
+ | bar:addChildWindow(item) | ||
+ | |||
+ | -- add a popupmenu to the bar's menuitem | ||
+ | local pop = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/PopupMenu","the_popup_menu") | ||
+ | item:addChildWindow(pop) | ||
+ | |||
+ | -- add a few menuitems to the popup | ||
+ | item = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/PopupMenuItem","the_popup_menu_item_1") | ||
+ | item:setText("Popup item 1") | ||
+ | pop:addChildWindow(item) | ||
+ | |||
+ | item = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/PopupMenuItem","the_popup_menu_item_2") | ||
+ | item:setText("Popup item 2") | ||
+ | pop:addChildWindow(item) | ||
+ | Creates a simple menubar and adds a popupmenu with two items to it. |
Revision as of 14:30, 4 July 2005
All code on this page is Lua script using the CEGUILua bindings available on CVS HEAD. The code snippets might not be specifically useful, but they should show off some of the posibilities with CEGUI and Lua used together. And give an idea of how to write these scripts.
Off we go :)
--Lindquist 20:56, 9 Jun 2005 (BST)
Contents
Change logging level
local logger = CEGUI.Logger:getSingleton() -- get the logger local lvl = logger:getLoggingLevel() -- get logging level if lvl < CEGUI.Insane then -- if logging level is less than insane logger:setLoggingLevel(lvl+1) -- then increase it end
Bumps up the logging level a notch unless we're already at Insane.
Load a scheme
CEGUI.SchemeManager:getSingleton():loadScheme("../datafiles/schemes/TaharezLook.scheme")
Loads the TaharezLook scheme.
Simple Interface
-- create the GUI sheet local sheet = CEGUI.WindowManager:getSingleton():createWindow("DefaultGUISheet","root"); CEGUI.System:getSingleton():setGUISheet(sheet) -- and attach it to the system -- create a FrameWindow local fw = CEGUI.WindowManager:getSingleton():createWindow("TaharezLook/FrameWindow","framewnd"); -- add it to the sheet sheet:addChildWindow(fw) -- set its size and position local sz = CEGUI.Size:new_local(0.5,0.5) local pos = CEGUI.Point:new_local(0.2,0.1) fw:setSize(sz) fw:setPosition(pos) -- disable user sizing fw:setProperty("SizingEnabled","False") -- make the close button work fw:subscribeEvent("CloseClicked","fwCloseClicked") -- the CloseClicked event handler function fwCloseClicked(eventArgs) local we = CEGUI.toWindowEventArgs(eventArgs) CEGUI.WindowManager:getSingleton():destroyWindow(we.window) -- destroy the frame window end
Creates a GUISheet and attaches it to the System. Then creates a FrameWindow, sets its size and position. Disables the sizing feature and subscribes a scripted event handler to destroy the window when the close button is clicked.
Load a layout
local w = CEGUI.WindowManager:getSingleton():loadWindowLayout("../datafiles/layouts/test.layout") CEGUI.System:getSingleton():getGUISheet():addChildWindow(w)
Loads a XML layout and adds the returned window to the active GUISheet.
Menubar with popup
-- do the menubar local bar = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/Menubar","the_menu_bar") bar:setSize(CEGUI.Size:new_local(1,0.1)) CEGUI.System:getSingleton():getGUISheet():addChildWindow(bar) -- add a menuitem to the bar local item = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/MenubarItem","the_menu_bar_item") item:setText("Bar item") bar:addChildWindow(item) -- add a popupmenu to the bar's menuitem local pop = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/PopupMenu","the_popup_menu") item:addChildWindow(pop) -- add a few menuitems to the popup item = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/PopupMenuItem","the_popup_menu_item_1") item:setText("Popup item 1") pop:addChildWindow(item) item = CEGUI.WindowManager:getSingleton():createWindow("WindowsLook/PopupMenuItem","the_popup_menu_item_2") item:setText("Popup item 2") pop:addChildWindow(item)
Creates a simple menubar and adds a popupmenu with two items to it.