Skip to content

Commit

Permalink
70 percent
Browse files Browse the repository at this point in the history
  • Loading branch information
David O'Toole committed Mar 8, 2012
1 parent 9c5e190 commit 733b34c
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 81 deletions.
2 changes: 1 addition & 1 deletion blocks.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ either a symbol naming the field, or a list of the form (SYMBOL
(setf name0 name)
(when super (setf super0 super)))))
`(define-prototype ,name0 (:super ,(make-prototype-id super0))
; (wiki-name :initform ,(verbose-symbol-name name0))
(wiki-name :initform ,(verbose-symbol-name name0))
,@(if (keywordp (first args))
(plist-to-descriptors args)
args))))
Expand Down
2 changes: 1 addition & 1 deletion blocky.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ holding-control *scale-output-to-window* keyboard-released-p *edit*
with-font *font* find-heading keyboard-time-in-current-state
pretty-string ugly-symbol *pointer-x* *pointer-y* is-joystick-event
*self* is-raw-joystick-event keyboard-time-in-previous-state *updates*
keyboard-down-p keyboard-keys-down keyboard-modifier-down-p
keyboard-down-p keyboard-keys-down keyboard-modifier-down-p *socket-size*
keyboard-modifiers draw-filled-circle draw-aa-circle get-keys
*project-package-name* project-package-name make-block add-block
remove-block with-quadtree *initialization-hook* hit-blocks
Expand Down
13 changes: 13 additions & 0 deletions listener.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

(defparameter *logo-height* 26)

(defparameter *socket-size* 16)
(defparameter *active-prompt-color* "red")
(defparameter *inactive-prompt-color* "gray10")
(defparameter *prompt-cursor-inactive-color* "gray50")
Expand Down Expand Up @@ -519,6 +520,18 @@
;; update the entry value if the user mouses away
(enter self))

;;; Dropping expressions onto argument inputs

(define-method accept entry (thing)
(with-fields (parent) self
(when (is-a 'arguments parent)
(prog1 t
(let ((index (position-within-parent self)))
(send :replace-widget parent index
(send :schema-widget parent
(nth index (%schema parent))
:force-socket t)))))))

;;; Allow dragging the parent block more easily

(define-method hit entry (x y)
Expand Down
7 changes: 5 additions & 2 deletions prototypes.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ extended argument list ARGLIST."

(defun method-schema (prototype method)
(assert (hash-table-p *methods*))
(let ((id (find-method-id (object-name (find-prototype prototype)) method)))
(let ((id (find-method-id (object-name (find-prototype prototype))
(make-keyword method))))
(assert (stringp id))
(let ((result (gethash id *methods*)))
(when result
Expand Down Expand Up @@ -710,6 +711,8 @@ upon binding."
(defmacro with-forward-message-handler (form &body body)
`(let ((*forward-message-handler* ,form)) ,@body))

(defvar *self* nil)

