BsGUIWindowFrameWidget.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "GUI/BsGUIWindowFrameWidget.h"
  4. #include "RTTI/BsGUIWindowFrameWidgetRTTI.h"
  5. #include "GUI/BsGUIPanel.h"
  6. #include "GUI/BsCGUIWidget.h"
  7. #include "GUI/BsGUILayout.h"
  8. #include "GUI/BsGUITexture.h"
  9. #include "GUI/BsGUIWindowFrame.h"
  10. #include "RenderAPI/BsRenderWindow.h"
  11. #include "Platform/BsPlatform.h"
  12. namespace bs
  13. {
  14. const UINT32 WindowFrameWidget::RESIZE_BORDER_WIDTH = 3;
  15. WindowFrameWidget::WindowFrameWidget(const HSceneObject& parent, bool allowResize, const SPtr<Camera>& camera, RenderWindow* parentWindow, const HGUISkin& skin)
  16. :CGUIWidget(parent, camera), mAllowResize(allowResize), mWindowFramePanel(nullptr), mParentWindow(parentWindow)
  17. {
  18. setSkin(skin);
  19. GUIPanel* backgroundPanel = getPanel()->addNewElement<GUIPanel>(500);
  20. backgroundPanel->addElement(GUITexture::create(TextureScaleMode::RepeatToFit,
  21. GUIOptions(GUIOption::flexibleWidth(), GUIOption::flexibleHeight()), "WindowBackground"));
  22. mWindowFramePanel = getPanel()->addNewElement<GUIPanel>(499);
  23. mWindowFrame = GUIWindowFrame::create("WindowFrame");
  24. mWindowFramePanel->addElement(mWindowFrame);
  25. refreshNonClientAreas();
  26. }
  27. void WindowFrameWidget::ownerWindowFocusChanged()
  28. {
  29. mWindowFrame->setFocused(mParentWindow->getProperties().hasFocus);
  30. CGUIWidget::ownerWindowFocusChanged();
  31. }
  32. void WindowFrameWidget::ownerTargetResized()
  33. {
  34. CGUIWidget::ownerTargetResized();
  35. refreshNonClientAreas();
  36. }
  37. void WindowFrameWidget::refreshNonClientAreas() const
  38. {
  39. if (!mAllowResize)
  40. return;
  41. INT32 x = 0;
  42. INT32 y = 0;
  43. UINT32 width = getTarget()->getPixelArea().width;
  44. UINT32 height = getTarget()->getPixelArea().height;
  45. Vector<NonClientResizeArea> nonClientAreas(8);
  46. nonClientAreas[0].type = NonClientAreaBorderType::TopLeft;
  47. nonClientAreas[0].area = Rect2I(x, y,
  48. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  49. nonClientAreas[1].type = NonClientAreaBorderType::Top;
  50. nonClientAreas[1].area = Rect2I(x + RESIZE_BORDER_WIDTH, y,
  51. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  52. nonClientAreas[2].type = NonClientAreaBorderType::TopRight;
  53. nonClientAreas[2].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y,
  54. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  55. nonClientAreas[3].type = NonClientAreaBorderType::Left;
  56. nonClientAreas[3].area = Rect2I(x, y + RESIZE_BORDER_WIDTH,
  57. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  58. nonClientAreas[4].type = NonClientAreaBorderType::Right;
  59. nonClientAreas[4].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y + RESIZE_BORDER_WIDTH,
  60. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  61. nonClientAreas[5].type = NonClientAreaBorderType::BottomLeft;
  62. nonClientAreas[5].area = Rect2I(x, y + height - RESIZE_BORDER_WIDTH,
  63. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  64. nonClientAreas[6].type = NonClientAreaBorderType::Bottom;
  65. nonClientAreas[6].area = Rect2I(x + RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  66. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  67. nonClientAreas[7].type = NonClientAreaBorderType::BottomRight;
  68. nonClientAreas[7].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  69. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  70. Platform::setResizeNonClientAreas(*mParentWindow->getCore(), nonClientAreas);
  71. }
  72. RTTITypeBase* WindowFrameWidget::getRTTIStatic()
  73. {
  74. return WindowFrameWidgetRTTI::instance();
  75. }
  76. RTTITypeBase* WindowFrameWidget::getRTTI() const
  77. {
  78. return WindowFrameWidget::getRTTIStatic();
  79. }
  80. }