Viewport Ui Cluster Locked State Overlay (#1139)
* Viewport Ui Cluster Locked State Overlay * PR feedback changes.
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<title>Icon / Locked Status</title>
|
||||
<g id="Icon-/-Locked-Status" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="Group-9">
|
||||
<g id="Icons-/-Icon-Grid" transform="translate(17.000000, 15.000000)" fill="#FFFFFF">
|
||||
<path d="M3,0 C4.03553391,-1.90224492e-16 4.875,0.839466094 4.875,1.875 L4.875,3.6 L6,3.6 L6,8 L0,8 L0,3.6 L1.125,3.6 L1.125,1.875 C1.125,0.839466094 1.96446609,1.90224492e-16 3,0 Z M3.375,5.2 L2.625,5.2 L2.625,6.4 L3.375,6.4 L3.375,5.2 Z M3,0.8 C2.37867966,0.8 1.875,1.30367966 1.875,1.925 L1.875,1.925 L1.875,3.6 L4.125,3.6 L4.125,1.925 C4.125,1.30367966 3.62132034,0.8 3,0.8 Z" id="Combined-Shape"></path>
|
||||
</g>
|
||||
<rect id="Rectangle" fill="#F9F9F9" opacity="0" x="0" y="0" width="24" height="24"></rect>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1017 B |
@@ -356,7 +356,8 @@
|
||||
<file>img/UI20/toolbar/Load.svg</file>
|
||||
<file>img/UI20/toolbar/Local.svg</file>
|
||||
<file>img/UI20/toolbar/Locked.svg</file>
|
||||
<file>img/UI20/toolbar/LUA.svg</file>
|
||||
<file>img/UI20/toolbar/Locked_Status.svg</file>
|
||||
<file>img/UI20/toolbar/LUA.svg</file>
|
||||
<file>img/UI20/toolbar/Material.svg</file>
|
||||
<file>img/UI20/toolbar/Measure.svg</file>
|
||||
<file>img/UI20/toolbar/Move.svg</file>
|
||||
|
||||
+3
@@ -2646,6 +2646,9 @@ namespace AzToolsFramework
|
||||
m_spaceCluster.m_spaceLock = ReferenceFrame::World;
|
||||
}
|
||||
}
|
||||
ViewportUi::ViewportUiRequestBus::Event(
|
||||
ViewportUi::DefaultViewportId, &ViewportUi::ViewportUiRequestBus::Events::SetClusterButtonLocked,
|
||||
m_spaceCluster.m_spaceClusterId, buttonId, m_spaceCluster.m_spaceLock.has_value());
|
||||
};
|
||||
|
||||
m_spaceCluster.m_spaceSelectionHandler = AZ::Event<ViewportUi::ButtonId>::Handler(onButtonClicked);
|
||||
|
||||
@@ -108,6 +108,61 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
m_widgetCallbacks.Update();
|
||||
}
|
||||
|
||||
void ViewportUiCluster::SetButtonLocked(const ButtonId buttonId, const bool isLocked)
|
||||
{
|
||||
const auto& buttons = m_buttonGroup->GetButtons();
|
||||
|
||||
// unlocked previously locked button
|
||||
if (m_lockedButtonId.has_value() && isLocked)
|
||||
{
|
||||
// find the button to extract the old icon (without overlay)
|
||||
auto findLocked = [this](const Button* button) { return (button->m_buttonId == m_lockedButtonId); };
|
||||
if (auto lockedButtonIt = AZStd::find_if(buttons.begin(), buttons.end(), findLocked); lockedButtonIt != buttons.end())
|
||||
{
|
||||
// get the action corresponding to the lockedButtonId
|
||||
if (auto actionEntry = m_buttonActionMap.find(m_lockedButtonId.value()); actionEntry != m_buttonActionMap.end())
|
||||
{
|
||||
// remove the overlay
|
||||
auto action = actionEntry->second;
|
||||
action->setIcon(QIcon(QString((*lockedButtonIt)->m_icon.c_str())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto found = [buttonId](Button* button) { return (button->m_buttonId == buttonId); };
|
||||
if (auto buttonIt = AZStd::find_if(buttons.begin(), buttons.end(), found); buttonIt != buttons.end())
|
||||
{
|
||||
QIcon newIcon;
|
||||
|
||||
if (isLocked)
|
||||
{
|
||||
// overlay the locked icon ontop of the button's icon
|
||||
QPixmap comboPixmap(24, 24);
|
||||
comboPixmap.fill(Qt::transparent);
|
||||
QPixmap firstImage(QString((*buttonIt)->m_icon.c_str()));
|
||||
QPixmap secondImage(QString(":/stylesheet/img/UI20/toolbar/Locked_Status.svg"));
|
||||
|
||||
QPainter painter(&comboPixmap);
|
||||
painter.drawPixmap(0, 0, firstImage);
|
||||
painter.drawPixmap(0, 0, secondImage);
|
||||
newIcon.addPixmap(comboPixmap);
|
||||
m_lockedButtonId = buttonId;
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove the overlay
|
||||
newIcon = QIcon(QString((*buttonIt)->m_icon.c_str()));
|
||||
m_lockedButtonId = AZStd::nullopt;
|
||||
}
|
||||
|
||||
if (auto actionEntry = m_buttonActionMap.find(buttonId); actionEntry != m_buttonActionMap.end())
|
||||
{
|
||||
auto action = actionEntry->second;
|
||||
action->setIcon(newIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ViewportUiWidgetCallbacks ViewportUiCluster::GetWidgetCallbacks()
|
||||
{
|
||||
return m_widgetCallbacks;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <AzToolsFramework/ViewportUi/Button.h>
|
||||
#include <AzToolsFramework/ViewportUi/ViewportUiWidgetCallbacks.h>
|
||||
#include <QToolBar>
|
||||
#include <QPainter>
|
||||
|
||||
namespace AzToolsFramework::ViewportUi::Internal
|
||||
{
|
||||
@@ -38,6 +39,8 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
void RemoveButton(ButtonId buttonId);
|
||||
//! Updates all registered actions.
|
||||
void Update();
|
||||
//! Adds a locked overlay to the button's icon.
|
||||
void SetButtonLocked(ButtonId buttonId, bool isLocked);
|
||||
//! Returns the widget manager.
|
||||
ViewportUiWidgetCallbacks GetWidgetCallbacks();
|
||||
|
||||
@@ -52,5 +55,6 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
AZStd::shared_ptr<ButtonGroup> m_buttonGroup; //!< Data structure which the cluster will be displaying to the Viewport UI.
|
||||
AZStd::unordered_map<ButtonId, QPointer<QAction>> m_buttonActionMap; //!< Map for buttons to their corresponding actions.
|
||||
ViewportUiWidgetCallbacks m_widgetCallbacks; //!< Registers actions and manages updates.
|
||||
AZStd::optional<ButtonId> m_lockedButtonId = AZStd::nullopt; //!< Used to track the last button locked.
|
||||
};
|
||||
} // namespace AzToolsFramework::ViewportUi::Internal
|
||||
|
||||
@@ -100,6 +100,14 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::SetClusterButtonLocked(const ViewportUiElementId clusterId, const ButtonId buttonId, const bool isLocked)
|
||||
{
|
||||
if (auto viewportUiCluster = qobject_cast<ViewportUiCluster*>(GetViewportUiElement(clusterId).get()))
|
||||
{
|
||||
viewportUiCluster->SetButtonLocked(buttonId, isLocked);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiDisplay::RemoveClusterButton(ViewportUiElementId clusterId, ButtonId buttonId)
|
||||
{
|
||||
if (auto cluster = qobject_cast<ViewportUiCluster*>(GetViewportUiElement(clusterId).get()))
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace AzToolsFramework::ViewportUi::Internal
|
||||
|
||||
void AddCluster(AZStd::shared_ptr<ButtonGroup> buttonGroup, Alignment align);
|
||||
void AddClusterButton(ViewportUiElementId clusterId, Button* button);
|
||||
void SetClusterButtonLocked(ViewportUiElementId clusterId, ButtonId buttonId, bool isLocked);
|
||||
void RemoveClusterButton(ViewportUiElementId clusterId, ButtonId buttonId);
|
||||
void UpdateCluster(const ViewportUiElementId clusterId);
|
||||
|
||||
|
||||
@@ -67,6 +67,16 @@ namespace AzToolsFramework::ViewportUi
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::SetClusterButtonLocked(const ClusterId clusterId, const ButtonId buttonId, const bool isLocked)
|
||||
{
|
||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
|
||||
{
|
||||
auto cluster = clusterIt->second;
|
||||
m_viewportUi->SetClusterButtonLocked(cluster->GetViewportUiElementId(), buttonId, isLocked);
|
||||
UpdateButtonGroupUi(cluster.get());
|
||||
}
|
||||
}
|
||||
|
||||
void ViewportUiManager::RegisterClusterEventHandler(const ClusterId clusterId, AZ::Event<ButtonId>::Handler& handler)
|
||||
{
|
||||
if (auto clusterIt = m_clusterButtonGroups.find(clusterId); clusterIt != m_clusterButtonGroups.end())
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace AzToolsFramework::ViewportUi
|
||||
const SwitcherId CreateSwitcher(Alignment align) override;
|
||||
void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) override;
|
||||
void SetSwitcherActiveButton(SwitcherId switcherId, ButtonId buttonId) override;
|
||||
void SetClusterButtonLocked(ClusterId clusterId, ButtonId buttonId, bool isLocked) override;
|
||||
const ButtonId CreateClusterButton(ClusterId clusterId, const AZStd::string& icon) override;
|
||||
const ButtonId CreateSwitcherButton(
|
||||
SwitcherId switcherId, const AZStd::string& icon, const AZStd::string& name = AZStd::string()) override;
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace AzToolsFramework::ViewportUi
|
||||
virtual void SetClusterActiveButton(ClusterId clusterId, ButtonId buttonId) = 0;
|
||||
//! Sets the active button of the switcher. This is the button which has a text label.
|
||||
virtual void SetSwitcherActiveButton(SwitcherId clusterId, ButtonId buttonId) = 0;
|
||||
//! Adds a locked overlay to the cluster button's icon.
|
||||
virtual void SetClusterButtonLocked(ClusterId clusterId, ButtonId buttonId, bool isLocked) = 0;
|
||||
//! Registers a new button onto a cluster.
|
||||
virtual const ButtonId CreateClusterButton(const ClusterId clusterId, const AZStd::string& icon) = 0;
|
||||
//! Registers a new button onto a switcher.
|
||||
|
||||
Reference in New Issue
Block a user