/*****************************************************************************
 * $Id: keyboard_opengl.cc,v 1.1 2006/08/02 01:29:41 devel Exp $
 * @file
 * @author	Jim E. Brooks  http://www.jimbrooks.org
 * @brief	Keyboard functions for input event queue.
 *//*
 * LEGAL:	COPYRIGHT (C) 2006 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE (GPL).
 *****************************************************************************/

#define GFXINPUT_KEYBOARD_OPENGL_CC 1
#include "gfx.hh"
#include "gfx_gfxsys.hh"
using namespace gfx;
#include "input_queue.hh"
#include "keyboard_opengl.hh"

namespace gfxInput {

/*****************************************************************************
 * Install/activate keyboard handlers.
 *****************************************************************************/
void
GfxsysEnableKeyboard( void )
{
	glutKeyboardFunc( OpenglKeyboard );
	glutSpecialFunc( OpenglKeyboardSpecial );
}

/*****************************************************************************
 * OpenGL keyboard handlers.
 *****************************************************************************/
static void
OpenglKeyboard( unsigned char key, int x, int y )
{
	OpenglKeyboardCommon( key, false );
}
static void
OpenglKeyboardSpecial( int key, int x, int y )
{
	OpenglKeyboardCommon( key, true );
}
static void
OpenglKeyboardCommon( int key, bool special )
{
	int modifiers = glutGetModifiers();
	bool shift = modifiers & GLUT_ACTIVE_SHIFT;
	bool ctrl  = modifiers & GLUT_ACTIVE_CTRL;
	bool alt   = modifiers & GLUT_ACTIVE_ALT;
	InputQueue::GetInstance()->PutKeyEvent( key, special, shift, ctrl, alt );
}

} // namespace gfxInput
