1
- package introprog
1
+ package introprog . fx
2
2
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. */
4
4
object FxPixelWindow {
5
5
def exit (): Unit = System .exit(0 )
6
6
@@ -103,8 +103,9 @@ class FxPixelWindow(
103
103
/** Draw a line from (`x1`, `y1`) to (`x2`, `y2`) using `color` and `lineWidth`. */
104
104
def line (x1 : Int , y1 : Int , x2 : Int , y2 : Int , color : java.awt.Color = foreground, lineWidth : Int = 1 ): Unit = withGC { gc =>
105
105
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)
108
109
}
109
110
110
111
// def setLineWidth(width: Double): Unit = withGC(_.setLineWidth(width))
@@ -118,7 +119,7 @@ class FxPixelWindow(
118
119
def fill (x : Int , y : Int , width : Int , height : Int , color : java.awt.Color = foreground): Unit = withGC { gc =>
119
120
// gc.setStroke(Fx.toFxColor(color))
120
121
gc.setFill(Fx .toFxColor(color))
121
- gc.fillRect(x,y ,width,height)
122
+ gc.fillRect(x.toDouble,y.toDouble ,width.toDouble ,height.toDouble )
122
123
}
123
124
124
125
def setPixel (x : Int , y : Int , color : java.awt.Color = foreground): Unit =
@@ -144,9 +145,9 @@ class FxPixelWindow(
144
145
fontName : String = " Monospaced Bold"
145
146
) = withGC { gc =>
146
147
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 ))
148
149
gc.setFontSmoothingType(javafx.scene.text.FontSmoothingType .LCD )
149
- gc.fillText(text, x, y + size)
150
+ gc.fillText(text, x.toDouble , y.toDouble + size.toDouble )
150
151
}
151
152
152
153
@@ -169,12 +170,12 @@ class FxPixelWindow(
169
170
s.setTitle(title)
170
171
root.setBackground(javafx.scene.layout.Background .EMPTY )
171
172
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 )
173
174
canvas.getGraphicsContext2D.setStroke(Fx .toFxColor(foreground))
174
175
s.setScene(scene)
175
176
root.setCenter(canvas)
176
- s.setMinWidth(width)
177
- s.setMinHeight(height)
177
+ s.setMinWidth(width.toDouble )
178
+ s.setMinHeight(height.toDouble )
178
179
s.show
179
180
180
181
// if (initBasicMenu) root.getChildren.add(0, basicMenuBar)
0 commit comments