BsSceneViewHandler.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include "BsEditorPrerequisites.h"
  3. #include "BsVector2I.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Handles various operations specific to the scene view, like updating,
  8. * selecting and rendering handles, selecting objects, rendering scene grid, etc.
  9. *
  10. * @note Internal class.
  11. */
  12. class BS_ED_EXPORT SceneViewHandler
  13. {
  14. public:
  15. SceneViewHandler(EditorWidgetBase* parentWidget, const SPtr<CameraHandler>& camera);
  16. virtual ~SceneViewHandler();
  17. /**
  18. * @brief Called once per frame. Updates gizmos and the scene grid.
  19. */
  20. void update();
  21. /**
  22. * @brief Updates currently active handles and updates
  23. * handles and selection drawing.
  24. *
  25. * @param position Position of the pointer relative to the scene camera viewport.
  26. * @param delta Movement of the pointer since last frame.
  27. */
  28. void updateHandle(const Vector2I& position, const Vector2I& delta);
  29. /**
  30. * @brief Selects a handle under the pointer position.
  31. *
  32. * @param position Position of the pointer relative to the scene camera viewport.
  33. */
  34. void trySelectHandle(const Vector2I& position);
  35. /**
  36. * @brief Is any handle currently active.
  37. */
  38. bool isHandleActive() const;
  39. /**
  40. * @brief Deselects any currently active handles.
  41. */
  42. void clearHandleSelection();
  43. /**
  44. * @brief Attempts to select a scene object under the pointer position.
  45. *
  46. * @param position Position of the pointer relative to the scene camera viewport.
  47. * @param additive Should this selection add to the existing selection, or replace it.
  48. */
  49. void pickObject(const Vector2I& position, bool additive);
  50. protected:
  51. /**
  52. * @brief Triggered by the Renderer when rendering the specified viewport.
  53. *
  54. * @param viewport Viewport about to be rendered.
  55. * @param drawList Draw list we can use to queue our render commands in.
  56. */
  57. void render(const Viewport* viewport, DrawList& drawList);
  58. /**
  59. * @brief Checks is the pointer currently within the provided window, and if it is not
  60. * the cursor is wrapped in such a way so that it is returned to within the window bounds.
  61. *
  62. * @return How far was the cursor moved due to wrapping. This will be (0, 0) if the cursor is within
  63. * window bounds initially.
  64. */
  65. Vector2I wrapCursorToWindow();
  66. private:
  67. EditorWidgetBase* mParentWidget;
  68. SPtr<CameraHandler> mCamera;
  69. SceneGrid* mSceneGrid;
  70. SelectionRenderer* mSelectionRenderer;
  71. HEvent mRenderCallback;
  72. Vector2I mMouseDeltaCompensate;
  73. };
  74. }