//[Test]
        public void TestCharPosition01()
        {
            //Test to make sure origin is correct
            //Character coordinates input: (0,0)
            //Screen coordinates expected: (Configurations.LeftMargin, 0)

            coordinates.SetCharacterPosition(new System.Drawing.Point(0, 0));
            Assert.IsTrue((System.Windows.Point)coordinates.GetScreenPosition() == new Point(Configurations.CanvasMarginLeft, 0));
        }
        internal void UpdateCaretPosition(bool ensureCursorVisible = true)
        {
            if (null == Solution.Current.ActiveScript)
            {
                return;
            }

            IScriptObject activeScript = Solution.Current.ActiveScript;
            CharPosition  converter    = activeScript.CreateCharPosition();

            System.Drawing.Point cursorPosition = textCore.CursorPosition;
            converter.SetCharacterPosition(cursorPosition);
            textCanvas.SetCursorScreenPos(converter.GetScreenPosition());
            if (ensureCursorVisible == true)
            {
                textCanvas.EnsureCursorVisible(cursorPosition.X, cursorPosition.Y);
            }

            // As the caret is moved around, more often than never the selection also
            // gets changed. It would make sense to update the visual here at the same time.
            textCanvas.SetSelectionRange(textCore.SelectionStart, textCore.SelectionEnd);

            // @TODO(Salman) merge these into one label control.
            LineCol.Text = "Line: " + Convert.ToString(cursorPosition.Y + 1) + "  " + "Col: " + Convert.ToString(cursorPosition.X + 1);
        }
Exemple #3
0
        public System.Windows.Point TranslateToScreenPoint(System.Drawing.Point charPosition)
        {
            IScriptObject activeScript = Solution.Current.ActiveScript;
            CharPosition  position     = activeScript.CreateCharPosition();

            position.SetCharacterPosition(charPosition.X, charPosition.Y);
            System.Windows.Point result = position.GetScreenPosition();

            // The screen position needs offset based on the current scroll position.
            result.Offset(-scrollViewer.HorizontalOffset, -scrollViewer.VerticalOffset);
            return(result);
        }
Exemple #4
0
        private void OnDragOver(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.Move;
            if ((e.KeyStates & DragDropKeyStates.ControlKey) != 0)
            {
                e.Effects = DragDropEffects.Copy;
            }

            // First, validate arbitrary screen coordinates...
            IScriptObject activeScript = Solution.Current.ActiveScript;
            CharPosition  mousePoint   = activeScript.CreateCharPosition();

            mousePoint.SetScreenPosition(GetRelativeCanvasPosition(e));

            // Here when the content is dragged to the first line in view, try to
            // bring it onto the previous line. This is so that the previous line
            // gets to scroll into view later on. If the cursor is on the last
            // visible line, then try to set it one line beyond that. This is so
            // that the next line get to scroll into view the same way.
            //
            int characterY      = mousePoint.CharacterY;
            int lastVisibleLine = textCanvas.FirstVisibleLine + textCanvas.MaxVisibleLines;

            if (characterY == textCanvas.FirstVisibleLine)
            {
                characterY = characterY - 1;
            }
            else if (characterY >= lastVisibleLine - 1)
            {
                characterY = characterY + 1;
            }

            mousePoint.SetCharacterPosition(mousePoint.CharacterX, characterY);

            // Then get the precised cursor coordinates, and then set the
            // character position so we get screen coordinates at character
            // boundaries...
            System.Drawing.Point cursor = mousePoint.GetCharacterPosition();
            mousePoint.SetCharacterPosition(cursor);
            textCanvas.SetCursorScreenPos(mousePoint.GetScreenPosition());
            textCanvas.EnsureCursorVisible(mousePoint.CharacterX, mousePoint.CharacterY);
        }