(defun send (method thing &rest args)
"Invoke the method identified by the keyword METHOD on the OBJECT with ARGS.
If the method is not found, attempt to forward the message."
Expand Down Expand Up @@ -1166,7 +1169,7 @@ slot value is inherited."
(defun ,accessor-name (thing)
(field-value ,field-name thing))
(defun (setf ,accessor-name) (thing value)
(set-field-value ,field-name thing value))
(set-field-value thing ,field-name value))
(export ',accessor-name)))))

(defun proto-intern (name)
Expand Down
37 changes: 20 additions & 17 deletions rgb.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@

;; Copyright (C) 1994 X Consortium

;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to
;; deal in the Software without restriction, including without limitation the
;; rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
;; sell copies of the Software, and to permit persons to whom the Software is
;; Permission is hereby granted, free of charge, to any person
;; obtaining a copy of this software and associated documentation
;; files (the "Software"), to deal in the Software without
;; restriction, including without limitation the rights to use, copy,
;; modify, merge, publish, distribute, sublicense, and/or sell copies
;; of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:

;; The above copyright notice and this permission notice shall be included in
;; all copies or substantial portions of the Software.
;; The above copyright notice and this permission notice shall be
;; included in all copies or substantial portions of the Software.

;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
;; AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
;; TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;; NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR
;; ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
;; TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.

;; Except as contained in this notice, the name of the X Consortium shall not
;; be used in advertising or otherwise to promote the sale, use or other deal-
;; ings in this Software without prior written authorization from the X Consor-
;; tium.
;; Except as contained in this notice, the name of the X Consortium
;; shall not be used in advertising or otherwise to promote the sale,
;; use or other dealings in this Software without prior written
;; authorization from the X Consortium.

;; X Window System is a trademark of X Consortium, Inc.

Expand Down
106 changes: 56 additions & 50 deletions syntax.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,28 @@

(deflist socket)

(define-method hit socket (x y)
(if %inputs
(hit%super self x y)
(when (touching-point self x y)
self)))
(define-method initialize socket (&optional target label)
(setf %label label)
(when target (setf %inputs (list target))))

(define-method accept socket (other-block)
"Replace the child object with OTHER-BLOCK."
(when other-block
(prog1 t
(setf %inputs (list other-block))
(set-parent other-block self))))

(define-method evaluate socket ()
(when %inputs (first %inputs)))

(defparameter *socket-size* 16)
(define-method can-pick socket () t)

(define-method pick socket ()
;; allow dragging of parent via empty socket
(if (null %inputs)
%parent
;; otherwise, pick object
(first %inputs)))

(define-method layout socket ()
(with-fields (label inputs height width) self
Expand Down Expand Up @@ -77,32 +92,16 @@
(draw (first inputs))
(draw-image "socket" x y)))))

(define-method hit socket (x y)
(if %inputs
(hit%super self x y)
(when (touching-point self x y)
self)))

(define-method draw-hover socket ()
(with-fields (x y width height) self
(draw-box x y width height :color *hover-color* :alpha *hover-alpha*)))

(define-method accept socket (other-block)
"Replace the child object with OTHER-BLOCK."
(when other-block
(prog1 t
(setf %inputs (list other-block))
(set-parent other-block self))))

(define-method evaluate socket ()
(when %inputs (first %inputs)))

(define-method can-pick socket () t)

(define-method pick socket ()
;; allow dragging of parent via empty socket
(if (null %inputs)
%parent
;; otherwise, pick object
(first %inputs)))

(define-method initialize socket (&optional input label)
(setf %input input %label label))

;;; Variables whose values are blocks

(defvar *parameters* nil)
Expand Down Expand Up @@ -140,8 +139,6 @@

;;; Self reference

(defvar *self* nil)

