ExecutionSlotConnectionPin.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <QPainter>
  9. #include <Components/Slots/Execution/ExecutionSlotConnectionPin.h>
  10. #include <GraphCanvas/Styling/definitions.h>
  11. namespace GraphCanvas
  12. {
  13. ///////////////////////////////
  14. // ExecutionSlotConnectionPin
  15. ///////////////////////////////
  16. ExecutionSlotConnectionPin::ExecutionSlotConnectionPin(const AZ::EntityId& slotId)
  17. : SlotConnectionPin(slotId)
  18. {
  19. }
  20. ExecutionSlotConnectionPin::~ExecutionSlotConnectionPin()
  21. {
  22. }
  23. void ExecutionSlotConnectionPin::OnRefreshStyle()
  24. {
  25. m_style.SetStyle(m_slotId, Styling::Elements::ExecutionConnectionPin);
  26. m_connectedStyle.SetStyle(m_slotId, ".connected");
  27. }
  28. void ExecutionSlotConnectionPin::DrawConnectionPin(QPainter *painter, QRectF drawRect, bool isConnected)
  29. {
  30. // draw triangle, pointing to the right
  31. if (isConnected)
  32. {
  33. // Add fill color for slots if it is connected
  34. painter->setBrush(m_connectedStyle.GetBrush(Styling::Attribute::BackgroundColor, QColor{ 0xFF, 0xFF, 0xFF }));
  35. }
  36. QPen decorationBorder = m_style.GetBorder();
  37. decorationBorder.setJoinStyle(Qt::PenJoinStyle::MiterJoin);
  38. painter->setPen(decorationBorder);
  39. qreal sideLength = AZ::GetMin(drawRect.width(), drawRect.height());
  40. qreal halfLength = sideLength * 0.5;
  41. painter->drawConvexPolygon(QPolygonF({
  42. drawRect.center() + QPointF(-halfLength, -halfLength),
  43. drawRect.center() + QPointF(halfLength,0),
  44. drawRect.center() + QPointF(-halfLength, halfLength)
  45. }));
  46. }
  47. }