BsEditorWidget.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. bool hasFocus() const { return mHasFocus; }
  17. void _setSize(UINT32 width, UINT32 height);
  18. void _setPosition(INT32 x, INT32 y);
  19. void _changeParent(EditorWidgetContainer* parent);
  20. void _setHasFocus(bool focus) { mHasFocus = focus; }
  21. EditorWidgetContainer* _getParent() const { return mParent; }
  22. Vector2I screenToWidgetPos(const Vector2I& screenPos) const;
  23. Vector2I widgetToScreenPos(const Vector2I& widgetPos) const;
  24. void _disable();
  25. void _enable();
  26. void close();
  27. virtual void _update() { }
  28. Event<void(UINT32, UINT32)> onResized;
  29. Event<void(INT32, INT32)> onMoved;
  30. Event<void(EditorWidgetContainer*)> onParentChanged;
  31. protected:
  32. friend class EditorWidgetManager;
  33. EditorWidgetBase(const HString& displayName, const String& name, EditorWidgetContainer& parentContainer);
  34. virtual ~EditorWidgetBase();
  35. virtual void doOnMoved(INT32 x, INT32 y);
  36. virtual void doOnResized(UINT32 width, UINT32 height);
  37. virtual void doOnParentChanged();
  38. String mName;
  39. HString mDisplayName;
  40. EditorWidgetContainer* mParent;
  41. INT32 mX, mY;
  42. UINT32 mWidth, mHeight;
  43. GUIArea* mContent;
  44. bool mHasFocus;
  45. GUIWidget& getParentWidget() const;
  46. static void destroy(EditorWidgetBase* widget);
  47. };
  48. template<typename Type>
  49. struct RegisterWidgetOnStart
  50. {
  51. public:
  52. RegisterWidgetOnStart()
  53. {
  54. EditorWidgetManager::preRegisterWidget(Type::getTypeName(), &create);
  55. }
  56. static EditorWidgetBase* create(EditorWidgetContainer& parentContainer)
  57. {
  58. return bs_new<Type>(EditorWidget<Type>::ConstructPrivately(), parentContainer);
  59. }
  60. void makeSureIAmInstantiated() { }
  61. };
  62. template <class Type>
  63. class EditorWidget : public EditorWidgetBase
  64. {
  65. static RegisterWidgetOnStart<Type> RegisterOnStart;
  66. protected:
  67. friend struct RegisterWidgetOnStart<Type>;
  68. struct ConstructPrivately {};
  69. EditorWidget(const HString& displayName, EditorWidgetContainer& parentContainer)
  70. :EditorWidgetBase(displayName, Type::getTypeName(), parentContainer)
  71. {
  72. RegisterOnStart.makeSureIAmInstantiated();
  73. }
  74. public:
  75. virtual ~EditorWidget() { }
  76. };
  77. template <typename Type>
  78. RegisterWidgetOnStart<Type> EditorWidget<Type>::RegisterOnStart;
  79. }