示例#1
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);
        }