private void bFill_Click(object sender, RoutedEventArgs e)
        {
            FillCommand command = new FillCommand(this.currentBrush, this.inkPanel);

            undoRedo.InsertComand(command);
            command.Execute();
        }
Exemple #2
0
        private void WatershedDialog_Load(object sender, EventArgs e)
        {
            _viewer.PostRender += new EventHandler <ImageViewerRenderEventArgs>(_viewer_Paint);
            _viewer.MouseDown  += new MouseEventHandler(_viewer_MouseDown);
            _viewer.MouseUp    += new MouseEventHandler(_viewer_MouseUp);
            _viewer.MouseMove  += new MouseEventHandler(_viewer_MouseMove);
            _form.FormClosing  += new FormClosingEventHandler(_form_FormClosing);

            _mainForm.DisableAllInteractiveModes(_viewer);

            _maskImage = new RasterImage(_viewer.Image);
            FillCommand command = new FillCommand(RasterColor.White);

            command.Run(_maskImage);

            _orgImage = _viewer.Image.Clone();

            _lengths        = new List <int>();
            _points         = new List <List <Point> >();
            _currentSegment = new List <Point>();

            _segIndex = -1;
            _drawing  = false;

            _viewer.Cursor = Cursors.Cross;
        }
Exemple #3
0
 //in safari, when canvas is captured, that has transparency, it fills transparent areas with 255 not black
 //we force transparent areas to be black instead
 static void PreProcessBitmap(RasterImage derivedImage)
 {
     using (RasterImage alpha = derivedImage.CreateAlphaImage())
     {
         alpha.AddColorRgbRangeToRegion(new RasterColor(0, 0, 0), new RasterColor(3, 3, 3), RasterRegionCombineMode.Set);
         derivedImage.SetRegion(null, alpha.GetRegion(null), RasterRegionCombineMode.Set);
         FillCommand fill = new FillCommand(new RasterColor(0, 0, 0));
         fill.Run(derivedImage);
     }
 }
