mouseOver(), mouseCliicked and conflicting cursors
in
Programming Questions
•
2 years ago
hey im doing a project where nodes are created in a list, each node is basically a rect(x,y,w,h). The nodes are drawn with no trouble there is a zoom in/out function using UP/DOWN key and also the ability to move the screen by clicking,holding and dragging. I wish to have the cursor set to an ARROW as normal when it is over a node i wish it so to HAND and when the mouse is pressed outside of a node changed to CROSS.
This is code from the button class which takes into account the zoom function (still have to account for the clicking and moving screen). This works and when the mouse is clicked the CROSS is shown, but the hand still shows when the cursor is moved into then out of the node.
I tried adding an else so the code looks like 2 but this then makes the cursor flicker when its over a node, maybe because the curson is being told 2or moore things at once? i will also have to add a click event to the node as seen in 3 it is only in development
The following code is in the main, 1 the zoom function, 2&3 the click and drag to move the screen, 4 is the draw method
I hope i am bein clear and will be great full for any help
This is code from the button class which takes into account the zoom function (still have to account for the clicking and moving screen). This works and when the mouse is clicked the CROSS is shown, but the hand still shows when the cursor is moved into then out of the node.
I tried adding an else so the code looks like 2 but this then makes the cursor flicker when its over a node, maybe because the curson is being told 2or moore things at once? i will also have to add a click event to the node as seen in 3 it is only in development
- void mouseOver()
{
if(mouseX > (x)*zoom && mouseX < (x + w)*zoom && mouseY > (y)*zoom && mouseY < (y + h)*zoom)
{
pushMatrix();
overNode = true;
println(mouseX + " " + mouseY);
cursor(HAND);
popMatrix();
}
} - void mouseOver()
{
if(mouseX > (x)*zoom && mouseX < (x + w)*zoom && mouseY > (y)*zoom && mouseY < (y + h)*zoom)
{
pushMatrix();
overNode = true;
println(mouseX + " " + mouseY);
cursor(HAND);
popMatrix();
}
else
{
overNode = false;
cursor(ARROW);
}
} - void mousePressed()
{
if(mouseX > (x)*zoom && mouseX < (x + w)*zoom && mouseY > (y)*zoom && mouseY < (y + h)*zoom && overNode == true)
{
println("0000000000000000000000000000000000000000000000000000");
}
}
The following code is in the main, 1 the zoom function, 2&3 the click and drag to move the screen, 4 is the draw method
I hope i am bein clear and will be great full for any help
- void keyPressed()
{
if(key == ESC)
{
exit();
}
else if (keyCode == UP)
{
zoom += 0.05;
}
else if (keyCode == DOWN)
{
zoom -= 0.05;
}} - void mouseReleased()
{
locked = false;
cursor(ARROW);
} - void mousePressed()
{
locked = true;
cursor(MOVE);
distanceX = mouseX-centerX;
distanceY = mouseY-centerY;
} - void draw()
{
background(255,255,255);
if (mousePressed == true)
{
centerX = mouseX-distanceX;
centerY = mouseY-distanceY;
}
translate(centerX,centerY);
scale(zoom);
for(Node n : nodes)
{
n.formatNode();
n.draw();
n.mouseOver();
}
createStats();
}
1