public override void Render(CellContext context, StateType state, double cellWidth, double cellHeight)
        {
            if (BoundObject == null)
            {
                return;
            }

            if (!(BoundObject is TrackInfo))
            {
                throw new InvalidCastException("ColumnCellAlbum can only bind to AlbumInfo objects");
            }

            TrackInfo track = (TrackInfo)BoundObject;

            context.Layout.Width     = (int)((cellWidth - 8) * Pango.Scale.PangoScale);
            context.Layout.Ellipsize = Pango.EllipsizeMode.End;
            context.Layout.FontDescription.Weight = font_weight;
            context.Layout.SetMarkup(String.Format("<b>{0}</b>\n<small><i>{1}</i></small>",
                                                   GLib.Markup.EscapeText(track.DisplayTrackTitle),
                                                   GLib.Markup.EscapeText(track.DisplayArtistName)));

            int text_width;
            int text_height;

            context.Layout.GetPixelSize(out text_width, out text_height);

            context.Context.MoveTo(4, ((int)cellHeight - text_height) / 2);
            Cairo.Color color = context.Theme.Colors.GetWidgetColor(
                context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, state);
            color.A = (!context.Opaque) ? 0.3 : 1.0;
            context.Context.Color = color;

            PangoCairoHelper.ShowLayout(context.Context, context.Layout);
        }
        protected override void RenderTrackInfo(Context cr, TrackInfo track, bool renderTrack, bool renderArtistAlbum)
        {
            if (track == null)
            {
                return;
            }

            double offset = ArtworkSizeRequest + ArtworkSpacing, y = 0;
            double x = Allocation.X + offset;
            double width = Allocation.Width - offset;
            int    fl_width, fl_height, sl_width, sl_height;
            int    pango_width = (int)(width * Pango.Scale.PangoScale);

            if (first_line_layout == null)
            {
                first_line_layout           = CairoExtensions.CreateLayout(this, cr);
                first_line_layout.Ellipsize = Pango.EllipsizeMode.End;
            }

            if (second_line_layout == null)
            {
                second_line_layout           = CairoExtensions.CreateLayout(this, cr);
                second_line_layout.Ellipsize = Pango.EllipsizeMode.End;
            }

            // Set up the text layouts
            first_line_layout.Width  = pango_width;
            second_line_layout.Width = pango_width;

            // Compute the layout coordinates
            first_line_layout.SetMarkup(GetFirstLineText(track));
            first_line_layout.GetPixelSize(out fl_width, out fl_height);
            second_line_layout.SetMarkup(GetSecondLineText(track));
            second_line_layout.GetPixelSize(out sl_width, out sl_height);

            if (fl_height + sl_height > Allocation.Height)
            {
                SetSizeRequest(-1, fl_height + sl_height);
            }

            y = Allocation.Y + (Allocation.Height - (fl_height + sl_height)) / 2;

            // Render the layouts
            cr.Antialias = Cairo.Antialias.Default;

            if (renderTrack)
            {
                cr.MoveTo(x, y);
                cr.Color = TextColor;
                PangoCairoHelper.ShowLayout(cr, first_line_layout);
            }

            if (!renderArtistAlbum)
            {
                return;
            }

            cr.MoveTo(x, y + fl_height);
            PangoCairoHelper.ShowLayout(cr, second_line_layout);
        }
示例#3
0
        protected override void ClippedRender(Data.Gui.CellContext context)
        {
            if (!EnsureLayout())
            {
                return;
            }

            var cr = context.Context;

            Foreground = new Brush(context.Theme.Colors.GetWidgetColor(
                                       context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, context.State));

            var foreground = Foreground;

            if (!foreground.IsValid)
            {
                return;
            }

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

            bool fade = Fade && text_alloc.Width > RenderSize.Width;

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

            cr.MoveTo(text_alloc.X, text_alloc.Y);
            Foreground.Apply(cr);
            UpdateLayout(GetText(), RenderSize.Width, RenderSize.Height, true);
            if (Hyena.PlatformDetection.IsWindows)
            {
                // FIXME windows; working around some unknown issue with ShowLayout; bgo#644311

                cr.Antialias = Cairo.Antialias.None;
                PangoCairoHelper.LayoutPath(cr, layout, true);
            }
            else
            {
                PangoCairoHelper.ShowLayout(cr, layout);
            }
            cr.Fill();

            TooltipMarkup = layout.IsEllipsized ? last_formatted_text : null;

            if (fade)
            {
                var 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.Dispose();
            }

            cr.ResetClip();
        }
