BsEditorWidget.h 2.7 KB

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