BsEditorWidget.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. virtual void doOnMoved(INT32 x, INT32 y);
  32. virtual void doOnResized(UINT32 width, UINT32 height);
  33. virtual void doOnParentChanged();
  34. String mName;
  35. HString mDisplayName;
  36. EditorWidgetContainer* mParent;
  37. INT32 mX, mY;
  38. UINT32 mWidth, mHeight;
  39. GUIArea* mContent;
  40. GUIWidget& getParentWidget() const;
  41. static void destroy(EditorWidgetBase* widget);
  42. };
  43. template<typename Type>
  44. struct RegisterWidgetOnStart
  45. {
  46. public:
  47. RegisterWidgetOnStart()
  48. {
  49. EditorWidgetManager::preRegisterWidget(Type::getTypeName(), &create);
  50. }
  51. static EditorWidgetBase* create(EditorWidgetContainer& parentContainer)
  52. {
  53. return bs_new<Type>(EditorWidget<Type>::ConstructPrivately(), parentContainer);
  54. }
  55. void makeSureIAmInstantiated() { }
  56. };
  57. template <class Type>
  58. class EditorWidget : public EditorWidgetBase
  59. {
  60. static RegisterWidgetOnStart<Type> RegisterOnStart;
  61. protected:
  62. friend struct RegisterWidgetOnStart<Type>;
  63. struct ConstructPrivately {};
  64. EditorWidget(const HString& displayName, EditorWidgetContainer& parentContainer)
  65. :EditorWidgetBase(displayName, Type::getTypeName(), parentContainer)
  66. {
  67. RegisterOnStart.makeSureIAmInstantiated();
  68. }
  69. public:
  70. virtual ~EditorWidget() { }
  71. };
  72. template <typename Type>
  73. RegisterWidgetOnStart<Type> EditorWidget<Type>::RegisterOnStart;
  74. }