BsHandleManager.h 4.1 KB

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