1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
195 lines
6.8 KiB
C++
195 lines
6.8 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 <QPainter>
|
|
|
|
#include <Components/Slots/Data/DataSlotConnectionPin.h>
|
|
|
|
#include <GraphCanvas/Components/Slots/SlotBus.h>
|
|
#include <GraphCanvas/Components/StyleBus.h>
|
|
#include <GraphCanvas/Components/Slots/Data/DataSlotBus.h>
|
|
#include <GraphCanvas/Styling/definitions.h>
|
|
|
|
#include <GraphCanvas/Utils/QtVectorMath.h>
|
|
#include <GraphCanvas/Utils/QtDrawingUtils.h>
|
|
|
|
namespace GraphCanvas
|
|
{
|
|
//////////////////////////
|
|
// DataSlotConnectionPin
|
|
//////////////////////////
|
|
|
|
DataSlotConnectionPin::DataSlotConnectionPin(const AZ::EntityId& slotId)
|
|
: SlotConnectionPin(slotId)
|
|
, m_colorPalette(nullptr)
|
|
{
|
|
}
|
|
|
|
DataSlotConnectionPin::~DataSlotConnectionPin()
|
|
{
|
|
}
|
|
|
|
void DataSlotConnectionPin::OnRefreshStyle()
|
|
{
|
|
m_style.SetStyle(m_slotId, Styling::Elements::DataConnectionPin);
|
|
|
|
size_t typeCount = 0;
|
|
DataSlotRequestBus::EventResult(typeCount, GetEntityId(), &DataSlotRequests::GetContainedTypesCount);
|
|
|
|
m_containerColorPalettes.clear();
|
|
|
|
for (size_t i = 0; i < typeCount; ++i)
|
|
{
|
|
const Styling::StyleHelper* colorPalette = nullptr;
|
|
DataSlotRequestBus::EventResult(colorPalette, GetEntityId(), &DataSlotRequests::GetContainedTypeColorPalette, i);
|
|
if (colorPalette)
|
|
{
|
|
m_containerColorPalettes.emplace_back(colorPalette);
|
|
}
|
|
}
|
|
|
|
DataSlotRequestBus::EventResult(m_colorPalette, GetEntityId(), &DataSlotRequests::GetDataColorPalette);
|
|
|
|
update();
|
|
}
|
|
|
|
void DataSlotConnectionPin::DrawConnectionPin(QPainter *painter, QRectF drawRect, bool isConnected)
|
|
{
|
|
painter->save();
|
|
|
|
DataSlotType dataType = DataSlotType::Unknown;
|
|
DataSlotRequestBus::EventResult(dataType, GetEntityId(), &DataSlotRequests::GetDataSlotType);
|
|
|
|
DataValueType valueType = DataValueType::Unknown;
|
|
DataSlotRequestBus::EventResult(valueType, GetEntityId(), &DataSlotRequests::GetDataValueType);
|
|
|
|
qreal radius = (AZ::GetMin(drawRect.width(), drawRect.height()) * 0.5) - m_style.GetBorder().width();
|
|
|
|
QPen pen = m_style.GetBorder();
|
|
QBrush brush = painter->brush();
|
|
|
|
if (m_colorPalette)
|
|
{
|
|
pen.setColor(m_colorPalette->GetColor(Styling::Attribute::LineColor));
|
|
brush.setColor(m_colorPalette->GetColor(Styling::Attribute::BackgroundColor));
|
|
}
|
|
else
|
|
{
|
|
brush.setColor(pen.color());
|
|
}
|
|
|
|
QRectF finalRect(drawRect.center().x() - radius, drawRect.center().y() - radius, radius * 2, radius * 2);
|
|
|
|
QLinearGradient penGradient;
|
|
QLinearGradient fillGradient;
|
|
|
|
if (m_containerColorPalettes.size() > 0)
|
|
{
|
|
QtDrawingUtils::GenerateGradients(m_containerColorPalettes, finalRect, penGradient, fillGradient);
|
|
|
|
penGradient.setColorAt(0, m_containerColorPalettes[0]->GetColor(Styling::Attribute::LineColor));
|
|
fillGradient.setColorAt(0, m_containerColorPalettes[0]->GetColor(Styling::Attribute::BackgroundColor));
|
|
|
|
double transition = 0.1 * (1.0 / m_containerColorPalettes.size());
|
|
|
|
for (size_t i = 1; i < m_containerColorPalettes.size(); ++i)
|
|
{
|
|
double transitionStart = AZStd::max(0.0, (double)i / m_containerColorPalettes.size() - (transition * 0.5));
|
|
double transitionEnd = AZStd::min(1.0, (double)i / m_containerColorPalettes.size() + (transition * 0.5));
|
|
|
|
penGradient.setColorAt(transitionStart, m_containerColorPalettes[i - 1]->GetColor(Styling::Attribute::LineColor));
|
|
penGradient.setColorAt(transitionEnd, m_containerColorPalettes[i]->GetColor(Styling::Attribute::LineColor));
|
|
|
|
fillGradient.setColorAt(transitionStart, m_containerColorPalettes[i - 1]->GetColor(Styling::Attribute::BackgroundColor));
|
|
fillGradient.setColorAt(transitionEnd, m_containerColorPalettes[i]->GetColor(Styling::Attribute::BackgroundColor));
|
|
}
|
|
|
|
penGradient.setColorAt(1, m_containerColorPalettes[m_containerColorPalettes.size() - 1]->GetColor(Styling::Attribute::LineColor));
|
|
fillGradient.setColorAt(1, m_containerColorPalettes[m_containerColorPalettes.size() - 1]->GetColor(Styling::Attribute::BackgroundColor));
|
|
|
|
pen.setBrush(penGradient);
|
|
}
|
|
|
|
// Add fill color for slots if it is connected
|
|
if (m_containerColorPalettes.size() > 0)
|
|
{
|
|
brush = fillGradient;
|
|
}
|
|
else if (m_colorPalette)
|
|
{
|
|
brush.setColor(m_colorPalette->GetColor(Styling::Attribute::BackgroundColor));
|
|
}
|
|
else
|
|
{
|
|
brush.setColor(pen.color());
|
|
}
|
|
|
|
painter->setPen(pen);
|
|
|
|
if (dataType == DataSlotType::Reference)
|
|
{
|
|
QRectF filledHalfRect = QRectF(drawRect.x(), drawRect.y(), drawRect.width() * 0.5, drawRect.height());
|
|
QRectF unfilledHalfRect = filledHalfRect;
|
|
unfilledHalfRect.moveLeft(drawRect.center().x());
|
|
|
|
ConnectionType connectionType = CT_Invalid;
|
|
SlotRequestBus::EventResult(connectionType, GetEntityId(), &SlotRequests::GetConnectionType);
|
|
|
|
if (connectionType == CT_Output)
|
|
{
|
|
QRectF swapRect = filledHalfRect;
|
|
filledHalfRect = unfilledHalfRect;
|
|
unfilledHalfRect = swapRect;
|
|
}
|
|
|
|
// Draw the unfilled half
|
|
painter->setClipRect(filledHalfRect);
|
|
|
|
if (valueType == DataValueType::Container)
|
|
{
|
|
painter->drawRect(finalRect);
|
|
}
|
|
else
|
|
{
|
|
painter->drawEllipse(drawRect.center(), radius, radius);
|
|
}
|
|
|
|
painter->setClipRect(unfilledHalfRect);
|
|
|
|
if (valueType == DataValueType::Container)
|
|
{
|
|
painter->fillRect(finalRect, brush);
|
|
}
|
|
else
|
|
{
|
|
painter->setBrush(brush);
|
|
painter->drawEllipse(drawRect.center(), radius, radius);
|
|
}
|
|
}
|
|
else if (dataType == DataSlotType::Value)
|
|
{
|
|
if (isConnected)
|
|
{
|
|
painter->setBrush(brush);
|
|
}
|
|
|
|
if (valueType == DataValueType::Primitive)
|
|
{
|
|
painter->drawEllipse(drawRect.center(), radius, radius);
|
|
}
|
|
else
|
|
{
|
|
painter->drawRect(finalRect);
|
|
}
|
|
}
|
|
|
|
painter->restore();
|
|
}
|
|
|
|
}
|