Clip() публичный Метод

public Clip ( ) : void
Результат void
Пример #1
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        int          w, h;
        ImageSurface image;

        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
        gr.Clip();
        gr.NewPath();

        image = new ImageSurface("data/e.png");
        w     = image.Width;
        h     = image.Height;

        gr.Scale(1.0 / w, 1.0 / h);

        image.Show(gr, 0, 0);

        image.Destroy();

        gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
        gr.Clip();

        gr.NewPath();
        gr.Rectangle(new PointD(0, 0), 1, 1);
        gr.Fill();
        gr.Color = new Color(0, 1, 0, 1);
        gr.MoveTo(new PointD(0, 0));
        gr.LineTo(new PointD(1, 1));
        gr.MoveTo(new PointD(1, 0));
        gr.LineTo(new PointD(0, 1));
        gr.Stroke();
    }
Пример #2
0
 public void IntersectClip(RectangleD newClip)
 {
     cairoContext.Rectangle(newClip.X * drawingScaleX,
                            newClip.Y * drawingScaleY,
                            newClip.Width * drawingScaleX,
                            newClip.Height * drawingScaleY);
     cairoContext.Clip();
 }
		protected override void DrawBackground (Context context, Gdk.Rectangle region)
		{
			LayoutRoundedRectangle (context, region);
			context.Clip ();

			context.SetSourceColor (CairoExtensions.ParseColor ("D3E6FF"));
			context.Paint ();

			context.Save ();
			context.Translate (region.X + region.Width / 2.0, region.Y + region.Height);

			using (var rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) {
				var color = CairoExtensions.ParseColor ("E5F0FF");
				rg.AddColorStop (0, color);
				color.A = 0;
				rg.AddColorStop (1, color);

				context.Scale (region.Width / (double)region.Height, 1.0);
				context.SetSource (rg);
				context.Paint ();
			}

			context.Restore ();

			LayoutRoundedRectangle (context, region, -3, -3, 2);
			context.SetSourceRGBA (1, 1, 1, 0.4);
			context.LineWidth = 1;
			context.StrokePreserve ();

			context.Clip ();

			int boxSize = 11;
			int x = region.Left + (region.Width % boxSize) / 2;
			for (; x < region.Right; x += boxSize) {
				context.MoveTo (x + 0.5, region.Top);
				context.LineTo (x + 0.5, region.Bottom);
			}

			int y = region.Top + (region.Height % boxSize) / 2;
			y += boxSize / 2;
			for (; y < region.Bottom; y += boxSize) {
				context.MoveTo (region.Left, y + 0.5);
				context.LineTo (region.Right, y + 0.5);
			}

			context.SetSourceRGBA (1, 1, 1, 0.2);
			context.Stroke ();

			context.ResetClip ();
		}
Пример #4
0
        protected unsafe override void OnFillRegionComputed(Point[][] polygonSet)
        {
            SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name);
            hist.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayer);

            PintaCore.Layers.ToolLayer.Clear ();
            ImageSurface surface = PintaCore.Layers.ToolLayer.Surface;

            ColorBgra* surf_data_ptr = (ColorBgra*)surface.DataPtr;
            int surf_width = surface.Width;

            for (int x = 0; x < stencil.Width; x++)
                for (int y = 0; y < stencil.Height; y++)
                    if (stencil.GetUnchecked (x, y))
                        surface.SetPixel (surf_data_ptr, surf_width, x, y, fill_color);

            using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Antialias.Subpixel;

                g.SetSource (surface);
                g.Paint ();
            }

            PintaCore.History.PushNewItem (hist);
            PintaCore.Workspace.Invalidate ();
        }
Пример #5
0
        public void clip(Context ctx)
        {
            foreach (Rectangle r in list)
                ctx.Rectangle(r);

            ctx.Clip();
        }
Пример #6
0
        public static SurfacePattern CreateImageBrush(ImageBrush brush, Size targetSize)
        {
            if (brush.Source == null)
            {
                return null;
            }

            // TODO: This is directly ported from Direct2D and could probably be made more
            // efficient on cairo by taking advantage of the fact that cairo has Extend.None.
            var image = ((BitmapImpl)brush.Source.PlatformImpl).Surface;
            var imageSize = new Size(brush.Source.PixelWidth, brush.Source.PixelHeight);
            var tileMode = brush.TileMode;
            var sourceRect = brush.SourceRect.ToPixels(imageSize);
            var destinationRect = brush.DestinationRect.ToPixels(targetSize);
            var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);

			var intermediate = new ImageSurface (Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height);
            using (var context = new Context(intermediate))
            {
                Rect drawRect;
                var transform = CalculateIntermediateTransform(
                    tileMode,
                    sourceRect,
                    destinationRect,
                    scale,
                    translate,
                    out drawRect);
                context.Rectangle(drawRect.ToCairo());
                context.Clip();
                context.Transform(transform.ToCairo());
                Gdk.CairoHelper.SetSourcePixbuf(context, image, 0, 0);
                context.Rectangle(0, 0, imageSize.Width, imageSize.Height);
                context.Fill();

                var result = new SurfacePattern(intermediate);

                if ((brush.TileMode & TileMode.FlipXY) != 0)
                {
                    // TODO: Currently always FlipXY as that's all cairo supports natively. 
                    // Support separate FlipX and FlipY by drawing flipped images to intermediate
                    // surface.
                    result.Extend = Extend.Reflect;
                }
                else
                {
                    result.Extend = Extend.Repeat;
                }

                if (brush.TileMode != TileMode.None)
                {
                    var matrix = result.Matrix;
                    matrix.InitTranslate(-destinationRect.X, -destinationRect.Y);
                    result.Matrix = matrix;
                }

                return result;
            }
        }
        void DrawString(string text, bool isMarkup, Cairo.Context context, int x, int y, int width, double opacity, Pango.Context pango, StatusArea.RenderArg arg)
        {
            Pango.Layout pl = new Pango.Layout(pango);
            if (isMarkup)
            {
                pl.SetMarkup(text);
            }
            else
            {
                pl.SetText(text);
            }
            pl.FontDescription = Styles.StatusFont;
            pl.FontDescription.AbsoluteSize = Pango.Units.FromPixels(Styles.StatusFontPixelHeight);
            pl.Ellipsize = Pango.EllipsizeMode.End;
            pl.Width     = Pango.Units.FromPixels(width);

            int w, h;

            pl.GetPixelSize(out w, out h);

            context.Save();
            // use widget height instead of message box height as message box does not have a true height when no widgets are packed in it
            // also ensures animations work properly instead of getting clipped
            context.Rectangle(new Rectangle(x, arg.Allocation.Y, width, arg.Allocation.Height));
            context.Clip();

            // Subtract off remainder instead of drop to prefer higher centering when centering an odd number of pixels
            context.MoveTo(x, y - h / 2 - (h % 2));
            context.Color = Styles.WithAlpha(FontColor(), opacity);

            Pango.CairoHelper.ShowLayout(context, pl);
            pl.Dispose();
            context.Restore();
        }
Пример #8
0
        public void Draw(ImageSurface dst)
        {
            if (disposed)
            {
                throw new ObjectDisposedException("PlacedSurface");
            }

            using (Cairo.Context g = new Cairo.Context(dst)) {
                g.Save();

                Rectangle r = what.GetBounds().ToCairoRectangle();

                // We need to use the source operator to fully replace the old
                // data.  Or else we may paint transparent on top of it and
                // it will still be visible.  [Bug #670411]
                using (Path p = g.CreateRectanglePath(new Rectangle(where.X, where.Y, r.Width, r.Height))) {
                    g.AppendPath(p);
                    g.Clip();
                    g.Operator = Operator.Source;
                    g.DrawPixbuf(what.ToPixbuf(), new Cairo.Point(where.X, where.Y));
                }

                g.Restore();
            }
        }
Пример #9
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            bool idle = incoming_track == null && current_track == null;

            if (!Visible || !IsMapped || (idle && !CanRenderIdle))
            {
                return(true);
            }

            Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window);

            foreach (Gdk.Rectangle damage in evnt.Region.GetRectangles())
            {
                cr.Rectangle(damage.X, damage.Y, damage.Width, damage.Height);
                cr.Clip();

                if (idle)
                {
                    RenderIdle(cr);
                }
                else
                {
                    RenderAnimation(cr);
                }

                cr.ResetClip();
            }

            CairoExtensions.DisposeContext(cr);

            return(true);
        }
Пример #10
0
        protected override bool OnExposeEvent(EventExpose ev)
        {
            if (!IsRealized)
            {
                return(false);
            }

            Cairo.Context cr = CairoHelper.Create(GdkWindow);

            Gdk.Rectangle rect = ev.Area;
            cr.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
            cr.Clip();

            paper.Draw(cr, rect);
            drawStrokes(cr, rect);

            // Uncomment this to see the clipping region

/*            cr.Color = new Cairo.Color(0.0,1.0,0.0,0.5);
 *          cr.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
 *          cr.Stroke();*/

            ((IDisposable)cr).Dispose();

            return(true);
        }
Пример #11
0
        protected void DrawBackground(Cairo.Context cr)
        {
            var totalRect = GetTotalBounds();

            cr.SetSourceColor(BackgroundColor);
            cr.Rectangle(totalRect.X, totalRect.Y, totalRect.Width, totalRect.Height);
            cr.Fill();

            cr.Save();
            cr.Translate(XOffset, YOffset);
            cr.Scale(Scale, Scale);

            if (Surface != null)
            {
                cr.SetSource(Surface, 0, 0);

                using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) {
                    pattern.Filter = Filter.Nearest;
                }

                cr.Paint();
            }
            else if (Image != null)
            {
                using (Surface source = new BitmapSurface(Image)) {
                    cr.SetSource(source, 0, 0);

                    using (SurfacePattern pattern = (SurfacePattern)cr.GetSource()) {
                        pattern.Filter = Filter.Nearest;
                    }

                    cr.Paint();
                }
            }
            else
            {
                Cairo.Rectangle extents = cr.ClipExtents();
                for (int i = 0; i < Width * Height; i++)
                {
                    int             tileX = i % Width;
                    int             tileY = i / Width;
                    Cairo.Rectangle rect  = GetTileRectWithPadding(tileX, tileY, scale: false, offset: false);

                    if (!CairoHelper.RectsOverlap(extents, rect))
                    {
                        continue;
                    }

                    cr.Save();
                    cr.Translate(rect.X + TilePaddingX, rect.Y + TilePaddingY);
                    cr.Rectangle(0, 0, TileWidth, TileHeight);
                    cr.Clip();
                    TileDrawer(i, cr);
                    cr.Restore();
                }
            }

            cr.Restore(); // Undo scale, offset
        }
 public static void RenderTiled(this Cairo.Context self, Gdk.Pixbuf source, Gdk.Rectangle area, Gdk.Rectangle clip, double opacity = 1)
 {
     Gdk.CairoHelper.SetSourcePixbuf(self, source, area.X, area.Y);
     cairo_pattern_set_extend(self.Pattern.Pointer, CairoExtend.CAIRO_EXTEND_REPEAT);
     self.Rectangle(clip.ToCairoRect());
     self.Clip();
     self.PaintWithAlpha(opacity);
     self.ResetClip();
 }
