From: Mark Slee Date: Thu, 8 Aug 2013 07:45:07 +0000 (-0700) Subject: Make pattern list scrollable, since we'll have many now X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0ba6ac440fc4901d11d90f7bef6e6da770bd6911;p=SugarCubes.git Make pattern list scrollable, since we'll have many now --- diff --git a/SugarCubes.pde b/SugarCubes.pde index eb8df74..7d4cebf 100644 --- a/SugarCubes.pde +++ b/SugarCubes.pde @@ -37,11 +37,11 @@ LXPattern[] patterns(GLucose glucose) { // Basic test patterns for reference, not art new TestCubePattern(glucose), -// new TestHuePattern(glucose), + new TestHuePattern(glucose), + new TestProjectionPattern(glucose), // new TestXPattern(glucose), - new TestYPattern(glucose), +// new TestYPattern(glucose), // new TestZPattern(glucose), -// new TestProjectionPattern(glucose), }; } diff --git a/_Internals.pde b/_Internals.pde index e5a7755..abfe6be 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -348,8 +348,12 @@ void mouseReleased() { } void mouseWheel(int delta) { - eyeR = constrain(eyeR - delta, -500, -80); - eyeX = midX + eyeR*sin(eyeA); - eyeZ = midZ + eyeR*cos(eyeA); + if (mouseX > ui.leftPos) { + ui.mouseWheel(delta); + } else { + eyeR = constrain(eyeR - delta, -500, -80); + eyeX = midX + eyeR*sin(eyeA); + eyeZ = midZ + eyeR*cos(eyeA); + } } diff --git a/_Overlay.pde b/_Overlay.pde index 74ba8f1..2ff364d 100644 --- a/_Overlay.pde +++ b/_Overlay.pde @@ -30,6 +30,7 @@ abstract class OverlayUI { protected final float knobIndent = .4; protected final int knobSpacing = 6; protected final int knobLabelHeight = 14; + protected final int scrollWidth = 14; protected final color lightBlue = #666699; protected final color lightGreen = #669966; @@ -85,10 +86,20 @@ abstract class OverlayUI { } protected int drawObjectList(int yPos, String title, Object[] items, Method stateMethod) { - return drawObjectList(yPos, title, items, classNameArray(items, null), stateMethod); + int sz = (items != null) ? items.length : 0; + return drawObjectList(yPos, title, items, stateMethod, sz, 0); } - + + protected int drawObjectList(int yPos, String title, Object[] items, Method stateMethod, int scrollLength, int scrollPos) { + return drawObjectList(yPos, title, items, classNameArray(items, null), stateMethod, scrollLength, scrollPos); + } + protected int drawObjectList(int yPos, String title, Object[] items, String[] names, Method stateMethod) { + int sz = (items != null) ? items.length : 0; + return drawObjectList(yPos, title, items, names, stateMethod, sz, 0); + } + + protected int drawObjectList(int yPos, String title, Object[] items, String[] names, Method stateMethod, int scrollLength, int scrollPos) { noStroke(); fill(titleColor); textFont(titleFont); @@ -98,7 +109,8 @@ abstract class OverlayUI { textFont(itemFont); color textColor; boolean even = true; - for (int i = 0; i < items.length; ++i) { + int yTop = yPos+6; + for (int i = scrollPos; i < items.length && i < (scrollPos + scrollLength); ++i) { Object o = items[i]; int state = STATE_DEFAULT; try { @@ -120,11 +132,21 @@ abstract class OverlayUI { fill(even ? #666666 : #777777); break; } - rect(leftPos, yPos+6, width, lineHeight); + rect(leftPos, yPos+6, w, lineHeight); fill(textColor); text(names[i], leftTextPos, yPos += lineHeight); even = !even; } + if ((scrollPos > 0) || (scrollLength < items.length)) { + int yHere = yPos+6; + noStroke(); + fill(color(0, 0, 0, 50)); + rect(leftPos + w - scrollWidth, yTop, scrollWidth, yHere - yTop); + fill(#666666); + rect(leftPos + w - scrollWidth + 2, yTop + (yHere-yTop) * (scrollPos / (float)items.length), scrollWidth - 4, (yHere - yTop) * (scrollLength / (float)items.length)); + + } + } return yPos; } @@ -163,6 +185,7 @@ abstract class OverlayUI { abstract public void mousePressed(); abstract public void mouseDragged(); abstract public void mouseReleased(); + abstract public void mouseWheel(int delta); } /** @@ -179,6 +202,9 @@ class ControlUI extends OverlayUI { private int firstTransitionKnobY; private int firstEffectY; private int firstEffectKnobY; + + private final int PATTERN_LIST_LENGTH = 8; + private int patternScrollPos = 0; private int tempoY; @@ -204,7 +230,7 @@ class ControlUI extends OverlayUI { drawLogoAndBackground(); int yPos = 0; firstPatternY = yPos + lineHeight + 6; - yPos = drawObjectList(yPos, "PATTERN", patterns, patternNames, patternStateMethod); + yPos = drawObjectList(yPos, "PATTERN", patterns, patternNames, patternStateMethod, PATTERN_LIST_LENGTH, patternScrollPos); yPos += controlSpacing; firstPatternKnobY = yPos; int xPos = leftTextPos; @@ -333,6 +359,7 @@ class ControlUI extends OverlayUI { private int patternKnobIndex = -1; private int transitionKnobIndex = -1; private int effectKnobIndex = -1; + private boolean patternScrolling = false; private int lastY; private int releaseEffect = -1; @@ -342,6 +369,7 @@ class ControlUI extends OverlayUI { lastY = mouseY; patternKnobIndex = transitionKnobIndex = effectKnobIndex = -1; releaseEffect = -1; + patternScrolling = false; if (mouseY > tempoY) { if (mouseY - tempoY < tempoHeight) { lx.tempo.tap(); @@ -371,15 +399,21 @@ class ControlUI extends OverlayUI { patternKnobIndex += glucose.NUM_PATTERN_KNOBS / 2; } } else if (mouseY > firstPatternY) { - int patternIndex = objectClickIndex(firstPatternY); - if (patternIndex < patterns.length) { - lx.goIndex(patternIndex); + if ((patterns.length > PATTERN_LIST_LENGTH) && (mouseX > width - scrollWidth)) { + patternScrolling = true; + } else { + int patternIndex = objectClickIndex(firstPatternY); + if (patternIndex < patterns.length) { + lx.goIndex(patternIndex + patternScrollPos); + } } } } + int scrolldy = 0; public void mouseDragged() { int dy = lastY - mouseY; + scrolldy += dy; lastY = mouseY; if (patternKnobIndex >= 0 && patternKnobIndex < glucose.NUM_PATTERN_KNOBS) { LXParameter p = glucose.patternKnobs.get(patternKnobIndex); @@ -390,10 +424,15 @@ class ControlUI extends OverlayUI { } else if (transitionKnobIndex >= 0 && transitionKnobIndex < glucose.NUM_TRANSITION_KNOBS) { LXParameter p = glucose.transitionKnobs.get(transitionKnobIndex); p.setValue(constrain(p.getValuef() + dy*.01, 0, 1)); + } else if (patternScrolling) { + int scroll = scrolldy / lineHeight; + scrolldy = scrolldy % lineHeight; + patternScrollPos = constrain(patternScrollPos - scroll, 0, patterns.length - PATTERN_LIST_LENGTH); } } public void mouseReleased() { + patternScrolling = false; tempoDown = false; if (releaseEffect >= 0) { effects[releaseEffect].trigger(); @@ -401,6 +440,15 @@ class ControlUI extends OverlayUI { } } + public void mouseWheel(int delta) { + if (mouseY > firstPatternY) { + int patternIndex = objectClickIndex(firstPatternY); + if (patternIndex < PATTERN_LIST_LENGTH) { + patternScrollPos = constrain(patternScrollPos + delta, 0, patterns.length - PATTERN_LIST_LENGTH); + } + } + } + } /** @@ -588,8 +636,8 @@ class MappingUI extends OverlayUI { } } - public void mouseReleased() { - } + public void mouseReleased() {} + public void mouseWheel(int delta) {} public void mouseDragged() { final int DRAG_THRESHOLD = 5;