123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- import drop.*;
-
- SDrop drop;
- Bounder bounder;
- int imageNo = 0;
- int imageAmount;
-
- ArrayList<Cover> covers = new ArrayList<Cover>();
-
- String[] imagePaths;
- PImage[] images;
- PImage imageThumb;
- boolean imageLoaded;
- String folderURI;
- PShape COVER;
- void setup() {
- size(240, 100);
- frameRate(30);
- noSmooth();
- COVER = createShape();
- drop = new SDrop(this);
- surface.setResizable(true);
- bounder = new Bounder();
- noLoop();
- }
-
- void draw() {
- background(255);
- fill(0);
- text("Drop image folder here", 52, 53, 20);
-
- if (imageLoaded) {
- if (images[imageNo] != null) {
- image(imageThumb, 0, 0, width, height);
- }
- }
-
- for (int i = 0; i < covers.size(); i++) {
- Cover c = covers.get(i);
- shape(c.coverRect);
- }
-
- 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);
- }
- }
- redraw();
- }
-
- void mousePressed() {
- bounder.click();
- }
-
- void setImage(int i) {
- images[i] = loadImage(imagePaths[i]);
- imageThumb = images[i].get();
- imageThumb.resize(images[i].width/7, images[i].height/7);
- imageLoaded = true;
- redraw();
- }
-
- 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);
- for (int i = covers.size(); i-- != 0; covers.remove(i));
- 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];
- if (imageNo++ <= imageAmount) imageNo++; //open on page 2
- setImage(imageNo);
- surface.setSize(displayWidth, displayHeight);
- }
- }
- }
|