/// <summary> /// Creates a new instance of the class. /// </summary> /// <param name="pixelWidth">Width the source texture.</param> /// <param name="pixelHeight">Height of the source texture.</param> /// <param name="font">Font used for rendering.</param> public TextureToSurfaceReader(int pixelWidth, int pixelHeight, IFont font, SadRogue.Primitives.Point fontSize) { width = pixelWidth; height = pixelHeight; pixels = new Color[pixelWidth * pixelHeight]; indexes = new int[pixelWidth * pixelHeight]; surface = new Console(pixelWidth / fontSize.X, pixelHeight / fontSize.Y) { Font = font, FontSize = fontSize }; fontPixels = fontSize.X * fontSize.Y; // build the indexes int currentIndex = 0; for (int h = 0; h < surface.Height; h++) { int startY = (h * surface.FontSize.Y); //System.Threading.Tasks.Parallel.For(0, image.Width / surface.Font.Size.X, (w) => for (int w = 0; w < surface.Width; w++) { int startX = (w * surface.FontSize.X); for (int y = 0; y < surface.FontSize.Y; y++) { for (int x = 0; x < surface.FontSize.X; x++) { int cY = y + startY; int cX = x + startX; indexes[currentIndex] = cY * pixelWidth + cX; currentIndex++; } } } } }
public LogConsole() : base(40, 40) { Position = new SadRogue.Primitives.Point(90 + 2, 1); messages = new Stack <string>(); }
public StatusConsole(GameObjects.Player player) : base(60, 3) { Position = new SadRogue.Primitives.Point(1, 30 + 1); this.player = player; }
public MessageConsole() : base(40, 1) { Position = new SadRogue.Primitives.Point(0, 0); }
public static Point ToPoint(this SadRogue.Primitives.Point point) => new Point(point.X, point.Y);
public MenuConsole(int width, int height) : base(width, height) { Position = new SadRogue.Primitives.Point(0, 0); }
/// <summary> /// Converts a texture's pixels to a <see cref="ICellSurface"/>. /// </summary> /// <param name="image">The texture to process.</param> /// <param name="font">The font used with the cell surface.</param> /// <param name="fontSize">The size of the font.</param> /// <param name="blockMode"><see langword="true"/> to indicate the result should use block characters instead of text characters.</param> /// <returns></returns> public static ICellSurface ToSurface(this Texture2D image, IFont font, SadRogue.Primitives.Point fontSize, bool blockMode = false) { int imageWidth = image.Width; int imageHeight = image.Height; Color[] pixels = new Color[imageWidth * imageHeight]; image.GetData <Color>(pixels); ICellSurface surface = new CellSurface(imageWidth / fontSize.X, imageHeight / fontSize.Y); global::System.Threading.Tasks.Parallel.For(0, imageHeight / fontSize.Y, (h) => //for (int h = 0; h < imageHeight / fontSize.Y; h++) { int startY = (h * fontSize.Y); //System.Threading.Tasks.Parallel.For(0, imageWidth / fontSize.X, (w) => for (int w = 0; w < imageWidth / fontSize.X; w++) { int startX = (w * fontSize.X); float allR = 0; float allG = 0; float allB = 0; for (int y = 0; y < fontSize.Y; y++) { for (int x = 0; x < fontSize.X; x++) { int cY = y + startY; int cX = x + startX; Color color = pixels[cY * imageWidth + cX]; allR += color.R; allG += color.G; allB += color.B; } } byte sr = (byte)(allR / (fontSize.X * fontSize.Y)); byte sg = (byte)(allG / (fontSize.X * fontSize.Y)); byte sb = (byte)(allB / (fontSize.X * fontSize.Y)); var newColor = new SadRogue.Primitives.Color(sr, sg, sb); float sbri = newColor.GetBrightness() * 255; if (blockMode) { if (sbri > 204) { surface.SetGlyph(w, h, 219, newColor); //█ } else if (sbri > 152) { surface.SetGlyph(w, h, 178, newColor); //▓ } else if (sbri > 100) { surface.SetGlyph(w, h, 177, newColor); //▒ } else if (sbri > 48) { surface.SetGlyph(w, h, 176, newColor); //░ } } else { if (sbri > 230) { surface.SetGlyph(w, h, '#', newColor); } else if (sbri > 207) { surface.SetGlyph(w, h, '&', newColor); } else if (sbri > 184) { surface.SetGlyph(w, h, '$', newColor); } else if (sbri > 161) { surface.SetGlyph(w, h, 'X', newColor); } else if (sbri > 138) { surface.SetGlyph(w, h, 'x', newColor); } else if (sbri > 115) { surface.SetGlyph(w, h, '=', newColor); } else if (sbri > 92) { surface.SetGlyph(w, h, '+', newColor); } else if (sbri > 69) { surface.SetGlyph(w, h, ';', newColor); } else if (sbri > 46) { surface.SetGlyph(w, h, ':', newColor); } else if (sbri > 23) { surface.SetGlyph(w, h, '.', newColor); } } } } ); return(surface); }
/// <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 Console GetSurface(Texture2D image) { surface.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); SadRogue.Primitives.Color newColor = new Color(sr, sg, sb).ToSadRogueColor(); float sbri = newColor.GetBrightness() * 255; SadRogue.Primitives.Point surfacePoint = SadRogue.Primitives.Point.FromIndex(i, surface.Width); if (UseBlockMode) { if (sbri > 204) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, 219, newColor); //█ } else if (sbri > 152) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, 178, newColor); //▓ } else if (sbri > 100) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, 177, newColor); //▒ } else if (sbri > 48) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, 176, newColor); //░ } else { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, 0, SadRogue.Primitives.Color.Black); } } else { if (sbri > 230) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, '#', newColor); } else if (sbri > 207) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, '&', newColor); } else if (sbri > 184) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, '$', newColor); } else if (sbri > 161) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, 'X', newColor); } else if (sbri > 138) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, 'x', newColor); } else if (sbri > 115) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, '=', newColor); } else if (sbri > 92) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, '+', newColor); } else if (sbri > 69) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, ';', newColor); } else if (sbri > 46) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, ':', newColor); } else if (sbri > 23) { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, '.', newColor); } else { surface.SetGlyph(surfacePoint.X, surfacePoint.Y, 0, SadRogue.Primitives.Color.Black); } } } ); return(surface); }