2
0

BsGUIWindowFrameWidget.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "BsGUIWindowFrameWidget.h"
  2. #include "BsGUIPanel.h"
  3. #include "BsCGUIWidget.h"
  4. #include "BsGUILayout.h"
  5. #include "BsGUITexture.h"
  6. #include "BsGUIWindowFrame.h"
  7. #include "BsBuiltinResources.h"
  8. #include "BsGUIMouseEvent.h"
  9. #include "BsRenderWindow.h"
  10. #include "BsMath.h"
  11. #include "BsPlatform.h"
  12. namespace BansheeEngine
  13. {
  14. const UINT32 WindowFrameWidget::RESIZE_BORDER_WIDTH = 3;
  15. WindowFrameWidget::WindowFrameWidget(const HSceneObject& parent, bool allowResize, const CameraPtr& camera, RenderWindow* parentWindow, const HGUISkin& skin)
  16. :CGUIWidget(parent, camera), mWindowFramePanel(nullptr), mParentWindow(parentWindow), mAllowResize(allowResize)
  17. {
  18. setSkin(skin);
  19. GUIPanel* backgroundPanel = getPanel()->addNewElement<GUIPanel>(500);
  20. backgroundPanel->addElement(GUITexture::create(GUIImageScaleMode::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::update()
  31. {
  32. }
  33. bool WindowFrameWidget::_mouseEvent(GUIElement* element, const GUIMouseEvent& ev)
  34. {
  35. return CGUIWidget::_mouseEvent(element, ev);
  36. }
  37. void WindowFrameWidget::ownerWindowFocusChanged()
  38. {
  39. mWindowFrame->setFocused(mParentWindow->getProperties().hasFocus());
  40. CGUIWidget::ownerWindowFocusChanged();
  41. }
  42. void WindowFrameWidget::ownerTargetResized()
  43. {
  44. CGUIWidget::ownerTargetResized();
  45. refreshNonClientAreas();
  46. }
  47. void WindowFrameWidget::refreshNonClientAreas() const
  48. {
  49. if (!mAllowResize)
  50. return;
  51. Rect2I bounds = mWindowFramePanel->getBounds();
  52. INT32 x = bounds.x;
  53. INT32 y = bounds.y;
  54. UINT32 width = bounds.width;
  55. UINT32 height = bounds.height;
  56. Vector<NonClientResizeArea> nonClientAreas(8);
  57. nonClientAreas[0].type = NonClientAreaBorderType::TopLeft;
  58. nonClientAreas[0].area = Rect2I(x, y,
  59. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  60. nonClientAreas[1].type = NonClientAreaBorderType::Top;
  61. nonClientAreas[1].area = Rect2I(x + RESIZE_BORDER_WIDTH, y,
  62. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  63. nonClientAreas[2].type = NonClientAreaBorderType::TopRight;
  64. nonClientAreas[2].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y,
  65. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  66. nonClientAreas[3].type = NonClientAreaBorderType::Left;
  67. nonClientAreas[3].area = Rect2I(x, y + RESIZE_BORDER_WIDTH,
  68. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  69. nonClientAreas[4].type = NonClientAreaBorderType::Right;
  70. nonClientAreas[4].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y + RESIZE_BORDER_WIDTH,
  71. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  72. nonClientAreas[5].type = NonClientAreaBorderType::BottomLeft;
  73. nonClientAreas[5].area = Rect2I(x, y + height - RESIZE_BORDER_WIDTH,
  74. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  75. nonClientAreas[6].type = NonClientAreaBorderType::Bottom;
  76. nonClientAreas[6].area = Rect2I(x + RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  77. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  78. nonClientAreas[7].type = NonClientAreaBorderType::BottomRight;
  79. nonClientAreas[7].area = Rect2I(x + width - RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  80. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  81. Platform::setResizeNonClientAreas(*mParentWindow->getCore(), nonClientAreas);
  82. }
  83. }