Improved NHL scoreboard layout: Added proper spacing, bounds checking, and repositioned elements to prevent overlap

This commit is contained in:
ChuckBuilds
2025-04-18 12:41:38 -05:00
parent 4151e35fc9
commit 19e2afa38a

View File

@@ -240,6 +240,7 @@ class BaseNHLManager:
home_logo = self._load_and_resize_logo(self.current_game["home_abbr"]) home_logo = self._load_and_resize_logo(self.current_game["home_abbr"])
away_logo = self._load_and_resize_logo(self.current_game["away_abbr"]) away_logo = self._load_and_resize_logo(self.current_game["away_abbr"])
self.logger.info(f"Display dimensions: {self.display_width}x{self.display_height}")
self.logger.info(f"Home team ({self.current_game['home_abbr']}) logo loaded: {home_logo is not None}") self.logger.info(f"Home team ({self.current_game['home_abbr']}) logo loaded: {home_logo is not None}")
self.logger.info(f"Away team ({self.current_game['away_abbr']}) logo loaded: {away_logo is not None}") self.logger.info(f"Away team ({self.current_game['away_abbr']}) logo loaded: {away_logo is not None}")
@@ -248,21 +249,24 @@ class BaseNHLManager:
if away_logo: if away_logo:
self.logger.info(f"Away logo size: {away_logo.size}, mode: {away_logo.mode}") self.logger.info(f"Away logo size: {away_logo.size}, mode: {away_logo.mode}")
# Create separate layers for each logo with glow effect # Create a single overlay for both logos
home_layer = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0)) overlay = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0))
away_layer = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0))
# Calculate vertical center line for alignment
# Create glow layers center_y = self.display_height // 2
home_glow = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0)) self.logger.info(f"Vertical center line: {center_y}")
away_glow = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0))
# Draw home team logo (far right) # Draw home team logo (far right)
if home_logo: if home_logo:
# Position home logo at the far right # Position home logo at the far right with padding
home_x = self.display_width - home_logo.width - 5 # 5 pixels padding from right edge home_x = self.display_width - home_logo.width - 10 # Increased padding to 10 pixels
home_y = (self.display_height - home_logo.height) // 2 # Vertically centered home_y = center_y - (home_logo.height // 2) # Center vertically
self.logger.info(f"Home logo position: ({home_x}, {home_y})") self.logger.info(f"Home logo position: ({home_x}, {home_y})")
# Check if logo fits within display bounds
if home_x < 0 or home_y < 0 or home_x + home_logo.width > self.display_width or home_y + home_logo.height > self.display_height:
self.logger.warning(f"Home logo may be out of bounds: x={home_x}, y={home_y}, width={home_logo.width}, height={home_logo.height}")
# Create a blue-tinted version of the home logo # Create a blue-tinted version of the home logo
home_tinted = home_logo.copy() home_tinted = home_logo.copy()
home_tinted_data = home_tinted.load() home_tinted_data = home_tinted.load()
@@ -274,7 +278,7 @@ class BaseNHLManager:
home_tinted_data[x, y] = (r, g, min(255, b + 200), a) home_tinted_data[x, y] = (r, g, min(255, b + 200), a)
# Create stronger glow effect # Create stronger glow effect
glow_draw = ImageDraw.Draw(home_glow) glow_draw = ImageDraw.Draw(overlay)
glow_color = (0, 0, 255, 180) # More opaque blue glow glow_color = (0, 0, 255, 180) # More opaque blue glow
glow_draw.ellipse([ glow_draw.ellipse([
home_x - 10, home_y - 10, home_x - 10, home_y - 10,
@@ -282,19 +286,22 @@ class BaseNHLManager:
home_y + home_logo.height + 10 home_y + home_logo.height + 10
], fill=glow_color) ], fill=glow_color)
# Paste glow first, then logo # Paste the home logo onto the overlay
home_layer.paste(home_glow, (0, 0), home_glow) overlay.paste(home_tinted, (home_x, home_y), home_tinted)
home_layer.paste(home_tinted, (home_x, home_y), home_tinted)
else: else:
self.logger.error(f"Home logo is None for team {self.current_game['home_abbr']}") self.logger.error(f"Home logo is None for team {self.current_game['home_abbr']}")
# Draw away team logo (far left) # Draw away team logo (far left)
if away_logo: if away_logo:
# Position away logo at the far left # Position away logo at the far left with padding
away_x = 5 # 5 pixels padding from left edge away_x = 10 # Increased padding to 10 pixels
away_y = (self.display_height - away_logo.height) // 2 # Vertically centered away_y = center_y - (away_logo.height // 2) # Center vertically
self.logger.info(f"Away logo position: ({away_x}, {away_y})") self.logger.info(f"Away logo position: ({away_x}, {away_y})")
# Check if logo fits within display bounds
if away_x < 0 or away_y < 0 or away_x + away_logo.width > self.display_width or away_y + away_logo.height > self.display_height:
self.logger.warning(f"Away logo may be out of bounds: x={away_x}, y={away_y}, width={away_logo.width}, height={away_logo.height}")
# Create a red-tinted version of the away logo # Create a red-tinted version of the away logo
away_tinted = away_logo.copy() away_tinted = away_logo.copy()
away_tinted_data = away_tinted.load() away_tinted_data = away_tinted.load()
@@ -306,7 +313,7 @@ class BaseNHLManager:
away_tinted_data[x, y] = (min(255, r + 200), g, b, a) away_tinted_data[x, y] = (min(255, r + 200), g, b, a)
# Create stronger glow effect # Create stronger glow effect
glow_draw = ImageDraw.Draw(away_glow) glow_draw = ImageDraw.Draw(overlay)
glow_color = (255, 0, 0, 180) # More opaque red glow glow_color = (255, 0, 0, 180) # More opaque red glow
glow_draw.ellipse([ glow_draw.ellipse([
away_x - 10, away_y - 10, away_x - 10, away_y - 10,
@@ -314,15 +321,13 @@ class BaseNHLManager:
away_y + away_logo.height + 10 away_y + away_logo.height + 10
], fill=glow_color) ], fill=glow_color)
# Paste glow first, then logo # Paste the away logo onto the overlay
away_layer.paste(away_glow, (0, 0), away_glow) overlay.paste(away_tinted, (away_x, away_y), away_tinted)
away_layer.paste(away_tinted, (away_x, away_y), away_tinted)
else: else:
self.logger.error(f"Away logo is None for team {self.current_game['away_abbr']}") self.logger.error(f"Away logo is None for team {self.current_game['away_abbr']}")
# Composite the layers in sequence with alpha blending # Composite the overlay with the main image
main_img = Image.alpha_composite(main_img, away_layer) main_img = Image.alpha_composite(main_img, overlay)
main_img = Image.alpha_composite(main_img, home_layer)
# Save debug image to check logo positions # Save debug image to check logo positions
debug_path = os.path.join(os.path.dirname(self.logo_dir), "debug_layout.png") debug_path = os.path.join(os.path.dirname(self.logo_dir), "debug_layout.png")
@@ -341,14 +346,16 @@ class BaseNHLManager:
# Calculate position for the score text (centered at the bottom) # Calculate position for the score text (centered at the bottom)
score_width = draw.textlength(score_text, font=self.fonts['score']) score_width = draw.textlength(score_text, font=self.fonts['score'])
score_x = (self.display_width - score_width) // 2 score_x = (self.display_width - score_width) // 2
score_y = 3 * self.display_height // 4 - 10 score_y = self.display_height - 15 # Position at bottom with padding
self.logger.info(f"Score text position: ({score_x}, {score_y})")
draw.text((score_x, score_y), score_text, font=self.fonts['score'], fill=(255, 255, 255)) draw.text((score_x, score_y), score_text, font=self.fonts['score'], fill=(255, 255, 255))
# Draw game status # Draw game status
status_text = self.current_game.get("status_text", "") status_text = self.current_game.get("status_text", "")
status_width = draw.textlength(status_text, font=self.fonts['status']) status_width = draw.textlength(status_text, font=self.fonts['status'])
status_x = (self.display_width - status_width) // 2 status_x = (self.display_width - status_width) // 2
status_y = self.display_height // 2 - 5 status_y = 5 # Position at top with padding
self.logger.info(f"Status text position: ({status_x}, {status_y})")
draw.text((status_x, status_y), status_text, font=self.fonts['status'], fill=(255, 255, 255)) draw.text((status_x, status_y), status_text, font=self.fonts['status'], fill=(255, 255, 255))
# Display the image # Display the image