popupMenu_ScriptBinding.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleMethodGroupBeginWithDocs(PopupMenu, SimObject)
  23. /*! Insert a new menu item
  24. @param pos The position of the item
  25. @param title The title of the item to add (optional)
  26. @param accelerator A keyboard accelerator for the menu item
  27. @return Returns the id of the new menu item as a nonnegative integer (-1 on fail)
  28. */
  29. ConsoleMethodWithDocs(PopupMenu, insertItem, ConsoleInt, 3, 5, (pos, [title]?, [accelerator]?))
  30. {
  31. return object->insertItem(dAtoi(argv[2]), argc < 4 ? NULL : argv[3], argc < 5 ? "" : argv[4]);
  32. }
  33. /*! Removes the menu item at the given position
  34. @param pos The position of the desired menu item to obliterate
  35. @return No return value
  36. */
  37. ConsoleMethodWithDocs(PopupMenu, removeItem, ConsoleVoid, 3, 3, (pos))
  38. {
  39. object->removeItem(dAtoi(argv[2]));
  40. }
  41. /*! Inserts a menu item into the current object
  42. @param pos The position of the menu item
  43. @param The desired title of the sub menu
  44. @param subMenu The submenu you are inserting.
  45. @return Returns the ID of the inserted item or -1 on failure
  46. */
  47. ConsoleMethodWithDocs(PopupMenu, insertSubMenu, ConsoleInt, 5, 5, (pos, title, subMenu))
  48. {
  49. PopupMenu *mnu = dynamic_cast<PopupMenu *>(Sim::findObject(argv[4]));
  50. if(mnu == NULL)
  51. {
  52. Con::errorf("PopupMenu::insertSubMenu - Invalid PopupMenu object specified for submenu");
  53. return -1;
  54. }
  55. return object->insertSubMenu(dAtoi(argv[2]), argv[3], mnu);
  56. }
  57. //////////////////////////////////////////////////////////////////////////
  58. /*! Enables the item at the given position
  59. @param pos The item's position
  60. @param enabled A boolean value to set its current status
  61. @return No return value
  62. */
  63. ConsoleMethodWithDocs(PopupMenu, enableItem, ConsoleVoid, 4, 4, (pos, enabled))
  64. {
  65. object->enableItem(dAtoi(argv[2]), dAtob(argv[3]));
  66. }
  67. /*! Sets the given item's \checked\ status
  68. @param pos The item's position
  69. @return No return value
  70. */
  71. ConsoleMethodWithDocs(PopupMenu, checkItem, ConsoleVoid, 4, 4, (pos, checked))
  72. {
  73. object->checkItem(dAtoi(argv[2]), dAtob(argv[3]));
  74. }
  75. /*! Checks the specified menu item and makes it a radio item
  76. @param firstPos The position of the first item in the group
  77. @param lastPos The position of the last item in the group
  78. @param checkPos The position of the item to check
  79. @return No return value.
  80. */
  81. ConsoleMethodWithDocs(PopupMenu, checkRadioItem, ConsoleVoid, 5, 5, (firstPos, lastPos, checkPos))
  82. {
  83. object->checkRadioItem(dAtoi(argv[2]), dAtoi(argv[3]), dAtoi(argv[4]));
  84. }
  85. /*! Checks (no pun intended) the \checked\ flag of the given menu item
  86. @param pos The position of the desired item
  87. @return Returns true if checked, false otherwise
  88. */
  89. ConsoleMethodWithDocs(PopupMenu, isItemChecked, ConsoleBool, 3, 3, (pos))
  90. {
  91. return object->isItemChecked(dAtoi(argv[2]));
  92. }
  93. //////////////////////////////////////////////////////////////////////////
  94. /*! Attaches given menu item to menu bar
  95. @param pos The position of the desired menu item
  96. @param title The menu item title
  97. @return No return value
  98. */
  99. ConsoleMethodWithDocs(PopupMenu, attachToMenuBar, ConsoleVoid, 4, 4, (pos, title))
  100. {
  101. object->attachToMenuBar(dAtoi(argv[2]), argv[3]);
  102. }
  103. /*! Removes current item from menu bar
  104. @return No return value
  105. */
  106. ConsoleMethodWithDocs(PopupMenu, removeFromMenuBar, ConsoleVoid, 2, 2, ())
  107. {
  108. object->removeFromMenuBar();
  109. }
  110. //////////////////////////////////////////////////////////////////////////
  111. /*! Show the menu (optional: specify position)
  112. @param x,y Coodinates to display menu (upper left corner)
  113. @return No return value.
  114. */
  115. ConsoleMethodWithDocs(PopupMenu, showPopup, ConsoleVoid, 2, 4, ([x, y]?))
  116. {
  117. S32 x = argc >= 3 ? dAtoi(argv[2]) : -1;
  118. S32 y = argc >= 4 ? dAtoi(argv[3]) : -1;
  119. object->showPopup(x, y);
  120. }
  121. ConsoleMethodGroupEndWithDocs(PopupMenu)