I forgot to mention that I had put together a sort of manifest for the changes I've made, to make it easier to find what's where.
In the file ScalaCodeRunner.scala, I've added the Staging namespace to the interpreter
+ interp.interpret("val Staging = predef.StagingAPI")
and, of course, the StagingAPI object
+ object StagingAPI {
---etc etc---
In the file figure/Figure.scala, I added a method to let my testing code look at shapes added to the canvas:
+ def dumpChild(n: Int): PNode = {
+ try {
+ currLayer.getChild(n)
+ }
+ catch { case e => throw e }
+ }
and declaractions for shape classes I added:
+ type FRRectangle = FigRoundRectangle
+ type FPath = FigPath
and corresponding drawing methods:
+ def roundRectangle(p1: Point, p2: Point, rx: Double, ry: Double) = {
+ val rrect = new FigRoundRectangle(canvas, p1, p2, rx, ry)
+ Utils.runInSwingThread {
+ rrect.pRect.setStroke(lineStroke)
+ rrect.pRect.setStrokePaint(lineColor)
+ rrect.pRect.setPaint(fillColor)
+ currLayer.addChild(rrect.pRect)
+ currLayer.repaint()
+ }
+ rrect
+ }
+ def polyLine(path: kgeom.PolyLine): kgeom.PolyLine = {
+ Utils.runInSwingThread {
+ path.setStroke(lineStroke)
+ path.setStrokePaint(lineColor)
+ path.setPaint(fillColor)
+ currLayer.addChild(path)
+ currLayer.repaint()
+ }
+ path
+ }
+ def path(descriptor: String): FigPath = {
+ val path = new FigPath(canvas, descriptor)
+ Utils.runInSwingThread {
+ path.pPath.setStroke(lineStroke)
+ path.pPath.setStrokePaint(lineColor)
+ path.pPath.setPaint(fillColor)
+ currLayer.addChild(path.pPath)
+ currLayer.repaint
+ }
+ path
+ }
I added a few files:
figure/FigRoundRectangle.scala
figure/FigPath.scala
test/. . ./Staging/ScreenMethodsTest.scala
test/. . ./Staging/ShapesTest.scala
test/. . ./Staging/Shapes2Test.scala
In the file core/Figure.scala, I added declarations for the shape types and methods:
+ type FRRectangle <: RoundRectangle with VisualElement
+ type FPath <: Path with VisualElement
+ def roundRectangle(p1: Point, p2: Point, rx: Double, ry: Double): FRRectangle
+ def polyLine(path: net.kogics.kojo.kgeom.PolyLine): net.kogics.kojo.kgeom.PolyLine
+ def path(descr: String): FPath
In the file core/shapes.scala, I added some methods for Point:
class Point(val x: Double, val y: Double) {
+ def +(that: Point) = new Point(this.x + that.x, this.y + that.y)
+ def -(that: Point) = new Point(this.x - that.x, this.y - that.y)
+ def unary_- = new Point(-x, -y)
override def toString = "Point(%.2f, %.2f)" format(x, y)
}
In the file core/shapes.scala, I added some methods for Point:
+class RoundRectangle(
+ override val bLeft: Point,
+ override val tRight: Point,
+ rx: Double, ry: Double
+) extends Rectangle(bLeft, tRight)
and the class Path:
+class Path(val descriptor: String)
That should be it.