BsGUIWindowFrameWidget.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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, Viewport* target, RenderWindow* parentWindow, const GUISkin& skin)
  15. :GUIWidget(parent, target), mWindowFrameArea(nullptr), mParentWindow(parentWindow)
  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. INT32 x = mWindowFrameArea->x();
  49. INT32 y = mWindowFrameArea->y();
  50. UINT32 width = mWindowFrameArea->width();
  51. UINT32 height = mWindowFrameArea->height();
  52. Vector<NonClientResizeArea> nonClientAreas(8);
  53. nonClientAreas[0].type = NonClientAreaBorderType::TopLeft;
  54. nonClientAreas[0].area = RectI(x, y,
  55. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  56. nonClientAreas[1].type = NonClientAreaBorderType::Top;
  57. nonClientAreas[1].area = RectI(x + RESIZE_BORDER_WIDTH, y,
  58. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  59. nonClientAreas[2].type = NonClientAreaBorderType::TopRight;
  60. nonClientAreas[2].area = RectI(x + width - RESIZE_BORDER_WIDTH, y,
  61. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  62. nonClientAreas[3].type = NonClientAreaBorderType::Left;
  63. nonClientAreas[3].area = RectI(x, y + RESIZE_BORDER_WIDTH,
  64. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  65. nonClientAreas[4].type = NonClientAreaBorderType::Right;
  66. nonClientAreas[4].area = RectI(x + width - RESIZE_BORDER_WIDTH, y + RESIZE_BORDER_WIDTH,
  67. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  68. nonClientAreas[5].type = NonClientAreaBorderType::BottomLeft;
  69. nonClientAreas[5].area = RectI(x, y + height - RESIZE_BORDER_WIDTH,
  70. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  71. nonClientAreas[6].type = NonClientAreaBorderType::Bottom;
  72. nonClientAreas[6].area = RectI(x + RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  73. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  74. nonClientAreas[7].type = NonClientAreaBorderType::BottomRight;
  75. nonClientAreas[7].area = RectI(x + width - RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  76. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  77. Platform::setResizeNonClientAreas(*mParentWindow, nonClientAreas);
  78. }
  79. }