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 & HelpPrograms › keyboard and mouse : not working coherent
Page Index Toggle Pages: 1
keyboard and mouse : not working coherent (Read 1317 times)
keyboard and mouse : not working coherent
Jul 21st, 2008, 11:56am
 
hello there
i want to draw links (lines) between two objects on screen.
I am doing drag and drop on the objects as well.
so i am using mouseDragged to call a function which depending upon shift key status, sets the root of the line or draws it temprarily or permanantly ....
but the variables shift_count and shift_released do not change their valuse properly i guess (they are being changed in keypressed and used in mouseDragged)...

I remember reading somewhere how the keyboard and mouse functions interact but can't find it.

can someone please help with it

To draw links on screen , press shift key and click on an object , keep key pressed ,drag the mouse to second object and then release the key, then release the mouse.
the link will appear when u click once more on that object


now the bug is
1) if i do not terminate link-drawing on an object , then, it remembers ther earlier root
2) it shows the link when you click on the object again after link drawing. it is not supposed to happen
Re: keyboard and mouse : not working coherent
Reply #1 - Jul 21st, 2008, 12:03pm
 
int terminus;     // weird
int shift_pressed=0;
int shift_count=0;  
int root;
int shift_released=0;
int link_number=0;
int num_l;
 
void setup()
{  
 int num2;
 num_b=0;
 num_f=0;
 num2=0;
 num_i=0;
 num_o=0;
 //stroke(153);
 size(1024,768,P3D);
 font = loadFont("Centaur-48.vlw"); // PT 2
 textAlign(LEFT,TOP);  
 strokeWeight(1/20);
 font_size=35;                     // PT 3
 textFont(font,font_size);

  /* lines[0]= new Line(0,0);
   link_number++;*/
}
Re: keyboard and mouse : not working coherent
Reply #2 - Jul 21st, 2008, 12:07pm
 
second relevent part of code:

void mouseDragged()
{
 if(mouseButton==LEFT)
 {
   if(check==0)
   { // to check for object drag  if space not pressed  check =0 means space not pressed ... so no panning needed ..so drag and drop can take place
        if(shift_pressed==1 || shift_released==1)
         {
          draw_link();      
         }
        else
       {
        for(i=0;i<=num-1;i++)    
       {  
       
         box[i].dragcheck();      
       
      }
      }
    }

}
}


void keyPressed()
{
 if (key == CODED) {
   if (keyCode == UP)updown = updown-30;
   else  
     if (keyCode == DOWN)updown = updown+30;
   else  
     if (keyCode == LEFT)leftright = leftright-30;  
   else  
     if (keyCode == RIGHT)leftright = leftright+30;  
   else
     if (keyCode== SHIFT )
     {
       shift_pressed=1;  
       shift_released=0;
     }  
}
 if(key == ' ') check= 1;
 else check=0;  // check tells if return pressed or not if yes then object can't be dragged
 if(key == '+') zoom = zoom-.1;
 else if (key == '-')zoom = zoom+.1;  

 if(key=='s')save_position();
 if(key=='u')update();
 if(key=='d')delete();
}

void keyReleased()
{
 if(key == ' ') check=0;  // to indicate panning not needed
 if(key== CODED && keyCode==SHIFT)
 {
   shift_pressed=0;
   shift_released=1;
 }
}


void draw_link()
{  
   int j;
    println(root);
    for(j=0;j<=num-1;j++)
    {
    float D=(box[j].x-mouseX)*(box[j].x-mouseX)+(box[j].y-mouseY)*(box[j].y-mouseY);  
    D=sqrt(D);
       
    if( D<=box[j].r)
    {
      if(shift_count==0 && shift_pressed==1)
      {
      root =j;
      shift_count=1;
      println(" in root setter");
      }
        if(shift_released ==1 && shift_count==1)
      {
       link_number++;
       lines[link_number-1]= new Line(root,j);
       line(box[root].x,box[root].y,box[j].x,box[j].y);
       //root=-364; // no need for that
       shift_count=0;
       println("in terminus setter");
       break;
      }
     }
   }

if(shift_released==1)
   {
     println("check");
     shift_released=0;
     shift_count=0;
   }  

 if(shift_count==1 && shift_pressed==1)
  {
    stroke(1);
    line(box[root].x,box[root].y,mouseX,mouseY);
    println(" just drawing ");
 }

}

