// all the mouse and kbd handling stuff boolean drag_comp = false; int drag_comp_mousex = 0; boolean drag_frame = false; int drag_frame_mousex = 0; void keyPressed(){ if (keyCode == RIGHT){ if (comp_focus == 1){ // nudge the composite theframe = constrain(theframe+1,0,numframes-1); loadFrame(); } else if (frame_focus == 1){ // nudge the frame thecomposite = constrain(thecomposite+1,0,numslices-1); loadComposite(); } updateRects(); } else if (keyCode == LEFT){ if (comp_focus == 1){ // nudge the composite theframe = constrain(theframe-1,0,numframes-1); loadFrame(); } else if (frame_focus == 1){ // nudge the frame thecomposite = constrain(thecomposite-1,0,numslices-1); loadComposite(); } updateRects(); } } void mousePressed(){ if (inRect(mouseX,mouseY,compRect)){ // mouse pressed in the composite crop drag_comp = true; drag_comp_mousex = mouseX; } // else if (inRect(mouseX,mouseY,(width*0.5)-(frame_width*0.5),ymargin+composite_height+midspace,frame_width,frame_height)){ else if (inRect(mouseX,mouseY,frameRect)){ drag_frame = true; drag_frame_mousex = mouseX; } } void mouseDragged(){ if (drag_comp){ theframe = constrain(theframe-(mouseX-drag_comp_mousex),0,numframes-1); drag_comp_mousex = mouseX; } else if (drag_frame){ thecomposite = constrain(thecomposite-(mouseX-drag_frame_mousex),0,numslices-1); drag_frame_mousex = mouseX; } updateRects(); } void mouseMoved(){ if (inRect(mouseX,mouseY,compRect)) comp_focus = 1; // switch focus else if (inRect(mouseX,mouseY,frameRect)) frame_focus = 1; else { comp_focus = 0; frame_focus = 0; } } void mouseReleased(){ if (drag_comp){ loadFrame(); drag_comp = false; } else if (drag_frame){ loadComposite(); drag_frame = false; } } // rects stuff here boolean inRect(float x_in, float y_in, Rect testRect){ boolean hit = false; if ((x_in > testRect.rx) && (y_in > testRect.ry) && (x_in < (testRect.rx+testRect.rwidth)) && (y_in < (testRect.ry+testRect.rheight))){ hit = true; } return hit; } void updateRects(){ compRect.rx = (width*0.5)-(theframe);//constrain((width*0.5)-(theframe*0.5),-10,240); compRect.rwidth = composite_width; //720;//constrain(min(240+(theframe*0.5),240+((numframes-theframe)*0.5)),240,720); frameRect.rx = (width*0.5)-(thecomposite); } class Rect{ float rx; float ry; float rwidth; float rheight; Rect(float _x, float _y, float _w, float _h){ rx = _x; ry = _y; rwidth = _w; rheight = _h; } }