diff --git a/collects/graphics/graphics-posn-less-unit.ss b/collects/graphics/graphics-posn-less-unit.ss index 2637703f3a..b06020d796 100644 --- a/collects/graphics/graphics-posn-less-unit.ss +++ b/collects/graphics/graphics-posn-less-unit.ss @@ -251,6 +251,7 @@ [stop-tick (lambda () (send the-time stop) + (set! on-char-proc #f) the-world)] [init-world (lambda (w) (set! the-world w))]) ;; --- end timing stuff diff --git a/collects/htdch/draw/Canvas.java b/collects/htdch/draw/Canvas.java index 35bfefeed6..d35fdbf7e4 100644 --- a/collects/htdch/draw/Canvas.java +++ b/collects/htdch/draw/Canvas.java @@ -18,8 +18,22 @@ public class Canvas { // I need to figure out how to accomplish these two things, especially stop, // directly at the Scheme level w/o going thru the Java layer. - public native boolean show(); - public native boolean close(); + private boolean showing = false; + public boolean show() { + if (!showing) { + xshow(); + showing = true; + } + return true; + } + public boolean close() { + xclose(); + showing = false; + return true; + } + + public native boolean xshow(); + public native boolean xclose(); public native boolean drawCircle(Posn p, int r, Color c); public native boolean drawDisk(Posn p, int r, Color c); public native boolean drawRect(Posn p, int width, int height, Color c); diff --git a/collects/htdch/draw/support.scm b/collects/htdch/draw/support.scm index 59d0cc8121..cd73d8af41 100644 --- a/collects/htdch/draw/support.scm +++ b/collects/htdch/draw/support.scm @@ -16,8 +16,8 @@ bigBangO-double-native)) (define-signature canvas-native^ - (show-native - close-native + (xshow-native + xclose-native stop-native copy-native drawCircle-geometry.Posn-int-colors.Color-native @@ -88,7 +88,7 @@ (lower (cdr s)))))))) (list->string (lower (string->list s))))) - (define (show-native this accs gets privates) + (define (xshow-native this accs gets privates) ;; Kathy: it looks like I am working around a bug here. ;; I really wanted to write ([hash-table-get privates 'width] this) ;; but that didn't work at all. 'width is not a key for privates, @@ -100,8 +100,9 @@ (start-and-export x y privates) void-or-true) - (define (close-native this accs gets privates) - (wrap-start-check ([hash-table-get privates '%stop]))) + (define (xclose-native this accs gets privates) + (wrap-start-check ([hash-table-get privates '%stop])) + void-or-true) (define (stop-native this accs gets privates) (wrap-start-check ([hash-table-get privates '%end-of-time]))) diff --git a/collects/htdch/idraw/Canvas.java b/collects/htdch/idraw/Canvas.java index 62763b389b..db23189c90 100644 --- a/collects/htdch/idraw/Canvas.java +++ b/collects/htdch/idraw/Canvas.java @@ -18,8 +18,23 @@ public class Canvas { // MF: I need to figure out how to accomplish these two things, especially // stop, directly at the Scheme level w/o going thru the Java layer. - public native void show(); - public native void close(); + + private boolean showing = false; + public void show() { + if (!showing) { + xshow(); + showing = true; + } + return ; + } + public void close() { + xclose(); + showing = false; + return ; + } + + public native void xshow(); + public native void xclose(); public native void drawCircle(Posn p, int r, Color c); public native void drawDisk(Posn p, int r, Color c); public native void drawRect(Posn p, int width, int height, Color c); diff --git a/collects/htdp/big-draw.ss b/collects/htdp/big-draw.ss index 32d6e2703a..a6263390c0 100644 --- a/collects/htdp/big-draw.ss +++ b/collects/htdp/big-draw.ss @@ -209,14 +209,17 @@ (setter vp* pm* %clear-string (make-%string 'clear-string (clear-string vp*))) ;; --- (set! %end-of-time + (let () #;([vp* vp*][pm* pm*]) (lambda () [(stop-tick vp*)] [(stop-tick pm*)] - #t)) + #t))) (hash-table-put! h '%end-of-time %end-of-time) ;; --- (set! %stop - (let ([a (lambda () (close-viewport @vp) (close-viewport @pm))]) + (let* ([vp* vp*] + [pm* pm*] + [a (lambda () (close-viewport vp*) (close-viewport pm*))]) (lambda () [(stop-tick vp*)] [(stop-tick pm*)] diff --git a/collects/teachpack/htdc/Docs/draw.thtml b/collects/teachpack/htdc/Docs/draw.thtml index f265df733b..4879c75af0 100644 --- a/collects/teachpack/htdc/Docs/draw.thtml +++ b/collects/teachpack/htdc/Docs/draw.thtml @@ -40,18 +40,27 @@ this canvas, and finally starts the clock at a rate of one tick per speed seconds. If it succeeds with all of its actions, the method produces true. -

A World is associated with one default Canvas, -called theCanvas. If a World needs additional -canvases for its graphical presentation, its concrete subclasses must add -those.

+

Note: width and height must be + positive ints, speed must be a positive + double. +

+ +

The canvas in World is called + theCanvas. References to a "canvas" in conjunction with the + World class denote this default canvas. +

  • endOfTime, stops the clock and, if it succeeds, produces -true. + true. After the end of time, events no longer trigger calls + to onTick or onKeyEvent (see below). The canvas + remains visible.
  • endOfWorld, stops the clock and, if it succeeds, produces the -last World. + last World. After the end of the world, events no longer trigger calls + to onTick or onKeyEvent (see below). The canvas + remains visible.
  • The methods may fail due to the unavailability of the physical devices, @@ -65,11 +74,11 @@ purpose is to create a World whose differences with the clock to tick. -
  • onKeyEvent(key), which is invoked for every keyboard event. Its -purposes is to create a World whose differences with -this one represent what happens due to the user's use of the -keyboard. The latter is represented with the string-valued argument -key. +
  • onKeyEvent(key), which is invoked for every keyboard event + associated with the canvas. Its purposes is to create a + World whose differences with this one represent + what happens due to the user's use of the keyboard. The latter is + represented with the string-valued argument key.
  • draw(), which is invoked after one of the two event @@ -80,6 +89,8 @@ graphically on its canvas. If it succeeds, its result is true.
  • erase(), which is invoked after one of the two event handlers has been called. Its purpose is to erase this World's canvas, as much as needed. If it succeeds, its result is true. + Simple erase methods just draw a white rectangle of appropriate width and + height located at the origin.
  • A program may, in principle, start several instances of (subclasses of) @@ -94,10 +105,14 @@ screen's borders. A program can use the following methods on instances of Canvas: