more menu debug

This commit is contained in:
Sundog Jones 2020-08-02 13:14:53 -07:00
parent b5206f6981
commit f0556afd28
2 changed files with 7 additions and 3 deletions

View File

@ -72,6 +72,8 @@ class SoundslabDisplay:
def updateMenu(self, menu_data=None):
# always start with a transparent menu overlay image
bg_color = (200, 0, 0, 255)
fg_color = (0, 0, 0, 255)
im_menu_overlay = Image.new("RGBA", self.screen_size, (0, 0, 0, 0))
menu_overlay = ImageDraw.Draw(im_menu_overlay)
if self.show_menu and menu_data is not None:
@ -88,17 +90,17 @@ class SoundslabDisplay:
# a translucent red background rectangle for the menu area itself
menu_overlay.rectangle([(21,21), (self.screen_size[0] - 21,self.screen_size[1] - 21)], (200, 0, 0, 200))
menu_overlay.rectangle([(21,21), (self.screen_size[0] - 21,self.screen_size[1] - 21)], bg_color)
offset_from_top = 21 # start at the 21st row of pixels to draw inside the outer overlay
font = ImageFont.truetype(font='/usr/share/fonts/truetype/hack/Hack-Regular.ttf', size=14)
for row in menu_data:
if row["selected"]:
menu_overlay.rectangle([(21, offset_from_top),(self.screen_size[0] - 21, offset_from_top + 40)], self.bg_color) # highlight background for selected menu item
menu_overlay.rectangle([(21, offset_from_top),(self.screen_size[0] - 21, offset_from_top + 40)], fg_color) # highlight background for selected menu item
output_size = menu_overlay.textsize(row["output"]) # get the size of the text to draw so we can center it in our rectangle for this row
print("showing '" + row["output"] + "' at (" + str((self.screen_size[0] / 2) - floor(output_size[0] / 2)) + ", " + str(offset_from_top + 20 - floor(output_size[1])) + ")")
menu_overlay.text(((self.screen_size[0] / 2) - floor(output_size[0] / 2), offset_from_top + (20 - floor(output_size[1]))), row["output"], font=font, fill=self.fg_color if row["selected"] else self.bg_color) # draw output text in appropriate color
menu_overlay.text(((self.screen_size[0] / 2) - floor(output_size[0] / 2) - 10, offset_from_top + (20 - floor(output_size[1]))), row["output"], font=font, fill=bg_color if row["selected"] else fg_color) # draw output text in appropriate color
offset_from_top += 40
# finally, set the current_menu image

View File

@ -143,6 +143,8 @@ while True:
{"output": "v", "selected": False}
]
)
else:
display.updateMenu()
# test album art
display.updateAlbumArt()
# test setting up the overlay