예제 #1
0
        public void DrawCaret(ICanvas c, CaretShape shape = CaretShape.UpArrow)
        {
            if (!(Caret is CaretHandle caret))
            {
                return;
            }
            var path = c.GetPath();

            if (!(Display.PointForIndex(TypesettingContext.Instance, InsertionIndex) is PointF cursorPosition))
            {
                return;
            }
            cursorPosition.Y *= -1; //inverted canvas, blah blah
            var point = caret.InitialPoint.Plus(cursorPosition);

            path.BeginRead(1);
            path.Foreground = caret.ActualColor;
            path.MoveTo(point.X, point.Y);
            switch (shape)
            {
            default:
            case CaretShape.UpArrow:
                ReadOnlySpan <PointF> s = stackalloc PointF[4] {
                    caret.NextPoint1, caret.NextPoint2,
                    caret.NextPoint3, caret.FinalPoint
                };
                foreach (var p in s)
                {
                    path.LineTo(p.X + cursorPosition.X, p.Y + cursorPosition.Y);
                }
                break;

            case CaretShape.IBeam:
                s = stackalloc PointF[4] {
                    new PointF(caret.Bounds.Width / 16, 0),
                    new PointF(caret.Bounds.Width / 16, -caret.Bounds.Height),
                    new PointF(-caret.Bounds.Width / 16, -caret.Bounds.Height),
                    new PointF(-caret.Bounds.Width / 16, 0),
                };
                foreach (var p in s)
                {
                    path.LineTo(p.X + cursorPosition.X, p.Y + cursorPosition.Y);
                }
                break;
            }
            path.CloseContour();
            path.EndRead();
        }
예제 #2
0
        public void DrawCaret(ICanvas canvas, Structures.Color color, CaretShape shape)
        {
            if (!(Caret is CaretHandle caret))
            {
                return;
            }
            if (!(Display.PointForIndex(TypesettingContext.Instance, InsertionIndex) is PointF cursorPosition))
            {
                return;
            }
            cursorPosition.Y *= -1; //inverted canvas, blah blah
            var path = canvas.GetPath();

            path.BeginRead(1);
            path.Foreground = color;
            path.MoveTo(cursorPosition.X, cursorPosition.Y);
            switch (shape)
            {
            case CaretShape.IBeam:
                ReadOnlySpan <PointF> s = stackalloc PointF[4] {
                    new PointF(caret.Width / 16, 0),
                    new PointF(caret.Width / 16, -caret.Height),
                    new PointF(-caret.Width / 16, -caret.Height),
                    new PointF(-caret.Width / 16, 0),
                };
                foreach (var p in s)
                {
                    path.LineTo(p.X + cursorPosition.X, p.Y + cursorPosition.Y);
                }
                break;

            case CaretShape.UpArrow:
                s = stackalloc PointF[4] {
                    new PointF(caret.Width / 2, caret.Height / 4),
                    new PointF(caret.Width / 2, caret.Height),
                    new PointF(-caret.Width / 2, caret.Height),
                    new PointF(-caret.Width / 2, caret.Height / 4)
                };
                foreach (var p in s)
                {
                    path.LineTo(p.X + cursorPosition.X, p.Y + cursorPosition.Y);
                }
                break;
            }
            path.CloseContour();
            path.EndRead();
        }
    }
