;;;; 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) (defparameter +mode+ '+normal-mode+) (defgeneric activate (x y pressed p) (:documentation "given x y and the button pressed it do actions")) (defmethod activate (x y pressed (p plane)) (loop :for key :in *mouse-keybinds* :do (when (sdl2:mouse-state-p (eval (car key))) (apply (cadr key) `(,x ,y ,p)) ))) (defmethod select-pointer (x y (p plane)) "with left button it select and deselect entities the map-gplane contain" (let ((mouse-point (sdl2:make-rect x y 10 10)) (entities (entities-list p))) (setf *pointer* nil) (loop :for obj :in entities :for obj-nth :from 0 :to (length entities) :do (when (sdl2:has-intersect mouse-point (screen-destination obj p)) (setf *pointer* obj-nth))) )) (defmethod move-entity (x y (p plane)) "with right button it move the entity around the plane" (when (numberp *pointer*) (let* ((x-offset (x p)) (y-offset (y p)) (i-x (floor (/ (- x x-offset) (grid-dimension p)))) (i-y (floor (/ (- y y-offset) (grid-dimension p)))) (object (nth *pointer* (entities-list p)))) (setf (coordinate object) (cons i-x i-y)) (setf (x object) i-x) (setf (y object) i-y) )))