PaintWithAlpha() public méthode

public PaintWithAlpha ( double alpha ) : void
alpha double
Résultat void
Exemple #1
0
        private void RenderAnimation(Cairo.Context cr)
        {
            if (stage.Actor == null)
            {
                // We are not in a transition, just render
                RenderStage(cr, current_track, current_image);
                return;
            }

            if (current_track == null)
            {
                // Fade in the whole stage, nothing to fade out
                CairoExtensions.PushGroup(cr);
                RenderStage(cr, incoming_track, incoming_image);
                CairoExtensions.PopGroupToSource(cr);

                cr.PaintWithAlpha(stage.Actor.Percent);
                return;
            }

            // XFade only the cover art
            RenderCoverArt(cr, incoming_image);

            CairoExtensions.PushGroup(cr);
            RenderCoverArt(cr, current_image);
            CairoExtensions.PopGroupToSource(cr);

            cr.PaintWithAlpha(1.0 - stage.Actor.Percent);

            // Fade in/out the text
            bool same_artist_album = incoming_track != null?incoming_track.ArtistAlbumEqual(current_track) : false;

            bool same_track = incoming_track != null?incoming_track.Equals(current_track) : false;

            if (same_artist_album)
            {
                RenderTrackInfo(cr, incoming_track, same_track, true);
            }

            if (stage.Actor.Percent <= 0.5)
            {
                // Fade out old text
                CairoExtensions.PushGroup(cr);
                RenderTrackInfo(cr, current_track, !same_track, !same_artist_album);
                CairoExtensions.PopGroupToSource(cr);

                cr.PaintWithAlpha(1.0 - (stage.Actor.Percent * 2.0));
            }
            else
            {
                // Fade in new text
                CairoExtensions.PushGroup(cr);
                RenderTrackInfo(cr, incoming_track, !same_track, !same_artist_album);
                CairoExtensions.PopGroupToSource(cr);

                cr.PaintWithAlpha((stage.Actor.Percent - 0.5) * 2.0);
            }
        }
Exemple #2
0
        // Flatten image
        public void FlattenImage()
        {
            if (Layers.Count < 2)
            {
                throw new InvalidOperationException("Cannot flatten image because there is only one layer.");
            }

            Layer dest = Layers[0];

            using (Cairo.Context g = new Cairo.Context(dest.Surface)) {
                for (int i = 1; i < Layers.Count; i++)
                {
                    Layer source = Layers[i];
                    g.SetSource(source.Surface);
                    g.PaintWithAlpha(source.Opacity);
                }
            }

            current_layer = 0;

            while (Layers.Count > 1)
            {
                Layer l = Layers[1];

                Layers.RemoveAt(1);
            }

            PintaCore.Layers.OnLayerRemoved();
            Workspace.Invalidate();
        }
Exemple #3
0
        public void FinishSelection()
        {
            // We don't have an uncommitted layer, abort
            if (!ShowSelectionLayer)
            {
                return;
            }

            FinishPixelsHistoryItem hist = new FinishPixelsHistoryItem();

            hist.TakeSnapshot();

            Layer layer = SelectionLayer;

            using (Cairo.Context g = new Cairo.Context(CurrentLayer.Surface)) {
                g.Save();

                g.SetSourceSurface(layer.Surface, (int)layer.Offset.X, (int)layer.Offset.Y);
                g.PaintWithAlpha(layer.Opacity);

                g.Restore();
            }

            DestroySelectionLayer();
            Workspace.Invalidate();

            Workspace.History.PushNewItem(hist);
        }
