Пример #1
0
        public void onMouseDown(object sender, MouseEventArgs e)
        {
            if (settings.getBitmapCurrentLayer(true) != null)
            {
                Color c = settings.getBitmapCurrentLayer(true).GetPixel(e.X, e.Y);

                int tol = 1;//settings.getGreenScreenTolerance();

                if (e.Button == MouseButtons.Left)
                {
                    Bitmap Temp = SharedSettings.bitmapCurrentLayer;

                    //Avoid Green screening Transparancy
                    //if (!(Temp.GetPixel(e.X, e.Y).A == 255))
                    {
                        for (int r = -tol; r < tol; r++)
                        {
                            for (int g = -tol; g < tol; g++)
                            {
                                for (int b = -tol; b < tol; b++)
                                {
                                    if (!((c.R + r) < 0 || (c.G + g) < 0 || (c.B + b) < 0 || (c.R + r) > 255 || (c.G + g) > 255 || (c.B + b) > 255))
                                    {
                                        Color tmpColor = Color.FromArgb(c.R + r, c.G + g, c.B + b);
                                        //Temp.MakeTransparent(tmpColor);

                                        //Experimaental -- Slower, but avoids extra code complexity
                                        for (int x = 0; x < Temp.Width; x++)
                                        {
                                            for (int y = 0; y < Temp.Height; y++)
                                            {
                                                Color tmp = Temp.GetPixel(x, y);
                                                if (tmp.R == tmpColor.R && tmp.G == tmpColor.G && tmp.B == tmpColor.B)
                                                {
                                                    Temp.SetPixel(x, y, Color.Transparent);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    //settings.setBitmapLayerUpdate(Temp);
                }
            }
        }
Пример #2
0
        public void onMouseUp(object sender, MouseEventArgs e)
        {
            pOld.X = 0;
            pOld.Y = 0;
            pNew.X = 0;
            pNew.Y = 0;

            p2 = new Point(e.X, e.Y);

            if (p1.X == p2.X || p1.Y == p2.Y)
            {
                SharedSettings.flattenSelection();
            }
            else
            {
                if (!ss.getActiveSelection())
                {
                    int tlX = p1.X, tlY = p1.Y;
                    int width  = Math.Abs(p1.X - p2.X);
                    int height = Math.Abs(p1.Y - p2.Y);

                    if (p2.X < p1.X)
                    {
                        tlX = p2.X;
                    }
                    if (p2.Y < p1.Y)
                    {
                        tlY = p2.Y;
                    }

                    tlX    = tlX < 0 ? 0 : tlX;
                    tlY    = tlY < 0 ? 0 : tlY;
                    width  = width + tlX <= SharedSettings.iCanvasWidth ? width : SharedSettings.iCanvasWidth - tlX;
                    height = height + tlY <= SharedSettings.iCanvasHeight ? height : SharedSettings.iCanvasHeight - tlY;

                    Point loc = new Point(tlX, tlY);
                    Size  sze = new Size(width, height);
                    ss.setSelectionPoint(loc);
                    ss.setSelectionSize(sze);

                    updateInterfaceLayer();

                    //Get selected area data
                    bEdit = ss.getBitmapCurrentLayer(true).Clone(new Rectangle(loc, sze), ss.getBitmapCurrentLayer(true).PixelFormat);

                    //clear data below selection
                    ss.getActiveGraphics().CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                    ss.getActiveGraphics().FillRectangle(new SolidBrush(Color.Transparent), new Rectangle(loc, sze));
                    ss.getActiveGraphics().CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                    SharedSettings.setSelection(bEdit, loc);
                }
            }
        }
Пример #3
0
        public void onMouseDown(object sender, MouseEventArgs e)
        {
            if (graphics != null)
            {
                bMouseDown = true;
                pOld       = e.Location;
                int x = pOld.X;
                int y = pOld.Y;

                bmp   = settings.getBitmapCurrentLayer(true);
                state = new bool[bmp.Width, bmp.Height];
                if (bmp == null)
                {
                    return;
                }

                nextPixels = new Queue <Point>();

                switch (e.Button)
                {
                case MouseButtons.Left:
                    replacementColor = settings.getPrimaryBrushColor();
                    break;

                case MouseButtons.Right:
                    replacementColor = settings.getSecondaryBrushColor();
                    break;

                default:
                    break;
                }

                targetColor = bmp.GetPixel(x, y);

                if (targetColor.ToArgb() == replacementColor.ToArgb())
                {
                    return;
                }

                AddNextPixel(pOld);
                while (nextPixels.Count > 0) // while the queue is not empty
                {
                    Point p = nextPixels.Dequeue();
                    if (ColorMatch(bmp.GetPixel(p.X, p.Y), targetColor))
                    {
                        // add 8 surrounding pixels to queue
                        int xNew = p.X, yNew = p.Y;

                        // add 3 pixels above
                        if (yNew - 1 >= 0)
                        {
                            if (xNew + 1 < bmp.Width)
                            {
                                AddNextPixel(new Point(xNew + 1, yNew - 1));
                            }
                            if (xNew - 1 >= 0)
                            {
                                AddNextPixel(new Point(xNew - 1, yNew - 1));
                            }
                            AddNextPixel(new Point(xNew, yNew - 1));
                        }

                        // add left and right
                        if (xNew > 0)
                        {
                            AddNextPixel(new Point(xNew - 1, yNew));
                        }
                        if (xNew + 1 < bmp.Width)
                        {
                            AddNextPixel(new Point(xNew + 1, yNew));
                        }

                        // add 3 upixels below
                        if (yNew + 1 < bmp.Height)
                        {
                            if (xNew + 1 < bmp.Width)
                            {
                                AddNextPixel(new Point(xNew + 1, yNew + 1));
                            }
                            if (xNew - 1 >= 0)
                            {
                                AddNextPixel(new Point(xNew - 1, yNew + 1));
                            }
                            AddNextPixel(new Point(xNew, yNew + 1));
                        }

                        bmp.SetPixel(xNew, yNew, replacementColor); // replace the pixel color
                    }
                    else
                    {
                        continue;
                    }
                }

                nextPixels.Clear();
                return;
            }
        }