From 8d1902c8e6d6486a657de060b8a0b9ffc915b15a Mon Sep 17 00:00:00 2001 From: Corwin Brust Date: Tue, 23 Jun 2026 22:17:54 -0500 Subject: [PATCH] Wire cg-gaps and cg-bid display through the renderer registry --- cg-bid-ui.el | 37 +++++++++++++++++++++++++++++-------- cg-gaps.el | 43 +++++++++++++++++++++++++++++-------------- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/cg-bid-ui.el b/cg-bid-ui.el index 35cccd5..472524e 100644 --- a/cg-bid-ui.el +++ b/cg-bid-ui.el @@ -33,6 +33,7 @@ (require 'cg-core) (require 'cg-bid) (require 'cg-svg) +(require 'cg-render) (require 'svg) (require 'color) @@ -388,17 +389,37 @@ Folds the controls into the single action-button row (see (cg-bid--button "[Help]" #'cg-bid-help "Show help") (insert "\n")) +(cl-defmethod cg-renderer-draw ((_renderer cg-text-renderer) (game cg-bid-game)) + "Draw the 500 GAME as UNICODE text with the action buttons." + (insert (cg-render game)) + (cg-bid--insert-buttons game)) + +(cl-defmethod cg-renderer-draw ((_renderer cg-svg-renderer) (game cg-bid-game)) + "Draw the 500 GAME as an SVG table with the action buttons." + (cg-bid--insert-graphical game) + (cg-bid--insert-buttons game)) + +(cl-defmethod cg-renderer-draw ((_renderer cg-svg-fill-renderer) (game cg-bid-game)) + "Draw the 500 GAME as a frameless full-window SVG table." + (cg-bid--insert-svg-ui game)) + +(defun cg-bid--treatment () + "Return the display treatment symbol for the current 500 buffer. +Honours `cg-bid-svg-ui' and whether the display is graphical." + (cond ((and cg-bid-svg-ui (display-graphic-p)) 'svg-fill) + ((display-graphic-p) 'svg) + (t 'text))) + (defun cg-bid--redisplay () - "Redraw the current 500 buffer (SVG table on a graphical display)." - (let ((inhibit-read-only t) (game cg-bid--game)) + "Redraw the current 500 buffer through its renderer. +The treatment is chosen by `cg-bid--treatment' and dispatched with +`cg-renderer-draw'." + (let* ((inhibit-read-only t) + (game cg-bid--game) + (renderer (cg-render-set-treatment game (cg-bid--treatment)))) (setq-local mode-line-process (cg-bid--mode-line game)) (erase-buffer) - (if (and cg-bid-svg-ui (display-graphic-p)) - (cg-bid--insert-svg-ui game) - (if (display-graphic-p) - (cg-bid--insert-graphical game) - (insert (cg-render game))) - (cg-bid--insert-buttons game)) + (cg-renderer-draw renderer game) (goto-char (point-min)))) (defun cg-bid--refresh () diff --git a/cg-gaps.el b/cg-gaps.el index 3df9a5a..d05aa02 100644 --- a/cg-gaps.el +++ b/cg-gaps.el @@ -49,6 +49,7 @@ (require 'cg-core) (require 'cg-svg) +(require 'cg-render) ;;;; Cards @@ -419,23 +420,37 @@ buttons (the keyboard hint *is* the button)." (cg-gaps--key-button "?" "help" #'cg-gaps-help "Show the rules and keys") (insert "\n")) +(cl-defmethod cg-renderer-draw ((_renderer cg-text-renderer) (game cg-gaps-game)) + "Draw the Gaps GAME as UNICODE text with the control line." + (insert (cg-render game)) + (cg-gaps--insert-controls)) + +(cl-defmethod cg-renderer-draw ((_renderer cg-svg-renderer) (game cg-gaps-game)) + "Draw the Gaps GAME as an inline SVG board with the control line." + (cg-gaps--insert-graphical game) + (cg-gaps--insert-controls)) + +(cl-defmethod cg-renderer-draw ((_renderer cg-svg-fill-renderer) (game cg-gaps-game)) + "Draw the Gaps GAME as a full-window SVG table." + (cg-gaps--insert-svg-ui game)) + +(defun cg-gaps--treatment () + "Return the display treatment symbol for the current Gaps buffer. +Honours `cg-gaps-svg-ui' and whether the display is graphical." + (cond ((and cg-gaps-svg-ui (display-graphic-p)) 'svg-fill) + ((display-graphic-p) 'svg) + (t 'text))) + (defun cg-gaps--redisplay () - "Redraw the current Gaps buffer. -Full-buffer SVG when `cg-gaps-svg-ui'; otherwise an inline SVG board (or -UNICODE text on a terminal), each followed by the single control line." - (let ((game cg-gaps--game) - (inhibit-read-only t)) + "Redraw the current Gaps buffer through its renderer. +The treatment is chosen by `cg-gaps--treatment' and dispatched with +`cg-renderer-draw'." + (let* ((game cg-gaps--game) + (inhibit-read-only t) + (renderer (cg-render-set-treatment game (cg-gaps--treatment)))) (setq-local mode-line-process (cg-gaps--mode-line game)) (erase-buffer) - (cond - ((and cg-gaps-svg-ui (display-graphic-p)) - (cg-gaps--insert-svg-ui game)) - ((display-graphic-p) - (cg-gaps--insert-graphical game) - (cg-gaps--insert-controls)) - (t - (insert (cg-render game)) - (cg-gaps--insert-controls))) + (cg-renderer-draw renderer game) (if (display-graphic-p) (goto-char (point-min)) (let ((cur (cg-get game :cursor)))