Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6355


Ignore:
Timestamp:
Dec 15, 2009, 5:02:22 PM (15 years ago)
Author:
dafrick
Message:

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.

Location:
code/branches/presentation2/data/gui/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/data/gui/scripts/GUITools.lua

    r6311 r6355  
    1111    InfoPopup.setCloseButton(closeButton)
    1212end
     13
     14function getMinTextSize(window)
     15    local size = {}
     16   
     17    local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(window:getLookNFeel())
     18    local height = window:getFont():getLineSpacing() + window:getUnclippedPixelRect():getHeight() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getHeight()
     19    local width =  window:getFont():getTextExtent(window:getText()) + window:getUnclippedPixelRect():getWidth() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getWidth()
     20   
     21    table.insert(size, height)
     22    table.insert(size, width)
     23    return size
     24end
     25
     26function getScrollingStepSize(window)
     27    local height = window:getUnclippedPixelRect():getHeight()
     28    local maxHeight = CEGUI.System:getSingleton():getGUISheet():getUnclippedPixelRect():getHeight()
     29    local ratio = height/maxHeight
     30    return 0.008*ratio/0.3204
     31end
  • code/branches/presentation2/data/gui/scripts/KeyBindMenu.lua

    r6352 r6355  
    6767    linesList = {}
    6868
    69     lineHeight = 30
    70     commandWidth = 150
     69    --Calculate design parameters:
     70    sampleWindow = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/SampleWindow")
     71    sampleWindow:setText("SampleText")
     72   
     73    local size = getMinTextSize(sampleWindow)
     74    lineHeight = size[1]
     75   
     76    commandWidth = 0
     77    for k,v in pairs(commandList) do
     78        sampleWindow:setText(nameList[k])
     79        size = getMinTextSize(sampleWindow)
     80        if size[2] > commandWidth then
     81            commandWidth = size[2]
     82        end
     83    end
     84
     85    sampleWindow:setText("add")
     86    size = getMinTextSize(sampleWindow)
     87    addWidth = size[2]
     88   
     89    sampleWindow:setText("X")
     90    size = getMinTextSize(sampleWindow)
     91    clearWidth = size[2]
     92
     93    spaceWidth = math.floor(1/14*commandWidth)
     94   
    7195    buttonWidth = 145
    72     clearWidth = 20
    73     addWidth = 30
    74     spaceWidth = 10
    7596
    7697    P.createLines()
     
    101122
    102123    local command = winMgr:createWindow("TaharezLook/StaticText", "orxonox/KeyBindPane/Binding" .. k .. "/Command")
     124    command:setText(nameList[k])
    103125    command:setSize(CEGUI.UVector2(CEGUI.UDim(0, commandWidth), CEGUI.UDim(1, 0)))
    104126    command:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0, 0)))
    105     command:setText(nameList[k])
    106127    line:addChildWindow(command)
    107128    offset = offset + commandWidth + spaceWidth
     
    118139    for i=0,(numButtons-1) do
    119140        local button = winMgr:createWindow("TaharezLook/TabButton", "orxonox/KeyBindPane/Binding" .. k .. "/Button" .. i)
    120         button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
    121         button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
    122141        local name = orxonox.KeyBinderManager:getInstance():getCurrent():getBinding(commandList[k],i)
    123142        name = P.KeyNameNiceifier(name)
    124143        button:setText(name)
     144        sampleWindow:setText(name)
     145        local size = getMinTextSize(sampleWindow)
     146        local buttonWidth = size[2]
     147        button:setSize(CEGUI.UVector2(CEGUI.UDim(0, buttonWidth), CEGUI.UDim(0.7, 0)))
     148        button:setPosition(CEGUI.UVector2(CEGUI.UDim(0, offset), CEGUI.UDim(0.15, 0)))
    125149        orxonox.KeyBinderManager:getInstance():subscribeEventHelper(button, "Clicked", P.filename .. ".KeyBindButton_clicked")
    126150        --button:subscribeScriptedEvent("EventClicked", P.filename .. ".KeyBindButton_clicked")
     
    150174        window:addChildWindow(line)
    151175    end
     176   
     177    pane = tolua.cast(window, "CEGUI::ScrollablePane")
     178    pane:setVerticalStepSize(getScrollingStepSize(window))
    152179end
    153180
Note: See TracChangeset for help on using the changeset viewer.