BsGUIWindowFrameWidget.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "BsGUIWindowFrameWidget.h"
  2. #include "BsGUIArea.h"
  3. #include "BsGUILayout.h"
  4. #include "BsGUITexture.h"
  5. #include "BsGUIWindowFrame.h"
  6. #include "BsEngineGUI.h"
  7. #include "BsGUIMouseEvent.h"
  8. #include "CmRenderWindow.h"
  9. #include "CmMath.h"
  10. #include "CmPlatform.h"
  11. using namespace CamelotFramework;
  12. using namespace BansheeEngine;
  13. namespace BansheeEditor
  14. {
  15. const UINT32 WindowFrameWidget::RESIZE_BORDER_WIDTH = 3;
  16. WindowFrameWidget::WindowFrameWidget(const HSceneObject& parent)
  17. :GUIWidget(parent), mWindowFrameArea(nullptr)
  18. {
  19. }
  20. WindowFrameWidget::~WindowFrameWidget()
  21. {
  22. }
  23. void WindowFrameWidget::initialize(CM::Viewport* target, CM::RenderWindow* ownerWindow)
  24. {
  25. GUIWidget::initialize(target, ownerWindow);
  26. GUIArea* backgroundArea = GUIArea::createStretchedXY(*this, 0, 0, 0, 0, 500);
  27. backgroundArea->getLayout().addElement(GUITexture::create(*this, GUILayoutOptions::expandableXY(), GUIImageScaleMode::RepeatToFit, getSkin().getStyle("WindowBackground")));
  28. mWindowFrameArea = GUIArea::createStretchedXY(*this, 0, 0, 0, 0, 499);
  29. mWindowFrame = GUIWindowFrame::create(*this, getSkin().getStyle("WindowFrame"));
  30. mWindowFrameArea->getLayout().addElement(mWindowFrame);
  31. refreshNonClientAreas();
  32. }
  33. void WindowFrameWidget::update()
  34. {
  35. }
  36. bool WindowFrameWidget::_mouseEvent(GUIElement* element, const GUIMouseEvent& ev)
  37. {
  38. return GUIWidget::_mouseEvent(element, ev);
  39. }
  40. void WindowFrameWidget::ownerWindowFocusChanged()
  41. {
  42. mWindowFrame->setFocused(getOwnerWindow()->hasFocus());
  43. GUIWidget::ownerWindowFocusChanged();
  44. }
  45. void WindowFrameWidget::ownerWindowResized()
  46. {
  47. GUIWidget::ownerWindowResized();
  48. refreshNonClientAreas();
  49. }
  50. void WindowFrameWidget::refreshNonClientAreas() const
  51. {
  52. INT32 x = mWindowFrameArea->x();
  53. INT32 y = mWindowFrameArea->y();
  54. UINT32 width = mWindowFrameArea->width();
  55. UINT32 height = mWindowFrameArea->height();
  56. CM::Vector<NonClientResizeArea>::type nonClientAreas(8);
  57. nonClientAreas[0].type = NonClientAreaBorderType::TopLeft;
  58. nonClientAreas[0].area = Rect(x, y,
  59. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  60. nonClientAreas[1].type = NonClientAreaBorderType::Top;
  61. nonClientAreas[1].area = Rect(x + RESIZE_BORDER_WIDTH, y,
  62. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  63. nonClientAreas[2].type = NonClientAreaBorderType::TopRight;
  64. nonClientAreas[2].area = Rect(x + width - RESIZE_BORDER_WIDTH, y,
  65. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  66. nonClientAreas[3].type = NonClientAreaBorderType::Left;
  67. nonClientAreas[3].area = Rect(x, y + RESIZE_BORDER_WIDTH,
  68. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  69. nonClientAreas[4].type = NonClientAreaBorderType::Right;
  70. nonClientAreas[4].area = Rect(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 = Rect(x, y + height - RESIZE_BORDER_WIDTH,
  74. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  75. nonClientAreas[6].type = NonClientAreaBorderType::Bottom;
  76. nonClientAreas[6].area = Rect(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 = Rect(x + width - RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  80. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  81. Platform::setResizeNonClientAreas(*getOwnerWindow(), nonClientAreas);
  82. }
  83. }