Пример #1
0
            public static ConsoleFont GetConsoleFont()
            {
                ConsoleFont font = new ConsoleFont();

                GetCurrentConsoleFont(GetStdHandle(StdHandle.OutputHandle), false, out font);
                return(font);
            }
Пример #2
0
        protected override void EndProcessing()
        {
            base.EndProcessing();

            if (ListAvailable.ToBool())
            {
                if (Extended.ToBool())
                {
                    FontFamily.PseudoMonoSpaced = true;
                    WriteObject(FontFamily.Monospaced.Where(f => f.FontType != FontType.PostScript && f.Name.Length <= 32), true);
                }
                else
                {
                    WriteObject(FontFamily.Console, true);
                }
            }
            else if (string.IsNullOrEmpty(Name))
            {
                ConsoleFont info = new ConsoleFont
                {
                    cbSize = Marshal.SizeOf <ConsoleFont>()
                };

                // First determine whether there's already a TrueType font.
                if (GetCurrentConsoleFontEx(ConsoleOutputHandle, true, ref info))
                {
                    var ff = FontFamily.All.FirstOrDefault(f => f.Name == info.FontName);

                    if (null != ff)
                    {
                        var result = new PSObject(ff);
                        result.Properties.Add(new PSNoteProperty("Size", info.FontWidth + "x" + info.FontSize));
                        result.Properties.Add(new PSNoteProperty("Weight", info.FontWeight));

                        WriteObject(result);
                    }
                    else
                    {
                        WriteObject(info);
                    }
                }
                else
                {
                    var er = Marshal.GetLastWin32Error();
                    throw new System.ComponentModel.Win32Exception(er, "Error getting the console font");
                }
            }
            else
            {
                var pattern = WildcardPattern.Get(Name, WildcardOptions.Compiled & WildcardOptions.CultureInvariant & WildcardOptions.IgnoreCase);
                WriteObject(FontFamily.All.Where(f => pattern.IsMatch(f.Name)), true);
            }
        }
Пример #3
0
        public override void Draw(GameTime gameTime)
        {
            if (InputManager.IsConsoleOpen && ConsoleFont != null)
            {
                Renderer.Begin();

                Renderer.FillRectangle(Bounds, BackgroundColor * BackgroundOpacity);
                Renderer.DrawRectangle(Bounds, BorderColor, BorderThickness);

                var inputLine = InputPrompt + InputManager.InputText;
                var inputPos  = InputManager.CursorPos + InputPrompt.Length;

                var inputTextHeight = ConsoleFont.MeasureString(inputLine).Y;
                var inputHeight     = inputTextHeight + (InnerPadding * 2);

                Renderer.FillRectangle(
                    new Rectangle(
                        Bounds.Left + BorderThickness,
                        Bounds.Bottom - BorderThickness - (int)inputHeight - InputBorderThickness,
                        Bounds.Width - (BorderThickness * 2), InputBorderThickness),
                    InputBorderColor);

                var cursorPos = ConsoleFont.MeasureString(inputLine.Substring(0, inputPos)).X + Bounds.Left + BorderThickness + InnerPadding;

                Renderer.DrawString(ConsoleFont, inputLine, new Vector2(Bounds.Left + BorderThickness + InnerPadding, Bounds.Bottom - BorderThickness - InnerPadding - inputTextHeight), InputColor);
                Renderer.DrawString(ConsoleFont, "_", new Vector2(cursorPos, Bounds.Bottom - BorderThickness - InnerPadding - inputTextHeight), InputColor);

                float linePos = Bounds.Bottom - BorderThickness - inputHeight - InputBorderThickness - InnerPadding;

                for (int i = _lines.Count - 1; i >= 0; i--)
                {
                    var line = _lines[i];

                    var lineText  = line.Text;
                    var lineColor = line.Color;

                    var lineMeasure = ConsoleFont.MeasureString(lineText);

                    linePos -= lineMeasure.Y;

                    Renderer.DrawString(ConsoleFont, lineText, new Vector2(Bounds.Left + BorderThickness + InnerPadding, linePos), lineColor);

                    if (linePos <= Bounds.Top + BorderThickness + InnerPadding)
                    {
                        break;
                    }
                }

                Renderer.End();
            }
        }
Пример #4
0
        public static ConsoleFont[] GetConsoleFonts()
        {
            IntPtr hConsole = GetOutputHandle();

            if (hConsole.IsInvalidHandle())
            {
                return(Array.Empty <ConsoleFont>());
            }

            int c = GetFontCount();

            if (c == 0)
            {
                return(Array.Empty <ConsoleFont>());
            }

            ConsoleFont[] fonts = new ConsoleFont[c];
            Win32.GetConsoleFontInfo(hConsole, false, (uint)fonts.Length, fonts);
            return(fonts);
        }
Пример #5
0
 private static extern bool GetCurrentConsoleFont(IntPtr hConsoleOutput, bool bMaximumWindow, out ConsoleFont currentFont);
Пример #6
0
 internal static extern bool GetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool MaximumWindow, ref ConsoleFont ConsoleCurrentFontEx);