Exemple #4
0
        public static void ShowWithOptions(this DockySurface self, DockySurface target, PointD point, double zoom, double rotation, double opacity)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Cairo.Context cr = target.Context;

            double cos, sin;

            cos = Math.Cos(rotation);
            sin = Math.Sin(rotation);
            Matrix m = new Matrix(cos, sin, -sin, cos, point.X, point.Y);

            cr.Transform(m);

            if (zoom != 1)
            {
                cr.Scale(zoom, zoom);
            }

            cr.SetSource(self.Internal,
                         -self.Width / 2,
                         -self.Height / 2);

            cr.PaintWithAlpha(opacity);

            cr.IdentityMatrix();
        }
        protected override void Draw(Context cr, Pixbuf prev, Pixbuf next, int width, int height, double progress)
        {
            cr.Color = new Color (0, 0, 0, progress);
            if (next != null) {
                double scale = Math.Min ((double)width/(double)next.Width, (double)height/(double)next.Height);
                cr.Save ();

                cr.Rectangle (0, 0, width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, height - .5 * (height - scale*next.Height), width, .5 * (height - scale*next.Height));
                cr.Fill ();

                cr.Rectangle (0, 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (width - .5 * (width - scale*next.Width), 0, .5 * (width - scale*next.Width), height);
                cr.Fill ();

                cr.Rectangle (0, 0, width, height);
                cr.Scale (scale, scale);
                CairoHelper.SetSourcePixbuf (cr, next, .5 * ((double)width/scale - next.Width), .5 * ((double)height/scale - next.Height));
                cr.PaintWithAlpha (progress);
                cr.Restore ();
            }
        }
Exemple #6
0
        public static void ShowAsReflection(this DockySurface self, DockySurface target, PointD point, double zoom,
                                            double rotation, double opacity, double height, DockPosition position)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }

            Cairo.Context cr = target.Context;

            switch (position)
            {
            case DockPosition.Left:
                point.X -= self.Width * zoom + height;
                break;

            case DockPosition.Top:
                point.Y -= self.Height * zoom + height;
                break;

            case DockPosition.Right:
                point.X += self.Width * zoom + height;
                break;

            case DockPosition.Bottom:
                point.Y += self.Height * zoom + height;
                break;
            }

            double cos, sin;

            cos = Math.Cos(rotation);
            sin = Math.Sin(rotation);
            Matrix m = new Matrix(cos, sin, -sin, cos, point.X, point.Y);

            cr.Transform(m);

            if (zoom != 1)
            {
                cr.Scale(zoom, zoom);
            }

            if (position == DockPosition.Left || position == DockPosition.Right)
            {
                cr.Scale(-1, 1);
            }
            else
            {
                cr.Scale(1, -1);
            }

            cr.SetSource(self.Internal,
                         -self.Width / 2,
                         -self.Height / 2);

            cr.PaintWithAlpha(opacity * .3);

            cr.IdentityMatrix();
        }
 public static void RenderTiled(this Cairo.Context self, Gdk.Pixbuf source, Gdk.Rectangle area, Gdk.Rectangle clip, double opacity = 1)
 {
     Gdk.CairoHelper.SetSourcePixbuf(self, source, area.X, area.Y);
     cairo_pattern_set_extend(self.Pattern.Pointer, CairoExtend.CAIRO_EXTEND_REPEAT);
     self.Rectangle(clip.ToCairoRect());
     self.Clip();
     self.PaintWithAlpha(opacity);
     self.ResetClip();
 }
        public static void RenderTiled(this Cairo.Context self, Gdk.Pixbuf source, Gdk.Rectangle area, Gdk.Rectangle clip, double opacity = 1)
        {
            Gdk.CairoHelper.SetSourcePixbuf(self, source, area.X, area.Y);
            //NOTE: Mono.Cairo.Context.Pattern returns an object than cannot be safely disposed, so P/Invoke directly
            var pattern = cairo_get_source(self.Handle);

            cairo_pattern_set_extend(pattern, CairoExtend.CAIRO_EXTEND_REPEAT);
            self.Rectangle(clip.ToCairoRect());
            self.Clip();
            self.PaintWithAlpha(opacity);
            self.ResetClip();
        }
