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 "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, CM::Viewport* target, CM::RenderWindow* parentWindow, const GUISkin& skin)
  17. :GUIWidget(parent, target), mWindowFrameArea(nullptr), mParentWindow(parentWindow)
  18. {
  19. setSkin(skin);
  20. GUIArea* backgroundArea = GUIArea::createStretchedXY(*this, 0, 0, 0, 0, 500);
  21. backgroundArea->getLayout().addElement(GUITexture::create(*this, GUIImageScaleMode::RepeatToFit,
  22. GUIOptions(GUIOption::flexibleWidth(), GUIOption::flexibleHeight()), getSkin().getStyle("WindowBackground")));
  23. mWindowFrameArea = GUIArea::createStretchedXY(*this, 0, 0, 0, 0, 499);
  24. mWindowFrame = GUIWindowFrame::create(*this, getSkin().getStyle("WindowFrame"));
  25. mWindowFrameArea->getLayout().addElement(mWindowFrame);
  26. refreshNonClientAreas();
  27. }
  28. WindowFrameWidget::~WindowFrameWidget()
  29. {
  30. }
  31. void WindowFrameWidget::update()
  32. {
  33. }
  34. bool WindowFrameWidget::_mouseEvent(GUIElement* element, const GUIMouseEvent& ev)
  35. {
  36. return GUIWidget::_mouseEvent(element, ev);
  37. }
  38. void WindowFrameWidget::ownerWindowFocusChanged()
  39. {
  40. mWindowFrame->setFocused(mParentWindow->hasFocus());
  41. GUIWidget::ownerWindowFocusChanged();
  42. }
  43. void WindowFrameWidget::ownerTargetResized()
  44. {
  45. GUIWidget::ownerTargetResized();
  46. refreshNonClientAreas();
  47. }
  48. void WindowFrameWidget::refreshNonClientAreas() const
  49. {
  50. INT32 x = mWindowFrameArea->x();
  51. INT32 y = mWindowFrameArea->y();
  52. UINT32 width = mWindowFrameArea->width();
  53. UINT32 height = mWindowFrameArea->height();
  54. CM::Vector<NonClientResizeArea>::type nonClientAreas(8);
  55. nonClientAreas[0].type = NonClientAreaBorderType::TopLeft;
  56. nonClientAreas[0].area = RectI(x, y,
  57. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  58. nonClientAreas[1].type = NonClientAreaBorderType::Top;
  59. nonClientAreas[1].area = RectI(x + RESIZE_BORDER_WIDTH, y,
  60. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  61. nonClientAreas[2].type = NonClientAreaBorderType::TopRight;
  62. nonClientAreas[2].area = RectI(x + width - RESIZE_BORDER_WIDTH, y,
  63. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  64. nonClientAreas[3].type = NonClientAreaBorderType::Left;
  65. nonClientAreas[3].area = RectI(x, y + RESIZE_BORDER_WIDTH,
  66. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  67. nonClientAreas[4].type = NonClientAreaBorderType::Right;
  68. nonClientAreas[4].area = RectI(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 = RectI(x, y + height - RESIZE_BORDER_WIDTH,
  72. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  73. nonClientAreas[6].type = NonClientAreaBorderType::Bottom;
  74. nonClientAreas[6].area = RectI(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 = RectI(x + width - RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  78. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  79. Platform::setResizeNonClientAreas(*mParentWindow, nonClientAreas);
  80. }
  81. }