예제 #1
0
 static VisualElement()
 {
     Symbol        = GetSymbol();
     runProperties = TextConfiguration.GetGlobalTextRunProperties();
     textSource    = new SimpleTextSource(Symbol, runProperties);
     charSize      = TextConfiguration.GetCharSize();
 }
예제 #2
0
        private void UpdateSize()
        {
            var maxLineLen = (from VisualTextLine line in visuals select line.RenderedText.Length).Concat(new[] { 0 }).Max();
            var charHeight = TextConfiguration.GetCharSize().Height;

            Width  = maxLineLen * TextConfiguration.GetCharSize().Width;
            Height = Convert.ToInt32(visuals.Count * charHeight);
        }
예제 #3
0
        private void UpdateSize()
        {
            var h = linesCount * TextConfiguration.GetCharSize().Height;

            if (h > ActualHeight)
            {
                Height = h;
            }
        }
예제 #4
0
        private bool CanExecuteMouseMove(MouseEventArgs mouseEvent)
        {
            var docPosition = mouseEvent.GetPosition(caretView).GetDocumentPosition(TextConfiguration.GetCharSize());

            if (docPosition.Line < 0 || docPosition.Line >= textViewReader.LinesCount)
            {
                return(false);
            }

            return(docPosition.Column >= 0);
        }
예제 #5
0
        public void Redraw(int num)
        {
            var fontColor  = SharedEditorConfiguration.GetLinesColumnFontColor();
            var typeface   = SharedEditorConfiguration.GetTypeface();
            var fontHeight = TextConfiguration.GetCharSize().Height;

            using (var drawingContext = RenderOpen()) {
                drawingContext.DrawText(
                    new FormattedText(num.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, fontHeight, fontColor),
                    new Point(0, fontHeight * (num - 1)));
            }
        }
예제 #6
0
        private void OnScrollChanged(object sender, ScrollChangedEventArgs evt)
        {
            if (evt.VerticalChange != 0)
            {
                var firstIdx = (int)Math.Round(evt.VerticalOffset / TextConfiguration.GetCharSize().Height);
                var lastIdx  = (int)Math.Round((evt.VerticalOffset + evt.ViewportHeight) / TextConfiguration.GetCharSize().Height);

                Postbox.InstanceFor(GetHashCode()).Put(new ScrollChangedMessage {
                    FirstVisibleLineIndex = firstIdx,
                    LastVisibleLineIndex  = lastIdx,
                    LinesScrolled         = Math.Abs((int)Math.Ceiling(evt.VerticalChange / TextConfiguration.GetCharSize().Height))
                });
            }
        }
예제 #7
0
        private void RedrawFolds()
        {
            visuals.Clear();

            foreach (var kvp in GetClosedFoldingInfos())
            {
                var symbol = new VisualElementSymbol();
                var top    = (int)kvp.Key.Position.GetPositionRelativeToParent(TextConfiguration.GetCharSize()).Y;

                symbol.DrawFolding(kvp.Key.State, top);

                visuals.Add(symbol);
            }
        }
예제 #8
0
        public SelectionInfo LineSelection(MouseButtonEventArgs mouseEvent)
        {
            var clickPosition = mouseEvent.GetPosition(parent).GetDocumentPosition(TextConfiguration.GetCharSize());
            var startPosition = new TextPosition(column: 0, line: clickPosition.Line);
            var endPosition   = new TextPosition(column: textViewReader.GetLineLength(clickPosition.Line), line: clickPosition.Line);
            var cursorColumn  = clickPosition.Line + 1 < textViewReader.LinesCount ? 0 : textViewReader.GetLineLength(clickPosition.Line);
            var cursorLine    = clickPosition.Line + 1 < textViewReader.LinesCount ? clickPosition.Line + 1 : clickPosition.Line;

            return(new SelectionInfo {
                StartPosition = startPosition,
                EndPosition = endPosition,
                CursorPosition = new TextPosition(column: cursorColumn, line: cursorLine)
            });
        }
        public override void Draw()
        {
            var runProperties = TextConfiguration.GetGlobalTextRunProperties();

            using (var drawingContext = RenderOpen()) {
                double top;

                using (var textLine = Formatter.FormatLine(new SimpleTextSource(textBeforeCollapse, runProperties), 0, 96 * 6, ParagraphProperties, null)) {
                    top = Index * textLine.Height;

                    textLine.Draw(drawingContext, new Point(0, top), InvertAxes.None);
                }
                using (var textLine = Formatter.FormatLine(new SimpleTextSource(collapseRepresentation, runProperties), 0, 96 * 6, ParagraphProperties, null)) {
                    textLine.Draw(drawingContext, new Point(TextConfiguration.GetCharSize().Width *textBeforeCollapse.Length, top), InvertAxes.None);
                }
                using (var textLine = Formatter.FormatLine(new SimpleTextSource(textAfterCollapse, runProperties), 0, 96 * 6, ParagraphProperties, null)) {
                    textLine.Draw(drawingContext,
                                  new Point(TextConfiguration.GetCharSize().Width *textBeforeCollapse.Length + TextConfiguration.GetCharSize().Width *collapseRepresentation.Length, top),
                                  InvertAxes.None);
                }
            }
        }
