コード例 #1
0
ファイル: CairoSample.cs プロジェクト: akrisiun/gtk-sharp
	void FillChecks (Context cr, int x, int y, int width, int height)
	{
		int CHECK_SIZE = 32;
		
		cr.Save ();
		Surface check;
		using (var target = cr.GetTarget ()) {
			check = target.CreateSimilar (Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
		}
		
		// draw the check
		using (Context cr2 = new Context (check)) {
			cr2.Operator = Operator.Source;
			cr2.SetSourceRGB (0.4, 0.4, 0.4);
			cr2.Rectangle (0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
			cr2.Fill ();

			cr2.SetSourceRGB (0.7, 0.7, 0.7);
			cr2.Rectangle (x, y, CHECK_SIZE, CHECK_SIZE);
			cr2.Fill ();

			cr2.Rectangle (x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE);
			cr2.Fill ();
		}

		// Fill the whole surface with the check
		SurfacePattern check_pattern = new SurfacePattern (check);
		check_pattern.Extend = Extend.Repeat;
		cr.SetSource (check_pattern);
		cr.Rectangle (0, 0, width, height);
		cr.Fill ();

		check_pattern.Dispose ();
		check.Dispose ();
		cr.Restore ();
	}
コード例 #2
0
ファイル: SoftFocus.cs プロジェクト: modulexcite/f-spot
        ImageInfo CreateBlur(ImageInfo source)
        {
            double scale = Math.Max (256 / (double)source.Bounds.Width,
                               256 / (double)source.Bounds.Height);

            var small = new Gdk.Rectangle (0, 0,
                                      (int)Math.Ceiling (source.Bounds.Width * scale),
                                      (int)Math.Ceiling (source.Bounds.Height * scale));

            var image = new ImageSurface (Format.Argb32,
                                     small.Width,
                                     small.Height);

            var ctx = new Context (image);

            ctx.Matrix = source.Fit (small);
            ctx.Operator = Operator.Source;
            Pattern p = new SurfacePattern (source.Surface);
            ctx.SetSource (p);

            ctx.Paint ();
            p.Dispose ();
            ctx.Dispose ();

            ImageInfo overlay = null;
            using (var normal = image.ToPixbuf ())
            {
                using (var pixbufBlur = PixbufUtils.Blur (normal, 3, null))
                {
                    overlay = new ImageInfo (pixbufBlur);
                }
            }

            image.Dispose ();
            return overlay;
        }
コード例 #3
0
ファイル: SoftFocus.cs プロジェクト: modulexcite/f-spot
        public void Apply(Context ctx, Gdk.Rectangle allocation)
        {
            var p = new SurfacePattern (info.Surface);
            ctx.Matrix = new Matrix ();
            Matrix m = info.Fit (allocation);
            ctx.Operator = Operator.Over;
            ctx.Matrix = m;
            ctx.SetSource (p);
            ctx.Paint ();

            var overlay = new SurfacePattern (blur.Surface);
            ctx.Matrix = new Matrix ();
            ctx.Matrix = blur.Fit (allocation);
            ctx.Operator = Operator.Over;
            ctx.SetSource (overlay);

            // FIXME ouch this is ugly.
            if (mask == null)
                Radius = Radius;

            //ctx.Paint ();
            ctx.Mask (mask);
            overlay.Dispose ();
            p.Dispose ();
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: zwcloud/CairoSharp
        private void imagepatternToolStripMenuItem_Click(object sender, EventArgs e)
        {
            lastSelected = "imagepattern";
            OnPaintAction = cr =>
            {
                int w, h;
                ImageSurface image;

                Pattern pattern;
                Matrix matrix = new Matrix();

                image = new ImageSurface(romedalenPngData);
                w = image.Width;
                h = image.Height;

                pattern = new SurfacePattern(image);
                pattern.Extend = Extend.Repeat;

                cr.Translate(128.0, 128.0);
                cr.Rotate(Math.PI / 4);
                cr.Scale(1 / Math.Sqrt(2), 1 / Math.Sqrt(2));
                cr.Translate(-128.0, -128.0);

                matrix.InitScale(w/256.0*5.0, h/256.0*5.0);
                pattern.Matrix = matrix;

                cr.SetSource(pattern);

                cr.Rectangle(0, 0, 256.0, 256.0);
                cr.Fill();

                pattern.Dispose();
                image.Dispose();
            };

            Invalidate();
        }
コード例 #5
0
ファイル: ImageInfo.cs プロジェクト: modulexcite/f-spot
        public ImageInfo(ImageInfo info, Gdk.Rectangle allocation)
        {
            Surface = info.Surface.CreateSimilar (Content.Color,
                                  allocation.Width,
                                  allocation.Height);

            var ctx = new Context (Surface);
            Bounds = allocation;

            ctx.Matrix = info.Fill (allocation);
            Pattern p = new SurfacePattern (info.Surface);
            ctx.SetSource (p);
            ctx.Paint ();
            ctx.Dispose ();
            p.Dispose ();
        }
コード例 #6
0
ファイル: ImageInfo.cs プロジェクト: modulexcite/f-spot
        public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds)
        {
            using (var similar = CairoUtils.CreateSurface (w.GdkWindow)) {
                Bounds = bounds;
                Surface = similar.CreateSimilar (Content.ColorAlpha, Bounds.Width, Bounds.Height);
                var ctx = new Context (Surface);

                ctx.Matrix = info.Fill (Bounds);
                Pattern p = new SurfacePattern (info.Surface);
                ctx.SetSource (p);
                ctx.Paint ();
                ctx.Dispose ();
                p.Dispose ();
            }
        }