From 19e2afa38a33e3b9319909dd387587cc30110c0d Mon Sep 17 00:00:00 2001 From: ChuckBuilds <33324927+ChuckBuilds@users.noreply.github.com> Date: Fri, 18 Apr 2025 12:41:38 -0500 Subject: [PATCH] Improved NHL scoreboard layout: Added proper spacing, bounds checking, and repositioned elements to prevent overlap --- src/nhl_managers.py | 59 +++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/src/nhl_managers.py b/src/nhl_managers.py index 344b2dbc..26fd9d80 100644 --- a/src/nhl_managers.py +++ b/src/nhl_managers.py @@ -240,6 +240,7 @@ class BaseNHLManager: home_logo = self._load_and_resize_logo(self.current_game["home_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"Away team ({self.current_game['away_abbr']}) logo loaded: {away_logo is not None}") @@ -248,21 +249,24 @@ class BaseNHLManager: if away_logo: self.logger.info(f"Away logo size: {away_logo.size}, mode: {away_logo.mode}") - # Create separate layers for each logo with glow effect - home_layer = 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)) - - # Create glow layers - home_glow = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0)) - away_glow = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0)) + # Create a single overlay for both logos + overlay = Image.new('RGBA', (self.display_width, self.display_height), (0, 0, 0, 0)) + + # Calculate vertical center line for alignment + center_y = self.display_height // 2 + self.logger.info(f"Vertical center line: {center_y}") # Draw home team logo (far right) if home_logo: - # Position home logo at the far right - home_x = self.display_width - home_logo.width - 5 # 5 pixels padding from right edge - home_y = (self.display_height - home_logo.height) // 2 # Vertically centered + # Position home logo at the far right with padding + home_x = self.display_width - home_logo.width - 10 # Increased padding to 10 pixels + home_y = center_y - (home_logo.height // 2) # Center vertically 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 home_tinted = home_logo.copy() home_tinted_data = home_tinted.load() @@ -274,7 +278,7 @@ class BaseNHLManager: home_tinted_data[x, y] = (r, g, min(255, b + 200), a) # 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_draw.ellipse([ home_x - 10, home_y - 10, @@ -282,19 +286,22 @@ class BaseNHLManager: home_y + home_logo.height + 10 ], fill=glow_color) - # Paste glow first, then logo - home_layer.paste(home_glow, (0, 0), home_glow) - home_layer.paste(home_tinted, (home_x, home_y), home_tinted) + # Paste the home logo onto the overlay + overlay.paste(home_tinted, (home_x, home_y), home_tinted) else: self.logger.error(f"Home logo is None for team {self.current_game['home_abbr']}") # Draw away team logo (far left) if away_logo: - # Position away logo at the far left - away_x = 5 # 5 pixels padding from left edge - away_y = (self.display_height - away_logo.height) // 2 # Vertically centered + # Position away logo at the far left with padding + away_x = 10 # Increased padding to 10 pixels + away_y = center_y - (away_logo.height // 2) # Center vertically 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 away_tinted = away_logo.copy() away_tinted_data = away_tinted.load() @@ -306,7 +313,7 @@ class BaseNHLManager: away_tinted_data[x, y] = (min(255, r + 200), g, b, a) # 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_draw.ellipse([ away_x - 10, away_y - 10, @@ -314,15 +321,13 @@ class BaseNHLManager: away_y + away_logo.height + 10 ], fill=glow_color) - # Paste glow first, then logo - away_layer.paste(away_glow, (0, 0), away_glow) - away_layer.paste(away_tinted, (away_x, away_y), away_tinted) + # Paste the away logo onto the overlay + overlay.paste(away_tinted, (away_x, away_y), away_tinted) else: self.logger.error(f"Away logo is None for team {self.current_game['away_abbr']}") - # Composite the layers in sequence with alpha blending - main_img = Image.alpha_composite(main_img, away_layer) - main_img = Image.alpha_composite(main_img, home_layer) + # Composite the overlay with the main image + main_img = Image.alpha_composite(main_img, overlay) # Save debug image to check logo positions 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) score_width = draw.textlength(score_text, font=self.fonts['score']) 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 game status status_text = self.current_game.get("status_text", "") status_width = draw.textlength(status_text, font=self.fonts['status']) 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)) # Display the image