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

			cr2.Color = new Color (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.Source = check_pattern;
		cr.Rectangle (0, 0, width, height);
		cr.Fill ();

		check_pattern.Destroy ();
		check.Destroy ();
		cr.Restore ();
	}
コード例 #2
0
		public bool Convert (FilterRequest req)
		{
			string source = req.Current.LocalPath;
			Uri dest = req.TempUri (Path.GetExtension (source));
			
			using (ImageFile img = ImageFile.Create (source)) {
				using (Pixbuf pixbuf = img.Load ()) {
					using (ImageInfo info = new ImageInfo (pixbuf)) {
						MemorySurface surface = new MemorySurface (Format.Argb32, 
											   pixbuf.Width,
											   pixbuf.Height);
	
						Context ctx = new Context (surface);
						ctx.Matrix = info.Fill (info.Bounds, angle);
						Pattern p = new SurfacePattern (info.Surface);
						ctx.Source = p;
						ctx.Paint ();
						((IDisposable)ctx).Dispose ();
						p.Destroy ();
						using (Pixbuf result = CairoUtils.CreatePixbuf (surface)) {
							using (Stream output = File.OpenWrite (dest.LocalPath)) {
								img.Save (result, output);
							}
						}
						surface.Flush ();
						info.Dispose ();
						req.Current = dest;
						return true;
					}
				}
			}
		}
コード例 #3
0
		public ImageInfo (ImageInfo info, Gdk.Rectangle allocation)
		{
			#if false
			Surface = new ImageSurface (Format.RGB24,
						    allocation.Width,
						    allocation.Height);
			Context ctx = new Context (Surface);
			#else
			Console.WriteLine ("source status = {0}", info.Surface.Status);
			Surface = info.Surface.CreateSimilar (Content.Color,
							      allocation.Width,
							      allocation.Height);
			
			System.Console.WriteLine ("status = {1} pointer = {0}", Surface.Handle.ToString (), Surface.Status);
			Context ctx = new Context (Surface);
			#endif
			Bounds = allocation;
			
			ctx.Matrix = info.Fill (allocation);
			Pattern p = new SurfacePattern (info.Surface);
			ctx.Source = p;
			ctx.Paint ();
			((IDisposable)ctx).Dispose ();
			p.Destroy ();
		}
コード例 #4
0
        public ImageInfo(ImageInfo info, Widget w, Gdk.Rectangle bounds)
        {
            Cairo.Surface similar = CairoUtils.CreateSurface (w.GdkWindow);
            Bounds = bounds;
            Surface = similar.CreateSimilar (Content.ColorAlpha, Bounds.Width, Bounds.Height);
            Context ctx = new Context (Surface);

            ctx.Matrix = info.Fill (Bounds);
            Pattern p = new SurfacePattern (info.Surface);
            ctx.Source = p;
            ctx.Paint ();
            ((IDisposable)ctx).Dispose ();
            p.Destroy ();
        }
コード例 #5
0
        public bool OnExpose(Context ctx, Gdk.Rectangle allocation)
        {
            ctx.Operator = Operator.Source;

            SurfacePattern p = new SurfacePattern (info.Surface);

            p.Filter = Filter.Fast;

            Matrix m = info.Fill (allocation, angle);

            ctx.Matrix = m;
            ctx.Source = p;
            ctx.Paint ();
            p.Destroy ();

            return true;
        }
コード例 #6
0
		private Pixbuf ProcessImpl (Pixbuf input, Cms.Profile input_profile, bool fast) {
			Pixbuf result;
			using (ImageInfo info = new ImageInfo (input)) {
				MemorySurface surface = new MemorySurface (Format.Argb32,
									   input.Width,
									   input.Height);

				Context ctx = new Context (surface);
				ctx.Matrix = info.Fill (info.Bounds, angle);
				SurfacePattern p = new SurfacePattern (info.Surface);
				if (fast) {
					p.Filter =  Filter.Fast;
				}
				ctx.Source = p;
				ctx.Paint ();
				((IDisposable)ctx).Dispose ();
				p.Destroy ();
				result = MemorySurface.CreatePixbuf (surface);
				surface.Flush ();
			}
			return result;
		}
コード例 #7
0
ファイル: image_pattern.cs プロジェクト: nlhepler/mono
	static void draw (Cairo.Context gr, int width, int height)
	{
		int w, h;
		ImageSurface image;
		Matrix matrix;
		SurfacePattern pattern;
		
		gr.Scale (width, height);
		gr.LineWidth = 0.04;

		image = new ImageSurface ("data/e.png");
		w = image.Width;
		h = image.Height;
		
		pattern = new SurfacePattern (image);
		pattern.Extend = Cairo.Extend.Repeat;
		
		gr.Translate (0.5, 0.5);
		gr.Rotate (M_PI / 4);
		gr.Scale (1 / Math.Sqrt (2), 1 / Math.Sqrt (2));
		gr.Translate (- 0.5, - 0.5);
		
		matrix = new Matrix ();
		matrix.InitScale (w * 5.0, h * 5.0);
		
		pattern.Matrix = matrix;
		
		gr.Pattern = pattern;
		
		gr.Rectangle ( new PointD (0, 0),
			       1.0, 1.0);
		gr.Fill ();
		
		pattern.Destroy ();
		image.Destroy();
	}
