Skip to content

Commit

Permalink
added function to draw image overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
paddywwoof committed Aug 16, 2024
1 parent 5d40c55 commit 05feb15
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/picframe/viewer_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def __init__(self, config):
self.__clock_top_bottom = config['clock_top_bottom']
self.__clock_wdt_offset_pct = config['clock_wdt_offset_pct']
self.__clock_hgt_offset_pct = config['clock_hgt_offset_pct']
self.__image_overlay = None
self.__prev_overlay_time = None
ImageFile.LOAD_TRUNCATED_IMAGES = True # occasional damaged file hangs app

@property
Expand Down Expand Up @@ -432,6 +434,22 @@ def __draw_clock(self):
if self.__clock_overlay:
self.__clock_overlay.sprite.draw()

def __draw_overlay(self):
# Very simple function pasting the overlay_file below over the main picture but beneath
# the clock and the image info text. The user must make the image transparent as needed
# and the correct aspect ratio for the screen. The image will be scaled to the screen size
overlay_file = "/dev/shm/overlay.png" #TODO make this user configurable?
if not os.path.isfile(overlay_file): # empty file used as flag to return early
self.__image_overlay = None
return
change_time = os.path.getmtime(overlay_file)
if self.__prev_overlay_time is None or self.__prev_overlay_time < change_time: # load Texture
self.__prev_overlay_time = change_time
overlay_texture = pi3d.Texture(overlay_file, blend=True, free_after_load=True, mipmap=False) #TODO check generally OK with blend=False
self.__image_overlay = pi3d.Sprite(w=self.__display.width, h=self.__display.height,z=4.1) # just behind text_bkg
self.__image_overlay.set_draw_details(self.__flat_shader, [overlay_texture])
if self.__image_overlay is not None: # shouldn't be possible to get here otherwise, but just in case!
self.__image_overlay.draw()

@property
def display_width(self):
Expand Down Expand Up @@ -535,6 +553,7 @@ def slideshow_is_running(self, pics=None, time_delay=200.0, fade_time=10.0, paus
self.__in_transition = False

self.__slide.draw()
self.__draw_overlay()

if self.__alpha >= 1.0 and tm < self.__name_tm:
# this sets alpha for the TextBlock from 0 to 1 then back to 0
Expand Down

0 comments on commit 05feb15

Please sign in to comment.