Ejemplo n.º 1
0
 public void Dispose()
 {
     if (layout != null)
     {
         layout.Dispose();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// The measure text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">The font size.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <returns>The size of the text.</returns>
        public override OxySize MeasureText(string text, string fontFamily, double fontSize, double fontWeight)
        {
            if (text == null)
            {
                return(OxySize.Empty);
            }
            this.g.Save();
#if GTKSHARP3
            Pango.Layout layout = new Layout(this.c);
#else
            Pango.Layout layout = Pango.CairoHelper.CreateLayout(this.g);
#endif
            Pango.FontDescription font = new Pango.FontDescription();
            font.Family            = fontFamily;
            font.Weight            = (fontWeight >= 700) ? Pango.Weight.Bold : Pango.Weight.Normal;
            font.AbsoluteSize      = (int)(fontSize * Pango.Scale.PangoScale);
            layout.FontDescription = font;
            layout.SetText(text);
            Pango.Rectangle inkRect;
            Pango.Rectangle logicalRect;
            layout.GetExtents(out inkRect, out logicalRect);
            this.g.Restore();
            layout.Dispose();
            return(new OxySize(logicalRect.Width / Pango.Scale.PangoScale, logicalRect.Height / Pango.Scale.PangoScale));
        }
Ejemplo n.º 3
0
        // No dispose of resources on this class
        protected override void Dispose(bool disposing)
        {
            layout.Dispose();

            if (font_description != null)
            {
                font_description.Dispose();
            }
        }
Ejemplo n.º 4
0
 protected override void OnDestroyed()
 {
     this.Realized      -= OnRealized;
     this.SizeAllocated -= SizeAllocatedHandler;
     if (layout != null)
     {
         layout.Dispose();
         layout = null;
     }
     base.OnDestroyed();
 }
Ejemplo n.º 5
0
        void UpdateStyle()
        {
            this.GdkWindow.Background = this.Style.Base(StateType.Normal);
            if (layout != null)
            {
                layout.Dispose();
            }
            layout      = PangoUtil.CreateLayout(this);
            layout.Wrap = Pango.WrapMode.Char;

            FontDescription des = this.Style.FontDescription.Copy();

            layout.FontDescription = des;
            CalcVisibleRows();
        }
Ejemplo n.º 6
0
 protected override void OnDestroyed()
 {
     base.OnDestroyed();
     if (layout != null)
     {
         layout.Dispose();
         categoryLayout.Dispose();
         noMatchLayout.Dispose();
         layout = categoryLayout = noMatchLayout = null;
     }
     if (itemFont != null)
     {
         itemFont.Dispose();
         itemFont = null;
     }
 }
Ejemplo n.º 7
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            Cairo.Context cr = Gdk.CairoHelper.Create(e.Window);

            Gdk.Rectangle area = e.Area;

            if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage))
            {
                Pango.Layout messageLayout = new Pango.Layout(this.PangoContext);
                messageLayout.Alignment = Pango.Alignment.Center;
                messageLayout.Width     = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale);
                if (!string.IsNullOrEmpty(CustomMessage))
                {
                    messageLayout.SetText(CustomMessage);
                }
                else
                {
                    messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document."));
                }
                cr.MoveTo(Allocation.Width * 1 / 6, 12);
                cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor());
                Pango.CairoHelper.ShowLayout(cr, messageLayout);
                messageLayout.Dispose();
                ((IDisposable)cr).Dispose();
                return(true);
            }

            var backColor = Style.Base(StateType.Normal).ToCairoColor();

            cr.SetSourceColor(backColor);
            cr.Rectangle(area.X, area.Y, area.Width, area.Height);
            cr.Fill();

            int xpos        = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0);
            int vadjustment = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0);
            int ypos        = -vadjustment;
            ToolboxWidgetCategory lastCategory = null;
            int lastCategoryYpos = 0;

            cr.LineWidth = 1;

            Iterate(ref xpos, ref ypos, (category, itemDimension) => {
                ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

                if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension)))
                {
                    return(true);
                }
                cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                cr.SetSourceColor(Ide.Gui.Styles.PadCategoryBackgroundColor.ToCairoColor());
                cr.Fill();

                if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand)
                {
                    cr.MoveTo(xpos, ypos + 0.5);
                    cr.LineTo(itemDimension.Width, ypos + 0.5);
                }
                cr.MoveTo(0, ypos + itemDimension.Height - 0.5);
                cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5);
                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor());
                cr.Stroke();

                headerLayout.SetMarkup(category.Text);
                int width, height;
                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryLabelColor.ToCairoColor());
                headerLayout.GetPixelSize(out width, out height);
                cr.MoveTo(xpos + CategoryLeftPadding, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                Pango.CairoHelper.ShowLayout(cr, headerLayout);

                var img = category.IsExpanded ? discloseUp : discloseDown;
                cr.DrawImage(this, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + Math.Round((itemDimension.Height - img.Height) / 2));

                lastCategory     = category;
                lastCategoryYpos = ypos + itemDimension.Height;

                return(true);
            }, (curCategory, item, itemDimension) => {
                if (!area.IntersectsWith(new Gdk.Rectangle(new Gdk.Point(xpos, ypos), itemDimension)))
                {
                    return(true);
                }

                var icon = item.Icon;
                if (!icon.HasFixedSize)
                {
                    var maxIconSize     = Math.Min(itemDimension.Width, itemDimension.Height);
                    var fittingIconSize = maxIconSize > 32 ? Xwt.IconSize.Large : maxIconSize > 16 ? Xwt.IconSize.Medium : Xwt.IconSize.Small;
                    icon = item.Icon.WithSize(fittingIconSize);
                }
                if (item == SelectedItem)
                {
                    icon = icon.WithStyles("sel");
                    cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                    cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                    cr.Fill();
                }
                if (listMode || !curCategory.CanIconizeItems)
                {
                    cr.DrawImage(this, icon, xpos + ItemLeftPadding, ypos + Math.Round((itemDimension.Height - icon.Height) / 2));
                    layout.SetMarkup(item.Text);
                    layout.Width = (int)((itemDimension.Width - ItemIconTextItemSpacing - iconSize.Width - ItemLeftPadding * 2) * Pango.Scale.PangoScale);
                    layout.GetPixelSize(out var width, out var height);
                    cr.SetSourceColor(Style.Text(item != SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor());
                    cr.MoveTo(xpos + ItemLeftPadding + iconSize.Width + ItemIconTextItemSpacing, ypos + Math.Round((double)(itemDimension.Height - height) / 2));
                    Pango.CairoHelper.ShowLayout(cr, layout);
                }
                else
                {
                    cr.DrawImage(this, icon, xpos + Math.Round((itemDimension.Width - icon.Width) / 2), ypos + Math.Round((itemDimension.Height - icon.Height) / 2));
                }

                if (item == mouseOverItem)
                {
                    cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor());
                    cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1);
                    cr.Stroke();
                }

                return(true);
            });

            ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

            if (lastCategory != null && lastCategory.AnimatingExpand)
            {
                // Closing line when animating the last group of the toolbox
                cr.MoveTo(area.X, ypos + 0.5);
                cr.RelLineTo(area.Width, 0);
                cr.SetSourceColor(MonoDevelop.Ide.Gui.Styles.PadCategoryBorderColor.ToCairoColor());
                cr.Stroke();
            }

            ((IDisposable)cr).Dispose();
            return(true);
        }
