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

public Mask ( Pattern pattern ) : void
pattern Pattern
Результат void
Пример #1
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;
		}
Пример #2
0
        protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
        {
            int x = (int)point.X;
            int y = (int)point.Y;

            if (args.Event.Button == 1)//Left
            {
                //Select an origin with Ctrl + Click
                if((args.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask)
                {
                    from_point = new Point (x, y);
                    stamp = new Cairo.ImageSurface (PintaCore.Layers.CurrentLayer.Surface.Format, BrushWidth*2, BrushWidth*2);
                    from_point = ClampPoint(from_point);

                    using (Context g = new Context (stamp)) {
                        g.SetSourceSurface (PintaCore.Layers.CurrentLayer.Surface,
                                            0 - (from_point.X - BrushWidth),
                                            0 - (from_point.Y - BrushWidth));//dest - source

                        g.Rectangle(0, 0, BrushWidth * 2, BrushWidth * 2);

                        Gradient radpat = new RadialGradient(from_point.X, from_point.Y, BrushWidth, from_point.X, from_point.Y, BrushWidth);
                        radpat.AddColorStop(0, new Color(0, 0, 0, 1));
                        radpat.AddColorStop(1, new Color(0, 0, 0, 0));

                        g.Mask(radpat);

                        g.Fill ();
                    }

                // Draw the copy
                } else {
                    to_point = new Point (x, y);

                    if (PintaCore.Workspace.PointInCanvas (point) && !from_point.Equals (point_empty))
                    {
                        to_point = ClampPoint(to_point);
                        surface_modified = true;

                        undo_surface = PintaCore.Layers.CurrentLayer.Surface.Clone ();

                        ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;

                        using (Context g = new Context (surf)) {
                            g.SetSourceSurface (stamp, to_point.X - BrushWidth, to_point.Y - BrushWidth);
                            g.Paint ();
                        }

                        Gdk.Rectangle r = GetRectangleFromPoints (to_point, to_point);

                        PintaCore.Workspace.Invalidate ();
                        PintaCore.History.PushNewItem(new SimpleHistoryItem (Icon, Name,undo_surface, PintaCore.Layers.CurrentLayerIndex));
                    }
                    from_point = point_empty;
                }
            }
            base.OnMouseDown (canvas, args, point);
        }
Пример #3
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);
        }
Пример #4
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 ();
        }
Пример #5
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);
        }
Пример #6
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;
        }
        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 ();
        }
Пример #8
0
        protected override void ClippedRender(Context cr)
        {
            if (!EnsureLayout ()) {
                return;
            }

            Brush foreground = Foreground;
            if (!foreground.IsValid) {
                return;
            }

            cr.Rectangle (0, 0, RenderSize.Width, RenderSize.Height);
            cr.Clip ();

            bool fade = text_alloc.Width > RenderSize.Width;

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

            cr.MoveTo (text_alloc.X, text_alloc.Y);
            Foreground.Apply (cr);
            Pango.CairoHelper.ShowLayout (cr, layout);
            cr.Fill ();

            if (fade) {
                LinearGradient mask = new LinearGradient (RenderSize.Width - 20, 0, RenderSize.Width, 0);
                mask.AddColorStop (0, new Color (0, 0, 0, 1));
                mask.AddColorStop (1, new Color (0, 0, 0, 0));

                cr.PopGroupToSource ();
                cr.Mask (mask);
                mask.Destroy ();
            }

            cr.ResetClip ();
        }