Skip to content

Commit

Permalink
support millisecond for slideshow interval
Browse files Browse the repository at this point in the history
  • Loading branch information
d2phap committed Oct 15, 2022
1 parent 36c9cd8 commit efaa73f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
6 changes: 3 additions & 3 deletions v9/Components/ImageGlass.Settings/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,12 @@ public static class Config
/// <summary>
/// Gets, sets slide show interval (minimum value if it's random)
/// </summary>
public static int SlideshowInterval { get; set; } = 5;
public static float SlideshowInterval { get; set; } = 5f;

/// <summary>
/// Gets, sets the maximum slide show interval value
/// </summary>
public static int SlideshowIntervalTo { get; set; } = 5;
public static float SlideshowIntervalTo { get; set; } = 5f;

/// <summary>
/// Gets, sets value of thumbnail dimension in pixel
Expand Down Expand Up @@ -875,7 +875,7 @@ public static void Load()

#region Slide show
SlideshowInterval = items.GetValue(nameof(SlideshowInterval), SlideshowInterval);
if (SlideshowInterval < 1) SlideshowInterval = 5;
if (SlideshowInterval < 1) SlideshowInterval = 5f;

SlideshowIntervalTo = items.GetValue(nameof(SlideshowIntervalTo), SlideshowIntervalTo);
SlideshowIntervalTo = Math.Max(SlideshowIntervalTo, SlideshowInterval);
Expand Down
42 changes: 36 additions & 6 deletions v9/Utilities/igcmd/Slideshow/FrmSlideshow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public FrmSlideshow(string slideshowIndex, string initImagePath)

private void FrmSlideshow_Load(object sender, EventArgs e)
{
_slideshowTimer.Interval = Config.SlideshowInterval;
_slideshowTimer.Interval = 10; // support milliseconds
_slideshowTimer.Tick += SlideshowTimer_Tick;

PicMain.Render += PicMain_Render;
Expand Down Expand Up @@ -127,7 +127,7 @@ private void SlideshowTimer_Tick(object? sender, EventArgs e)
if (!_slideshowStopwatch.IsRunning)
_slideshowStopwatch.Restart();

if (_slideshowCountdown <= _slideshowStopwatch.Elapsed.TotalSeconds)
if (_slideshowStopwatch.Elapsed.TotalMilliseconds >= TimeSpan.FromSeconds(_slideshowCountdown).TotalMilliseconds)
{
// end of image list
if (_currentIndex == _imageList.Count - 1)
Expand All @@ -144,8 +144,14 @@ private void SlideshowTimer_Tick(object? sender, EventArgs e)
_ = ViewNextImageAsync(1);
}

// update the countdown text
PicMain.Invalidate();

// only update the countdown text if it's a full second number
var isSecond = _slideshowStopwatch.Elapsed.Milliseconds <= 100;
if (isSecond)
{
PicMain.Invalidate();
}

}


Expand All @@ -154,7 +160,8 @@ private void PicMain_Render(object? sender, RenderEventArgs e)
if (!_slideshowTimer.Enabled || !Config.ShowSlideshowCountdown) return;

// draw countdown text ----------------------------------------------
var text = TimeSpan.FromSeconds(_slideshowCountdown - _slideshowStopwatch.Elapsed.TotalSeconds + 1).ToString("mm':'ss");
var countdownTime = TimeSpan.FromSeconds(_slideshowCountdown + 1);
var text = (countdownTime - _slideshowStopwatch.Elapsed).ToString("mm':'ss");


var font = new Font(Font.FontFamily, 30f);
Expand Down Expand Up @@ -402,13 +409,24 @@ private void OnImageLoaded(IgPhoto photo)
else if (!(photo?.ImgData.IsImageNull ?? true))
{
var isImageBigForFading = photo.Metadata.Width > 8000
|| photo.Metadata.Height > 8000;
|| photo.Metadata.Height > 8000;
var enableFading = !isImageBigForFading;

// set the main image
PicMain.SetImage(photo.ImgData, enableFading, 0.4f, 0.02f);

PicMain.ClearMessage();


// reset countdown timer value
_slideshowCountdown = RandomizeSlideshowInterval();

// since the UI does not print milliseconds,
// this prevents the coutdown to flash the maximum value during the first tick
if (_slideshowCountdown == Math.Ceiling(_slideshowCountdown))
{
_slideshowCountdown -= 0.001f;
}
}


Expand Down Expand Up @@ -673,4 +691,16 @@ private void UpdateImageInfo(ImageInfoUpdateTypes types = ImageInfoUpdateTypes.A
}


/// <summary>
/// Randomize slideshow interval in seconds
/// </summary>
private static float RandomizeSlideshowInterval()
{
var intervalTo = Config.UseRandomIntervalForSlideshow ? Config.SlideshowIntervalTo : Config.SlideshowInterval;

var ran = new Random();
var interval = (float)(ran.NextDouble() * (intervalTo - Config.SlideshowInterval) + Config.SlideshowInterval);

return interval;
}
}

0 comments on commit efaa73f

Please sign in to comment.