当前位置: 首页>>代码示例>>C#>>正文


C# Context.Clip方法代码示例

本文整理汇总了C#中Cairo.Context.Clip方法的典型用法代码示例。如果您正苦于以下问题:C# Context.Clip方法的具体用法?C# Context.Clip怎么用?C# Context.Clip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cairo.Context的用法示例。


在下文中一共展示了Context.Clip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawBackground

		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 ();
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:50,代码来源:StatusAreaBuildTheme.cs

示例2: CreateImageBrush

        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;
            }
        }
开发者ID:shahid-pk,项目名称:Perspex,代码行数:60,代码来源:TileBrushes.cs

示例3: clip

        public void clip(Context ctx)
        {
            foreach (Rectangle r in list)
                ctx.Rectangle(r);

            ctx.Clip();
        }
开发者ID:jpbruyere,项目名称:Crow,代码行数:7,代码来源:Rectangles.cs

示例4: OnFillRegionComputed

        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 ();
        }
开发者ID:xxgreg,项目名称:Pinta,代码行数:30,代码来源:PaintBucketTool.cs

示例5: DrawShape

        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;
        }
开发者ID:rolandixor,项目名称:Pinta,代码行数:18,代码来源:LineCurveTool.cs

示例6: DrawShape

        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;
        }
开发者ID:joehillen,项目名称:Pinta,代码行数:21,代码来源:RectangleTool.cs

示例7: OnFillRegionComputed

        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 ();
        }
开发者ID:sandyarmstrong,项目名称:Pinta,代码行数:23,代码来源:PaintBucketTool.cs

示例8: DrawShape

        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;
        }
开发者ID:Kharevich,项目名称:Pinta,代码行数:23,代码来源:RectangleTool.cs

示例9: Draw

        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);
        }
开发者ID:PintaProject,项目名称:PintaDemoExtension,代码行数:55,代码来源:RandomPencilTool.cs

示例10: clip

		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();
		}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:17,代码来源:Snippets.cs

示例11: Draw

		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);
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:75,代码来源:TabStrip.cs

示例12: DrawChannel

        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 ());
        }
开发者ID:IAmAnubhavSaini,项目名称:Pinta,代码行数:61,代码来源:HistogramWidget.cs

示例13: Crop

        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;
        }
开发者ID:jobernolte,项目名称:Pinta,代码行数:21,代码来源:Layer.cs

示例14: OnStartTransform

        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 ();
        }
开发者ID:Kharevich,项目名称:Pinta,代码行数:36,代码来源:MoveSelectedTool.cs

示例15: GetClippedLayer

        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;
        }
开发者ID:linuxmhall,项目名称:Pinta,代码行数:14,代码来源:Document.cs


注:本文中的Cairo.Context.Clip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。