protected override void ClippedRender(CellContext context) { var artwork_id = BoundObject as string; var image_surface = artwork_id != null && artwork_manager != null ? artwork_manager.LookupScaleSurface (artwork_id, (int)ImageSize, true) : null; ArtworkRenderer.RenderThumbnail (context.Context, image_surface, false, 0, 0, ImageSize, ImageSize, true, context.Theme.Context.Radius, image_surface == null, new Color (0.8, 0.8, 0.8) ); }
public override void Render(CellContext context, 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; context.Widget.StyleContext.Save(); context.Widget.StyleContext.AddClass("entry"); Cairo.Color text_color = CairoExtensions.GdkRGBAToCairoColor(context.Widget.StyleContext.GetColor(StateFlags.Selected)); context.Widget.StyleContext.Restore(); 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.SetSourceColor(text_color); Pango.CairoHelper.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.SetSourceColor(text_color); Pango.CairoHelper.ShowLayout(context.Context, layout); }