//globals | //globals | ||||
uptime = 116717241 | |||||
uptime = 116747025 |
PImage bin; | PImage bin; | ||||
int maxSurfaceHeight = 500; | int maxSurfaceHeight = 500; | ||||
int nativeResoX, nativeResoY; | int nativeResoX, nativeResoY; | ||||
boolean renderSizeChanged = true; | |||||
public class SecondApplet extends PApplet { | public class SecondApplet extends PApplet { | ||||
ControlP5 cp5; | ControlP5 cp5; | ||||
} | } | ||||
if (currentBrickHeight + 120 > maxSurfaceHeight) { | if (currentBrickHeight + 120 > maxSurfaceHeight) { | ||||
surface.setSize(width, maxSurfaceHeight); | surface.setSize(width, maxSurfaceHeight); | ||||
println("hi"); | |||||
heightOverLimit = true; | heightOverLimit = true; | ||||
} else { | } else { | ||||
heightOverLimit = false; | heightOverLimit = false; | ||||
for (int i = 0; i < bricks.size(); i++) { | for (int i = 0; i < bricks.size(); i++) { | ||||
bricks.get(i).updateSliderPos(); | bricks.get(i).updateSliderPos(); | ||||
} | } | ||||
for (int i = min(pos1, pos2); i < shaderList.size(); i++) { | |||||
println(i); | |||||
//shaderList.get(i).change = true; | |||||
} | |||||
} | } | ||||
void moveShader(int pos1, int pos2) { | void moveShader(int pos1, int pos2) { | ||||
if (pos2 > pos1) { | if (pos2 > pos1) { | ||||
pos2 -=1; | pos2 -=1; | ||||
for (int i = pos1; i < pos2; i++) { | for (int i = pos1; i < pos2; i++) { | ||||
swapShader(i, i-1); | swapShader(i, i-1); | ||||
} | } | ||||
} | } | ||||
for (int i = max(pos1, pos2); i > 0; i--) { | |||||
//println(i); | |||||
//shaderList.get(i).change = true; | |||||
} | |||||
} | } | ||||
void removeShader(int pos) { | void removeShader(int pos) { | ||||
shaderList.get(i).pos = i; | shaderList.get(i).pos = i; | ||||
} | } | ||||
} | } | ||||
for (int i = pos; i < shaderList.size(); i++) { | |||||
//shaderList.get(i).change = true; | |||||
} | |||||
} | } | ||||
int previousRenderSize = renderSize; | |||||
void applyShader() { | void applyShader() { | ||||
renderSizeChanged = true; | |||||
if (previousRenderSize != renderSize) | |||||
previousRenderSize = renderSize; | |||||
else | |||||
renderSizeChanged = false; | |||||
for (int i = 0; i < shaderList.size(); i++) { | for (int i = 0; i < shaderList.size(); i++) { | ||||
try { | try { | ||||
shaderList.get(i).getValuesFromGUI(); | |||||
if (bricks.get(i).active) { | if (bricks.get(i).active) { | ||||
shaderList.get(i).getValuesFromGUI(); | |||||
//shaderList.get(i).getValuesFromGUI(); | |||||
shaderList.get(i).shade(); | shaderList.get(i).shade(); | ||||
} | } | ||||
} | } | ||||
resumeAllSliders(); | resumeAllSliders(); | ||||
} | } | ||||
} | } | ||||
void toggleActive() { | |||||
active = !active; | |||||
//for (int i = pos; i < shaderList.size(); i++) { | |||||
// shaderList.get(i).change = true; | |||||
//} | |||||
} | |||||
void pauseAllSliders() { | void pauseAllSliders() { | ||||
for (int i = 0; i < slider.size(); i++) { | for (int i = 0; i < slider.size(); i++) { | ||||
if (bricks.get(i).hovering) { | if (bricks.get(i).hovering) { | ||||
bricks.get(i).press(); | bricks.get(i).press(); | ||||
} | } | ||||
if (bricks.get(i).hoverActiveButton) bricks.get(i).active = !bricks.get(i).active; | |||||
if (bricks.get(i).hoverActiveButton) | |||||
{ | |||||
bricks.get(i).toggleActive(); | |||||
} | |||||
if (bricks.get(i).hoverPauseButton) bricks.get(i).playPause(); | if (bricks.get(i).hoverPauseButton) bricks.get(i).playPause(); | ||||
} | } | ||||
} | } |
class Shader { | class Shader { | ||||
int id; | int id; | ||||
int pos; | |||||
int pos, previousPos; | |||||
boolean previousActive; | |||||
String name; | String name; | ||||
ArrayList<Param> params = new ArrayList<Param>(); | ArrayList<Param> params = new ArrayList<Param>(); | ||||
ArrayList<Float> paramValues = new ArrayList<Float>(); | |||||
boolean paramChanged = true; | |||||
PGraphics canvas = createGraphics(renderer.width, renderer.height); | PGraphics canvas = createGraphics(renderer.width, renderer.height); | ||||
PGraphics result; | PGraphics result; | ||||
params = gui.bricks.get(pos).params; | params = gui.bricks.get(pos).params; | ||||
} | } | ||||
catch(Exception e) { | catch(Exception e) { | ||||
println(e); | |||||
} | } | ||||
if (paramValues.size() != params.size()) { | |||||
for (int i = 0; i < params.size(); i++) { | |||||
paramValues.add(0.0); | |||||
} | |||||
} | |||||
paramChanged = false; | |||||
for (int i = 0; i < params.size(); i++) { | |||||
if (paramValues.get(i) != params.get(i).value) { | |||||
paramValues.set(i, params.get(i).value); | |||||
paramChanged = true; | |||||
} | |||||
} | |||||
if(pos != previousPos){ | |||||
paramChanged = true; | |||||
} | |||||
previousPos = pos; | |||||
if(previousActive != gui.bricks.get(pos).active){ | |||||
paramChanged = true; | |||||
} | |||||
previousActive = gui.bricks.get(pos).active; | |||||
if (!paramChanged) { | |||||
for (int i = this.pos; i >= 0; i--) { | |||||
if (gui.shaderList.get(i).paramChanged) paramChanged = true; | |||||
} | |||||
} | |||||
if (frameRate < 1) println("Rendering " + this + " on position " + pos + "..."); | if (frameRate < 1) println("Rendering " + this + " on position " + pos + "..."); | ||||
} | } | ||||
} | } | ||||
void shade() { | void shade() { | ||||
if (renderSizeChanged || paramChanged) { | |||||
this.setupCanvas(); | |||||
this.apply(); | |||||
this.render(); | |||||
} else { | |||||
// println("nothing changed"); | |||||
renderer.beginDraw(); | |||||
renderer.image(result, 0, 0); | |||||
renderer.endDraw(); | |||||
}/* | |||||
this.setupCanvas(); | this.setupCanvas(); | ||||
this.apply(); | |||||
this.render(); | |||||
this.apply(); | |||||
this.render(); | |||||
*/ | |||||
} | } | ||||
void setupCanvas() { | void setupCanvas() { | ||||
if (directionParamIndex >= 0) direction = (int)this.params.get(directionParamIndex).value; | if (directionParamIndex >= 0) direction = (int)this.params.get(directionParamIndex).value; | ||||
int cw = (direction == 0 || direction == 2) ? renderer.width : renderer.height; | int cw = (direction == 0 || direction == 2) ? renderer.width : renderer.height; | ||||
int ch = (direction == 0 || direction == 2) ? renderer.height : renderer.width; | int ch = (direction == 0 || direction == 2) ? renderer.height : renderer.width; | ||||
//if (canvas.width != cw || canvas.height != ch) | |||||
canvas = createGraphics(cw, ch); | canvas = createGraphics(cw, ch); | ||||
canvas.beginDraw(); | canvas.beginDraw(); | ||||
canvas.imageMode(CENTER); | canvas.imageMode(CENTER); | ||||
void render() { | void render() { | ||||
renderer.beginDraw(); | renderer.beginDraw(); | ||||
renderer.imageMode(CENTER); | renderer.imageMode(CENTER); | ||||
renderer.pushMatrix(); | renderer.pushMatrix(); | ||||
renderer.translate(renderer.width/2, renderer.height/2); | renderer.translate(renderer.width/2, renderer.height/2); | ||||
renderer.endDraw(); | renderer.endDraw(); | ||||
result = createGraphics(renderer.width, renderer.height); | result = createGraphics(renderer.width, renderer.height); | ||||
result.beginDraw(); | result.beginDraw(); | ||||
result.image(renderer,0,0); | |||||
result.image(renderer, 0, 0); | |||||
result.endDraw(); | result.endDraw(); | ||||
} | } | ||||
} | } |