Ejemplo n.º 8
0
        protected override void Render (Gdk.Drawable drawable, Widget widget, Gdk.Rectangle background_area,
            Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags)
        {
            if (source == null || source is SourceManager.GroupSource) {
                return;
            }

            view = widget as SourceView;
            bool selected = view != null && view.Selection.IterIsSelected (iter);
            StateType state = RendererStateToWidgetState (widget, flags);

            RenderSelection (drawable, background_area, selected, state);

            int title_layout_width = 0, title_layout_height = 0;
            int count_layout_width = 0, count_layout_height = 0;
            int max_title_layout_width;

            int img_padding = 6;
            int expander_icon_spacing = 3;
            int x = cell_area.X;
            bool np_etc = (source.Order + Depth * 100) < 40;
            if (!np_etc) {
                x += Depth * img_padding + (int)Xpad;
            } else {
                // Don't indent NowPlaying and Play Queue as much
                x += Math.Max (0, (int)Xpad - 2);
            }

            Gdk.GC main_gc = widget.Style.TextGC (state);

            // Draw the expander if the source has children
            double exp_h = (cell_area.Height - 2.0*Ypad) / 3.2;
            double exp_w = exp_h * 1.6;
            if (view != null && view.Cr != null && source.Children != null && source.Children.Count > 0) {
                var r = new Gdk.Rectangle (x, cell_area.Y + (int)((cell_area.Height - exp_h) / 2.0), (int)exp_w, (int)exp_h);
                view.Theme.DrawArrow (view.Cr, r, source.Expanded ? Math.PI/2.0 : 0.0);
            }

            if (!np_etc) {
                x += (int) exp_w;
                x += 2; // a little spacing after the expander
                expander_right_x = x;
            }

            // Draw icon
            Pixbuf icon = SourceIconResolver.ResolveIcon (source, RowHeight);

            bool dispose_icon = false;
            if (state == StateType.Insensitive) {
                // Code ported from gtk_cell_renderer_pixbuf_render()
                var icon_source = new IconSource () {
                    Pixbuf = icon,
                    Size = IconSize.SmallToolbar,
                    SizeWildcarded = false
                };

                icon = widget.Style.RenderIcon (icon_source, widget.Direction, state,
                    (IconSize)(-1), widget, "SourceRowRenderer");

                dispose_icon = true;
                icon_source.Dispose ();
            }

            if (icon != null) {
                x += expander_icon_spacing;
                drawable.DrawPixbuf (main_gc, icon, 0, 0,
                    x, Middle (cell_area, icon.Height),
                    icon.Width, icon.Height, RgbDither.None, 0, 0);

                x += icon.Width;

                if (dispose_icon) {
                    icon.Dispose ();
                }
            }

            // Setup font info for the title/count, and see if we should show the count
            bool hide_count = source.EnabledCount <= 0 || source.Properties.Get<bool> ("SourceView.HideCount");
            FontDescription fd = widget.PangoContext.FontDescription.Copy ();
            fd.Weight = (ISource)ServiceManager.PlaybackController.NextSource == (ISource)source
                ? Pango.Weight.Bold
                : Pango.Weight.Normal;

            if (view != null && source == view.NewPlaylistSource) {
                fd.Style = Pango.Style.Italic;
                hide_count = true;
            }

            Pango.Layout title_layout = new Pango.Layout (widget.PangoContext);
            Pango.Layout count_layout = null;

            // If we have a count to draw, setup its fonts and see how wide it is to see if we have room
            if (!hide_count) {
                count_layout = new Pango.Layout (widget.PangoContext);
                count_layout.FontDescription = fd;
                count_layout.SetMarkup (String.Format ("<span size=\"small\">{0}</span>", source.EnabledCount));
                count_layout.GetPixelSize (out count_layout_width, out count_layout_height);
            }

            // Hide the count if the title has no space
            max_title_layout_width = cell_area.Width - x - count_layout_width;//(icon == null ? 0 : icon.Width) - count_layout_width - 10;
            if (!hide_count && max_title_layout_width <= 0) {
                hide_count = true;
            }

            // Draw the source Name
            title_layout.FontDescription = fd;
            title_layout.Width = (int)(max_title_layout_width * Pango.Scale.PangoScale);
            title_layout.Ellipsize = EllipsizeMode.End;
            title_layout.SetText (source.Name);
            title_layout.GetPixelSize (out title_layout_width, out title_layout_height);

            x += img_padding;
            drawable.DrawLayout (main_gc, x, Middle (cell_area, title_layout_height), title_layout);

            title_layout.Dispose ();

            // Draw the count
            if (!hide_count) {
                if (view != null && view.Cr != null) {
                    view.Cr.Color = state == StateType.Normal || (view != null && state == StateType.Prelight)
                        ? view.Theme.TextMidColor
                        : view.Theme.Colors.GetWidgetColor (GtkColorClass.Text, state);

                    view.Cr.MoveTo (
                        cell_area.X + cell_area.Width - count_layout_width - 2,
                        cell_area.Y + 0.5 + (double)(cell_area.Height - count_layout_height) / 2.0);
                    PangoCairoHelper.ShowLayout (view.Cr, count_layout);
                }

                count_layout.Dispose ();
            }

            fd.Dispose ();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <param name="text">The text.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="rotate">The rotation angle.</param>
        /// <param name="halign">The horizontal alignment.</param>
        /// <param name="valign">The vertical alignment.</param>
        /// <param name="maxSize">The maximum size of the text.</param>
        public override void DrawText(
            ScreenPoint p,
            string text,
            OxyColor fill,
            string fontFamily,
            double fontSize,
            double fontWeight,
            double rotate,
            HorizontalAlignment halign,
            VerticalAlignment valign,
            OxySize?maxSize)
        {
#if GTKSHARP3
            Pango.Layout layout = new Layout(this.c);
#else
            Pango.Layout layout = Pango.CairoHelper.CreateLayout(this.g);
#endif
            Pango.FontDescription font = new Pango.FontDescription();
            font.Family            = fontFamily;
            font.Weight            = (fontWeight >= 700) ? Pango.Weight.Bold : Pango.Weight.Normal;
            font.AbsoluteSize      = (int)(fontSize * Pango.Scale.PangoScale);
            layout.FontDescription = font;
            layout.SetText(text);
            Pango.Rectangle inkRect;
            Pango.Rectangle size;
            layout.GetExtents(out inkRect, out size);
            size.Width  /= (int)Pango.Scale.PangoScale;
            size.Height /= (int)Pango.Scale.PangoScale;
            if (maxSize != null)
            {
                int maxWidth  = (int)Math.Min((Double)Int32.MaxValue, maxSize.Value.Width);
                int maxHeight = (int)Math.Min((Double)Int32.MaxValue, maxSize.Value.Height);
                size.Width  = Math.Min(size.Width, maxWidth);
                size.Height = Math.Min(size.Height, maxHeight);
            }
            this.g.Save();
            double dx = 0;
            if (halign == HorizontalAlignment.Center)
            {
                dx = -size.Width / 2;
            }

            if (halign == HorizontalAlignment.Right)
            {
                dx = -size.Width;
            }

            double dy = 0;
            if (valign == VerticalAlignment.Middle)
            {
                dy = -size.Height / 2;
            }

            if (valign == VerticalAlignment.Bottom)
            {
                dy = -size.Height;
            }

            this.g.Translate(p.X, p.Y);
            if (Math.Abs(rotate) > double.Epsilon)
            {
                this.g.Rotate(rotate * Math.PI / 180.0);
            }

            this.g.Translate(dx, dy);

            g.Rectangle(0, 0, size.Width + 0.1f, size.Height + 0.1f);
            g.Clip();
            this.g.SetSourceColor(fill);
            Pango.CairoHelper.ShowLayout(this.g, layout);
            layout.Dispose();
            this.g.Restore();
        }
Ejemplo n.º 10
0
        protected override void OnRender(Cairo.Context cr, Widget widget, Gdk.Rectangle background_area,
                                         Gdk.Rectangle cell_area, CellRendererState flags)
        {
            if (source == null || source is SourceManager.GroupSource)
            {
                return;
            }

            view = widget as SourceView;
            bool       selected = view != null && view.Selection.IterIsSelected(iter);
            StateFlags state    = RendererStateToWidgetState(widget, flags);

            RenderBackground(cr, background_area, selected, state);

            int title_layout_width = 0, title_layout_height = 0;
            int count_layout_width = 0, count_layout_height = 0;
            int max_title_layout_width;

            int  img_padding           = 6;
            int  expander_icon_spacing = 3;
            int  x      = cell_area.X;
            bool np_etc = (source.Order + Depth * 100) < 40;

            if (!np_etc)
            {
                x += Depth * img_padding + (int)Xpad;
            }
            else
            {
                // Don't indent NowPlaying and Play Queue as much
                x += Math.Max(0, (int)Xpad - 2);
            }

            // Draw the expander if the source has children
            double exp_h = (cell_area.Height - 2.0 * Ypad) / 2.0;
            double exp_w = exp_h * 1.6;
            int    y     = Middle(cell_area, (int)exp_h);

            if (view != null && source.Children != null && source.Children.Count > 0)
            {
                var r = new Gdk.Rectangle(x, y, (int)exp_w, (int)exp_h);
                view.Theme.DrawArrow(cr, r, source.Expanded ? Math.PI / 2.0 : 0.0);
            }

            if (!np_etc)
            {
                x += (int)exp_w;
                x += 2; // a little spacing after the expander
                expander_right_x = x;
            }

            // Draw icon
            Pixbuf icon = SourceIconResolver.ResolveIcon(source, RowHeight);

            bool dispose_icon = false;

            if (state == StateFlags.Insensitive)
            {
                // Code ported from gtk_cell_renderer_pixbuf_render()
                var icon_source = new IconSource()
                {
                    Pixbuf         = icon,
                    Size           = IconSize.SmallToolbar,
                    SizeWildcarded = false
                };

                icon = widget.StyleContext.RenderIconPixbuf(icon_source, (IconSize)(-1));

                dispose_icon = true;
                icon_source.Dispose();
            }

            if (icon != null)
            {
                x += expander_icon_spacing;

                cr.Save();
                Gdk.CairoHelper.SetSourcePixbuf(cr, icon, x, Middle(cell_area, icon.Height));
                cr.Paint();
                cr.Restore();

                x += icon.Width;

                if (dispose_icon)
                {
                    icon.Dispose();
                }
            }

            // Setup font info for the title/count, and see if we should show the count
            bool            hide_count = source.EnabledCount <= 0 || source.Properties.Get <bool> ("SourceView.HideCount");
            FontDescription fd         = widget.PangoContext.FontDescription.Copy();

            fd.Weight = (ISource)ServiceManager.PlaybackController.NextSource == (ISource)source
                ? Pango.Weight.Bold
                : Pango.Weight.Normal;

            if (view != null && source == view.NewPlaylistSource)
            {
                fd.Style   = Pango.Style.Italic;
                hide_count = true;
            }

            Pango.Layout title_layout = new Pango.Layout(widget.PangoContext);
            Pango.Layout count_layout = null;

            // If we have a count to draw, setup its fonts and see how wide it is to see if we have room
            if (!hide_count)
            {
                count_layout = new Pango.Layout(widget.PangoContext);
                count_layout.FontDescription = fd;
                count_layout.SetMarkup(String.Format("<span size=\"small\">{0}</span>", source.EnabledCount));
                count_layout.GetPixelSize(out count_layout_width, out count_layout_height);
            }

            // Hide the count if the title has no space
            max_title_layout_width = cell_area.Width - x - count_layout_width;//(icon == null ? 0 : icon.Width) - count_layout_width - 10;
            if (!hide_count && max_title_layout_width <= 0)
            {
                hide_count = true;
            }

            // Draw the source Name
            title_layout.FontDescription = fd;
            title_layout.Width           = (int)(max_title_layout_width * Pango.Scale.PangoScale);
            title_layout.Ellipsize       = EllipsizeMode.End;
            title_layout.SetText(source.Name);
            title_layout.GetPixelSize(out title_layout_width, out title_layout_height);

            x += img_padding;
            widget.StyleContext.RenderLayout(cr, x, Middle(cell_area, title_layout_height), title_layout);

            title_layout.Dispose();

            // Draw the count
            if (!hide_count)
            {
                if (view != null)
                {
                    cr.SetSourceColor(state == StateFlags.Normal || (view != null && state == StateFlags.Prelight)
                        ? view.Theme.TextMidColor
                        : CairoExtensions.GdkRGBAToCairoColor(view.Theme.Widget.StyleContext.GetColor(state)));

                    cr.MoveTo(
                        cell_area.X + cell_area.Width - count_layout_width - 2,
                        cell_area.Y + 0.5 + (double)(cell_area.Height - count_layout_height) / 2.0);
                    Pango.CairoHelper.ShowLayout(cr, count_layout);
                }

                count_layout.Dispose();
            }

            fd.Dispose();
        }
Ejemplo n.º 11
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            Cairo.Context cr = Gdk.CairoHelper.Create(e.Window);

            Gdk.Rectangle area = e.Area;

            if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage))
            {
                Pango.Layout messageLayout = new Pango.Layout(this.PangoContext);
                messageLayout.Alignment = Pango.Alignment.Center;
                messageLayout.Width     = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale);
                if (!string.IsNullOrEmpty(CustomMessage))
                {
                    messageLayout.SetText(CustomMessage);
                }
                else
                {
                    messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document."));
                }
                cr.MoveTo(Allocation.Width * 1 / 6, 12);
                cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor());
                Pango.CairoHelper.ShowLayout(cr, messageLayout);
                messageLayout.Dispose();
                ((IDisposable)cr).Dispose();
                return(true);
            }

            var backColor = Style.Base(StateType.Normal).ToCairoColor();

            cr.SetSourceColor(backColor);
            cr.Rectangle(area.X, area.Y, area.Width, area.Height);
            cr.Fill();

            int      xpos             = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0);
            int      vadjustment      = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0);
            int      ypos             = -vadjustment;
            Category lastCategory     = null;
            int      lastCategoryYpos = 0;

            Iterate(ref xpos, ref ypos, delegate(Category category, Gdk.Size itemDimension) {
                const int foldSegmentHeight = 8;

                ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

                cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                using (var pat = new Cairo.LinearGradient(xpos, ypos, xpos, ypos + itemDimension.Height)) {
                    pat.AddColorStop(0, CategoryBackgroundGradientStartColor);
                    pat.AddColorStop(1, CategoryBackgroundGradientEndColor);
                    cr.SetSource(pat);
                    cr.Fill();
                }
                if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand)
                {
                    cr.MoveTo(xpos, ypos + 0.5);
                    cr.LineTo(itemDimension.Width, ypos + 0.5);
                }
                cr.MoveTo(0, ypos + itemDimension.Height - 0.5);
                cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5);
                cr.SetSourceColor(CategoryBorderColor);
                cr.LineWidth = 1;
                cr.Stroke();

                headerLayout.SetText(category.Text);
                int width, height;
                cr.SetSourceColor(CategoryLabelColor);
                layout.GetPixelSize(out width, out height);
                cr.MoveTo(xpos + CategoryLeftPadding, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                Pango.CairoHelper.ShowLayout(cr, headerLayout);

                var img = category.IsExpanded ? discloseUp : discloseDown;
                cr.DrawImage(this, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + Math.Round((itemDimension.Height - img.Height) / 2));

                lastCategory     = category;
                lastCategoryYpos = ypos + itemDimension.Height;
            }, delegate(Category curCategory, Item item, Gdk.Size itemDimension) {
                if (item == SelectedItem)
                {
                    cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor());
                    cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height);
                    cr.Fill();
                }
                if (listMode || !curCategory.CanIconizeItems)
                {
                    cr.DrawImage(this, item.Icon, xpos + ItemLeftPadding, ypos + Math.Round((itemDimension.Height - item.Icon.Height) / 2));
                    layout.SetText(item.Text);
                    int width, height;
                    layout.GetPixelSize(out width, out height);
                    cr.SetSourceColor(Style.Text(item != this.SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor());
                    cr.MoveTo(xpos + ItemLeftPadding + IconSize.Width + ItemIconTextItemSpacing, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2)));
                    Pango.CairoHelper.ShowLayout(cr, layout);
                }
                else
                {
                    cr.DrawImage(this, item.Icon, xpos + Math.Round((itemDimension.Width - item.Icon.Width) / 2), ypos + Math.Round((itemDimension.Height - item.Icon.Height) / 2));
                }

                if (item == mouseOverItem)
                {
                    cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor());
                    cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1);
                    cr.Stroke();
                }
            });

            ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos);

            if (lastCategory != null && lastCategory.AnimatingExpand)
            {
                // Closing line when animating the last group of the toolbox
                cr.MoveTo(area.X, ypos + 0.5);
                cr.RelLineTo(area.Width, 0);
                cr.SetSourceColor(CategoryBorderColor);
                cr.Stroke();
            }

            ((IDisposable)cr).Dispose();
            return(true);
        }
