BsToolbarItemManager.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsScriptEditorPrerequisites.h"
  5. #include "Utility/BsModule.h"
  6. namespace bs
  7. {
  8. /** @addtogroup EditorScript
  9. * @{
  10. */
  11. /** Tracks toolbar items that are registered in managed code using the ToolbarItem attribute. */
  12. class BS_SCR_BED_EXPORT ToolbarItemManager : public Module<ToolbarItemManager>
  13. {
  14. public:
  15. ToolbarItemManager(ScriptAssemblyManager& scriptObjectManager);
  16. ~ToolbarItemManager();
  17. private:
  18. /** Removes all managed toolbar items from the main menu. */
  19. void clearToolbarItems();
  20. /**
  21. * Reloads all assembly types and attempts to find uses of ToolbarItem. Old toolbar items are cleared and new are
  22. * added.
  23. */
  24. void reloadAssemblyData();
  25. /**
  26. * Parse the provided method and detect whether it has a ToolbarItem attribute. If it has extract needed data from
  27. * it.
  28. *
  29. * @param[in] method Managed method to parse.
  30. * @param[in] name Output name defined in the ToolbarItem attribute.
  31. * @param[in] icon Texture defined in the ToolbarItem attribute.
  32. * @param[in] tooltip Optional tooltip defined in the ToolbarItem attribute.
  33. * @param[in] priority Menu item priority defined in the MenuItem attribute.
  34. * @param[in] separator Should the separator be inserted before the menu item.
  35. * @return True if the method has a ToolbarItem attribute. If false is returned output parameters
  36. * from this method are undefined.
  37. */
  38. bool parseToolbarItemMethod(MonoMethod* method, String& name, HSpriteTexture& icon, HString& tooltip,
  39. INT32& priority, bool& separator) const;
  40. /**
  41. * Triggered when one of the managed toolbar items is clicked.
  42. *
  43. * @param[in] method Managed method that the ToolbarItem is referencing.
  44. */
  45. static void toolbarItemCallback(MonoMethod* method);
  46. ScriptAssemblyManager& mScriptObjectManager;
  47. HEvent mDomainLoadedConn;
  48. MonoClass* mToolbarItemAttribute;
  49. MonoField* mNameField;
  50. MonoField* mIconField;
  51. MonoField* mBuiltinIconField;
  52. MonoField* mTooltipField;
  53. MonoField* mPriorityField;
  54. MonoField* mSeparatorField;
  55. Vector<String> mToolbarItems;
  56. };
  57. /** @} */
  58. }