Exemple #1
0
        private RectangleF getDocumentArea(Graphics g, RectangleF typingArea, SizeF cellSize)
        {
            RectangleF unlimitedHeightArea = getUnlimitedHeightArea(typingArea);

            RectangleF cursorArea      = getCursorCharArea(g, unlimitedHeightArea);
            Point      cursorColumnRow = getColumnRow(cursorArea.Location, unlimitedHeightArea.Location, cellSize);

            oldCursorPositionChangedEventArgs = Util.RaiseIfEventArgsChanged(
                OnCursorPositionChanged,
                new CursorPositionChangedEventArgs(cursorColumnRow.Y + 1, cursorColumnRow.X + 1),
                oldCursorPositionChangedEventArgs);

            int currentLineColumns = ImportedText.LineLength(TypedText.Length);

            Size documentColumnsRows = new Size(ImportedText.LongestLineLength,
                                                getDocumentRows(g, unlimitedHeightArea, cellSize));

            Size visibleColumnsRows = getVisibleColumnsRows(typingArea.Size, cellSize);

            float hOffset = cellSize.Width * calcColumnOffset(cursorColumnRow.X, visibleColumnsRows.Width, documentColumnsRows.Width,
                                                              currentLineColumns),
                  vOffset = cellSize.Height * calcRowOffset(cursorColumnRow.Y, visibleColumnsRows.Height, documentColumnsRows.Height);

            return(new RectangleF(typingArea.X + hOffset,
                                  typingArea.Y + vOffset,
                                  typingArea.Width,
                                  typingArea.Height - vOffset));
        }
Exemple #2
0
        private int calcColumnOffset(int cursorColumn, int visibleColumns, int documentColumns, int currentLineColumns)
        {
            int columnOffset;

            if (WordWrap)
            {
                visibleColumns += 1;

                columnOffset = Math.Min(0, visibleColumns - 1 - cursorColumn);

                int extraColumns = 0;

                if (cursorColumn >= visibleColumns - 1)
                {
                    extraColumns = -columnOffset + Math.Max(0, ImportedText.CountSpaces(TypedText.Length) - 1);
                }

                documentColumns = visibleColumns + extraColumns;
            }
            else
            {
                const int visibleColumnsBeforeJumpBack = 6;

                int jumpBackZone = Math.Max(1, visibleColumns - (visibleColumns / 2) + 2 - visibleColumnsBeforeJumpBack);

                columnOffset = calculateOffset(cursorColumn, visibleColumns, currentLineColumns, jumpBackZone);
            }

            var horizontalEventArgs = createVisibleRegionChangedEventArgs(columnOffset, visibleColumns, documentColumns);

            oldHorizontalEventArgs = Util.RaiseIfEventArgsChanged(OnHorizontalVisibleRegionChanged,
                                                                  horizontalEventArgs,
                                                                  oldHorizontalEventArgs);

            return(columnOffset);
        }