Wire cg-gaps and cg-bid display through the renderer registry

This commit is contained in:
Corwin Brust 2026-06-23 22:17:54 -05:00
parent 2c29d5db35
commit 8d1902c8e6
2 changed files with 58 additions and 22 deletions

View file

@ -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 ()

View file

@ -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)))