Sfoglia il codice sorgente

first steps for moveIn function in gui

master
Victor Giers 1 anno fa
parent
commit
2e1986d398
1 ha cambiato i file con 65 aggiunte e 18 eliminazioni
  1. 65
    18
      secondapplet.pde

+ 65
- 18
secondapplet.pde Vedi File

stroke(255); stroke(255);
strokeWeight(1); strokeWeight(1);
line(0, height-120, width, height-120); line(0, height-120, width, height-120);
totalBrickHeight = 0;
totalBrickHeight = 0;
for (int i = 0; i < shaderList.size(); i++) { for (int i = 0; i < shaderList.size(); i++) {
bricks.get(i).update(); bricks.get(i).update();
bricks.get(i).display(); bricks.get(i).display();
} }


class shaderManager { class shaderManager {

void addShader(Shader shader) { void addShader(Shader shader) {
shaderList.add(shader); shaderList.add(shader);
shader.pos = shaderList.size()-1; shader.pos = shaderList.size()-1;
refreshSurface(0); refreshSurface(0);
println("Added " + shader + " to fxList at spot. List length: " + shaderList.size()); println("Added " + shader + " to fxList at spot. List length: " + shaderList.size());
} }

void swapShader(int pos1, int pos2) { void swapShader(int pos1, int pos2) {
if (pos1 >= 0 && pos2 < shaderList.size()) {
Collections.swap(shaderList, pos1, pos2);
Collections.swap(bricks, pos1, pos2);
shaderList.get(pos1).pos = pos1;
shaderList.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();
}
//if (pos1 >= 0 && pos2 < shaderList.size()) {
Collections.swap(shaderList, pos1, pos2);
Collections.swap(bricks, pos1, pos2);
shaderList.get(pos1).pos = pos1;
shaderList.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 moveShader(int pos1, int pos2) {
Shader s = shaderList.remove(pos1);
Brick b = bricks.remove(pos1);

shaderList.add(pos2, s);
bricks.add(pos2, b);
for (int i = 0; i < bricks.size(); i++) {
bricks.get(i).updateSliderPos();
} }
} }


shaderList.remove(pos); shaderList.remove(pos);
bricks.remove(pos); bricks.remove(pos);
for (int i = shaderList.size()-1; i > -1; i--) { for (int i = shaderList.size()-1; i > -1; i--) {
//bricks.get(i).pos = i;
bricks.get(i).setPos(i); bricks.get(i).setPos(i);
bricks.get(i).updateSliderPos();
shaderList.get(i).pos = i; shaderList.get(i).pos = i;
} }
} }
} }
} }
} }

int pressedBrick = -1; int pressedBrick = -1;
class Brick { class Brick {
ArrayList<Slider> slider = new ArrayList<Slider>(); ArrayList<Slider> slider = new ArrayList<Slider>();
ArrayList<Param> params = new ArrayList<Param>(); ArrayList<Param> params = new ArrayList<Param>();
boolean dragging, dragHovering, hovering;
boolean dragging, dragHovering, hovering, hoveringLineAbove, hoveringLineBelow;
color brickBGcol; color brickBGcol;
int pos; int pos;
int h, y; int h, y;
sliderHover = true; sliderHover = true;
} }


if (mouseY > totalBrickHeight && mouseY < totalBrickHeight+h && !sliderHover) {
hovering = true;
if (mouseY > y-5 && mouseY < y+5 && pressedBrick != -1) {
hoveringLineAbove = true;
} else if (pos == bricks.size()-1 && mouseY > y+h-5 && mouseY < y+h+5 && pressedBrick != -1) {
hoveringLineBelow = true;
} else { } else {
hovering = false;
hoveringLineBelow = false;
hoveringLineAbove = false;
if (mouseY > totalBrickHeight && mouseY < totalBrickHeight+h && !sliderHover) {
hovering = true;
} else {
hovering = false;
}
} }


for (int i = 0; i < slider.size(); i++) { for (int i = 0; i < slider.size(); i++) {
void display() { void display() {
noStroke(); noStroke();
if (dragging) brickBGcol = color(51, 51, 51); if (dragging) brickBGcol = color(51, 51, 51);
else if (dragHovering) brickBGcol= color (105, 105, 105);
else if (dragHovering && !hoveringLineBelow && !hoveringLineAbove) brickBGcol= color (105, 105, 105);
else brickBGcol = color(85, 85, 85); else brickBGcol = color(85, 85, 85);
fill(brickBGcol); fill(brickBGcol);
rect(0, totalBrickHeight, width, h); rect(0, totalBrickHeight, width, h);
stroke(150); stroke(150);
strokeWeight(1); strokeWeight(1);
line(0, totalBrickHeight+h-1, width, totalBrickHeight+h-1); line(0, totalBrickHeight+h-1, width, totalBrickHeight+h-1);
if(hoveringLineAbove){
stroke(200);
strokeWeight(5);
line(0,y,width,y);
}
if(hoveringLineBelow){
stroke(200);
strokeWeight(5);
line(0,y+h,width,y+h);
}
} }
} }


void mouseReleased() { void mouseReleased() {
if (pressedBrick != -1) { if (pressedBrick != -1) {
bricks.get(pressedBrick).dragging = false; bricks.get(pressedBrick).dragging = false;
for (int i = 0; i < bricks.size(); i++) { for (int i = 0; i < bricks.size(); i++) {
bricks.get(i).dragHovering = false; bricks.get(i).dragHovering = false;
if (pressedBrick != i && bricks.get(i).hovering) {
if (pressedBrick != i && bricks.get(i).hovering && !bricks.get(i).hoveringLineAbove && !bricks.get(i).hoveringLineBelow) {
shaderManager.swapShader(pressedBrick, i); shaderManager.swapShader(pressedBrick, i);
} }
if(pressedBrick != i && bricks.get(i).hoveringLineAbove){
shaderManager.moveShader(pressedBrick,i);
}
if(pressedBrick != i && bricks.get(i).hoveringLineBelow){
shaderManager.moveShader(pressedBrick,bricks.size()-1); //move to last
}
} }
if (mouseX > binX && mouseX < binX+binS && mouseY > binY && mouseY < binY+binS) { if (mouseX > binX && mouseX < binX+binS && mouseY > binY && mouseY < binY+binS) {
println("removing"); println("removing");
shaderManager.removeShader(pressedBrick); shaderManager.removeShader(pressedBrick);

Loading…
Annulla
Salva