コード例 #8
0
		public bool OnExpose (Context ctx, Gdk.Rectangle allocation)
		{
			if (frames == 0)
				start = DateTime.UtcNow;
			
			frames ++;
			TimeSpan elapsed = DateTime.UtcNow - start;
			double fraction = elapsed.Ticks / (double) duration.Ticks; 
			double opacity = Math.Sin (Math.Min (fraction, 1.0) * Math.PI * 0.5);
			
			ctx.Operator = Operator.Source;
			
			SurfacePattern p = new SurfacePattern (begin_buffer.Surface);
			ctx.Matrix = begin_buffer.Fill (allocation);
			p.Filter = Filter.Fast;
			ctx.Source = p;
			ctx.Paint ();
			
			ctx.Operator = Operator.Over;
			ctx.Matrix = end_buffer.Fill (allocation);
			SurfacePattern sur = new SurfacePattern (end_buffer.Surface);
			Pattern black = new SolidPattern (new Cairo.Color (0.0, 0.0, 0.0, opacity));
			//ctx.Source = black;
			//ctx.Fill ();
			sur.Filter = Filter.Fast;
			ctx.Source = sur;
			ctx.Mask (black);
			//ctx.Paint ();
			
			ctx.Matrix = new Matrix ();
			
			ctx.MoveTo (allocation.Width / 2.0, allocation.Height / 2.0);
			ctx.Source = new SolidPattern (1.0, 0, 0);	
			#if debug
			ctx.ShowText (String.Format ("{0} {1} {2} {3} {4} {5} {6} {7}", 
						     frames,
						     sur.Status,
						     p.Status,
						     opacity, fraction, elapsed, start, DateTime.UtcNow));
			#endif
			sur.Destroy ();
			p.Destroy ();
			return fraction < 1.0;
		}
コード例 #9
0
        public bool OnExpose(Context ctx, Gdk.Rectangle allocation)
        {
            ctx.Operator = Operator.Source;
            ctx.Matrix = end_buffer.Fill (allocation);
            SurfacePattern sur = new SurfacePattern (end_buffer.Surface);
            ctx.Source = sur;
            ctx.Paint ();
            sur.Destroy ();

            ctx.Operator = Operator.Over;
            SurfacePattern p = new SurfacePattern (begin_buffer.Surface);
            Matrix m = begin_buffer.Fill (allocation);
            m.Translate (Math.Round (- allocation.Width * fraction), 0);
            ctx.Matrix = m;
            p.Filter = Filter.Fast;
            ctx.Source = p;
            ctx.Paint ();
            p.Destroy ();

            return fraction < 1.0;
        }
コード例 #10
0
ファイル: Snippets.cs プロジェクト: REALTOBIZ/mono
		public void imagepattern(Context cr, int width, int height)
		{
			Normalize (cr, width, height);
			
			ImageSurface image = new ImageSurface ("data/romedalen.png");
			int w = image.Width;
			int h = image.Height;

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

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

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

			cr.Source = pattern;

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

			pattern.Destroy ();
			image.Destroy ();
		}
コード例 #11
0
ファイル: ImageDisplay.cs プロジェクト: iainlane/f-spot
        private void OnExpose(Context ctx, Region region)
        {
            SetClip (ctx, region);
            if (Transition != null) {
                bool done = false;
                foreach (Gdk.Rectangle area in GetRectangles (region)) {
                    BlockProcessor proc = new BlockProcessor (area, block_size);
                    Gdk.Rectangle subarea;
                    while (proc.Step (out subarea)) {
                        ctx.Save ();
                        SetClip (ctx, subarea);
                        done = ! Transition.OnExpose (ctx, Allocation);
                        ctx.Restore ();
                    }
                }
                if (done) {
                    System.Console.WriteLine ("frames = {0}", Transition.Frames);
                    Transition = null;
                }
            } else {
                ctx.Operator = Operator.Source;
                SurfacePattern p = new SurfacePattern (current.Surface);
                p.Filter = Filter.Fast;
                SetClip (ctx, region);
                ctx.Matrix = current.Fill (Allocation);

                ctx.Source = p;
                ctx.Paint ();
                p.Destroy ();
            }
        }