Пример #13
0
        protected override void OnStartTransform()
        {
            base.OnStartTransform();

            Document doc = PintaCore.Workspace.ActiveDocument;

            // If there is no selection, select the whole image.
            if (doc.Selection.SelectionPolygons.Count == 0)
            {
                doc.Selection.CreateRectangleSelection(
                    new Cairo.Rectangle(0, 0, doc.ImageSize.Width, doc.ImageSize.Height));
            }

            original_selection = doc.Selection.Clone();
            original_transform.InitMatrix(doc.SelectionLayer.Transform);

            hist = new MovePixelsHistoryItem(Icon, Name, doc);
            hist.TakeSnapshot(!doc.ShowSelectionLayer);

            if (!doc.ShowSelectionLayer)
            {
                // Copy the selection to the temp layer
                doc.CreateSelectionLayer();
                doc.ShowSelectionLayer = true;
                //Use same BlendMode, Opacity and Visibility for SelectionLayer
                doc.SelectionLayer.BlendMode = doc.CurrentUserLayer.BlendMode;
                doc.SelectionLayer.Opacity   = doc.CurrentUserLayer.Opacity;
                doc.SelectionLayer.Hidden    = doc.CurrentUserLayer.Hidden;

                using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource(doc.CurrentUserLayer.Surface);
                    g.Clip();
                    g.Paint();
                }

                Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface;

                using (Cairo.Context g = new Cairo.Context(surf)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    if (is_alt_pressed)
                    {
                        g.Operator = Cairo.Operator.Clear;
                    }
                    else
                    {
                        g.Operator = Operator.Source;
                        g.SetSourceColor(PintaCore.Palette.SecondaryColor);
                    }
                    g.Fill();
                }
            }

            PintaCore.Workspace.Invalidate();
        }
        void DrawBuildEffect(Cairo.Context context, Gdk.Rectangle area, double progress, double opacity)
        {
            context.Save();
            LayoutRoundedRectangle(context, area);
            context.Clip();

            Gdk.Point center = new Gdk.Point(area.Left + 19, (area.Top + area.Bottom) / 2);
            context.Translate(center.X, center.Y);
            var circles = new [] {
                new { Radius = 200, Thickness = 12, Speed = 1, ArcLength = Math.PI * 1.50 },
                new { Radius = 195, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.50 },
                new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 },
                new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 },
                new { Radius = 240, Thickness = 12, Speed = 3, ArcLength = Math.PI * 1.50 },
                new { Radius = 160, Thickness = 17, Speed = 3, ArcLength = Math.PI * 0.75 },
                new { Radius = 200, Thickness = 15, Speed = 2, ArcLength = Math.PI * 0.25 },
                new { Radius = 215, Thickness = 20, Speed = 2, ArcLength = Math.PI * 1.25 }
            };

            double zmod  = 1.0d;
            double zporg = progress;

            foreach (var arc in circles)
            {
                double zoom = 1.0d;
                zoom = (double)Math.Sin(zporg * Math.PI * 2 + zmod);
                zoom = ((zoom + 1) / 6.0d) + .05d;

                context.Rotate(Math.PI * 2 * progress * arc.Speed);
                context.MoveTo(arc.Radius * zoom, 0);
                context.Arc(0, 0, arc.Radius * zoom, 0, arc.ArcLength);
                context.LineWidth = arc.Thickness * zoom;
                context.SetSourceColor(CairoExtensions.ParseColor("B1DDED", 0.35 * opacity));
                context.Stroke();
                context.Rotate(Math.PI * 2 * -progress * arc.Speed);

                progress = -progress;

                context.Rotate(Math.PI * 2 * progress * arc.Speed);
                context.MoveTo(arc.Radius * zoom, 0);
                context.Arc(0, 0, arc.Radius * zoom, 0, arc.ArcLength);
                context.LineWidth = arc.Thickness * zoom;
                context.Stroke();
                context.Rotate(Math.PI * 2 * -progress * arc.Speed);

                progress = -progress;

                zmod += (float)Math.PI / circles.Length;
            }

            context.LineWidth = 1;
            context.ResetClip();
            context.Restore();
        }
Пример #15
0
        public static void RenderTiled(this Cairo.Context self, Gdk.Pixbuf source, Gdk.Rectangle area, Gdk.Rectangle clip, double opacity = 1)
        {
            Gdk.CairoHelper.SetSourcePixbuf(self, source, area.X, area.Y);
            //NOTE: Mono.Cairo.Context.Pattern returns an object than cannot be safely disposed, so P/Invoke directly
            var pattern = cairo_get_source(self.Handle);

            cairo_pattern_set_extend(pattern, CairoExtend.CAIRO_EXTEND_REPEAT);
            self.Rectangle(clip.ToCairoRect());
            self.Clip();
            self.PaintWithAlpha(opacity);
            self.ResetClip();
        }
Пример #16
0
        public ImageSurface GetClippedLayer(int index)
        {
            Cairo.ImageSurface surf = new Cairo.ImageSurface(Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

            using (Cairo.Context g = new Cairo.Context(surf)) {
                g.AppendPath(Selection.SelectionPath);
                g.Clip();

                g.SetSource(UserLayers[index].Surface);
                g.Paint();
            }

            return(surf);
        }
        void DrawProgressBar(Cairo.Context context, double progress, Gdk.Rectangle bounding, StatusArea.RenderArg arg)
        {
            LayoutRoundedRectangle(context, new Gdk.Rectangle(bounding.X, bounding.Y, (int)(bounding.Width * progress), bounding.Height), 0, 0, 1);
            context.Clip();

            LayoutRoundedRectangle(context, bounding, 0, 0, 1);
            context.SetSourceColor(Styles.WithAlpha(Styles.StatusBarProgressBackgroundColor, Styles.StatusBarProgressBackgroundColor.A * arg.ProgressBarAlpha));
            context.FillPreserve();

            context.ResetClip();

            context.SetSourceColor(Styles.WithAlpha(Styles.StatusBarProgressOutlineColor, Styles.StatusBarProgressOutlineColor.A * arg.ProgressBarAlpha));
            context.LineWidth = 1;
            context.Stroke();
        }
Пример #18
0
        protected override void OnStartTransform()
        {
            base.OnStartTransform();

            Document doc = PintaCore.Workspace.ActiveDocument;

            // If there is no selection, select the whole image.
            if (doc.Selection.SelectionPolygons.Count == 0)
            {
                doc.Selection.CreateRectangleSelection(
                    doc.SelectionLayer.Surface, new Cairo.Rectangle(0, 0, doc.ImageSize.Width, doc.ImageSize.Height));
            }

            original_selection = new List <List <IntPoint> > (doc.Selection.SelectionPolygons);
            original_transform.InitMatrix(doc.SelectionLayer.Transform);

            hist = new MovePixelsHistoryItem(Icon, Name, doc);
            hist.TakeSnapshot(!doc.ShowSelectionLayer);

            if (!doc.ShowSelectionLayer)
            {
                // Copy the selection to the temp layer
                doc.CreateSelectionLayer();
                doc.ShowSelectionLayer = true;

                using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource(doc.CurrentUserLayer.Surface);
                    g.Clip();
                    g.Paint();
                }

                Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface;

                using (Cairo.Context g = new Cairo.Context(surf)) {
                    g.AppendPath(doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Operator = Cairo.Operator.Clear;
                    g.Fill();
                }
            }

            PintaCore.Workspace.Invalidate();
        }
Пример #19
0
    static void draw(Cairo.Context gr, int width, int height)
    {
        gr.Scale(width, height);
        gr.LineWidth = 0.04;

        gr.Arc(0.5, 0.5, 0.3, 0, 2 * M_PI);
        gr.Clip();

        gr.NewPath();
        gr.Rectangle(new PointD(0, 0), 1, 1);
        gr.Fill();
        gr.Color = new Color(0, 1, 0, 1);
        gr.MoveTo(new PointD(0, 0));
        gr.LineTo(new PointD(1, 1));
        gr.MoveTo(new PointD(1, 0));
        gr.LineTo(new PointD(0, 1));
        gr.Stroke();
    }
Пример #20
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.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

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

                dirty = g.DrawLine (shape_origin, current_point , outline_color, BrushWidth);
            }

            return dirty;
        }
Пример #21
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            if (!IsRealized)
            {
                return(false);
            }

            Cairo.Context cr = Gdk.CairoHelper.Create(GdkWindow);

            foreach (Gdk.Rectangle rect in evnt.Region.GetRectangles())
            {
                cr.Rectangle(rect.X, rect.Y, rect.Width, rect.Height);
                cr.Clip();
                Draw(cr);
            }

            ((IDisposable)cr).Dispose();
            return(false);
        }
