示例#1
0
        protected override void OnMouseUp(Document document, ToolMouseEventArgs e)
        {
            // If the user didn't move the mouse, they want to deselect
            var tolerance = 0;

            if (Math.Abs(reset_origin.X - e.WindowPoint.X) <= tolerance && Math.Abs(reset_origin.Y - e.WindowPoint.Y) <= tolerance)
            {
                // Mark as being done interactive drawing before invoking the deselect action.
                // This will allow AfterSelectionChanged() to clear the selection.
                is_drawing = false;

                if (hist != null)
                {
                    // Roll back any changes made to the selection, e.g. in OnMouseDown().
                    hist.Undo();

                    hist.Dispose();
                    hist = null;
                }

                PintaCore.Actions.Edit.Deselect.Activate();
            }
            else
            {
                ClearHandles(document.Layers.ToolLayer);

                var dirty = ReDraw(document, e.IsShiftPressed);

                if (document.Selection != null)
                {
                    SelectionModeHandler.PerformSelectionMode(combine_mode, document.Selection.SelectionPolygons);

                    document.Selection.Origin = shape_origin;
                    document.Selection.End    = shape_end;
                    document.Workspace.Invalidate(last_dirty.Union(dirty));
                    last_dirty = dirty;
                }
                if (hist != null)
                {
                    document.History.PushNewItem(hist);
                    hist = null;
                }
            }

            is_drawing     = false;
            active_control = null;

            // Update the mouse cursor.
            UpdateCursor(document, e.PointDouble);
        }
        public void Reposition(Gdk.Rectangle rect)
        {
            bool firstRect = true;

            foreach (SelectionHandlePart s in selection)
            {
                s.Reposition(rect);
                Gdk.Rectangle r = s.Allocation;
                if (firstRect)
                {
                    allocation = r;
                    firstRect  = false;
                }
                else
                {
                    allocation = allocation.Union(r);
                }
            }
        }
示例#3
0
        protected override void OnSizeAllocated(Gdk.Rectangle alloc)
        {
            base.OnSizeAllocated(alloc);
            int legend_height = LegendHeight();

            Gdk.Rectangle bar = new Rectangle(alloc.X + border, alloc.Y + border,
                                              alloc.Width - 2 * border,
                                              alloc.Height - 2 * border - glass.handle_height);


            if (left.Allocation.Y != bar.Y || left.Allocation.X != bar.X)
            {
                left.SetSizeRequest(-1, bar.Height);
                this.Move(left, bar.X - Allocation.X, bar.Y - Allocation.Y);
            }

            if (right.Allocation.Y != bar.Y || right.Allocation.X != bar.X + bar.Width - right.Allocation.Width)
            {
                right.SetSizeRequest(-1, bar.Height);
                this.Move(right, bar.X - Allocation.X + bar.Width - right.Allocation.Width,
                          bar.Y - Allocation.Y);
            }

            background = new Rectangle(bar.X + left.Allocation.Width, bar.Y,
                                       bar.Width - left.Allocation.Width - right.Allocation.Width,
                                       bar.Height);

            legend = new Rectangle(background.X, background.Y,
                                   background.Width, legend_height);

            action = background.Union(glass.Bounds());

            if (event_window != null)
            {
                event_window.MoveResize(action.X, action.Y, action.Width, action.Height);
            }

            this.Offset = this.Offset;

            UpdateButtons();
        }
