SinDot[] sins = new SinDot[7]; 
int selectedStart = -1, selectedEnd = -1;

HashMap combos = new HashMap();

void setup() {
  size(200,200);
 
  textFont(loadFont("ArialNarrow-Bold-20.vlw"));
   textAlign(CENTER);
   
   int mycenter = 100;

  sins[0] = new SinDot("A","Lust",mycenter-30,20,true);
  sins[1] = new SinDot("B","Gluttony",mycenter+30,20,true);
  sins[2] = new SinDot("C","Greed",mycenter+60,60,true);
  sins[3] = new SinDot("D","Sloth",mycenter+50,100,false);
  sins[4] = new SinDot("E","Wrath",mycenter,120,false);
  sins[5] = new SinDot("F","Envy",mycenter-50,100,false);
  sins[6] = new SinDot("G","Pride",mycenter-60,60,true);

  combos.put("AB","Edible Undies");
  combos.put("AC","Prostitution");
  combos.put("AD","Quickie");
  combos.put("AE","Domestic Abuse");
  combos.put("AF","Adultery");
  combos.put("AG","Trophy Wife");
  combos.put("BC","Last Donut");
  combos.put("BD","Saturday");
  combos.put("BE","Bulimia");
  combos.put("BF","High Metabolism");
  combos.put("BG","Fat Men in Speedos");
  combos.put("CD","Get Rich Quick Scams");
  combos.put("CE","Muggings");
  combos.put("CF","Advertising");
  combos.put("CG","Status Symbols");
  combos.put("DE","Passive Aggression");
  combos.put("DF","Welfare");
  combos.put("DG","Slackers");
  combos.put("EF","Cattiness");
  combos.put("EG","Boxing");
  combos.put("FG","2nd Place");

}

void draw() { 


  background(#CCCCCC);
strokeWeight(1);
  stroke(#000000);
  for(int i = 0; i < 7; i++){
    for(int j = i+1; j < 7; j++){
      sins[i].lineTo(sins[j]);
    }
  }
  stroke(#CC3333);
strokeWeight(2);
  drawSelectedLine();
  
  int mouseIsOver = getIndexOfSin(mouseX,mouseY);
  
  for(int i = 0; i < 7; i++){
  if(i != selectedStart && i != selectedEnd && i != mouseIsOver){
    sins[i].drawNormal(); 
  } else {
     sins[i].drawPicked(); 
  }
  }  

  if(selectedStart != -1 && selectedEnd != -1){
    showCombo();
  }  

} 


void showCombo(){
  if(selectedStart == selectedEnd) return; //no doubled sins
  String first = sins[selectedStart].getLabel();
  String last  = sins[selectedEnd].getLabel();
  
  if(first.compareTo(last) > 0){
   first = sins[selectedEnd].getLabel();
   last  = sins[selectedStart].getLabel();     
  }

  String val = (String)combos.get(first + last);
  if(val != null) {
  fill(#CC3333);
    text(val,100,170);
  }  
  
  
}



void mousePressed(){
    int clicked = getIndexOfSin(mouseX,mouseY);
    
    if(clicked == -1) {
       selectedStart = -1; 
    }
    
  if(selectedStart == -1){
    selectedStart = clicked;
    selectedEnd = -1;
  } else {
    if(selectedEnd == -1) {
      selectedEnd = clicked;
    } else {
       selectedStart = clicked;
      selectedEnd = -1; 
    }
   
  }
}

void mouseMoved(){
    int clicked = getIndexOfSin(mouseX,mouseY);
  if(  -1  != clicked){
   cursor(HAND); 


} else {
  cursor(ARROW);
}
  
}

void mouseDragged(){
  int clicked = getIndexOfSin(mouseX,mouseY);

  selectedEnd = clicked;
  
 
}

void drawSelectedLine(){
  if(selectedStart != -1){
        if(selectedEnd == -1){

           line(sins[selectedStart].getX(), 
               sins[selectedStart].getY(),
               mouseX,
               mouseY);

        } else {

           line(sins[selectedStart].getX(), 
               sins[selectedStart].getY(),
sins[selectedEnd].getX(), 
               sins[selectedEnd].getY());

        }  
  }  
}


int getIndexOfSin(float x, float y){
   for(int i = 0 ; i < 7; i++){
      if(sins[i].inBox(x,y) ){
      return i;
      }
   } 
    return -1;
}



class SinDot {
  float xpos, ypos;
  String label, caption;
  boolean above;
  static final int TEXTHEIGHT = 16;
  float boxleft, boxright,boxtop,boxbottom;


  SinDot(String newLabel,String newCaption,

  //constructor records basic params and also 
  //computes bounding box coordinates
  float newXpos,float newYpos, boolean newAbove){
    label = newLabel;
    caption = newCaption;
    xpos = newXpos;
    ypos = newYpos; 
    above = newAbove;
    float boxwidth = textWidth(caption);
    boxleft = xpos - (boxwidth)/2;
    boxright = xpos + (boxwidth)/2;
    if(above){
      boxtop = ypos - TEXTHEIGHT; 
      boxbottom = ypos;
    } 
    else {
      boxtop = ypos;
      boxbottom = ypos + TEXTHEIGHT; 
    }

  }
  
  boolean inBox(float x, float y){
     return (   x >= boxleft && x  <= boxright && y >= boxtop && y <= boxbottom);
  }
  
  
  //for now just punt, if "below" add in a constant value
  void drawNormal(){
  fill(color(#000000));
      text(caption, xpos,boxtop+TEXTHEIGHT);
 // drawBox();
  }
  void drawPicked(){
  fill(color(#CC3333));
      text(caption, xpos,boxtop+TEXTHEIGHT);
  //drawBox();
  }
  
  void drawBox(){
    line(boxleft,boxtop,boxright,boxtop);
    line(boxright,boxtop,boxright,boxbottom);
    line(boxright,boxbottom,boxleft,boxbottom);
    line(boxleft,boxbottom,boxleft,boxtop);
 
  }

  float getX(){
    return xpos;
  }
  float getY(){
    return ypos; 
  }
  String getCaption(){
     return caption; 
  }
  String getLabel(){
     return label; 
  }

  void lineTo(SinDot target){
    line(xpos,ypos,target.getX(),target.getY()); 
  }

}