style(board): replace hover crosshair with square name tag
public
style(board): replace hover crosshair with square name tag Tag prefers top-right (flush with board coordinates), then bottom-right, top-left, bottom-left when the hover arrow cuts it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Changeset | 489813b337434761f9d3b07ec03fd775bbda7eea |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | c02631b5642e |
| Children | 4e35d08bc0a1 |
| Pushlog | by timo via ssh by timo via ssh |
modified schach/diagram.py +44 −13
| @@ -295,9 +295,9 @@ class BoardPainter: | ||
| 295 | 295 | if self.threat_from is not None and self.threat_to is not None: |
| 296 | 296 | self._draw_arrow(cr, self.threat_from, self.threat_to, sq, THREAT) |
| 297 | 297 | if self.spotlight is not None: |
| 298 | - self._crosshair(cr, self.spotlight, sq, SPOTLIGHT) | |
| 299 | 298 | if self.spotlight_from is not None: |
| 300 | 299 | self._draw_arrow(cr, self.spotlight_from, self.spotlight, sq, SPOTLIGHT, outline=True) |
| 300 | + self._square_tag(cr, self.spotlight, sq, SPOTLIGHT, self.spotlight_from) | |
| 301 | 301 | for tail, head, color in self.shapes: |
| 302 | 302 | rgb = SHAPE_COLORS.get(color, SHAPE_COLORS["green"]) |
| 303 | 303 | if tail == head: |
| @@ -345,20 +345,51 @@ class BoardPainter: | ||
| 345 | 345 | cr.rectangle(x + inset, y + inset, sq - 2 * inset, sq - 2 * inset) |
| 346 | 346 | cr.stroke() |
| 347 | 347 | |
| 348 | - def _crosshair(self, cr, square, sq, rgb): | |
| 349 | - """Zielfeld wie im Visier: vier Kreisbögen in den Ecken, die Figur bleibt frei.""" | |
| 348 | + def _square_tag(self, cr, square, sq, rgb, came_from=None): | |
| 349 | + """Zielfeld mit Namensschild („c4“): die Figur bleibt frei, der Name steht da. | |
| 350 | + | |
| 351 | + Am liebsten oben rechts – bündig mit den Ziffern oben und den Buchstaben rechts am Brettrand. | |
| 352 | + Schneidet der Pfeil dort, dann unten rechts, oben links, zuletzt unten links. | |
| 353 | + """ | |
| 350 | 354 | x, y = self._square_origin(square) |
| 351 | - cx, cy = x + sq / 2, y + sq / 2 | |
| 355 | + text = chess.square_name(square) | |
| 352 | 356 | cr.save() |
| 353 | - cr.set_line_cap(cairo.LINE_CAP_ROUND) | |
| 354 | - for width, color in ((sq * 0.11, (0, 0, 0, 0.35)), (sq * 0.07, (*rgb, 1.0))): # dunkler Rand: auf jedem Feld sichtbar | |
| 355 | - cr.set_source_rgba(*color) | |
| 356 | - cr.set_line_width(width) | |
| 357 | - for corner in range(4): | |
| 358 | - middle = math.pi / 4 + corner * math.pi / 2 | |
| 359 | - cr.new_path() | |
| 360 | - cr.arc(cx, cy, sq * 0.44, middle - 0.42, middle + 0.42) | |
| 361 | - cr.stroke() | |
| 357 | + cr.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) | |
| 358 | + cr.set_font_size(sq * 0.2) | |
| 359 | + ext = cr.text_extents(text) | |
| 360 | + pad = sq * 0.05 | |
| 361 | + w, h = ext.width + 2 * pad, sq * 0.26 | |
| 362 | + inset = sq * 0.04 | |
| 363 | + corners = [(x + sq - w - inset, y + inset), (x + sq - w - inset, y + sq - h - inset), | |
| 364 | + (x + inset, y + inset), (x + inset, y + sq - h - inset)] | |
| 365 | + left, top = corners[0] | |
| 366 | + if came_from is not None: | |
| 367 | + fx, fy = self._square_origin(came_from) | |
| 368 | + shaft = [(x + sq / 2 + (fx - x) * t / 20, y + sq / 2 + (fy - y) * t / 20) for t in range(21)] | |
| 369 | + margin = sq * 0.06 # halber Schaft mit Rand | |
| 370 | + for cx, cy in corners: | |
| 371 | + if not any(cx - margin < px < cx + w + margin and cy - margin < py < cy + h + margin | |
| 372 | + for px, py in shaft): | |
| 373 | + left, top = cx, cy | |
| 374 | + break | |
| 375 | + else: | |
| 376 | + left, top = corners[-1] | |
| 377 | + r = h * 0.3 | |
| 378 | + cr.new_path() | |
| 379 | + cr.arc(left + w - r, top + r, r, -math.pi / 2, 0) | |
| 380 | + cr.arc(left + w - r, top + h - r, r, 0, math.pi / 2) | |
| 381 | + cr.arc(left + r, top + h - r, r, math.pi / 2, math.pi) | |
| 382 | + cr.arc(left + r, top + r, r, math.pi, 3 * math.pi / 2) | |
| 383 | + cr.close_path() | |
| 384 | + cr.set_source_rgba(*rgb, 1.0) | |
| 385 | + cr.fill_preserve() | |
| 386 | + cr.set_source_rgba(0, 0, 0, 0.35) # dunkler Rand: auf jedem Feld sichtbar | |
| 387 | + cr.set_line_width(sq * 0.02) | |
| 388 | + cr.stroke() | |
| 389 | + cr.set_source_rgb(0.15, 0.12, 0.05) | |
| 390 | + cr.move_to(left + pad - ext.x_bearing, top + h / 2 - ext.y_bearing - ext.height / 2) | |
| 391 | + cr.show_text(text) | |
| 392 | + cr.new_path() | |
| 362 | 393 | cr.restore() |
| 363 | 394 | |
| 364 | 395 | def _ring(self, cr, square, sq, rgb): |