示例#4
0
        /// <summary>
        /// Create a cursor icon with a shape that visually represents the tool's thickness.
        /// </summary>
        /// <param name="imgName">A string containing the name of the tool's icon image to use.</param>
        /// <param name="shape">The shape to draw.</param>
        /// <param name="shapeWidth">The width of the shape.</param>
        /// <param name="imgToShapeX">The horizontal distance between the image's top-left corner and the shape center.</param>
        /// <param name="imgToShapeY">The verical distance between the image's top-left corner and the shape center.</param>
        /// <param name="shapeX">The X position in the returned Pixbuf that will be the center of the shape.</param>
        /// <param name="shapeY">The Y position in the returned Pixbuf that will be the center of the shape.</param>
        /// <returns>The new cursor icon with an shape that represents the tool's thickness.</returns>
        public static Gdk.Pixbuf CreateIconWithShape(string imgName, CursorShape shape, int shapeWidth,
                                                     int imgToShapeX, int imgToShapeY,
                                                     out int shapeX, out int shapeY)
        {
            Gdk.Pixbuf img = PintaCore.Resources.GetIcon(imgName);

            double zoom = 1d;

            if (PintaCore.Workspace.HasOpenDocuments)
            {
                zoom = Math.Min(30d, PintaCore.Workspace.ActiveDocument.Workspace.Scale);
            }

            shapeWidth = (int)Math.Min(800d, ((double)shapeWidth) * zoom);
            int halfOfShapeWidth = shapeWidth / 2;

            // Calculate bounding boxes around the both image and shape
            // relative to the image top-left corner.
            Gdk.Rectangle imgBBox   = new Gdk.Rectangle(0, 0, img.Width, img.Height);
            Gdk.Rectangle shapeBBox = new Gdk.Rectangle(
                imgToShapeX - halfOfShapeWidth,
                imgToShapeY - halfOfShapeWidth,
                shapeWidth,
                shapeWidth);

            // Inflate shape bounding box to allow for anti-aliasing
            shapeBBox.Inflate(2, 2);

            // To determine required size of icon,
            // find union of the image and shape bounding boxes
            // (still relative to image top-left corner)
            Gdk.Rectangle iconBBox = imgBBox.Union(shapeBBox);

            // Image top-left corner in icon co-ordinates
            int imgX = imgBBox.Left - iconBBox.Left;
            int imgY = imgBBox.Top - iconBBox.Top;

            // Shape center point in icon co-ordinates
            shapeX = imgToShapeX - iconBBox.Left;
            shapeY = imgToShapeY - iconBBox.Top;

            using (var i = CairoExtensions.CreateImageSurface(Cairo.Format.ARGB32, iconBBox.Width, iconBBox.Height)) {
                using (var g = new Cairo.Context(i)) {
                    // Don't show shape if shapeWidth less than 3,
                    if (shapeWidth > 3)
                    {
                        int             diam      = Math.Max(1, shapeWidth - 2);
                        Cairo.Rectangle shapeRect = new Cairo.Rectangle(shapeX - halfOfShapeWidth,
                                                                        shapeY - halfOfShapeWidth,
                                                                        diam,
                                                                        diam);

                        Cairo.Color outerColor = new Cairo.Color(255, 255, 255, 0.75);
                        Cairo.Color innerColor = new Cairo.Color(0, 0, 0);

                        switch (shape)
                        {
                        case CursorShape.Ellipse:
                            g.DrawEllipse(shapeRect, outerColor, 2);
                            shapeRect = shapeRect.Inflate(-1, -1);
                            g.DrawEllipse(shapeRect, innerColor, 1);
                            break;

                        case CursorShape.Rectangle:
                            g.DrawRectangle(shapeRect, outerColor, 1);
                            shapeRect = shapeRect.Inflate(-1, -1);
                            g.DrawRectangle(shapeRect, innerColor, 1);
                            break;
                        }
                    }

                    // Draw the image
                    g.DrawPixbuf(img, new Cairo.Point(imgX, imgY));
                }

                return(CairoExtensions.ToPixbuf(i));
            }
        }
示例#5
0
        protected override void OnSizeAllocated(Gdk.Rectangle alloc)
        {
            base.OnSizeAllocated (alloc);
            int legend_height = LegendHeight ();

            Gdk.Rectangle bar = new Rectangle (alloc.X + border, alloc.Y + border,
                               alloc.Width - 2 *  border,
                               alloc.Height - 2 * border - glass.handle_height);

            if (left.Allocation.Y != bar.Y || left.Allocation.X != bar.X) {
                left.SetSizeRequest (-1, bar.Height);
                this.Move (left, bar.X - Allocation.X, bar.Y - Allocation.Y);
            }

            if (right.Allocation.Y != bar.Y || right.Allocation.X != bar.X + bar.Width - right.Allocation.Width) {
                right.SetSizeRequest (-1, bar.Height);
                this.Move (right,  bar.X - Allocation.X + bar.Width - right.Allocation.Width,
                       bar.Y - Allocation.Y);
            }

            background = new Rectangle (bar.X + left.Allocation.Width, bar.Y,
                            bar.Width - left.Allocation.Width - right.Allocation.Width,
                            bar.Height);

            legend = new Rectangle (background.X, background.Y,
                        background.Width, legend_height);

            action = background.Union (glass.Bounds ());

            if (event_window != null)
                event_window.MoveResize (action.X, action.Y, action.Width, action.Height);

            this.Offset = this.Offset;

            UpdateButtons ();
        }
