BsGUIWindowFrameWidget.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. WindowFrameWidget::~WindowFrameWidget()
  28. {
  29. }
  30. void WindowFrameWidget::ownerWindowFocusChanged()
  31. {
  32. mWindowFrame->setFocused(mParentWindow->getProperties().hasFocus);
  33. CGUIWidget::ownerWindowFocusChanged();
  34. }
  35. void WindowFrameWidget::ownerTargetResized()
  36. {
  37. CGUIWidget::ownerTargetResized();
  38. refreshNonClientAreas();
  39. }
  40. void WindowFrameWidget::refreshNonClientAreas() const
  41. {
  42. if (!mAllowResize)
  43. return;
  44. INT32 x = 0;
  45. INT32 y = 0;
  46. UINT32 width = getTarget()->getPixelArea().width;
  47. UINT32 height = getTarget()->getPixelArea().height;
  48. Vector<NonClientResizeArea> nonClientAreas(8);
  49. nonClientAreas[0].type = NonClientAreaBorderType::TopLeft;
  50. nonClientAreas[0].area = Rect2I(x, y,
  51. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  52. nonClientAreas[1].type = NonClientAreaBorderType::Top;
  53. nonClientAreas[1].area = Rect2I(x + RESIZE_BORDER_WIDTH, y,
  54. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  55. nonClientAreas[2].type = NonClientAreaBorderType::TopRight;
  56. nonClientAreas[2].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y,
  57. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  58. nonClientAreas[3].type = NonClientAreaBorderType::Left;
  59. nonClientAreas[3].area = Rect2I(x, y + RESIZE_BORDER_WIDTH,
  60. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  61. nonClientAreas[4].type = NonClientAreaBorderType::Right;
  62. nonClientAreas[4].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y + RESIZE_BORDER_WIDTH,
  63. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  64. nonClientAreas[5].type = NonClientAreaBorderType::BottomLeft;
  65. nonClientAreas[5].area = Rect2I(x, y + height - RESIZE_BORDER_WIDTH,
  66. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  67. nonClientAreas[6].type = NonClientAreaBorderType::Bottom;
  68. nonClientAreas[6].area = Rect2I(x + RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  69. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  70. nonClientAreas[7].type = NonClientAreaBorderType::BottomRight;
  71. nonClientAreas[7].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  72. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  73. Platform::setResizeNonClientAreas(*mParentWindow->getCore(), nonClientAreas);
  74. }
  75. RTTITypeBase* WindowFrameWidget::getRTTIStatic()
  76. {
  77. return WindowFrameWidgetRTTI::instance();
  78. }
  79. RTTITypeBase* WindowFrameWidget::getRTTI() const
  80. {
  81. return WindowFrameWidget::getRTTIStatic();
  82. }
  83. }