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