示例#1
0
        internal void PutChar(char ch)
        {
            if (ch == '\n')
            {
                Caption caption = this;
                caption.cursorRow = caption.cursorRow + 1;
                if (this.cursorRow >= this.WindowRows)
                {
                    this.ScrollText(this.cursorRow - this.WindowRows + 1);
                    Caption windowRows = this;
                    windowRows.cursorRow = windowRows.cursorRow - (this.cursorRow - this.WindowRows + 1);
                }
                return;
            }
            if (this.cursorCol >= this.WindowCols)
            {
                this.cursorCol = 0;
                Caption caption1 = this;
                caption1.cursorRow = caption1.cursorRow + 1;
            }
            if (this.cursorRow >= this.WindowRows)
            {
                this.ScrollText(this.cursorRow - this.WindowRows + 1);
                Caption windowRows1 = this;
                windowRows1.cursorRow = windowRows1.cursorRow - (this.cursorRow - this.WindowRows + 1);
            }
            this.text[this.cursorRow, this.cursorCol] = ch;
            Caption caption2 = this;

            caption2.cursorCol = caption2.cursorCol + 1;
            if (this.WindowRef != null)
            {
                this.WindowRef.Dispatcher.Invoke <string>(() => {
                    CaptionWindow windowRef = this.WindowRef;
                    string text             = this.Text;
                    string str     = text;
                    windowRef.Text = text;
                    return(str);
                });
            }
        }
        public void ParseData(byte[] data)
        {
            switch (data[1])
            {
            case 0:
            case 1:
            {
                if (this.current == null)
                {
                    break;
                }
                this.current.PutChar(CCDataCodeTable.CodeTable[data[2]]);
                return;
            }

            case 2:
            case 3:
            case 4:
            {
                if (data[1] < 152 || data[1] > 159)
                {
                    break;
                }
                Caption caption1 = this.captions.Find((Caption o) => o.ID == data[1] - 151);
                if (caption1 != null)
                {
                    this.current = caption1;
                    this.current.ResizeWindow((data[5] & 15) + 1, (data[6] & 63) + 1);
                    this.current.Position = new Point((double)data[4], (double)(data[3] & 127));
                }
                else
                {
                    this.current = new Caption(data[1] - 151, (int)data[4], data[3] & 127, (data[5] & 15) + 1, (data[6] & 63) + 1, (data[2] & 32) > 0);
                    this.captions.Add(this.current);
                }
                if (!this.current.Visible || this.current.WindowRef != null)
                {
                    break;
                }
                Application.Current.Dispatcher.Invoke(() => {
                        this.current.WindowRef = new CaptionWindow()
                        {
                            Text = this.current.Text
                        };
                        this.OnShowCaption(this, new CaptionEventArgs()
                        {
                            WindowRef = this.current.WindowRef,
                            WindowPos = this.current.Position
                        });
                    });
                break;
            }

            case 5:
            {
                if (data[2] != 13)
                {
                    return;
                }
                if (this.current == null)
                {
                    break;
                }
                this.current.PutChar('\n');
                return;
            }

            case 6:
            {
                CCDataCodeTable.ControlCode controlCode = (CCDataCodeTable.ControlCode)data[2];
                switch (controlCode)
                {
                case CCDataCodeTable.ControlCode.TGW:
                {
                    Application.Current.Dispatcher.Invoke(() => {
                                foreach (Caption captionWindow in this.captions.FindAll((Caption o) => (o.ID & data[3]) > 0))
                                {
                                    if (!captionWindow.Visible)
                                    {
                                        captionWindow.WindowRef = new CaptionWindow()
                                        {
                                            Text = captionWindow.Text
                                        };
                                        captionWindow.Visible = true;
                                        this.OnShowCaption(this, new CaptionEventArgs()
                                        {
                                            WindowRef = captionWindow.WindowRef,
                                            WindowPos = captionWindow.Position
                                        });
                                    }
                                    else
                                    {
                                        this.OnHideCaption(this, new CaptionEventArgs()
                                        {
                                            WindowRef = captionWindow.WindowRef,
                                            WindowPos = captionWindow.Position
                                        });
                                    }
                                }
                            });
                    return;
                }

                case CCDataCodeTable.ControlCode.DLW:
                {
                    Application.Current.Dispatcher.Invoke(() => {
                                foreach (Caption caption in this.captions.FindAll((Caption o) => (o.ID & data[3]) > 0))
                                {
                                    this.OnHideCaption(this, new CaptionEventArgs()
                                    {
                                        WindowRef = caption.WindowRef,
                                        WindowPos = caption.Position
                                    });
                                    this.captions.Remove(caption);
                                }
                            });
                    return;
                }

                default:
                {
                    if (controlCode != CCDataCodeTable.ControlCode.SPL)
                    {
                        return;
                    }
                    if (this.current == null)
                    {
                        return;
                    }
                    this.current.SetCursorPos(data[3] & 15, data[4] & 63);
                    return;
                }
                }
                break;
            }

            default:
            {
                goto case 4;
            }
            }
        }