OSDN Git Service

layers/screens.lisp: created render and getscreen functions
[rulp/rulp.git] / render / render.lisp
index c7e0075..f708040 100644 (file)
@@ -41,6 +41,9 @@ used by itself, the functions in this package will use it for you.")
   necessary without creating and destroying rectangles. Use this with
 the rectangle function.")
 
+(defun make-rectangle (x y width height)
+  (sdl2:make-rect x y width height))
+
 (defun move-rectangle (x y width height rectangle)
   "setup a rectangle and return it"
   (setf (sdl2:rect-x rectangle) x)
@@ -66,14 +69,29 @@ the rectangle function.")
   "These rectangles are cache used by render-texture to renderize without
   creating and destroying them every time")
 
-(defun render-texture (source-x source-y source-width source-height
-                       dest-x dest-y dest-width dest-height
+(defun render-texture (source-list
+                       destination-list
                        texture)
-  (move-rectangle source-x source-y source-width source-height (car *texture-cache-rectangles*))
-  (move-rectangle dest-x dest-y dest-width dest-height (cdr *texture-cache-rectangles*))
-  (sdl2:render-copy *renderer* texture
-                    (car *texture-cache-rectangles*)
+  "Given two list of four numbers (x y width height) or empty lists it render
+them on screen. When given an empty list it uses the whole source or destination
+to print the result. If source-list is nil then the whole texture is displayed,
+if destination-list is nil then the selected texture is displayed on the whole
+window or destination screen buffer."
+  (when source-list
+    (move-rectangle (nth 0 source-list) (nth 1 source-list)
+                    (nth 2 source-list) (nth 3 source-list)
+                    (car *texture-cache-rectangles*)))
+  (when destination-list
+    (move-rectangle (nth 0 destination-list) (nth 1 destination-list)
+                    (nth 2 destination-list) (nth 3 destination-list)
                     (cdr *texture-cache-rectangles*)))
+  (sdl2:render-copy *renderer* texture
+                    :source-rect (if source-list
+                                     (car *texture-cache-rectangles*)
+                                     nil)
+                    :dest-rect (if destination-list
+                                   (cdr *texture-cache-rectangles*)
+                                   nil)))
 
 ;; collision detection
 (defun intersect-square (source-x source-y source-width source-height
@@ -85,3 +103,18 @@ the rectangle function.")
 (defun intersect-point (source-x source-y source-width source-height
                         point-x point-y)
   (intersect-square source-x source-y source-width source-height point-x point-y 10 10))
+
+(defun load-texture (path)
+  (let* ((temporary-surface nil))
+    (setf temporary-surface (sdl2-image:load-image path))
+    (prog1
+        (sdl2:create-texture-from-surface *renderer* temporary-surface)
+      (sdl2:free-surface temporary-surface))
+    )
+  )
+
+(defun texture-width (texture)
+  (sdl2:texture-width texture))
+
+(defun texture-height (texture)
+  (sdl2:texture-height texture))