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.
117 lines
4.1 KiB
C++
117 lines
4.1 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
|
|
*
|
|
*/
|
|
#include "EditorCommon.h"
|
|
|
|
ViewportHighlight::ViewportHighlight()
|
|
: m_highlightIconSelected(new ViewportIcon("Editor/Icons/Viewport/Border_Selected.tif"))
|
|
, m_highlightIconUnselected(new ViewportIcon("Editor/Icons/Viewport/Border_Unselected.tif"))
|
|
{
|
|
}
|
|
|
|
ViewportHighlight::~ViewportHighlight()
|
|
{
|
|
}
|
|
|
|
void ViewportHighlight::Draw(Draw2dHelper& draw2d,
|
|
QTreeWidgetItem* invisibleRootItem,
|
|
HierarchyItemRawPtrList& selectedItems,
|
|
uint32 flags)
|
|
{
|
|
// first draw any unselected element borders (if flag is set to draw them)
|
|
if (flags & ViewportWidget::DrawElementBorders_Unselected)
|
|
{
|
|
HierarchyItemRawPtrList allItems;
|
|
HierarchyHelpers::AppendAllChildrenToEndOfList(invisibleRootItem, allItems);
|
|
|
|
for (auto item : allItems)
|
|
{
|
|
AZ::Entity* element = item->GetElement();
|
|
AZ_Warning("UI", element, "Missing entity for hierarchy item");
|
|
if (!element)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
bool shouldDrawBorder = true;
|
|
if (item->isSelected())
|
|
{
|
|
// this element is in the selected list
|
|
// ignore the selected items - we draw border for those afterwards so that they are on top
|
|
|
|
shouldDrawBorder = false;
|
|
}
|
|
else
|
|
{
|
|
// This element is not selected
|
|
|
|
if (!(flags & ViewportWidget::DrawElementBorders_Parent))
|
|
{
|
|
// the flag is NOT set to draw borders on elements that are parents
|
|
// so if this element has children we should NOT draw a border for it
|
|
|
|
int numChildren = 0;
|
|
EBUS_EVENT_ID_RESULT(numChildren, element->GetId(), UiElementBus, GetNumChildElements);
|
|
if (numChildren > 0)
|
|
{
|
|
shouldDrawBorder = false;
|
|
}
|
|
}
|
|
|
|
if (!(flags & ViewportWidget::DrawElementBorders_Visual))
|
|
{
|
|
// the flag is NOT set to draw borders on elements that are visual
|
|
// so if this element has any visual components we should NOT draw a border for it
|
|
|
|
if (UiVisualBus::FindFirstHandler(element->GetId()))
|
|
{
|
|
shouldDrawBorder = false;
|
|
}
|
|
}
|
|
|
|
if (!(flags & ViewportWidget::DrawElementBorders_Hidden))
|
|
{
|
|
// the flag is NOT set to draw borders on elements that are hidden
|
|
// so if this element is hidden we should NOT draw a border for it
|
|
|
|
bool isVisible = false;
|
|
EBUS_EVENT_ID_RESULT(isVisible, element->GetId(), UiEditorBus, GetIsVisible);
|
|
|
|
bool areAllAncestorsVisible = false;
|
|
EBUS_EVENT_ID_RESULT(areAllAncestorsVisible, element->GetId(), UiEditorBus, AreAllAncestorsVisible);
|
|
|
|
if (!(isVisible && areAllAncestorsVisible))
|
|
{
|
|
shouldDrawBorder = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (shouldDrawBorder)
|
|
{
|
|
m_highlightIconUnselected->DrawElementRectOutline(draw2d, element->GetId(), ViewportHelpers::unselectedColor);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Now draw the borders for any selected elements
|
|
for (auto item : selectedItems)
|
|
{
|
|
AZ::Entity* element = item->GetElement();
|
|
AZ_Warning("UI", element, "Missing entity for hierarchy item");
|
|
if (element)
|
|
{
|
|
m_highlightIconSelected->DrawElementRectOutline(draw2d, element->GetId(), ViewportHelpers::selectedColor);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ViewportHighlight::DrawHover(Draw2dHelper& draw2d, AZ::EntityId hoverElement)
|
|
{
|
|
m_highlightIconSelected->DrawElementRectOutline(draw2d, hoverElement, ViewportHelpers::highlightColor);
|
|
}
|