Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add universe-inset parameter #237

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions htdp-lib/2htdp/private/check-aux.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

(provide (all-defined-out))

(define INSET 5) ;; the space around the image in the canvas
(define universe-inset ;; the space around the image in the canvas
(make-parameter
5
(λ (v)
(unless (and (integer? v)
(<= 0 v 1000))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1000 really? Did you try to run a big-bang program with such an inset?

(Very minor: this is a world-inset not a universe-insert.)

(raise-argument-error 'universe-inset "an integer between 0 and 1000 (inclusive)" v))
v)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever you really choose for an inset (1) name the max constant and (2) use the name instead of the constant.

(define RATE 1/30) ;; the clock tick rate
(define TRIES 3) ;; how many times should register try to connect to the server
(define PAUSE 1/2) ;; # secs to wait between attempts to connect to server
Expand Down Expand Up @@ -53,8 +60,8 @@
;; MouseEvent% -> [List Nat Nat MouseEventType]
;; turn a mouse event into its pieces
(define (mouse-event->parts e)
(define x (- (send e get-x) INSET))
(define y (- (send e get-y) INSET))
(define x (- (send e get-x) (universe-inset)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use (define INSET (universe-inset)) and then leave these lines alone. (It's not like INSET will change during the course of the big-bang program. (Yes this is a "contract" that we don't enforce right now.))

(define y (- (send e get-y) (universe-inset)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INSET

(values x y
(cond [(send e button-down?) "button-down"]
[(send e button-up?) "button-up"]
Expand Down
9 changes: 5 additions & 4 deletions htdp-lib/2htdp/private/world.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
(define/pubment (create-frame/universe)
(define play-back:cust (make-custodian))

(define inset (universe-inset))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INSET

(define frame-x 2)
(define frame-y 2)

Expand Down Expand Up @@ -256,10 +257,10 @@
(stretchable-width #f)
(stretchable-height #f)
(style '(no-hscroll no-vscroll))
(horizontal-inset INSET)
(vertical-inset INSET)))
(send editor-canvas min-client-width (sub1 (+ width INSET INSET)))
(send editor-canvas min-client-height (sub1 (+ height INSET INSET)))
(horizontal-inset inset)
(vertical-inset inset)))
(send editor-canvas min-client-width (sub1 (+ width inset inset)))
(send editor-canvas min-client-height (sub1 (+ height inset inset)))
(set!-values (enable-images-button disable-images-button)
(inner (values void void) create-frame/universe frame play-back:cust))
(send editor-canvas focus)
Expand Down
5 changes: 3 additions & 2 deletions htdp-lib/2htdp/universe.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
;;
(only-in "private/launch-many-worlds.rkt" launch-many-worlds launch-many-worlds/proc)
(only-in "private/stop.rkt" make-stop-the-world)
(only-in "private/check-aux.rkt" sexp? SQPORT)
(only-in "private/check-aux.rkt" sexp? SQPORT universe-inset)
(only-in "private/pad.rkt" pad-event? pad=?)
htdp/error
(rename-in lang/prim (first-order->higher-order f2h)))
Expand Down Expand Up @@ -178,7 +178,8 @@

(provide
big-bang ;; <syntax> : see below
pad-handler ;; <syntax> : see below
pad-handler ;; <syntax> : see below
universe-inset
)

(provide-primitives
Expand Down