BsHandleManager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. */
  31. void updateInput(const SPtr<Camera>& camera, const Vector2I& inputPos, const Vector2I& inputDelta);
  32. /**
  33. * Triggers handle post-input callbacks. Must be called after all updateInput() calls and after beginInput().
  34. * This should be called once per frame.
  35. */
  36. void endInput();
  37. /**
  38. * To be called every frame. Queues handles for drawing.
  39. *
  40. * @param[in] camera Camera to draw the handles to.
  41. */
  42. void draw(const SPtr<Camera>& camera);
  43. /**
  44. * Select a handle slider at the specified location, if there is any under the pointer. Makes the selected slider
  45. * active and draggable.
  46. *
  47. * @param[in] camera Camera that the input positions are relative to, and destination to draw the handles to.
  48. * @param[in] inputPos Position of the pointer, relative to the provided camera viewport.
  49. */
  50. void trySelect(const SPtr<Camera>& camera, const Vector2I& inputPos);
  51. /** Clears the currently selected/active handle slider for the specified camera. */
  52. void clearSelection(const SPtr<Camera>& camera);
  53. /** Is any handle slider selected/active on the specified camera. */
  54. bool isHandleActive(const SPtr<Camera>& camera) const;
  55. /** Returns the manager that can be used for interacting with handle sliders. */
  56. HandleSliderManager& getSliderManager() const { return *mSliderManager; }
  57. /** Returns the manager that can be used for drawing handle geometry. */
  58. HandleDrawManager& getDrawManager() const { return *mDrawManager; }
  59. /**
  60. * Returns the uniform size for a handle rendered in @p camera, at the world position @p handlePos. The handles
  61. * will be scaled so that they appear the same size regardless of distance from camera.
  62. */
  63. float getHandleSize(const SPtr<Camera>& camera, const Vector3& handlePos) const;
  64. /** Sets the default handle size. This controls the uniform scale returned from getHandleSize() method. */
  65. void setDefaultHandleSize(float value) { mDefaultHandleSize = value; }
  66. /** Sets editor settings that will be used for controlling various handle behaviour. */
  67. void setSettings(const SPtr<EditorSettings>& settings);
  68. protected:
  69. /** Updates the internal properties from editor settings. */
  70. void updateFromEditorSettings();
  71. /** Called during handle update. Allows handle sliders to be created or destroyed before any input is handled. */
  72. virtual void triggerPreInput() = 0;
  73. /**
  74. * Called during handle update after handle input is processed. Allows implementation to respond to delta values
  75. * calculated in sliders due to input.
  76. */
  77. virtual void triggerPostInput() = 0;
  78. /** Called during handle update. Allows implementation to queue handle draw commands. */
  79. virtual void queueDrawCommands() = 0;
  80. HandleSliderManager* mSliderManager;
  81. HandleDrawManager* mDrawManager;
  82. float mDefaultHandleSize = 20.0f;
  83. bool mInputStarted;
  84. SPtr<EditorSettings> mSettings;
  85. UINT32 mSettingsHash;
  86. UINT64 mLastDrawFrameIdx;
  87. };
  88. /** @} */
  89. }