Exemple #9
0
        public ImageSurface GetFlattenedImage()
        {
            Cairo.ImageSurface surf = new Cairo.ImageSurface(Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

            using (Cairo.Context g = new Cairo.Context(surf)) {
                foreach (var layer in GetLayersToPaint())
                {
                    g.SetSource(layer.Surface);
                    g.PaintWithAlpha(layer.Opacity);
                }
            }

            return(surf);
        }
Exemple #10
0
        public override void Render(Node node, Context context)
        {
            ImageNode image = node as ImageNode;

            ImageSurface surfaceCache = image.Data as ImageSurface;
            if (surfaceCache == null) {
                surfaceCache = new ImageSurface (image.File);
            }
            int x = (int)((image.Width - surfaceCache.Width) * image.XAlign);
            int y = (int)((image.Height - surfaceCache.Height) * image.YAlign);
            context.SetSourceSurface (surfaceCache, x, y);
            double opacity = image.Opacity;
            if (opacity == 1)
                context.Paint ();
            else
                context.PaintWithAlpha (image.Opacity);
        }
Exemple #11
0
        // Flatten current layer
        public void MergeCurrentLayerDown()
        {
            if (current_layer == 0)
            {
                throw new InvalidOperationException("Cannot flatten layer because current layer is the bottom layer.");
            }

            Layer source = CurrentLayer;
            Layer dest   = Layers[current_layer - 1];

            using (Cairo.Context g = new Cairo.Context(dest.Surface)) {
                g.SetSource(source.Surface);
                g.PaintWithAlpha(source.Opacity);
            }

            DeleteCurrentLayer();
        }
        public static void CachedDraw(this Cairo.Context self, ref SurfaceWrapper surface, Gdk.Rectangle region,
                                      object parameters = null, float opacity = 1.0f, Action <Cairo.Context, float> draw = null, double?forceScale = null)
        {
            double displayScale = forceScale.HasValue ? forceScale.Value : QuartzSurface.GetRetinaScale(self);
            int    targetWidth  = (int)(region.Width * displayScale);
            int    targetHeight = (int)(region.Height * displayScale);

            bool redraw = false;

            if (surface == null || surface.Width != targetWidth || surface.Height != targetHeight)
            {
                if (surface != null)
                {
                    surface.Dispose();
                }
                surface = new SurfaceWrapper(self, targetWidth, targetHeight);
                redraw  = true;
            }
            else if ((surface.Data == null && parameters != null) || (surface.Data != null && !surface.Data.Equals(parameters)))
            {
                redraw = true;
            }


            if (redraw)
            {
                surface.Data = parameters;
                using (var context = new Cairo.Context(surface.Surface)) {
                    context.Operator = Operator.Clear;
                    context.Paint();
                    context.Operator = Operator.Over;
                    context.Save();
                    context.Scale(displayScale, displayScale);
                    draw(context, 1.0f);
                    context.Restore();
                }
            }

            self.Save();
            self.Translate(region.X, region.Y);
            self.Scale(1 / displayScale, 1 / displayScale);
            self.SetSourceSurface(surface.Surface, 0, 0);
            self.PaintWithAlpha(opacity);
            self.Restore();
        }
        void RenderPreview(Cairo.Context context, Gdk.Point position, double opacity)
        {
            if (brandedIcon != null)
            {
                if (previewSurface == null)
                {
                    previewSurface = new SurfaceWrapper(context, brandedIcon);
                }
                double scale = PreviewSize / previewSurface.Width;

                context.Save();
                context.Translate(position.X, position.Y);
                context.Scale(scale * IconScale, scale * IconScale);
                context.SetSourceSurface(previewSurface.Surface, -previewSurface.Width / 2, -previewSurface.Height / 2);
                context.PaintWithAlpha(opacity);
                context.Restore();
            }
        }
Exemple #14
0
 public void Draw(Context ctx, ImageSurface surface, double opacity)
 {
     ctx.Save();
     ctx.Transform(Transform);
     ctx.SetSourceSurface(surface, 0, 0);
     ctx.PaintWithAlpha(opacity);
     ctx.Restore();
 }
Exemple #15
0
        protected override bool OnDrawn(Cairo.Context cr)
        {
            if (this.Controls != null && this.Controls.PlayerPocess != null)
            {
                return(true);
            }

            bool baseDrawnResult = base.OnDrawn(cr);

            var scaledPixbuf = this.ScaledPixbuf;

            if (scaledPixbuf == null)
            {
                this.hasFrameBeenQueued = false;
                return(baseDrawnResult);
            }

            // black background in fullscreen mode
            if (BooruApp.BooruApplication.MainWindow.IsFullscreen)
            {
                cr.SetSourceRGB(0, 0, 0);
                cr.Rectangle(new Rectangle(0, 0, this.Allocation.Width, this.Allocation.Height));
                cr.Fill();
            }

            cr.Rectangle(this.TargetRect);
            Gdk.CairoHelper.SetSourcePixbuf(cr, scaledPixbuf, TargetRect.X, TargetRect.Y);
            if (this.fadeAlpha < 1.0)
            {
                cr.PaintWithAlpha(this.fadeAlpha);
                cr.NewPath();
            }
            else
            {
                cr.Fill();
            }

            cr.SelectFontFace("Noto Mono", FontSlant.Normal, FontWeight.Normal);
            cr.SetFontSize(12.0);
            cr.LineWidth = 3.5;

            if (this.fadeAlpha < 1.0)
            {
                var ext          = cr.TextExtents("Loading...");
                var center       = new Point2D(this.Allocation.Width / 2 - (int)ext.Width / 2, this.Allocation.Height / 2 - (int)ext.Height / 2);
                var whiteInverse = new Color(1, 1, 1, 1 - this.fadeAlpha);
                var blackInverse = new Color(0, 0, 0, 1 - this.fadeAlpha);
                cr.DrawStringAt(center.X, center.Y, "Loading...", blackInverse, whiteInverse);
            }

            var white = new Cairo.Color(1, 1, 1, this.fadeAlpha);
            var black = new Cairo.Color(0, 0, 0, this.fadeAlpha);

            // cr.DrawStringAt (4, 4 + cr.FontExtents.Height, System.IO.Path.GetFileName (this.image.Details.Path), black, white);

            if (this.image.MaxImage > -1)
            {
                string text;
                if (this.image.SubImage < 0)
                {
                    text = string.Format("{0:D} images in file", this.image.MaxImage);
                }
                else
                {
                    text = string.Format("{0:D3}/{1:D3} {2}", this.image.SubImage, this.image.MaxImage, this.image.SubImageName);
                }
                cr.DrawStringAt(4, this.Allocation.Height - cr.FontExtents.Height - 4, text, black, white);
            }

            this.hasFrameBeenQueued = false;
            return(baseDrawnResult);
        }
Exemple #16
0
		/// <summary>
		/// Gets the final pixel color for the given point, taking layers, opacity, and blend modes into account.
		/// </summary>
		public ColorBgra GetComputedPixel (int x, int y)
		{
            using (var dst = new ImageSurface (Format.Argb32, 1, 1)) {
                using (var g = new Context (dst)) {
			        foreach (var layer in GetLayersToPaint ()) {
                        var color = layer.Surface.GetColorBgraUnchecked (x, y).ToStraightAlpha ().ToCairoColor ();

                        g.SetBlendMode (layer.BlendMode);
                        g.SetSourceColor (color);

                        g.Rectangle (dst.GetBounds ().ToCairoRectangle ());
                        g.PaintWithAlpha (layer.Opacity);
                    }
                }

                return dst.GetColorBgraUnchecked (0, 0);
            }
		}
 private void Save(string filename,bool bSource,bool bDrawings)
 {
     Surface pngSurface = new ImageSurface(Format.ARGB32,sourceWidth,sourceHeight);
     using(Context c = new Context(pngSurface)) {
         if(bSource) {
             c.SetSourceSurface(source,0,0);
             c.Paint();
         }
         if(bDrawings) {
             c.SetSourceSurface(drawings,0,0);
             c.PaintWithAlpha(transparency);
         }
     }
     pngSurface.WriteToPng(filename);
 }
Exemple #18
0
        private void RenderAnimation(Cairo.Context cr)
        {
            if (stage.Actor == null)
            {
                // We are not in a transition, just render
                RenderStage(cr, current_track, current_image);
                return;
            }

            if (current_track == null)
            {
                // Fade in the whole stage, nothing to fade out
                cr.PushGroup();
                RenderStage(cr, incoming_track, incoming_image);
                cr.PopGroupToSource();

                cr.PaintWithAlpha(stage.Actor.Percent);
                return;
            }

            // Draw the old cover art more and more translucent
            cr.PushGroup();
            RenderCoverArt(cr, current_image);
            cr.PopGroupToSource();
            cr.PaintWithAlpha(1.0 - stage.Actor.Percent);

            // Draw the new cover art more and more opaque
            cr.PushGroup();
            RenderCoverArt(cr, incoming_image);
            cr.PopGroupToSource();
            cr.PaintWithAlpha(stage.Actor.Percent);

            bool same_artist_album = incoming_track != null?incoming_track.ArtistAlbumEqual(current_track) : false;

            bool same_track = incoming_track != null?incoming_track.Equals(current_track) : false;

            if (same_artist_album)
            {
                RenderTrackInfo(cr, incoming_track, same_track, true);
            }

            // Don't xfade the text since it'll look bad (overlapping words); instead, fade
            // the old out, and then the new in
            if (stage.Actor.Percent <= 0.5)
            {
                // Fade out old text
                cr.PushGroup();
                RenderTrackInfo(cr, current_track, !same_track, !same_artist_album);
                cr.PopGroupToSource();

                cr.PaintWithAlpha(1.0 - (stage.Actor.Percent * 2.0));
            }
            else
            {
                // Fade in new text
                cr.PushGroup();
                RenderTrackInfo(cr, incoming_track, !same_track, !same_artist_album);
                cr.PopGroupToSource();

                cr.PaintWithAlpha((stage.Actor.Percent - 0.5) * 2.0);
            }
        }
Exemple #19
0
        public void DrawWithOperator(Context ctx, ImageSurface surface, Operator op, double opacity = 1.0, bool transform = true)
        {
            ctx.Save ();

            if (transform)
                ctx.Transform (Transform);
            ctx.Operator = op;
            ctx.SetSourceSurface (surface, 0, 0);
            if (opacity >= 1.0)
                ctx.Paint ();
            else
                ctx.PaintWithAlpha (opacity);
            ctx.Restore ();
        }
Exemple #20
0
        /// <summary>
        /// Paints an overview of the forecast including high/low temps and a condition icon.
        /// </summary>
        /// <param name="cr">
        /// A <see cref="Cairo.Context"/> to do the painting.
        /// </param>
        void DrawVertForecast(Cairo.Context cr)
        {
            int    cellHeight = (int)((Allocation.Height - BUTTON_SIZE) / WeatherController.Weather.ForecastDays / 1.5);
            double xOffset    = 0;
            double yOffset    = cellHeight / 4.0;

            using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) {
                Pango.Rectangle inkRect, logicalRect;

                layout.FontDescription        = new Gtk.Style().FontDescription;
                layout.FontDescription.Weight = Pango.Weight.Bold;
                layout.Ellipsize = Pango.EllipsizeMode.None;
                layout.Width     = Pango.Units.FromPixels(cellHeight);

                for (int day = 0; day < WeatherController.Weather.ForecastDays; day++)
                {
                    layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(cellHeight / 5));

                    cr.Color = colorTitle;
                    layout.SetText(string.Format("{0}", WeatherForecast.DayShortName(WeatherController.Weather.Forecasts [day].dow)));
                    layout.GetPixelExtents(out inkRect, out logicalRect);
                    cr.MoveTo(xOffset + (cellHeight - inkRect.Width) / 2, yOffset);
                    Pango.CairoHelper.LayoutPath(cr, layout);
                    cr.Fill();

                    cr.Color = colorHigh;
                    layout.SetText(string.Format("{0}{1}", WeatherController.Weather.Forecasts [day].high, AbstractWeatherSource.TempUnit));
                    layout.GetPixelExtents(out inkRect, out logicalRect);
                    cr.MoveTo(xOffset + (cellHeight - inkRect.Width) / 2, yOffset + (cellHeight - logicalRect.Height) / 2);
                    Pango.CairoHelper.LayoutPath(cr, layout);
                    cr.Fill();

                    cr.Color = colorLow;
                    layout.SetText(string.Format("{0}{1}", WeatherController.Weather.Forecasts [day].low, AbstractWeatherSource.TempUnit));
                    layout.GetPixelExtents(out inkRect, out logicalRect);
                    cr.MoveTo(xOffset + (cellHeight - inkRect.Width) / 2, yOffset + cellHeight - logicalRect.Height);
                    Pango.CairoHelper.LayoutPath(cr, layout);
                    cr.Fill();

                    using (Gdk.Pixbuf pbuf = DockServices.Drawing.LoadIcon(WeatherController.Weather.Forecasts [day].image, cellHeight - 5)) {
                        Gdk.CairoHelper.SetSourcePixbuf(cr, pbuf, xOffset + 5 + cellHeight, yOffset + 2);
                        cr.PaintWithAlpha(WeatherController.Weather.Forecasts [day].chanceOf ? .6 : 1);
                    }

                    if (WeatherController.Weather.Forecasts [day].chanceOf)
                    {
                        layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels((int)(cellHeight / 2));

                        layout.SetText("?");

                        layout.GetPixelExtents(out inkRect, out logicalRect);
                        cr.MoveTo(xOffset + cellHeight + (cellHeight - inkRect.Width) / 2, yOffset + (cellHeight - logicalRect.Height) / 2);

                        cr.LineWidth = 4;
                        cr.Color     = new Cairo.Color(0, 0, 0, 0.3);
                        Pango.CairoHelper.LayoutPath(cr, layout);
                        cr.StrokePreserve();

                        cr.Color = new Cairo.Color(1, 1, 1, .6);
                        cr.Fill();
                    }

                    yOffset += (int)(1.5 * cellHeight);
                }

                layout.FontDescription.Dispose();
                layout.Context.Dispose();
            }
        }
