Ejemplo n.º 1
0
 /// <summary>
 /// Determines whether the position is at the beginning of the line.
 /// </summary>
 /// <param name="bufferPosition">The buffer position.</param>
 /// <param name="buffer">The buffer.</param>
 /// <returns>
 ///   <c>true</c> if [is beginning of buffer] [the specified buffer]; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsBeginningOfBuffer(
     this TextPosition bufferPosition,
     EditorViewRenderer buffer)
 {
     return(bufferPosition.LinePosition == 0 &&
            bufferPosition.CharacterPosition == 0);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Determines whether this position represents the last line in the buffer.
 /// </summary>
 /// <param name="lineLayoutBuffer">The line layout buffer.</param>
 /// <returns>
 ///     <c>true</c> if [is last line in buffer] [the specified line layout buffer]; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsLastLineInBuffer(
     this TextPosition bufferPosition,
     EditorViewRenderer lineLayoutBuffer)
 {
     return(bufferPosition.LinePosition
            == lineLayoutBuffer.LineBuffer.LineCount - 1);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Determines whether the position is at the end of the buffer.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <returns>
 ///     <c>true</c> if [is end of buffer] [the specified buffer]; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsEndOfBuffer(
     this TextPosition bufferPosition,
     EditorViewRenderer buffer)
 {
     return(bufferPosition.LinePosition == buffer.LineBuffer.LineCount - 1 &&
            bufferPosition.IsEndOfLine(buffer));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Determines whether the position is at the end of the line.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 /// <returns>
 ///     <c>true</c> if [is end of line] [the specified buffer]; otherwise, <c>false</c>.
 /// </returns>
 public static bool IsEndOfLine(
     this TextPosition bufferPosition,
     EditorViewRenderer buffer)
 {
     return(bufferPosition.CharacterPosition
            == buffer.LineBuffer.GetLineLength(
                bufferPosition.LinePosition, LineContexts.Unformatted));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Moves the position to the end of line.
 /// </summary>
 /// <param name="bufferPosition">The buffer position.</param>
 /// <param name="buffer">The buffer.</param>
 /// <returns></returns>
 public static TextPosition ToEndOfLine(
     this TextPosition bufferPosition,
     EditorViewRenderer buffer)
 {
     return(new TextPosition(
                bufferPosition.LinePosition,
                buffer.LineBuffer.GetLineLength(
                    bufferPosition.LinePosition, LineContexts.Unformatted)));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Moves the position to the end of buffer.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        public static TextPosition ToEndOfBuffer(
            this TextPosition bufferPosition,
            EditorViewRenderer buffer)
        {
            int endLineIndex = buffer.LineBuffer.LineCount - 1;

            return(new TextPosition(
                       endLineIndex,
                       buffer.LineBuffer.GetLineLength(endLineIndex, LineContexts.Unformatted)));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorViewRendererDecorator"/> class.
        /// </summary>
        /// <param name="displayContext">The display context.</param>
        /// <param name="editorViewRenderer">The text renderer.</param>
        protected EditorViewRendererDecorator(
            IDisplayContext displayContext,
            EditorViewRenderer editorViewRenderer)
            : base(displayContext)
        {
            EditorViewRenderer = editorViewRenderer;

            if (editorViewRenderer == null)
            {
                throw new ArgumentNullException("editorViewRenderer");
            }
        }
 /// <summary>
 /// Sets the line buffer since the renderer.
 /// </summary>
 /// <param name="value">The value.</param>
 public override void SetLineBuffer(LineBuffer value)
 {
     EditorViewRenderer.SetLineBuffer(value);
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Converts the given line and character coordinates into pixel coordinates
        /// on the display.
        /// </summary>
        /// <param name="bufferPosition">The buffer position.</param>
        /// <param name="displayContext">The display context.</param>
        /// <param name="lineHeight">Will contains the height of the current line.</param>
        /// <returns></returns>
        public static PointD ToScreenCoordinates(
            this TextPosition bufferPosition,
            IDisplayContext displayContext,
            out int lineHeight)
        {
            // Get the line index, which needs to be a number in range.
            EditorViewRenderer buffer = displayContext.Renderer;
            int lineIndex             =
                bufferPosition.LinePosition.GetLineIndex(displayContext.LineBuffer);

            // Pull out some of the common things we'll be using in this method.
            int    bufferLineIndex = buffer.LineBuffer.NormalizeLineIndex(lineIndex);
            Layout layout          = buffer.GetLineLayout(
                bufferLineIndex, LineContexts.Unformatted);
            LineBlockStyle style = buffer.GetLineStyle(
                bufferLineIndex, LineContexts.Unformatted);

            // Figure out the top of the current line in relation to the entire
            // buffer and view. For lines beyond the first, we use
            // GetLineLayoutHeight because it also takes into account the line
            // spacing and borders which we would have to calculate otherwise.
            double y = bufferLineIndex == 0
                                ? 0
                                : buffer.GetLineLayoutHeight(0, bufferLineIndex - 1);

            // Add the style offset for the top-padding.
            y += style.Top;

            // The cursor position code uses Unicode instead of C# character
            // positions. This means we have to advance more than just one
            // value to calculate it. This actually uses UTF-8 encoding to
            // calculate the indexes.
            string lineText       = displayContext.LineBuffer.GetLineText(lineIndex);
            int    characterIndex =
                bufferPosition.GetCharacterIndex(displayContext.LineBuffer);
            int unicodeCharacter = PangoUtility.TranslateStringToPangoIndex(
                lineText, characterIndex);

            // We need to figure out the relative position. If the position equals
            // the length of the string, we want to put the caret at the end of the
            // character. Otherwise, we put it on the front of the character to
            // indicate insert point.
            bool trailing   = false;
            int  lineLength = buffer.LineBuffer.GetLineLength(
                bufferLineIndex, LineContexts.Unformatted);

            if (unicodeCharacter == lineLength)
            {
                // Shift back one character to calculate the position and put
                // the cursor at the end of the character.
                unicodeCharacter--;
                trailing = true;
            }

            // Figure out which wrapped line we are actually on and the position
            // inside that line. If the character equals the length of the string,
            // then we want to move to the end of it.
            int wrappedLineIndex;
            int layoutX;

            layout.IndexToLineX(
                unicodeCharacter, trailing, out wrappedLineIndex, out layoutX);

            // Get the relative offset into the wrapped lines.
            Rectangle layoutPoint = layout.IndexToPos(unicodeCharacter);

            y += Units.ToPixels(layoutPoint.Y);

            // Get the height of the wrapped line.
            Rectangle ink     = Rectangle.Zero;
            Rectangle logical = Rectangle.Zero;

            layout.Lines[wrappedLineIndex].GetPixelExtents(ref ink, ref logical);
            lineHeight = logical.Height;

            // Return the results.
            return(new PointD(Units.ToPixels(layoutX), y));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Moves the position to the beginning of line.
 /// </summary>
 /// <param name="buffer">The buffer.</param>
 public static TextPosition ToBeginningOfLine(
     this TextPosition bufferPosition,
     EditorViewRenderer buffer)
 {
     return(new TextPosition(bufferPosition.LinePosition, 0));
 }