menuBar.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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. #include "platform/platform.h"
  23. #include "platform/menus/menuBar.h"
  24. #include "platform/menus/popupMenu.h"
  25. #include "gui/core/guiCanvas.h"
  26. //-----------------------------------------------------------------------------
  27. // Constructor/Destructor
  28. //-----------------------------------------------------------------------------
  29. MenuBar::MenuBar()
  30. {
  31. createPlatformPopupMenuData();
  32. mCanvas = NULL;
  33. }
  34. MenuBar::~MenuBar()
  35. {
  36. removeFromCanvas();
  37. deletePlatformPopupMenuData();
  38. }
  39. IMPLEMENT_CONOBJECT(MenuBar);
  40. ConsoleDocClass( MenuBar,
  41. "@brief Used for rendering platform menu bars\n\n"
  42. "Internal use only\n\n"
  43. "@internal"
  44. );
  45. //-----------------------------------------------------------------------------
  46. // Public Methods
  47. //-----------------------------------------------------------------------------
  48. void MenuBar::addObject(SimObject *obj)
  49. {
  50. Parent::addObject(obj);
  51. updateMenuBar(dynamic_cast<PopupMenu *>(obj));
  52. }
  53. void MenuBar::removeObject(SimObject *obj)
  54. {
  55. Parent::removeObject(obj);
  56. updateMenuBar(dynamic_cast<PopupMenu *>(obj));
  57. }
  58. void MenuBar::insertObject(SimObject *obj, S32 pos)
  59. {
  60. Parent::addObject(obj);
  61. if(pos >= size())
  62. pos = size() - 1;
  63. if(pos < size())
  64. {
  65. if(pos < 0) pos = 0;
  66. Parent::reOrder(obj, at(pos));
  67. }
  68. updateMenuBar(dynamic_cast<PopupMenu *>(obj));
  69. }
  70. void MenuBar::pushObject(SimObject *obj)
  71. {
  72. Parent::pushObject(obj);
  73. updateMenuBar(dynamic_cast<PopupMenu *>(obj));
  74. }
  75. void MenuBar::popObject()
  76. {
  77. Parent::popObject();
  78. updateMenuBar();
  79. }
  80. bool MenuBar::reOrder(SimObject *obj, SimObject *target /*= 0*/)
  81. {
  82. bool ret = Parent::reOrder(obj, target);
  83. if(ret)
  84. updateMenuBar(dynamic_cast<PopupMenu *>(obj));
  85. return ret;
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Console Methods
  89. //-----------------------------------------------------------------------------
  90. ConsoleMethod(MenuBar, attachToCanvas, void, 4, 4, "(GuiCanvas, pos)")
  91. {
  92. object->attachToCanvas(dynamic_cast<GuiCanvas*>(Sim::findObject(argv[2])), dAtoi(argv[3]));
  93. }
  94. ConsoleMethod(MenuBar, removeFromCanvas, void, 2, 2, "()")
  95. {
  96. object->removeFromCanvas();
  97. }
  98. //-----------------------------------------------------------------------------
  99. ConsoleMethod(MenuBar, insert, void, 4, 4,"(object, pos) insert object at position")
  100. {
  101. SimObject* pObject = Sim::findObject(argv[2]);
  102. if(pObject)
  103. object->insertObject(pObject, dAtoi(argv[3]));
  104. }