fixed bug and specs of draw/idraw Canvases in htdch

svn: r3865
This commit is contained in:
Matthias Felleisen 2006-07-28 14:43:22 +00:00
parent 61079f028b
commit 04e4477b20
6 changed files with 73 additions and 24 deletions

View File

@ -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

View File

@ -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);

View File

@ -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])))

View File

@ -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);

View File

@ -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*)]

View File

@ -40,18 +40,27 @@ this canvas, and finally starts the clock at a rate of one tick per
<code>speed</code> seconds. If it succeeds with all of its actions, the method
produces <code>true</code>.
<p>A <code>World</code> is associated with one default <code>Canvas</code>,
called <code>theCanvas</code>. If a <code>World</code> needs additional
canvases for its graphical presentation, its concrete subclasses must add
those.</p>
<p><strong>Note:</strong> <code>width</code> and <code>height</code> must be
positive <code>int</code>s, <code>speed</code> must be a positive
<code>double</code>.
</p>
<p>The canvas in <code>World</code> is called
<code>theCanvas</code>. References to a "canvas" in conjunction with the
<code>World</code> class denote this default canvas.
</p>
</li>
<li><code>endOfTime</code>, stops the clock and, if it succeeds, produces
<code>true</code>.
<code>true</code>. After the end of time, events no longer trigger calls
to <code>onTick</code> or <code>onKeyEvent</code> (see below). The canvas
remains visible.
</li>
<li><code>endOfWorld</code>, stops the clock and, if it succeeds, produces the
last <code>World</code>.
last <code>World</code>. After the end of the world, events no longer trigger calls
to <code>onTick</code> or <code>onKeyEvent</code> (see below). The canvas
remains visible.
</li>
</ul>
The methods may fail due to the unavailability of the physical devices,
@ -65,11 +74,11 @@ purpose is to create a <code>World</code> whose differences with
the clock to tick.
</li>
<li><code>onKeyEvent(key)</code>, which is invoked for every keyboard event. Its
purposes is to create a <code>World</code> whose differences with
<code>this</code> one represent what happens due to the user's use of the
keyboard. The latter is represented with the string-valued argument
<code>key</code>.
<li><code>onKeyEvent(key)</code>, which is invoked for every keyboard event
associated with the canvas. Its purposes is to create a
<code>World</code> whose differences with <code>this</code> one represent
what happens due to the user's use of the keyboard. The latter is
represented with the string-valued argument <code>key</code>.
</li>
<li><code>draw()</code>, which is invoked <em>after</em> one of the two event
@ -80,6 +89,8 @@ graphically on its canvas. If it succeeds, its result is <code>true.</code>
<li><code>erase()</code>, which is invoked <em>after</em> one of the two event
handlers has been called. Its purpose is to erase <code>this World</code>'s
canvas, as much as needed. If it succeeds, its result is <code>true.</code>
Simple erase methods just draw a white rectangle of appropriate width and
height located at the origin.
</li>
</ul>
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
<code>Canvas:</code>
<ul>
<li><code>show()</code>, which displays the canvas.
If it succeeds, it produces <code>true</code>.</li>
If it succeeds, it produces <code>true</code>. Invoking the method a second
time without calling <code>close</code> before has no effect.
</li>
<li><code>close()</code>, which destroys the canvas.
If it succeeds, it produces <code>true</code>.</li>
If it succeeds, it produces <code>true</code>. Invoking <code>show</code>
again, displays an empty canvas of the same size.
</li>
<li><code>drawCircle(p,r,c)</code>, which draws a circle on <code>this
Canvas</code> at <code>p</code> with radius <code>r</code> and color