Ejemplo n.º 12
0
        protected override bool OnExposeEvent(Gdk.EventExpose e)
        {
            Gdk.Drawable  draw = e.Window;
            Gdk.Rectangle area = e.Area;
            if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage))
            {
                Pango.Layout messageLayout = new Pango.Layout(this.PangoContext);
                messageLayout.Alignment = Pango.Alignment.Center;
                messageLayout.Width     = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale);
                if (!string.IsNullOrEmpty(CustomMessage))
                {
                    messageLayout.SetText(CustomMessage);
                }
                else
                {
                    messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document."));
                }
                draw.DrawLayout(Style.TextGC(StateType.Normal), Allocation.Width * 1 / 6, 12, messageLayout);
                messageLayout.Dispose();
                return(true);
            }

            Cairo.Context cr = Gdk.CairoHelper.Create(e.Window);
            draw.DrawRectangle(Style.BaseGC(StateType.Normal), true, area);
            int xpos        = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0);
            int vadjustment = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0);
            int ypos        = -vadjustment;

            Iterate(ref xpos, ref ypos, delegate(Category category, Gdk.Size itemDimension) {
                const int foldSegmentHeight = 8;

                if (category == SelectedItem)
                {
                    draw.DrawRectangle(Style.BaseGC(StateType.Selected),
                                       true,
                                       new Gdk.Rectangle(xpos,
                                                         ypos,
                                                         itemDimension.Width,
                                                         itemDimension.Height));
                }
                else
                {
                    cr.NewPath();
                    cr.MoveTo(xpos, ypos);
                    cr.RelLineTo(itemDimension.Width, 0);
                    cr.RelLineTo(0, itemDimension.Height);
                    cr.RelLineTo(-itemDimension.Width, 0);
                    cr.RelLineTo(0, -itemDimension.Height);
                    cr.ClosePath();
                    using (var pat = new Cairo.LinearGradient(xpos, ypos, xpos, ypos + itemDimension.Height)) {
                        Cairo.Color ccol = Convert(Style.Mid(StateType.Normal));
                        ccol.A           = 0.2;
                        pat.AddColorStop(0, ccol);
                        ccol.A = 1;
                        pat.AddColorStop(1, ccol);
                        cr.Pattern = pat;
                        cr.FillPreserve();
                    }
                }
                DrawFoldSegment(draw, xpos + 2, ypos + (itemDimension.Height - foldSegmentHeight) / 2, foldSegmentHeight, foldSegmentHeight, category.IsExpanded, category == mouseOverItem && mouseX < xpos + 2 + 12);
                headerLayout.SetText(category.Text);
                int width, height;
                layout.GetPixelSize(out width, out height);
                draw.DrawLayout(Style.TextGC(category != this.SelectedItem ? StateType.Normal : StateType.Selected), xpos + 2 + 12, ypos + (itemDimension.Height - height) / 2, headerLayout);
                if (category == mouseOverItem)
                {
                    draw.DrawRectangle(Style.DarkGC(StateType.Prelight),
                                       false,
                                       new Gdk.Rectangle(xpos,
                                                         ypos,
                                                         itemDimension.Width - 1,
                                                         itemDimension.Height - 1));
                }
            }, delegate(Category curCategory, Item item, Gdk.Size itemDimension) {
                if (item == SelectedItem)
                {
                    draw.DrawRectangle(Style.BaseGC(StateType.Selected),
                                       true,
                                       new Gdk.Rectangle(xpos,
                                                         ypos,
                                                         itemDimension.Width,
                                                         itemDimension.Height));
                }
                if (listMode || !curCategory.CanIconizeItems)
                {
                    draw.DrawPixbuf(this.Style.ForegroundGC(StateType.Normal),
                                    item.Icon, 0, 0,
                                    xpos + 4,
                                    ypos + 1 + (itemDimension.Height - item.Icon.Height) / 2,
                                    item.Icon.Width, item.Icon.Height, Gdk.RgbDither.None, 0, 0);
                    layout.SetText(item.Text);
                    int width, height;
                    layout.GetPixelSize(out width, out height);
                    draw.DrawLayout(Style.TextGC(item != this.SelectedItem ? StateType.Normal : StateType.Selected), xpos + IconSize.Width + 4, ypos + (itemDimension.Height - height) / 2, layout);
                }
                else
                {
                    draw.DrawPixbuf(this.Style.ForegroundGC(StateType.Normal),
                                    item.Icon, 0, 0,
                                    xpos + (itemDimension.Width - item.Icon.Width) / 2,
                                    ypos + (itemDimension.Height - item.Icon.Height) / 2,
                                    item.Icon.Width, item.Icon.Height, Gdk.RgbDither.None, 0, 0);
                }

                if (item == mouseOverItem)
                {
                    draw.DrawRectangle(Style.DarkGC(StateType.Prelight),
                                       false,
                                       new Gdk.Rectangle(xpos,
                                                         ypos,
                                                         itemDimension.Width,
                                                         itemDimension.Height));
                }
            });
            ((IDisposable)cr).Dispose();
            return(true);
        }
