PDA

View Full Version : mouse button 'repeat'



PopeKetric
12-12-2002, 03:58 PM
Is there anyway to make a mouse button repeat? I'm basicly looking for a way to write clickable GL_QUADS that perform certian tasks. But I need them to do those tasks for as long as the button is held.


--Pope

nexusone
12-12-2002, 04:40 PM
Are you using glut or what to get the mouse?

under glutmousefunc since is only works when a button has been pressed, just make a flag to tell that the button was pressed and released.


if(button_down) mouse_flag = 1;
if(button_up) mouse_flag = 0;



Originally posted by PopeKetric:


Is there anyway to make a mouse button repeat? I'm basicly looking for a way to write clickable GL_QUADS that perform certian tasks. But I need them to do those tasks for as long as the button is held.


--Pope

PopeKetric
12-13-2002, 03:47 PM
Originally posted by nexusone:
Are you using glut or what to get the mouse?

under glutmousefunc since is only works when a button has been pressed, just make a flag to tell that the button was pressed and released.


if(button_down) mouse_flag = 1;
if(button_up) mouse_flag = 0;




I have that setup, and it's working well. But I want to have it perform an acction for as long as the mouse button is down, without any motion.

--Pope

31337
12-13-2002, 04:48 PM
I use that setup with GLFW but nomatter what I do I cant get it to stop registering mouseclicks while the button is held down. Any ideas?

nexusone
12-13-2002, 06:58 PM
In order to get motion without any mouse action, you need to use a timer type function.
Example would be glutTimerFunc or glutIdleFunc.

here is a little code:
// Place before glutMainLoop();
glutTimerFunc( 100, TimeEvent, 1);

// Timmer routine
static void TimeEvent(int te)
{

if ( mouse_state == 1)
{
// when mouse button has been pressed down this is called until mouse up.
// do what ever stuff for mouse down here

}

glutPostRedisplay(); // Update screen with new data
glutTimerFunc( 100, TimeEvent, 1); // Reset our timmer.
}

// mouse routine

void mouse(int button, int state, int x, int y)
{

if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN))
{
// Mouse down state becomes one
mouse_state = 1;
}

if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_UP))
{
// Mouse up state becomes zero
mouse_state = 0;
}

}


Originally posted by PopeKetric:
I have that setup, and it's working well. But I want to have it perform an acction for as long as the mouse button is down, without any motion.

--Pope

31337
12-13-2002, 07:06 PM
Do you have any insight into my problem nexusone?

marcus256
12-14-2002, 12:16 PM
Originally posted by 31337:
I use that setup with GLFW but nomatter what I do I cant get it to stop registering mouseclicks while the button is held down. Any ideas?

So basically, what you are doing is either:



void GLFWCALL MouseButton( int button, int action )
{
if( button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS ) button_down = 1;
else if( button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE ) button_down = 0;
}

...or...



button_down = glfwGetMouseButton( GLFW_MOUSE_BUTTON_LEFT );

?????

In any case, button_down will be flagged as long as the button is being held down.

What DO you want to accomplish?

PopeKetric
12-16-2002, 09:19 AM
Originally posted by nexusone:
In order to get motion without any mouse action, you need to use a timer type function.
Example would be glutTimerFunc or glutIdleFunc.

here is a little code:
// Place before glutMainLoop();
glutTimerFunc( 100, TimeEvent, 1);

// Timmer routine
static void TimeEvent(int te)
{

if ( mouse_state == 1)
{
// when mouse button has been pressed down this is called until mouse up.
// do what ever stuff for mouse down here

}

glutPostRedisplay(); // Update screen with new data
glutTimerFunc( 100, TimeEvent, 1); // Reset our timmer.
}

// mouse routine

void mouse(int button, int state, int x, int y)
{

if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN))
{
// Mouse down state becomes one
mouse_state = 1;
}

if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_UP))
{
// Mouse up state becomes zero
mouse_state = 0;
}

}




Makes sense. Thanks a bunch.

--Pope

nexusone
12-16-2002, 09:36 AM
Just read your message, I can only answer for GLUT on this instance, not used the other.


Originally posted by 31337:
Do you have any insight into my problem nexusone?