Example #1
0
        static ReLineTransformSource()
        {
            _transformDefault = new LineTransform(0, 0, 1);
            _transformToSmall = new LineTransform(0, 0, 0.75);

            //Dictionary<fieldname, Dictionary<ReplaceThisValue, WithThatValue>>
            //The replace Function will be executed more than once...
            //Prevent the double execution with small differences like 0.001
            _replaceOriginalVars = new Dictionary <string, Dictionary <double, double> >()
            {
                { "_height", new Dictionary <double, double>() //Line height
                  {
                      { 13, 11 },                              //small transformed lines
                      { 16, 13.001 },                          //normal lines
                      //{ 29, 26 }, //lines with codelens //Does bounce while writing code
                  } },
                { "_topSpace", new Dictionary <double, double>()
                  {
                      //{ 13, 12 }, //space after line with codelens //Does bounce while writing code
                  } },
                { "_textHeight", new Dictionary <double, double>()
                  {
                      //{ 12, 11 }, //small transformed lines //Does bounce while writing code
                      //{ 15, 14 }, //normal lines //Does bounce while writing code
                  } },
            };
        }
Example #2
0
    public LineTransform GetLineTransform(CellSide side)
    {
        LineTransform line = new LineTransform();

        switch (side)
        {
        case CellSide.Left:
            line.Position = this.left;
            line.Rotation = this.verticalRotation;
            break;

        case CellSide.Right:
            line.Position = this.right;
            line.Rotation = this.verticalRotation;
            break;

        case CellSide.Bottom:
            line.Position = this.bottom;
            line.Rotation = Quaternion.identity;
            break;

        default:
            line.Position = this.top;
            line.Rotation = Quaternion.identity;
            break;
        }

        return(line);
    }
        /// <summary>
        /// Sets a point in the line
        /// This function is not guaranteed to have an effect
        /// </summary>
        /// <param name="pointIndex"></param>
        /// <param name="point"></param>
        public void SetPoint(int pointIndex, Vector3 point)
        {
            if (pointIndex < 0 || pointIndex >= PointCount)
            {
                Debug.LogError("Invalid point index");
                return;
            }

            SetPointInternal(pointIndex, LineTransform.InverseTransformPoint(point));
        }
        /// <summary>
        /// Gets a point along the line at the specified index
        /// </summary>
        /// <param name="pointIndex"></param>
        /// <returns></returns>
        public Vector3 GetPoint(int pointIndex)
        {
            if (pointIndex < 0 || pointIndex >= PointCount)
            {
                Debug.LogError("Invalid point index");
                return(Vector3.zero);
            }

            return(LineTransform.TransformPoint(GetPointInternal(pointIndex)));
        }
        private void SetTransforms()
        {
            var lineHeight  = textView?.TextViewLines?.FirstVisibleLine?.TextHeight ?? 10d;
            var lineSpacing = (double)settings.LineSpacingPercent;
            var pixelSpace  = settings.LineSpacingPercent != 0 ? Math.Round(lineHeight * lineSpacing / 200d) : 0d;

            lineSpacingTransform  = new LineTransform(pixelSpace, pixelSpace, 1d);
            emptyLineTransform    = new LineTransform(0d, 0d, EmptyLineScale);
            customTokensTransform = new LineTransform(0d, 0d, CustomTokensScale);
        }
        private Vector3 TransformPoint(Vector3 point)
        {
            switch (transformMode)
            {
            case LinePointTransformMode.UseTransform:
            default:
                return(LineTransform.TransformPoint(point));

            case LinePointTransformMode.UseMatrix:
                return(localToWorldMatrix.MultiplyPoint3x4(point));
            }
        }
Example #7
0
            public LineTransform GetLineTransform(ITextViewLine line, double yPosition, ViewRelativePosition placement)
            {
                var transform = removeExtraTextLineVerticalPixels ?
                                new LineTransform(0, 0, line.DefaultLineTransform.VerticalScale, line.DefaultLineTransform.Right) :
                                line.DefaultLineTransform;

                foreach (var source in lineTransformSources)
                {
                    transform = LineTransform.Combine(transform, source.GetLineTransform(line, yPosition, placement));
                }
                return(transform);
            }
        private Vector3 InverseTransformPoint(Vector3 point)
        {
            switch (transformMode)
            {
            case LinePointTransformMode.UseTransform:
            default:
                return(LineTransform.InverseTransformPoint(point));

            case LinePointTransformMode.UseMatrix:
                return(worldToLocalMatrix.MultiplyPoint3x4(point));
            }
        }
