Files
garmin-padel/source/CourtRenderer.mc
Christophe Vila 926f876a6e feat: refine watch UI — arc HR gauge, proper padel court, spacing
- HR shown as a top arc gauge in Garmin zone colors (grey/blue/green/
  orange/red) with a marker on the current zone and the bpm number below
- Redraw court to a proper padel layout: net centered, service lines at
  the 3m-from-back-wall proportion, center line only between service lines
- Wider court with a configurable blue surface (bgColor param on
  CourtRenderer, ready for the future settings screen)
- Serve ball marks the back zone (farthest from the net) of the server
- Roomier score spacing; games column white, sets accent green; "Pts"
- HR + time on a matched FONT_MEDIUM

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-04 16:42:33 +02:00

53 lines
2.3 KiB
MonkeyC

import Toybox.Lang;
import Toybox.Graphics;
// Draws a top-down padel court centered at (cx, cy) and a yellow serve ball
// in the given quadrant. Half-width HW and half-height HH keep it inside the
// central band of the round screen.
class CourtRenderer {
private const HW = 92; // half court width (px)
private const HH = 95; // half court height (px)
private const BALL_R = 7;
// bgColor fills the court surface (blue for now; a future settings screen
// will drive it via RulesConfig).
public function draw(dc as Graphics.Dc, cx as Number, cy as Number,
quadrant as Number, showBall as Boolean,
bgColor as Number) as Void {
var left = cx - HW;
var top = cy - HH;
// Service line sits 3m from the back wall (7m from the net) on a 10m
// half, i.e. 0.7 of the way from the net to the back boundary.
var sl = (7 * HH) / 10;
dc.setColor(bgColor, Graphics.COLOR_TRANSPARENT);
dc.fillRectangle(left, top, 2 * HW, 2 * HH); // court surface
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
dc.setPenWidth(2);
dc.drawRectangle(left, top, 2 * HW, 2 * HH); // outer boundary
dc.drawLine(left, cy - sl, left + 2 * HW, cy - sl); // upper service line
dc.drawLine(left, cy + sl, left + 2 * HW, cy + sl); // lower service line
dc.drawLine(cx, cy - sl, cx, cy + sl); // center line (between service lines only)
dc.setPenWidth(4);
dc.drawLine(left, cy, left + 2 * HW, cy); // net (boldest)
if (showBall) {
var pos = _ballPos(quadrant, cx, cy);
dc.setColor(Graphics.COLOR_YELLOW, Graphics.COLOR_TRANSPARENT);
dc.fillCircle(pos[0], pos[1], BALL_R);
}
}
private function _ballPos(quadrant as Number, cx as Number, cy as Number) as Array<Number> {
var dx = HW / 2;
var dy = (17 * HH) / 20; // centered in the back zone, farthest from the net
if (quadrant == QUAD_BOTTOM_RIGHT) { return [cx + dx, cy + dy]; }
if (quadrant == QUAD_BOTTOM_LEFT) { return [cx - dx, cy + dy]; }
if (quadrant == QUAD_UPPER_LEFT) { return [cx - dx, cy - dy]; }
return [cx + dx, cy - dy]; // QUAD_UPPER_RIGHT
}
}