Пример #22
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            // If we are already drawing, ignore any additional mouse down events
            if (is_dragging)
            {
                return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

            origin_offset = point;
            is_dragging   = true;

            hist = new MovePixelsHistoryItem(Icon, Name, doc);
            hist.TakeSnapshot(!doc.ShowSelectionLayer);

            if (!doc.ShowSelectionLayer)
            {
                // Copy the selection to the temp layer
                doc.CreateSelectionLayer();
                doc.ShowSelectionLayer = true;

                using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) {
                    g.AppendPath(doc.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource(doc.CurrentLayer.Surface);
                    g.Clip();
                    g.Paint();
                }

                Cairo.ImageSurface surf = doc.CurrentLayer.Surface;

                using (Cairo.Context g = new Cairo.Context(surf)) {
                    g.AppendPath(doc.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Operator = Cairo.Operator.Clear;
                    g.Fill();
                }
            }

            canvas.GdkWindow.Invalidate();
        }
Пример #23
0
        protected override bool OnExposeEvent(Gdk.EventExpose ee)
        {
            // get dimensions
            int    width   = this.Allocation.Width;
            int    height  = this.Allocation.Height;
            double centerx = (double)width / 2.0;
            double centery = (double)height / 2.0;

            // init cairo or die.
            Cairo.Context gc = Gdk.CairoHelper.Create(this.GdkWindow);

            // paint widget background
            gc.Rectangle(0, 0, width, height);
            gc.Color = background;
            gc.FillPreserve();
            gc.Clip();

            gc.NewPath();
            gc.Save();
            gc.Matrix = transformMatrix;

            // draw the graphics.
            if (render != null)
            {
                render(gc);
            }

            gc.Restore();

            if (overlay != null)
            {
                overlay(gc);
            }

            PaintZoomScale(gc, width, height, centerx, centery);
            PaintMotionIndicators(gc, width, height, centerx, centery);

            ((IDisposable)gc.Target).Dispose();
            ((IDisposable)gc).Dispose();
            return(true);
        }
Пример #24
0
        protected override Rectangle DrawShape(Rectangle rect, Layer l)
        {
            Rectangle dirty;

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

                g.Antialias = Antialias.Subpixel;

                if (FillShape && StrokeShape)
                    dirty = g.FillStrokedRectangle (rect, fill_color, outline_color, BrushWidth);
                else if (FillShape)
                    dirty = g.FillRectangle (rect, outline_color);
                else
                    dirty = g.DrawRectangle (rect, outline_color, BrushWidth);
            }

            return dirty;
        }
Пример #25
0
 private static void Draw(LayoutGroup group, Cairo.Context context, bool needClip)
 {
     if (needClip)
     {
         var rect  = group.Rect;
         var style = group.Style;
         context.Rectangle(rect.X + style.PaddingLeft + style.BorderLeft, rect.Y + style.PaddingTop + style.BorderTop,
                           rect.Width - style.PaddingHorizontal - style.BorderHorizontal, rect.Height - style.PaddingVertical - style.BorderVertical);
         //context.StrokePreserve();
         context.Clip();
     }
     foreach (var entry in @group.Entries)
     {
         if (entry.HorizontallyStretched || entry.VerticallyStretched)
         {
             context.FillRectangle(entry.Rect, CairoEx.ColorLightBlue);
         }
         else if (entry.IsFixedWidth || entry.IsFixedHeight)
         {
             context.FillRectangle(entry.Rect, CairoEx.ColorOrange);
         }
         else
         {
             context.FillRectangle(entry.Rect, CairoEx.ColorPink);
         }
         context.StrokeRectangle(entry.Rect, CairoEx.ColorBlack);
         var innerGroup = entry as LayoutGroup;
         if (innerGroup != null)
         {
             context.Save();
             Draw(innerGroup, context, needClip);
             context.Restore();
         }
     }
     if (needClip)
     {
         context.ResetClip();
     }
 }
        void DrawErrorAnimation(Cairo.Context context, StatusArea.RenderArg arg)
        {
            const int surfaceWidth = 2000;
            double    opacity;
            int       progress;

            if (arg.ErrorAnimationProgress < .5f)
            {
                progress = (int)(arg.ErrorAnimationProgress * arg.Allocation.Width * 2.4);
                opacity  = 1.0d;
            }
            else
            {
                progress = (int)(arg.ErrorAnimationProgress * arg.Allocation.Width * 2.4);
                opacity  = 1.0d - (arg.ErrorAnimationProgress - .5d) * 2;
            }

            LayoutRoundedRectangle(context, arg.Allocation);

            context.Clip();
            context.CachedDraw(surface: ref errorSurface,
                               position: new Gdk.Point(arg.Allocation.X - surfaceWidth + progress, arg.Allocation.Y),
                               size: new Gdk.Size(surfaceWidth, arg.Allocation.Height),
                               opacity: (float)opacity,
                               draw: (c, o) => {
                // The smaller the pixel range of our gradient the less error there will be in it.
                using (var lg = new LinearGradient(surfaceWidth - 250, 0, surfaceWidth, 0)) {
                    lg.AddColorStop(0.00, Styles.WithAlpha(Styles.StatusBarErrorColor, 0.15 * o));
                    lg.AddColorStop(0.10, Styles.WithAlpha(Styles.StatusBarErrorColor, 0.15 * o));
                    lg.AddColorStop(0.88, Styles.WithAlpha(Styles.StatusBarErrorColor, 0.30 * o));
                    lg.AddColorStop(1.00, Styles.WithAlpha(Styles.StatusBarErrorColor, 0.00 * o));

                    c.SetSource(lg);
                    c.Paint();
                }
            });
            context.ResetClip();
        }
Пример #27
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;

                if (FillShape && StrokeShape)
                    dirty = g.FillStrokedRectangle (rect, fill_color, outline_color, BrushWidth);
                else if (FillShape)
                    dirty = g.FillRectangle (rect, outline_color);
                else
                    dirty = g.DrawRectangle (rect, outline_color, BrushWidth);
            }

            return dirty;
        }
Пример #28
0
        protected unsafe override void OnFillRegionComputed(Point[][] polygonSet)
        {
            SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name);
            hist.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayer);

            using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                // Reset FillRule to the default
                g.FillRule = FillRule.Winding;
                g.AppendPath (g.CreatePolygonPath (polygonSet));

                g.Antialias = Antialias.Subpixel;

                g.Color = fill_color;
                g.Fill ();
            }

            PintaCore.History.PushNewItem (hist);
            PintaCore.Workspace.Invalidate ();
        }
Пример #29
0
        public ImageSurface GetClippedLayer(int index)
        {
            Cairo.ImageSurface surf = new Cairo.ImageSurface (Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

            using (Cairo.Context g = new Cairo.Context (surf)) {
                g.AppendPath (SelectionPath);
                g.Clip ();

                g.SetSource (Layers[index].Surface);
                g.Paint ();
            }

            return surf;
        }
Пример #30
0
        void Draw(Cairo.Context ctx)
        {
            int tabArea = tabEndX - tabStartX;
            int x       = GetRenderOffset();
            int y       = 0;
            int n       = 0;
            Action <Cairo.Context>         drawActive   = c => {};
            List <Action <Cairo.Context> > drawCommands = new List <Action <Context> > ();

            for (; n < notebook.Tabs.Count; n++)
            {
                if (x + TabWidth < tabStartX)
                {
                    x += TabWidth;
                    continue;
                }

                if (x > tabEndX)
                {
                    break;
                }

                int closingWidth;
                var cmd = DrawClosingTab(n, new Gdk.Rectangle(x, y, 0, Allocation.Height), out closingWidth);
                drawCommands.Add(cmd);
                x += closingWidth;

                var  tab    = (DockNotebookTab)notebook.Tabs [n];
                bool active = tab == notebook.CurrentTab;

                int width = Math.Min(TabWidth, Math.Max(50, tabEndX - x - 1));
                if (tab == notebook.Tabs.Last())
                {
                    width += LastTabWidthAdjustment;
                }
                width = (int)(width * tab.WidthModifier);

                if (active)
                {
                    int tmp = x;
                    drawActive     = c => DrawTab(c, tab, Allocation, new Gdk.Rectangle(tmp, y, width, Allocation.Height), true, true, draggingTab, CreateTabLayout(tab));
                    tab.Allocation = new Gdk.Rectangle(tmp, Allocation.Y, width, Allocation.Height);
                }
                else
                {
                    int  tmp         = x;
                    bool highlighted = tab == highlightedTab;

                    if (tab.SaveStrength > 0.0f)
                    {
                        tmp = (int)(tab.SavedAllocation.X + (tmp - tab.SavedAllocation.X) * (1.0f - tab.SaveStrength));
                    }

                    drawCommands.Add(c => DrawTab(c, tab, Allocation, new Gdk.Rectangle(tmp, y, width, Allocation.Height), highlighted, false, false, CreateTabLayout(tab)));
                    tab.Allocation = new Gdk.Rectangle(tmp, Allocation.Y, width, Allocation.Height);
                }

                x += width;
            }

            Gdk.Rectangle allocation = Allocation;
            int           tabWidth;

            drawCommands.Add(DrawClosingTab(n, new Gdk.Rectangle(x, y, 0, allocation.Height), out tabWidth));
            drawCommands.Reverse();

            DrawBackground(ctx, allocation);

            // Draw breadcrumb bar header
            if (notebook.Tabs.Count > 0)
            {
                ctx.Rectangle(0, allocation.Height - BottomBarPadding, allocation.Width, BottomBarPadding);
                ctx.Color = Styles.BreadcrumbBackgroundColor;
                ctx.Fill();
            }

            ctx.Rectangle(tabStartX - LeanWidth / 2, allocation.Y, tabArea + LeanWidth, allocation.Height);
            ctx.Clip();

            foreach (var cmd in drawCommands)
            {
                cmd(ctx);
            }

            ctx.ResetClip();

            // Redraw the dragging tab here to be sure its on top. We drew it before to get the sizing correct, this should be fixed.
            drawActive(ctx);
        }
Пример #31
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

            Pango.Layout layout       = new Pango.Layout(PangoContext);
            TableRow     lastCategory = null;

            foreach (var r in rowList)
            {
                int w, h;
                layout.SetText(r.Label);
                layout.GetPixelSize(out w, out h);
                int indent = 0;

                if (r.IsCategory)
                {
                    var rh = h + CategoryTopBottomPadding * 2;
                    ctx.Rectangle(0, y, Allocation.Width, rh);
                    using (var gr = new LinearGradient(0, y, 0, rh)) {
                        gr.AddColorStop(0, new Cairo.Color(248d / 255d, 248d / 255d, 248d / 255d));
                        gr.AddColorStop(1, new Cairo.Color(240d / 255d, 240d / 255d, 240d / 255d));
                        ctx.SetSource(gr);
                        ctx.Fill();
                    }

                    if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand)
                    {
                        ctx.MoveTo(0, y + 0.5);
                        ctx.LineTo(Allocation.Width, y + 0.5);
                    }
                    ctx.MoveTo(0, y + rh - 0.5);
                    ctx.LineTo(Allocation.Width, y + rh - 0.5);
                    ctx.SetSourceColor(DividerColor);
                    ctx.Stroke();

                    ctx.MoveTo(x, y + CategoryTopBottomPadding);
                    ctx.SetSourceColor(CategoryLabelColor);
                    Pango.CairoHelper.ShowLayout(ctx, layout);

                    var img = r.Expanded ? discloseUp : discloseDown;
                    CairoHelper.SetSourcePixbuf(ctx, img, Allocation.Width - img.Width - CategoryTopBottomPadding, y + (rh - img.Height) / 2);
                    ctx.Paint();

                    y           += rh;
                    lastCategory = r;
                }
                else
                {
                    var cell = GetCell(r);
                    r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject;
                    var state = r.Enabled ? State : Gtk.StateType.Insensitive;
                    ctx.Save();
                    ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                    ctx.Clip();
                    ctx.MoveTo(x, y + PropertyTopBottomPadding);
                    ctx.SetSourceColor(Style.Text(state).ToCairoColor());
                    Pango.CairoHelper.ShowLayout(ctx, layout);
                    ctx.Restore();

                    if (r != currentEditorRow)
                    {
                        cell.Render(GdkWindow, ctx, r.EditorBounds, state);
                    }

                    y     += r.EditorBounds.Height;
                    indent = PropertyIndent;
                }

                if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand))
                {
                    int py = y;

                    ctx.Save();
                    if (r.AnimatingExpand)
                    {
                        ctx.Rectangle(0, y, Allocation.Width, r.AnimationHeight);
                    }
                    else
                    {
                        ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height);
                    }

                    ctx.Clip();
                    Draw(ctx, r.ChildRows, dividerX, x + indent, ref y);
                    ctx.Restore();

                    if (r.AnimatingExpand)
                    {
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceColor(LabelBackgroundColor);
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceRGB(1, 1, 1);
                        ctx.Fill();
                    }
                }
            }
        }
