Revise IContentProvider.GetThumbnail signature
This commit is contained in:
parent
732186a512
commit
f5cf6c48eb
6 changed files with 18 additions and 20 deletions
|
|
@ -70,10 +70,9 @@ namespace MatterHackers.MatterControl
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task GetThumbnail(ILibraryItem item, int width, int height, Action<ImageBuffer> imageCallback)
|
public Task GetThumbnail(ILibraryItem item, int width, int height, ThumbnailSetter imageCallback)
|
||||||
{
|
{
|
||||||
imageCallback(thumbnailImage);
|
imageCallback(thumbnailImage, false);
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2017, John Lewin
|
Copyright (c) 2018, John Lewin
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
|
@ -32,15 +32,14 @@ using System.Threading.Tasks;
|
||||||
namespace MatterHackers.MatterControl.Library
|
namespace MatterHackers.MatterControl.Library
|
||||||
{
|
{
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using MatterHackers.Agg;
|
|
||||||
using MatterHackers.Agg.Image;
|
using MatterHackers.Agg.Image;
|
||||||
using MatterHackers.DataConverters3D;
|
using MatterHackers.DataConverters3D;
|
||||||
using MatterHackers.MatterControl.Library;
|
|
||||||
|
public delegate void ThumbnailSetter(ImageBuffer imageBuffer, bool raytracedImage);
|
||||||
|
|
||||||
public interface IContentProvider
|
public interface IContentProvider
|
||||||
{
|
{
|
||||||
Task GetThumbnail(ILibraryItem item, int width, int height, Action<ImageBuffer> imageCallback);
|
Task GetThumbnail(ILibraryItem item, int width, int height, ThumbnailSetter imageCallback);
|
||||||
ImageBuffer DefaultImage { get; }
|
ImageBuffer DefaultImage { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ namespace MatterHackers.MatterControl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task GetThumbnail(ILibraryItem item, int width, int height, Action<ImageBuffer> imageCallback)
|
public async Task GetThumbnail(ILibraryItem item, int width, int height, ThumbnailSetter imageCallback)
|
||||||
{
|
{
|
||||||
IObject3D object3D = null;
|
IObject3D object3D = null;
|
||||||
|
|
||||||
|
|
@ -162,18 +162,18 @@ namespace MatterHackers.MatterControl
|
||||||
writableContainer.SetThumbnail(item, thumbnail.Width, thumbnail.Height, thumbnail);
|
writableContainer.SetThumbnail(item, thumbnail.Width, thumbnail.Height, thumbnail);
|
||||||
}
|
}
|
||||||
|
|
||||||
imageCallback(thumbnail);
|
imageCallback(thumbnail, raytracedImage: true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If thumbnail generation was aborted or failed, return the default icon for this content type
|
// If thumbnail generation was aborted or failed, return the default icon for this content type
|
||||||
imageCallback(DefaultImage);
|
imageCallback(DefaultImage, raytracedImage: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// If thumbnail generation was skipped, return the default icon for this content type
|
// If thumbnail generation was skipped, return the default icon for this content type
|
||||||
imageCallback(DefaultImage);
|
imageCallback(DefaultImage, raytracedImage: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -262,7 +262,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
||||||
container.AddChild(text);
|
container.AddChild(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.SetItemThumbnail(loadingImage);
|
this.SetItemThumbnail(loadingImage, raytracedImage: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToolTipText
|
public override string ToolTipText
|
||||||
|
|
|
||||||
|
|
@ -76,12 +76,12 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
||||||
() => this.ActuallyVisibleOnScreen());
|
() => this.ActuallyVisibleOnScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task LoadItemThumbnail(ILibraryItem libraryItem, ILibraryContainer libraryContainer, int thumbWidth, int thumbHeight, Action<ImageBuffer, bool> thumbnailSetter, Func<bool> shouldGenerateThumbnail)
|
private async Task LoadItemThumbnail(ILibraryItem libraryItem, ILibraryContainer libraryContainer, int thumbWidth, int thumbHeight, ThumbnailSetter thumbnailSetter, Func<bool> shouldGenerateThumbnail)
|
||||||
{
|
{
|
||||||
var thumbnail = ListView.LoadCachedImage(libraryItem, thumbWidth, thumbHeight);
|
var thumbnail = ListView.LoadCachedImage(libraryItem, thumbWidth, thumbHeight);
|
||||||
if (thumbnail != null)
|
if (thumbnail != null)
|
||||||
{
|
{
|
||||||
thumbnailSetter(thumbnail, false);
|
thumbnailSetter(thumbnail, raytracedImage: false);
|
||||||
return;
|
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
|
// 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)
|
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(
|
await contentProvider.GetThumbnail(
|
||||||
libraryItem,
|
libraryItem,
|
||||||
thumbWidth,
|
thumbWidth,
|
||||||
|
|
@ -143,7 +143,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
||||||
thumbnail = ((libraryItem is ILibraryContainerLink) ? defaultFolderIcon : defaultItemIcon).AlphaToPrimaryAccent();
|
thumbnail = ((libraryItem is ILibraryContainerLink) ? defaultFolderIcon : defaultItemIcon).AlphaToPrimaryAccent();
|
||||||
}
|
}
|
||||||
|
|
||||||
thumbnailSetter(thumbnail, false);
|
thumbnailSetter(thumbnail, raytracedImage: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void EnsureSelection()
|
internal void EnsureSelection()
|
||||||
|
|
@ -198,7 +198,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
|
||||||
|
|
||||||
public event EventHandler ImageSet;
|
public event EventHandler ImageSet;
|
||||||
|
|
||||||
protected void SetItemThumbnail(ImageBuffer thumbnail, bool colorize = false)
|
protected void SetItemThumbnail(ImageBuffer thumbnail, bool raytracedImage)
|
||||||
{
|
{
|
||||||
if (thumbnail != null)
|
if (thumbnail != null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ namespace MatterHackers.MatterControl.Tests.Automation
|
||||||
|
|
||||||
// Generate thumbnail
|
// Generate thumbnail
|
||||||
var stopWatch = Stopwatch.StartNew();
|
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");
|
Assert.Less(stopWatch.ElapsedMilliseconds, 2000, "Elapsed thumbnail generation for Rook.amf should be less than 2 seconds for expected orthographic mode");
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue