BsGUIWindowFrameWidget.cpp 3.6 KB

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