Пример #32
0
		public void xxx_clip_rectangle(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

			cr.NewPath();
			cr.MoveTo(.25, .25);
			cr.LineTo(.25, .75);
			cr.LineTo(.75, .75);
			cr.LineTo(.75, .25);
			cr.LineTo(.25, .25);
			cr.ClosePath();

			cr.Clip();

			cr.MoveTo(0, 0);
			cr.LineTo(1, 1);
			cr.Stroke();
		}
Пример #33
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (mouse_button <= 0) {
                last_point = point_empty;
                return;
            }

            DrawingArea drawingarea1 = (DrawingArea)o;

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

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

            if (PintaCore.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

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

                g.Antialias = Antialias.Subpixel;

                g.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.Operator = Operator.Clear;
                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;

                g.Stroke ();
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            PintaCore.Workspace.Invalidate (r);

            last_point = new Point (x, y);
        }
Пример #34
0
 public void Clip(Context g)
 {
     g.AppendPath (selection_path);
     g.FillRule = FillRule.EvenOdd;
     g.Clip ();
 }
Пример #35
0
		public void clip(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

			cr.Arc(0.5, 0.5, 0.3, 0, 2 * Math.PI);
			cr.Clip();

			cr.NewPath();  // current path is not consumed by cairo_clip()
			cr.Rectangle(0, 0, 1, 1);
			cr.Fill();
			cr.Color = new Color (0, 1, 0);
			cr.MoveTo(0, 0);
			cr.LineTo(1, 1);
			cr.MoveTo(1, 0);
			cr.LineTo(0, 1);
			cr.Stroke();
		}
Пример #36
0
        protected override void onDraw(Context gr)
        {
            Rectangle rBack = new Rectangle (Slot.Size);

            Background.SetAsSource (gr, rBack);
            CairoHelpers.CairoRectangle(gr,rBack, CornerRadius);
            gr.Fill ();

            gr.Save ();
            if (ClipToClientRect) {
                //clip to scrolled client zone
                CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
                gr.Clip ();
            }

            gr.Translate (-ScrollX, -ScrollY);
            if (child != null)
                child.Paint (ref gr);
            gr.Restore ();
        }
Пример #37
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Color tool_color;

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

            DrawingArea drawingarea1 = (DrawingArea)o;

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

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

            if (PintaCore.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

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

                g.Antialias = Antialias.None;

                g.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.Color = tool_color;
                g.LineWidth = 1;
                g.LineCap = LineCap.Square;

                g.Stroke ();
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            PintaCore.Workspace.Invalidate (r);

            last_point = new Point (x, y);
        }
Пример #38
0
        public static SurfacePattern CreateVisualBrush(VisualBrush brush, Size targetSize)
        {
            var visual = brush.Visual;

            if (visual == null)
            {
                return null;
            }

            var layoutable = visual as ILayoutable;

            if (layoutable?.IsArrangeValid == false)
            {
                layoutable.Measure(Size.Infinity);
                layoutable.Arrange(new Rect(layoutable.DesiredSize));
            }

            // TODO: This is directly ported from Direct2D and could probably be made more
            // efficient on cairo by taking advantage of the fact that cairo has Extend.None.
            var tileMode = brush.TileMode;
            var sourceRect = brush.SourceRect.ToPixels(layoutable.Bounds.Size);
            var destinationRect = brush.DestinationRect.ToPixels(targetSize);
            var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size);
            var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale);
            var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size);
            
			using (var intermediate = new ImageSurface(Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height))
            using (var context = new Context(intermediate))
            {
                Rect drawRect;
                var transform = CalculateIntermediateTransform(
                    tileMode,
                    sourceRect,
                    destinationRect,
                    scale,
                    translate,
                    out drawRect);
                var renderer = new Renderer(intermediate);

                context.Rectangle(drawRect.ToCairo());
                context.Clip();
                context.Transform(transform.ToCairo());
                renderer.Render(visual, new PlatformHandle(IntPtr.Zero, "RTB"), transform, drawRect);

                var result = new SurfacePattern(intermediate);

                if ((brush.TileMode & TileMode.FlipXY) != 0)
                {
                    // TODO: Currently always FlipXY as that's all cairo supports natively. 
                    // Support separate FlipX and FlipY by drawing flipped images to intermediate
                    // surface.
                    result.Extend = Extend.Reflect;
                }
                else
                {
                    result.Extend = Extend.Repeat;
                }

                if (brush.TileMode != TileMode.None)
                {
                    var matrix = result.Matrix;
                    matrix.InitTranslate(-destinationRect.X, -destinationRect.Y);
                    result.Matrix = matrix;
                }

                return result;
            }
        }
Пример #39
0
        void InternalDraw(int markerStart, int markerEnd, MonoTextEditor editor, Cairo.Context cr, LineMetrics metrics, bool selected, int startOffset, int endOffset, double y, double startXPos, double endXPos)
        {
            if (markerStart >= markerEnd)
            {
                return;
            }
            var    layout = metrics.Layout.Layout;
            double @from;
            double to;

            if (markerStart < startOffset && endOffset < markerEnd)
            {
                @from = startXPos;
                to    = endXPos;
            }
            else
            {
                int             start = Math.Max(startOffset, markerStart);
                int             end   = Math.Min(endOffset, markerEnd);
                int /*lineNr,*/ x_pos;
                uint            curIndex  = 0;
                uint            byteIndex = 0;

                var textLength = metrics.Layout.Text.Length;
                if (textLength > 0)
                {
                    uint idx = (uint)Math.Min(Math.Max(0, start - startOffset), textLength - 1);
                    metrics.Layout.TranslateToUTF8Index(idx, ref curIndex, ref byteIndex);

                    x_pos = layout.IndexToPos(System.Math.Max(0, (int)byteIndex)).X;
                    @from = startXPos + (int)(x_pos / Pango.Scale.PangoScale);

                    idx = (uint)Math.Min(Math.Max(0, end - startOffset), textLength - 1);
                    metrics.Layout.TranslateToUTF8Index(idx, ref curIndex, ref byteIndex);

                    x_pos = layout.IndexToPos(System.Math.Max(0, (int)byteIndex)).X;

                    to = startXPos + (int)(x_pos / Pango.Scale.PangoScale);
                }
                else
                {
                    @from = startXPos;
                    to    = startXPos + editor.TextViewMargin.CharWidth;
                }

                var line = editor.GetLineByOffset(endOffset);
                if (markerEnd > endOffset || @from == to)
                {
                    to += editor.TextViewMargin.CharWidth;
                    if (@from >= to)
                    {
                        @from = to - editor.TextViewMargin.CharWidth;
                    }
                }
            }
            @from = System.Math.Max(@from, editor.TextViewMargin.XOffset);
            to    = System.Math.Max(to, editor.TextViewMargin.XOffset);
            if (Length == 0)
            {
                to += editor.TextViewMargin.charWidth;
            }

            if (@from >= to)
            {
                return;
            }
            double height = editor.LineHeight / 5;

            if (string.IsNullOrEmpty(ColorName))
            {
                cr.SetSourceColor(Color);
            }
            else
            {
                HslColor color;
                editor.EditorTheme.TryGetColor(ColorName, out color);
                cr.SetSourceColor(color);
            }
            cr.LineWidth = editor.Options.Zoom;

            switch (Effect)
            {
            case MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.WavedLine:
                cr.Rectangle(@from, 0, to - @from, editor.Allocation.Height);
                cr.Clip();
                Pango.CairoHelper.ShowErrorUnderline(cr, metrics.TextRenderStartPosition, y + editor.LineHeight - height, editor.Allocation.Width, height);
                cr.ResetClip();
                break;

            case MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.DottedLine:
                cr.Save();
                cr.MoveTo(@from, y + editor.LineHeight - editor.Options.Zoom - 0.5);
                cr.LineTo(to, y + editor.LineHeight - editor.Options.Zoom - 0.5);
                cr.SetDash(new double [] { 2 * editor.Options.Zoom, 2 * editor.Options.Zoom }, 0);
                cr.Stroke();
                cr.Restore();
                break;

            case MonoDevelop.Ide.Editor.TextSegmentMarkerEffect.Underline:
                cr.MoveTo(@from, y + editor.LineHeight - editor.Options.Zoom - 0.5);
                cr.LineTo(to, y + editor.LineHeight - editor.Options.Zoom - 0.5);
                cr.Stroke();
                break;

            default:
                throw new InvalidOperationException("Invalid text segment marker effect " + Effect + " not supported by this marker.");
            }
        }