示例#4
0
        private void RenderLabels(Context cr)
        {
            if (segments.Count == 0)
            {
                return;
            }

            Pango.Layout layout           = null;
            Gdk.RGBA     rgba             = StyleContext.GetColor(StateFlags);
            Color        text_color       = CairoExtensions.GdkRGBAToCairoColor(rgba);
            Color        box_stroke_color = new Color(0, 0, 0, 0.6);

            int x = 0;

            foreach (Segment segment in segments)
            {
                cr.LineWidth = 1;
                cr.Rectangle(x + 0.5, 2 + 0.5, segment_box_size - 1, segment_box_size - 1);
                LinearGradient grad = MakeSegmentGradient(segment_box_size, segment.Color, true);
                cr.Pattern = grad;
                cr.FillPreserve();
                cr.Color = box_stroke_color;
                cr.Stroke();
                grad.Destroy();

                x += segment_box_size + segment_box_spacing;

                int lw, lh;
                layout = CreateAdaptLayout(layout, false, true);
                layout.SetText(FormatSegmentText(segment));
                layout.GetPixelSize(out lw, out lh);

                cr.MoveTo(x, 0);
                text_color.A = 0.9;
                cr.Color     = text_color;
                PangoCairoHelper.ShowLayout(cr, layout);
                cr.Fill();

                layout = CreateAdaptLayout(layout, true, false);
                layout.SetText(FormatSegmentValue(segment));

                cr.MoveTo(x, lh);
                text_color.A = 0.75;
                cr.Color     = text_color;
                PangoCairoHelper.ShowLayout(cr, layout);
                cr.Fill();

                x += segment.LayoutWidth + segment_label_spacing;
            }

            layout.Dispose();
        }
示例#5
0
        void RenderLabels(Context cr)
        {
            if (segments.Count == 0)
            {
                return;
            }

            Pango.Layout layout           = null;
            Color        text_color       = CairoExtensions.GdkColorToCairoColor(Style.Foreground(State));
            var          box_stroke_color = new Color(0, 0, 0, 0.6);

            int x = 0;

            foreach (var segment in segments)
            {
                cr.LineWidth = 1;
                cr.Rectangle(x + 0.5, 2 + 0.5, segment_box_size - 1, segment_box_size - 1);
                var grad = MakeSegmentGradient(segment_box_size, segment.Color, true);
                cr.SetSource(grad);
                cr.FillPreserve();
                cr.SetSourceColor(box_stroke_color);
                cr.Stroke();
                grad.Dispose();

                x += segment_box_size + segment_box_spacing;

                int lw, lh;
                layout = CreateAdaptLayout(layout, false, true);
                layout.SetText(FormatSegmentText(segment));
                layout.GetPixelSize(out lw, out lh);

                cr.MoveTo(x, 0);
                text_color.A = 0.9;
                cr.SetSourceColor(text_color);
                PangoCairoHelper.ShowLayout(cr, layout);
                cr.Fill();

                layout = CreateAdaptLayout(layout, true, false);
                layout.SetText(FormatSegmentValue(segment));

                cr.MoveTo(x, lh);
                text_color.A = 0.75;
                cr.SetSourceColor(text_color);
                PangoCairoHelper.ShowLayout(cr, layout);
                cr.Fill();

                x += segment.LayoutWidth + segment_label_spacing;
            }

            layout.Dispose();
        }