예제 #10
0
        public void Execute(object parameter)
        {
            var          keyboardEvent = parameter as KeyEventArgs;
            var          mouseEvent    = parameter as MouseButtonEventArgs;
            TextPosition newPos        = null;

            if (keyboardEvent != null)
            {
                newPos = caretView.GetNextPosition(keyboardEvent.Key);
                keyboardEvent.Handled = true;
            }
            else if (mouseEvent != null)
            {
                newPos = mouseEvent.GetPosition(caretView).GetDocumentPosition(TextConfiguration.GetCharSize());
            }
            if (newPos == null)
            {
                return;
            }

            int column = -1, line = -1;

            if (newPos.Column > textViewReader.GetLineLength(newPos.Line))
            {
                column = textViewReader.GetLineLength(newPos.Line);
            }
            if (newPos.Line >= textViewReader.LinesCount)
            {
                line = textViewReader.LinesCount - 1;
            }

            var moveDir = GetMoveDirection(newPos, caretView.CaretPosition);

            newPos = new TextPosition(column > -1 ? column : newPos.Column, line > -1 ? line : newPos.Line);
            newPos = textViewReader.AdjustStep(newPos, moveDir);

            caretView.MoveCursor(newPos);
        }
예제 #11
0
        public SelectionInfo WordSelection(MouseButtonEventArgs mouseEvent)
        {
            var clickPosition = mouseEvent.GetPosition(parent).GetDocumentPosition(TextConfiguration.GetCharSize());
            var activeLine    = textViewReader.GetVisualLine(clickPosition.Line);
            var lineLength    = textViewReader.GetLineLength(clickPosition.Line);

            int[] selectionRange;

            if (!activeLine.GetCharInfoAt(clickPosition.Column).IsCharacter)
            {
                selectionRange = GetCollapseSelectionRange(clickPosition, activeLine, lineLength);
            }
            else
            {
                selectionRange = GetStandardWordSelectionRange(clickPosition, activeLine, lineLength);
            }

            return(new SelectionInfo {
                StartPosition = new TextPosition(column: selectionRange[0], line: clickPosition.Line),
                EndPosition = new TextPosition(column: selectionRange[1], line: clickPosition.Line),
                CursorPosition = new TextPosition(column: selectionRange[1], line: clickPosition.Line)
            });
        }
예제 #12
0
        private IEnumerable <PointsPair> GetSelectionPointsForward(TextPosition start, TextPosition end)
        {
            var pairs = new List <PointsPair>();

            for (var i = start.Line; i <= end.Line; i++)
            {
                var tmpStartColumn = 0;
                var tmpStartLine   = i;
                var tmpEndColumn   = 0;
                var tmpEndLine     = i;

                if (i == start.Line)
                {
                    tmpStartColumn = start.Column;
                }

                var lineLen = textViewReader.GetLineLength(i);

                if (i == end.Line)
                {
                    tmpEndColumn = end.Column > lineLen ? lineLen : end.Column;
                }
                else
                {
                    tmpEndColumn = lineLen;
                }

                pairs.Add(new PointsPair {
                    StartingPoint = (new TextPosition(column: tmpStartColumn, line: tmpStartLine)).GetPositionRelativeToParent(TextConfiguration.GetCharSize())
                                    .AlignToVisualLineTop(TextConfiguration.GetCharSize()),
                    EndingPoint = (new TextPosition(column: tmpEndColumn, line: tmpEndLine)).GetPositionRelativeToParent(TextConfiguration.GetCharSize())
                                  .AlignToVisualLineBottom(TextConfiguration.GetCharSize())
                });
            }

            return(pairs);
        }
예제 #13
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            var position = e.GetPosition(this).GetDocumentPosition(TextConfiguration.GetCharSize());

            RunFoldingOnClick(position);
        }
예제 #14
0
 public TextPosition StandardSelection(MouseEventArgs mouseEvent) => mouseEvent.GetPosition(parent).GetDocumentPosition(TextConfiguration.GetCharSize());
 private bool CanExecuteMouse(MouseEventArgs mouseEvent) =>
 mouseEvent.LeftButton == MouseButtonState.Pressed &&
 textViewReader.IsInTextRange(mouseEvent.GetPosition(caretView).GetDocumentPosition(TextConfiguration.GetCharSize()));