Пример #40
0
        private Surface CreateScene (Cairo.Context window_cr, ImageSurface image, int reflect)
        {
            Surface surface = window_cr.Target.CreateSimilar (window_cr.Target.Content,
                image.Width, image.Height + reflect);
            Cairo.Context cr = new Context (surface);

            cr.Save ();

            cr.SetSource (image);
            cr.Paint ();

            cr.Rectangle (0, image.Height, image.Width, reflect);
            cr.Clip ();

            Matrix matrix = new Matrix ();
            matrix.InitScale (1, -1);
            matrix.Translate (0, -(2 * image.Height) + 1);
            cr.Transform (matrix);

            cr.SetSource (image);
            cr.Paint ();

            cr.Restore ();

            Color bg_transparent = BackgroundColor;
            bg_transparent.A = 0.65;

            LinearGradient mask = new LinearGradient (0, image.Height, 0, image.Height + reflect);
            mask.AddColorStop (0, bg_transparent);
            mask.AddColorStop (1, BackgroundColor);

            cr.Rectangle (0, image.Height, image.Width, reflect);
            cr.Pattern = mask;
            cr.Fill ();

            ((IDisposable)cr).Dispose ();
            return surface;
        }
Пример #41
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            origin_offset = point;
            is_dragging = true;

            hist = new MovePixelsHistoryItem (Icon, Name);
            hist.TakeSnapshot ();

            if (!PintaCore.Layers.ShowSelectionLayer) {
                // Copy the selection to the temp layer
                PintaCore.Layers.CreateSelectionLayer ();
                PintaCore.Layers.ShowSelectionLayer = true;

                using (Cairo.Context g = new Cairo.Context (PintaCore.Layers.SelectionLayer.Surface)) {
                    g.AppendPath (PintaCore.Layers.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource (PintaCore.Layers.CurrentLayer.Surface);
                    g.Clip ();
                    g.Paint ();
                }

                Cairo.ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

                using (Cairo.Context g = new Cairo.Context (surf)) {
                    g.AppendPath (PintaCore.Layers.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Operator = Cairo.Operator.Clear;
                    g.Fill ();
                }
            }

            canvas.GdkWindow.Invalidate ();
        }
Пример #42
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            // If we are already drawing, ignore any additional mouse down events
            if (is_dragging)
                return;

            Document doc = PintaCore.Workspace.ActiveDocument;

            origin_offset = point;
            is_dragging = true;

            hist = new MovePixelsHistoryItem (Icon, Name, doc);
            hist.TakeSnapshot (!doc.ShowSelectionLayer);

            if (!doc.ShowSelectionLayer) {
                // Copy the selection to the temp layer
                doc.CreateSelectionLayer ();
                doc.ShowSelectionLayer = true;

                using (Cairo.Context g = new Cairo.Context (doc.SelectionLayer.Surface)) {
                    g.AppendPath (doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource (doc.CurrentLayer.Surface);
                    g.Clip ();
                    g.Paint ();
                }

                Cairo.ImageSurface surf = doc.CurrentLayer.Surface;

                using (Cairo.Context g = new Cairo.Context (surf)) {
                    g.AppendPath (doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Operator = Cairo.Operator.Clear;
                    g.Fill ();
                }
            }

            canvas.GdkWindow.Invalidate ();
        }
Пример #43
0
        protected unsafe override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            ColorBgra old_color;
            ColorBgra new_color;

            if (mouse_button == 1) {
                old_color = PintaCore.Palette.PrimaryColor.ToColorBgra ();
                new_color = PintaCore.Palette.SecondaryColor.ToColorBgra ();
            } else if (mouse_button == 3) {
                old_color = PintaCore.Palette.SecondaryColor.ToColorBgra ();
                new_color = PintaCore.Palette.PrimaryColor.ToColorBgra ();
            } 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);

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

            ImageSurface surf = doc.CurrentLayer.Surface;
            ImageSurface tmp_layer = doc.ToolLayer.Surface;

            Gdk.Rectangle roi = GetRectangleFromPoints (last_point, new Point (x, y));

            roi = PintaCore.Workspace.ClampToImageSize (roi);
            myTolerance = (int)(Tolerance * 256);

            tmp_layer.Flush ();

            ColorBgra* tmp_data_ptr = (ColorBgra*)tmp_layer.DataPtr;
            int tmp_width = tmp_layer.Width;
            ColorBgra* surf_data_ptr = (ColorBgra*)surf.DataPtr;
            int surf_width = surf.Width;

            // The stencil lets us know if we've already checked this
            // pixel, providing a nice perf boost
            // Maybe this should be changed to a BitVector2DSurfaceAdapter?
            for (int i = roi.X; i <= roi.GetRight (); i++)
                for (int j = roi.Y; j <= roi.GetBottom (); j++) {
                    if (stencil[i, j])
                        continue;

                    if (IsColorInTolerance (new_color, surf.GetColorBgra (surf_data_ptr, surf_width, i, j)))
                        *tmp_layer.GetPointAddressUnchecked (tmp_data_ptr, tmp_width, i, j) = AdjustColorDifference (new_color, old_color, surf.GetColorBgra (surf_data_ptr, surf_width, i, j));

                    stencil[i, j] = true;
                }

            tmp_layer.MarkDirty ();

            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.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;

                g.SetSource (tmp_layer);

                g.Stroke ();
            }

            doc.Workspace.Invalidate (roi);

            last_point = new Point (x, y);
        }
