|
|
@@ -2,13 +2,14 @@ |
|
|
|
|
|
|
|
PImage bin; |
|
|
|
|
|
|
|
|
|
|
|
public class SecondApplet extends PApplet { |
|
|
|
ControlP5 cp5; |
|
|
|
shaderManager shaderManager = new shaderManager(); |
|
|
|
ArrayList<Shader> shaderList = new ArrayList<Shader>(); |
|
|
|
ArrayList<Brick> bricks = new ArrayList<Brick>(); |
|
|
|
ArrayList<Slider> slider = new ArrayList<Slider>(); //brick |
|
|
|
|
|
|
|
int binX, binY, binS; |
|
|
|
public void settings() { |
|
|
|
size(275, 120); |
|
|
|
} |
|
|
@@ -29,6 +30,10 @@ public class SecondApplet extends PApplet { |
|
|
|
.setPosition(100, height-50) |
|
|
|
.setSize(20, 20) |
|
|
|
.plugTo(this, "CP5_recordAction"); |
|
|
|
|
|
|
|
binX = width-55; |
|
|
|
binY = height-85; |
|
|
|
binS = 40; |
|
|
|
} |
|
|
|
|
|
|
|
void CP5_recordAction() { |
|
|
@@ -38,7 +43,7 @@ public class SecondApplet extends PApplet { |
|
|
|
int totalBrickHeight; |
|
|
|
public void draw() { |
|
|
|
background(68, 68, 68); |
|
|
|
image(bin, width-55, height-85, 40, 40); |
|
|
|
image(bin, binX, binY, binS, binS); |
|
|
|
stroke(255); |
|
|
|
strokeWeight(1); |
|
|
|
line(0, height-120, width, height-120); |
|
|
@@ -46,14 +51,27 @@ public class SecondApplet extends PApplet { |
|
|
|
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(); |
|
|
|
rect(mouseX, mouseY, 35, 15); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void refreshSurface() { |
|
|
|
surface.setSize(width, height+bricks.get(shaderList.size()-1).h); |
|
|
|
void refreshSurface(int mode) { |
|
|
|
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 { |
|
|
|
surface.setSize(width, 120); |
|
|
|
} |
|
|
|
|
|
|
|
cp5.setPosition(0, height-120); |
|
|
|
binY = height-85; |
|
|
|
} |
|
|
|
|
|
|
|
class shaderManager { |
|
|
@@ -61,7 +79,7 @@ public class SecondApplet extends PApplet { |
|
|
|
shaderList.add(shader); |
|
|
|
shader.pos = shaderList.size()-1; |
|
|
|
bricks.add(new Brick(shaderList.size()-1, shaderList.get(shaderList.size()-1).params, shader.name)); |
|
|
|
refreshSurface(); |
|
|
|
refreshSurface(0); |
|
|
|
println("Added " + shader + " to fxList at spot. List length: " + shaderList.size()); |
|
|
|
} |
|
|
|
void swapShader(int pos1, int pos2) { |
|
|
@@ -70,19 +88,24 @@ public class SecondApplet extends PApplet { |
|
|
|
Collections.swap(bricks, pos1, pos2); |
|
|
|
shaderList.get(pos1).pos = pos1; |
|
|
|
shaderList.get(pos2).pos = pos2; |
|
|
|
bricks.get(pos1).pos = pos1; |
|
|
|
bricks.get(pos2).pos = pos2; |
|
|
|
bricks.get(pos1).setPos(pos1); |
|
|
|
bricks.get(pos2).setPos(pos2); |
|
|
|
for (int i = 0; i < bricks.size(); i++) { |
|
|
|
bricks.get(i).updateSliderPos(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void removeShader(int 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).pos = i; |
|
|
|
//bricks.get(i).pos = i; |
|
|
|
bricks.get(i).setPos(i); |
|
|
|
shaderList.get(i).pos = i; |
|
|
|
} |
|
|
|
refreshSurface(); |
|
|
|
} |
|
|
|
} |
|
|
|
void applyShader() { |
|
|
@@ -93,28 +116,42 @@ public class SecondApplet extends PApplet { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int pressedBrick = -1; |
|
|
|
class Brick { |
|
|
|
ArrayList<Slider> slider = new ArrayList<Slider>(); |
|
|
|
ArrayList<Param> params = new ArrayList<Param>(); |
|
|
|
boolean dragHovered; |
|
|
|
boolean dragging, dragHovering, hovering; |
|
|
|
color brickBGcol; |
|
|
|
int pos; |
|
|
|
int h; |
|
|
|
int h, y; |
|
|
|
String name; |
|
|
|
|
|
|
|
Brick(int pos_, ArrayList params_, String name_) { |
|
|
|
name = name_; |
|
|
|
pos = pos_; |
|
|
|
params = params_; |
|
|
|
|
|
|
|
y = totalBrickHeight; |
|
|
|
h = 20 + params.size() * 20; |
|
|
|
for (int i = 0; i < params.size(); i++) { |
|
|
|
slider.add(new Slider(10, 20+(20*i)+totalBrickHeight, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type, params.get(i).osciModes)); //add possible waves to slider |
|
|
|
slider.add(new Slider(10, 20+(20*i)+y, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type, params.get(i).osciModes)); //add possible waves to slider |
|
|
|
} |
|
|
|
println(totalBrickHeight + " " + h); |
|
|
|
} |
|
|
|
|
|
|
|
void setPos(int pos_) { |
|
|
|
pos = pos_; |
|
|
|
} |
|
|
|
|
|
|
|
void updateSliderPos() { |
|
|
|
y = 0; |
|
|
|
for (int i = 0; i < pos; i++) { |
|
|
|
y += bricks.get(i).h; |
|
|
|
} |
|
|
|
for (int i = 0; i < slider.size(); i++) { |
|
|
|
slider.get(i).y = 20+(20*i)+y; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void exchangeSlider(int sliderNo, Param param) { |
|
|
|
slider.get(sliderNo).setMinMax(param.minValue, param.maxValue); |
|
|
|
slider.get(sliderNo).setMode(param.type); |
|
|
@@ -123,6 +160,18 @@ public class SecondApplet extends PApplet { |
|
|
|
|
|
|
|
|
|
|
|
void update() { |
|
|
|
boolean sliderHover = false; |
|
|
|
for (int i = 0; i < slider.size(); i++) { |
|
|
|
if (slider.get(i).hovering || slider.get(i).hovering_anim_btn) |
|
|
|
sliderHover = true; |
|
|
|
} |
|
|
|
|
|
|
|
if (mouseY > totalBrickHeight && mouseY < totalBrickHeight+h && !sliderHover) { |
|
|
|
hovering = true; |
|
|
|
} else { |
|
|
|
hovering = false; |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < slider.size(); i++) { |
|
|
|
slider.get(i).update(); |
|
|
|
params.get(i).value = slider.get(i).value; |
|
|
@@ -130,8 +179,15 @@ public class SecondApplet extends PApplet { |
|
|
|
brickBGcol = color(85, 85, 85); |
|
|
|
} |
|
|
|
|
|
|
|
void press() { |
|
|
|
pressedBrick = pos; |
|
|
|
} |
|
|
|
|
|
|
|
void display() { |
|
|
|
noStroke(); |
|
|
|
if (dragging) brickBGcol = color(51, 51, 51); |
|
|
|
else if (dragHovering) brickBGcol= color (105, 105, 105); |
|
|
|
else brickBGcol = color(85, 85, 85); |
|
|
|
fill(brickBGcol); |
|
|
|
rect(0, totalBrickHeight, width, h); |
|
|
|
|
|
|
@@ -143,7 +199,7 @@ public class SecondApplet extends PApplet { |
|
|
|
} |
|
|
|
|
|
|
|
stroke(150); |
|
|
|
strokeWeight(1+int(dragHovered)*2); |
|
|
|
strokeWeight(1); |
|
|
|
line(0, totalBrickHeight+h-1, width, totalBrickHeight+h-1); |
|
|
|
} |
|
|
|
} |
|
|
@@ -239,6 +295,7 @@ public class SecondApplet extends PApplet { |
|
|
|
void display() { |
|
|
|
|
|
|
|
stroke(255); |
|
|
|
strokeWeight(1); |
|
|
|
fill(100+(40*int(hovering))); |
|
|
|
rect(x, y, w, h); |
|
|
|
fill(185+(40*int(hovering))); |
|
|
@@ -343,20 +400,50 @@ public class SecondApplet extends PApplet { |
|
|
|
} |
|
|
|
|
|
|
|
void mousePressed() { |
|
|
|
for (int i = slider.size()-1; i >= 0; i--) { |
|
|
|
for (int i = slider.size()-1; i >= 0; i--) { |
|
|
|
Slider s = slider.get(i); |
|
|
|
if (s.hovering) s.press(i); |
|
|
|
if (s.hovering_anim_btn) s.animated = !s.animated; |
|
|
|
} |
|
|
|
for (int i = bricks.size()-1; i >= 0; i--) { |
|
|
|
if (bricks.get(i).hovering) { |
|
|
|
bricks.get(i).press(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
void mouseDragged() { |
|
|
|
if (pressedSlider != -1) { |
|
|
|
Slider s = slider.get(pressedSlider); |
|
|
|
s.setValue(map(mouseX, s.x, s.x+s.w, s.minVal, s.maxVal)); |
|
|
|
} |
|
|
|
if (pressedBrick != -1) { |
|
|
|
bricks.get(pressedBrick).dragging = true; |
|
|
|
|
|
|
|
for (int i = 0; i < bricks.size(); i++) { |
|
|
|
if (pressedBrick != i && bricks.get(i).hovering) { |
|
|
|
bricks.get(i).dragHovering = true; |
|
|
|
} else { |
|
|
|
bricks.get(i).dragHovering = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void mouseReleased() { |
|
|
|
if (pressedBrick != -1) { |
|
|
|
bricks.get(pressedBrick).dragging = false; |
|
|
|
for (int i = 0; i < bricks.size(); i++) { |
|
|
|
bricks.get(i).dragHovering = false; |
|
|
|
if (pressedBrick != i && bricks.get(i).hovering) { |
|
|
|
shaderManager.swapShader(pressedBrick, i); |
|
|
|
} |
|
|
|
} |
|
|
|
if (mouseX > binX && mouseX < binX+binS && mouseY > binY && mouseY < binY+binS) { |
|
|
|
println("removing"); |
|
|
|
shaderManager.removeShader(pressedBrick); |
|
|
|
} |
|
|
|
} |
|
|
|
pressedSlider = -1; |
|
|
|
pressedBrick = -1; |
|
|
|
} |
|
|
|
} |