示例#6
0
        //int? height;
        //public override Size Measure (Size available)
        //{
        //int min, max;
        //GetWidthRange (ParentLayout.View.PangoLayout, out min, out max);
        //

        /*if (height == null) {
         *  using (var layout = new Pango.Layout (ParentLayout.View.PangoContext)) {
         *      if (layout.FontDescription == null) {
         *          layout.FontDescription = new Pango.FontDescription ();
         *      }
         *      UpdateText (layout, 100, "Woo Mar");
         *      height = TextHeight;
         *  }
         * }*/

        //return FixedSize ?? new Size (0, (double)height + Padding.Y);
        //}

        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            UpdateText(context, cellWidth);
            if (String.IsNullOrEmpty(last_text))
            {
                return;
            }

            //context.Context.Rectangle (0, 0, cellWidth, cellHeight);
            //context.Context.Clip ();
            context.Context.MoveTo(Padding.Left, ((int)cellHeight - text_height) / 2);
            Cairo.Color color = context.Theme.Colors.GetWidgetColor(
                context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, context.State);
            color.A = Alpha ?? (context.Opaque ? 1.0 : 0.5);
            context.Context.SetSourceColor(color);

            PangoCairoHelper.ShowLayout(context.Context, context.Layout);
            //context.Context.ResetClip ();
        }
示例#7
0
        //int? height;
        //public override Size Measure (Size available)
        //{
        //int min, max;
        //GetWidthRange (ParentLayout.View.PangoLayout, out min, out max);
        //

        /*if (height == null) {
         *  using (var layout = new Pango.Layout (ParentLayout.View.PangoContext)) {
         *      if (layout.FontDescription == null) {
         *          layout.FontDescription = new Pango.FontDescription ();
         *      }
         *      UpdateText (layout, 100, "Woo Mar");
         *      height = TextHeight;
         *  }
         * }*/

        //return FixedSize ?? new Size (0, (double)height + Padding.Y);
        //}

        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            UpdateText(context, cellWidth);
            if (String.IsNullOrEmpty(last_text))
            {
                return;
            }

            //context.Context.Rectangle (0, 0, cellWidth, cellHeight);
            //context.Context.Clip ();
            context.Context.MoveTo(Padding.Left, ((int)cellHeight - text_height) / 2);
            var color = CairoExtensions.GdkRGBAToCairoColor(context.Theme.Widget.StyleContext.GetColor(context.State));

            color.A = Alpha ?? (context.Opaque ? 1.0 : 0.5);
            context.Context.Color = color;

            PangoCairoHelper.ShowLayout(context.Context, context.Layout);
            //context.Context.ResetClip ();
        }
