Skip to content

Commit

Permalink
Merge pull request #229 from helgeerbe/Issue-203,-Text-fade
Browse files Browse the repository at this point in the history
Fix issue 203 - Text fade isn't smooth
  • Loading branch information
jgodfrey authored Jan 15, 2022
2 parents 09263a9 + b47960e commit dcf4b0f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions picframe/viewer_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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()
self.__display.destroy()

0 comments on commit dcf4b0f

Please sign in to comment.