Example #9
0
    public void HighlightSide(GameObject prefab, LineTransform line)
    {
        if (this.lineHighlight != null && this.lineHighlight.GetComponent <RectTransform>().position == line.Position)
        {
            return;
        }

        Destroy(this.lineHighlight);

        this.lineHighlight = Instantiate(prefab, line.Position, line.Rotation);

        RectTransform lineHighlightRect = this.lineHighlight.GetComponent <RectTransform>();

        lineHighlightRect.SetParent(this.GetComponent <RectTransform>());
        lineHighlightRect.localScale = new Vector3(1, 0.333f);
    }
Example #10
0
        public void SetLineTransform(LineTransform transform)
        {
            if (!IsValid)
            {
                throw new ObjectDisposedException(nameof(WpfTextViewLine));
            }
            var  oldScaledTopSpace = scaledTopSpace;
            bool resetTransform    = lineTransform.VerticalScale != transform.VerticalScale;

            lineTransform    = transform;
            scaledTopSpace   = Math.Ceiling(Math.Max(transform.TopSpace, realTopSpace) * transform.VerticalScale);
            scaledTextHeight = Math.Ceiling(realTextHeight * transform.VerticalScale);
            scaledHeight     = scaledTextHeight + scaledTopSpace + Math.Ceiling(Math.Max(transform.BottomSpace, realBottomSpace) * transform.VerticalScale);
            if (resetTransform || scaledTopSpace != oldScaledTopSpace)
            {
                UpdateVisualTransform();
            }
        }
Example #11
0
        LineTransform ILineTransformSource.GetLineTransform(ITextViewLine line, double yPosition, ViewRelativePosition placement)
        {
            int           lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
            LineTransform lineTransform;

            if (this.manager.DisplayedTextBlocks.ContainsKey(lineNumber) &&
                this.manager.DisplayedTextBlocks[lineNumber].Count > 0)
            {
                var spaceAboveLine = line.DefaultLineTransform.TopSpace + ((ConstVisualizerPackage.Instance.Options.TopPadding + ConstVisualizerPackage.Instance.Options.BottomPadding) * Constants.TextBlockSizeToFontScaleFactor);
                var spaceBelowLine = line.DefaultLineTransform.BottomSpace;
                lineTransform = new LineTransform(spaceAboveLine + ResourceAdornmentManager.TextSize, spaceBelowLine, 1.0);
            }
            else
            {
                lineTransform = new LineTransform(0, 0, 1.0);
            }

            return(lineTransform);
        }