示例#8
0
        protected override void RenderTrackInfo(Context cr, TrackInfo track, bool renderTrack, bool renderArtistAlbum)
        {
            if (track == null)
            {
                return;
            }

            Gdk.Rectangle alloc = RenderAllocation;
            int           width = ArtworkSizeRequest;
            int           fl_width, fl_height, sl_width, sl_height, tl_width, tl_height;
            int           pango_width = (int)(width * Pango.Scale.PangoScale);

            string first_line = GetFirstLineText(track);

            // FIXME: This is incredibly bad, but we don't want to break
            // translations right now. It needs to be replaced for 1.4!!
            string line = GetSecondLineText(track);
            string second_line = line, third_line = String.Empty;
            int    split_pos = line.LastIndexOf("<span");

            if (split_pos >= 0
                // Check that there are at least 3 spans in the string, else this
                // will break for tracks with missing artist or album info.
                && StringUtil.SubstringCount(line, "<span") >= 3)
            {
                second_line = line.Substring(0, Math.Max(0, split_pos - 1)) + "</span>";
                third_line  = String.Format("<span color=\"{0}\">{1}",
                                            CairoExtensions.ColorGetHex(TextColor, false),
                                            line.Substring(split_pos, line.Length - split_pos));
            }

            if (first_line_layout == null)
            {
                first_line_layout           = CairoExtensions.CreateLayout(this, cr);
                first_line_layout.Ellipsize = Pango.EllipsizeMode.End;
                first_line_layout.Alignment = Pango.Alignment.Right;

                int base_size = first_line_layout.FontDescription.Size;
                first_line_layout.FontDescription.Size = (int)(base_size * Pango.Scale.XLarge);
            }

            if (second_line_layout == null)
            {
                second_line_layout           = CairoExtensions.CreateLayout(this, cr);
                second_line_layout.Ellipsize = Pango.EllipsizeMode.End;
                second_line_layout.Alignment = Pango.Alignment.Right;
            }

            if (third_line_layout == null)
            {
                third_line_layout           = CairoExtensions.CreateLayout(this, cr);
                third_line_layout.Ellipsize = Pango.EllipsizeMode.End;
                third_line_layout.Alignment = Pango.Alignment.Right;
            }

            // Set up the text layouts
            first_line_layout.Width  = pango_width;
            second_line_layout.Width = pango_width;
            third_line_layout.Width  = pango_width;

            // Compute the layout coordinates
            first_line_layout.SetMarkup(first_line);
            first_line_layout.GetPixelSize(out fl_width, out fl_height);
            second_line_layout.SetMarkup(second_line);
            second_line_layout.GetPixelSize(out sl_width, out sl_height);
            third_line_layout.SetMarkup(third_line);
            third_line_layout.GetPixelSize(out tl_width, out tl_height);

            text_alloc.X      = alloc.X;
            text_alloc.Width  = width;
            text_alloc.Height = fl_height + sl_height + tl_height;
            text_alloc.Y      = alloc.Y + (ArtworkSizeRequest - text_alloc.Height) / 2;

            // Render the layouts
            cr.Antialias = Cairo.Antialias.Default;

            if (renderTrack)
            {
                cr.MoveTo(text_alloc.X, text_alloc.Y);
                cr.Color = TextColor;
                PangoCairoHelper.ShowLayout(cr, first_line_layout);
            }

            if (!renderArtistAlbum)
            {
                return;
            }

            cr.MoveTo(text_alloc.X, text_alloc.Y + fl_height);
            PangoCairoHelper.ShowLayout(cr, second_line_layout);

            cr.MoveTo(text_alloc.X, text_alloc.Y + fl_height + sl_height);
            PangoCairoHelper.ShowLayout(cr, third_line_layout);
        }
示例#9
0
        public override void Render(CellContext context, StateType state, double cellWidth, double cellHeight)
        {
            if (BoundObject == null)
            {
                return;
            }

            if (!(BoundObject is AlbumInfo))
            {
                throw new InvalidCastException("ColumnCellAlbum can only bind to AlbumInfo objects");
            }

            AlbumInfo album = (AlbumInfo)BoundObject;

            bool         is_default = false;
            ImageSurface image      = artwork_manager == null ? null
                : artwork_manager.LookupScaleSurface(album.ArtworkId, image_size, true);

            if (image == null)
            {
                image      = default_cover_image;
                is_default = true;
            }

            // int image_render_size = is_default ? image.Height : (int)cellHeight - 8;
            int image_render_size = image_size;
            int x = image_spacing;
            int y = ((int)cellHeight - image_render_size) / 2;

            ArtworkRenderer.RenderThumbnail(context.Context, image, false, x, y,
                                            image_render_size, image_render_size, !is_default, context.Theme.Context.Radius);

            int fl_width = 0, fl_height = 0, sl_width = 0, sl_height = 0;

            Cairo.Color text_color = context.Theme.Colors.GetWidgetColor(GtkColorClass.Text, state);
            text_color.A = 0.75;

            Pango.Layout layout = context.Layout;
            layout.Width     = (int)((cellWidth - cellHeight - x - 10) * Pango.Scale.PangoScale);
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.FontDescription.Weight = Pango.Weight.Bold;

            // Compute the layout sizes for both lines for centering on the cell
            int old_size = layout.FontDescription.Size;

            layout.SetText(album.DisplayTitle);
            layout.GetPixelSize(out fl_width, out fl_height);

            if (!String.IsNullOrEmpty(album.ArtistName))
            {
                layout.FontDescription.Weight = Pango.Weight.Normal;
                layout.FontDescription.Size   = (int)(old_size * Pango.Scale.Small);
                layout.FontDescription.Style  = Pango.Style.Italic;
                layout.SetText(album.ArtistName);
                layout.GetPixelSize(out sl_width, out sl_height);
            }

            // Calculate the layout positioning
            x = ((int)cellHeight - x) + 10;
            y = (int)((cellHeight - (fl_height + sl_height)) / 2);

            // Render the second line first since we have that state already
            if (!String.IsNullOrEmpty(album.ArtistName))
            {
                context.Context.MoveTo(x, y + fl_height);
                context.Context.Color = text_color;
                PangoCairoHelper.ShowLayout(context.Context, layout);
            }

            // Render the first line, resetting the state
            layout.SetText(album.DisplayTitle);
            layout.FontDescription.Weight = Pango.Weight.Bold;
            layout.FontDescription.Size   = old_size;
            layout.FontDescription.Style  = Pango.Style.Normal;

            layout.SetText(album.DisplayTitle);

            context.Context.MoveTo(x, y);
            text_color.A          = 1;
            context.Context.Color = text_color;
            PangoCairoHelper.ShowLayout(context.Context, layout);
        }
