on-release works without on-key; Closes PR12291 please propagate

This commit is contained in:
Matthias Felleisen 2011-10-16 16:31:50 -04:00
parent 08b2d7b595
commit 2a43c68dd7
4 changed files with 32 additions and 6 deletions

View File

@ -52,8 +52,8 @@
(class* object% (start-stop<%>) (class* object% (start-stop<%>)
(inspect #f) (inspect #f)
(init-field world0) (init-field world0)
(init-field name state register check-with on-key on-mouse record?) (init-field name state register check-with on-key on-release on-mouse record?)
(init on-release on-receive on-draw stop-when) (init on-receive on-draw stop-when)
;; ----------------------------------------------------------------------- ;; -----------------------------------------------------------------------
(field (field
@ -152,7 +152,8 @@
(show fst-scene))) (show fst-scene)))
(define/public (deal-with-key %) (define/public (deal-with-key %)
(if (not on-key) % (if (and (not on-key) (not on-release))
%
(class % (class %
(super-new) (super-new)
(define/override (on-char e) (define/override (on-char e)
@ -235,8 +236,8 @@
;; ---------------------------------------------------------------------- ;; ----------------------------------------------------------------------
;; callbacks ;; callbacks
(field (field
(key on-key) (key (if on-key on-key (lambda (w ke) w)))
(release on-release) (release (if on-release on-release (lambda (w ke) w)))
(mouse on-mouse) (mouse on-mouse)
(rec on-receive)) (rec on-receive))

View File

@ -0,0 +1,24 @@
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-advanced-reader.ss" "lang")((modname on-release-no-key) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ())))
;; Any key inflates the balloon
(require 2htdp/image)
(require 2htdp/universe)
(define large 50)
(define (balloon b)
(if (<= b 10)
(text "press any key now" 22 'red)
(circle b "solid" "red")))
(define (blow-up b k) large)
(define (deflate b) (max (- b 1) 1))
(big-bang 20
(on-release blow-up)
(on-tick deflate)
(to-draw balloon 200 200)
(stop-when (lambda (w) (>= w large))))

View File

@ -93,7 +93,7 @@
[on-key DEFAULT #f (function-with-arity 2)] [on-key DEFAULT #f (function-with-arity 2)]
;; World KeyEvent -> World ;; World KeyEvent -> World
;; on-release must specify a release event handler ;; on-release must specify a release event handler
[on-release DEFAULT #'K (function-with-arity 2)] [on-release DEFAULT #f (function-with-arity 2)]
;; (U #f (World S-expression -> World)) ;; (U #f (World S-expression -> World))
;; -- on-receive must specify a receive handler ;; -- on-receive must specify a receive handler
[on-receive DEFAULT #'#f (function-with-arity 2)] [on-receive DEFAULT #'#f (function-with-arity 2)]

View File

@ -35,4 +35,5 @@ run record-stop-when.rkt
run stop-when-crash.rkt run stop-when-crash.rkt
run on-tick-universe-with-limit.rkt run on-tick-universe-with-limit.rkt
run on-tick-with-limit.rkt run on-tick-with-limit.rkt
run on-release-no-key.rkt