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); } }
/// <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 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 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); }