Exemple #21
0
        // Flatten current layer
        public void MergeCurrentLayerDown()
        {
            if (current_layer == 0)
                throw new InvalidOperationException ("Cannot flatten layer because current layer is the bottom layer.");

            Layer source = CurrentLayer;
            Layer dest = Layers[current_layer - 1];

            using (Cairo.Context g = new Cairo.Context (dest.Surface)) {
                g.SetSource (source.Surface);
                g.PaintWithAlpha (source.Opacity);
            }

            DeleteCurrentLayer ();
        }
Exemple #22
0
        public ImageSurface GetFlattenedImage()
        {
            Cairo.ImageSurface surf = new Cairo.ImageSurface (Cairo.Format.Argb32, ImageSize.Width, ImageSize.Height);

            using (Cairo.Context g = new Cairo.Context (surf)) {
                foreach (var layer in GetLayersToPaint ()) {
                    g.SetSource (layer.Surface);
                    g.PaintWithAlpha (layer.Opacity);
                }
            }

            return surf;
        }
Exemple #23
0
        // Flatten image
        public void FlattenImage()
        {
            if (Layers.Count < 2)
                throw new InvalidOperationException ("Cannot flatten image because there is only one layer.");

            Layer dest = Layers[0];

            using (Cairo.Context g = new Cairo.Context (dest.Surface)) {
                for (int i = 1; i < Layers.Count; i++) {
                    Layer source = Layers[i];
                    g.SetSource (source.Surface);
                    g.PaintWithAlpha (source.Opacity);
                }
            }

            current_layer = 0;

            while (Layers.Count > 1) {
                Layer l = Layers[1];

                Layers.RemoveAt (1);
            }

            PintaCore.Layers.OnLayerRemoved ();
            Workspace.Invalidate ();
        }
