;;;; 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 :graphics) #| ------------------------------------------- | This file manipulate the window and the | sdl initialization. | ------------------------------------------- |# (defmacro with-playground ((window renderer &key (title "RuLP") (width 740) (height 480)) &body body) `(sdl2:with-window (,window :title title :w width :h height :flags '(:resizable)) (sdl2:with-renderer (,renderer ,window :index -1 :flags '(:accelerated :presentvsync)) ;later add delta (sdl2-image:init '(:png :jpg)) (sdl2-ttf:init) ,@body (sdl2-ttf:quit) (sdl2-image:quit) ))) ;(defparameter +grid-span+ 50) ;; renderer exists only inside this function, so you cannot create a texture outside ;; (at least for now), more on this later os (defun playground (width height title &optional (fps 60) (debug-info nil)) (sdl2:with-init (:video) (with-playground (window *renderer* :title title :width width :height height) (setf *tr-texture* (let* ((font (sdl2-ttf:open-font "media/IBMPlex.ttf" 100)) ;; this line throw fault, works anyway (font-surface (sdl2-ttf:render-text-solid font *tr-string* 0 0 0 0)) (font-texture (sdl2:create-texture-from-surface *renderer* font-surface))) (sdl2:free-surface font-surface) font-texture)) (setf +plane+ (make-instance 'plane :image (truename "media/board.tga"))) (setf (entities-list +plane+) (list (make-instance 'entity))) (sdl2:with-event-loop (:method :poll) (:quit () t) (:mousebuttondown (:x x :y y :state state) (activate x y state +plane+)) (:idle () ;; clean window texture (sdl2:render-clear *renderer*) (when +plane+ (sdl2:render-copy *renderer* (texture +plane+) :source-rect (screen-source +plane+) :dest-rect (screen-destination +plane+ t)) (loop :for entities :in (entities-list +plane+) :do (when (displayp entities) (sdl2:render-copy *renderer* (texture entities) :source-rect (screen-source entities) :dest-rect (screen-destination entities +plane+)))) ;; Grid creation (when *is-grid* (grid-render *renderer* +plane+)) ;; Indexes creation (when *is-indexes* (indexes-render *renderer* +plane+)) ) ;; pointer section (when *pointer* (sdl2:set-render-draw-color *renderer* 128 250 33 255) (let ((select-rectangle (screen-destination (nth *pointer* (entities-list +plane+)) +plane+))) (sdl2:render-draw-rect *renderer* select-rectangle)) (sdl2:set-render-draw-color *renderer* 0 0 0 255) ) (sdl2:render-present *renderer*) )))))