Exemple #1
0
        public async Task LoadItemThumbnail()
        {
            ILibraryItem      libraryItem      = listViewItem.Model;
            ILibraryContainer libraryContainer = listViewItem.Container;

            // Load from cache via LibraryID
            var thumbnail = ApplicationController.Instance.Thumbnails.LoadCachedImage(libraryItem, thumbWidth, thumbHeight);

            if (thumbnail != null)
            {
                this.SetItemThumbnail(thumbnail);
                return;
            }

            if (thumbnail == null)
            {
                // Ask the container - allows the container to provide its own interpretation of the item thumbnail
                thumbnail = await libraryContainer.GetThumbnail(libraryItem, thumbWidth, thumbHeight);
            }

            if (thumbnail == null && libraryItem is IThumbnail)
            {
                // If the item provides its own thumbnail, try to collect it
                thumbnail = await(libraryItem as IThumbnail).GetThumbnail(thumbWidth, thumbHeight);
            }

            if (thumbnail == null)
            {
                // Ask content provider - allows type specific thumbnail creation
                var contentProvider = ApplicationController.Instance.Library.GetContentProvider(libraryItem);
                if (contentProvider != null)
                {
                    // Before we have a thumbnail set to the content specific thumbnail
                    thumbnail = contentProvider.DefaultImage;

                    if (contentProvider is MeshContentProvider meshContentProvider)
                    {
                        // Store meshContentProvider reference
                        this.meshContentProvider = meshContentProvider;

                        // Schedule work
                        this.ScheduleRaytraceOperation();
                    }
                    else
                    {
                        // Show processing image
                        this.SetItemThumbnail(theme.GeneratingThumbnailIcon);

                        // Ask the provider for a content specific thumbnail
                        thumbnail = await contentProvider.GetThumbnail(libraryItem, thumbWidth, thumbHeight);
                    }
                }
            }

            if (thumbnail == null)
            {
                // Use the listview defaults
                thumbnail = ((libraryItem is ILibraryContainerLink) ? defaultFolderIcon : defaultItemIcon).AlphaToPrimaryAccent();
            }

            this.SetItemThumbnail(thumbnail);
        }
Exemple #2
0
        public async Task LoadItemThumbnail(Action <ImageBuffer> thumbnailListener, Action <MeshContentProvider> buildThumbnail, ILibraryItem libraryItem, ILibraryContainer libraryContainer, int thumbWidth, int thumbHeight, ThemeConfig theme)
        {
            void setItemThumbnail(ImageBuffer icon)
            {
                if (icon != null)
                {
                    icon = this.EnsureCorrectThumbnailSizing(icon, thumbWidth, thumbHeight);
                    thumbnailListener?.Invoke(icon);
                }
            }

            // Load from cache via LibraryID
            var thumbnail = ApplicationController.Instance.Thumbnails.LoadCachedImage(libraryItem, thumbWidth, thumbHeight);

            if (thumbnail != null)
            {
                setItemThumbnail(thumbnail);
                return;
            }

            if (thumbnail == null && libraryContainer != null)
            {
                // Ask the container - allows the container to provide its own interpretation of the item thumbnail
                thumbnail = await libraryContainer.GetThumbnail(libraryItem, thumbWidth, thumbHeight);
            }

            if (thumbnail == null && libraryItem is IThumbnail)
            {
                // If the item provides its own thumbnail, try to collect it
                thumbnail = await(libraryItem as IThumbnail).GetThumbnail(thumbWidth, thumbHeight);
            }

            if (thumbnail == null)
            {
                // Ask content provider - allows type specific thumbnail creation
                var contentProvider = ApplicationController.Instance.Library.GetContentProvider(libraryItem);
                if (contentProvider != null)
                {
                    // Before we have a thumbnail set to the content specific thumbnail
                    thumbnail = contentProvider.DefaultImage;

                    if (contentProvider is MeshContentProvider meshContentProvider)
                    {
                        buildThumbnail?.Invoke(meshContentProvider);
                    }
                    else
                    {
                        // Show processing image
                        setItemThumbnail(theme.GeneratingThumbnailIcon);

                        // Ask the provider for a content specific thumbnail
                        thumbnail = await contentProvider.GetThumbnail(libraryItem, thumbWidth, thumbHeight);
                    }
                }
            }

            if (thumbnail == null)
            {
                // Use the listview defaults
                if (thumbHeight < 24 && thumbWidth < 24)
                {
                    thumbnail = ((libraryItem is ILibraryContainerLink) ? defaultFolderIconx20 : defaultItemIconx20);;

                    //if (!theme.InvertIcons)
                    //{
                    //	thumbnail = thumbnail.InvertLightness();
                    //}

                    thumbnail = thumbnail.MultiplyWithPrimaryAccent();
                }
                else
                {
                    thumbnail = ((libraryItem is ILibraryContainerLink) ? defaultFolderIcon : defaultItemIcon).AlphaToPrimaryAccent();
                }
            }

            // TODO: Resolve and implement
            // Allow the container to draw an overlay - use signal interface or add method to interface?
            //var iconWithOverlay = ActiveContainer.DrawOverlay()

            setItemThumbnail(thumbnail);
        }