Пример #44
0
        public unsafe void HueSaturation(int hueDelta, int satDelta, int lightness)
        {
            ImageSurface dest = Surface.Clone ();
            ColorBgra* dstPtr = (ColorBgra*)dest.DataPtr;

            int len = Surface.Data.Length / 4;

            // map the range [0,100] -> [0,100] and the range [101,200] -> [103,400]
            if (satDelta > 100)
                satDelta = ((satDelta - 100) * 3) + 100;

            UnaryPixelOp op;

            if (hueDelta == 0 && satDelta == 100 && lightness == 0)
                op = new UnaryPixelOps.Identity ();
            else
                op = new UnaryPixelOps.HueSaturationLightness (hueDelta, satDelta, lightness);

            op.Apply (dstPtr, len);

            using (Context g = new Context (Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.SetSource (dest);
                g.Paint ();
            }

            (dest as IDisposable).Dispose ();
        }
Пример #45
0
        public void Crop(Gdk.Rectangle rect, Path path)
        {
            ImageSurface dest = new ImageSurface (Format.Argb32, rect.Width, rect.Height);

            using (Context g = new Context (dest)) {
                // Move the selected content to the upper left
                g.Translate (-rect.X, -rect.Y);
                g.Antialias = Antialias.None;

                // Respect the selected path
                g.AppendPath (path);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();

                g.SetSource (Surface);
                g.Paint ();
            }

            (Surface as IDisposable).Dispose ();
            Surface = dest;
        }
Пример #46
0
		void Draw (Context ctx)
		{
			int tabArea = tabEndX - tabStartX;
			int x = GetRenderOffset ();
			const int y = 0;
			int n = 0;
			Action<Context> drawActive = c => {
			};
			var drawCommands = new List<Action<Context>> ();
			for (; n < notebook.Tabs.Count; n++) {
				if (x + TabWidth < tabStartX) {
					x += TabWidth;
					continue;
				}

				if (x > tabEndX)
					break;

				int closingWidth;
				var cmd = DrawClosingTab (n, new Gdk.Rectangle (x, y, 0, Allocation.Height), out closingWidth);
				drawCommands.Add (cmd);
				x += closingWidth;

				var tab = (DockNotebookTab)notebook.Tabs [n];
				bool active = tab == notebook.CurrentTab;

				int width = Math.Min (TabWidth, Math.Max (50, tabEndX - x - 1));
				if (tab == notebook.Tabs.Last ())
					width += LastTabWidthAdjustment;
				width = (int)(width * tab.WidthModifier);

				if (active) {
					int tmp = x;
					drawActive = c => DrawTab (c, tab, Allocation, new Gdk.Rectangle (tmp, y, width, Allocation.Height), true, true, draggingTab, CreateTabLayout (tab));
					tab.Allocation = new Gdk.Rectangle (tmp, Allocation.Y, width, Allocation.Height);
				} else {
					int tmp = x;
					bool highlighted = tab == highlightedTab;

					if (tab.SaveStrength > 0.0f) {
						tmp = (int)(tab.SavedAllocation.X + (tmp - tab.SavedAllocation.X) * (1.0f - tab.SaveStrength));
					}

					drawCommands.Add (c => DrawTab (c, tab, Allocation, new Gdk.Rectangle (tmp, y, width, Allocation.Height), highlighted, false, false, CreateTabLayout (tab)));
					tab.Allocation = new Gdk.Rectangle (tmp, Allocation.Y, width, Allocation.Height);
				}

				x += width;
			}

			var allocation = Allocation;
			int tabWidth;
			drawCommands.Add (DrawClosingTab (n, new Gdk.Rectangle (x, y, 0, allocation.Height), out tabWidth));
			drawCommands.Reverse ();

			DrawBackground (ctx, allocation);

			// Draw breadcrumb bar header
			if (notebook.Tabs.Count > 0) {
				ctx.Rectangle (0, allocation.Height - BottomBarPadding, allocation.Width, BottomBarPadding);
				ctx.SetSourceColor (Styles.BreadcrumbBackgroundColor);
				ctx.Fill ();
			}

			ctx.Rectangle (tabStartX - LeanWidth / 2, allocation.Y, tabArea + LeanWidth, allocation.Height);
			ctx.Clip ();

			foreach (var cmd in drawCommands)
				cmd (ctx);

			ctx.ResetClip ();

			// Redraw the dragging tab here to be sure its on top. We drew it before to get the sizing correct, this should be fixed.
			drawActive (ctx);
		}
Пример #47
0
        private void DrawChannel(Context g, ColorBgra color, int channel, long max, float mean)
        {
            Rectangle rect = Allocation.ToCairoRectangle ();
            Histogram histogram = Histogram;

            int l = (int)rect.X;
            int t = (int)rect.Y;
            int r = (int)(rect.X + rect.Width);
            int b = (int)(rect.Y + rect.Height);

            int entries = histogram.Entries;
            long[] hist = histogram.HistogramValues [channel];

            ++max;

            if (FlipHorizontal) {
                Utility.Swap(ref l, ref r);
            }

            if (!FlipVertical) {
                Utility.Swap(ref t, ref b);
            }

            PointD[] points = new PointD[entries + 2];

            points[entries] = new PointD (Utility.Lerp (l, r, -1), Utility.Lerp (t, b, 20));
            points[entries + 1] = new PointD (Utility.Lerp (l, r, -1), Utility.Lerp (b, t, 20));

            for (int i = 0; i < entries; i += entries - 1) {
                points[i] = new PointD (
                    Utility.Lerp (l, r, (float)hist[i] / (float)max),
                    Utility.Lerp (t, b, (float)i / (float)entries));

                CheckPoint (rect, points [i]);
            }

            long sum3 = hist[0] + hist[1];

            for (int i = 1; i < entries - 1; ++i) {
                sum3 += hist[i + 1];

                points[i] = new PointD(
                    Utility.Lerp(l, r, (float)(sum3) / (float)(max * 3.1f)),
                    Utility.Lerp(t, b, (float)i / (float)entries));

                CheckPoint (rect, points [i]);
                sum3 -= hist[i - 1];
            }

            byte intensity = selected[channel] ? (byte)96 : (byte)32;
            ColorBgra pen_color = ColorBgra.Blend (ColorBgra.Black, color, intensity);
            ColorBgra brush_color = color;
               	brush_color.A = intensity;

            g.LineWidth = 1;

            g.Rectangle (rect);
            g.Clip ();
            g.DrawPolygonal (points, pen_color.ToCairoColor ());
            g.FillPolygonal (points, brush_color.ToCairoColor ());
        }
Пример #48
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (mouse_button == 1) {
                StrokeColor = PintaCore.Palette.PrimaryColor;
                FillColor = PintaCore.Palette.SecondaryColor;
            } else if (mouse_button == 3) {
                StrokeColor = PintaCore.Palette.SecondaryColor;
                FillColor = PintaCore.Palette.PrimaryColor;
            } else {
                LastPoint = point_empty;
                return;
            }

            // TODO: also multiply by pressure
            StrokeColor = new Color (StrokeColor.R, StrokeColor.G, StrokeColor.B,
                StrokeColor.A * active_brush.StrokeAlphaMultiplier);

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

            if (LastPoint.Equals (point_empty))
                LastPoint = new Point (x, y);

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

            var surf = doc.CurrentUserLayer.Surface;
            var invalidate_rect = Gdk.Rectangle.Zero;
            var brush_width = BrushWidth;

            Surface = surf;

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

                Drawable.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;
                Drawable.LineWidth = brush_width;
                Drawable.LineJoin = LineJoin.Round;
                Drawable.LineCap = BrushWidth == 1 ? LineCap.Butt : LineCap.Round;
                Drawable.Color = StrokeColor;

                invalidate_rect = active_brush.DoMouseMove (Drawable, StrokeColor, Surface,
                                                            x, y, LastPoint.X, LastPoint.Y);
            }

            Surface = null;
            Drawable = null;

            // If we draw partially offscreen, Cairo gives us a bogus
            // dirty rectangle, so redraw everything.
            if (doc.Workspace.IsPartiallyOffscreen (invalidate_rect)) {
                doc.Workspace.Invalidate ();
            } else {
                doc.Workspace.Invalidate (doc.ClampToImageSize (invalidate_rect));
            }

            LastPoint = new Point (x, y);
        }
Пример #49
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (!CairoHelper.ShouldDrawWindow(cr, Window))
            {
                return(base.OnDrawn(cr));
            }

            if (reflect)
            {
                cr.PushGroup();
            }

            cr.Operator = Operator.Over;
            cr.Translate(h_padding, 0);
            cr.Rectangle(0, 0, Allocation.Width - h_padding, Math.Max(2 * bar_height,
                                                                      bar_height + bar_label_spacing + layout_height));
            cr.Clip();

            using (var bar = RenderBar(Allocation.Width - 2 * h_padding, bar_height)) {
                cr.Save();
                cr.SetSource(bar);
                cr.Paint();
                cr.Restore();

                if (reflect)
                {
                    cr.Save();

                    cr.Rectangle(0, bar_height, Allocation.Width - h_padding, bar_height);
                    cr.Clip();

                    Matrix matrix = new Matrix();
                    matrix.InitScale(1, -1);
                    matrix.Translate(0, -(2 * bar_height) + 1);
                    cr.Transform(matrix);

                    cr.SetSource(bar);

                    using (var mask = new LinearGradient(0, 0, 0, bar_height)) {
                        mask.AddColorStop(0.25, new Color(0, 0, 0, 0));
                        mask.AddColorStop(0.5, new Color(0, 0, 0, 0.125));
                        mask.AddColorStop(0.75, new Color(0, 0, 0, 0.4));
                        mask.AddColorStop(1.0, new Color(0, 0, 0, 0.7));

                        cr.Mask(mask);
                    }

                    cr.Restore();

                    cr.PopGroupToSource();
                    cr.Paint();
                }

                if (show_labels)
                {
                    cr.Translate((reflect ? 0 : -h_padding) + (Allocation.Width - layout_width) / 2,
                                 bar_height + bar_label_spacing);
                    RenderLabels(cr);
                }
            }

            return(true);
        }
Пример #50
0
        void Draw(Cairo.Context ctx, List <TableRow> rowList, int dividerX, int x, ref int y)
        {
            if (!heightMeasured)
            {
                return;
            }

            Pango.Layout layout       = new Pango.Layout(PangoContext);
            TableRow     lastCategory = null;

            foreach (var r in rowList)
            {
                int w, h;
                layout.SetText(r.Label);
                layout.GetPixelSize(out w, out h);
                int indent = 0;

                if (r.IsCategory)
                {
                    var rh = h + CategoryTopBottomPadding * 2;
                    ctx.Rectangle(0, y, Allocation.Width, rh);
                    ctx.SetSourceColor(Styles.PadCategoryBackgroundColor.ToCairoColor());
                    ctx.Fill();

                    if (IsFocus && r.Focused)
                    {
                        ctx.Rectangle(1, y + 1, Allocation.Width - 2, rh - 3);
                        ctx.SetDash(new double[] { 1, 1 }, 0.5);
                        ctx.LineWidth = 1.0;
                        ctx.SetSourceColor(Styles.BaseForegroundColor.ToCairoColor());
                        ctx.Stroke();
                    }

                    if (lastCategory == null || lastCategory.Expanded || lastCategory.AnimatingExpand)
                    {
                        ctx.MoveTo(0, y + 0.5);
                        ctx.LineTo(Allocation.Width, y + 0.5);
                    }
                    ctx.MoveTo(0, y + rh - 0.5);
                    ctx.LineTo(Allocation.Width, y + rh - 0.5);
                    ctx.SetSourceColor(Styles.PadCategoryBorderColor.ToCairoColor());
                    ctx.Stroke();

                    ctx.MoveTo(x, y + CategoryTopBottomPadding);
                    ctx.SetSourceColor(Styles.PadCategoryLabelColor.ToCairoColor());
                    Pango.CairoHelper.ShowLayout(ctx, layout);

                    var img = r.Expanded ? discloseUp : discloseDown;
                    ctx.DrawImage(this, img, Allocation.Width - img.Width - CategoryTopBottomPadding, y + Math.Round((rh - img.Height) / 2));

                    y           += rh;
                    lastCategory = r;
                }
                else
                {
                    var cell = GetCell(r);
                    r.Enabled = !r.Property.IsReadOnly || cell.EditsReadOnlyObject;
                    var state = r.Enabled ? State : Gtk.StateType.Insensitive;
                    ctx.Save();
                    ctx.Rectangle(0, y, dividerX, h + PropertyTopBottomPadding * 2);
                    ctx.Clip();
                    ctx.MoveTo(x, y + PropertyTopBottomPadding);
                    ctx.SetSourceColor(Style.Text(state).ToCairoColor());
                    Pango.CairoHelper.ShowLayout(ctx, layout);
                    ctx.Restore();

                    if (r != currentEditorRow)
                    {
                        var bounds = GetInactiveEditorBounds(r);

                        cell.Render(GdkWindow, ctx, bounds, state);

                        if (r.IsExpandable)
                        {
                            var img = r.Expanded ? discloseUp : discloseDown;
                            ctx.DrawImage(
                                this, img,
                                Allocation.Width - img.Width - PropertyTopBottomPadding,
                                y + Math.Round((h + PropertyTopBottomPadding * 2 - img.Height) / 2)
                                );
                        }
                    }

                    y     += r.EditorBounds.Height;
                    indent = PropertyIndent;
                }

                if (r.ChildRows != null && r.ChildRows.Count > 0 && (r.Expanded || r.AnimatingExpand))
                {
                    int py = y;

                    ctx.Save();
                    if (r.AnimatingExpand)
                    {
                        ctx.Rectangle(0, y, Allocation.Width, r.AnimationHeight);
                    }
                    else
                    {
                        ctx.Rectangle(0, 0, Allocation.Width, Allocation.Height);
                    }

                    ctx.Clip();
                    Draw(ctx, r.ChildRows, dividerX, x + indent, ref y);
                    ctx.Restore();

                    if (r.AnimatingExpand)
                    {
                        y = py + r.AnimationHeight;
                        // Repaing the background because the cairo clip doesn't work for gdk primitives
                        int dx = (int)((double)Allocation.Width * dividerPosition);
                        ctx.Rectangle(0, y, dx, Allocation.Height - y);
                        ctx.SetSourceColor(Styles.PropertyPadLabelBackgroundColor.ToCairoColor());
                        ctx.Fill();
                        ctx.Rectangle(dx + 1, y, Allocation.Width - dx - 1, Allocation.Height - y);
                        ctx.SetSourceColor(Styles.BrowserPadBackground.ToCairoColor());
                        ctx.Fill();
                    }
                }
            }
            layout.Dispose();
        }
