BsHandleSlider2D.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2018 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. #include "Handles/BsHandleSlider.h"
  6. #include "Math/BsVector2.h"
  7. namespace bs
  8. {
  9. /** @addtogroup Handles
  10. * @{
  11. */
  12. /** Constraint that determines in which direction can a HandleSlider2D be moved. */
  13. enum class Slider2DConstraint
  14. {
  15. None, /**< Slider can be moved in both dimensions. */
  16. Horizontal, /**< Slider can only be moved horizontally. */
  17. Vertical /**< Slider can only be moved vertically. */
  18. };
  19. /**
  20. * Handle slider that is positioned in screen-space, and reports 2D movement in screen space (in pixels). When setting
  21. * the position the Z coordinate will be ignored, and XY coordinates will be interpreted as pixels relative to the
  22. * camera its viewed through.
  23. */
  24. class BS_ED_EXPORT HandleSlider2D : public HandleSlider
  25. {
  26. public:
  27. /**
  28. * Constructs a new 2D slider.
  29. *
  30. * @param[in] width Width of the area of the slider that can be interacted with, in pixels.
  31. * @param[in] height Height of the area of the slider that can be interacted with, in pixels.
  32. * @param[in] layer Layer that allows filtering of which sliders are interacted with from a specific camera.
  33. * @param[in] constraint Optional constraint that determines in which direction is the slider allowed to be
  34. * moved in.
  35. */
  36. HandleSlider2D(UINT32 width, UINT32 height, UINT64 layer, Slider2DConstraint constraint = Slider2DConstraint::None);
  37. ~HandleSlider2D();
  38. /** @copydoc HandleSlider::intersects */
  39. bool intersects(const Vector2I& screenPos, const Ray& ray, float& t) const override;
  40. /** @copydoc HandleSlider::handleInput */
  41. void handleInput(const SPtr<Camera>& camera, const Vector2I& inputDelta) override;
  42. /**
  43. * Returns a delta value that is the result of dragging/sliding the pointer. This changes every frame and will be
  44. * zero unless the slider is active. The value is in screen space (pixels).
  45. */
  46. Vector2I getDelta() const { return mDelta; }
  47. protected:
  48. /** @copydoc HandleSlider::activate */
  49. void activate(const SPtr<Camera>& camera, const Vector2I& pointerPos) override;
  50. /** @copydoc HandleSlider::reset */
  51. void reset() override { mDelta = Vector2I::ZERO; }
  52. UINT32 mWidth, mHeight;
  53. Slider2DConstraint mConstraint;
  54. Vector2I mDelta;
  55. Vector2I mStartPosition;
  56. };
  57. /** @} */
  58. }