class Line
 {
    int i1,i2;
    Line (int pi1, int pi2)
    {
    i1=pi1;
    i2=pi2;
    }
   void display()
   {
   stroke(1);
   line(box[this.i1].x,box[this.i1].y,box[this.i2].x,box[this.i2].y);
   }
}

Re: keyboard and mouse : not working coherent
Reply #3 - Jul 21st, 2008, 1:09pm
 
Why are you using two variables - shiftPressed and shiftReleased - to store the same information about the shift key? You would better use only one boolean to check if the key is pressed or not.

Please post your full code. Concatening these parts of code you gave doesn't run. And feel free to use the [code] and [ /code] tags (remove the space in closing tag).
Re: keyboard and mouse : not working coherent
Reply #4 - Jul 21st, 2008, 2:28pm
 
actually i need the shift_pressed and shify_releqased tags to enter the draw_link fn at two different situation types
shift_pressed when root is being found or when still terminus is not got but root is got
shift_released to enter when terminus has been got.

Also the real problem i just found out is that the
variable change in keyboard function & finding the terminus inside the mouseDrag func don't occur in same cycle

Code:

Box[] box; // an array of objects of type Box
Line[] lines;
int i=0;
int num=0;
int odrag=0; // tells if some object beign dragged or not...if yes then odrag=1 ..if odrag==1 then panning can take place
int anyresize=1; // if it is one , any object can resize if it is zero no object is allowed to resize
float zoom=1;
float leftright,updown,notches;
int check=0;
PFont font;
float w,h;
float font_size;
PImage b;
int counter=0;
String [] feeds;
String [] elements;
int dc=0;

int terminus; // weird
int shift_pressed=0;
int shift_count=0;
int root;
int shift_released=0;
int link_number=0;
int num_l;

PImage [] img;
int num_b,num_f,num_i,num_o;

int feed_stroke_color=153; // PT1
int feed_background_color=255;
int bookmark_stroke_color=153 ;
int bookmark_background_color=255;
int img_stroke_color=153;
int img_background_color=255;
int scene_background_color=255;
int font_color=153; // I do not know where to use it