Пример #51
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <param name="text">The text.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="rotate">The rotation angle.</param>
        /// <param name="halign">The horizontal alignment.</param>
        /// <param name="valign">The vertical alignment.</param>
        /// <param name="maxSize">The maximum size of the text.</param>
        public override void DrawText(
            ScreenPoint p,
            string text,
            OxyColor fill,
            string fontFamily,
            double fontSize,
            double fontWeight,
            double rotate,
            HorizontalAlignment halign,
            VerticalAlignment valign,
            OxySize?maxSize)
        {
            Pango.Layout          layout = Pango.CairoHelper.CreateLayout(this.g);
            Pango.FontDescription font   = new Pango.FontDescription();
            font.Family            = fontFamily;
            font.Weight            = (fontWeight >= 700) ? Pango.Weight.Bold : Pango.Weight.Normal;
            font.AbsoluteSize      = (int)(fontSize * Pango.Scale.PangoScale);
            layout.FontDescription = font;
            layout.SetText(text);
            Pango.Rectangle inkRect;
            Pango.Rectangle size;
            layout.GetExtents(out inkRect, out size);
            size.Width  /= (int)Pango.Scale.PangoScale;
            size.Height /= (int)Pango.Scale.PangoScale;
            if (maxSize != null)
            {
                int maxWidth  = (int)Math.Min((Double)Int32.MaxValue, maxSize.Value.Width);
                int maxHeight = (int)Math.Min((Double)Int32.MaxValue, maxSize.Value.Height);
                size.Width  = Math.Min(size.Width, maxWidth);
                size.Height = Math.Min(size.Height, maxHeight);
            }
            this.g.Save();
            double dx = 0;

            if (halign == HorizontalAlignment.Center)
            {
                dx = -size.Width / 2;
            }

            if (halign == HorizontalAlignment.Right)
            {
                dx = -size.Width;
            }

            double dy = 0;

            if (valign == VerticalAlignment.Middle)
            {
                dy = -size.Height / 2;
            }

            if (valign == VerticalAlignment.Bottom)
            {
                dy = -size.Height;
            }

            this.g.Translate(p.X, p.Y);
            if (Math.Abs(rotate) > double.Epsilon)
            {
                this.g.Rotate(rotate * Math.PI / 180.0);
            }

            this.g.Translate(dx, dy);

            g.Rectangle(0, 0, size.Width + 0.1f, size.Height + 0.1f);
            g.Clip();
            this.g.SetSourceColor(fill);
            Pango.CairoHelper.ShowLayout(this.g, layout);
            this.g.Restore();
        }
 void ClipProgressBar(Cairo.Context context, Gdk.Rectangle bounding)
 {
     LayoutRoundedRectangle(context, bounding);
     context.Clip();
 }
Пример #53
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            base.OnMouseMove (o, args, point);
            if (tracking) {

                UserBlendOps.NormalBlendOp normalBlendOp = new UserBlendOps.NormalBlendOp();
                GradientRenderer gr = null;
                switch (GradientType) {
                    case eGradientType.Linear:
                        gr = new GradientRenderers.LinearClamped (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                    case eGradientType.LinearReflected:
                        gr = new GradientRenderers.LinearReflected (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                    case eGradientType.Radial:
                        gr = new GradientRenderers.Radial (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                    case eGradientType.Diamond:
                        gr = new GradientRenderers.LinearDiamond (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                    case eGradientType.Conical:
                        gr = new GradientRenderers.Conical (GradientColorMode  == GradientColorMode.Transparency, normalBlendOp);
                    break;
                }
                if (button == 3) {//right
                    gr.StartColor = PintaCore.Palette.SecondaryColor.ToColorBgra ();
                    gr.EndColor = PintaCore.Palette.PrimaryColor.ToColorBgra ();
                }
                else {//1 left
                    gr.StartColor = PintaCore.Palette.PrimaryColor.ToColorBgra ();
                    gr.EndColor = PintaCore.Palette.SecondaryColor.ToColorBgra ();
                }

                gr.StartPoint = startpoint;
                gr.EndPoint = point;
                gr.AlphaBlending = UseAlphaBlending;

                gr.BeforeRender ();

                Gdk.Rectangle selection_bounds = PintaCore.Layers.SelectionPath.GetBounds ();
                ImageSurface scratch_layer = PintaCore.Layers.ToolLayer.Surface;

                gr.Render (scratch_layer, new Gdk.Rectangle[] { selection_bounds });

                using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                    g.AppendPath (PintaCore.Layers.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Clip ();

                    g.SetSource (scratch_layer);
                    g.Paint ();
                }

                selection_bounds.Inflate (5, 5);
                PintaCore.Workspace.Invalidate (selection_bounds);
            }
        }
        public void Render(Cairo.Context context, StatusArea.RenderArg arg, Gtk.Widget widget)
        {
            context.CachedDraw(surface: ref backgroundSurface,
                               region: arg.Allocation,
                               draw: (c, o) => DrawBackground(c, new Gdk.Rectangle(0, 0, arg.Allocation.Width, arg.Allocation.Height)));

            if (arg.BuildAnimationOpacity > 0.001f)
            {
                DrawBuildEffect(context, arg.Allocation, arg.BuildAnimationProgress, arg.BuildAnimationOpacity);
            }

            if (arg.ErrorAnimationProgress > 0.001 && arg.ErrorAnimationProgress < .999)
            {
                DrawErrorAnimation(context, arg);
            }

            DrawBorder(context, arg.Allocation);

            if (arg.HoverProgress > 0.001f)
            {
                context.Clip();
                int x1 = arg.Allocation.X + arg.MousePosition.X - 200;
                int x2 = x1 + 400;
                using (Cairo.LinearGradient gradient = new LinearGradient(x1, 0, x2, 0))
                {
                    Cairo.Color targetColor      = Styles.StatusBarFill1Color;
                    Cairo.Color transparentColor = targetColor;
                    targetColor.A      = .7;
                    transparentColor.A = 0;

                    targetColor.A = .7 * arg.HoverProgress;

                    gradient.AddColorStop(0.0, transparentColor);
                    gradient.AddColorStop(0.5, targetColor);
                    gradient.AddColorStop(1.0, transparentColor);

                    context.SetSource(gradient);

                    context.Rectangle(x1, arg.Allocation.Y, x2 - x1, arg.Allocation.Height);
                    context.Fill();
                }
                context.ResetClip();
            }
            else
            {
                context.NewPath();
            }

            int progress_bar_x     = arg.ChildAllocation.X;
            int progress_bar_width = arg.ChildAllocation.Width;

            if (arg.CurrentPixbuf != null)
            {
                int y = arg.Allocation.Y + (arg.Allocation.Height - (int)arg.CurrentPixbuf.Size.Height) / 2;
                context.DrawImage(widget, arg.CurrentPixbuf, arg.ChildAllocation.X, y);
                progress_bar_x     += (int)arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
                progress_bar_width -= (int)arg.CurrentPixbuf.Width + Styles.ProgressBarOuterPadding;
            }

            int center = arg.Allocation.Y + arg.Allocation.Height / 2;

            Gdk.Rectangle progressArea = new Gdk.Rectangle(progress_bar_x, center - Styles.ProgressBarHeight / 2, progress_bar_width, Styles.ProgressBarHeight);
            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                DrawProgressBar(context, arg.ProgressBarFraction, progressArea, arg);
                ClipProgressBar(context, progressArea);
            }

            int text_x     = progress_bar_x + Styles.ProgressBarInnerPadding;
            int text_width = progress_bar_width - (Styles.ProgressBarInnerPadding * 2);

            double textTweenValue = arg.TextAnimationProgress;

            if (arg.LastText != null)
            {
                double opacity = Math.Max(0.0f, 1.0f - textTweenValue);
                DrawString(arg.LastText, arg.LastTextIsMarkup, context, text_x,
                           center - (int)(textTweenValue * arg.Allocation.Height * 0.3), text_width, opacity, arg.Pango, arg);
            }

            if (arg.CurrentText != null)
            {
                DrawString(arg.CurrentText, arg.CurrentTextIsMarkup, context, text_x,
                           center + (int)((1.0f - textTweenValue) * arg.Allocation.Height * 0.3), text_width, Math.Min(textTweenValue, 1.0), arg.Pango, arg);
            }

            if (arg.ShowProgressBar || arg.ProgressBarAlpha > 0)
            {
                context.ResetClip();
            }
        }
Пример #55
0
        protected override bool OnExposeEvent(Gdk.EventExpose evnt)
        {
            if (evnt.Window != GdkWindow)
            {
                return(base.OnExposeEvent(evnt));
            }

            Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window);

            if (reflect)
            {
                CairoExtensions.PushGroup(cr);
            }

            cr.Operator = Operator.Over;
            cr.Translate(Allocation.X + h_padding, Allocation.Y);
            cr.Rectangle(0, 0, Allocation.Width - h_padding, Math.Max(2 * bar_height,
                                                                      bar_height + bar_label_spacing + layout_height));
            cr.Clip();

            Pattern bar = RenderBar(Allocation.Width - 2 * h_padding, bar_height);

            cr.Save();
            cr.SetSource(bar);
            cr.Paint();
            cr.Restore();

            if (reflect)
            {
                cr.Save();

                cr.Rectangle(0, bar_height, Allocation.Width - h_padding, bar_height);
                cr.Clip();

                var matrix = new Matrix();
                matrix.InitScale(1, -1);
                matrix.Translate(0, -(2 * bar_height) + 1);
                cr.Transform(matrix);

                cr.SetSource(bar);

                var mask = new LinearGradient(0, 0, 0, bar_height);

                mask.AddColorStop(0.25, new Color(0, 0, 0, 0));
                mask.AddColorStop(0.5, new Color(0, 0, 0, 0.125));
                mask.AddColorStop(0.75, new Color(0, 0, 0, 0.4));
                mask.AddColorStop(1.0, new Color(0, 0, 0, 0.7));

                cr.Mask(mask);
                mask.Dispose();

                cr.Restore();

                CairoExtensions.PopGroupToSource(cr);
                cr.Paint();
            }

            if (show_labels)
            {
                cr.Translate((reflect ? Allocation.X : -h_padding) + (Allocation.Width - layout_width) / 2,
                             (reflect ? Allocation.Y : 0) + bar_height + bar_label_spacing);

                RenderLabels(cr);
            }

            bar.Dispose();
            CairoExtensions.DisposeContext(cr);

            return(true);
        }
Пример #56
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            if (mouse_button == 1) {
                StrokeColor = PintaCore.Palette.PrimaryColor;
                FillColor = PintaCore.Palette.SecondaryColor;
            } else if (mouse_button == 3) {
                StrokeColor = PintaCore.Palette.SecondaryColor;
                FillColor = PintaCore.Palette.PrimaryColor;
            } else {
                LastPoint = point_empty;
                return;
            }

            // TODO: also multiply by pressure
            StrokeColor = new Color (StrokeColor.R, StrokeColor.G, StrokeColor.B,
                StrokeColor.A * active_brush.StrokeAlphaMultiplier);

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

            if (LastPoint.Equals (point_empty))
                LastPoint = new Point (x, y);

            if (PintaCore.Workspace.PointInCanvas (point))
                surface_modified = true;

            var surf = PintaCore.Layers.CurrentLayer.Surface;
            var invalidate_rect = Gdk.Rectangle.Zero;
            var brush_width = BrushWidth;

            using (Drawable = new Context (surf)) {
                Drawable.AppendPath (PintaCore.Workspace.ActiveDocument.SelectionPath);
                Drawable.FillRule = FillRule.EvenOdd;
                Drawable.Clip ();

                Drawable.Antialias = Antialias.Subpixel;
                Drawable.LineWidth = brush_width;
                Drawable.LineJoin = LineJoin.Round;
                Drawable.LineCap = BrushWidth == 1 ? LineCap.Butt : LineCap.Round;
                Drawable.Color = StrokeColor;

                Drawable.Translate (brush_width / 2.0, brush_width / 2.0);

                active_brush.Tool = this;
                invalidate_rect = active_brush.DoMouseMove (x, y, LastPoint.X, LastPoint.Y);
                active_brush.Tool = null;
            }

            Drawable = null;

            if (invalidate_rect.IsEmpty) {
                PintaCore.Workspace.Invalidate ();
            } else {
                PintaCore.Workspace.Invalidate (invalidate_rect);
            }

            LastPoint = new Point (x, y);
        }
        private void Draw(DrawingArea drawingarea1, Color tool_color, Cairo.PointD point, bool first_pixel)
        {
            int x = (int)point.X;
            int y = (int) point.Y;

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

                if (!first_pixel)
                    return;
            }

            Document doc = PintaCore.Workspace.ActiveDocument;

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

            ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

            if (first_pixel) {
                // Does Cairo really not support a single-pixel-long single-pixel-wide line?
                surf.Flush ();
                int shiftedX = (int)point.X;
                int shiftedY = (int)point.Y;
                ColorBgra source = surf.GetColorBgraUnchecked (shiftedX, shiftedY);
                source = UserBlendOps.NormalBlendOp.ApplyStatic (source, tool_color.ToColorBgra ());
                surf.SetColorBgra (source, shiftedX, shiftedY);
                surf.MarkDirty ();
            } else {
                using (Context g = new Context (surf)) {
                    g.AppendPath (doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Clip ();

                    g.Antialias = Antialias.None;

                    // Adding 0.5 forces cairo into the correct square:
                    // See https://bugs.launchpad.net/bugs/672232
                    g.MoveTo (last_point.X + 0.5, last_point.Y + 0.5);
                    g.LineTo (x + 0.5, y + 0.5);

                    g.Color = tool_color;
                    g.LineWidth = 1;
                    g.LineCap = LineCap.Square;

                    g.Stroke ();
                }
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            doc.Workspace.Invalidate (r);

            last_point = new Point (x, y);
        }
Пример #58
0
        protected override void OnStartTransform()
        {
            base.OnStartTransform ();

            Document doc = PintaCore.Workspace.ActiveDocument;
            original_selection = new List<List<IntPoint>> (doc.Selection.SelectionPolygons);
            original_transform.InitMatrix (doc.SelectionLayer.Transform);

            hist = new MovePixelsHistoryItem (Icon, Name, doc);
            hist.TakeSnapshot (!doc.ShowSelectionLayer);

            if (!doc.ShowSelectionLayer) {
                // Copy the selection to the temp layer
                doc.CreateSelectionLayer ();
                doc.ShowSelectionLayer = true;

                using (Cairo.Context g = new Cairo.Context (doc.SelectionLayer.Surface)) {
                    g.AppendPath (doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.SetSource (doc.CurrentUserLayer.Surface);
                    g.Clip ();
                    g.Paint ();
                }

                Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface;

                using (Cairo.Context g = new Cairo.Context (surf)) {
                    g.AppendPath (doc.Selection.SelectionPath);
                    g.FillRule = FillRule.EvenOdd;
                    g.Operator = Cairo.Operator.Clear;
                    g.Fill ();
                }
            }

            PintaCore.Workspace.Invalidate ();
        }
Пример #59
0
        protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            if (mouse_button <= 0) {
                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);

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

            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;

                // Adding 0.5 forces cairo into the correct square:
                // See https://bugs.launchpad.net/bugs/672232
                g.MoveTo (last_point.X + 0.5, last_point.Y + 0.5);
                g.LineTo (x + 0.5, y + 0.5);

                // Right-click is erase to background color, left-click is transparent
                if (mouse_button == 3)
                    g.SetSourceRGBA(PintaCore.Palette.SecondaryColor);
                else
                    g.Operator = Operator.Clear;

                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;

                g.Stroke ();
            }

            Gdk.Rectangle r = GetRectangleFromPoints (last_point, new Point (x, y));

            if (doc.Workspace.IsPartiallyOffscreen (r)) {
                doc.Workspace.Invalidate ();
            } else {
                doc.Workspace.Invalidate (doc.ClampToImageSize (r));
            }

            last_point = new Point (x, y);
        }
