1- package introprog
1+ package introprog . fx
22
3- /** A module ready to use in the Scala REPL or in a main Scala program */
3+ /** A window for pixel-based drawing in an underlying javafx window. */
44object FxPixelWindow {
55 def exit (): Unit = System .exit(0 )
66
@@ -103,8 +103,9 @@ class FxPixelWindow(
103103 /** Draw a line from (`x1`, `y1`) to (`x2`, `y2`) using `color` and `lineWidth`. */
104104 def line (x1 : Int , y1 : Int , x2 : Int , y2 : Int , color : java.awt.Color = foreground, lineWidth : Int = 1 ): Unit = withGC { gc =>
105105 gc.setStroke(Fx .toFxColor(color))
106- gc.setLineWidth(lineWidth)
107- gc.strokeLine(x1,y1,x2,y2)
106+ gc.setLineWidth(lineWidth.toDouble)
107+ gc.strokeLine(x1.toDouble,y1.toDouble,x2.toDouble,y2.toDouble)
108+ gc.strokeLine(x1.toDouble,y1.toDouble,x2.toDouble,y2.toDouble)
108109 }
109110
110111 // def setLineWidth(width: Double): Unit = withGC(_.setLineWidth(width))
@@ -118,7 +119,7 @@ class FxPixelWindow(
118119 def fill (x : Int , y : Int , width : Int , height : Int , color : java.awt.Color = foreground): Unit = withGC { gc =>
119120 // gc.setStroke(Fx.toFxColor(color))
120121 gc.setFill(Fx .toFxColor(color))
121- gc.fillRect(x,y ,width,height)
122+ gc.fillRect(x.toDouble,y.toDouble ,width.toDouble ,height.toDouble )
122123 }
123124
124125 def setPixel (x : Int , y : Int , color : java.awt.Color = foreground): Unit =
@@ -144,9 +145,9 @@ class FxPixelWindow(
144145 fontName : String = " Monospaced Bold"
145146 ) = withGC { gc =>
146147 gc.setFill(Fx .toFxColor(color))
147- gc.setFont(new javafx.scene.text.Font (fontName, size))
148+ gc.setFont(new javafx.scene.text.Font (fontName, size.toDouble ))
148149 gc.setFontSmoothingType(javafx.scene.text.FontSmoothingType .LCD )
149- gc.fillText(text, x, y + size)
150+ gc.fillText(text, x.toDouble , y.toDouble + size.toDouble )
150151 }
151152
152153
@@ -169,12 +170,12 @@ class FxPixelWindow(
169170 s.setTitle(title)
170171 root.setBackground(javafx.scene.layout.Background .EMPTY )
171172 canvas.getGraphicsContext2D.setFill(Fx .toFxColor(background))
172- canvas.getGraphicsContext2D.fillRect(0 , 0 ,width,height)
173+ canvas.getGraphicsContext2D.fillRect(0.0 , 0.0 ,width.toDouble ,height.toDouble )
173174 canvas.getGraphicsContext2D.setStroke(Fx .toFxColor(foreground))
174175 s.setScene(scene)
175176 root.setCenter(canvas)
176- s.setMinWidth(width)
177- s.setMinHeight(height)
177+ s.setMinWidth(width.toDouble )
178+ s.setMinHeight(height.toDouble )
178179 s.show
179180
180181 // if (initBasicMenu) root.getChildren.add(0, basicMenuBar)
0 commit comments