BsHandleManager.h 3.9 KB

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