diff --git a/clog-canvas.lisp b/clog-canvas.lisp new file mode 100644 index 0000000..d7b5d9d --- /dev/null +++ b/clog-canvas.lisp @@ -0,0 +1,64 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; CLOG - The Common Lisp Omnificent GUI ;;;; +;;;; (c) 2020-2021 David Botton ;;;; +;;;; License BSD 3 Clause ;;;; +;;;; ;;;; +;;;; clog-canvas.lisp ;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(cl:in-package :clog) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Implementation - clog-canvas +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defclass clog-canvas (clog-element)() + (:documentation "CLOG Canvas Objects.")) + + +;;;;;;;;;;;;;;;;;;; +;; create-canvas ;; +;;;;;;;;;;;;;;;;;;; + +(defgeneric create-canvas (clog-obj &key auto-place) + (:documentation "Create a new CLOG-Canvas as child of CLOG-OBJ if +:AUTO-PLACE (default t) place-inside-bottom-of CLOG-OBJ.")) + +(defmethod create-canvas ((obj clog-obj) &key (auto-place t)) + (create-child obj "" + :clog-type 'clog-canvas :auto-place auto-place)) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Implementation - clog-context2d +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defclass clog-context2d () + ((connection-id + :reader connection-id + :initarg :connection-id) + (html-id + :reader html-id + :initarg :html-id)) + (:documentation "CLOG Context Objects.")) + +;;;;;;;;;;;;;;;;;;;;;; +;; create-context2d ;; +;;;;;;;;;;;;;;;;;;;;;; + +(defgeneric create-context2d (clog-canvas) + (:documentation "Create a new CLOG-Context2d from a CLOG-Canvas")) + + +(defmethod create-context2d ((obj clog-canvas)) + (let ((web-id (cc:generate-id))) + (cc:execute (connection-id obj) + (format nil "clog['~A']=clog['~A'].get(0).getContext('2d')" + web-id + (html-id obj))) + + (make-instance 'clog-context2d + :connection-id (connection-id obj) + :html-id web-id))) + diff --git a/clog.asd b/clog.asd index 0bce800..548caed 100644 --- a/clog.asd +++ b/clog.asd @@ -18,6 +18,7 @@ (:file "clog-base") (:file "clog-element") (:file "clog-element-common") + (:file "clog-canvas") (:file "clog-form") (:file "clog-window") (:file "clog-document") diff --git a/clog.lisp b/clog.lisp index a4e5877..34e42ac 100644 --- a/clog.lisp +++ b/clog.lisp @@ -33,6 +33,7 @@ application." (@clog-element section) (@clog-element-common section) (@clog-form section) + (@clog-canvas section) (@clog-body section) (@clog-window section) (@clog-document section) @@ -371,6 +372,14 @@ application." (rows generic-function) (disable-resize generic-function)) +(defsection @clog-canvas (:title "CLOG Canvas Objects") + "CLOG-Canvas - Class for CLOG canvas objects" + (clog-canvas class) + (create-canvas generic-function) + + (clog-context2d class) + (create-context2d generic-function)) + (defsection @clog-body (:title "CLOG Body Objects") "CLOG-Body - CLOG Body Objects" (clog-body class) diff --git a/tutorial/10-tutorial.lisp b/tutorial/10-tutorial.lisp new file mode 100644 index 0000000..2f174b6 --- /dev/null +++ b/tutorial/10-tutorial.lisp @@ -0,0 +1,18 @@ +(defpackage #:clog-user + (:use #:cl #:clog) + (:export start-tutorial)) + +(in-package :clog-user) + +(defun on-new-window (body) + (let* ((canvas (create-canvas body)) + (cx (create-context2d canvas))) + ) + + (run body)) + +(defun start-tutorial () + "Start turtorial." + + (initialize #'on-new-window) + (open-browser))