Files
o3de/Gems/LyShine/Code/Editor/ViewportAnchor.cpp
T
lumberyard-employee-dm 3dec5d3b71 LYN-2537 engine assets (#254)
* LYN-2537 Moved the Engine and Editor folder to be within the EngineAssets folder

* Fixed Documentation in bootstrap.cfg to correct the path to the user project specific registry file

* Adding a newline to the output of AssetCatalog 'Registering asset..., but type is not set' message

* Updating the AssetProcessorPlatformConfig.setreg Scan Folder to detect
the @ENGINEROOT@/EngineAssets/Engine path for engine runtime assets and
@ENGINEROOT@/EngineAssets/Editor path for engine tool assets

* Updating references to Icons and other assets to account for moving the
Engine and Editor folder under a single EngineAssets folder

* Moving the Engine Settings Registry folder from Engine/Registry -> Registry

* Removed the LY_PROJECT_CMAKE_PATH define as it is not portable to other locations. It is hard coded to the project location that was used for the CMake configuration. Furthermore it paths with backslashes within it are treated as escape characters and not a path separator

* Updated the LyTestTools asset_processor.py script to copy the exclude.filetag from the EngineAssets/Engine directory now

* Fixed Atom Shader Preprocessing when running using an External Project

* Updated the TSGenerateAction.cpp to fix the build error with using a renamed variable

* Updated the Install_Common.cmake ly_setup_others function to install the
EngineAssets directory and the each of the Gem's Assets directory while
maintaining the relative directory structure to the Engine Root
Also updated the install step to install the Registry folder at the
engine root

* Fixed the copying of the Registry folder to be in the install root, instead of under a second 'Registry' folder

* Moving the AssetProcessorPlatformConfig.setreg file over to the Registry folder

* Updated the LyTestTools and C++ code to point that the new location of
the AssetProcessorPlatformConfig.setreg file inside of the Registry
folder

* Renamed Test AssetProcessor*Config.ini files to have the .setreg extension

* Converted the AssetProcessor test setreg files from ini format to json
format using the SerializeContextTools convert-ini command

* Updated the AssetProcessor CMakeLists.txt to copy over the test setreg files to the build folder

* Updated the assetprocessor test file list to point at the renamed AsssetProcessor*Config setreg filenames

* Removed the Output Prefix code from the AssetProcessor. The complexity that it brought to the AP code is not needed, as users can replicate the behavior by just moving there assets underneath a another folder, underneath the scan folder

* Adding back support to read the AssetProcessorPlatformConfig.setreg file from the asset root. This is only needed for C++ UnitTests as they run in an environment where the accessing the Engine Settings Registry is not available

* Updating the Install_common.cmake logic to copy any "Assets" folder to
the install layout.
The Script has also been updated to copy over the "Assets" folder in the
Engine Root to the install layout instead of an "EngineAssets" folder

* Updating References to EngineAssets source asset folder in code to be the Assets source folder

* Moved the Engine Source Asset folder of 'EngineAssets' to a new folder name of 'Assets'. This is inline with the naming scheme we use for Gem asset folders

* Adding the EngineFinder.cmake to the AutomatedTesting project to allow it to work in a project centric manner

* Updating the LyTestTools copy_assets_to_project function to be able to copy assets with folders to the temporary project root
Fixed an issue in LyTestTools where the temporary log directory could have shutil.rmtree being called twice on it leading to an exception which fails an automated test

Updated the asset_procesor_gui_tests_2 AddScanFolder test to not use the
output prefix, but instead place the source asset root into a
subdirectory

* Correct the AssetProcessorPlatformConfig Scan Folders for the EngineAssets directory to point at the Assets directory

* Updated the asset procesor batch dependency test scan folder to point at the 'Assets' folder instead of 'EngineAssets'
2021-04-28 21:38:43 -05:00

297 lines
15 KiB
C++

/*
* 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 "UiCanvasEditor_precompiled.h"
#include "EditorCommon.h"
ViewportAnchor::ViewportAnchor()
: m_anchorWhole(new ViewportIcon("Plugins/UiCanvasEditor/CanvasIcons/Anchor_Whole.tif"))
, m_anchorLeft(new ViewportIcon("Plugins/UiCanvasEditor/CanvasIcons/Anchor_Left.tif"))
, m_anchorLeftTop(new ViewportIcon("Plugins/UiCanvasEditor/CanvasIcons/Anchor_TopLeft.tif"))
, m_dottedLine(new ViewportIcon("Plugins/UiCanvasEditor/CanvasIcons/DottedLine.tif"))
{
}
ViewportAnchor::~ViewportAnchor()
{
}
void ViewportAnchor::Draw(Draw2dHelper& draw2d, AZ::Entity* element, bool drawUnTransformedRect, bool drawAnchorLines, bool drawLinesToParent,
bool anchorInteractionEnabled, ViewportHelpers::SelectedAnchors highlightedAnchors) const
{
if (!element || ViewportHelpers::IsControlledByLayout(element))
{
// Don't draw anything if there is no element or it's controlled by a layout.
return;
}
// check that the element is using transform2d - if not then can't draw the anchors
if (!UiTransform2dBus::FindFirstHandler(element->GetId()))
{
return;
}
AZ::Entity* parentElement = EntityHelpers::GetParentElement(element);
// get the anchors from the element's transform component
UiTransform2dInterface::Anchors anchors;
EBUS_EVENT_ID_RESULT(anchors, element->GetId(), UiTransform2dBus, GetAnchors);
// get the parent element's pre-transform points and its transform.
// The anchors are in terms of the parent's space
UiTransformInterface::RectPoints parentPoints;
EBUS_EVENT_ID(parentElement->GetId(), UiTransformBus, GetCanvasSpacePointsNoScaleRotate, parentPoints);
AZ::Vector2 parentSize = parentPoints.GetAxisAlignedSize();
AZ::Matrix4x4 parentTransform;
EBUS_EVENT_ID(parentElement->GetId(), UiTransformBus, GetTransformToViewport, parentTransform);
UiTransformInterface::RectPoints elemRect;
EBUS_EVENT_ID(element->GetId(), UiTransformBus, GetCanvasSpacePointsNoScaleRotate, elemRect);
// Here we optionally draw a rect outline, either the element's rect or the parent element's
// rect depending on the situation
if (drawUnTransformedRect || drawLinesToParent)
{
UiTransformInterface::RectPoints rectPointsToDraw;
if (drawLinesToParent)
{
// If we are going to draw distance lines to the parent then draw the parent rectangle
rectPointsToDraw = parentPoints.Transform(parentTransform);
}
else
{
// drawUnTransformedRect must be true
// we draw the outline of this element's rect before its local rotate and scale
// the untransformed rect we want to draw has all the parents' transforms but not this element's transforms
// so transform the NoScaleRotate with the parent transform
rectPointsToDraw = elemRect.Transform(parentTransform);
}
AZ::Color rectColor(1.0f, 1.0f, 1.0f, 0.2f);
draw2d.DrawLine(rectPointsToDraw.TopLeft(), rectPointsToDraw.TopRight(), rectColor); // top
draw2d.DrawLine(rectPointsToDraw.TopRight(), rectPointsToDraw.BottomRight(), rectColor); // right
draw2d.DrawLine(rectPointsToDraw.BottomRight(), rectPointsToDraw.BottomLeft(), rectColor); // bottom
draw2d.DrawLine(rectPointsToDraw.BottomLeft(), rectPointsToDraw.TopLeft(), rectColor); // left
}
if (drawLinesToParent)
{
// When moving the anchors (or if we are highlighting them) we draw lines from the anchors
// to the parent rectangle to make it clear that the anchors are normalized distances from
// the edges of the parent
DrawAnchorToParentLines(draw2d, anchors, parentPoints, parentTransform, highlightedAnchors);
// if moving the anchors we do not want to draw the lines from the anchors to the element rect
drawAnchorLines = false;
}
// we draw the anchors in a different color if anchor interaction is disabled
AZ::Color anchorColor = (anchorInteractionEnabled) ? ViewportHelpers::anchorColor : ViewportHelpers::anchorColorDisabled;
// the anchors we draw depend on whether the left/right and top/bottom anchors are together or split apart
if (anchors.m_left == anchors.m_right)
{
if (anchors.m_top == anchors.m_bottom)
{
// all anchors together
AZ::Vector2 anchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_top);
if (drawAnchorLines)
{
AZ::Vector2 pivot;
EBUS_EVENT_ID_RESULT(pivot, element->GetId(), UiTransformBus, GetCanvasSpacePivotNoScaleRotate);
m_dottedLine->DrawAnchorLines(draw2d, anchorPos, pivot, parentTransform, true, true, true);
}
m_anchorWhole->Draw(draw2d, anchorPos, parentTransform, 0.0f, anchorColor);
}
else
{
// stretching vertically
AZ::Vector2 topAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_top);
AZ::Vector2 bottomAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_bottom);
if (drawAnchorLines)
{
AZ::Vector2 pivot;
EBUS_EVENT_ID_RESULT(pivot, element->GetId(), UiTransformBus, GetCanvasSpacePivotNoScaleRotate);
AZ::Vector2 topTarget;
AZ::Vector2 bottomTarget;
ViewportHelpers::GetVerticalTargetPoints(elemRect, topAnchorPos.GetX(), topTarget, bottomTarget);
m_dottedLine->DrawAnchorLines(draw2d, topAnchorPos, topTarget, parentTransform, true, false, true);
m_dottedLine->DrawAnchorLines(draw2d, bottomAnchorPos, bottomTarget, parentTransform, true, false, true);
m_dottedLine->DrawAnchorLinesSplit(draw2d, topAnchorPos, bottomAnchorPos, pivot, parentTransform, false);
}
m_anchorLeft->Draw(draw2d, topAnchorPos, parentTransform, 90.0f, anchorColor);
m_anchorLeft->Draw(draw2d, bottomAnchorPos, parentTransform, -90.0f, anchorColor);
}
}
else
{
if (anchors.m_top == anchors.m_bottom)
{
// stretching horizontally
AZ::Vector2 leftAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_top);
AZ::Vector2 rightAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_right, anchors.m_top);
if (drawAnchorLines)
{
AZ::Vector2 pivot;
EBUS_EVENT_ID_RESULT(pivot, element->GetId(), UiTransformBus, GetCanvasSpacePivotNoScaleRotate);
AZ::Vector2 leftTarget;
AZ::Vector2 rightTarget;
ViewportHelpers::GetHorizTargetPoints(elemRect, leftAnchorPos.GetY(), leftTarget, rightTarget);
m_dottedLine->DrawAnchorLines(draw2d, leftAnchorPos, leftTarget, parentTransform, false, true, false);
m_dottedLine->DrawAnchorLines(draw2d, rightAnchorPos, rightTarget, parentTransform, false, true, false);
m_dottedLine->DrawAnchorLinesSplit(draw2d, leftAnchorPos, rightAnchorPos, pivot, parentTransform, true);
}
m_anchorLeft->Draw(draw2d, leftAnchorPos, parentTransform, 0.0f, anchorColor);
m_anchorLeft->Draw(draw2d, rightAnchorPos, parentTransform, 180.0f, anchorColor);
}
else
{
// stretching in both directions
AZ::Vector2 topLeftAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_top);
AZ::Vector2 topRightAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_right, anchors.m_top);
AZ::Vector2 bottomRightAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_right, anchors.m_bottom);
AZ::Vector2 bottomLeftAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_bottom);
if (drawAnchorLines)
{
AZ::Vector2 pivot;
EBUS_EVENT_ID_RESULT(pivot, element->GetId(), UiTransformBus, GetCanvasSpacePivotNoScaleRotate);
AZ::Vector2 anchorMidpoint = (topLeftAnchorPos + bottomRightAnchorPos) * 0.5f;
AZ::Vector2 leftTarget;
AZ::Vector2 rightTarget;
ViewportHelpers::GetHorizTargetPoints(elemRect, anchorMidpoint.GetY(), leftTarget, rightTarget);
AZ::Vector2 topTarget;
AZ::Vector2 bottomTarget;
ViewportHelpers::GetVerticalTargetPoints(elemRect, anchorMidpoint.GetX(), topTarget, bottomTarget);
m_dottedLine->DrawAnchorLinesSplit(draw2d, topLeftAnchorPos, topRightAnchorPos, topTarget, parentTransform, true);
m_dottedLine->DrawAnchorLinesSplit(draw2d, bottomLeftAnchorPos, bottomRightAnchorPos, bottomTarget, parentTransform, true);
m_dottedLine->DrawAnchorLinesSplit(draw2d, topLeftAnchorPos, bottomLeftAnchorPos, leftTarget, parentTransform, false);
m_dottedLine->DrawAnchorLinesSplit(draw2d, topRightAnchorPos, bottomRightAnchorPos, rightTarget, parentTransform, false);
}
m_anchorLeftTop->Draw(draw2d, topLeftAnchorPos, parentTransform, 0.0f, anchorColor);
m_anchorLeftTop->Draw(draw2d, topRightAnchorPos, parentTransform, 90.0f, anchorColor);
m_anchorLeftTop->Draw(draw2d, bottomRightAnchorPos, parentTransform, 180.0f, anchorColor);
m_anchorLeftTop->Draw(draw2d, bottomLeftAnchorPos, parentTransform, -90.0f, anchorColor);
}
}
// If the user is hovering over any anchors, highlight them
if (highlightedAnchors.All())
{
AZ::Vector2 anchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_top);
m_anchorWhole->Draw(draw2d, anchorPos, parentTransform, 0.0f, ViewportHelpers::highlightColor);
}
else if (highlightedAnchors.TopLeft())
{
AZ::Vector2 topLeftAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_top);
m_anchorLeftTop->Draw(draw2d, topLeftAnchorPos, parentTransform, 0.0f, ViewportHelpers::highlightColor);
}
else if (highlightedAnchors.TopRight())
{
AZ::Vector2 topRightAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_right, anchors.m_top);
m_anchorLeftTop->Draw(draw2d, topRightAnchorPos, parentTransform, 90.0f, ViewportHelpers::highlightColor);
}
else if (highlightedAnchors.BottomRight())
{
AZ::Vector2 bottomRightAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_right, anchors.m_bottom);
m_anchorLeftTop->Draw(draw2d, bottomRightAnchorPos, parentTransform, 180.0f, ViewportHelpers::highlightColor);
}
else if (highlightedAnchors.BottomLeft())
{
AZ::Vector2 bottomLeftAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_bottom);
m_anchorLeftTop->Draw(draw2d, bottomLeftAnchorPos, parentTransform, -90.0f, ViewportHelpers::highlightColor);
}
else if (highlightedAnchors.m_top)
{
AZ::Vector2 topAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_top);
m_anchorLeft->Draw(draw2d, topAnchorPos, parentTransform, 90.0f, ViewportHelpers::highlightColor);
}
else if (highlightedAnchors.m_bottom)
{
AZ::Vector2 bottomAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_bottom);
m_anchorLeft->Draw(draw2d, bottomAnchorPos, parentTransform, -90.0f, ViewportHelpers::highlightColor);
}
else if (highlightedAnchors.m_left)
{
AZ::Vector2 leftAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_left, anchors.m_top);
m_anchorLeft->Draw(draw2d, leftAnchorPos, parentTransform, 0.0f, ViewportHelpers::highlightColor);
}
else if (highlightedAnchors.m_right)
{
AZ::Vector2 rightAnchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, anchors.m_right, anchors.m_top);
m_anchorLeft->Draw(draw2d, rightAnchorPos, parentTransform, 180.0f, ViewportHelpers::highlightColor);
}
}
void ViewportAnchor::DrawAnchorToParentLines(Draw2dHelper& draw2d, const UiTransform2dInterface::Anchors& anchors,
const UiTransformInterface::RectPoints& parentPoints, const AZ::Matrix4x4& transform,
ViewportHelpers::SelectedAnchors highlightedAnchors) const
{
bool drawHoriz = true;
bool drawVert = true;
// if we have just one side of the anchors selected we only draw one line
if (!highlightedAnchors.All() && highlightedAnchors.Any())
{
if (!(highlightedAnchors.m_left || highlightedAnchors.m_right))
{
// we are dragging up/down only
drawHoriz = false;
}
else if (!(highlightedAnchors.m_top || highlightedAnchors.m_bottom))
{
// we are dragging left/right only
drawVert = false;
}
}
AZ::Vector2 parentSize = parentPoints.GetAxisAlignedSize();
float horizAnchorVal = (highlightedAnchors.m_left) ? anchors.m_left : anchors.m_right;
float vertAnchorVal = (highlightedAnchors.m_top) ? anchors.m_top : anchors.m_bottom;
AZ::Vector2 anchorPos = ViewportHelpers::ComputeAnchorPoint(parentPoints.TopLeft(), parentSize, horizAnchorVal, vertAnchorVal);
if (drawHoriz)
{
// draw distance line horizontally from the anchor pos to the left edge of the parent rect
// The distance value is the anchor value (0 - 1 range)
AZ::Vector2 targetPosLeft(parentPoints.TopLeft().GetX(), anchorPos.GetY());
m_dottedLine->DrawDistanceLineWithTransform(draw2d, anchorPos, targetPosLeft, transform, horizAnchorVal * 100.0f, "%");
}
if (drawVert)
{
// draw distance line vertically from the anchor pos to the top edge of the parent rect
// The distance value is the anchor value (0 - 1 range)
AZ::Vector2 targetPosTop(anchorPos.GetX(), parentPoints.TopLeft().GetY());
m_dottedLine->DrawDistanceLineWithTransform(draw2d, anchorPos, targetPosTop, transform, vertAnchorVal * 100.0f, "%");
}
}