X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FGuiTest.java;h=c72519a96dd1d91d1b90247acde5d90c29f51626;hb=ed56b145bc04170b4129f4ff92b9eab0e6e4dc74;hp=6dbb5ffec1cfb49dbabb03dc15ec5c308bd749b9;hpb=d182b8ccdbbbdadc4441170f0135ec98c76f5d17;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/GuiTest.java b/src/kaka/cakelight/GuiTest.java index 6dbb5ff..c72519a 100644 --- a/src/kaka/cakelight/GuiTest.java +++ b/src/kaka/cakelight/GuiTest.java @@ -37,7 +37,7 @@ public class GuiTest extends Application { 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(); } @@ -56,18 +56,18 @@ public class GuiTest extends Application { private void setupCakeLight() { log("Running with config:\n" + config); - cakelight = new CakeLight(config, new LedController() { - @Override - public void onFrame(LedFrame ledFrame) { - if (!paused) drawLEDs(canvas.getGraphicsContext2D(), ledFrame); - } - }); + cakelight = new CakeLight(config); VideoMode mode = new VideoMode(); cakelight.setMode(mode); cakelight.startLoop(); 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) { if (paused) return; System.out.println("Drawing a frame"); @@ -83,15 +83,19 @@ public class GuiTest extends Application { 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(x + config.leds.rows)); + // 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(config.leds.rows * 2 + config.leds.cols * 2 - 1 - 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(config.leds.rows - 1 - 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(y + config.leds.rows + config.leds.cols)); + // Right + gc.setFill(getLedColor(frame, config.leds.rows + config.leds.cols - y - 1)); gc.fillRect(GUTTER + 16 * BLOCK, GUTTER + y * rowSize, ledLength, rowSize); } }