コード例 #1
0
ファイル: ScreenCell.cs プロジェクト: yiyi99/RemoteTerminal
 public void Reset()
 {
     this.Character = ' ';
     this.Modifications = ScreenCellModifications.None;
     this.ForegroundColor = ScreenColor.DefaultForeground;
     this.BackgroundColor = ScreenColor.DefaultBackground;
 }
コード例 #2
0
        /// <summary>
        /// Renders the screen.
        /// </summary>
        /// <param name="target">The Direct2D drawing target.</param>
        public virtual void Render(TargetBase target)
        {
            Point drawingPosition = new Point(0, 0);
            SurfaceImageSourceTarget surfaceImageSourceTarget = target as SurfaceImageSourceTarget;

            if (surfaceImageSourceTarget != null)
            {
                drawingPosition = surfaceImageSourceTarget.DrawingPosition;
            }

            IRenderableScreenCopy screenCopy = this.screen.GetScreenCopy();

            var context2D = target.DeviceManager.ContextDirect2D;

            context2D.BeginDraw();
            context2D.Transform = Matrix.Identity;
            context2D.Clear(this.GetColor(ScreenColor.DefaultBackground));

            // 1. Paint backgrounds
            {
                RectangleF rect  = new RectangleF();
                var        lines = screenCopy.Cells;
                for (int y = 0; y < lines.Length; y++)
                {
                    var cols = lines[y];

                    rect.Top    = drawingPosition.Y + (y * this.physicalFontMetrics.CellHeight);
                    rect.Bottom = rect.Top + this.physicalFontMetrics.CellHeight;

                    ScreenColor currentBackgroundColor = cols.Length > 0 ? cols[0].BackgroundColor : ScreenColor.DefaultBackground;
                    ScreenColor cellBackgroundColor;
                    int         blockStart = 0;
                    for (int x = 0; x <= cols.Length; x++) // loop once above the upper bound
                    {
                        var cell = cols[x < cols.Length ? x : x - 1];

                        bool isCursor = !screenCopy.CursorHidden && y == screenCopy.CursorRow && x == screenCopy.CursorColumn;
                        cellBackgroundColor = isCursor ? ScreenColor.CursorBackground : cell.BackgroundColor;
                        if (cellBackgroundColor != currentBackgroundColor || x == cols.Length)
                        {
                            rect.Left  = drawingPosition.X + (blockStart * this.physicalFontMetrics.CellWidth);
                            rect.Right = drawingPosition.X + (x * this.physicalFontMetrics.CellWidth);

                            Brush backgroundBrush = this.GetBrush(context2D, this.GetColor(currentBackgroundColor));
                            if (currentBackgroundColor == ScreenColor.CursorBackground && !screenCopy.HasFocus)
                            {
                                rect.Right = rect.Right - 1.0f;
                                context2D.DrawRectangle(rect, backgroundBrush);
                            }
                            else
                            {
                                context2D.FillRectangle(rect, backgroundBrush);
                            }

                            blockStart = x;

                            currentBackgroundColor = cellBackgroundColor;
                        }
                    }
                }
            }

            // 2. Paint foregrounds
            {
                RectangleF rect  = new RectangleF();
                var        lines = screenCopy.Cells;
                for (int y = 0; y < lines.Length; y++)
                {
                    var cols = lines[y];

                    rect.Top    = drawingPosition.Y + (y * this.physicalFontMetrics.CellHeight);
                    rect.Bottom = rect.Top + this.physicalFontMetrics.CellHeight;

                    ScreenColor             currentForegroundColor   = cols.Length > 0 ? cols[0].ForegroundColor : ScreenColor.DefaultForeground;
                    ScreenCellModifications currentCellModifications = cols.Length > 0 ? cols[0].Modifications : ScreenCellModifications.None;
                    bool        currentCellUCSWIDE = cols.Length > 0 ? cols[0].Character == CjkWidth.UCSWIDE : false;
                    ScreenColor cellForegroundColor;
                    int         blockStart = 0;
                    for (int x = 0; x <= cols.Length; x++) // loop once above the upper bound
                    {
                        var cell = cols[x < cols.Length ? x : x - 1];

                        bool isCursor = !screenCopy.CursorHidden && y == screenCopy.CursorRow && x == screenCopy.CursorColumn;
                        cellForegroundColor = isCursor && screenCopy.HasFocus ? ScreenColor.CursorForeground : cell.ForegroundColor;
                        if (currentCellUCSWIDE || cellForegroundColor != currentForegroundColor || cell.Modifications != currentCellModifications || x == cols.Length)
                        {
                            rect.Left  = drawingPosition.X + (blockStart * this.physicalFontMetrics.CellWidth);
                            rect.Right = drawingPosition.X + (x * this.physicalFontMetrics.CellWidth);

                            Brush      foregroundBrush = this.GetBrush(context2D, this.GetColor(currentForegroundColor));
                            TextFormat textFormat      = this.textFormatNormal;
                            if (currentCellModifications.HasFlag(ScreenCellModifications.Bold))
                            {
                                textFormat = this.textFormatBold;
                            }

                            string text = new string(cols.Skip(blockStart).Take(x - blockStart).Select(c => char.IsWhiteSpace(c.Character) ? ' ' : c.Character).Where(ch => ch != CjkWidth.UCSWIDE).ToArray()).TrimEnd();

                            if (text.Length > 0)
                            {
                                context2D.DrawText(text, textFormat, rect, foregroundBrush, DrawTextOptions.Clip);
                            }

                            if (currentCellModifications.HasFlag(ScreenCellModifications.Underline))
                            {
                                var point1 = new Vector2(rect.Left, rect.Bottom - 1.0f) + drawingPosition;
                                var point2 = new Vector2(rect.Right, rect.Bottom - 1.0f) + drawingPosition;
                                context2D.DrawLine(point1, point2, foregroundBrush);
                            }

                            blockStart = x;

                            currentForegroundColor = cellForegroundColor;
                        }
                        currentCellUCSWIDE = cell.Character == CjkWidth.UCSWIDE;
                    }
                }
            }

            context2D.EndDraw();
        }
コード例 #3
0
ファイル: ScreenCell.cs プロジェクト: yiyi99/RemoteTerminal
        /// <summary>
        /// Applies the specified format to this screen cell.
        /// </summary>
        /// <param name="format">The format to apply.</param>
        public void ApplyFormat(ScreenCellFormat format)
        {
            if (format == null)
            {
                return;
            }

            this.Modifications = ScreenCellModifications.None;
            if (format.BoldMode)
            {
                this.Modifications |= ScreenCellModifications.Bold;
            }

            if (format.UnderlineMode)
            {
                this.Modifications |= ScreenCellModifications.Underline;
            }

            if (format.ReverseMode)
            {
                this.BackgroundColor = format.ForegroundColor;
                this.ForegroundColor = format.BackgroundColor;
            }
            else
            {
                this.BackgroundColor = format.BackgroundColor;
                this.ForegroundColor = format.ForegroundColor;
            }
        }