BsGUIWindowFrameWidget.cpp 3.5 KB

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