コード例 #1
0
        protected override Rectangle DrawShape(Rectangle rect, Layer l)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            Rectangle dirty;

            using (Context g = new Context(l.Surface)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                dirty = rect;

                g.SetDash(DashPatternBox.GenerateDashArray(dashPattern, BrushWidth), 0.0);

                if (FillShape && StrokeShape)
                {
                    dirty = g.FillStrokedEllipse(rect, fill_color, outline_color, BrushWidth);
                }
                else if (FillShape)
                {
                    dirty = g.FillStrokedEllipse(rect, outline_color, outline_color, BrushWidth);
                }
                else
                {
                    dirty = g.DrawEllipse(rect, outline_color, BrushWidth);
                }
            }

            return(dirty);
        }
コード例 #2
0
        protected override void OnMouseUp(Document document, ToolMouseEventArgs e)
        {
            document.Layers.ToolLayer.Clear();
            document.Layers.ToolLayer.Hidden = true;

            using (Context g = document.CreateClippedContext()) {
                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                g.SetDash(DashPatternBox.GenerateDashArray(dash_pattern, BrushWidth), 0.0);

                if (path != null)
                {
                    g.AppendPath(path);
                    path.Dispose();
                    path = null;
                }

                g.ClosePath();
                g.LineWidth = BrushWidth;
                g.FillRule  = FillRule.EvenOdd;

                if (FillShape && StrokeShape)
                {
                    g.SetSourceColor(fill_color);
                    g.FillPreserve();
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
                else if (FillShape)
                {
                    g.SetSourceColor(outline_color);
                    g.FillPreserve();
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
                else
                {
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
            }

            if (surface_modified && undo_surface != null)
            {
                document.History.PushNewItem(new SimpleHistoryItem(Icon, Name, undo_surface, document.Layers.CurrentUserLayerIndex));
            }
            else if (undo_surface != null)
            {
                undo_surface.Dispose();
            }

            surface_modified = false;

            document.Workspace.Invalidate();
        }
コード例 #3
0
        protected override Rectangle DrawShape(Rectangle rect, Layer l)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            Rectangle dirty;

            using (Context g = new Context(l.Surface)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                double[] dashes = DashPatternBox.GenerateDashArray(dashPattern, BrushWidth);
                g.SetDash(dashes, 0.0);

                if (dashes.Length == 2 && dashes[1] == 0.0)
                {
                    //No dash pattern (solid line), so draw rectangle normally (glitch free).

                    if (FillShape && StrokeShape)
                    {
                        dirty = g.FillStrokedRectangle(rect, fill_color, outline_color, BrushWidth);
                    }
                    else if (FillShape)
                    {
                        dirty = g.FillStrokedRectangle(rect, outline_color, outline_color, BrushWidth);
                    }
                    else
                    {
                        dirty = g.DrawRectangle(rect, outline_color, BrushWidth);
                    }
                }
                else
                {
                    //Dash pattern, so draw rectangle as best as possible for dashes (but with possible corner glitches for some rectangle sizes).

                    if (FillShape && StrokeShape)
                    {
                        dirty = g.FillStrokedFullRectangle(rect, fill_color, outline_color, BrushWidth);
                    }
                    else if (FillShape)
                    {
                        dirty = g.FillStrokedFullRectangle(rect, outline_color, outline_color, BrushWidth);
                    }
                    else
                    {
                        dirty = g.DrawFullRectangle(rect, outline_color, BrushWidth);
                    }
                }
            }

            return(dirty);
        }
コード例 #4
0
        protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            doc.ToolLayer.Hidden = true;

            if (surface_modified)
            {
                PintaCore.History.PushNewItem(new SimpleHistoryItem(Icon, Name, undo_surface, doc.CurrentUserLayerIndex));
            }
            else if (undo_surface != null)
            {
                (undo_surface as IDisposable).Dispose();
            }

            surface_modified = false;
            ImageSurface surf = doc.CurrentUserLayer.Surface;

            using (Context g = new Context(surf)) {
                g.AppendPath(doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                g.SetDash(DashPatternBox.GenerateDashArray(dashPattern, BrushWidth), 0.0);

                if (path != null)
                {
                    g.AppendPath(path);
                    (path as IDisposable).Dispose();
                    path = null;
                }

                g.ClosePath();
                g.LineWidth = BrushWidth;
                g.FillRule  = FillRule.EvenOdd;

                if (FillShape && StrokeShape)
                {
                    g.SetSourceColor(fill_color);
                    g.FillPreserve();
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
                else if (FillShape)
                {
                    g.SetSourceColor(outline_color);
                    g.FillPreserve();
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
                else
                {
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
            }

            doc.Workspace.Invalidate();
        }
コード例 #5
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if ((args.Event.State & Gdk.ModifierType.Button1Mask) == Gdk.ModifierType.Button1Mask)
            {
                outline_color = PintaCore.Palette.PrimaryColor;
                fill_color    = PintaCore.Palette.SecondaryColor;
            }
            else if ((args.Event.State & Gdk.ModifierType.Button3Mask) == Gdk.ModifierType.Button3Mask)
            {
                outline_color = PintaCore.Palette.SecondaryColor;
                fill_color    = PintaCore.Palette.PrimaryColor;
            }
            else
            {
                last_point = point_empty;
                return;
            }

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals(point_empty))
            {
                last_point = new Point(x, y);
                return;
            }

            if (doc.Workspace.PointInCanvas(point))
            {
                surface_modified = true;
            }

            doc.ToolLayer.Clear();
            ImageSurface surf = doc.ToolLayer.Surface;

            using (Context g = new Context(surf)) {
                doc.Selection.Clip(g);

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                g.SetDash(DashPatternBox.GenerateDashArray(dashPattern, BrushWidth), 0.0);

                if (path != null)
                {
                    g.AppendPath(path);
                    (path as IDisposable).Dispose();
                }
                else
                {
                    g.MoveTo(x, y);
                }

                g.LineTo(x, y);

                path = g.CopyPath();

                g.ClosePath();
                g.LineWidth = BrushWidth;
                g.FillRule  = FillRule.EvenOdd;

                if (FillShape && StrokeShape)
                {
                    g.SetSourceColor(fill_color);
                    g.FillPreserve();
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
                else if (FillShape)
                {
                    g.SetSourceColor(outline_color);
                    g.FillPreserve();
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
                else
                {
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
            }

            doc.Workspace.Invalidate();

            last_point = new Point(x, y);
        }
コード例 #6
0
        protected override void OnMouseMove(Document document, ToolMouseEventArgs e)
        {
            if (e.IsLeftMousePressed)
            {
                outline_color = Palette.PrimaryColor;
                fill_color    = Palette.SecondaryColor;
            }
            else if (e.IsRightMousePressed)
            {
                outline_color = Palette.SecondaryColor;
                fill_color    = Palette.PrimaryColor;
            }
            else
            {
                last_point = point_empty;
                return;
            }

            var x = e.Point.X;
            var y = e.Point.Y;

            if (last_point.Equals(point_empty))
            {
                last_point = e.Point;
                return;
            }

            if (document.Workspace.PointInCanvas(e.PointDouble))
            {
                surface_modified = true;
            }

            document.Layers.ToolLayer.Clear();

            using (var g = document.CreateClippedToolContext()) {
                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                g.SetDash(DashPatternBox.GenerateDashArray(dash_pattern, BrushWidth), 0.0);

                if (path != null)
                {
                    g.AppendPath(path);
                    path.Dispose();
                }
                else
                {
                    g.MoveTo(x, y);
                }

                g.LineTo(x, y);

                path = g.CopyPath();

                g.ClosePath();
                g.LineWidth = BrushWidth;
                g.FillRule  = FillRule.EvenOdd;

                if (FillShape && StrokeShape)
                {
                    g.SetSourceColor(fill_color);
                    g.FillPreserve();
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
                else if (FillShape)
                {
                    g.SetSourceColor(outline_color);
                    g.FillPreserve();
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
                else
                {
                    g.SetSourceColor(outline_color);
                    g.Stroke();
                }
            }

            document.Workspace.Invalidate();

            last_point = new Point(x, y);
        }