1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
//global variables PImage currentBk, bk; int w, h; int k; float rx,ry; ArrayList ibuttons; // arraylist for the 3 buttons which change the background plan ArrayList sbuttons; // arraylist for the furnitures PFont font; BrushButton selectedBrush = null; ArrayList furnitures = new ArrayList(); int findex = -1; void setup(){ frameRate(150); size(800,600); bk = loadImage("pojectf_empty.png"); // this is my interface image //Arraylist for the plan buttons ibuttons = new ArrayList(); ibuttons.add(new ImageButton("plan_1.png", 51, 549, "image_1_released.png", "image_1_hit.png")); ibuttons.add(new ImageButton("plan_2.png", 161, 549, "image_2_released.png", "image_2_hit.png")); ibuttons.add(new ImageButton("plan_3.png", 271, 549, "image_3_released.png", "image_3_hit.png")); ImageButton bkB = ((ImageButton)ibuttons.get(0)); currentBk = bkB.getBKImage(); bkB.isSelected = true; w = currentBk.width; h = currentBk.height; //Arraylist for the furniture buttons sbuttons = new ArrayList(); sbuttons.add(new BrushButton(606, 47, "stove.png", "stove_Hit.png")); sbuttons.add(new BrushButton(679, 48, "Refrigerator.png", "Refrigerator_Hit.png")); sbuttons.add(new BrushButton(580, 162, "Bed_king.png", "Bed_king_Hit.png")); sbuttons.add(new BrushButton(653, 161, "Bed_single.png", "Bed_single_Hit.png")); sbuttons.add(new BrushButton(695, 159, "NightStand_001.png", "NightStand_001_Hit.png")); sbuttons.add(new BrushButton(696, 199, "NightStand_002.png", "NightStand_002_Hit.png")); sbuttons.add(new BrushButton(584, 235, "Desk.png", "Desk_Hit.png")); sbuttons.add(new BrushButton(639, 237, "Deresser.png", "Deresser_Hit.png")); sbuttons.add(new BrushButton(697, 238, "Table_001.png", "Table_001_Hit.png")); sbuttons.add(new BrushButton(585, 308, "Couch_001.png", "Couch_001_Hit.png")); sbuttons.add(new BrushButton(654, 309, "Couch_002.png", "Couch_002_Hit.png")); sbuttons.add(new BrushButton(584, 348, "Couch_003.png", "Couch_003_Hit.png")); sbuttons.add(new BrushButton(650, 349, "Couch_004.png", "Couch_004_Hit.png")); sbuttons.add(new BrushButton(597, 401, "Sofa_001.png", "Sofa_001_Hit.png")); sbuttons.add(new BrushButton(641, 404, "Sofa_003.png", "Sofa_003_Hit.png")); sbuttons.add(new BrushButton(691, 405, "Sofa_002.png", "Sofa_002_Hit.png")); sbuttons.add(new BrushButton(585, 455, "Dining_table.png", "Dining_table_Hit.png")); sbuttons.add(new BrushButton(690, 462, "Plant.png", "Plant_Hit.png")); sbuttons.add(new BrushButton(603, 523, "Table_002.png", "Table_002_Hit.png")); sbuttons.add(new BrushButton(692, 500, "Chair_001.png", "Chair_001_Hit.png")); sbuttons.add(new BrushButton(654, 541, "TV.png", "TV_Hit.png")); ((BrushButton)sbuttons.get(0)).isSelected = true; drawBackground(); } void drawPanelBackground(){ fill(0); doDisplay(sbuttons); } void drawBackground(){ background(bk); doDisplay(ibuttons); drawPanelBackground(); image(currentBk, 50, 30); } // a method which says whenever the mouse is over the buttons the cursor shape changes to hand void doMouseOver(ArrayList buttons){ for (int i = 0; i < buttons.size(); i++){ if (((BrushButton)buttons.get(i)).isOver()){ cursor(HAND); } } } void doDisplay(ArrayList buttons){ for (int i = 0; i < buttons.size(); i++){ ((BrushButton)buttons.get(i)).display(); } } void draw() { if (selectedBrush != null){ drawBackground(); if (isOnPlan()){ selectedBrush.display(mouseX, mouseY); } } cursor(ARROW); doMouseOver(ibuttons); doMouseOver(sbuttons); for (int i = 0; i < furnitures.size(); i++){ ((BrushButton)furnitures.get(i)).display(); } } boolean isOnPlan(){ return (mouseX > 50 && mouseX < 510 && mouseY > 30 && mouseY < 525); // the area in which the furniture will be shown when they are selected } void keyPressed() { println("key: "+keyCode); if (keyCode == 127 && findex > -1 && findex < furnitures.size()){ println("Index: "+findex); furnitures.remove(findex); findex = -1; drawBackground(); } if ( selectedBrush != null){ if( key == '+') { selectedBrush.rotation += 90; //hitting the + key will rotate the furniture 90 degrees clockwise } else if (key == '-'){ selectedBrush.rotation -= 90; //hitting the + key will rotate the furniture 90 degrees counter clockwise } } } // a method to define whenever the mouse clicked on the buttons another image for that button will load ( image for showing the button is clicked) void mouseClicked(){ boolean isDone = false; for (int i = 0; !isDone && i < ibuttons.size(); i++){ ImageButton bb = (ImageButton)ibuttons.get(i); if (bb.isOver()){ isDone = true; currentBk = bb.getBKImage(); for(int j = 0; j < ibuttons.size(); j++){ ImageButton bbb = (ImageButton)ibuttons.get(j); if (j != i){ bbb.isSelected = false; } } bb.isSelected = true; drawBackground(); furnitures.clear(); findex = -1; } } for (int i = 0; selectedBrush == null && !isDone && i < furnitures.size(); i++){ BrushButton bb = (BrushButton)furnitures.get(i); if (bb.isOver()){ isDone = true; for(int j = 0; j < furnitures.size(); j++){ BrushButton bbb = (BrushButton)furnitures.get(j); if (j != i && bbb.isSelected){ bbb.isSelected = false; bbb.display(); } } bb.isSelected = true; findex = i; bb.display(); } } if (isOnPlan() && selectedBrush != null){ furnitures.add(new BrushButton(mouseX, mouseY, selectedBrush.bButton, selectedBrush.hButton, selectedBrush.rotation)); } for (int i = 0; !isDone && i < sbuttons.size(); i++){ BrushButton bb = (BrushButton)sbuttons.get(i); if (bb.isOver()){ isDone = true; for(int j = 0; j < sbuttons.size(); j++){ BrushButton bbb = (BrushButton)sbuttons.get(j); if (j != i && bbb.isSelected){ bbb.isSelected = false; bbb.display(); } } bb.isSelected = !bb.isSelected; if (bb.isSelected){ selectedBrush = new BrushButton(bb.x, bb.y, bb.hButton, bb.bButton, bb.rotation); }else{ if (selectedBrush != null){ drawBackground(); selectedBrush = null; } } bb.display(); } } } // image buttons are subclasses from the brush buttons class ImageButton extends BrushButton{ PImage bkImage; ImageButton(String bkfilename, int x, int y, String bfilename, String hfilename){ super(x, y, bfilename, hfilename); bkImage = loadImage(bkfilename); } PImage getBKImage(){ return bkImage; } } class BrushButton{ PImage bButton, hButton; int x, y; boolean isSelected = false; int rotation = 0; BrushButton(int x, int y, String bfilename, String hfilename){ this.x = x; this.y = y; bButton = loadImage(bfilename); hButton = loadImage(hfilename); } BrushButton(int x, int y, PImage bButton, PImage hButton, int rot){ this.x = x; this.y = y; this.bButton = bButton; this.hButton = hButton; rotation = rot; } boolean isOver(){ return (mouseX > x && mouseX < x + bButton.width && mouseY > y && mouseY < y + bButton.height); } void display(){ PImage button = (isSelected)?hButton:bButton; display(button, rotation, x, y); } void display(int nx, int ny){ display(hButton, rotation, nx, ny); } void display(PImage im, int rot, int nx, int ny){ pushMatrix(); translate(nx, ny); rotate(radians(rot)); image(im, 0, 0); popMatrix(); } } |