Пример #1
0
 protected virtual void RenderCoverArt(Cairo.Context cr, ImageSurface image)
 {
     ArtworkRenderer.RenderThumbnail(cr, image, false, Allocation.X, Allocation.Y,
                                     ArtworkSizeRequest, ArtworkSizeRequest,
                                     !IsMissingImage(image), 0,
                                     IsMissingImage(image), BackgroundColor);
 }
        private bool RenderArtistImage(string imagePath, CellContext context)
        {
            // majority of artist images has size 400 * 155
            int originalImageWidth = 400;
            int orginalImageHeight = 155;

            double scale = 0.22;

            // calculate size:
            int spacing      = 0;
            int thumb_height = (int)(orginalImageHeight * scale);
            int thumb_width  = (int)(originalImageWidth * scale);

            Gdk.Pixbuf artistPixbuf = null;
            artistPixbuf = new Gdk.Pixbuf(imagePath);

            if (artistPixbuf != null)
            {
                artistPixbuf = artistPixbuf.ScaleSimple(thumb_width, thumb_height, Gdk.InterpType.Bilinear);
                bool has_border = false;
                using (var artistImage = PixbufImageSurface.Create(artistPixbuf)) {
                    // display get artist image:
                    ArtworkRenderer.RenderThumbnail(context.Context, artistImage, false,
                                                    spacing, spacing,
                                                    thumb_width, thumb_height,
                                                    has_border, context.Theme.Context.Radius);
                }
                return(true);
            }
            return(false);
        }
Пример #3
0
        protected override void RenderIdle(Cairo.Context cr)
        {
            idle_album = idle_album ?? PixbufImageSurface.Create(Banshee.Gui.IconThemeUtils.LoadIcon(
                                                                     ArtworkSizeRequest, MissingAudioIconName), true);

            ArtworkRenderer.RenderThumbnail(cr, idle_album, false, 0, 0,
                                            ArtworkSizeRequest, ArtworkSizeRequest,
                                            false, 0, true, BackgroundColor);
        }
Пример #4
0
        protected override void RenderIdle(Cairo.Context cr)
        {
            idle_album = idle_album ?? PixbufImageSurface.Create(Banshee.Gui.IconThemeUtils.LoadIcon(
                                                                     ArtworkSizeRequest, "media-optical"), true);

            ArtworkRenderer.RenderThumbnail(cr, idle_album, false, Allocation.X, Allocation.Y,
                                            ArtworkSizeRequest, ArtworkSizeRequest,
                                            false, 0, true, BackgroundColor);
        }
Пример #5
0
 protected override void RenderIdle(Context cr)
 {
     ArtworkRenderer.RenderThumbnail(cr,
                                     image:      null,// Uses the Banshee vector logo
                                     dispose:    false,
                                     x:          0,
                                     y:          0,
                                     width:      ArtworkSizeRequest,
                                     height:     ArtworkSizeRequest,
                                     drawBorder: false,
                                     radius:     0,
                                     fill:       true,
                                     fillColor:  BackgroundColor);
 }
Пример #6
0
 protected override void RenderIdle(Context cr)
 {
     ArtworkRenderer.RenderThumbnail(cr, null, false, 0, 0, ArtworkSizeRequest, ArtworkSizeRequest, false, 0, true, BackgroundColor);
 }