Пример #60
0
        private void RenderNodeGroup(NodeGroup ng, Network network, Cairo.Context gc)
        {
            gc.Save();

            SizeD size = CalculateNodeGroupSize(ng, gc);

            ng.Dimension = size;
            CreateRoundedRectPath(gc, ng.Position.X, ng.Position.Y, size.Width, size.Height, 20);
            gc.Color = new Cairo.Color(0, 0, 0, 0.5);
            gc.FillPreserve();

            if (selectedGroup == ng)
            {
                gc.Save();
                gc.Color = orangeOverlay;
                gc.StrokePreserve();
                gc.Restore();
            }

            var titleTextSize = CalculateNodeGroupTitleTextSize(ng, gc);
            var titleSize     = new SizeD(size.Width, titleTextSize.Height + (Padding * 2.0));

            gc.Clip();
            gc.Rectangle(ng.Position.X, ng.Position.Y, titleSize.Width, titleSize.Height);
            gc.Fill();
            gc.ResetClip();

            gc.Color = lightGray;

            double hostTextX = ng.Position.X + (titleSize.Width / 2.0) - (titleTextSize.Width / 2.0);
            double hostTextY = ng.Position.Y + (titleSize.Height / 2.0) - (titleTextSize.Height / 2.0);

            gc.MoveTo(hostTextX, hostTextY /* + titleTextSize.Height */);

            Pango.Layout layout = new Pango.Layout(this.PangoContext);
            layout.FontDescription      = this.PangoContext.FontDescription.Copy();
            layout.FontDescription.Size = Pango.Units.FromDouble(NodegroupNameFontSize);
            layout.SetText(ng.Name);
            Pango.CairoHelper.ShowLayout(gc, layout);

            SizeD nodesSize = CalculateNodeGroupSize(ng, gc);

            if (ng.Nodes.Count == 1)
            {
                double positionY = ng.Position.Y + titleSize.Height + Padding;
                double positionX = ng.Position.X + (ng.Dimension.Width / 2.0) - HalfAvatarDimension;
                RenderNode(gc, (Node)ng.Nodes[0], positionX, positionY);
            }
            else if (ng.Nodes.Count == 2)
            {
                // position them side-by-side, separated by (padding) number of pixels, centered in the
                // space.
                double positionY  = ng.Position.Y + titleSize.Height + Padding;
                double position1X = ng.Position.X + (ng.Dimension.Width / 2.0) - (Padding / 2.0) - AvatarDimension;
                double position2X = position1X + Padding + AvatarDimension;
                RenderNode(gc, (Node)ng.Nodes[0], position1X, positionY);
                RenderNode(gc, (Node)ng.Nodes[1], position2X, positionY);
            }
            else
            {
                double deg = 0;
                double x   = 0;
                double y   = 0;

                var contentY      = ng.Position.Y + titleSize.Height;
                var contentHeight = size.Height - titleSize.Height;
                var middle        = new System.Drawing.Point(Convert.ToInt32(ng.Position.X + size.Width - (size.Width / 2.0)),
                                                             Convert.ToInt32(contentY + contentHeight - (contentHeight / 2.0)));

                int nodeSize = Convert.ToInt32(AvatarDimension);
                for (int i = 0; i < ng.Nodes.Count; i++)
                {
                    x = Math.Sin(deg) * ((size.Width / 2.0) - (nodeSize)) + middle.X - (nodeSize / 2.0);
                    y = Math.Cos(deg) * ((contentHeight / 2.0) - (nodeSize)) + middle.Y - (nodeSize / 2.0);
                    RenderNode(gc, (Node)ng.Nodes[i], x, y);
                    deg += Math.PI / (ng.Nodes.Count / 2.0);
                }
            }
            gc.Restore();
        }