new docs for htdch
svn: r2760
This commit is contained in:
parent
770e6aa288
commit
d7d55e05b4
|
@ -1,7 +1,7 @@
|
|||
{ (define LIBNAME "A Functional Drawing Library (HtDC)")
|
||||
(include "head.tinc") }
|
||||
|
||||
This `draw' package provides classes and methods for a visual
|
||||
This <code>draw</code> package provides classes and methods for a visual
|
||||
world. Here is its class diagram of public fields and methods:
|
||||
<pre>
|
||||
<code>
|
||||
|
@ -11,9 +11,9 @@ world. Here is its class diagram of public fields and methods:
|
|||
| Canvas theCanvas |------>| Canvas |
|
||||
+-----------------------------------+ +---------------------------------------+
|
||||
| boolean bigBang(int,int,double) | +---------------------------------------+
|
||||
| boolean endOfTime() | | boolean start(int,int) |
|
||||
| boolean endOfWorld() | | boolean stop() |
|
||||
| World lastWorld() | | boolean drawCircle(Posn,int,Color) |
|
||||
| boolean endOfTime() | | boolean show() |
|
||||
| World endOfWorld() | | boolean close() |
|
||||
| | | boolean drawCircle(Posn,int,Color) |
|
||||
| | | boolean drawDisk(Posn,int,Color) |
|
||||
| abstract World onTick() | | boolean drawRect(Posn,int,int,Color) |
|
||||
| abstract World onKeyEvent(String) | | boolean drawLine(Posn,Posn,Color) |
|
||||
|
@ -46,4 +46,125 @@ world. Here is its class diagram of public fields and methods:
|
|||
</code>
|
||||
</pre>
|
||||
|
||||
<a name="world" />
|
||||
<p>The abstract <code>World</code> class exports the following methods:
|
||||
<ul>
|
||||
|
||||
<li><code>bigBang(width,height,speed)</code>, which initializes the world,
|
||||
associates it with a <code>width</code> x <code>height</code> <a
|
||||
href="#canvas"><code>Canvas</code></a>, displays
|
||||
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>
|
||||
</li>
|
||||
|
||||
<li><code>endOfTime</code>, stops the clock and, if it succeeds, produces
|
||||
<code>true</code>.
|
||||
</li>
|
||||
|
||||
<li><code>endOfWorld</code>, stops the clock and, if it succeeds, produces the
|
||||
last <code>World</code>.
|
||||
</li>
|
||||
</ul>
|
||||
The methods may fail due to the unavailability of the physical devices,
|
||||
inappropriate uses, etc. In those cases, they fail with an exception.</p>
|
||||
|
||||
<p>A derived concrete class must supply definitions for the following methods:
|
||||
<ul>
|
||||
<li><code>onTick()</code>, which is invoked for every tick of the clock. Its
|
||||
purpose is to create a <code>World</code> whose differences with
|
||||
<code>this</code> one represent what happened during the amount of time it takes
|
||||
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>
|
||||
|
||||
<li><code>draw()</code>, which is invoked <em>after</em> one of the two event
|
||||
handlers has been called. Its purpose is to present <code>this World </code>
|
||||
graphically on its canvas. If it succeeds, its result is <code>true.</code>
|
||||
</li>
|
||||
|
||||
<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>
|
||||
</li>
|
||||
</ul>
|
||||
A program may, in principle, start several instances of (subclasses of)
|
||||
<code>World</code>. If it does, the event handlers are called in a unpredictable
|
||||
order. </p>
|
||||
|
||||
<a name="canvas" />
|
||||
<p>To create an instance of the <code>Canvas</code> class, a program must supply
|
||||
two <code>int</code> values: one for the width of the canvas and one for its
|
||||
height. The canvas is a rectangle, whose borders are parallel to the computer
|
||||
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>
|
||||
|
||||
<li><code>close()</code>, which destroys the canvas.
|
||||
If it succeeds, it produces <code>true</code>.</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
|
||||
<code>c</code>. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>drawDisk(p,r,c)</code>, which draws a disk on
|
||||
<code>this Canvas</code> at <code>p</code> with radius <code>r</code> and color
|
||||
<code>c</code>. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>drawRect(p,w,h, c)</code>, which draws a solid rectangle on <code>this
|
||||
Canvas</code> at <code>p</code> with width <code>w</code>, height
|
||||
<code>h</code>, and color <code>c</code>. The rectangle's lines are parallel to
|
||||
the canvas's borders. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>drawLine(p0,p1,c)</code>, which draws a line on <code>this
|
||||
Canvas</code> from <code>p0</code> to <code>p1</code> using color
|
||||
<code>c</code>. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>drawString(p,s)</code>, which draws the string <code>s</code> at
|
||||
<code>p</code> on <code>this Canvas</code>. If it succeeds, it produces
|
||||
<code>true</code>.</li>
|
||||
|
||||
<li><code>clearCircle(p,r,c)</code>, which erases a circle from <code>this
|
||||
Canvas</code> at <code>p</code> with radius <code>r</code> and color
|
||||
<code>c</code>. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>clearDisk(p,r,c)</code>, which erases a disk from
|
||||
<code>this Canvas</code> at <code>p</code> with radius <code>r</code> and color
|
||||
<code>c</code>. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>clearRect(p,w,w,c)</code>, which draws a solid rectangle from <code>this
|
||||
Canvas</code> at <code>p</code> with width <code>w</code>, height
|
||||
<code>h</code>, and color <code>c</code>. The rectangle's lines are parallel to
|
||||
the canvas's borders. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
<li><code>clearLine(Posn p0, Posn p1, Color c)</code>, which erases a line from <code>this
|
||||
Canvas</code> from <code>p0</code> to <code>p1</code> using color
|
||||
<code>c</code>. If it succeeds, it produces <code>true</code>.</li>
|
||||
|
||||
</ul>
|
||||
The methods may fail due to the unavailability of the physical devices,
|
||||
inappropriate uses, etc. In those cases, they fail with an exception.</p>
|
||||
</p>
|
||||
|
||||
<p>To create an instance of the <code>Posn</code> class, a program must supply
|
||||
two <code>int</code> values: one for its x coordinate of the canvas and the
|
||||
second for its y coordinate. </p>
|
||||
|
||||
<p>The <code>Color</code> class is abstract. Its variants (subclasses) are
|
||||
created with no arguments.
|
||||
</p>
|
||||
|
||||
{(include "foot.tinc")}
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
(include "head.tinc") }
|
||||
|
||||
|
||||
This `idraw' package provides classes and imperative methods for
|
||||
a visual world. Here is its class diagram of public fields and methods:
|
||||
This <code>idraw</code> package provides stateful classes and imperative methods
|
||||
for a visual world. Here is its class diagram of public fields and methods:
|
||||
|
||||
<pre>
|
||||
<code>
|
||||
import draw.Color;
|
||||
import draw.Posn;
|
||||
|
||||
+---------------------------------+
|
||||
| abstract World |
|
||||
+---------------------------------+ +------------------------------------+
|
||||
|
@ -25,28 +28,18 @@ a visual world. Here is its class diagram of public fields and methods:
|
|||
| void clearRect(Posn,int,int,Color) |
|
||||
| void clearLine(Posn,Posn,Color) |
|
||||
+------------------------------------+
|
||||
|
||||
+----------+
|
||||
| Posn |
|
||||
+----------+
|
||||
| int x |
|
||||
| int y |
|
||||
+----------+
|
||||
|
||||
+-------+
|
||||
| Color |
|
||||
+-------+
|
||||
|
|
||||
/ \
|
||||
---
|
||||
|
|
||||
------------------------------------------
|
||||
| | | | |
|
||||
+-------+ +-------+ +-------+ +-------+ +-------+
|
||||
| Blue | | Green | | Red | | White | | Yellow|
|
||||
+-------+ +-------+ +-------+ +-------+ +-------+
|
||||
|
||||
</code>
|
||||
</pre>
|
||||
|
||||
<p>The abstract <code>World</code> class in <code>idraw</code> provides the same
|
||||
methods as the <code>World</code> class in <a href="./draw.html#world">the
|
||||
<code>draw</code> library</a>. Their return values are usually <code>void</code>,
|
||||
however, except for <code>endOfTime</code> and <code>endOfWorld</code>, which
|
||||
continue to return the last world.</p>
|
||||
|
||||
<p>In an analogous manner, the methods in the <code>Canvas</code> class export
|
||||
the same methods as the <code>Canvas</code> class in <a
|
||||
href="./draw.html#canvas">the <code>draw</code> package</a>. Their return values,
|
||||
however, are <code>void</code>. </p>
|
||||
|
||||
{(include "foot.tinc")}
|
||||
|
|
Loading…
Reference in New Issue
Block a user