BsGUIWidget.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "CmComponent.h"
  4. #include "CmRect.h"
  5. #include "CmVector3.h"
  6. #include "CmQuaternion.h"
  7. namespace BansheeEngine
  8. {
  9. class BS_EXPORT GUIWidget : public CM::Component
  10. {
  11. public:
  12. virtual ~GUIWidget();
  13. /**
  14. * @brief Initializes the GUIWidget. Must be called in order for GUIWidget to start rendering.
  15. *
  16. * @param target Target onto which we want to render the widget.
  17. * @param ownerWindow Window that contains the widget. This will be the source of all input
  18. * for the widget. "target" and "ownerWindow" may be the same object.
  19. */
  20. virtual void initialize(CM::Viewport* target, CM::RenderWindow* ownerWindow);
  21. void setSkin(const GUISkin* skin);
  22. const GUISkin* getSkin() const;
  23. CM::UINT8 getDepth() const { return mDepth; }
  24. void setDepth(CM::UINT8 depth) { mDepth = depth; mWidgetIsDirty = true; }
  25. bool inBounds(const CM::Int2& position) const;
  26. /**
  27. * @brief Return true if widget or any of its elements are dirty.
  28. *
  29. * @param cleanIfDirty If true, all dirty elements will be updated and widget will be marked as clean.
  30. *
  31. * @return True if dirty, false if not. If "cleanIfDirty" is true, the returned state is the one before cleaning.
  32. */
  33. bool isDirty(bool cleanIfDirty);
  34. CM::RenderWindow* getOwnerWindow() const { return mOwnerWindow; }
  35. CM::Viewport* getTarget() const { return mTarget; }
  36. const CM::Vector<GUIElement*>::type& getElements() const { return mElements; }
  37. void _updateLayout();
  38. /**
  39. * @brief Forwards the specified mouse event to the specified element. The element
  40. * must be a child of this widget.
  41. */
  42. virtual bool _mouseEvent(GUIElement* element, const GUIMouseEvent& ev);
  43. /**
  44. * @brief Forwards the specified key event to the specified element. The element
  45. * must be a child of this widget.
  46. */
  47. virtual bool _keyEvent(GUIElement* element, const GUIKeyEvent& ev);
  48. protected:
  49. friend class CM::SceneObject;
  50. friend class GUIElement;
  51. friend class GUIArea;
  52. friend class GUIManager;
  53. GUIWidget(const CM::HSceneObject& parent);
  54. void registerElement(GUIElement* elem);
  55. void unregisterElement(GUIElement* elem);
  56. void registerArea(GUIArea* area);
  57. void unregisterArea(GUIArea* area);
  58. private:
  59. void updateBounds() const;
  60. virtual void ownerWindowResized();
  61. virtual void ownerWindowFocusChanged();
  62. virtual void update();
  63. CM::RenderWindow* mOwnerWindow;
  64. CM::Viewport* mTarget;
  65. CM::Vector<GUIElement*>::type mElements;
  66. CM::Vector<GUIArea*>::type mAreas;
  67. CM::UINT8 mDepth;
  68. CM::Vector3 mLastFramePosition;
  69. CM::Quaternion mLastFrameRotation;
  70. CM::Vector3 mLastFrameScale;
  71. mutable bool mWidgetIsDirty;
  72. mutable CM::Rect mBounds;
  73. mutable CM::Vector<CM::HMesh>::type mCachedMeshes;
  74. mutable CM::Vector<CM::HMaterial>::type mCachedMaterials;
  75. const GUISkin* mSkin;
  76. static GUISkin DefaultSkin;
  77. };
  78. }