2
0

BsGUIWindowFrameWidget.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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* ownerWindow, const GUISkin& skin)
  17. :GUIWidget(parent, target, ownerWindow), mWindowFrameArea(nullptr)
  18. {
  19. setSkin(skin);
  20. GUIArea* backgroundArea = GUIArea::createStretchedXY(*this, 0, 0, 0, 0, 500);
  21. backgroundArea->getLayout().addElement(GUITexture::create(*this, GUILayoutOptions::expandableXY(), GUIImageScaleMode::RepeatToFit, getSkin().getStyle("WindowBackground")));
  22. mWindowFrameArea = GUIArea::createStretchedXY(*this, 0, 0, 0, 0, 499);
  23. mWindowFrame = GUIWindowFrame::create(*this, getSkin().getStyle("WindowFrame"));
  24. mWindowFrameArea->getLayout().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 GUIWidget::_mouseEvent(element, ev);
  36. }
  37. void WindowFrameWidget::ownerWindowFocusChanged()
  38. {
  39. mWindowFrame->setFocused(getOwnerWindow()->hasFocus());
  40. GUIWidget::ownerWindowFocusChanged();
  41. }
  42. void WindowFrameWidget::ownerWindowResized()
  43. {
  44. GUIWidget::ownerWindowResized();
  45. refreshNonClientAreas();
  46. }
  47. void WindowFrameWidget::refreshNonClientAreas() const
  48. {
  49. INT32 x = mWindowFrameArea->x();
  50. INT32 y = mWindowFrameArea->y();
  51. UINT32 width = mWindowFrameArea->width();
  52. UINT32 height = mWindowFrameArea->height();
  53. CM::Vector<NonClientResizeArea>::type nonClientAreas(8);
  54. nonClientAreas[0].type = NonClientAreaBorderType::TopLeft;
  55. nonClientAreas[0].area = Rect(x, y,
  56. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  57. nonClientAreas[1].type = NonClientAreaBorderType::Top;
  58. nonClientAreas[1].area = Rect(x + RESIZE_BORDER_WIDTH, y,
  59. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  60. nonClientAreas[2].type = NonClientAreaBorderType::TopRight;
  61. nonClientAreas[2].area = Rect(x + width - RESIZE_BORDER_WIDTH, y,
  62. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  63. nonClientAreas[3].type = NonClientAreaBorderType::Left;
  64. nonClientAreas[3].area = Rect(x, y + RESIZE_BORDER_WIDTH,
  65. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  66. nonClientAreas[4].type = NonClientAreaBorderType::Right;
  67. nonClientAreas[4].area = Rect(x + width - RESIZE_BORDER_WIDTH, y + RESIZE_BORDER_WIDTH,
  68. RESIZE_BORDER_WIDTH, height - 2 * RESIZE_BORDER_WIDTH);
  69. nonClientAreas[5].type = NonClientAreaBorderType::BottomLeft;
  70. nonClientAreas[5].area = Rect(x, y + height - RESIZE_BORDER_WIDTH,
  71. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  72. nonClientAreas[6].type = NonClientAreaBorderType::Bottom;
  73. nonClientAreas[6].area = Rect(x + RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  74. width - 2 * RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  75. nonClientAreas[7].type = NonClientAreaBorderType::BottomRight;
  76. nonClientAreas[7].area = Rect(x + width - RESIZE_BORDER_WIDTH, y + height - RESIZE_BORDER_WIDTH,
  77. RESIZE_BORDER_WIDTH, RESIZE_BORDER_WIDTH);
  78. Platform::setResizeNonClientAreas(*getOwnerWindow(), nonClientAreas);
  79. }
  80. }