Пример #7
0
        public override void Render(CellContext context, 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;

            context.Widget.StyleContext.Save();
            context.Widget.StyleContext.AddClass("cell");
            context.StyleContext.State |= context.State;
            Cairo.Color text_color = CairoExtensions.GdkRGBAToCairoColor(context.Widget.StyleContext.GetColor(context.StyleContext.State));
            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(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.SetSourceColor(text_color);
                Pango.CairoHelper.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.SetSourceColor(text_color);
            Pango.CairoHelper.ShowLayout(context.Context, layout);
        }
        public override void Render(CellContext context, double cellWidth, double cellHeight)
        {
            if (!artwork_initialized)
            {
                artwork_manager = ServiceManager.Get <ArtworkManager> ();

                if (!artwork_manager.IsCachedSize(image_size))
                {
                    artwork_manager.AddCachedSize(image_size);
                }
                if (artwork_manager != null)
                {
                    artwork_manager.ChangeCacheSize(ImageSize, GetAllAlbumsCount() + 3);
                }

                artwork_initialized = true;
            }

            bool is_queryalble_source = ServiceManager.SourceManager.ActiveSource is PrimarySource;

            is_queryalble_source = is_queryalble_source || ServiceManager.SourceManager.ActiveSource is PlaylistSource;
            is_queryalble_source = is_queryalble_source || ServiceManager.SourceManager.ActiveSource is SmartPlaylistSource;

            if (BoundObject == null)
            {
                return;
            }

            if (!(BoundObject is ArtistInfo))
            {
                throw new InvalidCastException("ColumnCellArtist can only bind to ArtistInfo objects");
            }
            var artist = (ArtistInfo)BoundObject;

            DatabaseArtistInfo db_artist = DatabaseArtistInfo.FindOrCreate(artist.Name, artist.NameSort);

            AlbumInfo[] albums      = GetAlbums(db_artist.DbId);
            int         album_count = albums.Length;

            string pattern = Catalog.GetString("All Artists ({0})")
                             .Replace("(", "\\(")
                             .Replace(")", "\\)")
                             .Replace("{0}", "[0-9]+");

            if (!String.IsNullOrEmpty(artist.Name) && System.Text.RegularExpressions.Regex.IsMatch(artist.Name, pattern))
            {
                album_count = GetAllAlbumsCount();
            }

            ImageSurface image  = null;
            var          images = new List <ImageSurface> ();

            int non_empty = 0;

            for (int i = 0; i < albums.Length && non_empty < 3; i++)
            {
                if (artwork_manager != null)
                {
                    ImageSurface sur = artwork_manager.LookupScaleSurface(albums [i].ArtworkId, image_size, true);
                    images.Add(sur);
                    if (sur != null)
                    {
                        non_empty++;
                    }
                }
            }

            //bringing non-empty images to the front
            images.Sort(delegate(ImageSurface a, ImageSurface b) {
                if (a == null && b != null)
                {
                    return(-1);
                }
                if (a != null && b == null)
                {
                    return(1);
                }
                return(0);
            });

            if (images.Count > 3)
            {
                images.RemoveRange(3, images.Count - 3);
            }

            bool is_default = false;

            if (images.Count == 0)
            {
                image      = default_cover_image;
                is_default = true;
            }
            else
            {
                image = images[images.Count - 1];
            }

            int image_render_size = image_size;
            int x = image_spacing;
            int y = image_spacing;

            if (use_small_images)
            {
                x = image_spacing / 2;
                y = image_spacing / 2;
            }

            const int y_image_spacing = 1;
            int       x_offset        = (use_small_images ? album_spacing_small : album_spacing_normal);

            if (images.Count > 1)
            {
                x_offset *= 2;
            }
            int y_offset = (images.Count > 1) ? y_image_spacing * 2 : y_image_spacing;

            for (int i = 0; i < images.Count - 1; i++)
            {
                int move_x = x + ((i) * (use_small_images ? album_spacing_small : album_spacing_normal));
                int move_y = y + ((i) * y_image_spacing);
                ArtworkRenderer.RenderThumbnail(context.Context, images[i], false, move_x, move_y,
                                                image_render_size, image_render_size, !is_default, context.Theme.Context.Radius, true, new Color(1.0, 1.0, 1.0, 1.0));
            }

            if (images.Count > 0)
            {
                ArtworkRenderer.RenderThumbnail(context.Context, image, false, x + x_offset, y + y_offset,
                                                image_render_size, image_render_size, !is_default, context.Theme.Context.Radius, true, new Color(1.0, 1.0, 1.0, 1.0));
            }
            else
            {
                ArtworkRenderer.RenderThumbnail(context.Context, image, false, x + x_offset, y + y_offset,
                                                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");
            Color text_color = CairoExtensions.GdkRGBAToCairoColor(context.Widget.StyleContext.GetColor(context.State));

            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(artist.DisplayName);
            layout.GetPixelSize(out fl_width, out fl_height);

            layout.FontDescription.Weight = Pango.Weight.Normal;
            layout.FontDescription.Size   = (int)(old_size * Pango.Scale.Small);
            layout.FontDescription.Style  = Pango.Style.Italic;

            string album_string_singular = Catalog.GetString("Album");
            string album_string_plural   = Catalog.GetString("Albums");

            layout.SetText(album_count + " " + ((album_count == 1) ? album_string_singular : album_string_plural));
            layout.GetPixelSize(out sl_width, out sl_height);

            // Calculate the layout positioning
            x = ((int)cellHeight - x) + (use_small_images ? album_spacing_small : album_spacing_normal) + 8;
            y = use_small_images ? (int)((cellHeight - (fl_height)) / 2) : (int)((cellHeight - (fl_height + sl_height)) / 2);

            // Render the second line first since we have that state already
            if (album_count > 0 && is_queryalble_source)
            {
                if (use_small_images)
                {
                    context.Context.MoveTo(cellWidth - sl_width - image_spacing, y + image_spacing / 2);
                }
                else
                {
                    context.Context.MoveTo(x, y + fl_height);
                }
                context.Context.SetSourceColor(text_color);
                if (!use_small_images || fl_width + x + sl_width <= cellWidth)
                {
                    Pango.CairoHelper.ShowLayout(context.Context, layout);
                }
            }

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

            layout.SetText(artist.DisplayName);

            context.Context.MoveTo(x, y);
            text_color.A = 1;
            context.Context.SetSourceColor(text_color);
            Pango.CairoHelper.ShowLayout(context.Context, layout);
        }