BsModalWindow.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "EditorWindow/BsEditorWindowBase.h"
  6. namespace bs
  7. {
  8. /** @addtogroup EditorWindow
  9. * @{
  10. */
  11. /**
  12. * Base implementation of a window that when open doesn't allow you to interact with other windows. Modal windows are
  13. * similar to editor windows but cannot be docked, and are meant to be used for temporary operations like dialog boxes
  14. * and progress bars.
  15. */
  16. class BS_ED_EXPORT ModalWindow : public EditorWindowBase
  17. {
  18. public:
  19. virtual ~ModalWindow() = default;
  20. /** @copydoc EditorWindowBase::update */
  21. void update() override;
  22. /** @copydoc EditorWindowBase::close */
  23. void close() override;
  24. /** Changes the text in the modal window title bar. */
  25. void setTitle(const HString& title);
  26. /** @copydoc EditorWindowBase::setSize */
  27. void setSize(UINT32 width, UINT32 height) override;
  28. /**
  29. * Returns the width of the content area of the window, in pixels. The content area represents the area of the
  30. * window not including the title bar and the border.
  31. */
  32. UINT32 getContentWidth() const;
  33. /**
  34. * Returns the height of the content area of the window, in pixels. The content area represents the area of the
  35. * window not including the title bar and the border.
  36. */
  37. UINT32 getContentHeight() const;
  38. /**
  39. * Sets the width & height of the content area of the window, in pixels. The content area represents the area of
  40. * the window not including the titlebar and the border.
  41. */
  42. void setContentSize(UINT32 width, UINT32 height);
  43. /** Converts screen pointer coordinates into coordinates relative to the window content's GUI panel. */
  44. Vector2I screenToWindowPos(const Vector2I& screenPos) const;
  45. /** Converts pointer coordinates relative to the window content's GUI panel into screen coordinates. */
  46. Vector2I windowToScreenPos(const Vector2I& windowPos) const;
  47. protected:
  48. friend class EditorWindowManager;
  49. ModalWindow(const HString& title, bool hasCloseButton = false, UINT32 width = 200, UINT32 height = 200);
  50. /**
  51. * Returns the area in which the GUI contents are displayed (not including title bar and other default
  52. * elements). Area is relative to window.
  53. */
  54. Rect2I getContentArea() const;
  55. /** @copydoc EditorWindowBase::resized */
  56. void resized() override;
  57. private:
  58. /**
  59. * Updates the placement of child GUI elements and their non-client areas (used for OS move/resize operations).
  60. * Should be called after window size changes.
  61. */
  62. void updateSize();
  63. /** Returns the height in pixels taken up by the title bar. */
  64. UINT32 getTitleBarHeight() const;
  65. GUIPanel* mTitleBarPanel = nullptr;
  66. GUIPanel* mTitleBarBgPanel = nullptr;
  67. GUILabel* mTitle = nullptr;
  68. GUIButton* mCloseButton = nullptr;
  69. GUITexture* mTitleBarBg = nullptr;
  70. protected:
  71. GUIPanel* mContents = nullptr;
  72. };
  73. /** @} */
  74. }