Created
September 14, 2019 11:29
-
-
Save CraftedPvP/e1433f1b4a4620ca90cce2c9b2be65fe to your computer and use it in GitHub Desktop.
A C++ template for Glut Mouse button events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int lastMouseBtnStateLeft = GLUT_UP; // last left mouse buttons state | |
int lastMouseBtnStateRight = GLUT_UP; // last right mouse buttons state | |
void processMouse(int button, int state1, int x, int y){ | |
if (button == GLUT_LEFT_BUTTON) { | |
// decode and handle the mouse events by type | |
if ((lastMouseBtnStateLeft == GLUT_UP )&&(state1 == GLUT_DOWN)) // mouse down (click) | |
{ | |
// here do your stuff | |
} | |
if ((lastMouseBtnStateLeft == GLUT_DOWN)&&(state1 == GLUT_DOWN)) // mouse move while clicked | |
{ | |
// here do your stuff | |
} | |
if ((lastMouseBtnStateLeft == GLUT_DOWN)&&(state1 == GLUT_UP )) // mouse up (release) | |
{ | |
// here do your stuff | |
} | |
if ((lastMouseBtnStateLeft == GLUT_UP )&&(state1 == GLUT_UP )) // mouse move without buttons | |
{ | |
// here do your stuff | |
} | |
// store actual buttons state for next time | |
lastMouseBtnStateLeft = state1; | |
} | |
if (button == GLUT_RIGHT_BUTTON){ | |
// decode and handle the mouse events by type | |
if ((lastMouseBtnStateRight == GLUT_UP )&&(state1 == GLUT_DOWN)) // mouse down (click) | |
{ | |
// here do your stuff | |
} | |
if ((lastMouseBtnStateRight == GLUT_DOWN)&&(state1 == GLUT_DOWN)) // mouse move while clicked | |
{ | |
// here do your stuff | |
} | |
if ((lastMouseBtnStateRight == GLUT_DOWN)&&(state1 == GLUT_UP )) // mouse up (release) | |
{ | |
// here do your stuff | |
} | |
if ((lastMouseBtnStateRight == GLUT_UP )&&(state1 == GLUT_UP )) // mouse move without buttons | |
{ | |
// here do your stuff | |
} | |
// store actual buttons state for next time | |
lastMouseBtnStateRight = state1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment