| 1 | ----------------------------------------- | 
|---|
| 2 | -- Start of handler functions | 
|---|
| 3 | ----------------------------------------- | 
|---|
| 4 | ----------------------------------------- | 
|---|
| 5 | -- Alpha slider handler (not used!) | 
|---|
| 6 | ----------------------------------------- | 
|---|
| 7 | function sliderHandler(args) | 
|---|
| 8 |     CEGUI.System:getSingleton():getGUISheet():setAlpha(CEGUI.toSlider(CEGUI.toWindowEventArgs(args).window):getCurrentValue()) | 
|---|
| 9 | end | 
|---|
| 10 |  | 
|---|
| 11 | ----------------------------------------- | 
|---|
| 12 | -- Handler to slide pane | 
|---|
| 13 | -- | 
|---|
| 14 | -- Here we move the 'Demo8' sheet window | 
|---|
| 15 | -- and re-position the scrollbar | 
|---|
| 16 | ----------------------------------------- | 
|---|
| 17 | function panelSlideHandler(args) | 
|---|
| 18 |     local scroller = CEGUI.toScrollbar(CEGUI.toWindowEventArgs(args).window) | 
|---|
| 19 |     local demoWnd = CEGUI.WindowManager:getSingleton():getWindow("Demo8") | 
|---|
| 20 |  | 
|---|
| 21 |     local relHeight = demoWnd:getHeight():asRelative(demoWnd:getParentPixelHeight()) | 
|---|
| 22 |  | 
|---|
| 23 |     scroller:setPosition(CEGUI.UVector2(CEGUI.UDim(0,0), CEGUI.UDim(scroller:getScrollPosition() / relHeight,0))) | 
|---|
| 24 |     demoWnd:setPosition(CEGUI.UVector2(CEGUI.UDim(0,0), CEGUI.UDim(-scroller:getScrollPosition(),0))) | 
|---|
| 25 | end | 
|---|
| 26 |  | 
|---|
| 27 | ----------------------------------------- | 
|---|
| 28 | -- Handler to set preview colour when | 
|---|
| 29 | -- colour selector scrollers change | 
|---|
| 30 | ----------------------------------------- | 
|---|
| 31 | function colourChangeHandler(args) | 
|---|
| 32 |     local winMgr = CEGUI.WindowManager:getSingleton() | 
|---|
| 33 |      | 
|---|
| 34 |     local r = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Red")):getScrollPosition() | 
|---|
| 35 |     local g = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Green")):getScrollPosition() | 
|---|
| 36 |     local b = CEGUI.toScrollbar(winMgr:getWindow("Demo8/Window1/Controls/Blue")):getScrollPosition() | 
|---|
| 37 |     local col = CEGUI.colour:new_local(r, g, b, 1) | 
|---|
| 38 |     local crect = CEGUI.ColourRect(col) | 
|---|
| 39 |  | 
|---|
| 40 |     winMgr:getWindow("Demo8/Window1/Controls/ColourSample"):setProperty("ImageColours", CEGUI.PropertyHelper:colourRectToString(crect)) | 
|---|
| 41 | end | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | ----------------------------------------- | 
|---|
| 45 | -- Handler to add an item to the box | 
|---|
| 46 | ----------------------------------------- | 
|---|
| 47 | function addItemHandler(args) | 
|---|
| 48 |     local winMgr = CEGUI.WindowManager:getSingleton() | 
|---|
| 49 |  | 
|---|
| 50 |     local text = winMgr:getWindow("Demo8/Window1/Controls/Editbox"):getText() | 
|---|
| 51 |     local cols = CEGUI.PropertyHelper:stringToColourRect(winMgr:getWindow("Demo8/Window1/Controls/ColourSample"):getProperty("ImageColours")) | 
|---|
| 52 |  | 
|---|
| 53 |     local newItem = CEGUI.createListboxTextItem(text, 0, nil, false, true) | 
|---|
| 54 |     newItem:setSelectionBrushImage("TaharezLook", "MultiListSelectionBrush") | 
|---|
| 55 |     newItem:setSelectionColours(cols) | 
|---|
| 56 |  | 
|---|
| 57 |     CEGUI.toListbox(winMgr:getWindow("Demo8/Window1/Listbox")):addItem(newItem) | 
|---|
| 58 | end | 
|---|
| 59 |  | 
|---|
| 60 | ----------------------------------------- | 
|---|
| 61 | -- Script Entry Point | 
|---|
| 62 | ----------------------------------------- | 
|---|
| 63 | local guiSystem = CEGUI.System:getSingleton() | 
|---|
| 64 | local schemeMgr = CEGUI.SchemeManager:getSingleton() | 
|---|
| 65 | local winMgr = CEGUI.WindowManager:getSingleton() | 
|---|
| 66 |  | 
|---|
| 67 | -- load our demo8 scheme | 
|---|
| 68 | schemeMgr:loadScheme("Demo8.scheme"); | 
|---|
| 69 | -- load our demo8 window layout | 
|---|
| 70 | local root = winMgr:loadWindowLayout("Demo8.layout") | 
|---|
| 71 | -- set the layout as the root | 
|---|
| 72 | guiSystem:setGUISheet(root) | 
|---|
| 73 | -- set default mouse cursor | 
|---|
| 74 | guiSystem:setDefaultMouseCursor("TaharezLook", "MouseArrow") | 
|---|
| 75 | -- set the Tooltip type | 
|---|
| 76 | guiSystem:setDefaultTooltip("TaharezLook/Tooltip") | 
|---|
| 77 |  | 
|---|
| 78 | -- subscribe required events | 
|---|
| 79 | winMgr:getWindow("Demo8/ViewScroll"):subscribeEvent("ScrollPosChanged", "panelSlideHandler") | 
|---|
| 80 | winMgr:getWindow("Demo8/Window1/Controls/Blue"):subscribeEvent("ScrollPosChanged", "colourChangeHandler") | 
|---|
| 81 | winMgr:getWindow("Demo8/Window1/Controls/Red"):subscribeEvent("ScrollPosChanged", "colourChangeHandler") | 
|---|
| 82 | winMgr:getWindow("Demo8/Window1/Controls/Green"):subscribeEvent("ScrollPosChanged", "colourChangeHandler") | 
|---|
| 83 | winMgr:getWindow("Demo8/Window1/Controls/Add"):subscribeEvent("Clicked", "addItemHandler") | 
|---|