From b47960ed447a3a5cae768d8175a049c428b18d25 Mon Sep 17 00:00:00 2001 From: Jeff Godfrey Date: Sat, 15 Jan 2022 11:58:02 -0600 Subject: [PATCH] Fix issue 203 - Text fade isn't smooth - Change calculation of "dt" to ensure proper numeric range of text alpha - Ensure text alpha actually reaches zero to prevent still-visible ghosted text - Reorder some code to ensure slow image processing doesn't impact text fade time - Remove some commented-out code --- picframe/viewer_display.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/picframe/viewer_display.py b/picframe/viewer_display.py index 0e2a9f0..3dd3be7 100644 --- a/picframe/viewer_display.py +++ b/picframe/viewer_display.py @@ -452,15 +452,14 @@ def slideshow_is_running(self, pics=None, time_delay = 200.0, fade_time = 10.0, loop_running = self.__display.loop_running() tm = time.time() if pics is not None: - #self.__sbg = self.__sfg # if the first tex_load fails then __sfg might be Null TODO should fn return if None? + new_sfg = self.__tex_load(pics, (self.__display.width, self.__display.height)) + tm = time.time() self.__next_tm = tm + time_delay self.__name_tm = tm + fade_time + self.__show_text_tm # text starts after slide transition - new_sfg = self.__tex_load(pics, (self.__display.width, self.__display.height)) if new_sfg is not None: # this is a possible return value which needs to be caught self.__sbg = self.__sfg self.__sfg = new_sfg else: - #return (True, False) # return early (self.__sbg, self.__sfg) = (self.__sfg, self.__sbg) # swap existing images over self.__alpha = 0.0 if fade_time > 0.5: @@ -494,13 +493,9 @@ def slideshow_is_running(self, pics=None, time_delay = 200.0, fade_time = 10.0, self.__xstep, self.__ystep = (self.__slide.unif[i] * 2.0 / (time_delay - fade_time) for i in (48, 49)) self.__slide.unif[48] = 0.0 self.__slide.unif[49] = 0.0 - #self.__kb_up = not self.__kb_up # just go in one direction if self.__kenburns and self.__alpha >= 1.0: t_factor = time_delay - fade_time - self.__next_tm + tm - #t_factor = self.__next_tm - tm - #if self.__kb_up: - # t_factor = time_delay - t_factor # add exponentially smoothed tweening in case of timing delays etc. to avoid 'jumps' self.__slide.unif[48] = self.__slide.unif[48] * 0.95 + self.__xstep * t_factor * 0.05 self.__slide.unif[49] = self.__slide.unif[49] * 0.95 + self.__ystep * t_factor * 0.05 @@ -520,18 +515,22 @@ def slideshow_is_running(self, pics=None, time_delay = 200.0, fade_time = 10.0, if self.__alpha >= 1.0 and tm < self.__name_tm: # this sets alpha for the TextBlock from 0 to 1 then back to 0 - dt = 1.1 - (self.__name_tm - tm) / self.__show_text_tm # i.e. dt from 0.1 to 1.1 + dt = 1.0 - (self.__name_tm - tm) / self.__show_text_tm + if dt > 0.995: dt = 1 # ensure that calculated alpha value fully reaches 0 (TODO: Improve!) ramp_pt = max(4.0, self.__show_text_tm / 4.0) # always > 4 so text fade will always < 4s + # create single saw tooth over 0 to __show_text_tm alpha = max(0.0, min(1.0, ramp_pt * (1.0 - abs(1.0 - 2.0 * dt)))) # function only run if image alpha is 1.0 so can use 1.0 - abs... + + # if we have text, set it's current alpha value to fade in/out for block in self.__textblocks: if block is not None: block.sprite.set_alpha(alpha) - if self.__text_bkg_hgt: + # if we have a text background to render (and we currently have text), set its alpha and draw it + if self.__text_bkg_hgt and any(block is not None for block in self.__textblocks): #txt_len > 0: #only draw background if text there self.__text_bkg.set_alpha(alpha) - if any(block is not None for block in self.__textblocks): #txt_len > 0: #only draw background if text there - self.__text_bkg.draw() + self.__text_bkg.draw() for block in self.__textblocks: if block is not None: @@ -540,4 +539,4 @@ def slideshow_is_running(self, pics=None, time_delay = 200.0, fade_time = 10.0, return (loop_running, False) # now returns tuple with skip image flag added def slideshow_stop(self): - self.__display.destroy() \ No newline at end of file + self.__display.destroy()