Writing CEGUI scripts

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Revision as of 19:56, 9 June 2005 by Lindquist (Talk | contribs)

Jump to: navigation, search

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)


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():loadLayout("../datafiles/layouts/test.layout")
CEGUI.System:getSingleton():getGUISheet():addChildWindow(w)

Loads a XML layout and adds the returned window to the active GUISheet.