BsEditorWidget.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsEditorWidgetManager.h"
  4. #include "boost/signal.hpp"
  5. namespace BansheeEditor
  6. {
  7. class EditorWidgetBase
  8. {
  9. public:
  10. virtual void initialize() { }
  11. const CM::String& getName() const { return mName; }
  12. const CM::HString& getDisplayName() const { return mDisplayName; }
  13. void _setSize(CM::UINT32 width, CM::UINT32 height);
  14. void _setPosition(CM::INT32 x, CM::INT32 y);
  15. void _changeParent(EditorWidgetContainer* parent);
  16. EditorWidgetContainer* _getParent() const { return mParent; }
  17. void _disable();
  18. void _enable();
  19. void close();
  20. protected:
  21. friend class EditorWidgetManager;
  22. EditorWidgetBase(const CM::HString& displayName, const CM::String& name);
  23. virtual ~EditorWidgetBase();
  24. CM::String mName;
  25. CM::HString mDisplayName;
  26. EditorWidgetContainer* mParent;
  27. BS::GUIArea* mContent;
  28. BS::GUIWidget& getParentWidget() const;
  29. static void destroy(EditorWidgetBase* widget);
  30. };
  31. template<typename Type>
  32. struct RegisterWidgetOnStart
  33. {
  34. public:
  35. RegisterWidgetOnStart()
  36. {
  37. EditorWidgetManager::preRegisterWidget(Type::getTypeName(), &create);
  38. }
  39. static EditorWidgetBase* create()
  40. {
  41. return cm_new<Type>(EditorWidget<Type>::ConstructPrivately());
  42. }
  43. void makeSureIAmInstantiated() { }
  44. };
  45. template <class Type>
  46. class EditorWidget : public EditorWidgetBase
  47. {
  48. static RegisterWidgetOnStart<Type> RegisterOnStart;
  49. protected:
  50. friend struct RegisterWidgetOnStart<Type>;
  51. struct ConstructPrivately {};
  52. EditorWidget(const CM::HString& displayName)
  53. :EditorWidgetBase(displayName, Type::getTypeName())
  54. {
  55. RegisterOnStart.makeSureIAmInstantiated();
  56. }
  57. public:
  58. virtual ~EditorWidget() { }
  59. };
  60. template <typename Type>
  61. RegisterWidgetOnStart<Type> EditorWidget<Type>::RegisterOnStart;
  62. }