diff --git a/coordinates/w128h32.json.example b/coordinates/w128h32.json.example index c181acdf..5621a376 100644 --- a/coordinates/w128h32.json.example +++ b/coordinates/w128h32.json.example @@ -301,6 +301,7 @@ }, "record": { "enabled": false, + "position": "absolute", "away": { "font_name": "4x6", "x": 19, @@ -378,4 +379,4 @@ "y": 31 } } -} +} \ No newline at end of file diff --git a/coordinates/w128h64.json.example b/coordinates/w128h64.json.example index 184a7e0c..6e67c098 100644 --- a/coordinates/w128h64.json.example +++ b/coordinates/w128h64.json.example @@ -281,6 +281,7 @@ }, "record": { "enabled": false, + "position": "absolute", "away": { "x": 30, "y": 13 @@ -359,4 +360,4 @@ "y": 63 } } -} +} \ No newline at end of file diff --git a/coordinates/w192h64.json.example b/coordinates/w192h64.json.example index 6f010530..1dc6b1ad 100644 --- a/coordinates/w192h64.json.example +++ b/coordinates/w192h64.json.example @@ -281,6 +281,7 @@ }, "record": { "enabled": false, + "position": "absolute", "away": { "x": 30, "y": 13 @@ -359,4 +360,4 @@ "y": 63 } } -} +} \ No newline at end of file diff --git a/coordinates/w32h32.json.example b/coordinates/w32h32.json.example index 31a8dd0a..7a55924f 100644 --- a/coordinates/w32h32.json.example +++ b/coordinates/w32h32.json.example @@ -288,6 +288,7 @@ }, "record": { "enabled": false, + "position": "absolute", "away": { "x": 4, "y": 6 @@ -363,4 +364,4 @@ "y": 31 } } -} +} \ No newline at end of file diff --git a/coordinates/w64h32.json.example b/coordinates/w64h32.json.example index a9ee194b..51786014 100644 --- a/coordinates/w64h32.json.example +++ b/coordinates/w64h32.json.example @@ -153,7 +153,6 @@ "desc_length": "short", "enabled": true } - }, "batter_count": { "x": 34, @@ -275,6 +274,7 @@ }, "record": { "enabled": false, + "position": "absolute", "away": { "x": 15, "y": 6 @@ -350,4 +350,4 @@ "y": 31 } } -} +} \ No newline at end of file diff --git a/coordinates/w64h64.json.example b/coordinates/w64h64.json.example index 5ec273bb..eecefa32 100644 --- a/coordinates/w64h64.json.example +++ b/coordinates/w64h64.json.example @@ -257,6 +257,7 @@ }, "record": { "enabled": false, + "position": "absolute", "away": { "font_name": "4x6", "x": 18, @@ -334,4 +335,4 @@ "y": 63 } } -} +} \ No newline at end of file diff --git a/renderers/games/teams.py b/renderers/games/teams.py index 5d7bb78f..572e306d 100644 --- a/renderers/games/teams.py +++ b/renderers/games/teams.py @@ -1,5 +1,8 @@ from driver import graphics +ABSOLUTE = "absolute" +RELATIVE = "relative" + def render_team_banner( canvas, layout, team_colors, home_team, away_team, full_team_names, short_team_names_for_runs_hits, show_score, ): @@ -55,11 +58,11 @@ def render_team_banner( canvas, full_team_names, short_team_names_for_runs_hits, [home_team, away_team] ) - __render_team_text(canvas, layout, away_colors, away_team, "away", use_full_team_names, default_colors) - __render_team_text(canvas, layout, home_colors, home_team, "home", use_full_team_names, default_colors) + away_name_end_pos = __render_team_text(canvas, layout, away_colors, away_team, "away", use_full_team_names, default_colors) + home_name_end_pos = __render_team_text(canvas, layout, home_colors, home_team, "home", use_full_team_names, default_colors) - __render_record_text(canvas, layout, away_colors, away_team, "away", default_colors) - __render_record_text(canvas, layout, home_colors, home_team, "home", default_colors) + __render_record_text(canvas, layout, away_colors, away_team, "away", default_colors, away_name_end_pos) + __render_record_text(canvas, layout, home_colors, home_team, "home", default_colors, home_name_end_pos) if show_score: # Number of characters in each score. @@ -108,12 +111,14 @@ def __render_team_text(canvas, layout, colors, team, homeaway, full_team_names, text_color_graphic = graphics.Color(text_color["r"], text_color["g"], text_color["b"]) coords = layout.coords("teams.name.{}".format(homeaway)) font = layout.font("teams.name.{}".format(homeaway)) - team_text = "{:3s}".format(team.abbrev.upper()) + team_text = "{:3s}".format(team.abbrev.upper()).strip() if full_team_names: - team_text = "{:13s}".format(team.name) + team_text = "{:13s}".format(team.name).strip() graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], text_color_graphic, team_text) -def __render_record_text(canvas, layout, colors, team, homeaway, default_colors): + return (coords["x"] + (len(team_text) * font["size"]["width"]), coords["y"]) + +def __render_record_text(canvas, layout, colors, team, homeaway, default_colors, origin): if "losses" not in team.record or "wins" not in team.record: return if not layout.coords("teams.record").get("enabled", False): @@ -124,8 +129,14 @@ def __render_record_text(canvas, layout, colors, team, homeaway, default_colors) coords = layout.coords("teams.record.{}".format(homeaway)) font = layout.font("teams.record.{}".format(homeaway)) record_text = "({}-{})".format(team.record["wins"], team.record["losses"]) - graphics.DrawText(canvas, font["font"], coords["x"], coords["y"], text_color_graphic, record_text) + if layout.coords("teams.record").get("position", ABSOLUTE) != RELATIVE: + origin = (0, 0) + + x = coords["x"] + origin[0] + y = coords["y"] + origin[1] + + graphics.DrawText(canvas, font["font"], x, y, text_color_graphic, record_text) def __render_score_component(canvas, layout, colors, homeaway, default_colors, coords, component_val, width_chars): # The coords passed in are the rightmost pixel.