Example #12
0
        LineTransform ILineTransformSource.GetLineTransform(ITextViewLine line, double yPosition, ViewRelativePosition placement)
        {
            int           lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
            LineTransform lineTransform;

            // TODO: Don't show if line is collapsed. Issue #3
            if (this.manager.DisplayedTextBlocks.ContainsKey(lineNumber))
            {
                var defaultTopSpace    = line.DefaultLineTransform.TopSpace;
                var defaultBottomSpace = line.DefaultLineTransform.BottomSpace;
                lineTransform = new LineTransform(defaultTopSpace + ResourceAdornmentManager.TextSize, defaultBottomSpace, 1.0);
            }
            else
            {
                lineTransform = new LineTransform(0, 0, 1.0);
            }

            return(lineTransform);
        }
        public LineTransform GetLineTransform(ITextViewLine line, double yposition, ViewRelativePosition placement)
        {
            // Vertically compress lines that are far from the caret (based on buffer lines, not view lines).
            ITextSnapshot snapshot        = this.textView.TextSnapshot;
            int           caretLineNumber = snapshot.GetLineNumberFromPosition(this.textView.Caret.Position.BufferPosition);
            int           lineNumber      = snapshot.GetLineNumberFromPosition(line.Start);
            int           delta           = Math.Abs(caretLineNumber - lineNumber);

            // Idea: Provide options to control these factors. [Bill, 7/17/2015]
            // Idea: Optionally, compress whitespace and non-alphanumeric lines more. [Bill, 7/17/2015]
            const int    Group1Lines          = 3;
            const int    Group2Lines          = Group1Lines + 5;
            const int    Group3Lines          = Group2Lines + 10;
            const double Group1ScaleFactor    = 1.0;
            const double Group2ScaleFactor    = 0.9;
            const double Group3ScaleFactor    = 0.8;
            const double Group2ScaleDecrement = (Group1ScaleFactor - Group2ScaleFactor) / (Group2Lines - Group1Lines);
            const double Group3ScaleDecrement = (Group2ScaleFactor - Group3ScaleFactor) / (Group3Lines - Group2Lines);

            double scale;

            if (delta <= Group1Lines)
            {
                scale = Group1ScaleFactor;
            }
            else if (delta <= Group2Lines)
            {
                scale = Group1ScaleFactor - ((delta - (double)Group1Lines) * Group2ScaleDecrement);
            }
            else if (delta <= Group3Lines)
            {
                scale = Group2ScaleFactor - ((delta - (double)Group2Lines) * Group3ScaleDecrement);
            }
            else
            {
                scale = Group3ScaleFactor;
            }

            LineTransform result = new LineTransform(0.0, 0.0, scale);

            return(result);
        }
        protected override void OnRenderPoint(int index, BoundaryVertex point, Vector3 pos, float handleSize)
        {
            EventType eventType = Event.current.type;
            int       arrowId   = GUIUtility.GetControlID(FocusType.Passive);
            Vector3   dir       = LineTransform.TransformDirection(point.Normal);

            RenderNormal(pos, dir, eventType, arrowId);
            if (eventType == EventType.MouseDown)
            {
                if (HandleUtility.nearestControl == arrowId)
                {
                    selectedNormalIndex = index;
                    SelectPoint(index, notify: false);
                }
            }
            if (selectedNormalIndex != index)
            {
                return;
            }

            EditorGUI.BeginChangeCheck();
            Vector3 destination = Handles.DoPositionHandle(pos + dir, HandleTransform);

            destination = LineTransform.InverseTransformPoint(destination);
            if (!EditorGUI.EndChangeCheck())
            {
                return;
            }

            Undo.RecordObject(Line, "Move Normal");
            EditorUtility.SetDirty(Line);
            point.Normal = destination - point.Position;
            float sqrMagnitude = point.Normal.sqrMagnitude;

            // Don't normalize if less that 1 to avoid glitchy movement
            if (sqrMagnitude > 1)
            {
                point.Normal /= Mathf.Sqrt(sqrMagnitude);
            }
            Line.SetPoint(index, point);
        }
        /// <summary>
        /// Gets the rotation of a point along the line at the specified length
        /// </summary>
        /// <param name="normalizedLength"></param>
        /// <param name="lineRotationMode"></param>
        /// <returns></returns>
        public Quaternion GetRotation(float normalizedLength, LineRotationMode lineRotationMode = LineRotationMode.None)
        {
            lineRotationMode = (lineRotationMode != LineRotationMode.None) ? lineRotationMode : rotationMode;
            Vector3 rotationVector = Vector3.zero;

            switch (lineRotationMode)
            {
            case LineRotationMode.Velocity:
                rotationVector = GetVelocity(normalizedLength);
                break;

            case LineRotationMode.RelativeToOrigin:
                Vector3 point  = GetPoint(normalizedLength);
                Vector3 origin = LineTransform.TransformPoint(originOffset);
                rotationVector = (point - origin).normalized;
                break;

            case LineRotationMode.None:
                break;
            }

            if (rotationVector.magnitude < MinRotationMagnitude)
            {
                return(LineTransform.rotation);
            }

            Vector3 upVector = GetUpVectorInternal(normalizedLength);

            if (manualUpVectorBlend > 0f)
            {
                Vector3 manualUpVector = LineUtility.GetVectorCollectionBlend(manualUpVectors, normalizedLength, Loops);
                upVector = Vector3.Lerp(upVector, manualUpVector, manualUpVector.magnitude);
            }

            if (flipUpVector)
            {
                upVector = -upVector;
            }

            return(Quaternion.LookRotation(rotationVector, upVector));
        }
        LineTransform ILineTransformSource.GetLineTransform(ITextViewLine line, double yPosition, ViewRelativePosition placement)
        {
#pragma warning disable 219
            bool imageOnLine = false; // useful for tracing
#pragma warning restore 219

            int           lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
            LineTransform lineTransform;

            // Look up Image for current line and increase line height as necessary
            if (_manager.Images.ContainsKey(lineNumber) && ImageAdornmentManager.Enabled)
            {
                double       defaultHeight = line.DefaultLineTransform.BottomSpace;
                CommentImage image         = _manager.Images[lineNumber];
                lineTransform = new LineTransform(0, image.Height + defaultHeight, 1.0);

                imageOnLine = true;
            }
            else
            {
                lineTransform = new LineTransform(0, 0, 1.0);
            }
            return(lineTransform);
        }
        LineTransform ILineTransformSource.GetLineTransform(ITextViewLine line, double yPosition, ViewRelativePosition placement)
        {
            #pragma warning disable 219
            bool imageOnLine = false; // useful for tracing
            #pragma warning restore 219

            int lineNumber = line.Snapshot.GetLineFromPosition(line.Start.Position).LineNumber;
            LineTransform lineTransform;

            // Look up Image for current line and increase line height as necessary
            if (_manager.Images.ContainsKey(lineNumber) && ImageAdornmentManager.Enabled)
            {
                double defaultHeight = line.DefaultLineTransform.BottomSpace;
                MyImage image = _manager.Images[lineNumber];
                lineTransform = new LineTransform(0, image.Height + defaultHeight, 1.0);

                imageOnLine = true;
            }
            else
            {
                lineTransform = new LineTransform(0, 0, 1.0);
            }
            return lineTransform;
        }
 public void SetLineTransform(LineTransform transform)
 {
     throw new NotImplementedException();
 }
