diff --git a/Library/ContentProviders/GCodeContentProvider.cs b/Library/ContentProviders/GCodeContentProvider.cs index a88eb0c9b..3fc76bd49 100644 --- a/Library/ContentProviders/GCodeContentProvider.cs +++ b/Library/ContentProviders/GCodeContentProvider.cs @@ -70,10 +70,9 @@ namespace MatterHackers.MatterControl return null; } - public Task GetThumbnail(ILibraryItem item, int width, int height, Action imageCallback) + public Task GetThumbnail(ILibraryItem item, int width, int height, ThumbnailSetter imageCallback) { - imageCallback(thumbnailImage); - + imageCallback(thumbnailImage, false); return Task.CompletedTask; } } diff --git a/Library/ContentProviders/IContentProvider.cs b/Library/ContentProviders/IContentProvider.cs index b2abb9e8e..f54c4b356 100644 --- a/Library/ContentProviders/IContentProvider.cs +++ b/Library/ContentProviders/IContentProvider.cs @@ -1,5 +1,5 @@ /* -Copyright (c) 2017, John Lewin +Copyright (c) 2018, John Lewin All rights reserved. Redistribution and use in source and binary forms, with or without @@ -32,15 +32,14 @@ using System.Threading.Tasks; namespace MatterHackers.MatterControl.Library { using System; - using System.Collections.Generic; - using MatterHackers.Agg; using MatterHackers.Agg.Image; using MatterHackers.DataConverters3D; - using MatterHackers.MatterControl.Library; + + public delegate void ThumbnailSetter(ImageBuffer imageBuffer, bool raytracedImage); public interface IContentProvider { - Task GetThumbnail(ILibraryItem item, int width, int height, Action imageCallback); + Task GetThumbnail(ILibraryItem item, int width, int height, ThumbnailSetter imageCallback); ImageBuffer DefaultImage { get; } } diff --git a/Library/ContentProviders/MeshContentProvider.cs b/Library/ContentProviders/MeshContentProvider.cs index 18b429243..519b4523c 100644 --- a/Library/ContentProviders/MeshContentProvider.cs +++ b/Library/ContentProviders/MeshContentProvider.cs @@ -102,7 +102,7 @@ namespace MatterHackers.MatterControl } - public async Task GetThumbnail(ILibraryItem item, int width, int height, Action imageCallback) + public async Task GetThumbnail(ILibraryItem item, int width, int height, ThumbnailSetter imageCallback) { IObject3D object3D = null; @@ -162,18 +162,18 @@ namespace MatterHackers.MatterControl writableContainer.SetThumbnail(item, thumbnail.Width, thumbnail.Height, thumbnail); } - imageCallback(thumbnail); + imageCallback(thumbnail, raytracedImage: true); } else { // If thumbnail generation was aborted or failed, return the default icon for this content type - imageCallback(DefaultImage); + imageCallback(DefaultImage, raytracedImage: true); } } else { // If thumbnail generation was skipped, return the default icon for this content type - imageCallback(DefaultImage); + imageCallback(DefaultImage, raytracedImage: true); } } diff --git a/Library/Widgets/ListView/IconListView.cs b/Library/Widgets/ListView/IconListView.cs index ae6d1d7b1..6543a8741 100644 --- a/Library/Widgets/ListView/IconListView.cs +++ b/Library/Widgets/ListView/IconListView.cs @@ -262,7 +262,7 @@ namespace MatterHackers.MatterControl.CustomWidgets container.AddChild(text); } - this.SetItemThumbnail(loadingImage); + this.SetItemThumbnail(loadingImage, raytracedImage: false); } public override string ToolTipText diff --git a/Library/Widgets/ListView/ListViewItemBase.cs b/Library/Widgets/ListView/ListViewItemBase.cs index 6f122bdda..c35b2c7bd 100644 --- a/Library/Widgets/ListView/ListViewItemBase.cs +++ b/Library/Widgets/ListView/ListViewItemBase.cs @@ -76,12 +76,12 @@ namespace MatterHackers.MatterControl.CustomWidgets () => this.ActuallyVisibleOnScreen()); } - private static async Task LoadItemThumbnail(ILibraryItem libraryItem, ILibraryContainer libraryContainer, int thumbWidth, int thumbHeight, Action thumbnailSetter, Func shouldGenerateThumbnail) + private async Task LoadItemThumbnail(ILibraryItem libraryItem, ILibraryContainer libraryContainer, int thumbWidth, int thumbHeight, ThumbnailSetter thumbnailSetter, Func shouldGenerateThumbnail) { var thumbnail = ListView.LoadCachedImage(libraryItem, thumbWidth, thumbHeight); if (thumbnail != null) { - thumbnailSetter(thumbnail, false); + thumbnailSetter(thumbnail, raytracedImage: false); return; } @@ -111,9 +111,9 @@ namespace MatterHackers.MatterControl.CustomWidgets // When this widget is dequeued for generation, validate before processing. Off-screen widgets should be skipped and will requeue next time they become visible if (shouldGenerateThumbnail?.Invoke() == true) { - thumbnailSetter(generatingThumbnailIcon, false); + thumbnailSetter(generatingThumbnailIcon, raytracedImage: false); - // Then try to load a content specific thumbnail + // Ask the provider for a content specific thumbnail await contentProvider.GetThumbnail( libraryItem, thumbWidth, @@ -143,7 +143,7 @@ namespace MatterHackers.MatterControl.CustomWidgets thumbnail = ((libraryItem is ILibraryContainerLink) ? defaultFolderIcon : defaultItemIcon).AlphaToPrimaryAccent(); } - thumbnailSetter(thumbnail, false); + thumbnailSetter(thumbnail, raytracedImage: false); } internal void EnsureSelection() @@ -198,7 +198,7 @@ namespace MatterHackers.MatterControl.CustomWidgets public event EventHandler ImageSet; - protected void SetItemThumbnail(ImageBuffer thumbnail, bool colorize = false) + protected void SetItemThumbnail(ImageBuffer thumbnail, bool raytracedImage) { if (thumbnail != null) { diff --git a/Tests/MatterControl.AutomationTests/MatterControlTests.cs b/Tests/MatterControl.AutomationTests/MatterControlTests.cs index 22642f267..4ffaaac50 100644 --- a/Tests/MatterControl.AutomationTests/MatterControlTests.cs +++ b/Tests/MatterControl.AutomationTests/MatterControlTests.cs @@ -50,7 +50,7 @@ namespace MatterHackers.MatterControl.Tests.Automation // Generate thumbnail var stopWatch = Stopwatch.StartNew(); - await provider.GetThumbnail(item, 400, 400, (imageBuffer) => { }); + await provider.GetThumbnail(item, 400, 400, (imageBuffer, _) => { }); Assert.Less(stopWatch.ElapsedMilliseconds, 2000, "Elapsed thumbnail generation for Rook.amf should be less than 2 seconds for expected orthographic mode"); });