Beispiel #1
0
 protected virtual void OnRedraw(NeovimRedrawEventArgs e)
 {
     EventHandler<NeovimRedrawEventArgs> handler = Redraw;
     if (handler != null)
     {
         handler(this, e);
     }
 }
Beispiel #2
0
        protected virtual void OnRedraw(NeovimRedrawEventArgs e)
        {
            EventHandler <NeovimRedrawEventArgs> handler = Redraw;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Fires a redraw event after getting a notification from the MsgPackIO class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="msgPackEventArgs"></param>
        private void OnNotificationReceived(object sender, MsgPackEventArgs msgPackEventArgs)
        {
            if (msgPackEventArgs.Function != "redraw")
                return;

            var list = msgPackEventArgs.Result.AsList();
            NeovimRedrawEventArgs args = new NeovimRedrawEventArgs();
            args.Functions = list;
            OnRedraw(args);
        }
Beispiel #4
0
        /// <summary>
        /// Fires a redraw event after getting a notification from the MsgPackIO class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="msgPackNotificationEventArgs"></param>
        private void OnNotificationReceived(object sender, MsgPackNotificationEventArgs msgPackNotificationEventArgs)
        {
            if (msgPackNotificationEventArgs.Method != "redraw")
            {
                return;
            }

            NeovimRedrawEventArgs args = new NeovimRedrawEventArgs();

            args.Methods = NotificationParser.ParseRedraw(msgPackNotificationEventArgs.Params.AsList());
            OnRedraw(args);
        }
Beispiel #5
0
        /// <summary>
        /// Fires a redraw event after getting a notification from the MsgPackIO class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="msgPackEventArgs"></param>
        private void OnNotificationReceived(object sender, MsgPackEventArgs msgPackEventArgs)
        {
            if (msgPackEventArgs.Function != "redraw")
            {
                return;
            }

            var list = msgPackEventArgs.Result.AsList();
            NeovimRedrawEventArgs args = new NeovimRedrawEventArgs();

            args.Functions = list;
            OnRedraw(args);
        }
Beispiel #6
0
        protected virtual void OnRedraw(NeovimRedrawEventArgs e)
        {
            EventHandler <NeovimRedrawEventArgs> handler = Redraw;

            handler?.Invoke(this, e);
        }
Beispiel #7
0
        private void NeovimOnRedraw(object sender, NeovimRedrawEventArgs e)
        {
            bool shouldInvalidate = false;
     
            _backBuffer.Bind();
            foreach (var method in e.Methods)
            {
                switch (method.Method)
                {
                    case RedrawMethodType.Clear:
                        shouldInvalidate = true;
                        GL.Clear(ClearBufferMask.ColorBufferBit);
                        break;

                    //        case RedrawMethodType.Resize:
                    //            _term.Resize(args[0][1].AsInt32(), args[0][0].AsInt32());
                    //            break;

                    case RedrawMethodType.UpdateForeground:
                        _font.Color = ColorFromRgb(method.Params[0][0].AsInt32());
                        break;

                    case RedrawMethodType.UpdateBackground:
                        _bgColor = ColorFromRgb(method.Params[0][0].AsInt32());
                        GL.ClearColor(_bgColor);
                        break;

                    case RedrawMethodType.HighlightSet:
                        foreach (var arg in method.Params)
                        {
                            var dict = arg[0].AsDictionary();

                            foreach (var entry in dict)
                            {
                                var str = entry.Key.AsString(Encoding.Default);
                                if (str == "foreground")
                                    _font.Color = ColorFromRgb(entry.Value.AsInt32());
                                else if (str == "bold")
                                    if (entry.Value.AsBoolean())
                                        _font.FontStyle |= FontStyle.Bold;
                                    else _font.FontStyle &= ~FontStyle.Bold;
                                else if (str == "italic")
                                    if (entry.Value.AsBoolean())
                                        _font.FontStyle |= FontStyle.Italic;
                                    else _font.FontStyle &= FontStyle.Italic;
                            }
                        }
                        break;

                    case RedrawMethodType.EolClear:
                        shouldInvalidate = true;
                        DrawRectangle(new RectangleF(_cursor.X, _cursor.Y, _columns * _width - _cursor.X, _height), _bgColor);
                        break;

                    case RedrawMethodType.SetTitle:
                        Text = method.Params[0][0].AsString(Encoding.Default);
                        break;

                    case RedrawMethodType.Put:
                        shouldInvalidate = true;
                        List<byte> bytes = new List<byte>();
                        foreach (var arg in method.Params)
                            bytes.AddRange(arg[0].AsBinary());

                        var text = Encoding.Default.GetString(bytes.ToArray());
                        var tSize = _font.Measure(text);
                        
                        DrawRectangle(new RectangleF(_cursor.Location, tSize), _bgColor);

                        GL.Enable(EnableCap.Blend);
                        _font.Print(text, new Vector2(_cursor.X, _cursor.Y));
                        GL.Disable(EnableCap.Blend);
                        GL.Color4(Color.White);

                        _cursor.X += tSize.Width;
                        if (_cursor.X >= _columns*_width) // Dont know if this is needed
                        {
                            _cursor.X = 0;
                            _cursor.Y += _height;
                        }
                        break;

                    case RedrawMethodType.CursorGoto:
                        shouldInvalidate = true;
                        _cursor.Y = method.Params[0][0].AsInt32() * _height;
                        _cursor.X = method.Params[0][1].AsInt32() * _width;
                        break;

                    case RedrawMethodType.Scroll:
                        // Amount to scroll
                        var count = method.Params[0][0].AsSByte();
                        if (count == 0) return;

                        var srcRect = new RectangleF();
                        var dstRect = new RectangleF();
                        var clearRect = new RectangleF();

                        // Scroll up
                        if (count >= 1)
                        {
                            srcRect = new RectangleF(_scrollRegion.X, _scrollRegion.Y + _height, _scrollRegion.Width,
                                _scrollRegion.Height - _height);
                            dstRect = new RectangleF(_scrollRegion.X, _scrollRegion.Y, _scrollRegion.Width,
                                _scrollRegion.Height - _height);
                            clearRect = new RectangleF(_scrollRegion.X, _scrollRegion.Y + _scrollRegion.Height - _height,
                                _scrollRegion.Width, _height + 1);
                        }
                        // Scroll down
                        else if (count <= -1)
                        {
                            srcRect = new RectangleF(_scrollRegion.X, _scrollRegion.Y, _scrollRegion.Width,
                                _scrollRegion.Height - _height);
                            dstRect = new RectangleF(_scrollRegion.X, _scrollRegion.Y + _height, _scrollRegion.Width,
                                _scrollRegion.Height - _height);
                            clearRect = new RectangleF(_scrollRegion.X, _scrollRegion.Y, _scrollRegion.Width,
                                _height + 1);
                        }

                        _pingPongBuffer.Bind();
                        _backBuffer.Texture.Bind();

                        DrawTexturedRectangle(srcRect, dstRect);

                        _backBuffer.Bind();
                        _pingPongBuffer.Texture.Bind();

                        DrawTexturedRectangle(dstRect, dstRect);

                        Texture2D.Unbind();

                        DrawRectangle(clearRect, _bgColor);
                        break;

                    case RedrawMethodType.SetScrollRegion:
                        var x = method.Params[0][2].AsUInt32() * _width;
                        var y = method.Params[0][0].AsUInt32() * _height;
                        var width = (method.Params[0][3].AsUInt32() + 1) * _width;
                        var height = (method.Params[0][1].AsUInt32() + 1) * _height;

                        _scrollRegion = new RectangleF(x, y, width, height);
                        break;

                    case RedrawMethodType.ModeChange:
                        shouldInvalidate = true;
                        var mode = method.Params[0][0].AsString(Encoding.Default);
                        if (mode == "insert")
                            _cursor.Width = _width / 4;
                        else if (mode == "normal")
                            _cursor.Width = _width;
                        break;

                        //        case RedrawMethodType.BusyStart:
                        //            break;

                        //        case RedrawMethodType.BusyStop:
                        //            break;

                        //        case RedrawMethodType.MouseOn:
                        //            break;

                        //        case RedrawMethodType.MouseOff:
                        //            break;
                }
            }
            FrameBuffer.Unbind();
            if (shouldInvalidate)
                glControl.Invalidate();
        }