AzManipulatorTestFrameworkTestFixtures.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzManipulatorTestFramework/AzManipulatorTestFrameworkUtils.h>
  10. #include <AzTest/AzTest.h>
  11. #include <AzToolsFramework/UnitTest/AzToolsFrameworkTestHelpers.h>
  12. namespace UnitTest
  13. {
  14. class LinearManipulatorTestFixture : public ToolsApplicationFixture<>
  15. {
  16. protected:
  17. LinearManipulatorTestFixture(const AzToolsFramework::ManipulatorManagerId& manipulatorManagerId)
  18. : m_manipulatorManagerId(manipulatorManagerId)
  19. {
  20. }
  21. void SetUpEditorFixtureImpl() override
  22. {
  23. m_linearManipulator = AzManipulatorTestFramework::CreateLinearManipulator(
  24. m_manipulatorManagerId,
  25. /*position=*/AZ::Vector3::CreateZero(),
  26. /*radius=*/1.0f);
  27. // default sanity check call backs
  28. m_linearManipulator->InstallLeftMouseDownCallback(
  29. [this](const AzToolsFramework::LinearManipulator::Action& /*action*/)
  30. {
  31. m_receivedLeftMouseDown = true;
  32. });
  33. m_linearManipulator->InstallMouseMoveCallback(
  34. [this](const AzToolsFramework::LinearManipulator::Action& /*action*/)
  35. {
  36. m_receivedMouseMove = true;
  37. });
  38. m_linearManipulator->InstallLeftMouseUpCallback(
  39. [this](const AzToolsFramework::LinearManipulator::Action& /*action*/)
  40. {
  41. m_receivedLeftMouseUp = true;
  42. });
  43. }
  44. void TearDownEditorFixtureImpl() override
  45. {
  46. m_linearManipulator->Unregister();
  47. m_linearManipulator.reset();
  48. }
  49. const AzToolsFramework::ManipulatorManagerId m_manipulatorManagerId;
  50. AZStd::shared_ptr<AzToolsFramework::LinearManipulator> m_linearManipulator;
  51. // sanity flags for manipulator mouse callbacks
  52. bool m_receivedLeftMouseDown = false;
  53. bool m_receivedMouseMove = false;
  54. bool m_receivedLeftMouseUp = false;
  55. // initial world space starting position for mouse interaction
  56. const AzToolsFramework::ViewportInteraction::MousePick m_mouseStartingPositionRay{ AZ::Vector3(0.0f, -2.0f, 0.0f),
  57. AZ::Vector3(0.0f, 1.0f, 0.0f),
  58. AzFramework::ScreenPoint(0, 0) };
  59. // left mouse down ray in world space 2 units back from origin looking down +y axis with a null interaction
  60. // id and no keyboard modifiers
  61. AzToolsFramework::ViewportInteraction::MouseInteraction m_interaction =
  62. AzToolsFramework::ViewportInteraction::BuildMouseInteraction(
  63. m_mouseStartingPositionRay,
  64. AzToolsFramework::ViewportInteraction::BuildMouseButtons(AzToolsFramework::ViewportInteraction::MouseButton::Left),
  65. AzToolsFramework::ViewportInteraction::InteractionId(AZ::EntityId(0), 0),
  66. AzToolsFramework::ViewportInteraction::KeyboardModifiers(0));
  67. };
  68. } // namespace UnitTest