We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
double click (Read 176 times)
double click
Mar 18th, 2009, 7:14pm
 
so i'm trying to use the double click hack code:
http://processing.org/hacks/hacks:doubleclick

it works fine just like this by itself:
int value = 0;

void setup(){
 size(200,200);
}

void draw(){
 background(0);
 fill(value);
 rect(width/2, height/2, 40,40);
}

void mousePressed(MouseEvent e) {
 if (e.getClickCount()==1) {
   println("<single click>");
   value = 255;
 }  
 else if (e.getClickCount()==2) {
   println("<double click>");
   value = 0;
   link("http://processing.org", "_new");    
 }
}

...but, i'm trying to incorporate it in my code which i don't know how to do:

//Ideally, I would like to use this in my code
//CLICKING FUNCTION
boolean mousePressed(MouseEvent e;) {  
 if (e.getClickCount()==1) { //if mouse is clicked once, display sentence, if clicked again, disappear.
                               //if mouse moves away from dot, do not display & erase any previous clicked display commands
   println("<single click>");
   singleclick = true;
//        textFont(font, 14);    
//        text(sentence, xpos+16, ypos, 200, 350);
//        text(sex, xpos+16, ypos+300, 200, 350);

 }  
 else if (e.getClickCount()==2) { //if mouse is double-clicked, take to url
   println("<double click>");
   doubleclick = true;
//        textFont(font, 14);    
//        text(sentence, xpos+16, ypos, 200, 350);
//        text(sex, xpos+16, ypos+300, 200, 350);
//        link(url, "_new");  
 }
 return true;
 }
 }


I want to place that into this:


String url;
 boolean singleclick = false;
 boolean doubleclick = false;

 
 //UPDATE//////////////////////////////////////////////////////////
 //update the overstate of the dots
 void update(){
   //update when dot is on rollover
   if (over()){
     over = true;
   }
   else{
     over = false;
   }

 if (clicked()){
     singleclick = true;
   }
   else{
     singleclick = false;
   }
   
//NEED SOME KIND OF UPDATE FOR MOUSEPRESSED?
 
 }//end update

 //BOOLEANS//////////////////////////////////////////////////////////

 //test to see if mouse pressed the dot
 boolean clicked() {
   float disX = xpos - mouseX;
   float disY = ypos - mouseY;
   if ((sqrt(sq(disX) + sq(disY)) < sizeDot/2) && (singleclick == true)) {
     singleclick = true;
     return true;
   }else if ((sqrt(sq(disX) + sq(disY)) < sizeDot/2) && (doubleclick == true)){
     doubleclick = true;
     return true;
   }
   else {
     return false;
   }
 }

 // test to see if mouse is over the dot
 boolean over() {
   float disX = xpos - mouseX;
   float disY = ypos - mouseY;
   if (sqrt(sq(disX) + sq(disY)) < sizeDot/2 ) {
     return true;
   }
   else {
     return false;
   }
 }

 //DISPLAY//////////////////////////////////////////////////////////
 //draw the dot and text!
 void display(){    
     fill(dotColor, 180);
     ellipse(xpos, ypos, sizeDot, sizeDot);  
   //display a word!
   if (over){  
        textAlign(LEFT);
        textFont(font, 35);
        text(word, xpos, ypos-10);  
     }    
   }  
    //display the sentence if mouse is pressed!
    //NOT SURE IF THIS IS CORRECT?
     if (clicked){
       if (singleclick == true){
         textFont(font, 14);    
         text(sentence, xpos+16, ypos, 200, 350);
       }
       if (doubleclick == true){
         textFont(font, 14);    
         text(sentence, xpos+16, ypos, 200, 350);
         text(sex, xpos+16, ypos+300, 200, 350);
         link(url, "_new");  
         //<<<<<<<<<<<<<<<<need mousePressed function for 1 click and double click detection.
         // the function would also help prevent multiple tabs of the same post from opening!
       }
     }    
 }//end of display
Page Index Toggle Pages: 1