Guest User

Untitled

a guest
Jul 11th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 3.07 KB | None | 0 0
  1. (defpackage :vn-render
  2.   (:documentation "Render part of the engine")
  3.   (:use :common-lisp :sdl)
  4.   (:export
  5.    :init-render
  6.    :quit-render
  7.    :Window
  8.    :height
  9.    :width
  10.    :is-fullscreen-p
  11.    :set-fullscreen
  12.    :get-color-depth
  13.    :set-color-depth
  14.    :get-title
  15.    :set-title
  16.    :set-new-dimensions
  17.    ))
  18.  
  19. (in-package :vn-render)
  20.  
  21. (defun init-render (&optional (driver "x11"))
  22.   (sdl:set-video-driver driver)
  23.   (sdl:init-video))
  24.  
  25. (defun quit-render (&optional (force NIL))
  26.   (sdl:quit-video force))
  27.  
  28. (defclass Window ()
  29.   ((window :documentation "window pointer"
  30.            :reader window-pointer
  31.            :initform NIL
  32.            :initarg :win-pointer)
  33.    (fullscreen :documentation "is fullscreen?"
  34.                :reader is-fullscreen-p
  35.                :initarg :fullscreen
  36.                :initform NIL)
  37.    (bpp :documentation "color depth"
  38.         :reader get-color-depth
  39.         :initarg :bpp
  40.         :initform 32)
  41.    (caption :documentation "window caption"
  42.             :reader get-title
  43.             :initarg :caption
  44.             :initform "Unnamed")
  45.    (w :documentation "Width of the window (internal)"
  46.       :initform 0
  47.       :reader width
  48.       :initarg :width)
  49.    (h :documentation "Height of the window (internal)"
  50.       :initform 0
  51.       :reader height
  52.       :initarg :height)))
  53.  
  54. (defvar *main-window* NIL)
  55.  
  56. (defun has-window-p ()
  57.   (if *main-window*
  58.       T))
  59.  
  60. (defgeneric refresh-window (w))
  61.  
  62. (defmethod refresh-window ((window Window))
  63.   (setf (slot-value window 'window)
  64.         (sdl:window (width window)
  65.                     (height window)
  66.                     :HW T
  67.                     :POSITION #(0 0)
  68.                     :TITLE-CAPTION (get-title window)
  69.                     :ICON-CAPTION (get-title window)
  70.                     :RESIZABLE NIL
  71.                     :BPP (get-color-depth window)
  72.                     :ANY-FORMAT T
  73.                     :FULLSCREEN (is-fullscreen-p window))))
  74.  
  75. (defgeneric set-fullscreen (w bool))
  76.  
  77. (defmethod set-fullscreen ((window Window) bool)
  78.   (setf (slot-value window 'fullscreen) bool)
  79.   (refresh-window window)
  80.   window)
  81.  
  82. (defgeneric set-color-depth (w int))
  83.  
  84. (defmethod set-color-depth ((window Window) (int Integer))
  85.   (setf (slot-value window 'bpp) int)
  86.   (refresh-window window)
  87.   window)
  88.  
  89. (defgeneric set-title (w cap))
  90.  
  91. (defmethod set-title ((window Window) (caption String))
  92.   (setf (slot-value window 'caption) caption)
  93.   (refresh-window window)
  94.   window)
  95.  
  96. (defgeneric set-new-dimensions (window width height))
  97.  
  98. (defmethod set-new-dimensions ((window Window) width height)
  99.   (setf (slot-value window 'w) width)
  100.   (setf (slot-value window 'h) height)
  101.   (refresh-window window)
  102.   window)
  103.  
  104. (defun create-window (width height &optional (depth 32) (fullscreen NIL) (caption "Unnamed"))
  105.   "creates window and sets it to the *main-window* plus returns it"
  106.   (if (has-window-p)
  107.       NIL
  108.     (let ((mw (make-instance 'Window :width width :height height :bpp depth :fullscreen fullscreen :caption caption)))
  109.       (refresh-window mw)
  110.       (setf *main-window* mw)
  111.       mw)))
Add Comment
Please, Sign In to add comment