/*! * Photo Viewer. * created by visionline@gmail.com */ // required if using OPENGL //import processing.opengl.*; // Holds the set of images RotatableImage images[]; // List of integer, index into images, used to sort ArrayList order; // The selected image, index into images int active; // prefered icon for rotation. PImage rotateIcon; PImage resizeIcon; // Required setup function, called once. void setup( ) { //size(1000, 650, OPENGL); //size(1000, 650, P2D); size(800, 600); frameRate(30 ); imageMode( CENTER ); rectMode( CENTER ); // Java doesn't come with a good "rotate this" icon. rotateIcon = loadImage( "rotate.png"); resizeIcon = loadImage( "resize.png"); images = new RotatableImage[0]; order = new ArrayList(); // use your own list of images, one file or url per line. //String lines[] = loadStrings("images.txt"); String lines[] = loadStrings("http://www.HakanDances.com/images.txt"); for( int i = 0; i < lines.length; i++) { images = (RotatableImage[])append( images, new RotatableImage( lines[i])); order.add( i ); } active = -1; } // very simple draw loop. // iterate through "order", call that image's draw fn. void draw( ) { background( 255 ); for( int i = 0; i < order.size(); i++) { int offset = ((Integer) order.get( i )).intValue(); images[offset].draw( ); } } // process the 'r' key, used to randomize void keyPressed( ) { if( key == 'r' || key == 'R') { for( int i = 0; i < images.length; i++) { images[i].setRandom(); } } } // find out if the cursor is above an image. // the last image in the set has the highest // priority void mouseMoved( ) { boolean found = false; int select = -1; int orderSelect = -1; for( int i = order.size()-1; i > -1; i--) { int offset = ((Integer) order.get( i )).intValue(); if( !found ) { if( images[offset].mouseMoved( )) { found = true; select = offset; orderSelect = i; } } else { images[offset].cursorInside = false; } } if( !found) cursor( ARROW ); } // same as mouse move, but also set "active" void mousePressed( ) { boolean found = false; int select = -1; int orderSelect = -1; for( int i = order.size()-1; i > -1; i--) { int offset = ((Integer) order.get( i )).intValue(); if( !found ) { if( images[offset].mousePressed( )) { found = true; select = offset; orderSelect = i; } } else { images[offset].cursorInside = false; } } if( found ) { order.remove( orderSelect); order.add( select ); active = select; } } void mouseReleased( ) { active = -1; } void mouseDragged( ) { if( active > -1) { images[active].mouseDragged( ); } }