on-release works without on-key; Closes PR12291 please propagate
This commit is contained in:
parent
08b2d7b595
commit
2a43c68dd7
|
@ -52,8 +52,8 @@
|
|||
(class* object% (start-stop<%>)
|
||||
(inspect #f)
|
||||
(init-field world0)
|
||||
(init-field name state register check-with on-key on-mouse record?)
|
||||
(init on-release on-receive on-draw stop-when)
|
||||
(init-field name state register check-with on-key on-release on-mouse record?)
|
||||
(init on-receive on-draw stop-when)
|
||||
|
||||
;; -----------------------------------------------------------------------
|
||||
(field
|
||||
|
@ -152,7 +152,8 @@
|
|||
(show fst-scene)))
|
||||
|
||||
(define/public (deal-with-key %)
|
||||
(if (not on-key) %
|
||||
(if (and (not on-key) (not on-release))
|
||||
%
|
||||
(class %
|
||||
(super-new)
|
||||
(define/override (on-char e)
|
||||
|
@ -235,8 +236,8 @@
|
|||
;; ----------------------------------------------------------------------
|
||||
;; callbacks
|
||||
(field
|
||||
(key on-key)
|
||||
(release on-release)
|
||||
(key (if on-key on-key (lambda (w ke) w)))
|
||||
(release (if on-release on-release (lambda (w ke) w)))
|
||||
(mouse on-mouse)
|
||||
(rec on-receive))
|
||||
|
||||
|
|
24
collects/2htdp/tests/on-release-no-key.rkt
Normal file
24
collects/2htdp/tests/on-release-no-key.rkt
Normal 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))))
|
|
@ -93,7 +93,7 @@
|
|||
[on-key DEFAULT #f (function-with-arity 2)]
|
||||
;; World KeyEvent -> World
|
||||
;; 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))
|
||||
;; -- on-receive must specify a receive handler
|
||||
[on-receive DEFAULT #'#f (function-with-arity 2)]
|
||||
|
|
|
@ -35,4 +35,5 @@ run record-stop-when.rkt
|
|||
run stop-when-crash.rkt
|
||||
run on-tick-universe-with-limit.rkt
|
||||
run on-tick-with-limit.rkt
|
||||
run on-release-no-key.rkt
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user