106 lines
2.4 KiB
Plaintext
106 lines
2.4 KiB
Plaintext
import drop.*;
|
|
|
|
SDrop drop;
|
|
Bounder bounder;
|
|
int imageNo = 0;
|
|
int imageAmount;
|
|
String[] imagePaths;
|
|
PImage[] images;
|
|
PImage imageThumb;
|
|
boolean imageLoaded;
|
|
String folderURI;
|
|
|
|
void setup() {
|
|
size(240, 100);
|
|
frameRate(30);
|
|
noSmooth();
|
|
drop = new SDrop(this);
|
|
surface.setResizable(true);
|
|
bounder = new Bounder();
|
|
}
|
|
|
|
void draw() {
|
|
background(255);
|
|
fill(0);
|
|
text("Drop image folder here", 52, 53, 20);
|
|
|
|
if (imageLoaded) {
|
|
if (images[imageNo] != null) {
|
|
// image(images[imageNo], 0, 0, width, height);
|
|
image(imageThumb, 0, 0, width, height);
|
|
}
|
|
}
|
|
|
|
bounder.update();
|
|
bounder.display();
|
|
}
|
|
|
|
void keyPressed() {
|
|
if (key == ENTER) {
|
|
if (bounder.state >= 3) {
|
|
println("Compiling images");
|
|
bounder.compile(true);
|
|
println("Compiling finished, reset bounder");
|
|
//bounder.state = 0;
|
|
}
|
|
}
|
|
if (key == ' ') {
|
|
if(bounder.state == 3) bounder.compile(false);
|
|
bounder.state = 0;
|
|
println("Bounder reset");
|
|
}
|
|
if (key == CODED) {
|
|
if (keyCode == RIGHT) {
|
|
imageNo++;
|
|
if (imageNo > imageAmount) imageNo = imageAmount;
|
|
else setImage(imageNo);
|
|
println(imageNo);
|
|
} else if (keyCode == LEFT) {
|
|
imageNo--;
|
|
if (imageNo < 0) imageNo = 0;
|
|
else setImage(imageNo);
|
|
|
|
println(imageNo);
|
|
}
|
|
}
|
|
}
|
|
|
|
void mousePressed() {
|
|
bounder.click();
|
|
}
|
|
|
|
void setImage(int i) {
|
|
images[i] = loadImage(imagePaths[imageNo]);
|
|
imageThumb = images[i].get();
|
|
imageThumb.resize(images[i].width/7, images[i].height/7);
|
|
imageLoaded = true;
|
|
}
|
|
|
|
void dropEvent(DropEvent theDropEvent) {
|
|
|
|
if (theDropEvent.isFile()) {
|
|
File myFile = theDropEvent.file();
|
|
if (myFile.isDirectory()) {
|
|
File[] droppedFiles = myFile.listFiles();
|
|
println(droppedFiles);
|
|
folderURI = droppedFiles[0].getParent();
|
|
println(folderURI);
|
|
|
|
ArrayList<String> imgs = new ArrayList<String>();
|
|
imageAmount = 0;
|
|
for (int i = 0; i < droppedFiles.length; i++) {
|
|
String fn = droppedFiles[i].toString().toLowerCase();
|
|
if(fn.endsWith(".jpg") || fn.endsWith(".jpeg") || fn.endsWith(".bmp") || fn.endsWith(".png") || fn.endsWith(".gif"))
|
|
imgs.add(droppedFiles[i].toString());
|
|
}
|
|
imageAmount = imgs.size();
|
|
imagePaths = new String[imageAmount];
|
|
imagePaths = imgs.toArray(imagePaths);
|
|
imagePaths = sort(imagePaths);
|
|
images = new PImage[imageAmount];
|
|
setImage(imageNo);
|
|
|
|
}
|
|
}
|
|
}
|