using System.Net;
using System.Net.Http;
using System.IO;
+using OpenTween.Thumbnail;
namespace OpenTween
{
set
{
this.memoryImage = value;
- base.Image = value != null ? value.Image : null;
+ base.Image = value?.Image;
this.RestoreSizeMode();
}
base.SizeMode = this.currentSizeMode;
}
+ /// <summary>
+ /// SetImageFromTask メソッドを連続で呼び出した際に設定される画像が前後するのを防ぐため、
+ /// 現在進行中の Task を表す Id を記憶しておくためのフィールド
+ /// </summary>
+ private int currentImageTaskId = 0;
+
public async Task SetImageFromTask(Func<Task<MemoryImage>> imageTask)
{
+ var id = Interlocked.Increment(ref this.currentImageTaskId);
+
try
{
this.ShowInitialImage();
- this.Image = await imageTask();
+
+ var image = await imageTask();
+
+ if (id == this.currentImageTaskId)
+ this.Image = image;
}
catch (Exception)
{
- this.ShowErrorImage();
+ if (id == this.currentImageTaskId)
+ this.ShowErrorImage();
try
{
throw;
}
catch (HttpRequestException) { }
catch (InvalidImageException) { }
- catch (TaskCanceledException) { }
+ catch (OperationCanceledException) { }
catch (WebException) { }
+ catch (IOException) { }
}
}
try
{
base.OnPaint(pe);
+
+ // 動画なら再生ボタンを上から描画
+ DrawPlayableMark(pe);
}
catch (ExternalException)
{
}
}
+ private void DrawPlayableMark(PaintEventArgs pe)
+ {
+ var thumb = this.Tag as ThumbnailInfo;
+ if (thumb == null || !thumb.IsPlayable) return;
+ if (base.Image == base.InitialImage || base.Image == base.ErrorImage) return;
+
+ var overlayImage = Properties.Resources.PlayableOverlayImage;
+
+ var overlaySize = Math.Min(this.Width, this.Height) / 4;
+ var destRect = new Rectangle(
+ (this.Width - overlaySize) / 2,
+ (this.Height - overlaySize) / 2,
+ overlaySize,
+ overlaySize);
+
+ pe.Graphics.DrawImage(overlayImage, destRect, 0, 0, overlayImage.Width, overlayImage.Height, GraphicsUnit.Pixel);
+ }
+
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new string ImageLocation
{
- get { throw new NotSupportedException(); }
- set { throw new NotSupportedException(); }
+ get { return null; }
+ set { }
}
[EditorBrowsable(EditorBrowsableState.Never)]