Exemple #24
0
        public void FinishSelection()
        {
            // We don't have an uncommitted layer, abort
            if (!ShowSelectionLayer)
                return;

            FinishPixelsHistoryItem hist = new FinishPixelsHistoryItem ();
            hist.TakeSnapshot ();

            Layer layer = SelectionLayer;

            using (Cairo.Context g = new Cairo.Context (CurrentLayer.Surface)) {
                g.Save ();

                g.SetSourceSurface (layer.Surface, (int)layer.Offset.X, (int)layer.Offset.Y);
                g.PaintWithAlpha (layer.Opacity);

                g.Restore ();
            }

            DestroySelectionLayer ();
            Workspace.Invalidate ();

            Workspace.History.PushNewItem (hist);
        }
Exemple #25
0
        protected override bool OnExposeEvent(EventExpose evnt)
        {
            if (!IsRealized)
            {
                return(false);
            }

            Gdk.Rectangle allocation = Allocation;

            int pixbufSize = allocation.Height - IconBuffer * 2;

            if (item.ShowIcons && (icon_surface == null || (icon_surface.Height != pixbufSize && icon_surface.Width != pixbufSize)))
            {
                if (icon_surface != null)
                {
                    icon_surface.Dispose();
                }
                if (emblem_surface != null)
                {
                    emblem_surface.Dispose();
                }

                if (item.ForcePixbuf == null)
                {
                    icon_surface = LoadIcon(item.Icon, pixbufSize);
                }
                else
                {
                    icon_surface = LoadIcon(item.ForcePixbuf, pixbufSize);
                }

                if (!string.IsNullOrEmpty(item.Emblem))
                {
                    emblem_surface = LoadIcon(item.Emblem, pixbufSize);
                }
            }

            using (Cairo.Context cr = Gdk.CairoHelper.Create(evnt.Window)) {
                if (Selected && !item.Disabled)
                {
                    cr.Rectangle(allocation.X, allocation.Y, allocation.Width, allocation.Height);
                    cr.Color = TextColor.SetAlpha(.1);
                    cr.Fill();
                }

                if (item.ShowIcons)
                {
                    PlaceSurface(cr, icon_surface, allocation);
                    cr.PaintWithAlpha(item.Disabled ? 0.5 : 1);

                    if (item.Bold)
                    {
                        cr.Operator = Operator.Add;
                        PlaceSurface(cr, icon_surface, allocation);
                        cr.PaintWithAlpha(.8);
                        cr.Operator = Operator.Over;
                    }

                    if (!string.IsNullOrEmpty(item.Emblem))
                    {
                        PlaceSurface(cr, emblem_surface, allocation);
                        cr.Paint();
                    }
                }

                using (Pango.Layout layout = DockServices.Drawing.ThemedPangoLayout()) {
                    char   accel;
                    string text = GLib.Markup.EscapeText(item.Text.Replace("\n", ""));
                    if (item.Mnemonic.HasValue)
                    {
                        layout.SetMarkupWithAccel(text, '_', out accel);
                    }
                    else
                    {
                        layout.SetMarkup(text);
                    }
                    layout.Width           = Pango.Units.FromPixels(TextWidth);
                    layout.FontDescription = Style.FontDescription;
                    layout.Ellipsize       = Pango.EllipsizeMode.End;
                    layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(FontSize);
                    layout.FontDescription.Weight       = Pango.Weight.Bold;

                    Pango.Rectangle logical, ink;
                    layout.GetPixelExtents(out ink, out logical);

                    int offset = Padding;
                    if (MenuShowingIcons)
                    {
                        offset += MenuHeight + Padding;
                    }
                    cr.MoveTo(allocation.X + offset, allocation.Y + (allocation.Height - logical.Height) / 2);
                    Pango.CairoHelper.LayoutPath(cr, layout);
                    cr.Color = TextColor.SetAlpha(item.Disabled ? 0.5 : 1);
                    cr.Fill();

                    layout.Context.Dispose();
                }

                (cr.Target as IDisposable).Dispose();
            }

            return(true);
        }