示例#6
0
        /// <summary>
        /// Create a cursor icon with a shape that visually represents the tool's thickness.
        /// </summary>
        /// <param name="imgName">A string containing the name of the tool's icon image to use.</param>
        /// <param name="shape">The shape to draw.</param>
        /// <param name="shapeWidth">The width of the shape.</param>
        /// <param name="imgToShapeX">The horizontal distance between the image's top-left corner and the shape center.</param>
        /// <param name="imgToShapeX">The verical distance between the image's top-left corner and the shape center.</param>
        /// <param name="shapeX">The X position in the returned Pixbuf that will be the center of the shape.</param>
        /// <param name="shapeY">The Y position in the returned Pixbuf that will be the center of the shape.</param>
        /// <returns>The new cursor icon with an shape that represents the tool's thickness.</returns>
        protected Gdk.Pixbuf CreateIconWithShape(string imgName, CursorShape shape, int shapeWidth,
		                                          int imgToShapeX, int imgToShapeY,
		                                          out int shapeX, out int shapeY)
        {
            Gdk.Pixbuf img = PintaCore.Resources.GetIcon(imgName);

            double zoom = 1d;
            if (PintaCore.Workspace.HasOpenDocuments)
            {
                zoom = Math.Min(30d, PintaCore.Workspace.ActiveDocument.Workspace.Scale);
            }

            shapeWidth = (int)Math.Min(800d, ((double)shapeWidth) * zoom);
            int halfOfShapeWidth = shapeWidth / 2;

            // Calculate bounding boxes around the both image and shape
            // relative to the image top-left corner.
            Gdk.Rectangle imgBBox = new Gdk.Rectangle(0, 0, img.Width, img.Height);
            Gdk.Rectangle shapeBBox = new Gdk.Rectangle(
                imgToShapeX - halfOfShapeWidth,
                imgToShapeY - halfOfShapeWidth,
                shapeWidth,
                shapeWidth);

            // Inflate shape bounding box to allow for anti-aliasing
            shapeBBox.Inflate(2, 2);

            // To determine required size of icon,
            // find union of the image and shape bounding boxes
            // (still relative to image top-left corner)
            Gdk.Rectangle iconBBox = imgBBox.Union (shapeBBox);

            // Image top-left corner in icon co-ordinates
            int imgX = imgBBox.Left - iconBBox.Left;
            int imgY = imgBBox.Top - iconBBox.Top;

            // Shape center point in icon co-ordinates
            shapeX = imgToShapeX - iconBBox.Left;
            shapeY = imgToShapeY - iconBBox.Top;

            ImageSurface i = new ImageSurface(Format.ARGB32, iconBBox.Width, iconBBox.Height);
            using (Context g = new Context(i))
            {
                // Don't show shape if shapeWidth less than 3,
                if (shapeWidth > 3)
                {
                    int diam = Math.Max (1, shapeWidth - 2);
                    Cairo.Rectangle shapeRect = new Cairo.Rectangle(shapeX - halfOfShapeWidth,
                                                                     shapeY - halfOfShapeWidth,
                                                                     diam,
                                                                     diam);

                    Cairo.Color outerColor = new Cairo.Color (255, 255, 255, 0.5);
                    Cairo.Color innerColor = new Cairo.Color (0, 0, 0);

                    switch (shape)
                    {
                    case CursorShape.Ellipse:
                        g.DrawEllipse(shapeRect, outerColor, 1);
                        shapeRect = shapeRect.Inflate (-1, -1);
                        g.DrawEllipse(shapeRect, innerColor, 1);
                        break;
                    case CursorShape.Rectangle:
                        g.DrawRectangle(shapeRect, outerColor, 1);
                        shapeRect = shapeRect.Inflate (-1, -1);
                        g.DrawRectangle(shapeRect, innerColor, 1);
                        break;
                    }
                }

                // Draw the image
                g.DrawPixbuf(img, new Cairo.Point(imgX, imgY));
            }

            return CairoExtensions.ToPixbuf(i);
        }