BsHandleManager.h 4.3 KB

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