Beispiel #1
0
        /// <summary>
        /// Draws a bitmap image.
        /// </summary>
        /// <param name="source">The bitmap image.</param>
        /// <param name="opacity">The opacity to draw with.</param>
        /// <param name="sourceRect">The rect in the image to draw.</param>
        /// <param name="destRect">The rect in the output to draw to.</param>
        public void DrawImage(IBitmapImpl bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
            var pixbuf = bitmap as Gdk.Pixbuf;
            var rtb    = bitmap as RenderTargetBitmapImpl;
            var size   = new Size(pixbuf?.Width ?? rtb.PixelWidth, pixbuf?.Height ?? rtb.PixelHeight);
            var scale  = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);

            _context.Save();
            _context.Scale(scale.X, scale.Y);
            destRect /= scale;

            _context.PushGroup();

            if (pixbuf != null)
            {
                Gdk.CairoHelper.SetSourcePixbuf(
                    _context,
                    pixbuf,
                    -sourceRect.X + destRect.X,
                    -sourceRect.Y + destRect.Y);
            }
            else
            {
                _context.SetSourceSurface(
                    rtb.Surface,
                    (int)(-sourceRect.X + destRect.X),
                    (int)(-sourceRect.Y + destRect.Y));
            }

            _context.Rectangle(destRect.ToCairo());
            _context.Fill();
            _context.PopGroupToSource();
            _context.PaintWithAlpha(opacityOverride);
            _context.Restore();
        }
Beispiel #2
0
        /// <summary>
        /// Draws a bitmap image.
        /// </summary>
        /// <param name="source">The bitmap image.</param>
        /// <param name="opacity">The opacity to draw with.</param>
        /// <param name="sourceRect">The rect in the image to draw.</param>
        /// <param name="destRect">The rect in the output to draw to.</param>
        public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
        {
            var impl  = bitmap.PlatformImpl as BitmapImpl;
            var size  = new Size(impl.PixelWidth, impl.PixelHeight);
            var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);

            _context.Save();
            _context.Scale(scale.X, scale.Y);
            destRect /= scale;

            if (opacityOverride < 1.0f)
            {
                _context.PushGroup();
                Gdk.CairoHelper.SetSourcePixbuf(
                    _context,
                    impl.Surface,
                    -sourceRect.X + destRect.X,
                    -sourceRect.Y + destRect.Y);

                _context.Rectangle(destRect.ToCairo());
                _context.Fill();
                _context.PopGroupToSource();
                _context.PaintWithAlpha(opacityOverride);
            }
            else
            {
                _context.PushGroup();
                Gdk.CairoHelper.SetSourcePixbuf(
                    _context,
                    impl.Surface,
                    -sourceRect.X + destRect.X,
                    -sourceRect.Y + destRect.Y);

                _context.Rectangle(destRect.ToCairo());
                _context.Fill();
                _context.PopGroupToSource();
                _context.PaintWithAlpha(opacityOverride);
            }
            _context.Restore();
        }
        public void Fill(object backend)
        {
            var gtkc = (CairoContextBackend)backend;

            Cairo.Context ctx = gtkc.Context;
            if (gtkc.GlobalAlpha == 1)
            {
                ctx.Fill();
            }
            else
            {
                ctx.PushGroup();
                ctx.Fill();
                ctx.PopGroupToSource();
                ctx.PaintWithAlpha(gtkc.GlobalAlpha);
            }
        }
Beispiel #4
0
        public virtual void Render(Cairo.Context cr)
        {
            double opacity = Opacity;

            if (ContentAllocation.Width <= 0 || ContentAllocation.Height <= 0 || opacity <= 0)
            {
                return;
            }

            cr.Save();

            if (opacity < 1.0)
            {
                cr.PushGroup();
            }

            MarginStyle margin_style = MarginStyle;

            if (margin_style != null && margin_style != MarginStyle.None)
            {
                cr.Translate(Math.Round(Allocation.X), Math.Round(Allocation.Y));
                cr.Save();
                margin_style.Apply(this, cr);
                cr.Restore();
                cr.Translate(Math.Round(Margin.Left), Math.Round(Margin.Top));
            }
            else
            {
                cr.Translate(Math.Round(ContentAllocation.X), Math.Round(ContentAllocation.Y));
            }

            cr.Antialias = Cairo.Antialias.Default;
            ClippedRender(cr);

            if (opacity < 1.0)
            {
                cr.PopGroupToSource();
                cr.PaintWithAlpha(Opacity);
            }

            cr.Restore();
        }