コード例 #12
0
ファイル: ImageDisplay.cs プロジェクト: iainlane/f-spot
        protected override bool OnExposeEvent(EventExpose args)
        {
            bool double_buffer = false;
            base.OnExposeEvent (args);

            Context ctx = Gdk.CairoHelper.Create (GdkWindow);
            if (double_buffer) {
                ImageSurface cim = new ImageSurface (Format.RGB24,
                                     Allocation.Width,
                                     Allocation.Height);

                Context buffer = new Context (cim);
                OnExpose (buffer, args.Region);

                SurfacePattern sur = new SurfacePattern (cim);
                sur.Filter = Filter.Fast;
                ctx.Source = sur;
                SetClip (ctx, args.Region);

                ctx.Paint ();

                ((IDisposable)buffer).Dispose ();
                ((IDisposable)cim).Dispose ();
                sur.Destroy ();
            } else {
                OnExpose (ctx, args.Region);
            }

            ((IDisposable)ctx).Dispose ();
            return true;
        }
コード例 #13
0
        public bool OnExpose(Context ctx, Gdk.Rectangle allocation)
        {
            ctx.Operator = Operator.Source;
            SurfacePattern p = new SurfacePattern (begin_buffer.Surface);
            ctx.Matrix = begin_buffer.Fill (allocation);
            p.Filter = Filter.Fast;
            ctx.Source = p;
            ctx.Paint ();

            ctx.Operator = Operator.Over;
            ctx.Matrix = end_buffer.Fill (allocation);
            SurfacePattern sur = new SurfacePattern (end_buffer.Surface);
            sur.Filter = Filter.Fast;
            ctx.Source = sur;
            Pattern mask = CreateMask (allocation, fraction);
            ctx.Mask (mask);
            mask.Destroy ();
            p.Destroy ();
            sur.Destroy ();

            return fraction < 1.0;
        }
コード例 #14
0
        private ImageInfo CreateBlur(ImageInfo source)
        {
            double scale = Math.Max (256 / (double) source.Bounds.Width,
                         256 / (double) source.Bounds.Height);

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

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

            Context ctx = new Context (image);

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

            ctx.Paint ();
            p.Destroy ();
            ((IDisposable)ctx).Dispose ();
            Gdk.Pixbuf normal = image.ToPixbuf();

            Gdk.Pixbuf blur = PixbufUtils.Blur (normal, 3, null);

            ImageInfo overlay = new ImageInfo (blur);
            blur.Dispose ();
            normal.Dispose ();
            image.Destroy ();
            return overlay;
        }
コード例 #15
0
        public void Apply(Context ctx, Gdk.Rectangle allocation)
        {
            SurfacePattern p = new SurfacePattern (info.Surface);
            ctx.Matrix = new Matrix ();
            Matrix m = info.Fit (allocation);
            ctx.Operator = Operator.Over;
            ctx.Matrix = m;
            ctx.Source = p;
            ctx.Paint ();

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

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

            //ctx.Paint ();
            ctx.Mask (mask);
            overlay.Destroy ();
            p.Destroy ();
        }
コード例 #16
0
        public bool OnExpose(Context ctx, Gdk.Rectangle viewport)
        {
            double percent = Math.Min ((DateTime.UtcNow - start).Ticks / (double) duration.Ticks, 1.0);

            //Matrix m = info.Fill (allocation);
            Matrix m = new Matrix ();
            m.Translate (pan_x, pan_y);
            m.Scale (zoom, zoom);
            ctx.Matrix = m;

            SurfacePattern p = new SurfacePattern (info.Surface);
            ctx.Source = p;
            ctx.Paint ();
            p.Destroy ();

            return percent < 1.0;
        }
コード例 #17
0
        public bool OnExpose(Context ctx, Gdk.Rectangle viewport)
        {
            double percent = Math.Min ((DateTime.UtcNow - start).Ticks / (double) duration.Ticks, 1.0);
            frames ++;

            //ctx.Matrix = m;

            SurfacePattern p = new SurfacePattern (buffer.Surface);
            p.Filter = Filter.Fast;
            Matrix m = new Matrix ();
            m.Translate (pan_x * zoom, pan_y * zoom);
            m.Scale (zoom, zoom);
            zoom *= .98;
            p.Matrix = m;
            ctx.Source = p;
            ctx.Paint ();
            p.Destroy ();

            return percent < 1.0;
        }
コード例 #18
0
        public ImageInfo(ImageInfo info, Gdk.Rectangle allocation)
        {
            Surface = info.Surface.CreateSimilar (Content.Color,
                                  allocation.Width,
                                  allocation.Height);

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

            ctx.Matrix = info.Fill (allocation);
            Pattern p = new SurfacePattern (info.Surface);
            ctx.Source = p;
            ctx.Paint ();
            ((IDisposable)ctx).Dispose ();
            p.Destroy ();
        }