Exemplo n.º 1
0
            /// <summary>
            /// Initializes a new instance of the EllipseUndoTask class
            /// </summary>
            /// <param name="targetBitmap">The target bitmap of this EllipseUndoTask</param>
            /// <param name="firstColor">The first color to use when drawing the ellipse</param>
            /// <param name="secondColor">The second color to use when drawing the ellipse</param>
            /// <param name="area">The area of the ellipse to draw</param>
            /// <param name="compositingMode">The CompositingMode to use when drawing the ellipse</param>
            /// <param name="fillMode">The fill mode for this ellipse operation</param>
            public EllipseUndoTask(Bitmap targetBitmap, Color firstColor, Color secondColor, Rectangle area, CompositingMode compositingMode, OperationFillMode fillMode)
            {
                _firstColor      = firstColor;
                _secondColor     = secondColor;
                _area            = area;
                _bitmap          = targetBitmap;
                _compositingMode = compositingMode;
                _fillMode        = fillMode;

                // Take the image slide now
                _originalSlice = new Bitmap(area.Width + 1, area.Height + 1);

                Graphics g = Graphics.FromImage(_originalSlice);

                g.DrawImage(_bitmap, new Point(-area.X, -area.Y));
                g.Flush();
                g.Dispose();
            }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the ImageEditPanel
        /// </summary>
        public ImageEditPanel()
        {
            EditingEnabled = true;

            // Create the controls
            SuspendLayout();

            _internalPictureBox = new InternalPictureBox(this)
            {
                MinimumZoom           = new PointF(0.25f, 0.25f),
                MaximumZoom           = new PointF(160, 160),
                ShowImageArea         = false,
                ClipBackgroundToImage = true,
                AllowDrag             = false,
                NotifyTo = this,
                Dock     = DockStyle.Fill
            };

            _owningPanel = new Panel
            {
                Dock        = DockStyle.Fill,
                AutoScroll  = true,
                BorderStyle = BorderStyle.FixedSingle
            };

            // Add controls
            _owningPanel.Controls.Add(_internalPictureBox);
            Controls.Add(_owningPanel);

            ResumeLayout(true);

            _undoSystem = new UndoSystem();

            _defaultCompositingMode = CompositingMode.SourceOver;
            _defaultFillMode        = OperationFillMode.SolidFillFirstColor;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Performs the shape paint operation with the given parameters
 /// </summary>
 /// <param name="color1">The first color to use when drawing the shape</param>
 /// <param name="color2">The second color to use when drawing the shape</param>
 /// <param name="area">The area of the shape to draw</param>
 /// <param name="gph">The Graphics to draw the shape on</param>
 /// <param name="compMode">The CompositingMode to use when drawing the shape</param>
 /// <param name="opFillMode">The fill mode for this shape operation</param>
 /// <param name="registerUndo">Whether to register an undo task for this shape operation</param>
 public abstract void PerformShapeOperation(Color color1, Color color2, Rectangle area, Graphics gph, CompositingMode compMode, OperationFillMode opFillMode, bool registerUndo);
Exemplo n.º 4
0
 /// <summary>
 /// Performs the shape paint operation with the given parameters
 /// </summary>
 /// <param name="color1">The first color to use when drawing the shape</param>
 /// <param name="color2">The second color to use when drawing the shape</param>
 /// <param name="area">The area of the shape to draw</param>
 /// <param name="bitmap">The Bitmap to draw the shape on</param>
 /// <param name="compMode">The CompositingMode to use when drawing the shape</param>
 /// <param name="opFillMode">The fill mode for this shape operation</param>
 /// <param name="registerUndo">Whether to register an undo task for this shape operation</param>
 public abstract ShapeUndoTask PerformShapeOperation(Color color1, Color color2, Rectangle area, Bitmap bitmap, CompositingMode compMode, OperationFillMode opFillMode, bool registerUndo);
Exemplo n.º 5
0
        /// <summary>
        /// Performs the Ellipse paint operation with the given parameters
        /// </summary>
        /// <param name="firstColor">The first color to use when drawing the ellipse</param>
        /// <param name="secondColor">The second color to use when drawing the ellipse</param>
        /// <param name="area">The area of the ellipse to draw</param>
        /// <param name="graphics">The Graphics to draw the ellipse on</param>
        /// <param name="compositingMode">The CompositingMode to use when drawing the ellipse</param>
        /// <param name="fillMode">The fill mode for this ellipse operation</param>
        public static void PerformElipseOperation(Color firstColor, Color secondColor, Rectangle area, Graphics graphics, CompositingMode compositingMode, OperationFillMode fillMode)
        {
            Brush brush = new SolidBrush((fillMode == OperationFillMode.SolidFillFirstColor ? firstColor : secondColor));

            graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed;

            if (fillMode == OperationFillMode.SolidFillFirstColor || fillMode == OperationFillMode.OutlineFirstColorFillSecondColor || fillMode == OperationFillMode.SolidFillSecondColor)
            {
                graphics.FillEllipse(brush, area);
            }

            if (fillMode == OperationFillMode.OutlineFirstColor || fillMode == OperationFillMode.OutlineFirstColorFillSecondColor)
            {
                Pen pen = new Pen(firstColor);

                graphics.DrawEllipse(pen, area);

                pen.Dispose();
            }

            brush.Dispose();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Performs the Ellipse paint operation with the given parameters
        /// </summary>
        /// <param name="firstColor">The first color to use when drawing the ellipse</param>
        /// <param name="secondColor">The second color to use when drawing the ellipse</param>
        /// <param name="area">The area of the ellipse to draw</param>
        /// <param name="bitmap">The Bitmap to draw the ellipse on</param>
        /// <param name="compositingMode">The CompositingMode to use when drawing the ellipse</param>
        /// <param name="fillMode">The fill mode for this ellipse operation</param>
        public static void PerformEllipseOperation(Color firstColor, Color secondColor, Rectangle area, Bitmap bitmap, CompositingMode compositingMode, OperationFillMode fillMode)
        {
            //FastBitmap fb = new FastBitmap(bitmap);
            //fb.Lock();

            /*int originx = area.X + area.Width / 2;
             * int originy = area.Y;
             * int width = area.Width;
             * int height = area.Height;
             * int hh = height * height;
             * int ww = width * width;
             * int hhww = hh * ww;
             * int x0 = width;
             * int dx = 0;
             *
             * // do the horizontal diameter
             * for (int x = -width; x <= width; x++)
             * {
             *  //setpixel(origin.x + x, origin.y);
             *  if (originx + x > 0 && originx + x < fb.Width && originy > 0 && originy < fb.Height)
             *      fb.SetPixel(originx + x, originy, firstColor);
             * }
             *
             * // now do both halves at the same time, away from the diameter
             * for (int y = 1; y <= height; y++)
             * {
             *  int x1 = x0 - (dx - 1);  // try slopes of dx - 1 or more
             *  for (; x1 > 0; x1--)
             *      if (x1 * x1 * hh + y * y * ww <= hhww)
             *          break;
             *  dx = x0 - x1;  // current approximation of the slope
             *  x0 = x1;
             *
             *  for (int x = -x0; x <= x0; x++)
             *  {
             *      if (originx + x > 0 && originx + x < fb.Width && originy - y > 0 && originy - y < fb.Height)
             *      fb.SetPixel(originx + x, originy - y, firstColor);
             *      if (originx + x > 0 && originx + x < fb.Width && originy + y > 0 && originy + y < fb.Height)
             *      fb.SetPixel(originx + x, originy + y, firstColor);
             *      //setpixel(origin.x + x, origin.y - y);
             *      //setpixel(origin.x + x, origin.y + y);
             *  }
             * }*/

            //fb.Unlock();

            Graphics graphics = Graphics.FromImage(bitmap);

            graphics.CompositingMode = compositingMode;

            PerformElipseOperation(firstColor, secondColor, area, graphics, compositingMode, fillMode);

            graphics.Flush();
            graphics.Dispose();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Performs the shape paint operation with the given parameters
 /// </summary>
 /// <param name="color1">The first color to use when drawing the shape</param>
 /// <param name="color2">The second color to use when drawing the shape</param>
 /// <param name="area">The area of the shape to draw</param>
 /// <param name="gph">The Graphics to draw the shape on</param>
 /// <param name="compMode">The CompositingMode to use when drawing the shape</param>
 /// <param name="opFillMode">The fill mode for this shape operation</param>
 /// <param name="registerUndo">Whether to register an undo task for this shape operation</param>
 public override void PerformShapeOperation(Color color1, Color color2, Rectangle area, Graphics gph, CompositingMode compMode, OperationFillMode opFillMode, bool registerUndo)
 {
     PerformElipseOperation(color1, color2, area, gph, compMode, opFillMode);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Performs the shape paint operation with the given parameters
        /// </summary>
        /// <param name="color1">The first color to use when drawing the shape</param>
        /// <param name="color2">The second color to use when drawing the shape</param>
        /// <param name="area">The area of the shape to draw</param>
        /// <param name="bitmap">The Bitmap to draw the shape on</param>
        /// <param name="compMode">The CompositingMode to use when drawing the shape</param>
        /// <param name="opFillMode">The fill mode for this shape operation</param>
        /// <param name="registerUndo">Whether to register an undo task for this shape operation</param>
        public override ShapeUndoTask PerformShapeOperation(Color color1, Color color2, Rectangle area, Bitmap bitmap, CompositingMode compMode, OperationFillMode opFillMode, bool registerUndo)
        {
            ShapeUndoTask returnTask = null;

            if (registerUndo)
            {
                returnTask = new EllipseUndoTask(pictureBox.Bitmap, color1, color2, area, compMode, opFillMode);
                pictureBox.OwningPanel.UndoSystem.RegisterUndo(returnTask);
            }

            PerformEllipseOperation(color1, color2, area, bitmap, compMode, opFillMode);

            return(returnTask);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Performs the Rectangle paint operation with the given parameters
        /// </summary>
        /// <param name="firstColor">The first color to use when drawing the rectangle</param>
        /// <param name="secondColor">The second color to use when drawing the rectangle</param>
        /// <param name="area">The area of the rectangle to draw</param>
        /// <param name="graphics">The Graphics to draw the rectangle on</param>
        /// <param name="compositingMode">The CompositingMode to use when drawing the rectangle</param>
        /// <param name="fillMode">The fill mode for this rectangle operation</param>
        public static void PerformRectangleOperation(Color firstColor, Color secondColor, Rectangle area, Graphics graphics, CompositingMode compositingMode, OperationFillMode fillMode)
        {
            Brush brush = new SolidBrush((fillMode == OperationFillMode.SolidFillFirstColor ? firstColor : secondColor));

            if (fillMode == OperationFillMode.SolidFillFirstColor || fillMode == OperationFillMode.OutlineFirstColorFillSecondColor || fillMode == OperationFillMode.SolidFillSecondColor)
            {
                Rectangle nArea = area;

                if (fillMode == OperationFillMode.OutlineFirstColorFillSecondColor)
                {
                    nArea.Inflate(-1, -1);
                }

                graphics.FillRectangle(brush, nArea);
            }

            if (fillMode == OperationFillMode.OutlineFirstColor || fillMode == OperationFillMode.OutlineFirstColorFillSecondColor)
            {
                Pen pen = new Pen(firstColor);

                area.Inflate(-1, -1);

                RectangleF nArea = area;

                graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

                nArea.X      -= 0.5f;
                nArea.Y      -= 0.5f;
                nArea.Width  += 1f;
                nArea.Height += 1f;

                graphics.DrawRectangle(pen, nArea.X, nArea.Y, nArea.Width, nArea.Height);

                pen.Dispose();
            }

            brush.Dispose();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Performs the Rectangle paint operation with the given parameters
        /// </summary>
        /// <param name="firstColor">The first color to use when drawing the rectangle</param>
        /// <param name="secondColor">The second color to use when drawing the rectangle</param>
        /// <param name="area">The area of the rectangle to draw</param>
        /// <param name="bitmap">The Bitmap to draw the rectangle on</param>
        /// <param name="compositingMode">The CompositingMode to use when drawing the rectangle</param>
        /// <param name="fillMode">The fill mode for this rectangle operation</param>
        public static void PerformRectangleOperation(Color firstColor, Color secondColor, Rectangle area, Bitmap bitmap, CompositingMode compositingMode, OperationFillMode fillMode)
        {
            Graphics graphics = Graphics.FromImage(bitmap);

            graphics.CompositingMode = compositingMode;

            PerformRectangleOperation(firstColor, secondColor, area, graphics, compositingMode, fillMode);

            graphics.Flush();
            graphics.Dispose();
        }