ViewportHelpers.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. #pragma once
  9. #include <LyShine/IDraw2d.h>
  10. namespace ViewportHelpers
  11. {
  12. //-------------------------------------------------------------------------------
  13. const AZ::Color backgroundColorDark(0.133f, 0.137f, 0.149f, 1.0f); // #222236, RGBA: 34, 35, 38, 255
  14. const AZ::Color selectedColor(1.000f, 1.000f, 1.000f, 1.0f); // #FFFFFF, RGBA: 255, 255, 255, 255
  15. const AZ::Color unselectedColor(0.800f, 0.800f, 0.800f, 0.500f); // #CCCCCC, RGBA: 204, 204, 204, 128
  16. const AZ::Color highlightColor(1.000f, 0.600f, 0.000f, 1.0f); // #FF9900, RGBA: 255, 153, 0, 255
  17. const AZ::Color anchorColor(0.192f, 0.565f, 0.933f, 1.0f); // #3190EE, RGBA: 49, 144, 238, 255
  18. const AZ::Color anchorColorDisabled(0.85f, 0.85f, 0.85f, 0.5f);
  19. const AZ::Color pivotColor(anchorColor);
  20. const AZ::Color xColor(1.00f, 0.00f, 0.00f, 1.0f);
  21. const AZ::Color yColor(0.00f, 1.00f, 0.00f, 1.0f);
  22. const AZ::Color zColor(0.10f, 0.30f, 1.00f, 1.0f);
  23. //-------------------------------------------------------------------------------
  24. // Determines whether the element is being controlled by a layout component on its parent
  25. bool IsControlledByLayout(const AZ::Entity* element);
  26. // Determines whether the element is being horizontally fit by a LayoutFitter
  27. bool IsHorizontallyFit(const AZ::Entity* element);
  28. // Determines whether the element is being vertically fit by a LayoutFitter
  29. bool IsVerticallyFit(const AZ::Entity* element);
  30. // Returns a perpendicular angle between -180 and 180 degrees.
  31. float GetPerpendicularAngle(float angle);
  32. // Assumes that the provided angle is between -180 and 180 degrees.
  33. // Returns a sizing cursor that is perpendicular to a line at that angle,
  34. // where a 0 degree line points to the right, and a 90 degree line points down.
  35. Qt::CursorShape GetSizingCursor(float angle);
  36. void TransformIconScale(AZ::Vector2& iconSize, const AZ::Matrix4x4& transform);
  37. AZ::Vector2 ComputeAnchorPoint(AZ::Vector2 rectTopLeft, AZ::Vector2 rectSize, float anchorX, float anchorY);
  38. // Determine whether the point is inside this region of the icon.
  39. // leftPart, rightPart, topPart, and bottomPart are [-0.5, 0.5], where 0.0 is
  40. // the center of the icon. They describe the portion of the icon to check.
  41. bool IsPointInIconRect(AZ::Vector2 point, AZ::Vector2 iconCenter, AZ::Vector2 iconSize, float leftPart, float rightPart, float topPart, float bottomPart);
  42. // Helper function to get the target points on the left and right sides of the rect to end anchor lines on.
  43. // If the given y value is within the y bounds of the rect, then the targets are as that y value,
  44. // otherwise they are at the the y value of the nearest edge.
  45. void GetHorizTargetPoints(const UiTransformInterface::RectPoints& elemRect, float y, AZ::Vector2& leftTarget, AZ::Vector2& rightTarget);
  46. // Helper function to get the points on the top and bottom sides of the rect to end anchor lines on.
  47. // If the given x value is within the x bounds of the rect, then the targets are as that x value,
  48. // otherwise they are at the the x value of the nearest edge.
  49. void GetVerticalTargetPoints(const UiTransformInterface::RectPoints& elemRect, float x, AZ::Vector2& topTarget, AZ::Vector2& bottomTarget);
  50. //-------------------------------------------------------------------------------
  51. //! Indicates which edges of an element are under consideration
  52. struct ElementEdges
  53. {
  54. ElementEdges()
  55. : m_left(false)
  56. , m_top(false)
  57. , m_right(false)
  58. , m_bottom(false) {}
  59. void SetAll(bool state) { m_left = m_right = m_top = m_bottom = state; }
  60. bool Any() const { return m_left || m_right || m_top || m_bottom; }
  61. bool None() const { return !Any(); }
  62. bool BothHorizontal() const { return m_left && m_right; }
  63. bool BothVertical() const { return m_top && m_bottom; }
  64. bool TopLeft() const { return m_top && m_left; }
  65. bool TopRight() const { return m_top && m_right; }
  66. bool BottomRight() const { return m_bottom && m_right; }
  67. bool BottomLeft() const { return m_bottom && m_left; }
  68. bool m_left;
  69. bool m_right;
  70. bool m_top;
  71. bool m_bottom;
  72. };
  73. //! Indicates which anchors of an element are under consideration
  74. struct SelectedAnchors
  75. {
  76. SelectedAnchors()
  77. : m_left(false)
  78. , m_top(false)
  79. , m_right(false)
  80. , m_bottom(false) {}
  81. SelectedAnchors(bool left, bool top, bool right, bool bottom)
  82. : m_left(left)
  83. , m_top(top)
  84. , m_right(right)
  85. , m_bottom(bottom) {}
  86. void SetAll(bool state) { m_left = m_right = m_top = m_bottom = state; }
  87. bool Any() const { return m_left || m_right || m_top || m_bottom; }
  88. bool All() const { return m_left && m_right && m_top && m_bottom; }
  89. bool TopLeft() const { return m_top && m_left; }
  90. bool TopRight() const { return m_top && m_right; }
  91. bool BottomRight() const { return m_bottom && m_right; }
  92. bool BottomLeft() const { return m_bottom && m_left; }
  93. bool m_left;
  94. bool m_right;
  95. bool m_top;
  96. bool m_bottom;
  97. };
  98. //! Indicates which parts of a transform gizmo are under consideration
  99. struct GizmoParts
  100. {
  101. GizmoParts()
  102. : m_top(false)
  103. , m_right(false) {}
  104. void SetBoth(bool state) { m_top = m_right = state; }
  105. bool Both() const { return m_right && m_top; }
  106. bool Single() const { return m_right ^ m_top; }
  107. bool m_top;
  108. bool m_right;
  109. };
  110. UiTransform2dInterface::Offsets MoveGrabbedEdges(const UiTransform2dInterface::Offsets& offset,
  111. const ViewportHelpers::ElementEdges& grabbedEdges,
  112. const AZ::Vector2& v);
  113. UiTransform2dInterface::Anchors MoveGrabbedAnchor(const UiTransform2dInterface::Anchors& anchor,
  114. const ViewportHelpers::SelectedAnchors& grabbedAnchors, bool keepTogetherHorizontally, bool keepTogetherVertically,
  115. const AZ::Vector2& v);
  116. void MoveGrabbedEdges(UiTransformInterface::RectPoints& points,
  117. const ViewportHelpers::ElementEdges& grabbedEdges,
  118. const AZ::Vector2& topEdge,
  119. const AZ::Vector2& leftEdge);
  120. //-------------------------------------------------------------------------------
  121. const char* InteractionModeToString(int mode);
  122. const char* CoordinateSystemToString(int s);
  123. const char* InteractionTypeToString(int type);
  124. void DrawRotationValue(const AZ::Entity* element,
  125. ViewportInteraction* viewportInteraction,
  126. const ViewportPivot* viewportPivot,
  127. Draw2dHelper& draw2d);
  128. void DrawCursorText(const AZStd::string& textLabel,
  129. Draw2dHelper& draw2d,
  130. const ViewportWidget* viewport);
  131. //-------------------------------------------------------------------------------
  132. } // namespace ViewportHelpers