BsEditorWidget.h 2.7 KB

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