private CellSurface PrintingCells() { CellSurface surface = new CellSurface(3, 3); surface.DefaultBackground = Color.Transparent; surface.DefaultForeground = Color.DarkGoldenrod; surface.SetGlyph(0, 0, ' '); surface.SetGlyph(1, 0, ' '); surface.SetGlyph(2, 0, ' '); surface.SetGlyph(0, 1, '('); surface.SetGlyph(1, 1, ' '); surface.SetGlyph(2, 1, ')'); surface.SetGlyph(0, 2, ' '); surface.SetGlyph(1, 2, ' '); surface.SetGlyph(2, 2, '\\'); return(surface); }
public override void Draw(CellSurface surface, Rectangle area, object item, ControlStates itemState) { if (item is Color || item is Tuple <Color, Color, string> ) { string value = new string(' ', area.Width - 2); Cell cellLook = GetStateAppearance(itemState).Clone(); surface.Print(area.Left + 1, area.Top, value, cellLook); surface.Print(area.Left, area.Top, " ", cellLook); surface.Print(area.Left + area.Width - 1, area.Top, " ", cellLook); if (item is Color color) { cellLook.Background = color; surface.Print(area.Left + 1, area.Top, value, cellLook); } else { cellLook.Foreground = ((Tuple <Color, Color, string>)item).Item2; cellLook.Background = ((Tuple <Color, Color, string>)item).Item1; value = ((Tuple <Color, Color, string>)item).Item3.Align(HorizontalAlignment.Left, area.Width - 2); surface.Print(area.Left + 1, area.Top, value, cellLook); } if (itemState.HasFlag(ControlStates.Selected)) { surface.SetGlyph(area.Left, area.Top, 16); surface.SetGlyph(area.Left + area.Width - 1, area.Top, 17); } } else { base.Draw(surface, area, item, itemState); } }
private void Viewer_MouseMove(object sender, SadConsole.UI.Controls.ControlBase.ControlMouseState e) { if (e.OriginalMouseState.Mouse.LeftButtonDown) { if (!isDrawing) { isDrawing = true; mouseColors.ShiftLeft(); } var viewer = (SadConsole.UI.Controls.SurfaceViewer)sender; if (viewer.IsMouseButtonStateClean && viewer.SurfaceControl.MouseArea.Contains(e.MousePosition)) { _sharedSurface.SetGlyph(e.MousePosition.X + viewer.ChildSurface.ViewPosition.X, e.MousePosition.Y + viewer.ChildSurface.ViewPosition.Y, 0, mouseColors[0], mouseColors[0]); } } else { if (isDrawing) { isDrawing = false; } } }
public ScrollableView() : base(Program.MainWidth, Program.MainHeight) { // Create the shared surface _sharedSurface = new CellSurface(37, Program.MainHeight - 2); _sharedSurface.FillWithRandomGarbage(Font); // Create a 012345... border around the surface int counter = 0; for (int i = 0; i < Surface.Width; i++) { _sharedSurface.SetGlyph(i, 0, counter + 48, Color.Green, Color.Black, Mirror.None); _sharedSurface.SetGlyph(i, _sharedSurface.Height - 1, counter + 48, Color.Green, Color.Black, Mirror.None); counter++; if (counter == 10) { counter = 0; } } counter = 0; for (int i = 0; i < Surface.Height; i++) { _sharedSurface.SetGlyph(0, i, counter + 48, Color.Green, Color.Black, Mirror.None); _sharedSurface.SetGlyph(_sharedSurface.Width - 1, i, counter + 48, Color.Green, Color.Black, Mirror.None); counter++; if (counter == 10) { counter = 0; } } // Create viewer controls and attach them to the surface SadConsole.UI.Controls.SurfaceViewer viewer = new SadConsole.UI.Controls.SurfaceViewer(15, 15); viewer.ScrollBarMode = SadConsole.UI.Controls.SurfaceViewer.ScrollBarModes.AsNeeded; viewer.SetSurface(_sharedSurface); viewer.Position = (2, 1); viewer.MouseMove += Viewer_MouseMove; Controls.Add(viewer); viewer = new SadConsole.UI.Controls.SurfaceViewer(20, 10); viewer.ScrollBarMode = SadConsole.UI.Controls.SurfaceViewer.ScrollBarModes.AsNeeded; viewer.SetSurface(_sharedSurface); viewer.Position = (19, 1); viewer.MouseMove += Viewer_MouseMove; Controls.Add(viewer); viewer = new SadConsole.UI.Controls.SurfaceViewer(20, 10); viewer.ScrollBarMode = SadConsole.UI.Controls.SurfaceViewer.ScrollBarModes.AsNeeded; viewer.SetSurface(_sharedSurface); viewer.Position = (19, 12); viewer.MouseMove += Viewer_MouseMove; Controls.Add(viewer); viewer = new SadConsole.UI.Controls.SurfaceViewer(_sharedSurface.Width, _sharedSurface.Height); viewer.ScrollBarMode = SadConsole.UI.Controls.SurfaceViewer.ScrollBarModes.AsNeeded; viewer.SetSurface(_sharedSurface); viewer.Position = (41, 1); viewer.MouseMove += Viewer_MouseMove; Controls.Add(viewer); // Setup mouse palette mouseColors = new Palette(new[] { Color.AnsiBlue, Color.AnsiCyan, Color.AnsiGreen, Color.AnsiGreenBright, Color.AnsiRed, Color.AnsiRedBright }); }
public static CellSurface ToSurface(this Texture2D image, SadConsole.Font font, bool blockMode = false) { int imageWidth = image.Width; int imageHeight = image.Height; Color[] pixels = new Color[imageWidth * imageHeight]; image.GetData <Color>(pixels); CellSurface surface = new CellSurface(imageWidth / font.Size.X, imageHeight / font.Size.Y); global::System.Threading.Tasks.Parallel.For((int)0, (int)(imageHeight / font.Size.Y), (h) => //for (int h = 0; h < imageHeight / font.Size.Y; h++) { int startY = (h * font.Size.Y); //System.Threading.Tasks.Parallel.For(0, imageWidth / font.Size.X, (w) => for (int w = 0; w < imageWidth / font.Size.X; w++) { int startX = (w * font.Size.X); float allR = 0; float allG = 0; float allB = 0; for (int y = 0; y < font.Size.Y; y++) { for (int x = 0; x < font.Size.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 / (font.Size.X * font.Size.Y)); byte sg = (byte)(allG / (font.Size.X * font.Size.Y)); byte sb = (byte)(allB / (font.Size.X * font.Size.Y)); var newColor = new 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, (int)'#', newColor); } else if (sbri > 207) { surface.SetGlyph(w, h, (int)'&', newColor); } else if (sbri > 184) { surface.SetGlyph(w, h, (int)'$', newColor); } else if (sbri > 161) { surface.SetGlyph(w, h, (int)'X', newColor); } else if (sbri > 138) { surface.SetGlyph(w, h, (int)'x', newColor); } else if (sbri > 115) { surface.SetGlyph(w, h, (int)'=', newColor); } else if (sbri > 92) { surface.SetGlyph(w, h, (int)'+', newColor); } else if (sbri > 69) { surface.SetGlyph(w, h, (int)';', newColor); } else if (sbri > 46) { surface.SetGlyph(w, h, (int)':', newColor); } else if (sbri > 23) { surface.SetGlyph(w, h, (int)'.', newColor); } } } } ); return(surface); }