void addNewAnimation_Click(object sender, EventArgs e) { RenamePopup popup = new RenamePopup("", "Animation Name"); popup.Closed += (o, e2) => { if (popup.DialogResult) { string newName = popup.NewName.Trim(); var keys = entity.Animations.Keys.Select(k => k.ToLower()).ToList(); if (keys.Contains(newName.ToLower())) { Window.Message("Name must be unique", "Close"); } else if (string.IsNullOrEmpty(newName)) { Window.Message("Name cannot be blank", "Close"); } else { var previouslySelected = (AnimatedSurface)animations.SelectedItem; var animation = new AnimatedSurface(newName, previouslySelected.Width, previouslySelected.Height, Settings.Config.ScreenFont); animation.CreateFrame(); animation.AnimationDuration = 1; entity.Animations[animation.Name] = animation; RebuildListBox(); animations.SelectedItem = animation; } } }; popup.Show(true); popup.Center(); }
public BoxTool() { animSinglePoint = new AnimatedSurface("single", 1, 1, SadConsoleEditor.Settings.Config.ScreenFont); var _frameSinglePoint = animSinglePoint.CreateFrame(); _frameSinglePoint[0].Glyph = 42; frameEffect = new SadConsole.Effects.Fade() { UseCellBackground = true, FadeForeground = true, FadeDuration = 1f, AutoReverse = true }; _settingsPanel = new BoxToolPanel(); ControlPanels = new CustomPanel[] { _settingsPanel }; // Brush = new SadConsole.GameHelpers.GameObject(1, 1, SadConsoleEditor.Settings.Config.ScreenFont); AnimatedSurface animation = new AnimatedSurface("single", 1, 1, SadConsoleEditor.Settings.Config.ScreenFont); animation.CreateFrame()[0].Glyph = 42; Brush.Animations.Add(animation.Name, animation); Brush.Animation = animation; }
private void cloneSelectedAnimation_Click(object sender, EventArgs e) { RenamePopup popup = new RenamePopup("clone"); popup.Closed += (o, e2) => { if (popup.DialogResult) { var animation = (AnimatedSurface)animations.SelectedItem; var newAnimation = new AnimatedSurface(popup.NewName, animation.Width, animation.Height, Settings.Config.ScreenFont); foreach (var frame in animation.Frames) { var newFrame = newAnimation.CreateFrame(); frame.Copy(newFrame); } newAnimation.CurrentFrameIndex = 0; entity.Animations[newAnimation.Name] = newAnimation; RebuildListBox(); } }; popup.Show(true); popup.Center(); }
public bool LoadZone(Zone zone) { var gameObject = new GameObject(1, 1, Settings.Config.ScreenFont); var animation = new AnimatedSurface("default", zone.Area.Width, zone.Area.Height); var frame = animation.CreateFrame(); frame.DefaultBackground = zone.DebugAppearance.Background; gameObject.Name = zone.Title; Settings.QuickEditor.TextSurface = frame; Settings.QuickEditor.Clear(); Settings.QuickEditor.Print(0, 0, zone.Title, Color.DarkGray); gameObject.Animation = animation; gameObject.Position = new Point(zone.Area.Left, zone.Area.Top); var resizable = new ResizableObject <Zone>(ResizableObject.ObjectType.Zone, gameObject, zone); resizable.RenderOffset = MainScreen.Instance.InnerBorderPosition - surface.RenderArea.Location; Zones.Add(resizable); ZonesPanel.RebuildListBox(); return(true); }
/// <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 GameObjectTest() : base(80, 23) { var textAnimation = new AnimatedSurface("default", 14, 5); // Animated surface size. 14,5 fallingText = new SadConsole.GameHelpers.GameObject(textAnimation); var editor = new SadConsole.Surfaces.SurfaceEditor(new SadConsole.Surfaces.BasicSurface(1, 1)); for (int line = 0; line < 5; line++) { var frame = textAnimation.CreateFrame(); editor.TextSurface = frame; editor.Fill(Color.Purple, Color.DarkGray, 178, null); // 219 178 editor.Print(1, line, "Hello World!"); } textAnimation.AnimationDuration = 1; // Set it to -1 to make it faster than 1 sec textAnimation.Repeat = true; textAnimation.Start(); fallingText.Animation = textAnimation; //fallingText.Position = new Point(1,1); Children.Add(fallingText); }
private void MakeBoxAnimation(int width, int height, Point center) { AnimatedSurface animation; if (Brush.Animations.ContainsKey(AnimationSelection)) { animation = Brush.Animations[AnimationSelection]; if (animation.Width == width && animation.Height == height && animation.Center == center) { Brush.Animation = animation; return; } } animation = new AnimatedSurface(AnimationSelection, width, height, SadConsoleEditor.Settings.Config.ScreenFont); SadConsoleEditor.Settings.QuickEditor.TextSurface = animation.CreateFrame(); _boxShape = SadConsole.Shapes.Box.GetDefaultBox(); _boxShape.Position = new Point(0, 0); _boxShape.Width = width; _boxShape.Height = height; _boxShape.Draw(SadConsoleEditor.Settings.QuickEditor); //frame.SetEffect(frame, _pulseAnimation); animation.Center = center; Brush.Animations[animation.Name] = animation; Brush.Animation = animation; }
/// <summary> /// Creates a new GameObject with a default animation/ /// </summary> /// <param name="animation">The default animation. The animation will have its <see cref="Surfaces.AnimatedSurface.Name"/> property changesd to "default".</param> public GameObject(AnimatedSurface animation) { renderer = new Renderers.SurfaceRenderer(); font = animation.Font; animation.Name = "default"; Animation = animation; Animations.Add("default", animation); }
/// <summary> /// Creates a new GameObject. /// </summary> public GameObject(int width, int height, Font font) { renderer = new Renderers.SurfaceRenderer(); this.font = font; Animation = new AnimatedSurface("default", width, height, Global.FontDefault); animation.CreateFrame(); Animations.Add("default", animation); }
public Player() : base() { Animation = new AnimatedSurface("default", 1, 1); var frame = Animation.CreateFrame(); frame[0].Glyph = 5; this.CurrentDirection = Direction.None; Health = 70; }
public void SetAnimation(AnimatedSurface animation) { currentAnimation = animation; selectedFrame = currentAnimation.Frames[0]; EnableDisableControls(0); DrawFrameCount(); frameChangeCallback(selectedFrame); }
private void SetAnimationLine(Point mousePosition) { // Draw the line (erase old) to where the mouse is // create the animation frame AnimatedSurface animation = new AnimatedSurface("line", Math.Max(firstPoint.Value.X, mousePosition.X) - Math.Min(firstPoint.Value.X, mousePosition.X) + 1, Math.Max(firstPoint.Value.Y, mousePosition.Y) - Math.Min(firstPoint.Value.Y, mousePosition.Y) + 1, SadConsoleEditor.Settings.Config.ScreenFont); var frame = animation.CreateFrame(); Point p1; Point p2; if (firstPoint.Value.X > mousePosition.X) { if (firstPoint.Value.Y > mousePosition.Y) { p1 = new Point(frame.Width - 1, frame.Height - 1); p2 = new Point(0, 0); } else { p1 = new Point(frame.Width - 1, 0); p2 = new Point(0, frame.Height - 1); } } else { if (firstPoint.Value.Y > mousePosition.Y) { p1 = new Point(0, frame.Height - 1); p2 = new Point(frame.Width - 1, 0); } else { p1 = new Point(0, 0); p2 = new Point(frame.Width - 1, frame.Height - 1); } } animation.Center = p1; //_lineStyle = new Cell( // MainScreen.Instance.Instance.ToolPane.CommonCharacterPickerPanel.SettingForeground, // MainScreen.Instance.Instance.ToolPane.CommonCharacterPickerPanel.SettingBackground, // MainScreen.Instance.Instance.ToolPane.CommonCharacterPickerPanel.SettingCharacter); //_lineStyle.SpriteEffect = MainScreen.Instance.Instance.ToolPane.CommonCharacterPickerPanel.SettingMirrorEffect; //_lineStyle.CopyAppearanceTo(_lineCell); Brush.Animation = animation; }
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 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 void Resize(int width, int height) { width = Math.Max(100, width); height = Math.Max(100, height); List <AnimatedSurface> newAnimations = new List <AnimatedSurface>(gameObject.Animations.Count); foreach (var oldAnimation in gameObject.Animations.Values) { var newAnimation = new AnimatedSurface(oldAnimation.Name, width, height, SadConsoleEditor.Settings.Config.ScreenFont); for (int i = 0; i < oldAnimation.Frames.Count; i++) { oldAnimation.Frames[i].Copy(newAnimation.CreateFrame()); } newAnimation.CurrentFrameIndex = 0; newAnimations.Add(newAnimation); newAnimation.AnimationDuration = oldAnimation.AnimationDuration; newAnimation.Center = oldAnimation.Center; } foreach (var animation in newAnimations) { gameObject.Animations[animation.Name] = animation; if (gameObject.Animation.Name == animation.Name) { gameObject.Animation = animation; } if (selectedAnimation.Name == animation.Name) { selectedAnimation = animation; } } SetEntity(gameObject); if (MainScreen.Instance.ActiveEditor == this) { MainScreen.Instance.CenterEditor(); } }
public GameObjectConsole() : base(80, 23) { var animation = new AnimatedSurface("default", 1, 1); var frame = animation.CreateFrame(); frame.Cells[0].Glyph = 1; player = new SadConsole.GameHelpers.GameObject(animation); //player.RepositionRects = true; player.Position = new Point(textSurface.Width / 2, textSurface.Height / 2); playerPreviousPosition = player.Position; // Setup this console to accept keyboard input. UseKeyboard = true; IsVisible = false; Children.Add(player); }
private void SelectedAnimationChanged(AnimatedSurface animation) { selectedAnimation = animation; surface = new LayeredSurface(animation.Width, animation.Height, Settings.Config.ScreenFont, 4); SyncSpecialLayerToAnimation(); surface.SetActiveLayer(0); // inform the outer box we've changed size if (MainScreen.Instance.ActiveEditor == this) { MainScreen.Instance.RefreshBorder(); } framesPanel.SetAnimation(animation); SelectedTool = selectedTool; }
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 PreviewAnimationPopup(AnimatedSurface animation) : base(animation.Width + 2, animation.Height + 4) { textSurface.Font = Settings.Config.ScreenFont; this.animation = animation; CloseOnESC = true; entity = new GameObject(1, 1, Settings.Config.ScreenFont); entity.Position = new Point(1, 1); entity.Animation = animation; animation.Restart(); entity.Animation.Start(); entity.Position = new Point(1); Children.Add(entity); restartAnimation = new Button(animation.Width, 1); restartAnimation.Text = "Restart"; restartAnimation.Position = new Point(1, TextSurface.Height - 2); restartAnimation.Click += (s, e) => this.animation.Restart(); Add(restartAnimation); }
public SelectionTool() { Brush = new LayeredGameObject(); var animation = new AnimatedSurface(AnimationSingle, 1, 1, SadConsoleEditor.Settings.Config.ScreenFont); animation.CreateFrame()[0].Glyph = 42; animation.Frames[0][0].Background = Color.Black; Brush.Animations.Add(animation.Name, animation); animation = new AnimatedSurface(AnimationSelection, 1, 1, SadConsoleEditor.Settings.Config.ScreenFont); Brush.Animations.Add(animation.Name, animation); _frameEffect = new SadConsole.Effects.Fade() { UseCellBackground = true, FadeForeground = true, FadeDuration = 1f, AutoReverse = true }; _panel = new SelectionToolPanel(LoadBrush, SaveBrush); _panel.StateChangedHandler = PanelStateChanged; _panel.State = SelectionToolPanel.CloneState.SelectingPoint1; _altPanel = new SelectionToolAltPanel(); ControlPanels = new CustomPanel[] { _panel, _altPanel }; _pulseAnimation = new SadConsole.Effects.Fade() { FadeBackground = true, UseCellBackground = false, DestinationBackground = Color.Transparent, FadeDuration = 2d, CloneOnApply = false, AutoReverse = true, Repeat = true, }; }
public CircleTool() { frameEffect = new SadConsole.Effects.Fade() { UseCellBackground = true, FadeForeground = true, FadeDuration = 1f, AutoReverse = true }; // Configure the animations Brush = new SadConsole.GameHelpers.GameObject(1, 1, SadConsoleEditor.Settings.Config.ScreenFont); AnimatedSurface animation = new AnimatedSurface("single", 1, 1, SadConsoleEditor.Settings.Config.ScreenFont); animation.CreateFrame()[0].Glyph = 42; Brush.Animations.Add(animation.Name, animation); settingsPanel = new CircleToolPanel(); ControlPanels = new CustomPanel[] { settingsPanel, CharacterPickPanel.SharedInstance }; ResetCircle(); }
public Monster(String name, String inventoryName, int roomId, int x, int y, int character, int health, string description, string deadDescription) : base() { this.IsAlive = true; this.Name = inventoryName; this.InventoryName = name; this.RoomId = roomId; position.X = x; position.Y = y; this.Character = character; this.Health = health; this.Description = description; this.DeadDescription = deadDescription; this.Value = 100; this.IsGuard = false; Animation = new AnimatedSurface("default", 1, 1); var frame = Animation.CreateFrame(); frame[0].Glyph = character; }
public void New(Color foreground, Color background, int width, int height) { Reset(); width = Math.Max(100, width); height = Math.Max(100, height); var gameObject = new GameObject(1, 1, SadConsoleEditor.Settings.Config.ScreenFont); AnimatedSurface animation = new AnimatedSurface("default", width, height, SadConsoleEditor.Settings.Config.ScreenFont); animation.DefaultForeground = foreground; animation.DefaultBackground = background; animation.CreateFrame(); animation.AnimationDuration = 1; gameObject.Animations[animation.Name] = animation; gameObject.Animation = animation; gameObject.Name = "game object"; SetEntity(gameObject); }
public void ProcessMouse(MouseConsoleState info, ISurface surface, bool isInBounds) { if (cancelled) { // wait until left button is released... if (info.Mouse.LeftButtonDown) { return; } else { cancelled = false; } } if (info.Mouse.LeftButtonDown) { if (!firstPoint.HasValue) { RefreshTool(); firstPoint = info.ConsolePosition; return; } else { // Check for right click cancel. if (info.Mouse.RightButtonDown) { cancelled = true; firstPoint = null; secondPoint = null; Brush.Animation = Brush.Animations["single"]; settingsPanel.CircleWidth = 0; settingsPanel.CircleHeight = 0; return; } secondPoint = info.ConsolePosition; // Draw the line (erase old) to where the mouse is // create the animation frame AnimatedSurface animation = new AnimatedSurface("line", Math.Max(firstPoint.Value.X, secondPoint.Value.X) - Math.Min(firstPoint.Value.X, secondPoint.Value.X) + 1, Math.Max(firstPoint.Value.Y, secondPoint.Value.Y) - Math.Min(firstPoint.Value.Y, secondPoint.Value.Y) + 1, SadConsoleEditor.Settings.Config.ScreenFont); var frame = animation.CreateFrame(); Point p1; if (firstPoint.Value.X > secondPoint.Value.X) { if (firstPoint.Value.Y > secondPoint.Value.Y) { p1 = Point.Zero; } else { p1 = new Point(0, frame.Height - 1); } } else { if (firstPoint.Value.Y > secondPoint.Value.Y) { p1 = new Point(frame.Width - 1, 0); } else { p1 = new Point(frame.Width - 1, frame.Height - 1); } } animation.Center = p1; settingsPanel.CircleWidth = animation.Width; settingsPanel.CircleHeight = animation.Height; SadConsoleEditor.Settings.QuickEditor.TextSurface = frame; ellipseShape = new SadConsole.Shapes.Ellipse(); ellipseShape.BorderAppearance = borderAppearance; ellipseShape.EndingPoint = new Point(frame.Width - 1, frame.Height - 1); ellipseShape.Draw(SadConsoleEditor.Settings.QuickEditor); Brush.Animation = animation; } } else if (firstPoint.HasValue) { settingsPanel.CircleWidth = 0; settingsPanel.CircleHeight = 0; // We let go outside of bounds if (!isInBounds) { firstPoint = null; cancelled = true; Brush.Animation = Brush.Animations["single"]; return; } // Position the shape and draw Point p1 = new Point(Math.Min(firstPoint.Value.X, secondPoint.Value.X), Math.Min(firstPoint.Value.Y, secondPoint.Value.Y)); Point p2 = new Point(Math.Max(firstPoint.Value.X, secondPoint.Value.X), Math.Max(firstPoint.Value.Y, secondPoint.Value.Y)); SadConsoleEditor.Settings.QuickEditor.TextSurface = surface; ellipseShape.StartingPoint = p1 + info.Console.TextSurface.RenderArea.Location; ellipseShape.EndingPoint = p2 + info.Console.TextSurface.RenderArea.Location; ellipseShape.Draw(SadConsoleEditor.Settings.QuickEditor); Brush.Animation = Brush.Animations["single"]; Brush.Position = secondPoint.Value; firstPoint = null; secondPoint = null; } }
public object Load(string file) { return(AnimatedSurface.Load(file)); }
public WorldGenerationConsole() : base(80, 23) { // Create loading animation that looks like a sequence of / - \ | loadingAnimation = new AnimatedSurface("default", 1, 1); loadingAnimation.Frames.Clear(); var frame = loadingAnimation.CreateFrame(); frame[0].Glyph = 92; frame = loadingAnimation.CreateFrame(); frame[0].Glyph = 124; frame = loadingAnimation.CreateFrame(); frame[0].Glyph = 47; frame = loadingAnimation.CreateFrame(); frame[0].Glyph = 45; loadingAnimation.AnimationDuration = 1f; loadingAnimation.Repeat = true; messageData = new Console(80, 1); Children.Add(messageData); // Custom keyboard handler KeyboardHandler = (cons, info) => { if (info.IsKeyDown(Keys.Left)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left - 1, cons.TextSurface.RenderArea.Top, 80 * 2, 24 * 2); } if (info.IsKeyDown(Keys.Right)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left + 1, cons.TextSurface.RenderArea.Top, 80 * 2, 24 * 2); } if (info.IsKeyDown(Keys.Up)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left, cons.TextSurface.RenderArea.Top - 1, 80 * 2, 24 * 2); } if (info.IsKeyDown(Keys.Down)) { cons.TextSurface.RenderArea = new Rectangle(cons.TextSurface.RenderArea.Left, cons.TextSurface.RenderArea.Top + 1, 80 * 2, 24 * 2); } if (info.IsKeyReleased(Keys.Enter)) { state = InitState.BeforeGeneration; } if (info.IsKeyReleased(Keys.Space)) { var oldRenderArea = cons.TextSurface.RenderArea; var oldFont = cons.TextSurface.Font; if (textSurface == generator.HeightMapRenderer) { textSurface = generator.HeatMapRenderer; SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Heat"); } else if (textSurface == generator.HeatMapRenderer) { textSurface = generator.MoistureMapRenderer; SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Moisture"); } else if (textSurface == generator.MoistureMapRenderer) { textSurface = generator.BiomeMapRenderer; SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Biome "); } else { textSurface = generator.HeightMapRenderer; SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Height "); } cons.TextSurface.RenderArea = oldRenderArea; cons.TextSurface.Font = oldFont; } return(true); }; }
public void ProcessMouse(MouseConsoleState info, ISurface surface, bool isInBounds) { if (cancelled) { // wait until left button is released... if (info.Mouse.LeftButtonDown) { return; } else { cancelled = false; } } if (info.Mouse.LeftButtonDown) { if (!firstPoint.HasValue) { firstPoint = info.ConsolePosition; return; } else { // Check for right click cancel. if (info.Mouse.RightButtonDown) { cancelled = true; firstPoint = null; return; } secondPoint = info.ConsolePosition; // Draw the line (erase old) to where the mouse is // create the animation frame AnimatedSurface animation = new AnimatedSurface("line", Math.Max(firstPoint.Value.X, secondPoint.X) - Math.Min(firstPoint.Value.X, secondPoint.X) + 1, Math.Max(firstPoint.Value.Y, secondPoint.Y) - Math.Min(firstPoint.Value.Y, secondPoint.Y) + 1, SadConsoleEditor.Settings.Config.ScreenFont); var frame = animation.CreateFrame(); Point p1; if (firstPoint.Value.X > secondPoint.X) { if (firstPoint.Value.Y > secondPoint.Y) { p1 = Point.Zero; } else { p1 = new Point(0, frame.Height - 1); } } else { if (firstPoint.Value.Y > secondPoint.Y) { p1 = new Point(frame.Width - 1, 0); } else { p1 = new Point(frame.Width - 1, frame.Height - 1); } } animation.Center = p1; SadConsoleEditor.Settings.QuickEditor.TextSurface = frame; boxShape = SadConsole.Shapes.Box.GetDefaultBox(); if (_settingsPanel.UseCharacterBorder) { boxShape.LeftSideCharacter = boxShape.RightSideCharacter = boxShape.TopLeftCharacter = boxShape.TopRightCharacter = boxShape.TopSideCharacter = boxShape.BottomLeftCharacter = boxShape.BottomRightCharacter = boxShape.BottomSideCharacter = _settingsPanel.BorderCharacter; } boxShape.Foreground = _settingsPanel.LineForeColor; boxShape.FillColor = _settingsPanel.FillColor; boxShape.Fill = _settingsPanel.UseFill; boxShape.BorderBackground = _settingsPanel.LineBackColor; boxShape.Position = new Point(0, 0); boxShape.Width = frame.Width; boxShape.Height = frame.Height; boxShape.Draw(SadConsoleEditor.Settings.QuickEditor); Brush.Animation = animation; } } else if (firstPoint.HasValue) { // We let go outside of bounds if (!isInBounds) { cancelled = true; return; } // Position the box shape and draw boxShape.Position = new Point(Math.Min(firstPoint.Value.X, secondPoint.X), Math.Min(firstPoint.Value.Y, secondPoint.Y)) + info.Console.TextSurface.RenderArea.Location; SadConsoleEditor.Settings.QuickEditor.TextSurface = surface; boxShape.Draw(SadConsoleEditor.Settings.QuickEditor); firstPoint = null; Brush.Animation = Brush.Animations["single"]; } }
public void ProcessMouse(MouseConsoleState info, ISurface surface, bool isInBounds) { _previousSurface = surface; if (cancelled) { // wait until left button is released... if (info.Mouse.LeftButtonDown) { return; } else { cancelled = false; } } if (_panel.State == SelectionToolPanel.CloneState.SelectingPoint1) { if (info.Mouse.LeftButtonDown) { if (!firstPoint.HasValue) { firstPoint = info.ConsolePosition; return; } else { // Check for right click cancel. if (info.Mouse.RightButtonDown) { cancelled = true; firstPoint = null; return; } secondPoint = info.ConsolePosition; // Draw the line (erase old) to where the mouse is // create the animation frame int width = Math.Max(firstPoint.Value.X, secondPoint.X) - Math.Min(firstPoint.Value.X, secondPoint.X) + 1; int height = Math.Max(firstPoint.Value.Y, secondPoint.Y) - Math.Min(firstPoint.Value.Y, secondPoint.Y) + 1; Point p1; if (firstPoint.Value.X > secondPoint.X) { if (firstPoint.Value.Y > secondPoint.Y) { p1 = Point.Zero; } else { p1 = new Point(0, height - 1); } } else { if (firstPoint.Value.Y > secondPoint.Y) { p1 = new Point(width - 1, 0); } else { p1 = new Point(width - 1, height - 1); } } finalPostion = info.ConsolePosition + new Point(1); MakeBoxAnimation(width, height, p1); } } else if (firstPoint.HasValue) { // We let go outside of bounds if (!isInBounds) { cancelled = true; Brush.ShowSelectedSurface = false; Brush.IsVisible = false; Brush.Animation = Brush.Animations[AnimationSingle]; return; } secondPoint = info.ConsolePosition + info.Console.TextSurface.RenderArea.Location; firstPoint = firstPoint.Value + info.Console.TextSurface.RenderArea.Location; // Copy data to new animation AnimatedSurface cloneAnimation = new AnimatedSurface("clone", Brush.Animation.Width, Brush.Animation.Height, SadConsoleEditor.Settings.Config.ScreenFont); var frame = cloneAnimation.CreateFrame(); Point topLeftPoint = new Point(Math.Min(firstPoint.Value.X, secondPoint.X), Math.Min(firstPoint.Value.Y, secondPoint.Y)); surface.Copy(topLeftPoint.X, topLeftPoint.Y, cloneAnimation.Width, cloneAnimation.Height, frame, 0, 0); if (_altPanel.SkipEmptyCells && _altPanel.UseAltEmptyColor) { foreach (var cell in frame.Cells) { if (cell.Glyph == 0 && cell.Background == _altPanel.AltEmptyColor) { cell.Background = Color.Transparent; } } } cloneAnimation.Center = Brush.Animation.Center; Brush.SelectedSurface.Animation = cloneAnimation; Brush.Position = finalPostion; _panel.State = SelectionToolPanel.CloneState.Selected; } } if (info.Mouse.RightClicked) { _panel.State = SelectionToolPanel.CloneState.SelectingPoint1; firstPoint = null; } if (_panel.State == SelectionToolPanel.CloneState.Selected) { Brush.Position = finalPostion; Brush.IsVisible = true; } if (info.Mouse.LeftClicked && isInBounds) { if (_panel.State == SelectionToolPanel.CloneState.Stamp) { StampBrush(info.ConsolePosition.X, info.ConsolePosition.Y, surface); } else if (_panel.State == SelectionToolPanel.CloneState.Move) { StampBrush(info.ConsolePosition.X, info.ConsolePosition.Y, surface); _panel.State = SelectionToolPanel.CloneState.SelectingPoint1; } } }