Example #19
0
    public void SelectSide(GameObject prefab, CellSide side)
    {
        LineTransform line = this.GetLineTransform(side);

        GameObject selectionLine = Instantiate(prefab, line.Position, line.Rotation);

        RectTransform selectionLineRect = selectionLine.GetComponent <RectTransform>();

        selectionLineRect.SetParent(GetComponent <RectTransform>());
        selectionLineRect.localScale = new Vector3(1, 0.333f);

        Cell neighbourCell = null;

        switch (side)
        {
        case CellSide.Left:
            this.leftLine = selectionLine;
            if (this.Column > 0)
            {
                neighbourCell = this.gameMaster.Cells[this.Row][this.Column - 1];
            }

            break;

        case CellSide.Right:
            this.rightLine = selectionLine;
            if (this.Column < this.gameMaster.Cells.Count - 1)
            {
                neighbourCell = this.gameMaster.Cells[this.Row][this.Column + 1];
            }

            break;

        case CellSide.Bottom:
            this.bottomLine = selectionLine;
            if (this.Row < this.gameMaster.Cells.Count - 1)
            {
                neighbourCell = this.gameMaster.Cells[this.Row + 1][this.Column];
            }

            break;

        default:
            this.topLine = selectionLine;
            if (this.Row > 0)
            {
                neighbourCell = this.gameMaster.Cells[this.Row - 1][this.Column];
            }

            break;
        }

        bool isNeighboutClosed = false;

        if (neighbourCell != null)
        {
            isNeighboutClosed = neighbourCell.IsUpdatedNeighbourClosed(side, selectionLine);
        }

        if (this.IsClosed())
        {
            this.SetOwner();
            return;
        }

        if (isNeighboutClosed)
        {
            return;
        }

        this.gameMaster.UpdateTurn();
    }
Example #20
0
 private void SetTransforms()
 {
     emptyLineTransform    = new LineTransform(0d, 0d, (100d - settings.EmptyLineScale) / 100d);
     customTokensTransform = new LineTransform(0d, 0d, (100d - settings.CustomTokensScale) / 100d);
 }
Example #21
0
		public void SetLineTransform(LineTransform transform) {
			if (!IsValid)
				throw new ObjectDisposedException(nameof(WpfTextViewLine));
			var oldScaledTopSpace = scaledTopSpace;
			bool resetTransform = lineTransform.VerticalScale != transform.VerticalScale;
			lineTransform = transform;
			scaledTopSpace = Math.Ceiling(Math.Max(transform.TopSpace, realTopSpace) * transform.VerticalScale);
			scaledTextHeight = Math.Ceiling(realTextHeight * transform.VerticalScale);
			scaledHeight = scaledTextHeight + scaledTopSpace + Math.Ceiling(Math.Max(transform.BottomSpace, realBottomSpace) * transform.VerticalScale);
			if (resetTransform || scaledTopSpace != oldScaledTopSpace)
				UpdateVisualTransform();
		}
 /// <summary>
 /// Gets a point along the line at the specified length without using LineStartClamp or LineEndClamp
 /// </summary>
 /// <param name="normalizedLength"></param>
 /// <returns></returns>
 public Vector3 GetUnClampedPoint(float normalizedLength)
 {
     normalizedLength = Mathf.Clamp01(normalizedLength);
     return(DistortPoint(LineTransform.TransformPoint(GetPointInternal(normalizedLength)), normalizedLength));
 }