Exemple #4
0
        private static RasterImage CreateTextFooter(LeadSize size, string tag)
        {
            var bpp             = 24;
            var byteOrder       = RasterByteOrder.Bgr;
            var viewPerspective = RasterViewPerspective.TopLeft;

            var image = new RasterImage(RasterMemoryFlags.Conventional, size.Width, size.Height, bpp, byteOrder, viewPerspective, null, null, 0);

            var fill = new FillCommand(RasterColor.FromKnownColor(RasterKnownColor.White));

            fill.Run(image);

            using (var graphics = RasterImagePainter.CreateGraphics(image))
            {
                using (var brush = new SolidBrush(Color.Black))
                {
                    using (var font = new Font(FontFamily.GenericSansSerif, size.Width / 128))
                    {
                        var pos = new PointF(0, 0);

                        {
                            SizeF stringSize = new SizeF();
                            stringSize = graphics.Graphics.MeasureString(tag, font);

                            float scaleX = (float)size.Width / stringSize.Width;
                            float scaleY = (float)size.Height / stringSize.Height;

                            scaleX = Math.Min(1f, scaleX);
                            scaleY = Math.Min(1f, scaleY);

                            graphics.Graphics.ScaleTransform(scaleX, scaleY);

                            if (size.Height > (int)stringSize.Height)
                            {
                                size.Height = (int)stringSize.Height;
                            }
                        }

                        graphics.Graphics.DrawString(tag, font, Brushes.Black, new PointF(0, 0));
                    }
                }
            }

            if (size.Height < image.Height)
            {
                var crop = new CropCommand(LeadRect.FromLTRB(0, 0, size.Width, size.Height));
                crop.Run(image);
            }

            return(image);
        }
        /// <summary>
        /// Creates the command.
        /// </summary>
        /// <param name="input">The input command.</param>
        /// <returns></returns>
        public static ICommand CreateCommand(string input)
        {
            ICommand command = null;

            try
            {
                var inputSplit = input.Split(' ');
                switch (inputSplit[0])
                {
                case "C":
                    command = new CanvasCommand(inputSplit[1], inputSplit[2]);
                    break;

                case "L":
                    command = new LineCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3], inputSplit[4]);
                    break;

                case "R":
                    command = new RectCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3], inputSplit[4]);
                    break;

                case "B":
                    command = new FillCommand(inputSplit[1], inputSplit[2],
                                              inputSplit[3]);
                    break;

                case "Q":
                    command = new QuitCommand();
                    break;

                default:
                    break;
                }

                if (command != null && !command.IsValid)
                {
                    command = null;
                }
            }
            catch (System.Exception)
            {
                command = null;
            }
            return(command);
        }
        public override void Fill(AnnContainer container, LeadRectD bounds, string color)
        {
            if (_image == null)
            {
                return;
            }

            try
            {
                var fill = new FillCommand(RasterColor.Black);
                _image.AddRectangleToRegion(null, bounds.ToLeadRect(), RasterRegionCombineMode.Set);
                fill.Run(_image);
            }
            finally
            {
                _image.MakeRegionEmpty();
            }
        }
 public abstract void Visit(FillCommand command);
        public IEnumerable <ICommand> NextStep(State state)
        {
            if (FLAG)
            {
                FLAG = false;
                return(new List <ICommand> {
                    new FlipCommand()
                });
            }
            var ans = new List <ICommand>();

            var firstOrDefault = state.Bots.FirstOrDefault(x => state.Matrix.Contains(x.Pos) && state.Matrix.IsFull(x.Pos));

            if (firstOrDefault != null || state.Bots.Any(x => state.Bots.Where(y => y.Bid != x.Bid).Any(z => z.Pos == x.Pos)))
            {
                Console.WriteLine();

                return(new List <ICommand> {
                    new HaltCommand()
                });

                return(ans);
            }

            //самоуничтожение
            if (buildingTasks.Count == 0)
            {
                if (state.Bots.Length == 1)
                {
                    var debt = tehdebt.FirstOrDefault(x => state.Bots.Single().Pos.GetNears().Contains(x));
                    if (debt != null)
                    {
                        tehdebt.ExceptWith(new List <Vector> {
                            debt
                        });
                        var clearCommand = new FillCommand(debt - state.Bots.Single().Pos);
                        ans.Add(clearCommand);
                    }
                    else if (state.Bots.Single().Pos != new Vector(0, 0, 0))
                    {
                        fussionQueue = fussionQueue ??
                                       new Queue <ICommand>(GetMoveCommands(state, state.Bots.Single(), new Vector(0, 0, 0),
                                                                            new HashSet <Vector>()).commands);

                        ans.Add(fussionQueue.Dequeue());
                    }
                    else
                    {
                        ans.Add(new FlipCommand());
                        ans.Add(new HaltCommand());
                        return(ans);
                    }
                }

                for (var index = 0; index < state.Bots.Length - 1; index++)
                {
                    if (index < state.Bots.Length - 2)
                    {
                        ans.Add(new WaitCommand());
                        continue;
                    }

                    var bot1 = state.Bots[index];
                    var bot2 = state.Bots[index + 1];

                    var near = bot1.Pos.GetNears().FirstOrDefault(x => x == bot2.Pos);
                    if (near != null && fussionQueue?.Count == 0)
                    {
                        ans.Add(new FusionPCommand(near - bot1.Pos));
                        ans.Add(new FusionSCommand(new Vector(0, 0, 0) - near + bot1.Pos));

                        if (matrix.IsFull(bot2.Pos))
                        {
                            tehdebt.Add(bot2.Pos);
                        }
                        fussionQueue = null;
                    }
                    else
                    {
                        ans.Add(new WaitCommand());

                        var debt = tehdebt.FirstOrDefault(x => bot2.Pos.GetNears().Contains(x));
                        if (debt != null)
                        {
                            tehdebt.ExceptWith(new List <Vector> {
                                debt
                            });
                            var clearCommand = new FillCommand(debt - bot2.Pos);
                            ans.Add(clearCommand);
                        }
                        else
                        {
                            var nearest = GetNearestTargetPoint(bot2.Pos, bot1.Pos,
                                                                v => state.Matrix.Contains(v) && state.Bots.All(x => x.Pos != v));

                            if (fussionQueue == null)
                            {
                                var collection = GetMoveCommands(state, bot2, nearest, new HashSet <Vector>()).commands;
                                fussionQueue = new Queue <ICommand>(collection);
                                Nearest      = nearest;
                                BotPos       = bot2.Pos;
                                COllection   = collection;
                            }
                            var command = fussionQueue.Dequeue();
                            a.Add(command);

                            if (command is SMoveCommand c)
                            {
                                if (state.Matrix.IsFull(c.Direction + bot2.Pos))
                                {
                                    Console.WriteLine();
                                }
                            }

                            ans.Add(command);
                        }
                    }
                }
            }
            else if (state.Bots.Length != 8)
            {
                ans.AddRange(BotDivider.GetDivideCommandsForOneStep(state, state.Bots.Length));
            }
            else
            {
                var task = buildingTasks.Peek();

                var targetPoints = task.Region.Points();

                commandsQueue = commandsQueue ?? GetCommadsQueue(state, targetPoints, task.Region, true);

                if (!commandsQueue.Any() || commandsQueue.All(x => x.Value.Count == 0))
                {
                    commandsQueue = GetCommadsQueue(state, targetPoints, task.Region, true);
                }

                if (!commandsQueue.Any() || commandsQueue.All(x => x.Value.Count == 0))
                {
                    foreach (var fillCommand in GetFillCommands(state, task))
                    {
                        ans.Add(fillCommand);
                    }

                    commandsQueue = null;
                    buildingTasks.Dequeue();
                }
                else
                {
                    foreach (var bot in state.Bots)
                    {
                        if (commandsQueue.ContainsKey(bot.Bid) && commandsQueue[bot.Bid].Count != 0)
                        {
                            var moveCommand = commandsQueue[bot.Bid].Dequeue();

                            ans.Add(moveCommand);
                        }
                        else
                        {
                            ans.Add(new WaitCommand());
                        }
                    }
                }
            }

            if (ans.Count != state.Bots.Length)
            {
                throw new InvalidOperationException();
            }

            return(ans);
        }
            public override void Visit(FillCommand command)
            {
                var p = command.Nd;

                Console.WriteLine($"Fill <{p.X},{p.Y},{p.Z}>");
            }
Exemple #10
0
 public override void OnDown(int x, int y)
 {
     fillCommand = new FillCommand(bitmap, DrawColor.CurrentColor);
     fillCommand.Fill(x, y);
     history.Perform(fillCommand);
 }
 public virtual T Visit(FillCommand command)
 {
     return(default(T));
 }