BsHandleManager.h 3.5 KB

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