Make it possible to set the blender on the AsyncLoad widget

Fixed a crash with an empty queue
This commit is contained in:
Lars Brubaker 2015-07-27 11:00:07 -07:00
parent c31103a0d5
commit bf2484cdc3
3 changed files with 26 additions and 14 deletions

View file

@ -52,6 +52,9 @@ namespace MatterHackers.MatterControl
bool startedLoad = false; bool startedLoad = false;
string uriToLoad; string uriToLoad;
IRecieveBlenderByte scalingBlender = new BlenderBGRA();
public void SetScalingBlender(IRecieveBlenderByte blender) { scalingBlender = blender; }
public ImageWidget_AsyncLoadOnDraw(ImageBuffer image, string uriToLoad) public ImageWidget_AsyncLoadOnDraw(ImageBuffer image, string uriToLoad)
: base(image) : base(image)
{ {
@ -89,7 +92,7 @@ namespace MatterHackers.MatterControl
// The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results. // The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
// So we scale as many times as we need to to get the Image to be the right size. // So we scale as many times as we need to to get the Image to be the right size.
// If this were going to be a non-uniform scale we could do the x and y separatly to get better results. // If this were going to be a non-uniform scale we could do the x and y separatly to get better results.
ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, new BlenderBGRA()); ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, scalingBlender);
halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height); halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height);
unScaledImage = halfImage; unScaledImage = halfImage;
} }

View file

@ -113,7 +113,10 @@ namespace MatterHackers.MatterControl.ActionBar
public override void OnClosed(EventArgs e) public override void OnClosed(EventArgs e)
{ {
activePrintPreviewImage.PrintItem.SlicingOutputMessage -= PrintItem_SlicingOutputMessage; if (activePrintPreviewImage.PrintItem != null)
{
activePrintPreviewImage.PrintItem.SlicingOutputMessage -= PrintItem_SlicingOutputMessage;
}
if (unregisterEvents != null) if (unregisterEvents != null)
{ {
unregisterEvents(this, null); unregisterEvents(this, null);

View file

@ -136,15 +136,17 @@ namespace MatterHackers.MatterControl
get { return printItem; } get { return printItem; }
set set
{ {
if (printItem != null) if (PrintItem != null)
{ {
printItem.FileHasChanged -= item_FileHasChanged; PrintItem.FileHasChanged -= item_FileHasChanged;
} }
printItem = value; printItem = value;
thumbNailHasBeenCreated = false; thumbNailHasBeenCreated = false;
if (printItem != null) if (PrintItem != null)
{ {
printItem.FileHasChanged += item_FileHasChanged; PrintItem.FileHasChanged += item_FileHasChanged;
} }
} }
} }
@ -170,9 +172,10 @@ namespace MatterHackers.MatterControl
{ {
unregisterEvents(this, null); unregisterEvents(this, null);
} }
if (printItem != null)
if (PrintItem != null)
{ {
printItem.FileHasChanged -= item_FileHasChanged; PrintItem.FileHasChanged -= item_FileHasChanged;
} }
base.OnClosed(e); base.OnClosed(e);
} }
@ -477,12 +480,15 @@ namespace MatterHackers.MatterControl
private void OnDoneRendering() private void OnDoneRendering()
{ {
string stlHashCode = this.PrintItem.FileHashCode.ToString(); if (PrintItem != null)
string imageFileName = GetImageFileName(stlHashCode);
if (DoneRendering != null)
{ {
DoneRendering(this, new StringEventArgs(imageFileName)); string stlHashCode = this.PrintItem.FileHashCode.ToString();
string imageFileName = GetImageFileName(stlHashCode);
if (DoneRendering != null)
{
DoneRendering(this, new StringEventArgs(imageFileName));
}
} }
} }
@ -582,7 +588,7 @@ namespace MatterHackers.MatterControl
private bool SetImageFast() private bool SetImageFast()
{ {
if (this.printItem == null) if (this.PrintItem == null)
{ {
this.thumbnailImage = new ImageBuffer(this.noThumbnailImage); this.thumbnailImage = new ImageBuffer(this.noThumbnailImage);
this.Invalidate(); this.Invalidate();