/// <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, Font font) { this.width = pixelWidth; this.height = pixelHeight; pixels = new Color[pixelWidth * pixelHeight]; indexes = new int[pixelWidth * pixelHeight]; surface = new BasicSurface(pixelWidth / font.Size.X, pixelHeight / font.Size.Y, font); fontPixels = font.Size.X * font.Size.Y; editor = new SurfaceEditor(surface); // build the indexes int currentIndex = 0; for (int h = 0; h < surface.Height; h++) { int startY = (h * surface.Font.Size.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.Font.Size.X); 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; indexes[currentIndex] = cY * pixelWidth + cX; currentIndex++; } } } } }
void addNewLayerFromFile_Click(object sender, EventArgs e) { SelectFilePopup popup = new SelectFilePopup(); popup.Closed += (o2, e2) => { if (popup.DialogResult) { BasicSurface newSurface = BasicSurface.Load(popup.SelectedFile); if (newSurface.Width != surface.Width || newSurface.Height != surface.Height) { var tempSurface = new BasicSurface(surface.Width, surface.Height, surface.Font); newSurface.Copy(tempSurface); var newLayer = surface.Add(tempSurface); LayerMetadata.Create("Loaded", true, true, true, newLayer); } else { var layer = surface.Add(newSurface); LayerMetadata.Create("Loaded", true, true, true, layer); } surface.IsDirty = true; RebuildListBox(); } }; popup.CurrentFolder = Environment.CurrentDirectory; popup.FileLoaderTypes = new FileLoaders.IFileLoader[] { new FileLoaders.BasicSurface() }; popup.Show(true); popup.Center(); }
public Map(int width, int height) { Width = width; Height = height; // Create our tiles for the map Tiles = new MapObjects.TileBase[width * height]; // Fill the map with floors. for (int i = 0; i < Tiles.Length; i++) { Tiles[i] = new MapObjects.Floor(); } // Create the text surface that the console will render, based on our tiles. Surface = new BasicSurface(width, height, Tiles, SadConsole.Global.FontDefault, new Rectangle(0, 0, Program.ScreenWidth, Program.ScreenHeight)); // Set some temp walls // y * width + x = index of that x,y combination Tiles[5 * width + 5] = new MapObjects.Wall(); Tiles[2 * width + 5] = new MapObjects.Wall(); Tiles[10 * width + 29] = new MapObjects.Wall(); Tiles[17 * width + 44] = new MapObjects.Wall(); Surface.RenderArea = Surface.RenderArea; // Entity container Entities = new List <CsTextRPG.Entities.EntityBase>(); // Add a player Player = new CsTextRPG.Entities.Player(); Entities.Add(Player); }
public void LoadMap(int width, int height, float scale = 0.1f) { this.scale = scale; w = width; h = height; Tiles = new Cell[width * height]; Simplex.Noise.Seed = 1; var noise = Simplex.Noise.Calc2D(width, height, scale); var minNoise = noise.Min(); var maxNoise = noise.Max(); noise.Map(n => n.Map(minNoise, maxNoise, min, max)); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int cellIndex = y * width + x; Tiles[cellIndex] = new Cell(colorRamp[(int)noise[x, y]], Color.Black); if (isShowAll || ((int)noise[x, y] >= layerRangeMin && (int)noise[x, y] <= (layerRangeMin + layerRange))) { Tiles[cellIndex].Glyph = 178; } } } // Create a surface for drawing. It uses the tiles from a map object. surface = new BasicSurface(width, height, Tiles, SadConsole.Global.FontDefault, new Rectangle(0, 0, Width, Height)); drawCall = new SadConsole.DrawCallSurface(surface, position, false); }
public void New(Color foreground, Color background, int width, int height) { int renderWidth = Math.Min(MainScreen.Instance.InnerEmptyBounds.Width, width); int renderHeight = Math.Min(MainScreen.Instance.InnerEmptyBounds.Height, height); hotspotSurface = new BasicSurface(renderWidth, renderHeight, Settings.Config.ScreenFont); // Create the new text surface surface = new LayeredSurface(width, height, new Rectangle(0, 0, renderWidth, renderHeight), 1); // Update metadata LayerMetadata.Create("main", false, false, true, surface.GetLayer(0)); surface.SetActiveLayer(0); surface.Font = Settings.Config.ScreenFont; // Update the layer management panel layerManagementPanel.SetLayeredSurface(surface); // Set the text surface as the one we're displaying // Update the border if (MainScreen.Instance.ActiveEditor == this) { MainScreen.Instance.RefreshBorder(); } }
public ScrollingConsole(int width, int height, int bufferHeight) { controlsContainer = new SadConsole.ControlsConsole(1, height); mainConsole = new SadConsole.Console(width - 1, bufferHeight); mainConsole.TextSurface.RenderArea = new Microsoft.Xna.Framework.Rectangle(0, 0, width - 1, height); mainConsole.VirtualCursor.IsVisible = false; scrollBar = SadConsole.Controls.ScrollBar.Create(System.Windows.Controls.Orientation.Vertical, height); scrollBar.IsEnabled = false; scrollBar.ValueChanged += ScrollBar_ValueChanged; controlsContainer.Add(scrollBar); controlsContainer.Position = new Microsoft.Xna.Framework.Point(1 + mainConsole.TextSurface.Width, Position.Y); Children.Add(mainConsole); Children.Add(controlsContainer); scrollingCounter = 0; borderSurface = new SadConsole.Surfaces.BasicSurface(width + 2, height + 2, mainConsole.TextSurface.Font); var editor = new SadConsole.Surfaces.SurfaceEditor(borderSurface); SadConsole.Shapes.Box box = SadConsole.Shapes.Box.Thick(); box.Width = borderSurface.Width; box.Height = borderSurface.Height; box.Draw(editor); renderer = new SurfaceRenderer(); renderer.Render(borderSurface); }
public void Load(string file, FileLoaders.IFileLoader loader) { ClearEntities(); ClearZones(); ClearHotspots(); if (loader is FileLoaders.Scene) { var scene = (SadConsole.GameHelpers.Scene)loader.Load(file); surface = (LayeredSurface)scene.Surface.TextSurface; int renderWidth = Math.Min(MainScreen.Instance.InnerEmptyBounds.Width, surface.Width); int renderHeight = Math.Min(MainScreen.Instance.InnerEmptyBounds.Height, surface.Height); surface.RenderArea = new Rectangle(0, 0, renderWidth, renderHeight); hotspotSurface = new BasicSurface(renderWidth, renderHeight, Settings.Config.ScreenFont); foreach (var item in scene.Objects) { LoadEntity(item); } foreach (var zone in scene.Zones) { LoadZone(zone); } foreach (var spot in scene.Hotspots) { LoadHotspot(spot); } } surface.Font = Settings.Config.ScreenFont; Title = Path.GetFileName(file); }
public void Resize(int width, int height) { int renderWidth = Math.Min(MainScreen.Instance.InnerEmptyBounds.Width, width); int renderHeight = Math.Min(MainScreen.Instance.InnerEmptyBounds.Height, height); var oldSurface = surface; var newSurface = new LayeredSurface(width, height, Settings.Config.ScreenFont, new Rectangle(0, 0, renderWidth, renderHeight), oldSurface.LayerCount); hotspotSurface = new BasicSurface(renderWidth, renderHeight, Settings.Config.ScreenFont); for (int i = 0; i < oldSurface.LayerCount; i++) { var oldLayer = oldSurface.GetLayer(i); var newLayer = newSurface.GetLayer(i); oldSurface.SetActiveLayer(i); newSurface.SetActiveLayer(i); oldSurface.Copy(newSurface); newLayer.Metadata = oldLayer.Metadata; newLayer.IsVisible = oldLayer.IsVisible; } surface = newSurface; layerManagementPanel.SetLayeredSurface(surface); toolsPanel.SelectedTool = toolsPanel.SelectedTool; if (MainScreen.Instance.ActiveEditor == this) { MainScreen.Instance.RefreshBorder(); } }
private void SelectedFrameChanged(BasicSurface frame) { var meta = surface.GetLayer(LayerDrawing); meta.Cells = meta.RenderCells = frame.Cells; surface.SetActiveLayer(LayerDrawing); surface.IsDirty = true; }
private BasicSurface SaveBrush() { BasicSurface newSurface = new BasicSurface(Brush.SelectedSurface.Animation.CurrentFrame.Width, Brush.SelectedSurface.Animation.CurrentFrame.Height, SadConsoleEditor.Settings.Config.ScreenFont); Brush.SelectedSurface.Animation.CurrentFrame.Copy(newSurface); return(newSurface); }
public void SetContent(ISurface surface, ISurfaceRenderer renderer) { Rectangle newBounds = MainScreen.Instance.InnerEmptyBounds; contentContainer.TextSurface = surface; contentContainer.TextSurface.Font = Settings.Config.ScreenFont; contentContainer.Renderer = renderer; TextSurface = new BasicSurface(surface.RenderArea.Width + 2, surface.RenderArea.Height + 2, Settings.Config.ScreenFont); PrepBox(); }
private void LoadAnsi() { Clear(); writer = new SadConsole.Ansi.AnsiWriter(doc, this); writer.ReadEntireDocument(); TextSurface = new BasicSurface(80, 25 + TimesShiftedUp); writer = new SadConsole.Ansi.AnsiWriter(doc, this); writer.ReadEntireDocument(); textSurface.RenderArea = new Rectangle(0, 0, 80, 25); writer = null; }
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 void Draw() { int virtualCursorLocationIndex = BasicSurface.GetIndexFromPoint( new Point(Console.VirtualCursor.Position.X - Console.TextSurface.RenderArea.Left, Console.VirtualCursor.Position.Y - Console.TextSurface.RenderArea.Top), Console.TextSurface.RenderArea.Width); if (virtualCursorLocationIndex >= 0 && virtualCursorLocationIndex < Console.TextSurface.RenderRects.Length) { var rect = Console.TextSurface.RenderRects[virtualCursorLocationIndex]; rect.Offset(Console.Position.ConsoleLocationToPixel(Console.TextSurface.Font.Size.X, Console.TextSurface.Font.Size.Y)); Console.VirtualCursor.Render(Global.SpriteBatch, Console.TextSurface.Font, rect); } }
public virtual void RenderControls(ISurface surface, bool force = false) { if ((surface.IsDirty || force) && surface.Tint.A != 255) { int cellCount; Rectangle rect; Point point; Controls.ControlBase control; Cell cell; Font font; // For each control for (int i = 0; i < Controls.Count; i++) { if (Controls[i].IsVisible) { control = Controls[i]; cellCount = control.TextSurface.Cells.Length; font = control.AlternateFont == null ? surface.Font : control.AlternateFont; // Draw background of each cell for the control for (int cellIndex = 0; cellIndex < cellCount; cellIndex++) { cell = control[cellIndex]; if (cell.IsVisible) { point = BasicSurface.GetPointFromIndex(cellIndex, control.TextSurface.Width); point = new Point(point.X + control.Position.X, point.Y + control.Position.Y); if (surface.RenderArea.Contains(point.X, point.Y)) { point = new Point(point.X - surface.RenderArea.Left, point.Y - surface.RenderArea.Top); rect = surface.RenderRects[surface.GetIndexFromPoint(point)]; if (cell.Background != Color.Transparent) { Global.SpriteBatch.Draw(font.FontImage, rect, font.GlyphRects[font.SolidGlyphIndex], cell.Background, 0f, Vector2.Zero, SpriteEffects.None, 0.23f); } if (cell.Foreground != Color.Transparent) { Global.SpriteBatch.Draw(font.FontImage, rect, font.GlyphRects[cell.Glyph], cell.Foreground, 0f, Vector2.Zero, cell.Mirror, 0.26f); } } } } } } } }
public DungeonScreen(int screenX, int screenY, int screenWidth, int screenHeight, Font font) { Position = new Point(screenX, screenY); Width = screenWidth; Height = screenHeight; borderSurface = new SadConsole.Surfaces.BasicSurface(Width + 1, Height + 1, font); var editor = new SadConsole.Surfaces.SurfaceEditor(borderSurface); SadConsole.Shapes.Box box = SadConsole.Shapes.Box.Thick(); box.Width = borderSurface.Width; box.Height = borderSurface.Height; box.Draw(editor); renderer = new SurfaceRenderer(); renderer.Render(borderSurface); }
/// <summary> /// Called before the renderer applies a tint color. /// </summary> /// <param name="batch">The batch used in renderering.</param> protected virtual void OnBeforeRenderTint(SpriteBatch batch) { if (VirtualCursor.IsVisible) { // Bug - Virtual cursor position index is incorrectly positioned in the render area when the render area // is smaller than width. // Render int virtualCursorLocationIndex = BasicSurface.GetIndexFromPoint( new Point(VirtualCursor.Position.X - TextSurface.RenderArea.Left, VirtualCursor.Position.Y - TextSurface.RenderArea.Top), TextSurface.RenderArea.Width); if (virtualCursorLocationIndex >= 0 && virtualCursorLocationIndex < textSurface.RenderRects.Length) { VirtualCursor.Render(batch, textSurface.Font, textSurface.RenderRects[virtualCursorLocationIndex]); } } }
public void LoadBrush(BasicSurface surface) { _panel.State = SelectionToolPanel.CloneState.Stamp; // Copy data to new animation var cloneAnimation = new AnimatedSurface("clone", surface.Width, surface.Height, SadConsoleEditor.Settings.Config.ScreenFont); var frame = cloneAnimation.CreateFrame(); surface.Copy(frame); cloneAnimation.Center = new Point(cloneAnimation.Width / 2, cloneAnimation.Height / 2); Brush.SelectedSurface.Animation = cloneAnimation; //Brush.Animation.Tint = new Color(0f, 0f, 0f, 0f); Brush.IsVisible = true; MakeBoxAnimation(surface.Width, surface.Height, cloneAnimation.Center); }
public override void Draw(TimeSpan delta) { // These 3 render calls are a hack to get the console data generated and display a message to the user // Should add in async calls that let us generate these in the background... That would be cool. if (IsVisible) { if (!initialized) { base.Draw(delta); } else if (!initializedStep2) { initializedStep2 = true; base.Draw(delta); } else if (!initializedStep3) { base.Draw(delta); // Generate the content TextSurface = new BasicSurface(2000, 2000, new Rectangle(0, 0, 80, 23)); // Clear message data and make it transparent so that it acts as a layer messageData.Fill(Color.White, Color.Transparent, 0, null); // We need to set celldata to the big console data so we can use the FillWithRandom method. FillWithRandomGarbage(); initializedStep3 = true; } else { // Set message data information about where the viewport is located //messageData.Print(0, 0, $"{ViewArea.X} , {ViewArea.Y} ", Color.White, Color.Black); // Create a faux layering system. base.Draw(delta); //Renderer.Render(messageData.TextSurface, new Point(0, 0)); } } }
public override void Update(TimeSpan delta) { // If we're generating a new if (state == InitState.BeforeGeneration) { // Clear out the text surface TextSurface = new BasicSurface(1, 1); state = InitState.Generating; SetMessage("Generating map, please wait... "); // Kick off task loadingAnimation.Start(); createRandomWorldTask = new Task <BasicSurface>(GenerateWorld); createRandomWorldTask.Start(); } else if (state == InitState.Generating) { // Update the animation loadingAnimation.Update(); // "Print" the animation to the message console. loadingAnimation.Copy(messageData.TextSurface, messageData.Width - 1, 0); // If task done... if (createRandomWorldTask.IsCompleted) { SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Biome "); this.TextSurface = createRandomWorldTask.Result; state = InitState.AfterGeneration; } } else if (state == InitState.AfterGeneration) { loadingAnimation.Stop(); state = InitState.Completed; } else { base.Update(delta); } }
void saveLayerToFile_Click(object sender, EventArgs e) { var layer = (LayeredSurface.Layer)layers.SelectedItem; SelectFilePopup popup = new SelectFilePopup(); popup.Closed += (o2, e2) => { if (popup.DialogResult) { BasicSurface newSurface = new BasicSurface(surface.Width, surface.Height, layer.Cells, SadConsoleEditor.Settings.Config.ScreenFont, new Microsoft.Xna.Framework.Rectangle(0, 0, surface.Width, surface.Height)); newSurface.Save(popup.SelectedFile); } }; popup.CurrentFolder = Environment.CurrentDirectory; popup.FileLoaderTypes = new FileLoaders.IFileLoader[] { new FileLoaders.BasicSurface() }; popup.SelectButtonText = "Save"; popup.SkipFileExistCheck = true; popup.Show(true); popup.Center(); }
void saveFrameToFile_Click(object sender, EventArgs e) { SelectFilePopup popup = new SelectFilePopup(); popup.Closed += (o2, e2) => { if (popup.DialogResult) { BasicSurface surface = new BasicSurface(selectedFrame.Width, selectedFrame.Height, selectedFrame.Cells, Settings.Config.ScreenFont, new Microsoft.Xna.Framework.Rectangle(0, 0, selectedFrame.Width, selectedFrame.Height)); surface.DefaultForeground = selectedFrame.DefaultForeground; surface.DefaultBackground = selectedFrame.DefaultBackground; popup.SelectedLoader.Save(surface, popup.SelectedFile); } }; popup.CurrentFolder = Environment.CurrentDirectory; popup.FileLoaderTypes = new FileLoaders.IFileLoader[] { new FileLoaders.BasicSurface(), new FileLoaders.TextFile() }; popup.SelectButtonText = "Save"; popup.SkipFileExistCheck = true; popup.Show(true); popup.Center(); }
public bool HandleKeyboard(IConsole console, SadConsole.Input.Keyboard info) { var realConsole = (SadConsole.Console)console; // Check each key pressed. foreach (var key in info.KeysPressed) { // If the character associated with the key pressed is a printable character, print it if (key.Character != '\0') { int startingIndex = BasicSurface.GetIndexFromPoint(new Point(Room.MapWidth + 2, Room.MapHeight + 4), console.TextSurface.Width); String data = realConsole.GetString(startingIndex, BasicSurface.GetIndexFromPoint(console.VirtualCursor.Position, console.TextSurface.Width) - startingIndex); if (data.Length < 14) { console.VirtualCursor.Print(key.Character.ToString().ToUpper()); } } // Special character - BACKSPACE else if (key.Key == Keys.Back) { // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much. if (realConsole.TimesShiftedUp != 0) { realConsole.TimesShiftedUp = 0; } // Do not let them backspace into the prompt if (console.VirtualCursor.Position.Y != Room.MapHeight + 4 || console.VirtualCursor.Position.X > Room.MapWidth + 2) { console.VirtualCursor.LeftWrap(1).Print(" ").LeftWrap(1); } } // Special character - ENTER else if (key.Key == Keys.Enter) { // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much. if (realConsole.TimesShiftedUp != 0) { VirtualCursorLastY -= realConsole.TimesShiftedUp; realConsole.TimesShiftedUp = 0; } // Get the prompt to exclude it in determining the total length of the string the user has typed. int startingIndex = BasicSurface.GetIndexFromPoint(new Point(Room.MapWidth + 2, Room.MapHeight + 4), console.TextSurface.Width); String data = realConsole.GetString(startingIndex, BasicSurface.GetIndexFromPoint(console.VirtualCursor.Position, console.TextSurface.Width) - startingIndex); // Move the cursor to the next line before we send the string data to the processor // Send the string data EnterPressedAction(data); // After they have processed the string, we will create a new line and display the prompt. VirtualCursorLastY = console.VirtualCursor.Position.Y; // Preparing the next lines could have scrolled the console, reset the counter realConsole.TimesShiftedUp = 0; } } return(true); }
public void ProcessMouse(MouseConsoleState info, ISurface surface, bool isInBounds) { if (info.Mouse.LeftClicked && info.IsOnConsole) { Cell cellToMatch = new Cell(); Cell currentFillCell = new Cell(); info.Cell.CopyAppearanceTo(cellToMatch); currentFillCell.Glyph = CharacterPickPanel.SharedInstance.SettingCharacter; currentFillCell.Foreground = CharacterPickPanel.SharedInstance.SettingForeground; currentFillCell.Background = CharacterPickPanel.SharedInstance.SettingBackground; currentFillCell.Mirror = CharacterPickPanel.SharedInstance.SettingMirrorEffect; Func <Cell, bool> isTargetCell = (c) => { if (c.Glyph == 0 && cellToMatch.Glyph == 0) { return(c.Background == cellToMatch.Background); } return(c.Foreground == cellToMatch.Foreground && c.Background == cellToMatch.Background && c.Glyph == cellToMatch.Glyph && c.Mirror == cellToMatch.Mirror); }; Action <Cell> fillCell = (c) => { currentFillCell.CopyAppearanceTo(c); //console.TextSurface.SetEffect(c, _currentFillCell.Effect); }; System.Collections.Generic.List <Cell> cells = new System.Collections.Generic.List <Cell>(surface.Cells); Func <Cell, SadConsole.Algorithms.NodeConnections <Cell> > getConnectedCells = (c) => { Algorithms.NodeConnections <Cell> connections = new Algorithms.NodeConnections <Cell>(); Point position = BasicSurface.GetPointFromIndex(cells.IndexOf(c), surface.Width); connections.West = surface.IsValidCell(position.X - 1, position.Y) ? surface.GetCell(position.X - 1, position.Y) : null; connections.East = surface.IsValidCell(position.X + 1, position.Y) ? surface.GetCell(position.X + 1, position.Y) : null; connections.North = surface.IsValidCell(position.X, position.Y - 1) ? surface.GetCell(position.X, position.Y - 1) : null; connections.South = surface.IsValidCell(position.X, position.Y + 1) ? surface.GetCell(position.X, position.Y + 1) : null; return(connections); }; if (!isTargetCell(currentFillCell)) { SadConsole.Algorithms.FloodFill <Cell>(info.Cell, isTargetCell, fillCell, getConnectedCells); } info.Console.TextSurface.IsDirty = true; } if (info.Mouse.RightButtonDown && info.IsOnConsole) { var cell = info.Cell; CharacterPickPanel.SharedInstance.SettingCharacter = cell.Glyph; CharacterPickPanel.SharedInstance.SettingForeground = cell.Foreground; CharacterPickPanel.SharedInstance.SettingBackground = cell.Background; CharacterPickPanel.SharedInstance.SettingMirrorEffect = cell.Mirror; } }
public void LoadMap(Map map) { TextSurface = new BasicSurface(map.Width, map.Height, map.Tiles, Global.FontDefault, new Rectangle(0, 0, map.Width, map.Height)); drawCall = new DrawCallSurface(TextSurface, position, false); }
public static BasicSurface 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); BasicSurface surface = new BasicSurface(imageWidth / font.Size.X, imageHeight / font.Size.Y, font); SurfaceEditor editor = new SurfaceEditor(surface); 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 = pixels[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); } } } } ); return(surface); }
public bool HandleKeyboard(IConsole consoleObject, SadConsole.Input.Keyboard info) { // Upcast this because we know we're only using it with a Console type. var console = (Console)consoleObject; // Check each key pressed. foreach (var key in info.KeysPressed) { // If the character associated with the key pressed is a printable character, print it if (key.Character != '\0') { console.VirtualCursor.Print(key.Character.ToString()); } // Special character - BACKSPACE else if (key.Key == Keys.Back) { // Get the prompt that the console has. string prompt = ((CustomConsoles.DOSConsole)console).Prompt; // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much. if (console.TimesShiftedUp != 0) { VirtualCursorLastY -= console.TimesShiftedUp; console.TimesShiftedUp = 0; } // Do not let them backspace into the prompt if (console.VirtualCursor.Position.Y != VirtualCursorLastY || console.VirtualCursor.Position.X > prompt.Length) { console.VirtualCursor.LeftWrap(1).Print(" ").LeftWrap(1); } } // Special character - ENTER else if (key.Key == Keys.Enter) { // If the console has scrolled since the user started typing, adjust the starting row of the virtual cursor by that much. if (console.TimesShiftedUp != 0) { VirtualCursorLastY -= console.TimesShiftedUp; console.TimesShiftedUp = 0; } // Get the prompt to exclude it in determining the total length of the string the user has typed. string prompt = ((CustomConsoles.DOSConsole)console).Prompt; int startingIndex = BasicSurface.GetIndexFromPoint(new Point(prompt.Length, VirtualCursorLastY), console.TextSurface.Width); string data = ((Console)console).GetString(startingIndex, BasicSurface.GetIndexFromPoint(console.VirtualCursor.Position, console.TextSurface.Width) - startingIndex); // Move the cursor to the next line before we send the string data to the processor console.VirtualCursor.CarriageReturn().LineFeed(); // Send the string data EnterPressedAction(data); // After they have processed the string, we will create a new line and display the prompt. console.VirtualCursor.CarriageReturn().LineFeed(); console.VirtualCursor.DisableWordBreak = true; console.VirtualCursor.Print(((CustomConsoles.DOSConsole)console).Prompt); console.VirtualCursor.DisableWordBreak = false; VirtualCursorLastY = console.VirtualCursor.Position.Y; // Preparing the next lines could have scrolled the console, reset the counter console.TimesShiftedUp = 0; } } return(true); }
public void LoadMap(Map map) { // Create a surface for drawing. It uses the tiles from a map object. surface = new BasicSurface(map.Width, map.Height, map.Tiles, SadConsole.Global.FontDefault, new Rectangle(0, 0, Width, Height)); drawCall = new SadConsole.DrawCallSurface(surface, position, false); }
public SplashScreen() : base(80, 23) { IsVisible = false; effectsManager = new EffectsManager(this.TextSurface); // Setup the console text background string textTemplate = "sole SadCon"; System.Text.StringBuilder text = new System.Text.StringBuilder(2200); for (int i = 0; i < TextSurface.Width * TextSurface.Height; i++) { text.Append(textTemplate); } Print(0, 0, text.ToString(), Color.Black, Color.Transparent); // Load the logo System.IO.Stream imageStream = Microsoft.Xna.Framework.TitleContainer.OpenStream("sad.png"); var image = Texture2D.FromStream(Global.GraphicsDevice, imageStream); imageStream.Dispose(); // Configure the logo _consoleImage = image.ToSurface(Global.FontDefault, false); _consoleImagePosition = new Point(TextSurface.Width / 2 - _consoleImage.Width / 2, -1); _consoleImage.Tint = Color.Black; // Configure the animations _animation = new InstructionSet(); _animation.Instructions.AddLast(new Wait() { Duration = 0.3f }); // Animation to move the angled gradient spotlight effect. var moveGradientInstruction = new CodeInstruction(); moveGradientInstruction.CodeCallback = (inst) => { _x += 1; if (_x > TextSurface.Width + 50) { inst.IsFinished = true; } Color[] colors = new Color[] { Color.Black, Color.Blue, Color.White, Color.Blue, Color.Black }; float[] colorStops = new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }; Algorithms.GradientFill(TextSurface.Font.Size, new Point(_x, 12), 10, 45, new Rectangle(0, 0, TextSurface.Width, TextSurface.Height), new ColorGradient(colors, colorStops), SetForeground); }; _animation.Instructions.AddLast(moveGradientInstruction); // Animation to clear the SadConsole text. _animation.Instructions.AddLast(new CodeInstruction() { CodeCallback = (i) => { Fill(Color.Black, Color.Transparent, 0, null); i.IsFinished = true; } }); // Animation for the logo text. var logoText = new ColorGradient(new Color[] { Color.Magenta, Color.Yellow }, new float[] { 0.0f, 1f }).ToColoredString("[| Powered by SadConsole |]"); logoText.SetEffect(new SadConsole.Effects.Fade() { DestinationForeground = Color.Blue, FadeForeground = true, FadeDuration = 1f, Repeat = false, RemoveOnFinished = true, Permanent = true, CloneOnApply = true }); _animation.Instructions.AddLast(new DrawString(this) { Position = new Point(26, this.TextSurface.Height - 1), Text = logoText, TotalTimeToPrint = 1f }); // Animation for fading in the logo picture. _animation.Instructions.AddLast(new FadeTextSurfaceTint(_consoleImage, new ColorGradient(Color.Black, Color.Transparent), new TimeSpan(0, 0, 0, 0, 2000))); // Animation to blink SadConsole in the logo text _animation.Instructions.AddLast(new CodeInstruction() { CodeCallback = (i) => { SadConsole.Effects.Fade fadeEffect = new SadConsole.Effects.Fade(); fadeEffect.AutoReverse = true; fadeEffect.DestinationForeground = new ColorGradient(Color.Blue, Color.Yellow); fadeEffect.FadeForeground = true; fadeEffect.UseCellForeground = false; fadeEffect.Repeat = true; fadeEffect.FadeDuration = 0.7f; fadeEffect.RemoveOnFinished = true; List <Cell> cells = new List <Cell>(); for (int index = 0; index < 10; index++) { var point = new Point(26, this.TextSurface.Height - 1).ToIndex(this.TextSurface.Width) + 14 + index; cells.Add(textSurface.Cells[point]); cellindexes.Add(point); } effectsManager.SetEffect(cells, fadeEffect); i.IsFinished = true; } }); // Animation to delay, keeping the logo and all on there for 2 seconds, then destroy itself. _animation.Instructions.AddLast(new Wait() { Duration = 2.5f }); _animation.Instructions.AddLast(new FadeTextSurfaceTint(_consoleImage, new ColorGradient(Color.Transparent, Color.Black), new TimeSpan(0, 0, 0, 0, 2000))); _animation.Instructions.AddLast(new CodeInstruction() { CodeCallback = (i) => { SplashCompleted?.Invoke(); i.IsFinished = true; } }); }