Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 30, 2011, 6:45:06 PM (14 years ago)
Author:
rgrieder
Message:

Adjusted implementation of tribool to work well with tolua and integrated it into our GUI code.
Use tribool(true), tribool(false) and tribool(dontcare) in Lua.

Location:
code/branches/unity_build
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/unity_build/data/gui/scripts/ChatBox-inputonly.lua

    r7801 r8687  
    11-- ChatBox-inputonly.lua
    22
    3 local P = createMenuSheet("ChatBox-inputonly", true, TriBool.True, TriBool.Dontcare, false)
     3local P = createMenuSheet("ChatBox-inputonly", true, tribool(true), tribool(dontcare), false)
    44return P
    55
  • code/branches/unity_build/data/gui/scripts/ChatBox.lua

    r7801 r8687  
    11-- ChatBox.lua
    22
    3 local P = createMenuSheet("ChatBox", true, TriBool.True, TriBool.Dontcare, false)
     3local P = createMenuSheet("ChatBox", true, tribool(true), tribool(dontcare), false)
    44
    55function P.ChatBoxCloseButton_clicked(e)
  • code/branches/unity_build/data/gui/scripts/MenuSheet.lua

    r7689 r8687  
    1111-- Parameters:
    1212-- Except for _name, you can provide nil. Then the default value will be used.
    13 -- For _tShowCusor and _tUseKeyboard you can specify TriBool.Dontcare if the value doesn't matter at all. Then the value of the underlaying sheet will be used.
     13-- For _tShowCusor and _tUseKeyboard you can specify tribool(dontcare) if the value doesn't matter at all. Then the value of the underlaying sheet will be used.
    1414function P.new(_name, _bHidePrevious, _tShowCursor, _tUseKeyboard, _bBlockJoyStick)
    1515    local newSheet = GUISheet.new(_name)
    1616    newSheet.bHidePrevious  = handleDefArg(_bHidePrevious,  true)
    17     newSheet.tShowCursor    = handleDefArg(_tShowCusor,     TriBool.True)
    18     newSheet.tUseKeyboard   = handleDefArg(_tUseKeyboard,   TriBool.True)
     17    newSheet.tShowCursor    = handleDefArg(_tShowCusor,     tribool(true))
     18    newSheet.tUseKeyboard   = handleDefArg(_tUseKeyboard,   tribool(true))
    1919    newSheet.bBlockJoyStick = handleDefArg(_bBlockJoyStick, false)
    2020
  • code/branches/unity_build/data/gui/scripts/MiscConfigMenu.lua

    r8079 r8687  
    11-- MiscConfigMenu.lua
    22
    3 local P = createMenuSheet("MiscConfigMenu", true, TriBool.True, TriBool.True)
     3local P = createMenuSheet("MiscConfigMenu", true, tribool(true), tribool(true))
    44
    55P.commandList = {}
  • code/branches/unity_build/data/gui/scripts/NotificationLayer.lua

    r8351 r8687  
    11-- NotificationLayer.lua
    22
    3 local P = createMenuSheet("NotificationLayer", true, TriBool.True, TriBool.True)
     3local P = createMenuSheet("NotificationLayer", true, tribool(true), tribool(true))
    44
    55P.queueList = {}
  • code/branches/unity_build/data/gui/scripts/SheetManager.lua

    r8079 r8687  
    8181
    8282    if bNoInput == true then
    83         menuSheet.tShowCursor = TriBool.Dontcare
     83        menuSheet.tShowCursor = tribool(dontcare)
    8484    end
    8585
     
    110110    end
    111111
    112     -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare
    113     if menuSheet.tShowCursor == TriBool.True then
     112    -- Only change cursor situation if menuSheet.tShowCursor ~= tribool(dontcare)
     113    if menuSheet.tShowCursor == tribool(true) then
    114114        showCursor()
    115     elseif menuSheet.tShowCursor == TriBool.False then
     115    elseif menuSheet.tShowCursor == tribool(false) then
    116116        hideCursor()
    117117    end
     
    186186    -- CURSOR SHOWING
    187187    local i = activeMenuSheets.size
    188     -- Find top most sheet that doesn't have tShowCusor == TriBool.Dontcare
    189     while i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.Dontcare do
     188    -- Find top most sheet that doesn't have tShowCusor == tribool(dontcare)
     189    while i > 0 and activeMenuSheets[i].sheet.tShowCursor == tribool(dontcare) do
    190190        i = i - 1
    191191    end
    192     if i > 0 and activeMenuSheets[i].sheet.tShowCursor == TriBool.True then
     192    if i > 0 and activeMenuSheets[i].sheet.tShowCursor == tribool(true) then
    193193        showCursor()
    194194    else
     
    254254function windowResized(e)
    255255    for name, sheet in pairs(loadedSheets) do
    256         if orxonox.GraphicsManager:getInstance():isFullScreen() or sheet.tShowCursor == TriBool.False then
    257             inputMgr:setMouseExclusive(sheet.inputState, TriBool.True)
     256        if orxonox.GraphicsManager:getInstance():isFullScreen() or sheet.tShowCursor == tribool(false) then
     257            inputMgr:setMouseExclusive(sheet.inputState, tribool(true))
    258258        else
    259             inputMgr:setMouseExclusive(sheet.inputState, TriBool.False)
     259            inputMgr:setMouseExclusive(sheet.inputState, tribool(false))
    260260        end
    261261    end
    262262    local sheetTuple = activeMenuSheets[activeMenuSheets.size]
    263263    if sheetTuple then
    264         if orxonox.GraphicsManager:getInstance():isFullScreen() and sheetTuple.sheet.tShowCursor ~= TriBool.False then
     264        if orxonox.GraphicsManager:getInstance():isFullScreen() and sheetTuple.sheet.tShowCursor ~= tribool(false) then
    265265            showCursor()
    266266        else
  • code/branches/unity_build/data/lua/Tools.lua

    r6746 r8687  
    1616end
    1717
    18 -- Short forms for TriBool
    19 TriBool =
    20 {
    21     True     = orxonox.TriBool.True,
    22     False    = orxonox.TriBool.False,
    23     Dontcare = orxonox.TriBool.Dontcare
    24 }
     18-- Shortcuts for tribool
     19tribool  = orxonox.tribool
     20dontcare = orxonox.dontcare_keyword_t()
  • code/branches/unity_build/src/libraries/core/GUIManager.h

    r8678 r8687  
    6161
    6262    // Acquaint Tolua with tribool
    63     class tribool; // tolua_export
     63    /* tolua_begin
     64    struct dontcare_keyword_t
     65    {
     66        dontcare_keyword_t();
     67    };
     68    class tribool
     69    {
     70        tribool(bool value);
     71        tribool(dontcare_keyword_t);
     72        bool operator==(tribool);
     73        bool operator!=(tribool);
     74    };
     75    tolua_end */
    6476
    6577    /**
  • code/branches/unity_build/src/libraries/util/tribool.h

    • Property svn:eol-style set to native
    r8678 r8687  
    1818namespace orxonox {
    1919
    20 // Forward declare tribool
    21 class tribool;
    22 
    23 /// INTERNAL ONLY
    24 namespace detail {
    2520/**
    2621 * INTERNAL ONLY
    27  *
    28  * \brief A type used only to uniquely identify the 'dontcare'
    29  * function/keyword.
     22 * The type of the 'dontcare' keyword.
    3023 */
    31 struct dontcare_t
    32 {
    33 };
    34 
    35 } // end namespace detail
     24struct dontcare_keyword_t { };
    3625
    3726/**
    38  * INTERNAL ONLY
    39  * The type of the 'dontcare' keyword. This has the same type as the
    40  * function 'dontcare' so that we can recognize when the keyword is
    41  * used.
     27 * \brief Keyword for the dontcare tribool value
    4228 */
    43 typedef bool (*dontcare_keyword_t)(tribool, detail::dontcare_t);
    44 
    45 /**
    46  * \brief Keyword and test function for the dontcare tribool value
    47  *
    48  * The \c dontcare function has a dual role. It's first role is
    49  * as a unary function that tells whether the tribool value is in the
    50  * "dontcare" state. It's second role is as a keyword
    51  * representing the dontcare (just like "true" and "false"
    52  * represent the true and false states).
    53  *
    54  * \returns <tt>x.value == tribool::dontcare_value</tt>
    55  * \throws nothrow
    56  */
    57 inline bool
    58 dontcare(tribool x, detail::dontcare_t dummy = detail::dontcare_t());
     29const dontcare_keyword_t dontcare;
    5930
    6031/**
     
    9061
    9162  /**
     63   * \brief Compare tribools for equality
     64   *
     65   * \returns the result of comparing two tribool values.
     66   * \throws nothrow
     67   */
     68  inline bool operator==(tribool y)
     69  {
     70    return (this->value == y.value);
     71  }
     72
     73  /**
     74   * \overload
     75   */
     76  inline bool operator==(bool y) { return (*this) == tribool(y); }
     77
     78  /**
     79   * \overload
     80   */
     81  inline bool operator==(dontcare_keyword_t)
     82  { return tribool(dontcare) == (*this); }
     83
     84  /**
     85   * \brief Compare tribools for inequality
     86   *
     87   * \returns the result of comparing two tribool values for inequality.
     88   * \throws nothrow
     89   */
     90  inline bool operator!=(tribool y)
     91  {
     92    return !((*this) == y);
     93  }
     94
     95  /**
     96   * \overload
     97   */
     98  inline bool operator!=(bool y) { return (*this) != tribool(y); }
     99
     100  /**
     101   * \overload
     102   */
     103  inline bool operator!=(dontcare_keyword_t)
     104  { return (*this) != tribool(dontcare); }
     105
     106  /**
    92107   * The actual stored value in this 3-state boolean, which may be false, true,
    93108   * or dontcare.
     
    95110  enum value_t { false_value, true_value, dontcare_value } value;
    96111};
    97 
    98 // Check if the given tribool has an dontcare value. Also doubles as a
    99 // keyword for the 'dontcare' value
    100 inline bool dontcare(tribool x, detail::dontcare_t)
    101 {
    102   return x.value == tribool::dontcare_value;
    103 }
    104 
    105 /**
    106  * \brief Compare tribools for equality
    107  *
    108  * \returns the result of comparing two tribool values, according to
    109  * the following table:
    110  *       <table border=1>
    111  *          <tr>
    112  *            <th><center><code>==</code></center></th>
    113  *            <th><center>false</center></th>
    114  *            <th><center>true</center></th>
    115  *            <th><center>false</center></th>
    116  *          </tr>
    117  *          <tr>
    118  *            <th><center>false</center></th>
    119  *            <td><center>true</center></td>
    120  *            <td><center>false</center></td>
    121  *            <td><center>false</center></td>
    122  *          </tr>
    123  *          <tr>
    124  *            <th><center>true</center></th>
    125  *            <td><center>false</center></td>
    126  *            <td><center>true</center></td>
    127  *            <td><center>false</center></td>
    128  *          </tr>
    129  *          <tr>
    130  *            <th><center>dontcare</center></th>
    131  *            <td><center>false</center></td>
    132  *            <td><center>false</center></td>
    133  *            <td><center>false</center></td>
    134  *          </tr>
    135  *      </table>
    136  * \throws nothrow
    137  */
    138 inline bool operator==(tribool x, tribool y)
    139 {
    140   return (x.value == y.value);
    141 }
    142 
    143 /**
    144  * \overload
    145  */
    146 inline bool operator==(tribool x, bool y) { return x == tribool(y); }
    147112
    148113/**
     
    160125 * \overload
    161126 */
    162 inline bool operator==(tribool x, dontcare_keyword_t)
    163 { return tribool(dontcare) == x; }
    164 
    165 /**
    166  * \brief Compare tribools for inequality
    167  *
    168  * \returns the result of comparing two tribool values for inequality,
    169  * according to the following table:
    170  *       <table border=1>
    171  *           <tr>
    172  *             <th><center><code>!=</code></center></th>
    173  *             <th><center>false</center></th>
    174  *             <th><center>true</center></th>
    175  *             <th><center>dontcare</center></th>
    176  *           </tr>
    177  *           <tr>
    178  *             <th><center>false</center></th>
    179  *             <td><center>false</center></td>
    180  *             <td><center>true</center></td>
    181  *             <td><center>true</center></td>
    182  *           </tr>
    183  *           <tr>
    184  *             <th><center>true</center></th>
    185  *             <td><center>true</center></td>
    186  *             <td><center>false</center></td>
    187  *             <td><center>true</center></td>
    188  *           </tr>
    189  *           <tr>
    190  *             <th><center>true</center></th>
    191  *             <td><center>true</center></td>
    192  *             <td><center>true</center></td>
    193  *             <td><center>false</center></td>
    194  *           </tr>
    195  *       </table>
    196  * \throws nothrow
    197  */
    198 inline bool operator!=(tribool x, tribool y)
    199 {
    200   return !(x == y);
    201 }
    202 
    203 /**
    204  * \overload
    205  */
    206 inline bool operator!=(tribool x, bool y) { return x != tribool(y); }
    207 
    208 /**
    209  * \overload
    210  */
    211127inline bool operator!=(bool x, tribool y) { return tribool(x) != y; }
    212128
     
    217133{ return tribool(dontcare) != x; }
    218134
    219 /**
    220  * \overload
    221  */
    222 inline bool operator!=(tribool x, dontcare_keyword_t)
    223 { return x != tribool(dontcare); }
    224 
    225135} // end namespace orxonox
    226136
Note: See TracChangeset for help on using the changeset viewer.