From c5f346d32d79eea7bc89d31d8cd58651edb8c62e Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 14 Jul 2022 14:42:57 +0200 Subject: [PATCH] the GUI now has a maximum height. added functionality to scroll through effect-list if height is exceeded --- effects.pde | 2 +- secondapplet.pde | 133 +++++++++++++++++++++++++++++++---------------- 2 files changed, 88 insertions(+), 47 deletions(-) diff --git a/effects.pde b/effects.pde index 2352b4e..5f46bc0 100644 --- a/effects.pde +++ b/effects.pde @@ -378,7 +378,7 @@ class DISTORTER extends Shader { float times = (totalnum/floor(totalnum/neww)); float offx = (totalnum%neww)/times; float ratiox = neww/buffer.width; - println(ratiox); + //println(ratiox); renderer.beginDraw(); renderer.noStroke(); diff --git a/secondapplet.pde b/secondapplet.pde index 3f521ad..0080333 100644 --- a/secondapplet.pde +++ b/secondapplet.pde @@ -1,6 +1,7 @@ //contains the GUI (ie CP5) in the secondapplet. also contains 3 classes: shaderManager, Brick and Slider PImage bin; +int maxSurfaceHeight = 500; public class SecondApplet extends PApplet { @@ -8,7 +9,7 @@ public class SecondApplet extends PApplet { shaderManager shaderManager = new shaderManager(); ArrayList shaderList = new ArrayList(); ArrayList bricks = new ArrayList(); - ArrayList slider = new ArrayList(); //brick + ArrayList slider = new ArrayList(); //brick int binX, binY, binS; public void settings() { size(275, 120); @@ -78,6 +79,22 @@ public class SecondApplet extends PApplet { int totalBrickHeight; public void draw() { background(68, 68, 68); + + pushMatrix(); + if (heightOverLimit) { + translate(0, scrollAmount); + } + totalBrickHeight = 0; + for (int i = 0; i < shaderList.size(); i++) { + bricks.get(i).update(); + bricks.get(i).display(); + //bricks.get(i).y = totalBrickHeight; ????? what was that for + totalBrickHeight+= bricks.get(i).h; + } + popMatrix(); + fill(68, 68, 68); + noStroke(); + rect(0, height-120, width, 120); image(bin, binX, binY, binS, binS); stroke(255); strokeWeight(1); @@ -86,13 +103,7 @@ public class SecondApplet extends PApplet { text(renderer.width + "x" + renderer.height, 100, height-18); textSize(10); line(0, height-120, width, height-120); - totalBrickHeight = 0; - for (int i = 0; i < shaderList.size(); i++) { - bricks.get(i).update(); - bricks.get(i).display(); - bricks.get(i).y = totalBrickHeight; - totalBrickHeight+= bricks.get(i).h; - } + if (pressedBrick != -1) { fill(255); noStroke(); @@ -100,15 +111,33 @@ public class SecondApplet extends PApplet { } } + boolean heightOverLimit; void refreshSurface(int mode) { + int currentBrickHeight = 0; if (shaderList.size() > 0) { - if (mode == 0) surface.setSize(width, height+bricks.get(shaderList.size()-1).h); - else if (mode == 1) surface.setSize(width, height-bricks.get(pressedBrick).h); - } else { + if (mode == 0) { + currentBrickHeight = totalBrickHeight + bricks.get(shaderList.size()-1).h; + surface.setSize(width, height+bricks.get(shaderList.size()-1).h); + } else if (mode == 1) { + currentBrickHeight = totalBrickHeight - bricks.get(pressedBrick).h; + if (heightOverLimit) { + surface.setSize(width, currentBrickHeight+120); + } else { + surface.setSize(width, height-bricks.get(pressedBrick).h); + } + } + } else { surface.setSize(width, 120); } - + if (currentBrickHeight + 120 > maxSurfaceHeight) { + surface.setSize(width, maxSurfaceHeight); + println("hi"); + heightOverLimit = true; + } else { + heightOverLimit = false; + scrollAmount = 0; + } cp5.setPosition(0, height-120); binY = height-87; } @@ -143,7 +172,7 @@ public class SecondApplet extends PApplet { for (int i = pos1; i < pos2; i++) { swapShader(i, i+1); } - } else { + } else { for (int i = pos1; i > pos2; i--) { swapShader(i, i-1); } @@ -151,12 +180,12 @@ public class SecondApplet extends PApplet { } void removeShader(int pos) { - if (pos >= 0 && shaderList.size() > pos) { + if (pos >= 0 && shaderList.size() > pos) { refreshSurface(1); shaderList.remove(pos); bricks.remove(pos); for (int i = shaderList.size()-1; i > -1; i--) { - bricks.get(i).setPos(i); + bricks.get(i).setPos(i); bricks.get(i).updateSliderPos(); shaderList.get(i).pos = i; } @@ -169,7 +198,7 @@ public class SecondApplet extends PApplet { shaderList.get(i).getValuesFromGUI(); shaderList.get(i).apply(); } - } + } catch(Exception e) { println("Warning: Brick not yet loaded"); } @@ -257,29 +286,29 @@ public class SecondApplet extends PApplet { if (paused && slider.get(i).animated) paused = false; } - if (mouseX > 10 && mouseX < 22 && mouseY > 4+totalBrickHeight && mouseY < 4+totalBrickHeight+13) { + if (mouseX > 10 && mouseX < 22 && mouseY > 4+totalBrickHeight+scrollAmount && mouseY < 4+totalBrickHeight+13+scrollAmount) { hoverActiveButton = true; } else { hoverActiveButton = false; } - if (mouseX > 25 && mouseX < 37 && mouseY > 4+totalBrickHeight && mouseY < 4+totalBrickHeight+13) { + if (mouseX > 25 && mouseX < 37 && mouseY > 4+totalBrickHeight+scrollAmount && mouseY < 4+totalBrickHeight+13+scrollAmount) { hoverPauseButton = true; } else { hoverPauseButton = false; } - if (mouseY > y-5 && mouseY < y+5 && pressedBrick != -1) { + if (mouseY > y-5+scrollAmount && mouseY < y+5+scrollAmount && pressedBrick != -1) { hoveringLineAbove = true; if (pos > 0) { bricks.get(pos-1).hovering = false; } - } else if (pos == bricks.size()-1 && mouseY > y+h-5 && mouseY < y+h+5 && pressedBrick != -1) { + } else if (pos == bricks.size()-1 && mouseY > y+h-5+scrollAmount && mouseY < y+h+5+scrollAmount && pressedBrick != -1) { hoveringLineBelow = true; } else { hoveringLineBelow = false; hoveringLineAbove = false; - if (mouseY > totalBrickHeight && mouseY < totalBrickHeight+h && !sliderHover && !hoverActiveButton && !hoverPauseButton) { + if (mouseY > totalBrickHeight+scrollAmount && mouseY < totalBrickHeight+h+scrollAmount && !sliderHover && !hoverActiveButton && !hoverPauseButton) { hovering = true; } else { hovering = false; @@ -314,6 +343,7 @@ public class SecondApplet extends PApplet { text(name, 40, 13+totalBrickHeight, 10); stroke(255); + strokeWeight(1); if (active) fill(185); else noFill(); rect(10, 4+totalBrickHeight, 10, 10); @@ -420,13 +450,13 @@ public class SecondApplet extends PApplet { } - if (mouseX >= x && mouseX <= x+w && mouseY >= y && mouseY <= y+h) { + if (mouseX >= x && mouseX <= x+w && mouseY >= y+scrollAmount && mouseY <= y+h+scrollAmount) { hovering = true; } else { hovering = false; } - if (mouseX >= x+w+5 && mouseX <= x+w+5+15 && mouseY >= y && mouseY <= y+h) { + if (mouseX >= x+w+5 && mouseX <= x+w+5+15 && mouseY >= y+scrollAmount && mouseY <= y+h+scrollAmount) { hovering_anim_btn = true; } else { hovering_anim_btn = false; @@ -457,39 +487,39 @@ public class SecondApplet extends PApplet { void CP5_listActions(int n) { if (shaderList.size() < maxFx) { switch(n) { - case(0): - shaderManager.addShader(new ASDFPIXELSORT()); + case(0): + shaderManager.addShader(new ASDFPIXELSORT()); break; - case(1): - shaderManager.addShader(new DISTORTER()); + case(1): + shaderManager.addShader(new DISTORTER()); break; - case(2): - shaderManager.addShader(new FM()); + case(2): + shaderManager.addShader(new FM()); break; case(3): shaderManager.addShader(new WZIP()); break; - case(4): - shaderManager.addShader(new AUECHO()); + case(4): + shaderManager.addShader(new AUECHO()); break; - case(5): - shaderManager.addShader(new SLITSCAN()); + case(5): + shaderManager.addShader(new SLITSCAN()); break; - case(6): - shaderManager.addShader(new WAHWAH()); + case(6): + shaderManager.addShader(new WAHWAH()); break; - case(7): - shaderManager.addShader(new PHASER()); + case(7): + shaderManager.addShader(new PHASER()); break; - case(8): - shaderManager.addShader(new ECHO()); + case(8): + shaderManager.addShader(new ECHO()); break; case(9): shaderManager.addShader(new DARKER()); break; /* - case(4): - shaderManager.addShader(new AUECHO()); + case(4): + shaderManager.addShader(new AUECHO()); break; */ default: @@ -559,11 +589,22 @@ public class SecondApplet extends PApplet { pressedSlider = -1; pressedBrick = -1; } - + int scrollAmount; void mouseWheel(MouseEvent event) { - - if (event.getCount() < 0) renderSize += 8; - else renderSize -= 8; - renderSize = constrain(renderSize, 8, 15000); + textSize(25); + if (mouseX > 100 && mouseX < textWidth(str(renderer.width) + "x" + str(renderer.height)) + 100 && mouseY > height - 40 && mouseY < height) { + if (event.getCount() < 0) renderSize += 8; + else renderSize -= 8; + renderSize = constrain(renderSize, 8, 15000); + } + if (heightOverLimit && mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height-120) { + for (int i = 0; i < bricks.size(); i++) { + scrollAmount -= event.getCount(); + scrollAmount = constrain(scrollAmount, maxSurfaceHeight-120-totalBrickHeight, 0); + //bricks.get(i).y += event.getCount(); + //bricks.get(i).updateSliderPos(); + } + } + textSize(10); } }