Difference between revisions of "Writing CEGUI scripts"

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Jump to: navigation, search
 
Line 1: Line 1:
The Lua language is very versatile. It has mechanisms to override alot of its functionality, and [http://www.codenix.com/~tolua/ tolua++] makes heavy use of these mechanisms, in not just being a clever tool to generate Lua bindings for C++ code, it also introduces a set of new functions to allow basic object-oriented programming in Lua.
 
 
 
All code on this page is Lua script.
 
All code on this page is Lua script.
  

Revision as of 02:17, 2 June 2005

All code on this page is Lua script.


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.