void setup()
{
int num2;
num_b=0;
num_f=0;
num2=0;
num_i=0;
num_o=0;
//stroke(153);
size(1024,768,P3D);
font = loadFont("Centaur-48.vlw"); // PT 2
textAlign(LEFT,TOP);
strokeWeight(1/20);
font_size=35; // PT 3
textFont(font,font_size);
////////////////////////////////////////////////////////////////////////////////////////////
//update(); // VERY IMP CALLING UPDATE FUNCTION Should be in user's hand
/////////////////////////////////////////////////////////////////////////////////////////////
String url_f = "http://turing.lecolededesign.com:16080/~rshukla/gui_feed.php";
String [] feeds_f = loadStrings(url_f);
for (int i = 0; i < feeds_f.length; i++)
{
String [] elements_f=split(feeds_f[i], "RAM_BREAK");
if(elements_f.length!=1)num_f+=1;
println("Loading FEEDS");
}
String url_b = "http://turing.lecolededesign.com:16080/~rshukla/gui_bookmark.php";
String [] feeds_b = loadStrings(url_b);
for (int i = 0; i < feeds_b.length; i++)
{
String [] elements_b=split(feeds_b[i], "RAM_BREAK");
if(elements_b.length!=1)num_b+=1;
println("Loading BOOKMARKS");
}
String url_i = "http://turing.lecolededesign.com:16080/~rshukla/gui_img.php";
String [] feeds_i = loadStrings(url_i);
for (int i = 0; i < feeds_i.length; i++)
{
String [] elements_i=split(feeds_i[i], "RAM_BREAK");
if(elements_i.length!=1)num_i+=1;
}
String url_o = "http://turing.lecolededesign.com:16080/~rshukla/gui_onto.php";
String [] feeds_o = loadStrings(url_o);
for (int i = 0; i < feeds_o.length; i++)
{
String [] elements_o=split(feeds_o[i], "RAM_BREAK");
if(elements_o.length!=1)num_o+=1;
}

num=num_b+num_f+num_i+num_o;
box=new Box[num];
img = new PImage[num_i];
num_l= int ((num-1)*num/2) ;
lines = new Line[num_l];
Re: keyboard and mouse : not working coherent
Reply #5 - Jul 21st, 2008, 2:30pm
 
Code:

for (i = 0; i <= feeds_f.length-1; i++)
{
String [] elements_f=split(feeds_f[i], "RAM_BREAK");
if(elements_f.length!=1){
box[num2] = new Box(float (elements_f[8]) ,float (elements_f[9]), float(elements_f[10]) ,float(elements_f[11]),0,1,0,elements_f[5], elements_f[3],"FEED");
num2++;
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//num2=0;
for (i = 0; i <= feeds_b.length-1; i++)
{
String [] elements_b=split(feeds_b[i], "RAM_BREAK");
if(elements_b.length!=1){
box[num2] = new Box(float (elements_b[5]) ,float (elements_b[6]), float(elements_b[7]) ,float(elements_b[8]),0,1,0,elements_b[2], elements_b[1],"BM");
num2++;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
for (i = 0; i <= feeds_i.length-1; i++)
{
String [] elements_i=split(feeds_i[i], "RAM_BREAK");
if(elements_i.length!=1){
box[num2] = new Box(float (elements_i[4]) ,float (elements_i[5]), float(elements_i[6]) ,float(elements_i[7]),0,1,0,elements_i[0], elements_i[1],"IM");
num2++;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////

for(i=0;i<=num_i-1;i++)
{
int offset=num_f+num_b;
img[i]=loadImage(box[i+offset].txt,"png");
println("Loading IMAGES");
}

///////////////////////////////////////////////////////////////////////////////////////////////////
for(i=0;i<=num_o-1;i++)
{
String [] elements_o=split(feeds_o[i], "RAM_BREAK");
box[num2] = new Box(float (elements_o[2]) ,float (elements_o[3]), float(elements_o[4]) ,float(elements_o[5]),0,1,0,elements_o[0], "http://www.w3.org/2001/sw/WebOnt/#Current" ,elements_o[1]);
println("Loading Ontologies");
num2++;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
/* lines[0]= new Line(0,0);
link_number++;*/
}

class Box {
float x, y, ln, ht,cx,cy,r,rd;
int over,moving,resized;
String txt,plink,type;
Box( float px, float py, float pln,float pht,int pover,int pmoving,int presized,String ptxt,String pplink,String ptype ) {
x = px;
y = py;
ln = pln/2; // adjusted according to mode RADIUS
ht = pht/2;
r=sqrt(ln*ln+ht*ht);
cx=x+ln;
cy=y+ht;
over=pover; // not used this field in the code
resized=presized; //resized =1 means that it is being resized , resized =0 means it is not being resized
moving=pmoving; // moving means whether this is allowed to move or not...if 1 then allowed to move i.e. to be dragged
txt=ptxt;
plink=pplink;
type=ptype;
}


void dragcheck()
{
if(mousePressed) // update function for boxes
{

float D=(this.x-pmouseX)*(this.x-pmouseX)+(this.y-pmouseY)*(this.y-pmouseY); // calculate the distance of mouse position from the center of object who called the dragcheck
D=sqrt(D);
float D1=(this.cx-pmouseX)*(this.cx-pmouseX)+(this.cy-pmouseY)*(this.cy-pmouseY); // calculate the distance of mouse position from the center of object who called the dragcheck
D1=sqrt(D1);
if (D<=this.r )
{

if(D1<=this.rd) this.resized=1;
///////////////////////////////////////////////////////
if(this.moving==1 && this.resized==1 && anyresize==1) // if the box is being dragged but is over resize zone then this part works
{
for(i=0;i<=num-1;i++)
{
box[i].resized=0; //locking all others from being dragged
box[i].moving=0;
}
this.resized=1; //resize acts like a flag ...if it is one then the object can be resized lest no
this.moving=1; // here we just stopped
odrag=1; //tells that this resize is for objects so no panning needed
this.ln=this.ln+(mouseX-pmouseX)*2; // *2 has made sensitivity good
this.ht=this.ht+(mouseY-pmouseY)*2;
if(this.ln <=0)this.ln=2;
if(this.ht<=0)this.ht=2;
this.r=sqrt(this.ln*this.ln+this.ht*this.ht);
this.cx=this.x+this.ln;
this.cy=this.y+this.ht;
//counter++;
}
///////////////////////////////////////////////////
if(this.moving==1 && this.resized==0) // this is the move and drag loop
{
for(i=0;i<=num-1;i++) //
{
box[i].moving=0; //locking all others from being dragged
box[i].resized=0;
}
this.moving=1; //moving acts like a flag ...if it is one then the object can move lest no
odrag=1; //tells that this drag is for objects so no panning needed
anyresize=0;
this.x=mouseX;
this.y=mouseY;
this.cx=this.x+this.ln;
this.cy=this.y+this.ht;
}
/////////////////////////////////////////////////////////////////
}
} // till here for boxs being dragged or resized
}
Re: keyboard and mouse : not working coherent
Reply #6 - Jul 21st, 2008, 2:30pm
 
Code:

void display()
{
rectMode(RADIUS);
text(this.txt,this.x,this.y,this.ln,this.ht);
ellipse(this.x, this.y,2*this.r,2*this.r);
fill(1); // PT 4 this is to get black circles
this.rd=zoom*this.r/8;
ellipse(this.cx, this.cy,this.rd,this.rd);
}
}
////////////////////////////////////////////////////////////////////

void mouseDragged()
{
if(mouseButton==LEFT)
{
if(check==0)
{ // to check for object drag if space not pressed check =0 means space not pressed ... so no panning needed ..so drag and drop can take place
if(shift_pressed==1 || shift_released==1)
{
draw_link();
}
else
{
for(i=0;i<=num-1;i++)
{

box[i].dragcheck();

}
}
}

if(odrag==0 && check==1)
{ // is for panning, will have to do by buttons
cursor(MOVE);
leftright=leftright-2*(mouseX-pmouseX);
updown=updown-2*(mouseY-pmouseY);
}
if(odrag==1)
{ // this is to pan if object being dragged and reached the corner of screen
if(mouseX>width-3 &&mouseX>pmouseX)leftright= leftright+30;
else if(mouseX<3 &&mouseX<pmouseX)leftright= leftright-30;
if(mouseY>height-3 &&mouseY>pmouseY)updown= updown+30;
else if(mouseY<3 &&mouseY<pmouseY)updown= updown-30;
}
}
}

///////////////////////////////////////////////////////////////////////////////

void mouseReleased() // to set all objects as not bein dragged
{
int j;
if(mouseButton==LEFT){
for(i=0;i<=num-1;i++)
{
box[i].moving=1; // so that on releasing the mouse, all boxs are unlocked.
box[i].resized=0; // so that on releasing mouse it becomes known that nobody is being resized.
}
odrag=0; // to allow panning to take place now
anyresize=1;
}
cursor(ARROW);
Re: keyboard and mouse : not working coherent
Reply #7 - Jul 21st, 2008, 2:31pm
 
Code:

void draw()
{
background(scene_background_color); // PT 5
if(dc==1)
{
new_window();
dc=0;
}
myzoom();
mytranslate();
for(i=0;i<=num_f-1;i++)
{
fill(feed_background_color); // PT 6
stroke(feed_stroke_color);
box[i].display();
}
int offset = num_f;
for(i=0;i<=num_b-1;i++)
{
fill(bookmark_background_color); // PT 7
stroke(bookmark_stroke_color);
box[i+offset].display();
}

offset = num_f+num_b;
for(i=0;i<=num_i-1;i++)
{
fill(img_background_color); // PT 8
stroke(img_stroke_color);
image (img[i],box[offset+i].x-box[offset+i].ln ,box[offset+i].y-box[offset+i].ht, 2*box[offset+i].ln, 2*box[offset+i].ht );
ellipse(box[offset+i].x, box[offset+i].y,2*box[offset+i].r,2*box[offset+i].r);
box[offset+i].rd=zoom*box[offset+i].r/8;
fill(1); // PT 9 for black ellipses
ellipse(box[offset+i].cx, box[offset+i].cy,box[offset+i].rd,box[offset+i].rd);
}

offset = num_f+num_b+num_i;
for(i=0;i<=num_o-1;i++)
{
fill(120,120,50,100);
stroke(255);
box[i+offset].display();
}

for(i=0;i<=link_number-1;i++)
{
lines[i].display();
}

}

void keyPressed()
{
if (key == CODED) {
if (keyCode == UP)updown = updown-30;
else
if (keyCode == DOWN)updown = updown+30;
else
if (keyCode == LEFT)leftright = leftright-30;
else
if (keyCode == RIGHT)leftright = leftright+30;
else
if (keyCode== SHIFT )
{
shift_pressed=1;
shift_released=0;
}
}
if(key == ' ') check= 1;
else check=0; // check tells if return pressed or not if yes then object can't be dragged
if(key == '+') zoom = zoom-.1;
else if (key == '-')zoom = zoom+.1;

if(key=='s')save_position();
if(key=='u')update();
if(key=='d')delete();
}

void keyReleased()
{
if(key == ' ') check=0; // to indicate panning not needed
if(key== CODED && keyCode==SHIFT)
{
shift_pressed=0;
shift_released=1;
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void draw_link()
{
int j;
println(root);
for(j=0;j<=num-1;j++)
{
float D=(box[j].x-mouseX)*(box[j].x-mouseX)+(box[j].y-mouseY)*(box[j].y-mouseY);
D=sqrt(D);

if( D<=box[j].r)
{
if(shift_count==0 && shift_pressed==1)
{
root =j;
shift_count=1;
println(" in root setter");
}
if(shift_released ==1 && shift_count==1)
{
link_number++;
lines[link_number-1]= new Line(root,j);
line(box[root].x,box[root].y,box[j].x,box[j].y);
//root=-364; // no need for that
shift_count=0;
println("in terminus setter");
break;
}
}
}

if(shift_released==1)
{
println("check");
shift_released=0;
shift_count=0;
}

if(shift_count==1 && shift_pressed==1)
{
stroke(1);
line(box[root].x,box[root].y,mouseX,mouseY);
println(" just drawing ");
}

}
Re: keyboard and mouse : not working coherent
Reply #8 - Jul 21st, 2008, 2:32pm
 
Code:

void draw()
{
background(scene_background_color); // PT 5
if(dc==1)
{
new_window();
dc=0;
}
myzoom();
mytranslate();
for(i=0;i<=num_f-1;i++)
{
fill(feed_background_color); // PT 6
stroke(feed_stroke_color);
box[i].display();
}
int offset = num_f;
for(i=0;i<=num_b-1;i++)
{
fill(bookmark_background_color); // PT 7
stroke(bookmark_stroke_color);
box[i+offset].display();
}

offset = num_f+num_b;
for(i=0;i<=num_i-1;i++)
{
fill(img_background_color); // PT 8
stroke(img_stroke_color);
image (img[i],box[offset+i].x-box[offset+i].ln ,box[offset+i].y-box[offset+i].ht, 2*box[offset+i].ln, 2*box[offset+i].ht );
ellipse(box[offset+i].x, box[offset+i].y,2*box[offset+i].r,2*box[offset+i].r);
box[offset+i].rd=zoom*box[offset+i].r/8;
fill(1); // PT 9 for black ellipses
ellipse(box[offset+i].cx, box[offset+i].cy,box[offset+i].rd,box[offset+i].rd);
}

offset = num_f+num_b+num_i;
for(i=0;i<=num_o-1;i++)
{
fill(120,120,50,100);
stroke(255);
box[i+offset].display();
}

for(i=0;i<=link_number-1;i++)
{
lines[i].display();
}

}

void keyPressed()
{
if (key == CODED) {
if (keyCode == UP)updown = updown-30;
else
if (keyCode == DOWN)updown = updown+30;
else
if (keyCode == LEFT)leftright = leftright-30;
else
if (keyCode == RIGHT)leftright = leftright+30;
else
if (keyCode== SHIFT )
{
shift_pressed=1;
shift_released=0;
}
}
if(key == ' ') check= 1;
else check=0; // check tells if return pressed or not if yes then object can't be dragged
if(key == '+') zoom = zoom-.1;
else if (key == '-')zoom = zoom+.1;

if(key=='s')save_position();
if(key=='u')update();
if(key=='d')delete();
}

void keyReleased()
{
if(key == ' ') check=0; // to indicate panning not needed
if(key== CODED && keyCode==SHIFT)
{
shift_pressed=0;
shift_released=1;
}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void draw_link()
{
int j;
println(root);
for(j=0;j<=num-1;j++)
{
float D=(box[j].x-mouseX)*(box[j].x-mouseX)+(box[j].y-mouseY)*(box[j].y-mouseY);
D=sqrt(D);

if( D<=box[j].r)
{
if(shift_count==0 && shift_pressed==1)
{
root =j;
shift_count=1;
println(" in root setter");
}
if(shift_released ==1 && shift_count==1)
{
link_number++;
lines[link_number-1]= new Line(root,j);
line(box[root].x,box[root].y,box[j].x,box[j].y);
//root=-364; // no need for that
shift_count=0;
println("in terminus setter");
break;
}
}
}

if(shift_released==1)
{
println("check");
shift_released=0;
shift_count=0;
}

if(shift_count==1 && shift_pressed==1)
{
stroke(1);
line(box[root].x,box[root].y,mouseX,mouseY);
println(" just drawing ");
}

}
Re: keyboard and mouse : not working coherent
Reply #9 - Jul 21st, 2008, 2:33pm
 
Code:

class Line
{
int i1,i2;
Line (int pi1, int pi2)
{
i1=pi1;
i2=pi2;
}
void display()
{
stroke(1);
line(box[this.i1].x,box[this.i1].y,box[this.i2].x,box[this.i2].y);
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void save_position()
{
int index;
float db_ln, db_ht;
for(i=0;i<=num_f-1;i++)
{
db_ln=box[i].ln*2;
db_ht=box[i].ht*2;
String url_s="http://turing.lecolededesign.com:16080/~rshukla/savefeed.php?x="+box[i].x+"&y="+box[i].y+"&ln="+db_ln+"&ht="+db_ht+"&url="+box[i].plink;
println("saving FEEDS");
loadStrings(url_s);
println(i);
}
for(i=0;i<=num_b-1;i++)
{
index=i+num_f;
db_ln=box[index].ln*2;
db_ht=box[index].ht*2;
String url_s="http://turing.lecolededesign.com:16080/~rshukla/savebm.php?x="+box[index].x+"&y="+box[index].y+"&ln="+db_ln+"&ht="+db_ht+"&url="+box[index].plink;
println("saving BOOKMARKS");
loadStrings(url_s);
println(index);
}
for(i=0;i<=num_i-1;i++)
{
index=i+num_f+num_b;
db_ln=box[index].ln*2;
db_ht=box[index].ht*2;
String url_s="http://turing.lecolededesign.com:16080/~rshukla/saveimg.php?x="+box[index].x+"&y="+box[index].y+"&ln="+db_ln+"&ht="+db_ht+"&url="+box[index].txt;
println("saving IMAGES");
println(i);
loadStrings(url_s);
}

for(i=0;i<=num_o-1;i++)
{
index=i+num_f+num_b+num_i;
db_ln=box[index].ln*2;
db_ht=box[index].ht*2;
String url_s="http://turing.lecolededesign.com:16080/~rshukla/saveonto.php?x="+box[index].x+"&y="+box[index].y+"&ln="+db_ln+"&ht="+db_ht+"&name="+box[index].txt+"&type="+box[index].type;
println("saving ONTO");
println(i);
loadStrings(url_s);
}

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void update() // refreshes database
{
String url_s;
url_s="http://turing.lecolededesign.com:16080/~rshukla/parse_feed.php";
loadStrings(url_s);
url_s="http://turing.lecolededesign.com:16080/~rshukla/parse_bm.php";
loadStrings(url_s);
url_s="http://turing.lecolededesign.com:16080/~rshukla/parse_img.php";
loadStrings(url_s);

url_s="http://turing.lecolededesign.com:16080/~rshukla/update_bm.php";
loadStrings(url_s);
url_s="http://turing.lecolededesign.com:16080/~rshukla/update_feeds.php";
loadStrings(url_s);
url_s="http://turing.lecolededesign.com:16080/~rshukla/update_img.php";
loadStrings(url_s);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void mousePressed()
{
if(mouseButton!= LEFT && mouseButton!= RIGHT)
{
addMouseWheelListener(new java.awt.event.MouseWheelListener() {
public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
int notches = evt.getWheelRotation();
if(notches!=0){
zoom=zoom + notches*0.01;
notches=0;
//updown=-height/2+mouseY; // trying to zoom at mouse position haah could not do it
//leftright=+mouseX-width/2;
}
}
}
); // weird funnction don't ask what it does
}
if (mouseEvent.getClickCount()==2)dc=1;
}


void delete()
{
}


void mouseMoved() // if passing the entire screen then to shift the arena
{ //replace this functionality by buttons on screen
if(mouseX>width-3 &&mouseX>=pmouseX)leftright= leftright+30;
else if(mouseX<3 &&mouseX<=pmouseX)leftright= leftright-30;
if(mouseY>height-3 &&mouseY>=pmouseY)updown= updown+30;
else if(mouseY<3 &&mouseY<=pmouseY && mouseX<width-75)updown= updown-30; // third conditiopn there so that no movement when you try to close the window
}

void myzoom()
{
if(zoom!=1){
cursor(CROSS);
scale(zoom);
for(i=0;i<=num-1;i++){
box[i].ln=box[i].ln/zoom;
box[i].ht=box[i].ht/zoom;
box[i].x=box[i].x/zoom;
box[i].y=box[i].y/zoom;
box[i].r=box[i].r/zoom;
box[i].rd=box[i].rd/zoom;
box[i].cx=box[i].cx/zoom;
box[i].cy=box[i].cy/zoom;
//font_size=font_size/zoom;
}
zoom=1;
}
}

void new_window()
{
for(i=num-1;i>=0;i--)
{
float D=(box[i].x-pmouseX)*(box[i].x-pmouseX)+(box[i].y-pmouseY)*(box[i].y-pmouseY); // calculate the distance of mouse position from the center of object who called the dragcheck
D=sqrt(D);
if(D<=box[i].r)
{
link(box[i].plink,"_new");
break;
}
}
}

void mytranslate(){
if(leftright!=0 || updown!=0){
translate (leftright,updown);
for(i=0;i<=num-1;i++){
box[i].x=box[i].x-leftright;
box[i].y=box[i].y-updown;
box[i].cx=box[i].cx-leftright;
box[i].cy=box[i].cy-updown;
}
leftright=updown=0;
}
}
Re: keyboard and mouse : not working coherent
Reply #10 - Jul 21st, 2008, 2:34pm
 
i know it is a long code that is why i had previously sent only relevent section
Re: keyboard and mouse : not working coherent
Reply #11 - Jul 21st, 2008, 5:08pm
 
I think changing the way you handle the mouse events on the boxes may solve your problem.

Quote:
Box boxStart;

void mousePressed() {
 if (keyPressed && key == CODED && key == SHIFT)
   boxStart = getBoxUnderMouse();
}

void mouseReleased() {
 if (boxStart != null) {
   Box boxEnd = getBoxUnderMouse();
   if (boxEnd != null && boxEnd != boxStart) {
     // <-- create a new line between boxStart and boxEnd
   }
 }
 boxStart = null;
}

void draw() {
 background(255);
 if (boxStart != null)
   line(boxStart.x, boxStart.y, mouseX, mouseY);
}

Box getBoxUnderMouse() {
 // <-- iterate the boxes array here and return the first box under the mouse cursor
 // else :
 return null;
}

class Box{
 int x, y;
}
Re: keyboard and mouse : not working coherent
Reply #12 - Jul 25th, 2008, 12:41pm
 
thanks
i understood that I was calling the overall link drawing function .. i.e. I was making new links by detecting shift key states inside a mouse function.

so automatically , even after the key was released, I had to wait for next cycle to register mouse key state.

I guess i should call all functions that use both mouse and key states always from draw or setup...

Page Index Toggle Pages: 1