(define-block-macro self
(:super :list
:fields
Expand Down Expand Up @@ -197,6 +194,7 @@
;;; Closure for parameterizing a tree



;;; Inactive placeholder

(deflist blank)
Expand Down Expand Up @@ -232,24 +230,34 @@
(assert (blockyp block))
nil)

(define-method schema-widget arguments (entry &key force-socket no-label)
(if (or force-socket
(eq 'block (schema-type entry)))
(new 'socket :label (unless no-label
(pretty-string (schema-name entry))))
(clone (if (eq 'string (schema-type entry))
"BLOCKY:STRING"
"BLOCKY:ENTRY")
:value (schema-option entry :default)
:parent (find-uuid self)
:type-specifier (schema-type entry)
:options (schema-options entry)
:label (pretty-string (schema-name entry)))))

(define-method replace-widget arguments (index widget)
(with-fields (inputs) self
(assert inputs)
(assert (< index (length inputs)))
(setf (nth index inputs) widget)))

(define-method initialize arguments (&key method label target)
(let ((schema (find-schema method target))
(inputs nil))
(initialize%super self)
(setf %no-background t)
;; create appropriate controls for the arguments in the schema
(dolist (entry schema)
(let ((thing
(if (eq 'block (schema-type entry))
(new 'socket :label (pretty-string (schema-name entry)))
(clone (if (eq 'string (schema-type entry))
"BLOCKY:STRING" "BLOCKY:ENTRY")
:value (schema-option entry :default)
:parent (find-uuid self)
:type-specifier (schema-type entry)
:options (schema-options entry)
:label (pretty-string (schema-name entry))))))
(push thing inputs)))
(push (schema-widget self entry) inputs))
(when inputs
(setf %inputs (nreverse inputs)))
(setf %schema schema
Expand All @@ -258,9 +266,6 @@

(define-method draw arguments ()
(with-fields (x y width height label inputs) self
;; (when %button-p
;; (with-style :flat
;; (draw-patch self x y (+ x width) (+ y height))))
(let ((*text-baseline* (+ y (dash 1))))
(when label (draw-label-string self label "white"))
(dolist (each inputs)
Expand Down Expand Up @@ -330,17 +335,18 @@
(let ((method-key (make-keyword (ugly-symbol method)))
(target (or (get-target self) (find-object "BLOCKY:BLOCK"))))
(when (not (eq method-key %method))
;; time to change args
;; remember to change args at next update.
(setf %method method-key)
(setf (second %inputs)
(new 'arguments :method method-key
:target target))
(setf %updated t))))))

(define-method update message ()
(when %updated
(grab-focus (first %inputs))
(setf %updated nil)))
(with-input-values (method) self
(grab-focus (first %inputs))
(setf (second %inputs)
(new 'arguments :method method
:target (get-target self)))
(setf %updated nil))))

(define-method set-method message (method)
(set-value %%method (pretty-string method))
Expand Down
13 changes: 7 additions & 6 deletions tasks.org
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
** TODO [#C] allow replacing field as computed method using (defstruct computed-field
** TODO [#A] being able to replace/augment any arguments entry with a labeled socket
*** TODO refactor initialize arguments to allow individual updating
** TODO [#A] local variable palettes with add-variable etc
** TODO Navigate to a prototype's page to make a method or derived block
** TODO better listener menu
** TODO local variables in ROOK defworld are the fields of ROOK and body is initializer?
**** TODO locked to 0,0 position
** TODO demo and test defining a new method before demoing defining a new object
** TODO [#A] (browse-method ... some command from listener
** TODO [#A] intelligent rejection of listener eof
** TODO [#A] Navigate to a prototype's page to make a method or derived block
** TODO [#A] local variables in ROOK defworld are the fields of ROOK and body is initializer?
**** TODO locked to 0,0 position
** TODO [#A] better listener menu
** TODO [#A] graceful rejection of listener eof
** TODO [#A] Generic + handle to add message
**** TODO Keybinding for add-foo in current list SHIFT-F1 etc
** TODO Possibly F1 system/help, F2 browser, F3 browser, F4 browser
Expand Down
8 changes: 4 additions & 4 deletions worlds.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
((:m :alt) :add-message)
((:s :alt) :add-statement)
((:v :alt) :add-variable)
((:l :alt) :add-self)
((:f :alt) :add-field)
((:e :alt) :add-expression)
))
Expand Down Expand Up @@ -232,10 +233,6 @@
(define-method drop-at-pointer world (object)
(add-block self object *pointer-x* *pointer-y* :prepend))

;; (define-method drop-dwim world (object)
;; (if %focused-block
;; (accept

(define-method add-message world ()
(drop-at-pointer self (new 'message)))

Expand All @@ -251,6 +248,9 @@
(define-method add-field world ()
(drop-at-pointer self (new 'field)))

(define-method add-self world ()
(drop-at-pointer self (new 'self)))

(define-method contains-object world (object)
(gethash (find-uuid object)
%objects))
Expand Down

0 comments on commit 733b34c

Please sign in to comment.