How to implement dragging feature for mouse in GLFW library

GLFW library does have a feature for keyboard input for detecting hold button status but it doesn't support same feature for mouse event. I need to manually implement it. This is my approach

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bool Mouse::isRightDown()
{
	if (m_button == GLFW_MOUSE_BUTTON_RIGHT && m_action == GLFW_PRESS){
		m_isRightHold = true;
		return true;
	}
	
	return false;
}

bool Mouse::isRightUp()
{
	if (m_button == GLFW_MOUSE_BUTTON_RIGHT && m_action == GLFW_RELEASE ){
		m_isRightHold = false;
		return true;
	}
	
	return false;
} 


Basically, the approach is to hold the status in bool flag, in the above code, it is m_isRightHold. When the user clicks on mouse button, the flag is set to true and once it is released, the flag is set to false. The approach works but in while-loop, even one click, it causes the function to report that the button is hold (i.e. while loop is faster than human's reaction to release the button). How this issue is handled? Sleep function to slow down my code. Any suggestions? Is using an independent thread an overkill solution? I've tried it and it works (i.e. sleep around 1.5 second is reasonable for my hand).
Last edited on
isRightDown and isRightUp should just be returning the value of m_isRightHold.

The setting of the value should be done elsewhere (such as a handler for mouse actions.) The documentation for glfw suggests that it supports callback functions for mouse events.
Topic archived. No new replies allowed.