3
0

EditorWhiteBoxComponentModeCommon.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #include "EditorWhiteBoxComponentModeCommon.h"
  9. #include <AzCore/Component/ComponentBus.h>
  10. #include <AzToolsFramework/ComponentMode/EditorComponentModeBus.h>
  11. #include <WhiteBox/EditorWhiteBoxComponentBus.h>
  12. #include <WhiteBox/WhiteBoxToolApi.h>
  13. namespace WhiteBox
  14. {
  15. using ComponentModeRequestBus = AzToolsFramework::ComponentModeFramework::ComponentModeRequestBus;
  16. void RecordWhiteBoxAction(
  17. WhiteBoxMesh& whiteBox, const AZ::EntityComponentIdPair entityComponentIdPair, const char* undoRedoDesc)
  18. {
  19. // update UVs
  20. Api::CalculatePlanarUVs(whiteBox);
  21. // record an undo step
  22. AzToolsFramework::ScopedUndoBatch undoBatch(undoRedoDesc);
  23. AzToolsFramework::ScopedUndoBatch::MarkEntityDirty(entityComponentIdPair.GetEntityId());
  24. // notify the component things have changed
  25. EditorWhiteBoxComponentRequestBus::Event(
  26. entityComponentIdPair, &EditorWhiteBoxComponentRequests::SerializeWhiteBox);
  27. // notify the white box mesh things have changed
  28. EditorWhiteBoxComponentNotificationBus::Event(
  29. entityComponentIdPair, &EditorWhiteBoxComponentNotifications::OnWhiteBoxMeshModified);
  30. // notify the component mode things have changed
  31. ComponentModeRequestBus::Event(entityComponentIdPair, &ComponentModeRequestBus::Events::Refresh);
  32. }
  33. bool InputFlipEdge(const AzToolsFramework::ViewportInteraction::MouseInteractionEvent& mouseInteraction)
  34. {
  35. return mouseInteraction.m_mouseInteraction.m_mouseButtons.Right() &&
  36. mouseInteraction.m_mouseEvent == AzToolsFramework::ViewportInteraction::MouseEvent::Down;
  37. }
  38. bool InputRestore(const AzToolsFramework::ViewportInteraction::MouseInteractionEvent& mouseInteraction)
  39. {
  40. return mouseInteraction.m_mouseInteraction.m_mouseButtons.Left() &&
  41. mouseInteraction.m_mouseEvent == AzToolsFramework::ViewportInteraction::MouseEvent::Down;
  42. }
  43. } // namespace WhiteBox