;;;; Ru*** roLeplay Playground virtual tabletop ;;;; Copyright (C) 2022 Zull ;;;; ;;;; This program is free software: you can redistribute it and/or modify ;;;; it under the terms of the GNU General Public License as published by ;;;; the Free Software Foundation, either version 3 of the License, or ;;;; (at your option) any later version. ;;;; ;;;; This program is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;;; GNU General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU General Public License ;;;; along with this program. If not, see . (in-package :rulp.graphics) (defparameter *tr-s-rectangle* (sdl2:make-rect 0 0 60 130)) ; FIXME: hardcoded, ; defparameter over ; font for ; generalization (defparameter *tr-d-rectangle* (sdl2:make-rect 0 0 10 10)) (defun coordinate-to-grid-index (value) "translate a coordinate into the chess coordinate as a string" (let ((first (format nil "~c" (elt *alphabet* (mod (car value) (length *alphabet*))))) (second (format nil "~d" (cdr value)))) (concatenate 'string first second))) (defun tr-parse-string (s) "Translate a string into the coordinates used to print with tr-write" (loop :for i :across s :collect (position i *tr-string*))) (defmacro tr-write (value x y width height renderer) `(let ((value-indexes (tr-parse-string ,value))) (loop :for character :in value-indexes :for character-position :from 0 :to (length value-indexes) :do (setf (sdl2:rect-x *tr-s-rectangle*) (* character 60) (sdl2:rect-x *tr-d-rectangle*) (+ ,x (* character-position ,width)) (sdl2:rect-y *tr-d-rectangle*) ,y (sdl2:rect-width *tr-d-rectangle*) ,width (sdl2:rect-height *tr-d-rectangle*) ,height) (sdl2:render-copy ,renderer *tr-texture* :source-rect *tr-s-rectangle* :dest-rect *tr-d-rectangle*))))