예제 #1
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;
            }
        }
예제 #2
0
        public static SurfacePattern CreateTileBrush(TileBrush brush, Size targetSize)
        {
            var helper = new TileBrushImplHelper(brush, targetSize);
            if (!helper.IsValid)
                return null;
            
			using (var intermediate = new ImageSurface(Format.ARGB32, (int)helper.IntermediateSize.Width, (int)helper.IntermediateSize.Height))
            using (var ctx = new RenderTarget(intermediate).CreateDrawingContext())
            {
                helper.DrawIntermediate(ctx);

                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(-helper.DestinationRect.X, -helper.DestinationRect.Y);
                    result.Matrix = matrix;
                }

                return result;
            }
        }
예제 #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 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;
					}
				}
			}
		}
예제 #5
0
	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 ();
	}
예제 #6
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 ();
        }
예제 #7
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);
#if MONO_1_2_5
			Pattern black = new SolidPattern (new Cairo.Color (0.0, 0.0, 0.0, opacity));
#else
			Pattern black = new SolidPattern (new Cairo.Color (0.0, 0.0, 0.0, opacity), true);
#endif
			//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;
		}
예제 #8
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;
        }
예제 #9
0
		public static void SetSourceDrawable (Context ctx, Gdk.Drawable d, double x, double y)
		{
			try {
				gdk_cairo_set_source_pixmap (ctx.Handle, d.Handle, x, y);
			} catch (EntryPointNotFoundException) {
				int width, height;
				d.GetSize (out width, out height);
				XlibSurface surface = new XlibSurface (GdkUtils.GetXDisplay (d.Display), 
								       (IntPtr)GdkUtils.GetXid (d),
								       GdkUtils.GetXVisual (d.Visual),
								       width, height);
				
				SurfacePattern p = new SurfacePattern (surface);
				Matrix m = new Matrix ();
				m.Translate (-x, -y);
				p.Matrix = m;
				ctx.Source = p;
			}
		}		
예제 #10
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;
		}
예제 #11
0
	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();
	}
        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;
        }
예제 #13
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;
            }
        }
        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 ();
        }
예제 #15
0
        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;
        }
예제 #16
0
        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 ();
        }
예제 #17
0
파일: helpers.cs 프로젝트: kig/filezoo
 /** ASYNC */
 public static ImageSurface ScaleDownSurface(ImageSurface s, uint size)
 {
     double scale = (double)size / (double)Math.Max(s.Width, s.Height);
     int nw = Math.Max(1, (int)(s.Width * scale));
     int nh = Math.Max(1, (int)(s.Height * scale));
     ImageSurface rv = new ImageSurface (Format.ARGB32, nw, nh);
     using (Context cr = new Context(rv)) {
       using (SurfacePattern p = new SurfacePattern(s)) {
     cr.Rectangle (0,0, rv.Width, rv.Height);
     cr.Scale (scale, scale);
     cr.Pattern = p;
     cr.Fill ();
       }
     }
     return rv;
 }
예제 #18
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();
        }
예제 #19
0
 void CairoSetPattern(Context cr, DColor color, double alpha, DFillStyle fillStyle)
 {
     switch (fillStyle)
     {
         case DFillStyle.ForwardDiagonalHatch:
             Surface patSurf = cr.Target.CreateSimilar(Content.ColorAlpha, 7, 7);
             Context patCr = new Context(patSurf);
             patCr.SetSource(MakeColor(color, alpha));
             patCr.LineWidth = 1;
             patCr.MoveTo(0, 0);
             patCr.LineTo(7, 7);
             patCr.Stroke();
             SurfacePattern pat = new SurfacePattern(patSurf);
             pat.Extend = Extend.Repeat;
             cr.SetSource(pat);
             ((IDisposable)patCr).Dispose();
             ((IDisposable)patSurf).Dispose();
             break;
         default:
             cr.SetSource(MakeColor(color, alpha));
             break;
     }
 }
예제 #20
0
파일: TiltEditor.cs 프로젝트: GNOME/f-spot
 private Pixbuf ProcessImpl(Pixbuf input, Cms.Profile input_profile, bool fast)
 {
     Pixbuf result;
     using (ImageInfo info = new ImageInfo (input)) {
         using (ImageSurface surface = new ImageSurface (Format.Argb32,
                                input.Width,
                                input.Height)) {
             using (Context ctx = new Context (surface)) {
                 ctx.Matrix = info.Fill (info.Bounds, angle);
                 using (SurfacePattern p = new SurfacePattern (info.Surface)) {
                     if (fast)
                         p.Filter =  Filter.Fast;
                     ctx.Source = p;
                     ctx.Paint ();
                 }
                 result = surface.ToPixbuf();
                 surface.Flush ();
             }
         }
     }
     return result;
 }
예제 #21
0
        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 ();
        }
예제 #22
0
        public void drawImage(string path, params double[] args)
        {
            double sx = 0
            , sy = 0
            , sw = 0
            , sh = 0
            , dx, dy, dw, dh;

            switch (args.Length)
            {
                // img, sx, sy, sw, sh, dx, dy, dw, dh
                case 8:
                  sx = args[0];
                  sy = args[1];
                  sw = args[2];
                  sh = args[3];
                  dx = args[4];
                  dy = args[5];
                  dw = args[6];
                  dh = args[7];
                  break;
                // img, dx, dy, dw, dh
                case 4:
                  dx = args[0];
                  dy = args[1];
                  dw = args[2];
                  dh = args[3];
                  break;
                // img, dx, dy
                case 2:
                  dx = args[0];
                  dy = args[1];
                  dw = sw;
                  dh = sh;
                  break;
                default:
                  throw new ArgumentException();
              }

            using (var imgSurface = new ImageSurface(path))
            {

                sw = imgSurface.Width;
                sh = imgSurface.Height;

                // Start draw
                canvas.Context.Save();

                this.savePath();
                canvas.Context.Rectangle(dx, dy, dw, dh);
                canvas.Context.Clip();
                this.restorePath();

                if (dw != sw || dh != sh)
                {
                    double fx = (double)dw / sw;
                    double fy = (double)dh / sh;
                    //scale
                    canvas.Context.Scale(fx, fy);
                    dx = dx / fx;
                    dy = dy / fy;
                }

                using (var pattern = new SurfacePattern(canvas.Surface))
                {
                    pattern.Filter = state.patternQuality;
                    canvas.Context.Pattern = pattern;
                    canvas.Context.SetSource(imgSurface, dx - sx, dy - sy);
                    canvas.Context.PaintWithAlpha(state.globalAlpha);
                }
                canvas.Context.Restore();
            }
        }
예제 #23
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;
        }
예제 #24
0
        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 ();
            }
        }
예제 #25
0
        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;
        }
예제 #26
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;
        }
예제 #27
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 ();
		}
예제 #28
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;
        }
예제 #29
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;
        }
예제 #30
0
        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 ();
            }
        }