[Orxonox-commit 1637] r6355 - code/branches/presentation2/data/gui/scripts
dafrick at orxonox.net
dafrick at orxonox.net
Tue Dec 15 17:02:22 CET 2009
Author: dafrick
Date: 2009-12-15 17:02:22 +0100 (Tue, 15 Dec 2009)
New Revision: 6355
Modified:
code/branches/presentation2/data/gui/scripts/GUITools.lua
code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua
Log:
Made KeyBindMenu less Resolution dependent, because of this the keybind buttons aren't vertically aligned anymore.
Also made scrolling (with the mouse wheel) (to some extent) invariant of the size of the ScrollablePane in the KeyBindManager.
Modified: code/branches/presentation2/data/gui/scripts/GUITools.lua
===================================================================
--- code/branches/presentation2/data/gui/scripts/GUITools.lua 2009-12-14 23:16:06 UTC (rev 6354)
+++ code/branches/presentation2/data/gui/scripts/GUITools.lua 2009-12-15 16:02:22 UTC (rev 6355)
@@ -10,3 +10,22 @@
InfoPopup.setText(text)
InfoPopup.setCloseButton(closeButton)
end
+
+function getMinTextSize(window)
+ local size = {}
+
+ local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(window:getLookNFeel())
+ local height = window:getFont():getLineSpacing() + window:getUnclippedPixelRect():getHeight() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getHeight()
+ local width = window:getFont():getTextExtent(window:getText()) + window:getUnclippedPixelRect():getWidth() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getWidth()
+
+ table.insert(size, height)
+ table.insert(size, width)
+ return size
+end
+
+function getScrollingStepSize(window)
+ local height = window:getUnclippedPixelRect():getHeight()
+ local maxHeight = CEGUI.System:getSingleton():getGUISheet():getUnclippedPixelRect():getHeight()
+ local ratio = height/maxHeight
+ return 0.008*ratio/0.3204
+end
Modified: code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua
===================================================================
--- code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua 2009-12-14 23:16:06 UTC (rev 6354)
+++ code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua 2009-12-15 16:02:22 UTC (rev 6355)
@@ -66,12 +66,33 @@
linesList = {}
- lineHeight = 30
- commandWidth = 150
+ --Calculate design parameters:
+ sampleWindow = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/SampleWindow")
+ sampleWindow:setText("SampleText")
+
+ local size = getMinTextSize(sampleWindow)
+ lineHeight = size[1]
+
+ commandWidth = 0
+ for k,v in pairs(commandList) do
+ sampleWindow:setText(nameList[k])
+ size = getMinTextSize(sampleWindow)
+ if size[2] > commandWidth then
+ commandWidth = size[2]
+ end
+ end
+
+ sampleWindow:setText("add")
+ size = getMinTextSize(sampleWindow)
+ addWidth = size[2]
+
+ sampleWindow:setText("X")
+ size = getMinTextSize(sampleWindow)
+ clearWidth = size[2]
+
+ spaceWidth = math.floor(1/14*commandWidth)
+
buttonWidth = 145
- clearWidth = 20
- addWidth = 30
- spaceWidth = 10
P.createLines()
@@ -100,9 +121,9 @@
line:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, lineHeight*(k-1))))
local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
+ command:setText(nameList[k])
command:setSize(CEGUI.UVector2(CEGUI.UDim(0, commandWidth), CEGUI.UDim(1, 0)))
command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
- command:setText(nameList[k])
line:addChildWindow(command)
offset = offset + commandWidth + spaceWidth
@@ -117,11 +138,14 @@
local numButtons = orxonox.KeyBinderManager:getInstance():getCurrent():getNumberOfBindings(commandList[k]);
for i=0,(numButtons-1) do
local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
- button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
- button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)
name = P.KeyNameNiceifier(name)
button:setText(name)
+ sampleWindow:setText(name)
+ local size = getMinTextSize(sampleWindow)
+ local buttonWidth = size[2]
+ button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
+ button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
--button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
line:addChildWindow(button)
@@ -149,6 +173,9 @@
table.insert(linesList, line)
window:addChildWindow(line)
end
+
+ pane = tolua.cast(window, "CEGUI::ScrollablePane")
+ pane:setVerticalStepSize(getScrollingStepSize(window))
end
function P.KeyBindButton_clicked(e)
More information about the Orxonox-commit
mailing list