示例#10
0
        protected override bool OnExposeEvent(Gdk.EventExpose args)
        {
            using (var context = Gdk.CairoHelper.Create(args.Window)) {
                context.LineWidth = 1;
                var alloc  = Allocation;
                int width  = alloc.Width;
                int height = alloc.Height;
                context.Rectangle(args.Area.X, args.Area.Y, args.Area.Width, args.Area.Height);
                context.Color = this.backgroundColor;
                context.Fill();

                int xpos = iconTextSpacing;
                int yPos = (int)-vadj.Value;

                //when there are no matches, display a message to indicate that the completion list is still handling input
                if (filteredItems.Count == 0)
                {
                    context.Rectangle(0, yPos, width, height - yPos);
                    context.Color = backgroundColor;
                    context.Stroke();
                    noMatchLayout.SetText(win.DataProvider.ItemCount == 0 ? NoSuggestionsMsg : NoMatchesMsg);
                    int lWidth, lHeight;
                    noMatchLayout.GetPixelSize(out lWidth, out lHeight);
                    context.Color = textColor;
                    context.MoveTo((width - lWidth) / 2, yPos + (height - lHeight - yPos) / 2 - lHeight);
                    PangoCairoHelper.ShowLayout(context, noMatchLayout);
                    return(false);
                }

                var matcher = CompletionMatcher.CreateCompletionMatcher(CompletionString);
                Iterate(true, ref yPos, delegate(Category category, int ypos) {
                    if (ypos >= height)
                    {
                        return;
                    }
                    if (ypos < -rowHeight)
                    {
                        return;
                    }

                    //	window.DrawRectangle (this.Style.BackgroundGC (StateType.Insensitive), true, 0, yPos, width, rowHeight);
                    int x = 2;
                    if (category.CompletionCategory != null && !string.IsNullOrEmpty(category.CompletionCategory.Icon))
                    {
                        var icon = ImageService.GetPixbuf(category.CompletionCategory.Icon, IconSize.Menu);
                        Gdk.CairoHelper.SetSourcePixbuf(context, icon, 0, ypos);
                        context.Paint();
                        x = icon.Width + 4;
                    }
                    context.Rectangle(0, ypos, Allocation.Width, rowHeight);
                    context.Color = backgroundColor;
                    context.Fill();


//					layout.SetMarkup ("<span weight='bold' foreground='#AAAAAA'>" + (category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized") + "</span>");
//					window.DrawLayout (textGCInsensitive, x - 1, ypos + 1 + (rowHeight - py) / 2, layout);
//					layout.SetMarkup ("<span weight='bold'>" + (category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized") + "</span>");
                    categoryLayout.SetMarkup((category.CompletionCategory != null ? category.CompletionCategory.DisplayText : "Uncategorized"));
                    int px, py;
                    categoryLayout.GetPixelSize(out px, out py);
                    context.MoveTo(x, ypos + (rowHeight - py) / 2);
                    context.Color = textColor;
                    PangoCairoHelper.ShowLayout(context, categoryLayout);
                }, delegate(Category curCategory, int item, int itemidx, int ypos) {
                    if (ypos >= height)
                    {
                        return(false);
                    }
                    if (ypos < -rowHeight)
                    {
                        return(true);
                    }
                    const int categoryModeItemIndenting = 0;
                    if (InCategoryMode && curCategory != null && curCategory.CompletionCategory != null)
                    {
                        xpos = iconTextSpacing + categoryModeItemIndenting;
                    }
                    else
                    {
                        xpos = iconTextSpacing;
                    }
                    string markup      = win.DataProvider.HasMarkup(item) ? (win.DataProvider.GetMarkup(item) ?? "&lt;null&gt;") : GLib.Markup.EscapeText(win.DataProvider.GetText(item) ?? "<null>");
                    string description = win.DataProvider.GetDescription(item);

                    if (string.IsNullOrEmpty(description))
                    {
                        layout.SetMarkup(markup);
                    }
                    else
                    {
                        if (item == SelectedItem)
                        {
                            layout.SetMarkup(markup + " " + description);
                        }
                        else
                        {
                            layout.SetMarkup(markup + " <span foreground=\"darkgray\">" + description + "</span>");
                        }
                    }

                    string text = win.DataProvider.GetText(item);

                    if (!string.IsNullOrEmpty(text))
                    {
                        int[] matchIndices = matcher.GetMatch(text);
                        if (matchIndices != null)
                        {
                            Pango.AttrList attrList = layout.Attributes ?? new Pango.AttrList();
                            for (int newSelection = 0; newSelection < matchIndices.Length; newSelection++)
                            {
                                int idx       = matchIndices [newSelection];
                                var fg        = new AttrForeground((ushort)(highlightColor.R * ushort.MaxValue), (ushort)(highlightColor.G * ushort.MaxValue), (ushort)(highlightColor.B * ushort.MaxValue));
                                fg.StartIndex = (uint)idx;
                                fg.EndIndex   = (uint)(idx + 1);
                                attrList.Insert(fg);
                            }
                            layout.Attributes = attrList;
                        }
                    }

                    Gdk.Pixbuf icon = win.DataProvider.GetIcon(item);
                    int iconHeight, iconWidth;
                    if (icon != null)
                    {
                        iconWidth  = icon.Width;
                        iconHeight = icon.Height;
                    }
                    else if (!Gtk.Icon.SizeLookup(Gtk.IconSize.Menu, out iconWidth, out iconHeight))
                    {
                        iconHeight = iconWidth = 24;
                    }

                    int wi, he, typos, iypos;
                    layout.GetPixelSize(out wi, out he);


                    typos = he < rowHeight ? ypos + (rowHeight - he) / 2 : ypos;
                    iypos = iconHeight < rowHeight ? ypos + (rowHeight - iconHeight) / 2 : ypos;
                    if (item == SelectedItem)
                    {
                        context.Rectangle(0, ypos, Allocation.Width, rowHeight / 2);
                        context.Color = SelectionEnabled ? selectedItemColor.Foreground : selectedItemInactiveColor.Background;
                        context.Fill();
                        context.Rectangle(0, ypos + rowHeight / 2, Allocation.Width, rowHeight / 2);
                        context.Color = SelectionEnabled ? selectedItemColor.Background : selectedItemInactiveColor.Background;
                        context.Fill();

                        context.Rectangle(0.5, ypos + 0.5, Allocation.Width - 1, rowHeight - 1);
                        if (!SelectionEnabled)
                        {
                            context.SetDash(new double[] { 4, 4 }, 0);
                        }
                        context.Color = SelectionEnabled ? selectionBorderColor : selectionBorderInactiveColor;
                        context.Stroke();
                    }

                    if (icon != null)
                    {
                        Gdk.CairoHelper.SetSourcePixbuf(context, icon, xpos, iypos);
                        context.Paint();
                        xpos += iconTextSpacing;
                    }
                    context.Color = textColor;
                    context.MoveTo(xpos + iconWidth + 2, typos);
                    PangoCairoHelper.ShowLayout(context, layout);

                    if (wi + xpos + iconWidth + 2 > listWidth)
                    {
                        WidthRequest = listWidth = wi + xpos + iconWidth + 2 + iconTextSpacing;
                        win.ResetSizes();
                    }
                    else
                    {
                        //workaround for the vscrollbar display - the calculated width needs to be the width ofthe render region.
                        if (Allocation.Width < listWidth)
                        {
                            if (listWidth - Allocation.Width < 30)
                            {
                                WidthRequest = listWidth + listWidth - Allocation.Width;
                                win.ResetSizes();
                            }
                        }
                    }


                    layout.SetMarkup("");
                    if (layout.Attributes != null)
                    {
                        layout.Attributes.Dispose();
                        layout.Attributes = null;
                    }
                    return(true);
                });

                return(false);
            }
        }
