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.
IndexProgramming Questions & HelpSyntax Questions › Making hyperlinks
Page Index Toggle Pages: 1
Making hyperlinks (Read 1065 times)
Making hyperlinks
Mar 28th, 2007, 12:03am
 
Hello all!

Kinda new to processing, but like it a lot. I was just wondering, is it possible to make a rectangle a hyperlink to take you to an image?

If you can, could someone show me the code or help me how to do it.

Thanks.
Re: Making hyperlinks
Reply #1 - Mar 28th, 2007, 12:14am
 
Hi AdamB-

This might be the -- uh -- link you're looking for:

 http://processing.org/reference/link_.html

-Matt
Re: Making hyperlinks
Reply #2 - Mar 28th, 2007, 12:41am
 
you'd have to check the mouse position relative to the rectangle.

if you want an 'easy' way to make a button, try the springGUI or myGUI in the interface library.

Re: Making hyperlinks
Reply #3 - Mar 28th, 2007, 1:23am
 
Ah... good point.  In my rush to make a terrible pun I missed the fact that the rectangle in the sample code isn't really a button.

I also recommend checking out the interface library if you want to make some nicer buttons.  If you just want something quick and dirty, you can look at the "button" example here:

 http://processing.org/learning/examples/button.html

Mix that (or the GUIs from the interface library) with a properly-placed call to link() and you're in business.
Re: Making hyperlinks
Reply #4 - Mar 28th, 2007, 2:02pm
 
ok great thank-you both. Il try them out.
Re: Making hyperlinks
Reply #5 - Nov 7th, 2007, 7:42pm
 
When I use link(), it launches the browser page six times per click. Is there a way to launch the URL only once without killing the draw loop?

If it helps, here is the relevant methods (animate() is called in the draw loop):


void animate(int turn){
 //println(turn);

 // color according to hex list
 noStroke();
 color t = color(color_array[turn]);
 fill(t);

 // draw ball according to bag weight
 ellipse(b[turn].b_xpos, b[turn].b_ypos, b[turn].b_weight, b[turn].b_weight);

 // write folder number on ball
 if (mouseOver(turn) == true){
   stroke(100,100,100);
   fill(100,100,100);
   text(turn, b[turn].b_xpos, b[turn].b_ypos);
   b[turn].b_xpos = b[turn].b_xpos + 0.1*(vel(turn));  // slow it down to make it readable
   b[turn].b_ypos = b[turn].b_ypos + 0.1*(vel(turn));
   if (mousePressed){
     if(mouseButton == LEFT){
       b[turn].b_vx = random(-2,2);
       b[turn].b_vy = random(-2,2);
     }
     if(mouseButton == RIGHT){
       link(makeURL(turn));
     //  noLoop(); // kills the whole draw loop Sad
     }

   }

 }

 else {
   b[turn].b_xpos = b[turn].b_xpos + b[turn].b_vx; // move the ball normally
   b[turn].b_ypos = b[turn].b_ypos + b[turn].b_vy;
 }

 // bounce balls off walls
 if (b[turn].b_ypos > height-(b[turn].b_weight/2) || b[turn].b_ypos < 0 + b[turn].b_weight/2){
   b[turn].b_vy = b[turn].b_vy*(-1.0);
 }
 if (b[turn].b_xpos > width- (b[turn].b_weight/2) || b[turn].b_xpos < 0 + (b[turn].b_weight/2)){
   b[turn].b_vx = b[turn].b_vx*(-1.0);
 }



}

// looks for the mouse at each ball
boolean mouseOver(int turn){
 if (mouseX >= b[turn].b_xpos - b[turn].b_weight/2 && mouseX <= b[turn].b_xpos + b[turn].b_weight/2 &&
   mouseY >= (b[turn].b_ypos - b[turn].b_weight/2) && mouseY <= (b[turn].b_ypos + b[turn].b_weight/2)){
   return true;
 }
 else return false;

}
Re: Making hyperlinks
Reply #6 - Nov 7th, 2007, 8:00pm
 
Use the mousePressed function and a boolean, e.g.

Code:
boolean rightClicked=false;

//...

void mousePressed()
{
if(mouseButton==RIGHT)
{
rightClicked=true;
}
}

void mouseReleased()
{
if(mouseButton==RIGHT)
{
rightClicked=false;
}
}


And then, when you check to see if the right mouse button is pressed in your animate function, check "rightClicked" and then set it to false, that way it'll not register another click until the button is released and pressed again.
Re: Making hyperlinks
Reply #7 - Nov 7th, 2007, 8:27pm
 
I tried this... as well as using mouseReleased() (removing mousePressed entirely)... still no dice.

void mouseReleased(int i){
 boolean openPage = false;
  if(mouseButton == LEFT){
       b[i].b_vx = random(-2,2);
       b[i].b_vy = random(-2,2);
     }
     if(mouseButton == RIGHT){
       openPage = true;
       link(makeURL(i), "_blank");
       openPage = false;
     }

}
Page Index Toggle Pages: 1