BsHandleManager.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsModule.h"
  4. #include "BsDegree.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief The central place for interacting with and drawing handles.
  9. */
  10. class BS_ED_EXPORT HandleManager : public Module<HandleManager>
  11. {
  12. public:
  13. HandleManager();
  14. virtual ~HandleManager();
  15. /**
  16. * @brief To be called every frame. Updates interactable handle sliders based on provided input
  17. * and queues handles for drawing.
  18. *
  19. * @param camera Camera that the input positions are relative to, and destination to draw the handles to.
  20. * @param inputPos Position of the pointer, relative to the provided camera viewport.
  21. * @param inputDelta Determines pointer movement since last call to this method.
  22. */
  23. void update(const CameraPtr& camera, const Vector2I& inputPos, const Vector2I& inputDelta);
  24. /**
  25. * @brief Select a handle slider at the specified location, if there is any under the pointer. Makes
  26. * the selected slider active and draggable.
  27. *
  28. * @param camera Camera that the input positions are relative to, and destination to draw the handles to.
  29. * @param inputPos Position of the pointer, relative to the provided camera viewport.
  30. */
  31. void trySelect(const CameraPtr& camera, const Vector2I& inputPos);
  32. /**
  33. * @brief Clears the currently selected/active handle slider.
  34. */
  35. void clearSelection();
  36. /**
  37. * @brief Is any handle slider selected/active.
  38. */
  39. bool isHandleActive() const;
  40. /**
  41. * @brief Returns the manager that can be used for interacting with handle sliders.
  42. */
  43. HandleSliderManager& getSliderManager() const { return *mSliderManager; }
  44. /**
  45. * @brief Returns the manager that can be used for drawing handle geometry.
  46. */
  47. HandleDrawManager& getDrawManager() const { return *mDrawManager; }
  48. /**
  49. * @brief Returns the uniform size for a handle rendered in @p camera, at the world
  50. * position @p handlePos. The handles will be scaled so that they appear
  51. * the same size regardless of distance from camera.
  52. */
  53. float getHandleSize(const CameraPtr& camera, const Vector3& handlePos) const;
  54. /**
  55. * @brief Sets the default handle size. This controls the uniform scale returned from
  56. * ::getHandleSize method.
  57. */
  58. void setDefaultHandleSize(float value) { mDefaultHandleSize = value; }
  59. /**
  60. * @brief Sets editor settings that will be used for controlling various
  61. * handle behaviour.
  62. */
  63. void setSettings(const EditorSettingsPtr& settings);
  64. protected:
  65. /**
  66. * @brief Updates the internal properties from editor settings.
  67. */
  68. void updateFromEditorSettings();
  69. /**
  70. * @brief Called during handle update. Allows handle sliders to be created or
  71. * destroyed before any input is handled.
  72. */
  73. virtual void refreshHandles() = 0;
  74. /**
  75. * @brief Called during handle update after handle input is processed.
  76. * Allows implementation to respond to delta values calculated in sliders
  77. * due to input.
  78. */
  79. virtual void triggerHandles() = 0;
  80. /**
  81. * @brief Called during handle update. Allows implementation to
  82. * queue handle draw commands.
  83. */
  84. virtual void queueDrawCommands() = 0;
  85. HandleSliderManager* mSliderManager;
  86. HandleDrawManager* mDrawManager;
  87. float mDefaultHandleSize = 20.0f;
  88. EditorSettingsPtr mSettings;
  89. UINT32 mSettingsHash;
  90. };
  91. }