X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FGuiTest.java;h=8c1516c43c03cafb50f372f0fd342a1ad2dc819c;hb=67b0a75891f19e91cc35e23fa56915cfd7cd52de;hp=b73d37fb33305408faad3dc05e0d2aabab5bf5f2;hpb=01ee91e7622bbdf6a940b2d8ca9efc1f133cbe97;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/GuiTest.java b/src/kaka/cakelight/GuiTest.java index b73d37f..8c1516c 100644 --- a/src/kaka/cakelight/GuiTest.java +++ b/src/kaka/cakelight/GuiTest.java @@ -9,6 +9,7 @@ import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.paint.Paint; import javafx.stage.Stage; +import kaka.cakelight.mode.AmbientMode; import org.opencv.core.Core; import org.opencv.core.Mat; @@ -37,7 +38,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(); } @@ -63,7 +64,12 @@ public class GuiTest extends Application { mode.onVideoFrame(frame -> drawFrame(canvas.getGraphicsContext2D(), frame)); } - private void drawFrame(GraphicsContext gc, Frame 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, VideoFrame frame) { if (paused) return; System.out.println("Drawing a frame"); drawCols(gc, frame); @@ -78,20 +84,24 @@ 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); } } - private void drawVideo(GraphicsContext gc, Frame frame) { + private void drawVideo(GraphicsContext gc, VideoFrame frame) { byte[] rgb = new byte[3]; Mat img = frame.getConvertedImage(); float colSize = 16 * BLOCK / (float)img.cols(); @@ -105,7 +115,7 @@ public class GuiTest extends Application { } } - private void drawCols(GraphicsContext gc, Frame frame) { + private void drawCols(GraphicsContext gc, VideoFrame frame) { byte[] rgb = new byte[3]; for (int x = 0; x < config.leds.cols; x++) { for (int y = 0; y < 9; y++) { @@ -115,7 +125,7 @@ public class GuiTest extends Application { } } - private void drawRows(GraphicsContext gc, Frame frame) { + private void drawRows(GraphicsContext gc, VideoFrame frame) { byte[] rgb = new byte[3]; for (int y = 0; y < config.leds.rows; y++) { for (int x = 0; x < 16; x++) {