BsEditorWidget.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsEditorWidgetManager.h"
  4. #include "BsEvent.h"
  5. namespace BansheeEngine
  6. {
  7. class BS_ED_EXPORT EditorWidgetBase
  8. {
  9. public:
  10. const String& getName() const { return mName; }
  11. const HString& getDisplayName() const { return mDisplayName; }
  12. INT32 getX() const { return mX; }
  13. INT32 getY() const { return mY; }
  14. UINT32 getWidth() const { return mWidth; }
  15. UINT32 getHeight() const { return mHeight; }
  16. void _setSize(UINT32 width, UINT32 height);
  17. void _setPosition(INT32 x, INT32 y);
  18. void _changeParent(EditorWidgetContainer* parent);
  19. EditorWidgetContainer* _getParent() const { return mParent; }
  20. void _disable();
  21. void _enable();
  22. void close();
  23. virtual void _update() { }
  24. Event<void(UINT32, UINT32)> onResized;
  25. Event<void(INT32, INT32)> onMoved;
  26. Event<void(EditorWidgetContainer*)> onParentChanged;
  27. protected:
  28. friend class EditorWidgetManager;
  29. EditorWidgetBase(const HString& displayName, const String& name, EditorWidgetContainer& parentContainer);
  30. virtual ~EditorWidgetBase();
  31. String mName;
  32. HString mDisplayName;
  33. EditorWidgetContainer* mParent;
  34. INT32 mX, mY;
  35. UINT32 mWidth, mHeight;
  36. GUIArea* mContent;
  37. GUIWidget& getParentWidget() const;
  38. static void destroy(EditorWidgetBase* widget);
  39. };
  40. template<typename Type>
  41. struct RegisterWidgetOnStart
  42. {
  43. public:
  44. RegisterWidgetOnStart()
  45. {
  46. EditorWidgetManager::preRegisterWidget(Type::getTypeName(), &create);
  47. }
  48. static EditorWidgetBase* create(EditorWidgetContainer& parentContainer)
  49. {
  50. return bs_new<Type>(EditorWidget<Type>::ConstructPrivately(), parentContainer);
  51. }
  52. void makeSureIAmInstantiated() { }
  53. };
  54. template <class Type>
  55. class EditorWidget : public EditorWidgetBase
  56. {
  57. static RegisterWidgetOnStart<Type> RegisterOnStart;
  58. protected:
  59. friend struct RegisterWidgetOnStart<Type>;
  60. struct ConstructPrivately {};
  61. EditorWidget(const HString& displayName, EditorWidgetContainer& parentContainer)
  62. :EditorWidgetBase(displayName, Type::getTypeName(), parentContainer)
  63. {
  64. RegisterOnStart.makeSureIAmInstantiated();
  65. }
  66. public:
  67. virtual ~EditorWidget() { }
  68. };
  69. template <typename Type>
  70. RegisterWidgetOnStart<Type> EditorWidget<Type>::RegisterOnStart;
  71. }