Skip to content

Commit

Permalink
slideshow interval: set min timer interval to 10ms and reduce redunda…
Browse files Browse the repository at this point in the history
…nt paint

#1155
  • Loading branch information
d2phap committed Oct 22, 2022
1 parent 57770b4 commit 0a1c191
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Source/ImageGlass/frmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 21 additions & 13 deletions Source/ImageGlass/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,18 +656,20 @@ public partial class frmMain: Form {
}


#region Validate image index

// temp index
var tempIndex = Local.CurrentIndex + step;

// Issue #609: do not auto-reactivate slideshow if disabled
if (Configs.IsSlideshow && timSlideShow.Enabled) {
timSlideShow.Enabled = false;
timSlideShow.Enabled = true;
_slideshowStopwatch.Reset();
}


#region Validate image index

// temp index
var tempIndex = Local.CurrentIndex + step;


// Issue #1019 : When showing the initial image, the ImageList is empty; don't show toast messages
if (!Configs.IsSlideshow && !Configs.IsLoopBackViewer && Local.ImageList.Length > 0) {
//Reach end of list
Expand Down Expand Up @@ -800,8 +802,9 @@ public partial class frmMain: Form {

// reset countdown timer value
_slideshowCountdown = Configs.RandomizeSlideshowInterval();
// since the UI does not print milliseconds, this prevents the coutdown to flash the maximum value during the first tick
if (_slideshowCountdown == Math.Floor(_slideshowCountdown))
// 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;

// reset Cropping region
Expand Down Expand Up @@ -2321,15 +2324,14 @@ public partial class frmMain: Form {
/// <summary>
/// Paint countdown clock in Slideshow mode
/// </summary>
/// <param name="e"></param>
private void PaintSlideshowClock(PaintEventArgs e) {
if (!timSlideShow.Enabled || !Configs.IsShowSlideshowCountdown) {
return;
}

// draw countdown text ----------------------------------------------
var gap = DPIScaling.Transform(20);
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");

e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Expand All @@ -2338,6 +2340,7 @@ public partial class frmMain: Form {
var fontSize = e.Graphics.MeasureString(text, font);

// calculate background size
var gap = DPIScaling.Transform(20);
var bgSize = new SizeF(fontSize.Width + gap, fontSize.Height + gap);
var bgX = picMain.Width - bgSize.Width - gap;
var bgY = picMain.Height - bgSize.Height - gap;
Expand Down Expand Up @@ -3759,11 +3762,12 @@ public partial class frmMain: Form {
if (!_slideshowStopwatch.IsRunning)
_slideshowStopwatch.Restart();

if (_slideshowCountdown <= _slideshowStopwatch.Elapsed.TotalSeconds) {
if (_slideshowStopwatch.Elapsed.TotalMilliseconds >= TimeSpan.FromSeconds(_slideshowCountdown).TotalMilliseconds) {
// end of image list
if (Local.CurrentIndex == Local.ImageList.Length - 1) {
// loop the list
if (!Configs.IsLoopBackSlideshow) {
// pause slideshow
mnuMainSlideShowPause_Click(null, null);
return;
}
Expand All @@ -3772,8 +3776,12 @@ public partial class frmMain: Form {
_ = NextPicAsync(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 (Configs.IsShowSlideshowCountdown && isSecond) {
picMain.Invalidate();
}
}

private void PicMain_Paint(object sender, PaintEventArgs e) {
Expand Down
19 changes: 2 additions & 17 deletions Source/ImageGlass/frmSetting.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Source/ImageGlass/frmSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -736,10 +736,10 @@ public partial class frmSetting: Form {
numSlideshowIntervalTo.Minimum = numSlideShowInterval.Value;

// format value
var time = TimeSpan.FromSeconds((double)numSlideShowInterval.Value).ToString("mm':'ss'.'fff");
var time = TimeSpan.FromSeconds((double)numSlideShowInterval.Value).ToString("mm':'ss'.'ff");

if (chkRandomSlideshowInterval.Checked) {
var timeTo = TimeSpan.FromSeconds((double)numSlideshowIntervalTo.Value).ToString("mm':'ss'.'fff");
var timeTo = TimeSpan.FromSeconds((double)numSlideshowIntervalTo.Value).ToString("mm':'ss'.'ff");

time = $"{time} - {timeTo}";
}
Expand All @@ -749,9 +749,9 @@ public partial class frmSetting: Form {

private void numSlideshowIntervalTo_ValueChanged(object sender, EventArgs e) {
// format value
var time = TimeSpan.FromSeconds((double)numSlideShowInterval.Value).ToString("mm':'ss'.'fff");
var time = TimeSpan.FromSeconds((double)numSlideShowInterval.Value).ToString("mm':'ss'.'ff");

var timeTo = TimeSpan.FromSeconds((double)numSlideshowIntervalTo.Value).ToString("mm':'ss'.'fff");
var timeTo = TimeSpan.FromSeconds((double)numSlideshowIntervalTo.Value).ToString("mm':'ss'.'ff");

time = $"{time} - {timeTo}";

Expand Down

0 comments on commit 0a1c191

Please sign in to comment.