BsGUIWindowFrameWidget.cpp 3.6 KB

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