/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "stdafx.h" #include "EditorCommon.h" #include "ViewportMoveGuideInteraction.h" #include "CanvasHelpers.h" #include "GuideHelpers.h" #include ViewportMoveGuideInteraction::ViewportMoveGuideInteraction( EditorWindow* editorWindow, AZ::EntityId canvasId, bool guideIsVertical, int guideIndex, const AZ::Vector2& startDragMousePos ) : ViewportDragInteraction(startDragMousePos) , m_editorWindow(editorWindow) , m_canvasId(canvasId) , m_guideIsVertical(guideIsVertical) , m_guideIndex(guideIndex) , m_cursorViewportPos(0.0f, 0.0f) { // store whether snapping is enabled for this canvas EBUS_EVENT_ID_RESULT(m_isSnapping, canvasId, UiEditorCanvasBus, GetIsSnapEnabled); m_startingPosition = GuideHelpers::GetGuidePosition(canvasId, m_guideIsVertical, m_guideIndex); // store the state before anything is moved m_canvasUndoXml = CanvasHelpers::BeginUndoableCanvasChange(m_canvasId); } ViewportMoveGuideInteraction::~ViewportMoveGuideInteraction() { } void ViewportMoveGuideInteraction::Update(const AZ::Vector2& mousePos) { // remember mouse position for render m_cursorViewportPos = mousePos; // Move the guide MoveGuideToMousePos(mousePos); } void ViewportMoveGuideInteraction::Render(Draw2dHelper& draw2d) { // We don't need to render the guide since its position has been updated and the normal canvas render will draw it // What we draw is the "visual aid" which in this case is a text display of the ruler position float pos = GuideHelpers::GetGuidePosition(m_canvasId, m_guideIsVertical, m_guideIndex); GuideHelpers::DrawGuidePosTextDisplay(draw2d, m_guideIsVertical, pos, m_editorWindow->GetViewport()); } void ViewportMoveGuideInteraction::EndInteraction(EndState endState) { // If the interaction ended inside the viewport then do a move, else do a delete const char* commandName = "move guide"; if (endState == EndState::OutsideXY || (m_guideIsVertical ? endState == EndState::OutsideX : endState == EndState::OutsideY)) { GuideHelpers::RemoveGuide(m_canvasId, m_guideIsVertical, m_guideIndex); commandName = "delete guide"; } CanvasHelpers::EndUndoableCanvasChange(m_editorWindow, commandName, m_canvasUndoXml); } void ViewportMoveGuideInteraction::MoveGuideToMousePos(const AZ::Vector2& viewportPos) { AZ::Vector2 snappedPos = CanvasHelpers::GetSnappedCanvasPoint(m_canvasId, viewportPos, m_isSnapping); GuideHelpers::SetGuidePosition(m_canvasId, m_guideIsVertical, m_guideIndex, snappedPos); }