示例#11
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();
        }
示例#12
0
        public override void Render(CellContext context, StateType state, double cellWidth, double cellHeight)
        {
            if (BoundObject == null)
            {
                return;
            }

            if (!(BoundObject is Feed))
            {
                throw new InvalidCastException("ColumnCellPodcast can only bind to Feed objects");
            }

            Feed feed = (Feed)BoundObject;

            bool         is_default = false;
            ImageSurface image      = artwork_manager == null ? null
                : artwork_manager.LookupScaleSurface(PodcastService.ArtworkIdFor(feed), image_size, true);

            if (image == null)
            {
                image      = default_cover_image;
                is_default = true;
            }

            // int image_render_size = is_default ? image.Height : (int)cellHeight - 8;
            int image_render_size = image_size;
            int x = image_spacing;
            int y = ((int)cellHeight - image_render_size) / 2;

            ArtworkRenderer.RenderThumbnail(context.Context, image, false, x, y,
                                            image_render_size, image_render_size, !is_default, context.Theme.Context.Radius);

            int fl_width = 0, fl_height = 0, sl_width = 0, sl_height = 0;

            Cairo.Color text_color = context.Theme.Colors.GetWidgetColor(GtkColorClass.Text, state);
            text_color.A = 0.75;

            Pango.Layout layout = context.Layout;
            layout.Width     = (int)((cellWidth - cellHeight - x - 10) * Pango.Scale.PangoScale);
            layout.Ellipsize = Pango.EllipsizeMode.End;
            layout.FontDescription.Weight = Pango.Weight.Bold;

            // Compute the layout sizes for both lines for centering on the cell
            int old_size = layout.FontDescription.Size;

            layout.SetText(feed.Title ?? String.Empty);
            layout.GetPixelSize(out fl_width, out fl_height);

            if (feed.DbId > 0)
            {
                layout.FontDescription.Weight = Pango.Weight.Normal;
                layout.FontDescription.Size   = (int)(old_size * Pango.Scale.Small);
                layout.FontDescription.Style  = Pango.Style.Italic;

                if (feed.LastDownloadTime == DateTime.MinValue)
                {
                    layout.SetText(Catalog.GetString("Never updated"));
                }
                else if (feed.LastDownloadTime.Date == DateTime.Now.Date)
                {
                    layout.SetText(String.Format(Catalog.GetString("Updated at {0}"), feed.LastDownloadTime.ToShortTimeString()));
                }
                else
                {
                    layout.SetText(String.Format(Catalog.GetString("Updated {0}"), Hyena.Query.RelativeTimeSpanQueryValue.RelativeToNow(feed.LastDownloadTime).ToUserQuery()));
                }
                layout.GetPixelSize(out sl_width, out sl_height);
            }

            // Calculate the layout positioning
            x = ((int)cellHeight - x) + 10;
            y = (int)((cellHeight - (fl_height + sl_height)) / 2);

            // Render the second line first since we have that state already
            if (feed.DbId > 0)
            {
                context.Context.MoveTo(x, y + fl_height);
                context.Context.Color = text_color;
                PangoCairoHelper.ShowLayout(context.Context, layout);
            }

            // Render the first line, resetting the state
            layout.SetText(feed.Title ?? String.Empty);
            layout.FontDescription.Weight = Pango.Weight.Bold;
            layout.FontDescription.Size   = old_size;
            layout.FontDescription.Style  = Pango.Style.Normal;

            layout.SetText(feed.Title ?? String.Empty);

            context.Context.MoveTo(x, y);
            text_color.A          = 1;
            context.Context.Color = text_color;
            PangoCairoHelper.ShowLayout(context.Context, layout);
        }