String[] toolNames = {"hammer", "schleifer", "spray"}; boolean[] toolDrag = {false, true, true}; String[] imgNames = {"fruh", "fruh2", "bahn", "auto", "holz"}; int[] toolOffsetX = {-1,16, -60}; int[] toolOffsetY = {-2,-47, -60}; int[] toolImageOffsetX = {-30,-120, -140}; int[] toolImageOffsetY = {-147,-157, -150}; int imageOffsetX = 100; int imageOffsetY = 30; PImage[][] toolImages = new PImage[toolNames.length][4]; // syntax: toolImages[tool_id][image_id] PImage[][] toolMasks = new PImage[toolNames.length][4]; PImage[] toolThumbs = new PImage[toolNames.length]; PImage[] img = new PImage[imgNames.length]; PImage cursorImg, cursorMask; int activeImg = 0; int activeTool = 0; int toolInAction = 0; int menuHeight = 120; int iconPosY = 600; int iconSize = 100; int menuGap = 15; int iconsPosX; int cursorOpacity = 0; void setup() { noCursor(); noStroke(); size(700, 600+menuHeight); cursorImg = loadImage("cursorimages/cursor.jpg"); cursorMask = loadImage("cursorimages/cursormask.jpg"); cursorImg.mask(cursorMask); // store 4 images per tool in toolImages[][] for(int j=0; j < toolNames.length; j++) { for(int i=0; i < 4; i++) { toolImages[j][i] = loadImage("toolimages/" + toolNames[j] + "/"+toolNames[j] + (i+1) + ".jpg"); toolMasks[j][i] = loadImage("toolimages/" + toolNames[j] + "/"+toolNames[j] + "mask" + (i+1) + ".jpg"); toolImages[j][i].mask(toolMasks[j][i]); } toolThumbs[j] = loadImage("toolimages/" + toolNames[j] + "/"+toolNames[j] + "thumb.jpg"); } loadBackgroundImages(); iconsPosX = (int)((width/2) - ((iconSize+menuGap) * toolNames.length-menuGap)/2); } void draw() { noStroke(); fill(255); rect(0,0,width,height); image(img[activeImg],imageOffsetX,imageOffsetY); if(toolDrag[activeTool] && toolInAction == 1) drawToolTrace(); drawMenu(); if(mouseY > imageOffsetY + img[activeImg].height + 30) cursorOpacity += 15; if(mouseY < imageOffsetY + img[activeImg].height + 30) cursorOpacity -= 15; if(cursorOpacity < 0) cursorOpacity = 0; if(cursorOpacity > 255) cursorOpacity = 255; tint(255,255-cursorOpacity); image(toolImages[activeTool][3*toolInAction],mouseX + toolImageOffsetX[activeTool], mouseY + toolImageOffsetY[activeTool]); // displays image 0 if toolInAction == 0 (mousebutton not pressed) or image 3 if toolInAction == 1 (mousebutton pressed) tint(255,cursorOpacity); image(cursorImg, mouseX - 7, mouseY - 5); // displays image 0 if toolInAction == 0 (mousebutton not pressed) or image 3 if toolInAction == 1 (mousebutton pressed) noTint(); } void loadBackgroundImages() { // store backgroundimages in img[] for(int j=0; j < imgNames.length; j++) img[j] = loadImage("backgroundimages/" + imgNames[j] + ".jpg"); } void drawMenu() { for(int i=0; i < toolNames.length; i++) { image(toolThumbs[i], iconsPosX + i*(iconSize+menuGap), iconPosY, iconSize, iconSize); stroke(200); if(i == activeTool) stroke(200,0,0); if(mouseX >= iconsPosX + i*(iconSize+menuGap) && mouseX < iconsPosX + i*(iconSize+menuGap) + iconSize && mouseY >= iconPosY && mouseY < iconPosY+iconSize && i != activeTool) stroke(0); noFill(); rect(iconsPosX + i*(iconSize+menuGap), iconPosY, iconSize, iconSize); } } void menuAction() { for(int i=0; i= iconsPosX + i*(iconSize+menuGap) && mouseX < iconsPosX + i*(iconSize+menuGap) + iconSize && mouseY >= iconPosY && mouseY < iconPosY+iconSize && i != activeTool) activeTool = i; } void mousePressed() { moveTool(1); drawToolTrace(); menuAction(); } void mouseReleased() { moveTool(0); } void moveTool(int type) { // display images 2 to 4 if type == 1 or images 3 to 1 if type == 0 if(cursorOpacity < 100) for(int i = 0; i < 3; i++) { noStroke(); fill(255); rect(0,0,width,height); image(img[activeImg],imageOffsetX,imageOffsetY); drawMenu(); image(toolImages[activeTool][(2-i)*(1-type)+(i+1)*type],mouseX+toolImageOffsetX[activeTool],mouseY+toolImageOffsetY[activeTool]); } toolInAction = type; } void drawToolTrace() { try { getClass().getMethod(toolNames[activeTool],null).invoke(this,null); } catch(Exception e) { println(e); } } void editPixels(int x, int y, color col) { if(x >= 0 && y >= 0 && x < img[activeImg].width && y < img[activeImg].height) { img[activeImg].loadPixels(); img[activeImg].pixels[img[activeImg].width*y+x] = col; img[activeImg].updatePixels(); } } color getPixels(int x, int y) { if(x >= 0 && y >= 0 && x < img[activeImg].width && y < img[activeImg].height) { img[activeImg].loadPixels(); return img[activeImg].pixels[img[activeImg].width*y+x]; } else return color(0); }