BsGUIWindowMover.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include "BsGUIWindowMover.h"
  2. #include "CmApplication.h"
  3. #include "CmTexture.h"
  4. #include "BsGUIWidget.h"
  5. #include "BsGUISkin.h"
  6. #include "BsSpriteTexture.h"
  7. #include "BsGUILayoutOptions.h"
  8. #include "BsGUIMouseEvent.h"
  9. using namespace CamelotFramework;
  10. namespace BansheeEngine
  11. {
  12. const String& GUIWindowMover::getGUITypeName()
  13. {
  14. static String name = "WindowMover";
  15. return name;
  16. }
  17. GUIWindowMover::GUIWindowMover(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
  18. :GUIElement(parent, style, layoutOptions)
  19. {
  20. mImageSprite = cm_new<ImageSprite, PoolAlloc>();
  21. mDesc.texture = mStyle->normal.texture;
  22. if(mDesc.texture != nullptr)
  23. {
  24. mDesc.width = mDesc.texture->getTexture()->getWidth();
  25. mDesc.height = mDesc.texture->getTexture()->getHeight();
  26. }
  27. mDesc.borderLeft = mStyle->border.left;
  28. mDesc.borderRight = mStyle->border.right;
  29. mDesc.borderTop = mStyle->border.top;
  30. mDesc.borderBottom = mStyle->border.bottom;
  31. }
  32. GUIWindowMover::~GUIWindowMover()
  33. {
  34. cm_delete<PoolAlloc>(mImageSprite);
  35. }
  36. GUIWindowMover* GUIWindowMover::create(GUIWidget& parent, const GUIElementStyle* style)
  37. {
  38. if(style == nullptr)
  39. {
  40. const GUISkin* skin = parent.getSkin();
  41. style = skin->getStyle(getGUITypeName());
  42. }
  43. return new (cm_alloc<GUIWindowMover, PoolAlloc>()) GUIWindowMover(parent, style, getDefaultLayoutOptions(style));
  44. }
  45. GUIWindowMover* GUIWindowMover::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style)
  46. {
  47. if(style == nullptr)
  48. {
  49. const GUISkin* skin = parent.getSkin();
  50. style = skin->getStyle(getGUITypeName());
  51. }
  52. return new (cm_alloc<GUIWindowMover, PoolAlloc>()) GUIWindowMover(parent, style, layoutOptions);
  53. }
  54. UINT32 GUIWindowMover::getNumRenderElements() const
  55. {
  56. return mImageSprite->getNumRenderElements();
  57. }
  58. const HMaterial& GUIWindowMover::getMaterial(UINT32 renderElementIdx) const
  59. {
  60. return mImageSprite->getMaterial(renderElementIdx);
  61. }
  62. UINT32 GUIWindowMover::getNumQuads(UINT32 renderElementIdx) const
  63. {
  64. return mImageSprite->getNumQuads(renderElementIdx);
  65. }
  66. void GUIWindowMover::updateRenderElementsInternal()
  67. {
  68. mDesc.width = mWidth;
  69. mDesc.height = mHeight;
  70. mImageSprite->update(mDesc);
  71. GUIElement::updateRenderElementsInternal();
  72. }
  73. void GUIWindowMover::updateBounds()
  74. {
  75. mBounds = mImageSprite->getBounds(mOffset, mClipRect);
  76. }
  77. UINT32 GUIWindowMover::_getOptimalWidth() const
  78. {
  79. if(mDesc.texture != nullptr)
  80. {
  81. return mDesc.texture->getTexture()->getWidth();
  82. }
  83. return 0;
  84. }
  85. UINT32 GUIWindowMover::_getOptimalHeight() const
  86. {
  87. if(mDesc.texture != nullptr)
  88. {
  89. return mDesc.texture->getTexture()->getHeight();
  90. }
  91. return 0;
  92. }
  93. void GUIWindowMover::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads,
  94. UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const
  95. {
  96. mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx, mOffset, mClipRect);
  97. }
  98. void GUIWindowMover::setFocused(bool focused)
  99. {
  100. if(focused)
  101. mDesc.texture = mStyle->focused.texture;
  102. else
  103. mDesc.texture = mStyle->normal.texture;
  104. markContentAsDirty();
  105. }
  106. bool GUIWindowMover::mouseEvent(const GUIMouseEvent& ev)
  107. {
  108. if(ev.getType() == GUIMouseEventType::MouseDown)
  109. {
  110. RenderWindow* window = _getParentWidget().getOwnerWindow();
  111. RenderWindowPtr windowPtr = std::static_pointer_cast<RenderWindow>(window->getThisPtr());
  112. gMainCA().startMove(windowPtr);
  113. return true;
  114. }
  115. return false;
  116. }
  117. }