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