Start of clog-canvas

This commit is contained in:
David Botton 2021-01-14 15:44:04 -05:00
parent 31054ad9d2
commit e75def587d
4 changed files with 92 additions and 0 deletions

64
clog-canvas.lisp Normal file
View file

@ -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 "<canvas/>"
: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)))

View file

@ -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")

View file

@ -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)

18
tutorial/10-tutorial.lisp Normal file
View file

@ -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))