BsModalWindow.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include "BsModalWindow.h"
  2. #include "BsEditorWindowManager.h"
  3. #include "BsRenderWindow.h"
  4. #include "BsPlatform.h"
  5. #include "BsGUILayoutX.h"
  6. #include "BsGUILayoutY.h"
  7. #include "BsGUISpace.h"
  8. #include "BsGUIButton.h"
  9. #include "BsGUITexture.h"
  10. #include "BsGUILabel.h"
  11. #include "BsGUIPanel.h"
  12. #include "BsGUIWidget.h"
  13. namespace BansheeEngine
  14. {
  15. ModalWindow::ModalWindow(const HString& title, bool hasCloseButton)
  16. :EditorWindowBase(true), mTitleBarPanel(nullptr), mTitleBarBgPanel(nullptr),
  17. mCloseButton(nullptr), mTitleBarBg(nullptr), mTitle(nullptr), mContents(nullptr)
  18. {
  19. EditorWindowManager::instance().registerWindow(this);
  20. mTitleBarBgPanel = mGUI->getPanel()->addNewElement<GUIPanel>();
  21. mTitleBarBgPanel->setDepthRange(std::numeric_limits<UINT16>::max() - 1);
  22. mTitleBarBgPanel->setPosition(1, 1);
  23. mTitleBarPanel = mGUI->getPanel()->addNewElement<GUIPanel>();
  24. mTitleBarPanel->setDepthRange(0);
  25. mTitleBarPanel->setPosition(1, 1);
  26. mTitleBarBg = GUITexture::create(GUIOptions(GUIOption::flexibleWidth()), "TitleBarBackground");
  27. mTitle = GUILabel::create(title);
  28. GUILayout* bgLayout = mTitleBarBgPanel->addNewElement<GUILayoutY>();
  29. GUILayout* bgLayoutX = bgLayout->addNewElement<GUILayoutX>();
  30. bgLayoutX->addElement(mTitleBarBg);
  31. bgLayoutX->addNewElement<GUIFixedSpace>(1);
  32. bgLayout->addNewElement<GUIFlexibleSpace>();
  33. bgLayout->addNewElement<GUIFixedSpace>(1);
  34. GUILayout* contentLayoutY = mTitleBarPanel->addNewElement<GUILayoutY>();
  35. GUILayout* contentLayoutX = contentLayoutY->addNewElement<GUILayoutX>();
  36. contentLayoutX->addNewElement<GUIFlexibleSpace>();
  37. GUILayout* titleLayout = contentLayoutX->addNewElement<GUILayoutY>();
  38. titleLayout->addNewElement<GUIFixedSpace>(2);
  39. titleLayout->addElement(mTitle);
  40. titleLayout->addNewElement<GUIFlexibleSpace>();
  41. contentLayoutX->addNewElement<GUIFlexibleSpace>();
  42. if (hasCloseButton)
  43. {
  44. mCloseButton = GUIButton::create(HString(L""), "WinCloseBtn");
  45. contentLayoutX->addElement(mCloseButton);
  46. mCloseButton->onClick.connect(std::bind(&ModalWindow::close, this));
  47. }
  48. contentLayoutX->addNewElement<GUIFixedSpace>(1);
  49. contentLayoutY->addNewElement<GUIFlexibleSpace>();
  50. contentLayoutY->addNewElement<GUIFixedSpace>(1);
  51. mContents = mGUI->getPanel()->addNewElement<GUIPanel>();
  52. mContents->setDepthRange(0);
  53. mContents->setPosition(1, 1 + getTitleBarHeight());
  54. updateSize();
  55. }
  56. ModalWindow::~ModalWindow()
  57. {
  58. }
  59. void ModalWindow::update()
  60. {
  61. }
  62. void ModalWindow::close()
  63. {
  64. EditorWindowManager::instance().destroy(this);
  65. }
  66. void ModalWindow::setTitle(const HString& title)
  67. {
  68. mTitle->setContent(GUIContent(title));
  69. }
  70. void ModalWindow::resized()
  71. {
  72. EditorWindowBase::resized();
  73. updateSize();
  74. }
  75. void ModalWindow::updateSize()
  76. {
  77. mContents->setWidth(getWidth() - 2);
  78. mContents->setHeight(getHeight() - 2 - getTitleBarHeight());
  79. Vector<Rect2I> captionAreas;
  80. captionAreas.push_back(Rect2I(1, 1, getWidth() - 2, getTitleBarHeight()));
  81. Platform::setCaptionNonClientAreas(*mRenderWindow->getCore().get(), captionAreas);
  82. }
  83. Rect2I ModalWindow::getContentArea() const
  84. {
  85. return Rect2I(1, 1 + getTitleBarHeight(), getWidth() - 2, getHeight() - getTitleBarHeight() - 2);
  86. }
  87. UINT32 ModalWindow::getTitleBarHeight() const
  88. {
  89. return mTitleBarBg->getBounds().height;
  90. }
  91. }