Scene scene = new Scene(root);
scene.setOnKeyPressed(keyEvent -> {
- if (keyEvent.getCode() == KeyCode.ESCAPE) {
+ if (keyEvent.getCode() == KeyCode.ESCAPE || keyEvent.getCode() == KeyCode.Q) {
stage.close();
cakelight.cleanup();
}
VideoMode mode = new VideoMode();
cakelight.setMode(mode);
cakelight.startLoop();
- mode.onFrame(frame -> drawFrame(canvas.getGraphicsContext2D(), frame));
+ mode.onVideoFrame(frame -> drawFrame(canvas.getGraphicsContext2D(), frame));
+ }
+
+ private javafx.scene.paint.Color getLedColor(LedFrame frame, int led) {
+ kaka.cakelight.Color c = frame.getLedColor(led);
+ return javafx.scene.paint.Color.rgb(c.r(), c.g(), c.b());
}
private void drawFrame(GraphicsContext gc, Frame frame) {
drawRows(gc, frame);
// drawVideo(gc, frame);
drawBorderAndGrid(gc);
- drawLEDs(gc, frame);
}
- private void drawLEDs(GraphicsContext gc, Frame frame) {
+ private void drawLEDs(GraphicsContext gc, LedFrame frame) {
int ledLength = GUTTER;
float colSize = 16f * BLOCK / config.leds.cols;
float rowSize = 9f * BLOCK / config.leds.rows;
// DropShadow shadow = new DropShadow(BlurType.ONE_PASS_BOX, Color.RED, colSize * 2, colSize, 0, 0);
for (int x = 0; x < config.leds.cols; x++) {
- gc.setFill(frame.getLedColor(ListPosition.TOP, x));
+ // Top
+ gc.setFill(getLedColor(frame, config.leds.cols * 2 + config.leds.rows - x - 1));
gc.fillRect(GUTTER + x * colSize, GUTTER - ledLength, colSize, ledLength);
- gc.setFill(frame.getLedColor(ListPosition.BOTTOM, x));
+ // Bottom
+ gc.setFill(getLedColor(frame, x));
gc.fillRect(GUTTER + x * colSize, GUTTER + 9 * BLOCK, colSize, ledLength);
}
for (int y = 0; y < config.leds.rows; y++) {
- gc.setFill(frame.getLedColor(ListPosition.LEFT, y));
+ // Left
+ gc.setFill(getLedColor(frame, config.leds.cols * 2 + config.leds.rows + y));
gc.fillRect(GUTTER - ledLength, GUTTER + y * rowSize, ledLength, rowSize);
- gc.setFill(frame.getLedColor(ListPosition.RIGHT, y));
+ // Right
+ gc.setFill(getLedColor(frame, config.leds.rows + config.leds.cols - y - 1));
gc.fillRect(GUTTER + 16 * BLOCK, GUTTER + y * rowSize, ledLength, rowSize);
}
}