1 ;;;; Ru*** roLeplay Playground virtual tabletop
2 ;;;; Copyright (C) 2022 Zull
4 ;;;; This program is free software: you can redistribute it and/or modify
5 ;;;; it under the terms of the GNU General Public License as published by
6 ;;;; the Free Software Foundation, either version 3 of the License, or
7 ;;;; (at your option) any later version.
9 ;;;; This program is distributed in the hope that it will be useful,
10 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;;; GNU General Public License for more details.
14 ;;;; You should have received a copy of the GNU General Public License
15 ;;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
17 (in-package :graphics)
19 (defun coordinate-to-grid-index (value)
20 "translate a coordinate into the chess coordinate as a string"
21 (let ((first (format nil "~c" (elt *alphabet* (mod (car value) (length *alphabet*)))))
22 (second (format nil "~d" (cdr value))))
23 (concatenate 'string first second)))
25 (defun tr-parse-string (s)
26 "Translate a string into the coordinates used to print with tr-write"
27 (loop :for i :across s
29 (position i *tr-string*)))
31 (defmacro tr-write (value x y width height renderer)
32 `(let ((value-indexes (tr-parse-string ,value)))
33 (loop :for character :in value-indexes
34 :for character-position :from 0 :to (length value-indexes)
35 :do (sdl2:render-copy ,renderer *tr-texture*
36 :source-rect (sdl2:make-rect (* character 60) 0 60 130)
37 :dest-rect (sdl2:make-rect (+ ,x (* character-position ,width)) ,y ,width ,height)))))