Browse Source

Platform: finally added proper key events to GlutApplication.

The functions were there all the time, I just didn't try hard enough to
find them. The special keys now have different values (the lower 16 bits
are reserved for ASCII), but it is a source-compatible change.
pull/51/head
Vladimír Vondruš 12 years ago
parent
commit
f021f09df8
  1. 22
      src/Magnum/Platform/GlutApplication.cpp
  2. 109
      src/Magnum/Platform/GlutApplication.h

22
src/Magnum/Platform/GlutApplication.cpp

@ -95,7 +95,10 @@ bool GlutApplication::tryCreateContext(const Configuration& configuration) {
return false; return false;
} }
glutReshapeFunc(staticViewportEvent); glutReshapeFunc(staticViewportEvent);
glutSpecialFunc(staticKeyEvent); glutKeyboardFunc(staticKeyPressEvent);
glutKeyboardUpFunc(staticKeyReleaseEvent);
glutSpecialFunc(staticSpecialKeyPressEvent);
glutSpecialUpFunc(staticSpecialKeyReleaseEvent);
glutMouseFunc(staticMouseEvent); glutMouseFunc(staticMouseEvent);
glutMotionFunc(staticMouseMoveEvent); glutMotionFunc(staticMouseMoveEvent);
glutDisplayFunc(staticDrawEvent); glutDisplayFunc(staticDrawEvent);
@ -108,11 +111,26 @@ GlutApplication::~GlutApplication() {
delete c; delete c;
} }
void GlutApplication::staticKeyEvent(int key, int x, int y){ void GlutApplication::staticKeyPressEvent(unsigned char key, int x, int y) {
KeyEvent e(static_cast<KeyEvent::Key>(key), {x, y}); KeyEvent e(static_cast<KeyEvent::Key>(key), {x, y});
instance->keyPressEvent(e); instance->keyPressEvent(e);
} }
void GlutApplication::staticKeyReleaseEvent(unsigned char key, int x, int y) {
KeyEvent e(static_cast<KeyEvent::Key>(key), {x, y});
instance->keyReleaseEvent(e);
}
void GlutApplication::staticSpecialKeyPressEvent(int key, int x, int y){
KeyEvent e(static_cast<KeyEvent::Key>(key << 16), {x, y});
instance->keyPressEvent(e);
}
void GlutApplication::staticSpecialKeyReleaseEvent(int key, int x, int y){
KeyEvent e(static_cast<KeyEvent::Key>(key << 16), {x, y});
instance->keyReleaseEvent(e);
}
void GlutApplication::staticMouseEvent(int button, int state, int x, int y) { void GlutApplication::staticMouseEvent(int button, int state, int x, int y) {
MouseEvent e(static_cast<MouseEvent::Button>(button), {x, y}); MouseEvent e(static_cast<MouseEvent::Button>(button), {x, y});
if(state == GLUT_DOWN) if(state == GLUT_DOWN)

109
src/Magnum/Platform/GlutApplication.h

@ -48,9 +48,8 @@ namespace Platform {
/** @nosubgrouping /** @nosubgrouping
@brief GLUT application @brief GLUT application
Application using GLUT toolkit. Supports keyboard handling for limited subset Application using GLUT toolkit. Supports keyboard and mouse handling with
of keys, mouse handling with support for changing cursor and mouse tracking and support for changing cursor and mouse tracking and warping.
warping.
This application library is available only on desktop OpenGL (Linux, Windows, This application library is available only on desktop OpenGL (Linux, Windows,
OS X). It depends on **GLUT** library and is built if `WITH_GLUTAPPLICATION` is OS X). It depends on **GLUT** library and is built if `WITH_GLUTAPPLICATION` is
@ -182,12 +181,7 @@ class GlutApplication {
/** @copydoc Sdl2Application::keyPressEvent() */ /** @copydoc Sdl2Application::keyPressEvent() */
virtual void keyPressEvent(KeyEvent& event); virtual void keyPressEvent(KeyEvent& event);
/** /** @copydoc Sdl2Application::keyReleaseEvent() */
* @brief Key release event
*
* Included only for compatibility with other toolkits, doesn't get
* called at all.
*/
virtual void keyReleaseEvent(KeyEvent& event); virtual void keyReleaseEvent(KeyEvent& event);
/*@}*/ /*@}*/
@ -254,7 +248,11 @@ class GlutApplication {
instance->viewportEvent({x, y}); instance->viewportEvent({x, y});
} }
static void staticKeyEvent(int key, int x, int y); static void staticKeyPressEvent(unsigned char key, int x, int y);
static void staticKeyReleaseEvent(unsigned char key, int x, int y);
static void staticSpecialKeyPressEvent(int key, int x, int y);
static void staticSpecialKeyReleaseEvent(int key, int x, int y);
static void staticMouseEvent(int button, int state, int x, int y); static void staticMouseEvent(int button, int state, int x, int y);
@ -396,27 +394,76 @@ class GlutApplication::KeyEvent: public GlutApplication::InputEvent {
* *
* @see @ref key() * @see @ref key()
*/ */
enum class Key: int { enum class Key: UnsignedInt {
Up = GLUT_KEY_UP, /**< Up arrow */ Esc = '\x1b', /**< Escape */
Down = GLUT_KEY_DOWN, /**< Down arrow */
Left = GLUT_KEY_LEFT, /**< Left arrow */ Up = GLUT_KEY_UP << 16, /**< Up arrow */
Right = GLUT_KEY_RIGHT, /**< Right arrow */ Down = GLUT_KEY_DOWN << 16, /**< Down arrow */
F1 = GLUT_KEY_F1, /**< F1 */ Left = GLUT_KEY_LEFT << 16, /**< Left arrow */
F2 = GLUT_KEY_F2, /**< F2 */ Right = GLUT_KEY_RIGHT << 16, /**< Right arrow */
F3 = GLUT_KEY_F3, /**< F3 */ F1 = GLUT_KEY_F1 << 16, /**< F1 */
F4 = GLUT_KEY_F4, /**< F4 */ F2 = GLUT_KEY_F2 << 16, /**< F2 */
F5 = GLUT_KEY_F5, /**< F5 */ F3 = GLUT_KEY_F3 << 16, /**< F3 */
F6 = GLUT_KEY_F6, /**< F6 */ F4 = GLUT_KEY_F4 << 16, /**< F4 */
F7 = GLUT_KEY_F7, /**< F7 */ F5 = GLUT_KEY_F5 << 16, /**< F5 */
F8 = GLUT_KEY_F8, /**< F8 */ F6 = GLUT_KEY_F6 << 16, /**< F6 */
F9 = GLUT_KEY_F9, /**< F9 */ F7 = GLUT_KEY_F7 << 16, /**< F7 */
F10 = GLUT_KEY_F10, /**< F10 */ F8 = GLUT_KEY_F8 << 16, /**< F8 */
F11 = GLUT_KEY_F11, /**< F11 */ F9 = GLUT_KEY_F9 << 16, /**< F9 */
F12 = GLUT_KEY_F12, /**< F12 */ F10 = GLUT_KEY_F10 << 16, /**< F10 */
Home = GLUT_KEY_HOME, /**< Home */ F11 = GLUT_KEY_F11 << 16, /**< F11 */
End = GLUT_KEY_END, /**< End */ F12 = GLUT_KEY_F12 << 16, /**< F12 */
PageUp = GLUT_KEY_PAGE_UP, /**< Page up */ Home = GLUT_KEY_HOME << 16, /**< Home */
PageDown = GLUT_KEY_PAGE_DOWN /**< Page down */ End = GLUT_KEY_END << 16, /**< End */
PageUp = GLUT_KEY_PAGE_UP << 16, /**< Page up */
PageDown = GLUT_KEY_PAGE_DOWN << 16, /**< Page down */
Space = ' ', /**< Space */
Comma = ',', /**< Comma */
Period = '.', /**< Period */
Minus = '-', /**< Minus */
Plus = '+', /**< Plus */
Slash = '/', /**< Slash */
Percent = '%', /**< Percent */
Equal = '=', /**< Equal */
Zero = '0', /**< Zero */
One = '1', /**< One */
Two = '2', /**< Two */
Three = '3', /**< Three */
Four = '4', /**< Four */
Five = '5', /**< Five */
Six = '6', /**< Six */
Seven = '7', /**< Seven */
Eight = '8', /**< Eight */
Nine = '9', /**< Nine */
A = 'a', /**< Letter A */
B = 'b', /**< Letter B */
C = 'c', /**< Letter C */
D = 'd', /**< Letter D */
E = 'e', /**< Letter E */
F = 'f', /**< Letter F */
G = 'g', /**< Letter G */
H = 'h', /**< Letter H */
I = 'i', /**< Letter I */
J = 'j', /**< Letter J */
K = 'k', /**< Letter K */
L = 'l', /**< Letter L */
M = 'm', /**< Letter M */
N = 'n', /**< Letter N */
O = 'o', /**< Letter O */
P = 'p', /**< Letter P */
Q = 'q', /**< Letter Q */
R = 'r', /**< Letter R */
S = 's', /**< Letter S */
T = 't', /**< Letter T */
U = 'u', /**< Letter U */
V = 'v', /**< Letter V */
W = 'w', /**< Letter W */
X = 'x', /**< Letter X */
Y = 'y', /**< Letter Y */
Z = 'z' /**< Letter Z */
}; };
/** @brief Key */ /** @brief Key */

Loading…
Cancel
Save