public void Update() { editor.Print(0, 0, stat.Name); editor.Clear(14, 0); editor.Clear(15, 0); editor.Print(14, 0, stat.Value.ToString()); if (stat.AltValue != 0) { editor.Clear(17, 0); editor.Clear(18, 0); editor.Print(17, 0, stat.AltValue.ToString()); } }
public FPSCounterComponent(Microsoft.Xna.Framework.Game game) : base(game) { console = new TextSurface(30, 1, Engine.DefaultFont); editor = new SurfaceEditor(console); console.DefaultBackground = Color.Black; editor.Clear(); consoleRender = new TextSurfaceRenderer(); }
public override void Draw(GameTime gameTime) { frameCounter++; string fps = string.Format("fps: {0}", frameRate); editor.Clear(); editor.Print(0, 0, fps); consoleRender.Render(console, Point.Zero); }
public FPSCounterComponent(Microsoft.Xna.Framework.Game game) : base(game) { surface = new BasicSurface(30, 1); editor = new SurfaceEditor(surface); surface.DefaultBackground = Color.Black; editor.Clear(); consoleRender = new SurfaceRenderer(); DrawOrder = 8; Global.GraphicsDevice.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents; }
public override void Draw(GameTime gameTime) { frameCounter++; string fps = string.Format("fps: {0}", frameRate); editor.Clear(); editor.Print(0, 0, fps); consoleRender.Render(surface); Global.GraphicsDevice.SetRenderTarget(null); Global.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone); Global.SpriteBatch.Draw(surface.LastRenderResult, Vector2.Zero, Color.White); Global.SpriteBatch.End(); }
public void Update() { editor.Clear(); editor.Print(0, 0, stat.Name); //calculation move to method? ColoredString statusString = stat.Value.ToString().CreateColored(colorOne, Color.Black, null) + "/".CreateColored(Color.White, Color.Black, null) + stat.AltValue.ToString().CreateColored(colorTwo, Color.Black, null); ColoredString gradient = new string((char)176, 14).CreateGradient(colorOne, colorTwo, colorOne, colorTwo); double percent = (double)stat.Value / (double)stat.AltValue; //drawing editor.Print(width - statusString.ToString().Length, 0, statusString); editor.Print(0, 1, gradient.SubString(0, (int)((double)gradient.Count * (double)percent))); }
/// <summary> /// Interprets an individual ansi code. /// </summary> /// <param name="code">The ANSI.SYS code to read.</param> public void AnsiInterpret(string code) { if (code[0] == (char)27 && code[1] == '[') { string data = code.Substring(2, code.Length - 3); string[] values = data.Split(';'); switch (code[code.Length - 1]) { case 'H': case 'h': if (values.Length == 2) { if (values[1] == "") { _cursor.Position = new Point(0, _cursor.Position.Y); } else { _cursor.Position = new Point(Convert.ToInt32(values[1]) - 1, _cursor.Position.Y); } if (values[0] == "") { _cursor.Position = new Point(_cursor.Position.X, 0); } else { _cursor.Position = new Point(_cursor.Position.X, Convert.ToInt32(values[0]) - 1); } } //else // System.Diagnostics.Debugger.Break(); break; case 'F': case 'f': break; case 'A': case 'a': if (data.Length == 0) { _cursor.Up(1); } else { _cursor.Up(Convert.ToInt32(data)); } break; case 'B': case 'b': if (data.Length == 0) { _cursor.Down(1); } else { _cursor.Down(Convert.ToInt32(data)); } break; case 'C': case 'c': if (data.Length == 0) { _cursor.Right(1); } else { _cursor.Right(Convert.ToInt32(data)); } break; case 'D': case 'd': if (data.Length == 0) { _cursor.Left(1); } else { _cursor.Left(Convert.ToInt32(data)); } break; case 'J': case 'j': if (data == "" || data == "0") { for (int i = _cursor.Position.X; i < _editor.TextSurface.Width; i++) { _editor.Clear(i, _cursor.Position.Y); } } else if (data == "1") { for (int i = _cursor.Position.X; i >= 0; i--) { _editor.Clear(i, _cursor.Position.Y); } } else if (data == "2") { _editor.Clear(); _cursor.Position = new Point(0, 0); } break; case 'K': case 'k': if (data == "" || data == "0") { for (int i = _cursor.Position.X; i < _editor.TextSurface.Width; i++) { _editor.Clear(i, _cursor.Position.Y); } } else if (data == "1") { for (int i = _cursor.Position.X; i >= 0; i--) { _editor.Clear(i, _cursor.Position.Y); } } else if (data == "2") { for (int i = 0; i < _editor.TextSurface.Width; i++) { _editor.Clear(i, _cursor.Position.Y); } } break; case 'S': case 's': _storedCursorLocation = _cursor.Position; break; case 'U': case 'u': _cursor.Position = _storedCursorLocation; break; case 'M': case 'm': if (data == "") { _ansiState.AnsiResetVideo(); } else { for (int i = 0; i < values.Length; i++) { int value = Convert.ToInt32(values[i]); switch (value) { case 0: _ansiState.AnsiResetVideo(); break; case 1: _ansiState.Bold = true; _ansiState.AnsiCorrectPrintColor(); break; case 5: //Appearance.Effect = BlinkEffect; break; case 7: Color tempFore = _ansiState.Foreground; _ansiState.Foreground = Helpers.AnsiAdjustColor(_ansiState.Background, _ansiState.Bold); _ansiState.Background = Helpers.AnsiJustNormalColor(tempFore); break; case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: Helpers.AnsiConfigurePrintColor(false, value - 30, _ansiState); break; case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: Helpers.AnsiConfigurePrintColor(true, value - 40, _ansiState); break; default: break; } } } break; default: System.Diagnostics.Debugger.Break(); break; } } }
public static void ToSurface(this Texture2D image, BasicSurface surface, Color[] cachedColorArray, bool blockMode = false) { int imageWidth = image.Width; int imageHeight = image.Height; image.GetData <Color>(cachedColorArray); SurfaceEditor editor = new SurfaceEditor(surface); editor.Clear(); global::System.Threading.Tasks.Parallel.For(0, imageHeight / surface.Font.Size.Y, (h) => //for (int h = 0; h < imageHeight / surface.Font.Size.Y; h++) { int startY = (h * surface.Font.Size.Y); //System.Threading.Tasks.Parallel.For(0, imageWidth / surface.Font.Size.X, (w) => for (int w = 0; w < imageWidth / surface.Font.Size.X; w++) { int startX = (w * surface.Font.Size.X); float allR = 0; float allG = 0; float allB = 0; for (int y = 0; y < surface.Font.Size.Y; y++) { for (int x = 0; x < surface.Font.Size.X; x++) { int cY = y + startY; int cX = x + startX; Color color = cachedColorArray[cY * imageWidth + cX]; allR += color.R; allG += color.G; allB += color.B; } } byte sr = (byte)(allR / (surface.Font.Size.X * surface.Font.Size.Y)); byte sg = (byte)(allG / (surface.Font.Size.X * surface.Font.Size.Y)); byte sb = (byte)(allB / (surface.Font.Size.X * surface.Font.Size.Y)); var newColor = new Color(sr, sg, sb); float sbri = newColor.GetBrightness() * 255; if (blockMode) { if (sbri > 204) { editor.SetGlyph(w, h, 219, newColor); //█ } else if (sbri > 152) { editor.SetGlyph(w, h, 178, newColor); //▓ } else if (sbri > 100) { editor.SetGlyph(w, h, 177, newColor); //▒ } else if (sbri > 48) { editor.SetGlyph(w, h, 176, newColor); //░ } } else { if (sbri > 230) { editor.SetGlyph(w, h, (int)'#', newColor); } else if (sbri > 207) { editor.SetGlyph(w, h, (int)'&', newColor); } else if (sbri > 184) { editor.SetGlyph(w, h, (int)'$', newColor); } else if (sbri > 161) { editor.SetGlyph(w, h, (int)'X', newColor); } else if (sbri > 138) { editor.SetGlyph(w, h, (int)'x', newColor); } else if (sbri > 115) { editor.SetGlyph(w, h, (int)'=', newColor); } else if (sbri > 92) { editor.SetGlyph(w, h, (int)'+', newColor); } else if (sbri > 69) { editor.SetGlyph(w, h, (int)';', newColor); } else if (sbri > 46) { editor.SetGlyph(w, h, (int)':', newColor); } else if (sbri > 23) { editor.SetGlyph(w, h, (int)'.', newColor); } } } } ); }
/// <summary> /// Returns a surface with the specified image rendered to it as characters. /// </summary> /// <param name="image">The image to render.</param> /// <returns>The surface.</returns> public BasicSurface GetSurface(Texture2D image) { editor.Clear(); image.GetData <Color>(pixels); System.Threading.Tasks.Parallel.For(0, surface.Width * surface.Height, (i) => //for (int i = 0; i < surface.Width * surface.Height; i++) { int allR = 0; int allG = 0; int allB = 0; int min = i * fontPixels; int max = min + fontPixels; for (int pixel = min; pixel < max; pixel++) { Color color = pixels[indexes[pixel]]; allR += color.R; allG += color.G; allB += color.B; } // print our character byte sr = (byte)(allR / fontPixels); byte sg = (byte)(allG / fontPixels); byte sb = (byte)(allB / fontPixels); var newColor = new Color(sr, sg, sb); float sbri = newColor.GetBrightness() * 255; Point surfacePoint = surface.GetPointFromIndex(i); if (UseBlockMode) { if (sbri > 204) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 219, newColor); //█ } else if (sbri > 152) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 178, newColor); //▓ } else if (sbri > 100) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 177, newColor); //▒ } else if (sbri > 48) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 176, newColor); //░ } else { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 0, Color.Black); } } else { if (sbri > 230) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'#', newColor); } else if (sbri > 207) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'&', newColor); } else if (sbri > 184) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'$', newColor); } else if (sbri > 161) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'X', newColor); } else if (sbri > 138) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'x', newColor); } else if (sbri > 115) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'=', newColor); } else if (sbri > 92) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'+', newColor); } else if (sbri > 69) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)';', newColor); } else if (sbri > 46) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)':', newColor); } else if (sbri > 23) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'.', newColor); } else { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 0, Color.Black); } } } ); return(surface); }
public unsafe static void ToSurface(this Texture2D image, TextSurface surface, Color[] cachedColorArray, bool blockMode = false) { #if SFML int imageWidth = (int)image.Size.X; int imageHeight = (int)image.Size.Y; Color[] pixels = new Color[imageWidth * imageHeight]; using (var imageData = image.CopyToImage()) { int pixelChanIndex = 0; fixed(byte *pixelChan = imageData.Pixels) { fixed(Color *color = pixels) { for (int i = 0; i < pixels.Length; i++) { color[i].R = pixelChan[pixelChanIndex]; color[i].G = pixelChan[pixelChanIndex + 1]; color[i].B = pixelChan[pixelChanIndex + 2]; color[i].A = pixelChan[pixelChanIndex + 3]; pixelChanIndex += 4; } } } } #elif MONOGAME int imageWidth = image.Width; int imageHeight = image.Height; image.GetData <Color>(cachedColorArray); #endif SurfaceEditor editor = new SurfaceEditor(surface); editor.Clear(); global::System.Threading.Tasks.Parallel.For(0, imageHeight / surface.Font.Size.Y, (h) => //for (int h = 0; h < imageHeight / surface.Font.Size.Y; h++) { int startY = (h * surface.Font.Size.Y); //System.Threading.Tasks.Parallel.For(0, imageWidth / surface.Font.Size.X, (w) => for (int w = 0; w < imageWidth / surface.Font.Size.X; w++) { int startX = (w * surface.Font.Size.X); float allR = 0; float allG = 0; float allB = 0; for (int y = 0; y < surface.Font.Size.Y; y++) { for (int x = 0; x < surface.Font.Size.X; x++) { int cY = y + startY; int cX = x + startX; Color color = cachedColorArray[cY * imageWidth + cX]; allR += color.R; allG += color.G; allB += color.B; } } byte sr = (byte)(allR / (surface.Font.Size.X * surface.Font.Size.Y)); byte sg = (byte)(allG / (surface.Font.Size.X * surface.Font.Size.Y)); byte sb = (byte)(allB / (surface.Font.Size.X * surface.Font.Size.Y)); var newColor = new Color(sr, sg, sb); float sbri = newColor.GetBrightness() * 255; if (blockMode) { if (sbri > 204) { editor.SetGlyph(w, h, 219, newColor); //█ } else if (sbri > 152) { editor.SetGlyph(w, h, 178, newColor); //▓ } else if (sbri > 100) { editor.SetGlyph(w, h, 177, newColor); //▒ } else if (sbri > 48) { editor.SetGlyph(w, h, 176, newColor); //░ } } else { if (sbri > 230) { editor.SetGlyph(w, h, (int)'#', newColor); } else if (sbri > 207) { editor.SetGlyph(w, h, (int)'&', newColor); } else if (sbri > 184) { editor.SetGlyph(w, h, (int)'$', newColor); } else if (sbri > 161) { editor.SetGlyph(w, h, (int)'X', newColor); } else if (sbri > 138) { editor.SetGlyph(w, h, (int)'x', newColor); } else if (sbri > 115) { editor.SetGlyph(w, h, (int)'=', newColor); } else if (sbri > 92) { editor.SetGlyph(w, h, (int)'+', newColor); } else if (sbri > 69) { editor.SetGlyph(w, h, (int)';', newColor); } else if (sbri > 46) { editor.SetGlyph(w, h, (int)':', newColor); } else if (sbri > 23) { editor.SetGlyph(w, h, (int)'.', newColor); } } } } ); }
/// <summary> /// Returns a surface with the specified image rendered to it as characters. /// </summary> /// <param name="image">The image to render.</param> /// <returns>The surface.</returns> public TextSurface GetSurface(Texture2D image) { editor.Clear(); #if SFML using (var imageData = image.CopyToImage()) { using (var memStream = new global::System.IO.MemoryStream()) { var binForm = new global::System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); memStream.Write(imageData.Pixels, 0, imageData.Pixels.Length); memStream.Seek(0, global::System.IO.SeekOrigin.Begin); pixels = (Color[])binForm.Deserialize(memStream); } } #elif MONOGAME image.GetData <Color>(pixels); #endif System.Threading.Tasks.Parallel.For(0, surface.Width * surface.Height, (i) => //for (int i = 0; i < surface.Width * surface.Height; i++) { int allR = 0; int allG = 0; int allB = 0; int min = i * fontPixels; int max = min + fontPixels; for (int pixel = min; pixel < max; pixel++) { Color color = pixels[indexes[pixel]]; allR += color.R; allG += color.G; allB += color.B; } // print our character byte sr = (byte)(allR / fontPixels); byte sg = (byte)(allG / fontPixels); byte sb = (byte)(allB / fontPixels); var newColor = new Color(sr, sg, sb); float sbri = newColor.GetBrightness() * 255; Point surfacePoint = surface.GetPointFromIndex(i); if (UseBlockMode) { if (sbri > 204) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 219, newColor); //█ } else if (sbri > 152) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 178, newColor); //▓ } else if (sbri > 100) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 177, newColor); //▒ } else if (sbri > 48) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 176, newColor); //░ } else { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 0, Color.Black); } } else { if (sbri > 230) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'#', newColor); } else if (sbri > 207) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'&', newColor); } else if (sbri > 184) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'$', newColor); } else if (sbri > 161) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'X', newColor); } else if (sbri > 138) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'x', newColor); } else if (sbri > 115) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'=', newColor); } else if (sbri > 92) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'+', newColor); } else if (sbri > 69) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)';', newColor); } else if (sbri > 46) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)':', newColor); } else if (sbri > 23) { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, (int)'.', newColor); } else { editor.SetGlyph(surfacePoint.X, surfacePoint.Y, 0, Color.Black); } } } ); return(surface); }