예제 #3
0
        public void DrawCaret(ICanvas canvas, Structures.Color color, CaretShape shape)
        {
            if (!ShowCaret)
            {
                return;
            }
            var cursorPosition = Display.PointForIndex(TypesettingContext.Instance, InsertionIndex) ?? Display.Position;

            cursorPosition.Y *= -1; //inverted canvas, blah blah
            var path = canvas.GetPath();

            path.BeginRead(1);
            path.Foreground = color;
            path.MoveTo(cursorPosition.X, cursorPosition.Y);
            switch (shape)
            {
            case CaretShape.IBeam:
                ReadOnlySpan <PointF> s = stackalloc PointF[4] {
                    new PointF(Font.PointSize / 2 / 16, 0),
                    new PointF(Font.PointSize / 2 / 16, -Font.PointSize * 2 / 3),
                    new PointF(-Font.PointSize / 2 / 16, -Font.PointSize * 2 / 3),
                    new PointF(-Font.PointSize / 2 / 16, 0),
                };
                foreach (var p in s)
                {
                    path.LineTo(p.X + cursorPosition.X, p.Y + cursorPosition.Y);
                }
                break;

            case CaretShape.UpArrow:
                s = stackalloc PointF[4] {
                    new PointF(Font.PointSize / 2 / 2, Font.PointSize * 2 / 3 / 4),
                    new PointF(Font.PointSize / 2 / 2, Font.PointSize * 2 / 3),
                    new PointF(-Font.PointSize / 2 / 2, Font.PointSize * 2 / 3),
                    new PointF(-Font.PointSize / 2 / 2, Font.PointSize * 2 / 3 / 4)
                };
                foreach (var p in s)
                {
                    path.LineTo(p.X + cursorPosition.X, p.Y + cursorPosition.Y);
                }
                break;
            }
            path.CloseContour();
            path.EndRead();
        }
    }
예제 #4
0
        public void DrawCaret(ICanvas canvas, Color color, CaretShape shape)
        {
            if (CaretState != MathKeyboardCaretState.Shown || Display is null)
            {
                return;
            }
            var cursorPosition = Display.PointForIndex(TypesettingContext.Instance, InsertionIndex) ?? Display.Position;

            cursorPosition.Y *= -1; //inverted canvas, blah blah
            using var path    = canvas.StartNewPath();
            path.Foreground   = color;
            path.MoveTo(cursorPosition.X, cursorPosition.Y);
            switch (shape)
            {
            case CaretShape.IBeam:
                ReadOnlySpan <PointF> s = stackalloc PointF[4] {
                    new PointF(Font.PointSize / 2 / 16, 0),
                    new PointF(Font.PointSize / 2 / 16, -Font.PointSize * 2 / 3),
                    new PointF(-Font.PointSize / 2 / 16, -Font.PointSize * 2 / 3),
                    new PointF(-Font.PointSize / 2 / 16, 0),
                };
                foreach (var p in s)
                {
                    path.LineTo(p.X + cursorPosition.X, p.Y + cursorPosition.Y);
                }
                break;

            case CaretShape.UpArrow:
                s = stackalloc PointF[4] {
                    new PointF(Font.PointSize / 2 / 2, Font.PointSize * 2 / 3 / 4),
                    new PointF(Font.PointSize / 2 / 2, Font.PointSize * 2 / 3),
                    new PointF(-Font.PointSize / 2 / 2, Font.PointSize * 2 / 3),
                    new PointF(-Font.PointSize / 2 / 2, Font.PointSize * 2 / 3 / 4)
                };
                foreach (var p in s)
                {
                    path.LineTo(p.X + cursorPosition.X, p.Y + cursorPosition.Y);
                }
                break;
            }
            path.CloseContour();
        }
    }
예제 #5
0
 public static void BindDisplay(this MathKeyboard keyboard,
                                SKCanvasView view, MathPainter settings, SKColor caretColor,
                                CaretShape caretShape = CaretShape.IBeam, SKStrokeCap cap = SKStrokeCap.Butt)
 {
     view.EnableTouchEvents = true;
     view.Touch            +=
         (sender, e) => {
         if (e.ActionType == SKTouchAction.Pressed)
         {
             keyboard.MoveCaretToPoint(new System.Drawing.PointF(e.Location.X, e.Location.Y));
         }
     };
     keyboard.RedrawRequested += (_, __) => view.InvalidateSurface();
     view.PaintSurface        +=
         (sender, e) => {
         var c = e.Surface.Canvas;
         c.Clear();
         MathPainter.DrawDisplay(settings, keyboard.Display, c);
         keyboard.DrawCaret(new SkiaCanvas(c, cap, AntiAlias.Enable), caretColor.FromNative(), caretShape);
     };
 }
예제 #6
0
 public void DrawCaret(global::SkiaSharp.SKCanvas canvas, CaretShape shape = CaretShape.UpArrow) =>
 Keyboard.DrawCaret(new SkiaSharp.SkiaCanvas(canvas, global::SkiaSharp.SKStrokeCap.Butt, false), shape);