private void PlotCell(SurfaceEditor surface, int x, int y, int glyph, bool fillMe = false) { if (surface.IsValidCell(x, y)) { var cell = surface[x, y]; if (fillMe) { cell.Background = FillColor; cell.Foreground = Foreground; cell.Glyph = glyph; return; } if (Foreground != Color.Transparent || DrawTransparency) { cell.Foreground = Foreground; } if (BorderBackground != Color.Transparent || DrawTransparency) { cell.Background = BorderBackground; } cell.Glyph = glyph; } }
/// <summary> /// Creates an animated surface that looks like static. /// </summary> /// <param name="width">The width of the surface.</param> /// <param name="height">The height of the surface.</param> /// <param name="frames">How many frames the animation should have.</param> /// <param name="blankChance">Chance a character will be blank. Characters are between index 48-158. Chance is evaluated versus <see cref="System.Random.NextDouble"/>.</param> /// <returns>An animation.</returns> public static AnimatedSurface CreateStatic(int width, int height, int frames, double blankChance) { var animation = new AnimatedSurface("default", width, height, Global.FontDefault); var editor = new SurfaceEditor(new BasicSurface(1, 1, Global.FontDefault)); for (int f = 0; f < frames; f++) { var frame = animation.CreateFrame(); editor.TextSurface = frame; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int character = Global.Random.Next(48, 168); if (Global.Random.NextDouble() <= blankChance) { character = 32; } editor.SetGlyph(x, y, character); editor.SetForeground(x, y, Color.White * (float)(Global.Random.NextDouble() * (1.0d - 0.5d) + 0.5d)); } } } animation.AnimationDuration = 1; animation.Repeat = true; animation.Start(); return(animation); }
public GradientStatusPanel(BaseStat bs, int width, int height, Color colorOne, Color colorTwo) : base(width, height) { this.colorOne = colorOne; this.colorTwo = colorTwo; editor = new SurfaceEditor(this); stat = bs; }
public RandomScrollingConsole() : base(80, 25) { messageData = new SurfaceEditor(new TextSurface(10, 1, Engine.DefaultFont)); IsVisible = false; KeyboardHandler = (cons, info) => { if (info.IsKeyDown(Keys.Left)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left - 1, cons.TextSurface.RenderArea.Top, 80, 25); } if (info.IsKeyDown(Keys.Right)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left + 1, cons.TextSurface.RenderArea.Top, 80, 25); } if (info.IsKeyDown(Keys.Up)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left, cons.TextSurface.RenderArea.Top - 1, 80, 25); } if (info.IsKeyDown(Keys.Down)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left, cons.TextSurface.RenderArea.Top + 1, 80, 25); } return(true); }; }
/// <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++; } } } } }
public void Draw(SurfaceEditor surface) { for (int x = Location.X; x < Location.X + Width; x++) { for (int y = Location.Y; y < Location.Y + Height; y++) { // Top row if (y == Location.Y) { if (x == Location.X) { PlotCell(surface, x, y, TopLeftCharacter); } else if (x == Location.X + Width - 1) { PlotCell(surface, x, y, TopRightCharacter); } else { PlotCell(surface, x, y, TopSideCharacter); } } // Bottom row else if (y == Location.Y + Height - 1) { if (x == Location.X) { PlotCell(surface, x, y, BottomLeftCharacter); } else if (x == Location.X + Width - 1) { PlotCell(surface, x, y, BottomRightCharacter); } else { PlotCell(surface, x, y, BottomSideCharacter); } } // Other rows else { if (x == Location.X) { PlotCell(surface, x, y, LeftSideCharacter); } else if (x == Location.X + Width - 1) { PlotCell(surface, x, y, RightSideCharacter); } else if (Fill) { PlotCell(surface, x, y, 0, Fill); } } } } }
/// <summary> /// Creates a new Scene from an existing <see cref="LayeredSurface"/>. /// </summary> /// <param name="surface">The surface for the scene.</param> /// <param name="renderer">The renderer for the surface.</param> public Scene(ISurface surface, Renderers.ISurfaceRenderer renderer) { Surface = new SurfaceEditor(surface); SurfaceRenderer = renderer; Objects = new List <GameObject>(); Zones = new List <Zone>(); Hotspots = new List <Hotspot>(); }
//public ICellAppearance FillAppearance; //public bool Fill; public void Draw(SurfaceEditor surface) { Algorithms.Ellipse(StartingPoint.X, StartingPoint.Y, EndingPoint.X, EndingPoint.Y, (x, y) => { if (surface.IsValidCell(x, y)) { surface.SetCellAppearance(x, y, BorderAppearance); } }); }
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 void SurfaceEditorTest() { var surfaceEditor1 = new SurfaceEditor(surface); surfaceEditor1.ShowDialog(); var surfaceEditor2 = new SurfaceEditor(surfaceEditor1.Surface); surfaceEditor2.ShowDialog(); }
public BorderedConsole(int width, int height) : base(width - 1, height - 1) { borderSurface = new TextSurface(width, height, base.textSurface.Font); borderEdit = new SurfaceEditor(borderSurface); Box box = Box.GetDefaultBox(); box.Width = borderSurface.Width; box.Height = borderSurface.Height; box.Draw(borderEdit); }
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; }
ParseCommandBase CustomParseCommand(string command, string parameters, ColoredGlyph[] glyphString, ISurface surface, SurfaceEditor editor, ParseCommandStacks commandStacks) { switch (command) { case "t": return(new ParseCommandRetext(parameters)); default: return(null);; } }
protected override void OnItemClick(Object selectedObject) { if (selectedObject is Material) { CSGModel activeModel = CSGModel.GetActiveCSGModel(); if (activeModel != null) { SurfaceEditor surfaceEditor = (SurfaceEditor)activeModel.GetTool(MainMode.Face); surfaceEditor.SetSelectionMaterial((Material)selectedObject); } } }
public void Draw(SurfaceEditor surface) { if (BorderAppearance == null) { BorderAppearance = new CellAppearance(Color.Blue, Color.Black, 4); } Algorithms.Circle(Center.X, Center.Y, Radius, (x, y) => { if (surface.IsValidCell(x, y)) { surface.SetCellAppearance(x, y, BorderAppearance); } }); }
public static GameObject CreateFromGlyph(int glyph, Color color = new Color()) { if (color == new Color()) { color = Color.White; } var animation = new AnimatedSurface("anim", 1, 1); var editor = new SurfaceEditor(animation.CreateFrame()); editor.SetGlyph(0, 0, glyph, color); return(new GameObject(animation)); }
public void Save(object surface, string file) { ISurface textSurface = (ISurface)surface; SurfaceEditor editor = new SurfaceEditor(textSurface); string[] lines = new string[textSurface.Height]; for (int y = 0; y < textSurface.Height; y++) { lines[y] = editor.GetString(0, y, textSurface.Width); } System.IO.File.WriteAllLines(file, lines); }
public AnsiWriter(Document ansiDocument, SurfaceEditor console) { _ansiDoc = ansiDocument; _console = console; _cursor = new Cursor(console); _cursor.UseStringParser = false; _cursor.DisableWordBreak = true; CharactersPerSecond = 800; _bytes = ansiDocument.AnsiBytes; _ansiState = new State(); _ansiCodeBuilder = new StringBuilder(5); _ansiStringBuilder = new StringBuilder(40); }
public static VertexColorWindow CreateAndShow(CSGModel csgModel, SurfaceEditor surfaceEditor) { VertexColorWindow window = EditorWindow.GetWindow <VertexColorWindow>(true, "Vertex Colors", true); window.surfaceEditor = surfaceEditor; window.csgModel = csgModel; // By setting both sizes to the same, even the resize cursor hover is automatically disabled window.minSize = WINDOW_SIZE; window.maxSize = WINDOW_SIZE; window.Show(); return(window); }
public BasicSurface GetHeatMapTexture(int width, int height, Tile[,] tiles) { var surface = new SurfaceEditor(new BasicSurface(width, height)); var pixels = new Color[width * height]; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { switch (tiles[x, y].HeatType) { case HeatType.Coldest: pixels[x + y * width] = Coldest; break; case HeatType.Colder: pixels[x + y * width] = Colder; break; case HeatType.Cold: pixels[x + y * width] = Cold; break; case HeatType.Warm: pixels[x + y * width] = Warm; break; case HeatType.Warmer: pixels[x + y * width] = Warmer; break; case HeatType.Warmest: pixels[x + y * width] = Warmest; break; } //darken the color if a edge tile if ((int)tiles[x, y].HeightType > 2 && tiles[x, y].Bitmask != 15) { pixels[x + y * width] = Color.Lerp(pixels[x + y * width], Color.Black, 0.4f); } } } surface.SetPixels(pixels); return((BasicSurface)surface.TextSurface); }
void OnGUI() { if (surfaceEditor == null || csgModel == null) { // Link to face tool has been lost, so attempt to reacquire CSGModel[] csgModels = FindObjectsOfType <CSGModel>(); // Build the first csg model that is currently being edited for (int i = 0; i < csgModels.Length; i++) { if (csgModels[i].EditMode) { csgModel = csgModels[i]; surfaceEditor = csgModels[i].GetTool(MainMode.Face) as SurfaceEditor; break; } } // If it's still null if (surfaceEditor == null || csgModel == null) { GUILayout.Label("No active CSG Model"); return; } } GUILayout.Label("Set Vertex Colors", SabreGUILayout.GetTitleStyle()); Color sourceColor = surfaceEditor.GetColor(); Color newColor = EditorGUILayout.ColorField(sourceColor); if (newColor != sourceColor) { surfaceEditor.SetSelectionColor(newColor); } // Preset color buttons GUILayout.BeginHorizontal(); for (int i = 0; i < PRESET_COLORS.Length; i++) { if (SabreGUILayout.ColorButton(PRESET_COLORS[i])) { surfaceEditor.SetSelectionColor(PRESET_COLORS[i]); } } GUILayout.EndHorizontal(); }
public override void Draw(ISurface surface, Microsoft.Xna.Framework.Rectangle area) { string value = ((LayerMetadata)((LayeredSurface.Layer)Item).Metadata).Name; if (value.Length < area.Width) { value += new string(' ', area.Width - value.Length); } else if (value.Length > area.Width) { value = value.Substring(0, area.Width); } var editor = new SurfaceEditor(surface); editor.Print(area.X, area.Y, value, _currentAppearance); _isDirty = false; }
public void New(Color foreground, Color background, int width, int height) { Reset(); int renderWidth = Math.Min(MainScreen.Instance.InnerEmptyBounds.Width, width); int renderHeight = Math.Min(MainScreen.Instance.InnerEmptyBounds.Height, height); surface = new SadConsole.Surfaces.LayeredSurface(width, height, SadConsoleEditor.Settings.Config.ScreenFont, new Rectangle(0, 0, renderWidth, renderHeight), 1); LayerMetadata.Create("Root", true, false, true, surface.ActiveLayer); var editor = new SurfaceEditor(surface); editor.FillWithRandomGarbage(); layerManagementPanel.SetLayeredSurface(surface); layerManagementPanel.IsCollapsed = true; }
public static GameObject CreateFromString(string s, Color color = new Color()) { if (color == new Color()) { color = Color.White; } var lines = s.Split('\n'); var text = new AnimatedSurface("deafult", lines.Max(ss => ss.Length), lines.Length); var editor = new SurfaceEditor(text.CreateFrame()); for (int i = 0; i < lines.Length; i++) { editor.Print(0, i, lines[i], color); } return(new GameObject(text)); }
public static GameObject CreateBlinkingFromGlyph(int glyph, float duration, Color color = new Color()) { if (color == new Color()) { color = Color.White; } var animation = new AnimatedSurface("anim", 1, 1); var editor = new SurfaceEditor(animation.CreateFrame()); editor.SetGlyph(0, 0, glyph, color); animation.CreateFrame(); //empty frame animation.AnimationDuration = duration; animation.Repeat = true; animation.Start(); return(new GameObject(animation)); }
public virtual void Draw(ISurface surface, Rectangle area) { string value = Item.ToString(); if (value.Length < area.Width) { value += new string(' ', area.Width - value.Length); } else if (value.Length > area.Width) { value = value.Substring(0, area.Width); } var editor = new SurfaceEditor(surface); editor.Print(area.Left, area.Top, value, _currentAppearance); _isDirty = false; }
public override void Draw(ISurface surface, Rectangle area) { string value = ((FileLoaders.IFileLoader)Item).FileTypeName; if (value.Length < area.Width) { value += new string(' ', area.Width - value.Length); } else if (value.Length > area.Width) { value = value.Substring(0, area.Width); } var editor = new SurfaceEditor(surface); editor.Print(area.Left, area.Top, value, _currentAppearance); _isDirty = false; }
public override void Draw(ITextSurface surface, Rectangle area) { string value = ((Editors.EntityEditor.FrameWrapper)Item).CurrentIndex.ToString(); if (value.Length < area.Width) { value += new string(' ', area.Width - value.Length); } else if (value.Length > area.Width) { value = value.Substring(0, area.Width); } var editor = new SurfaceEditor(surface); editor.Print(area.X, area.Y, value, _currentAppearance); _isDirty = false; }
/// <summary> /// /// </summary> /// <param name="surface"></param> /// <param name="area"></param> public override void Draw(ISurface surface, Microsoft.Xna.Framework.Rectangle area) { var hotSpot = ((Hotspot)Item); ColoredString value = ((char)hotSpot.DebugAppearance.Glyph).ToString().CreateColored(hotSpot.DebugAppearance.Foreground, hotSpot.DebugAppearance.Background, hotSpot.DebugAppearance.Mirror) + " ".CreateColored(_currentAppearance.Foreground, _currentAppearance.Background) + hotSpot.Title.CreateColored(_currentAppearance.Foreground, _currentAppearance.Background); if (value.Count < area.Width) { value += new string(' ', area.Width - value.Count).CreateColored(_currentAppearance.Foreground, _currentAppearance.Background); } else if (value.Count > area.Width) { value = new ColoredString(value.Take(area.Width).ToArray()); } var editor = new SurfaceEditor(surface); editor.Print(area.X, area.Y, value); _isDirty = false; }
/// <summary> /// Draws the line shape. /// </summary> /// <param name="surface">The cell surface to draw on.</param> public void Draw(SurfaceEditor surface) { List <Cell> cells = new List <Cell>(); Algorithms.Line(StartingLocation.X, StartingLocation.Y, EndingLocation.X, EndingLocation.Y, (x, y) => { cells.Add(surface[x, y]); return(true); }); if (cells.Count > 1) { if (UseStartingCell) { StartingCellAppearance.Copy(cells[0]); cells[0].Effect = StartingCellAppearance.Effect; } else { CellAppearance.Copy(cells[0]); cells[0].Effect = StartingCellAppearance.Effect; } if (UseEndingCell) { EndingCellAppearance.Copy(cells[cells.Count - 1]); cells[cells.Count - 1].Effect = EndingCellAppearance.Effect; } else { CellAppearance.Copy(cells[cells.Count - 1]); cells[cells.Count - 1].Effect = CellAppearance.Effect; } for (int i = 1; i < cells.Count - 1; i++) { CellAppearance.Copy(cells[i]); cells[i].Effect = CellAppearance.Effect; } } else if (cells.Count == 1) { CellAppearance.Copy(cells[0]); cells[0].Effect = CellAppearance.Effect; } }