diff --git a/src/package.lisp b/src/package.lisp index cc4f7ac..b4312bf 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -13,9 +13,9 @@ #:define-start-function ;; window - #:window #:gl-window #:initialize-window + #:window #:gl-window #:2d-window #:initialize-window - #:sdl-window #:sdl-window-id #:gl-context #:window-from-id + #:sdl-window #:sdl-window-id #:gl-context #:renderer #:window-from-id #:render-enabled #:all-windows #:focused-window #:last-window diff --git a/src/window.lisp b/src/window.lisp index f08ce7c..05d41f8 100644 --- a/src/window.lisp +++ b/src/window.lisp @@ -209,6 +209,30 @@ a cons, e.g. `(10 . 10)`." #+nil (format *error-output* "Unhandled event: ~S~%" (sdl2:get-event-type event))) +;;;;;; 2D-WINDOW + +(defclass 2d-window (window) + ((renderer :initform nil :reader renderer))) + +(defmethod initialize-window progn ((window 2d-window) &key &allow-other-keys) + (with-slots (renderer sdl-window) window + (setf renderer (sdl2:create-renderer sdl-window)))) + +(defmethod render :before ((window 2d-window)) + (with-slots (renderer) window + (sdl2-ffi.functions:sdl-render-clear renderer))) + +(defmethod render :after ((window 2d-window)) + (with-slots (renderer) window + (sdl2:render-present renderer))) + +(defmethod close-window ((window 2d-window)) + (with-slots (renderer) window + (when (and (slot-boundp window 'renderer) renderer) + (sdl2:destroy-renderer renderer))) + (call-next-method)) + + ;;;; GL-WINDOW (defmethod initialize-window progn