protected float HandleBorderScaleSlider(float x, float y, float width, float height, bool isHorizontal)
        {
            float   handleSize = styles.dragBorderdot.fixedWidth;
            Vector2 point      = Handles.matrix.MultiplyPoint(new Vector2(x, y));
            float   result;

            EditorGUI.BeginChangeCheck();

            if (isHorizontal)
            {
                Rect newRect = new Rect(point.x - handleSize * .5f, point.y, handleSize, height);
                result = SpriteEditorHandles.ScaleSlider(point, MouseCursor.ResizeHorizontal, newRect).x;
            }
            else
            {
                Rect newRect = new Rect(point.x, point.y - handleSize * .5f, width, handleSize);
                result = SpriteEditorHandles.ScaleSlider(point, MouseCursor.ResizeVertical, newRect).y;
            }

            if (EditorGUI.EndChangeCheck())
            {
                return(result);
            }

            return(isHorizontal ? x : y);
        }
Example #2
0
 private void HandleCreate()
 {
     if (!MouseOnTopOfInspector() && !eventSystem.current.alt)
     {
         // Create new rects via dragging in empty space
         EditorGUI.BeginChangeCheck();
         Rect newRect = SpriteEditorHandles.RectCreator(textureActualWidth, textureActualHeight, styles.createRect);
         if (EditorGUI.EndChangeCheck() && newRect.width > 0f && newRect.height > 0f)
         {
             CreateSprite(newRect);
             GUIUtility.keyboardControl = 0;
         }
     }
 }
        protected void HandleBorderPointSlider(ref float x, ref float y, MouseCursor mouseCursor, bool isHidden, GUIStyle dragDot, GUIStyle dragDotActive, Color color)
        {
            var originalColor = GUI.color;

            if (isHidden)
            {
                GUI.color = new Color(0, 0, 0, 0);
            }
            else
            {
                GUI.color = color;
            }

            Vector2 point = SpriteEditorHandles.PointSlider(new Vector2(x, y), mouseCursor, dragDot, dragDotActive);

            x = point.x;
            y = point.y;

            GUI.color = originalColor;
        }
        protected void HandlePivotHandle()
        {
            if (!hasSelected)
            {
                return;
            }

            EditorGUI.BeginChangeCheck();

            SpriteAlignment alignment = selectedSpriteAlignment;
            Vector2         pivot     = selectedSpritePivot;
            Rect            rect      = selectedSpriteRect;

            pivot = ApplySpriteAlignmentToPivot(pivot, rect, alignment);
            Vector2 pivotHandlePosition = SpriteEditorHandles.PivotSlider(rect, pivot, styles.pivotdot, styles.pivotdotactive);

            if (EditorGUI.EndChangeCheck())
            {
                // Pivot snapping only happen when ctrl is press. Same as scene view snapping move
                if (eventSystem.current.control)
                {
                    SnapPivotToSnapPoints(pivotHandlePosition, out pivot, out alignment);
                }
                else if (m_PivotUnitMode == PivotUnitMode.Pixels)
                {
                    SnapPivotToPixels(pivotHandlePosition, out pivot, out alignment);
                }
                else
                {
                    pivot     = pivotHandlePosition;
                    alignment = SpriteAlignment.Custom;
                }
                SetSpritePivotAndAlignment(pivot, alignment);
                PopulateSpriteFrameInspectorField();
            }
        }
Example #5
0
        private void HandleDragging()
        {
            if (hasSelected && !MouseOnTopOfInspector())
            {
                Rect textureBounds = new Rect(0, 0, textureActualWidth, textureActualHeight);
                EditorGUI.BeginChangeCheck();

                Rect oldRect = selectedSpriteRect;
                Rect newRect = SpriteEditorUtility.ClampedRect(SpriteEditorUtility.RoundedRect(SpriteEditorHandles.SliderRect(oldRect)), textureBounds, true);

                if (EditorGUI.EndChangeCheck())
                {
                    selectedSpriteRect = newRect;
                    UpdatePositionField(null);
                }
            }
        }