You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.9 KiB
C++
79 lines
2.9 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
#pragma once
|
|
|
|
#include "ViewportDragInteraction.h"
|
|
#include "ViewportInteraction.h"
|
|
|
|
#include <LyShine/Bus/UiTransform2dBus.h>
|
|
|
|
//! Class used while a move interaction is in progress in move or anchor mode
|
|
class ViewportMoveInteraction
|
|
: public ViewportDragInteraction
|
|
{
|
|
public:
|
|
|
|
ViewportMoveInteraction(
|
|
HierarchyWidget* hierarchy,
|
|
const QTreeWidgetItemRawPtrQList& selectedItems,
|
|
AZ::EntityId canvasId,
|
|
AZ::Entity* activeElement,
|
|
ViewportInteraction::CoordinateSystem coordinateSystem,
|
|
ViewportHelpers::GizmoParts grabbedGizmoParts,
|
|
ViewportInteraction::InteractionMode interactionMode,
|
|
ViewportInteraction::InteractionType interactionType,
|
|
const AZ::Vector2& startDragMousePos);
|
|
|
|
virtual ~ViewportMoveInteraction();
|
|
|
|
// ViewportDragInteraction
|
|
void Update(const AZ::Vector2& mousePos) override;
|
|
// ~ViewportDragInteraction
|
|
|
|
protected:
|
|
|
|
bool ConstrainMovementDirection(const AZ::Vector2& mouseDelta, AZ::Vector2& canvasSpaceMouseDelta, AZ::Vector2& localMouseDelta);
|
|
void SnapMouseDeltas(AZ::Vector2& canvasSpaceMouseDelta, AZ::Vector2& localMouseDelta);
|
|
|
|
//! Move the primary element by the given delta. This can actually change the mouse deltas due to constraints.
|
|
void MovePrimaryElement(bool restrictDirection, AZ::Vector2& canvasSpaceMouseDelta, AZ::Vector2& localMouseDelta);
|
|
|
|
//! Move one of the additional selected elements
|
|
void MoveSecondaryElement(AZ::Entity* element, bool restrictDirection, const AZ::Vector2& canvasSpaceMouseDelta);
|
|
|
|
//! Get the offset of the pivot from the top-left anchor in local space pixels
|
|
AZ::Vector2 GetPivotRelativeToTopLeftAnchor(AZ::EntityId entityId);
|
|
|
|
protected:
|
|
|
|
// State that we will need every frame in the update is cached locally in this object
|
|
|
|
AZ::Entity* m_primaryElement = nullptr;
|
|
AZ::Entity* m_primaryElementParent = nullptr;
|
|
|
|
LyShine::EntityArray m_secondarySelectedElements;
|
|
|
|
AZ::Vector2 m_startingPrimaryLocalPivot;
|
|
AZ::Vector2 m_startingPrimaryCanvasSpacePivot;
|
|
|
|
bool m_isSnapping = false;
|
|
|
|
AZ::EntityId m_canvasId;
|
|
|
|
ViewportInteraction::CoordinateSystem m_coordinateSystem;
|
|
ViewportHelpers::GizmoParts m_grabbedGizmoParts;
|
|
ViewportInteraction::InteractionMode m_interactionMode;
|
|
ViewportInteraction::InteractionType m_interactionType;
|
|
|
|
// For all elements store the offsets or anchors at the start (depending on the mode)
|
|
// We could separate this class into 2 for the anchor and move modes and only need one of these.
|
|
|
|
AZStd::map<AZ::EntityId, UiTransform2dInterface::Offsets> m_startingOffsets;
|
|
AZStd::map<AZ::EntityId, UiTransform2dInterface::Anchors> m_startingAnchors;
|
|
};
|