2026-07-04 10:44:07 +02:00
|
|
|
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 {
|
2026-07-04 16:42:33 +02:00
|
|
|
private const HW = 92; // half court width (px)
|
|
|
|
|
private const HH = 95; // half court height (px)
|
|
|
|
|
private const BALL_R = 7;
|
2026-07-04 10:44:07 +02:00
|
|
|
|
2026-07-04 16:42:33 +02:00
|
|
|
// bgColor fills the court surface (blue for now; a future settings screen
|
|
|
|
|
// will drive it via RulesConfig).
|
2026-07-04 10:44:07 +02:00
|
|
|
public function draw(dc as Graphics.Dc, cx as Number, cy as Number,
|
2026-07-04 16:42:33 +02:00
|
|
|
quadrant as Number, showBall as Boolean,
|
|
|
|
|
bgColor as Number) as Void {
|
2026-07-04 10:44:07 +02:00
|
|
|
var left = cx - HW;
|
|
|
|
|
var top = cy - HH;
|
|
|
|
|
|
2026-07-04 16:42:33 +02:00
|
|
|
// 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
|
|
|
|
|
|
2026-07-04 10:44:07 +02:00
|
|
|
dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
|
|
|
|
|
dc.setPenWidth(2);
|
2026-07-04 16:42:33 +02:00
|
|
|
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)
|
2026-07-04 10:44:07 +02:00
|
|
|
|
2026-07-04 16:42:33 +02:00
|
|
|
dc.setPenWidth(4);
|
|
|
|
|
dc.drawLine(left, cy, left + 2 * HW, cy); // net (boldest)
|
2026-07-04 10:44:07 +02:00
|
|
|
|
|
|
|
|
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;
|
2026-07-04 16:42:33 +02:00
|
|
|
var dy = (17 * HH) / 20; // centered in the back zone, farthest from the net
|
2026-07-04 10:44:07 +02:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|