From: Mark Slee Date: Sun, 30 Jun 2013 19:39:53 +0000 (-0700) Subject: Add a debug overlay mode that can set channels/cubes to black/white X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=554e38ff135a9f32fb900a945a772aa950f316c6;p=SugarCubes.git Add a debug overlay mode that can set channels/cubes to black/white --- diff --git a/_Internals.pde b/_Internals.pde index 3bf4d31..dab8bdd 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -53,6 +53,7 @@ boolean mappingMode = false; boolean pandaBoardsEnabled = false; boolean debugMode = false; +DebugUI debugUI; // Camera variables float eyeR, eyeA, eyeX, eyeY, eyeZ, midX, midY, midZ; @@ -93,6 +94,7 @@ void setup() { // Build overlay UI ui = controlUI = new ControlUI(); mappingUI = new MappingUI(mappingTool); + debugUI = new DebugUI(frontChannels, rearChannels); logTime("Built overlay UI"); // MIDI devices @@ -101,7 +103,7 @@ void setup() { } SCMidiDevices.initializeStandardDevices(glucose); logTime("Setup MIDI devices"); - + // Setup camera midX = glucose.model.xMax/2 + 20; midY = glucose.model.yMax/2; @@ -149,6 +151,10 @@ void draw() { // Draws the simulation and the 2D UI overlay background(40); color[] colors = glucose.getColors(); + if (debugMode) { + debugUI.maskColors(colors); + } + camera( eyeX, eyeY, eyeZ, midX, midY, midZ, @@ -181,6 +187,10 @@ void draw() { strokeWeight(1); drawUI(); + if (debugMode) { + debugUI.draw(); + } + // TODO(mcslee): move into GLucose engine if (pandaBoardsEnabled) { pandaFront.send(colors); @@ -216,6 +226,7 @@ void keyPressed() { case 'd': debugMode = !debugMode; println("Debug output: " + (debugMode ? "ON" : "OFF")); + break; case 'm': mappingMode = !mappingMode; if (mappingMode) { @@ -250,6 +261,9 @@ void mousePressed() { if (mouseX > ui.leftPos) { ui.mousePressed(); } else { + if (debugMode) { + debugUI.mousePressed(); + } mx = mouseX; my = mouseY; } diff --git a/_Overlay.pde b/_Overlay.pde index 5ee02a4..08e0bef 100644 --- a/_Overlay.pde +++ b/_Overlay.pde @@ -614,3 +614,148 @@ class MappingUI extends OverlayUI { } } +class DebugUI { + + final int[][] channelList; + final int debugX = 10; + final int debugY = 42; + final int debugXSpacing = 28; + final int debugYSpacing = 22; + final int[][] debugState = new int[17][6]; + + final int DEBUG_STATE_ANIM = 0; + final int DEBUG_STATE_WHITE = 1; + final int DEBUG_STATE_OFF = 2; + + DebugUI(int[][] frontChannels, int[][] rearChannels) { + channelList = new int[frontChannels.length + rearChannels.length][]; + int channelIndex = 0; + for (int[] channel : frontChannels) { + channelList[channelIndex++] = channel; + } + for (int[] channel : rearChannels) { + channelList[channelIndex++] = channel; + } + for (int i = 0; i < debugState.length; ++i) { + for (int j = 0; j < debugState[i].length; ++j) { + debugState[i][j] = DEBUG_STATE_ANIM; + } + } + } + + void draw() { + noStroke(); + int xBase = debugX; + int yPos = debugY; + + fill(color(0, 0, 0, 80)); + rect(4, 32, 172, 388); + + int channelNum = 0; + for (int[] channel : channelList) { + int xPos = xBase; + drawNumBox(xPos, yPos, channelNum+1, debugState[channelNum][0]); + + boolean first = true; + int cubeNum = 0; + for (int cube : channel) { + if (cube == 0) { + break; + } + xPos += debugXSpacing; + if (first) { + first = false; + } else { + stroke(#999999); + line(xPos - 12, yPos + 8, xPos, yPos + 8); + } + drawNumBox(xPos, yPos, cube, debugState[channelNum][cubeNum+1]); + ++cubeNum; + } + + yPos += debugYSpacing; + ++channelNum; + } + drawNumBox(xBase, yPos, "A", debugState[channelNum][0]); + } + + void drawNumBox(int xPos, int yPos, int label, int state) { + drawNumBox(xPos, yPos, "" + label, state); + } + + void drawNumBox(int xPos, int yPos, String label, int state) { + noFill(); + color textColor = #cccccc; + switch (state) { + case DEBUG_STATE_ANIM: + noStroke(); + fill(#880000); + rect(xPos, yPos, 16, 8); + fill(#000088); + rect(xPos, yPos+8, 16, 8); + noFill(); + stroke(textColor); + rect(xPos, yPos, 16, 16); + break; + case DEBUG_STATE_WHITE: + stroke(textColor); + fill(#e9e9e9); + rect(xPos, yPos, 16, 16); + textColor = #333333; + break; + case DEBUG_STATE_OFF: + stroke(textColor); + rect(xPos, yPos, 16, 16); + break; + } + + noStroke(); + fill(textColor); + text(label, xPos + 2, yPos + 12); + + } + + void maskColors(color[] colors) { + color white = #FFFFFF; + color off = #000000; + int channelIndex = 0; + for (int[] channel : channelList) { + int cubeIndex = 1; + for (int rawCubeIndex : channel) { + if (rawCubeIndex > 0) { + int state = debugState[channelIndex][cubeIndex]; + if (state != DEBUG_STATE_ANIM) { + color debugColor = (state == DEBUG_STATE_WHITE) ? white : off; + Cube cube = glucose.model.getCubeByRawIndex(rawCubeIndex); + for (Point p : cube.points) { + colors[p.index] = debugColor; + } + } + } + ++cubeIndex; + } + ++channelIndex; + } + } + + void mousePressed() { + int dx = (mouseX - debugX) / debugXSpacing; + int dy = (mouseY - debugY) / debugYSpacing; + if ((dy >= 0) && (dy < debugState.length)) { + if ((dx >= 0) && (dx < debugState[dy].length)) { + int newState = debugState[dy][dx] = (debugState[dy][dx] + 1) % 3; + if (dy == 16) { + for (int[] states : debugState) { + for (int i = 0; i < states.length; ++i) { + states[i] = newState; + } + } + } else if (dx == 0) { + for (int i = 0; i < debugState[dy].length; ++i) { + debugState[dy][i] = newState; + } + } + } + } + } +}