Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defpackage :vn-render
- (:documentation "Render part of the engine")
- (:use :common-lisp :sdl)
- (:export
- :init-render
- :quit-render
- :Window
- :height
- :width
- :is-fullscreen-p
- :set-fullscreen
- :get-color-depth
- :set-color-depth
- :get-title
- :set-title
- :set-new-dimensions
- ))
- (in-package :vn-render)
- (defun init-render (&optional (driver "x11"))
- (sdl:set-video-driver driver)
- (sdl:init-video))
- (defun quit-render (&optional (force NIL))
- (sdl:quit-video force))
- (defclass Window ()
- ((window :documentation "window pointer"
- :reader window-pointer
- :initform NIL
- :initarg :win-pointer)
- (fullscreen :documentation "is fullscreen?"
- :reader is-fullscreen-p
- :initarg :fullscreen
- :initform NIL)
- (bpp :documentation "color depth"
- :reader get-color-depth
- :initarg :bpp
- :initform 32)
- (caption :documentation "window caption"
- :reader get-title
- :initarg :caption
- :initform "Unnamed")
- (w :documentation "Width of the window (internal)"
- :initform 0
- :reader width
- :initarg :width)
- (h :documentation "Height of the window (internal)"
- :initform 0
- :reader height
- :initarg :height)))
- (defvar *main-window* NIL)
- (defun has-window-p ()
- (if *main-window*
- T))
- (defgeneric refresh-window (w))
- (defmethod refresh-window ((window Window))
- (setf (slot-value window 'window)
- (sdl:window (width window)
- (height window)
- :HW T
- :POSITION #(0 0)
- :TITLE-CAPTION (get-title window)
- :ICON-CAPTION (get-title window)
- :RESIZABLE NIL
- :BPP (get-color-depth window)
- :ANY-FORMAT T
- :FULLSCREEN (is-fullscreen-p window))))
- (defgeneric set-fullscreen (w bool))
- (defmethod set-fullscreen ((window Window) bool)
- (setf (slot-value window 'fullscreen) bool)
- (refresh-window window)
- window)
- (defgeneric set-color-depth (w int))
- (defmethod set-color-depth ((window Window) (int Integer))
- (setf (slot-value window 'bpp) int)
- (refresh-window window)
- window)
- (defgeneric set-title (w cap))
- (defmethod set-title ((window Window) (caption String))
- (setf (slot-value window 'caption) caption)
- (refresh-window window)
- window)
- (defgeneric set-new-dimensions (window width height))
- (defmethod set-new-dimensions ((window Window) width height)
- (setf (slot-value window 'w) width)
- (setf (slot-value window 'h) height)
- (refresh-window window)
- window)
- (defun create-window (width height &optional (depth 32) (fullscreen NIL) (caption "Unnamed"))
- "creates window and sets it to the *main-window* plus returns it"
- (if (has-window-p)
- NIL
- (let ((mw (make-instance 'Window :width width :height height :bpp depth :fullscreen fullscreen :caption caption)))
- (refresh-window mw)
- (setf *main-window* mw)
- mw)))
Add Comment
Please, Sign In to add comment