Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/media/gui/scripts/demo8.lua @ 5430

Last change on this file since 5430 was 5430, checked in by rgrieder, 15 years ago

svn:eol-style "native" for the gui scripts.

  • Property svn:eol-style set to native
File size: 3.6 KB
Line 
1-----------------------------------------
2-- Start of handler functions
3-----------------------------------------
4-----------------------------------------
5-- Alpha slider handler (not used!)
6-----------------------------------------
7function sliderHandler(args)
8    CEGUI.System:getSingleton():getGUISheet():setAlpha(CEGUI.toSlider(CEGUI.toWindowEventArgs(args).window):getCurrentValue())
9end
10
11-----------------------------------------
12-- Handler to slide pane
13--
14-- Here we move the 'Demo8' sheet window
15-- and re-position the scrollbar
16-----------------------------------------
17function 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)))
25end
26
27-----------------------------------------
28-- Handler to set preview colour when
29-- colour selector scrollers change
30-----------------------------------------
31function 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))
41end
42
43
44-----------------------------------------
45-- Handler to add an item to the box
46-----------------------------------------
47function 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)
58end
59
60-----------------------------------------
61-- Script Entry Point
62-----------------------------------------
63local guiSystem = CEGUI.System:getSingleton()
64local schemeMgr = CEGUI.SchemeManager:getSingleton()
65local winMgr = CEGUI.WindowManager:getSingleton()
66
67-- load our demo8 scheme
68schemeMgr:loadScheme("Demo8.scheme");
69-- load our demo8 window layout
70local root = winMgr:loadWindowLayout("Demo8.layout")
71-- set the layout as the root
72guiSystem:setGUISheet(root)
73-- set default mouse cursor
74guiSystem:setDefaultMouseCursor("TaharezLook", "MouseArrow")
75-- set the Tooltip type
76guiSystem:setDefaultTooltip("TaharezLook/Tooltip")
77
78-- subscribe required events
79winMgr:getWindow("Demo8/ViewScroll"):subscribeEvent("ScrollPosChanged", "panelSlideHandler")
80winMgr:getWindow("Demo8/Window1/Controls/Blue"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
81winMgr:getWindow("Demo8/Window1/Controls/Red"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
82winMgr:getWindow("Demo8/Window1/Controls/Green"):subscribeEvent("ScrollPosChanged", "colourChangeHandler")
83winMgr:getWindow("Demo8/Window1/Controls/Add"):subscribeEvent("Clicked", "addItemHandler")
Note: See TracBrowser for help on using the repository browser.