Ejemplo n.º 13
0
 public void Dispose()
 {
     pangoLayout.Dispose();
 }
        protected override void Render (Gdk.Drawable drawable, Widget widget, Gdk.Rectangle background_area,
            Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags)
        {
            if (source == null) {
                return;
            }

            view = widget as SourceView;
            bool selected = view != null && view.Selection.IterIsSelected (iter);
            StateType state = RendererStateToWidgetState (widget, flags);

            RenderSelection (drawable, background_area, selected, state);

            int title_layout_width = 0, title_layout_height = 0;
            int count_layout_width = 0, count_layout_height = 0;
            int max_title_layout_width;

            bool hide_counts = source.EnabledCount <= 0;

            Pixbuf icon = SourceIconResolver.ResolveIcon (source, RowHeight);

            bool dispose_icon = false;
            if (state == StateType.Insensitive) {
                // Code ported from gtk_cell_renderer_pixbuf_render()
                var icon_source = new IconSource () {
                    Pixbuf = icon,
                    Size = IconSize.SmallToolbar,
                    SizeWildcarded = false
                };

                icon = widget.Style.RenderIcon (icon_source, widget.Direction, state,
                    (IconSize)(-1), widget, "SourceRowRenderer");

                dispose_icon = true;
                icon_source.Dispose ();
            }

            FontDescription fd = widget.PangoContext.FontDescription.Copy ();
            fd.Weight = (ISource)ServiceManager.PlaybackController.NextSource == (ISource)source
                ? Pango.Weight.Bold
                : Pango.Weight.Normal;

            if (view != null && source == view.NewPlaylistSource) {
                fd.Style = Pango.Style.Italic;
                hide_counts = true;
            }

            Pango.Layout title_layout = new Pango.Layout (widget.PangoContext);
            Pango.Layout count_layout = null;

            if (!hide_counts) {
                count_layout = new Pango.Layout (widget.PangoContext);
                count_layout.FontDescription = fd;
                count_layout.SetMarkup (String.Format ("<span size=\"small\">{0}</span>", source.EnabledCount));
                count_layout.GetPixelSize (out count_layout_width, out count_layout_height);
            }

            max_title_layout_width = cell_area.Width - (icon == null ? 0 : icon.Width) - count_layout_width - 10;

            if (!hide_counts && max_title_layout_width < 0) {
                hide_counts = true;
            }

            title_layout.FontDescription = fd;
            title_layout.Width = (int)(max_title_layout_width * Pango.Scale.PangoScale);
            title_layout.Ellipsize = EllipsizeMode.End;
            title_layout.SetText (source.Name);
            title_layout.GetPixelSize (out title_layout_width, out title_layout_height);

            Gdk.GC main_gc = widget.Style.TextGC (state);

            drawable.DrawLayout (main_gc,
                cell_area.X + (icon == null ? 0 : icon.Width) + 6,
                Middle (cell_area, title_layout_height),
                title_layout);

            title_layout.Dispose ();

            if (icon != null) {
                drawable.DrawPixbuf (main_gc, icon, 0, 0,
                    cell_area.X, Middle (cell_area, icon.Height),
                    icon.Width, icon.Height, RgbDither.None, 0, 0);

                if (dispose_icon) {
                    icon.Dispose ();
                }
            }

            if (hide_counts) {
                fd.Dispose ();
                return;
            }

            if (view != null && view.Cr != null) {
                view.Cr.Color = state == StateType.Normal || (view != null && state == StateType.Prelight)
                    ? view.Theme.TextMidColor
                    : view.Theme.Colors.GetWidgetColor (GtkColorClass.Text, state);

                view.Cr.MoveTo (
                    cell_area.X + cell_area.Width - count_layout_width - 2,
                    cell_area.Y + 0.5 + (double)(cell_area.Height - count_layout_height) / 2.0);
                PangoCairoHelper.ShowLayout (view.Cr, count_layout);
            }

            count_layout.Dispose ();
            fd.Dispose ();
        }