Example #1
0
        private void automatonImage_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (!cameraStyle)
            {
                if (doFloodFill)
                {
                    System.Windows.Point point = e.GetPosition(e.Source as FrameworkElement);
                    int x = (int)point.X;
                    int y = (int)point.Y;

                    floodFiller.Fill(x, y, paintBitmap.GetColor(x, y), paintBitmap.BRUSH_COLOR);
                }
                else
                {
                    point1 = e.GetPosition(e.Source as FrameworkElement);
                    if (isFirstPoint)
                    {
                        firstPoint   = point1;
                        isFirstPoint = false;
                    }
                }
            }
            else
            {
                isLeftClickHold = false;
            }
        }
Example #2
0
        public void Fill(int x, int y, Color originalColor, Color fillColor)
        {
            Queue <System.Windows.Point> queue = new Queue <System.Windows.Point>();

            queue.Enqueue(new System.Windows.Point(x, y));

            while (queue.Count != 0)
            {
                System.Windows.Point p = queue.Dequeue();

                Color currentColor = paintBitmap.GetColor((int)p.X, (int)p.Y);

                if (equalColor(currentColor, originalColor))
                {
                    paintBitmap.PutPixel((int)p.X, (int)p.Y, fillColor);
                    if (paintBitmap.GetColor((int)p.X, (int)p.Y) != fillColor)
                    {
                        Console.Write("");
                    }

                    // ADD 4 NEIGHBORS
                    System.Windows.Point pointToAdd = new System.Windows.Point(p.X - 1, p.Y);
                    queue.Enqueue(pointToAdd);
                    pointToAdd = new System.Windows.Point(p.X + 1, p.Y);
                    queue.Enqueue(pointToAdd);

                    pointToAdd = new System.Windows.Point(p.X, p.Y - 1);
                    queue.Enqueue(pointToAdd);

                    pointToAdd = new System.Windows.Point(p.X, p.Y + 1);
                    queue.Enqueue(pointToAdd);
                }
            }

            return;
        }