BsHandleSliderManager.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsEditorPrerequisites.h"
  5. namespace bs
  6. {
  7. /** @addtogroup Handles-Internal
  8. * @{
  9. */
  10. /** Controls all instantiated HandleSlider%s. */
  11. class BS_ED_EXPORT HandleSliderManager
  12. {
  13. /** Contains active/hover sliders for each camera. */
  14. struct StatePerCamera
  15. {
  16. HandleSlider* activeSlider = nullptr;
  17. HandleSlider* hoverSlider = nullptr;
  18. };
  19. public:
  20. /**
  21. * Updates all underlying sliders, changing their state and dragging them depending on their state and pointer
  22. * movement.
  23. *
  24. * @param[in] camera Camera through which we're interacting with sliders.
  25. * @param[in] inputPos Position of the pointer.
  26. * @param[in] inputDelta Movement of the pointer since last frame.
  27. * @return True if slider state changed, false otherwise.
  28. */
  29. bool update(const SPtr<Camera>& camera, const Vector2I& inputPos, const Vector2I& inputDelta);
  30. /**
  31. * Attempts to select (activate) a slider at the specified position.
  32. *
  33. * @param[in] camera Camera through which we're interacting with sliders.
  34. * @param[in] inputPos Position of the pointer.
  35. * @return True if handle slider state changed, false otherwise.
  36. */
  37. bool trySelect(const SPtr<Camera>& camera, const Vector2I& inputPos);
  38. /** Clears the active slider (deactivates it) for the specified camera. */
  39. void clearSelection(const SPtr<Camera>& camera);
  40. /** Checks is any slider active for the specified camera. */
  41. bool isSliderActive(const SPtr<Camera>& camera) const;
  42. /** Registers a new instantiated slider. */
  43. void _registerSlider(HandleSlider* slider);
  44. /** Unregisters a previously instantiated slider. */
  45. void _unregisterSlider(HandleSlider* slider);
  46. private:
  47. /**
  48. * Attempts to find slider at the specified position.
  49. *
  50. * @param[in] camera Camera through which we're interacting with sliders.
  51. * @param[in] inputPos Position of the pointer.
  52. * @return Slider if we're intersecting with one, or null otherwise.
  53. */
  54. HandleSlider* findUnderCursor(const SPtr<Camera>& camera, const Vector2I& inputPos) const;
  55. UnorderedMap<UINT64, StatePerCamera> mStates;
  56. UnorderedSet<HandleSlider*> mSliders;
  57. };
  58. /** @} */
  59. }