Yank out all the glut dependencies and concentrate them in a (easily
reimplementable) Main/fg_os.cxx file.
This commit is contained in:
parent
d430290e48
commit
c0b4531d04
12 changed files with 422 additions and 492 deletions
|
@ -31,8 +31,6 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <plib/pu.h>
|
|
||||||
|
|
||||||
#include "ATC.hxx"
|
#include "ATC.hxx"
|
||||||
#include "transmission.hxx"
|
#include "transmission.hxx"
|
||||||
|
|
||||||
|
|
|
@ -33,9 +33,8 @@
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include FG_GLUT_H // needed before pu.h
|
#include <Main/fg_os.hxx> // must come before pu.h
|
||||||
|
#include <plib/pu.h>
|
||||||
#include <plib/pu.h> // plib include
|
|
||||||
|
|
||||||
#include <simgear/structure/exception.hxx>
|
#include <simgear/structure/exception.hxx>
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include FG_GLUT_H // needed before pu.h
|
#include <Main/fg_os.hxx> // needed before pu.h
|
||||||
#include <plib/pu.h> // plib include
|
#include <plib/pu.h> // plib include
|
||||||
|
|
||||||
#include <FDM/flight.hxx>
|
#include <FDM/flight.hxx>
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include FG_GLUT_H
|
#include <Main/fg_os.hxx>
|
||||||
|
|
||||||
#if defined(FX) && defined(XMESA)
|
#if defined(FX) && defined(XMESA)
|
||||||
# include <GL/xmesa.h>
|
# include <GL/xmesa.h>
|
||||||
|
@ -92,12 +92,6 @@ static int mouse_joystick_control = 0;
|
||||||
// if the little rodent is moved NHV
|
// if the little rodent is moved NHV
|
||||||
static int _mVtoggle = 0;
|
static int _mVtoggle = 0;
|
||||||
|
|
||||||
// we break up the glutGetModifiers return mask
|
|
||||||
// once per loop and stash what we need in these
|
|
||||||
static int glut_active_shift = 0;
|
|
||||||
static int glut_active_ctrl = 0;
|
|
||||||
static int glut_active_alt = 0;
|
|
||||||
|
|
||||||
static int MOUSE_XSIZE = 0;
|
static int MOUSE_XSIZE = 0;
|
||||||
static int MOUSE_YSIZE = 0;
|
static int MOUSE_YSIZE = 0;
|
||||||
|
|
||||||
|
@ -156,15 +150,15 @@ static inline void guiGetMouse(int *x, int *y)
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline int left_button( void ) {
|
static inline int left_button( void ) {
|
||||||
return( last_buttons & (1 << GLUT_LEFT_BUTTON) );
|
return( last_buttons & (1 << MOUSE_BUTTON_LEFT) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int middle_button( void ) {
|
static inline int middle_button( void ) {
|
||||||
return( last_buttons & (1 << GLUT_MIDDLE_BUTTON) );
|
return( last_buttons & (1 << MOUSE_BUTTON_MIDDLE) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int right_button( void ) {
|
static inline int right_button( void ) {
|
||||||
return( last_buttons & (1 << GLUT_RIGHT_BUTTON) );
|
return( last_buttons & (1 << MOUSE_BUTTON_RIGHT) );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void set_goal_view_offset( float offset )
|
static inline void set_goal_view_offset( float offset )
|
||||||
|
@ -246,19 +240,18 @@ void TurnCursorOn( void )
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
switch (mouse_mode) {
|
switch (mouse_mode) {
|
||||||
case MOUSE_POINTER:
|
case MOUSE_POINTER:
|
||||||
glutSetCursor(GLUT_CURSOR_INHERIT);
|
fgSetMouseCursor(MOUSE_CURSOR_INHERIT);
|
||||||
break;
|
break;
|
||||||
case MOUSE_YOKE:
|
case MOUSE_YOKE:
|
||||||
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
|
fgSetMouseCursor(MOUSE_CURSOR_CROSSHAIR);
|
||||||
break;
|
break;
|
||||||
case MOUSE_VIEW:
|
case MOUSE_VIEW:
|
||||||
glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
|
fgSetMouseCursor(MOUSE_CURSOR_LEFT_RIGHT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(X_CURSOR_TWEAKS)
|
#if defined(X_CURSOR_TWEAKS)
|
||||||
glutWarpPointer( MOUSE_XSIZE/2,
|
fgWarpMouse( MOUSE_XSIZE/2, MOUSE_YSIZE/2 );
|
||||||
MOUSE_YSIZE/2);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,10 +259,9 @@ void TurnCursorOff( void )
|
||||||
{
|
{
|
||||||
mouse_active = 0;
|
mouse_active = 0;
|
||||||
#if defined(WIN32_CURSOR_TWEAKS)
|
#if defined(WIN32_CURSOR_TWEAKS)
|
||||||
glutSetCursor(GLUT_CURSOR_NONE);
|
fgSetMouseCursor(MOUSE_CURSOR_NONE);
|
||||||
#elif defined(X_CURSOR_TWEAKS)
|
#elif defined(X_CURSOR_TWEAKS)
|
||||||
glutWarpPointer( MOUSE_XSIZE,
|
fgWarpMouse( MOUSE_XSIZE, MOUSE_YSIZE );
|
||||||
MOUSE_YSIZE);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,15 +293,15 @@ void maybeToggleMouse( void )
|
||||||
// Call with FALSE to init and TRUE to restore
|
// Call with FALSE to init and TRUE to restore
|
||||||
void BusyCursor( int restore )
|
void BusyCursor( int restore )
|
||||||
{
|
{
|
||||||
static GLenum cursor = (GLenum) 0;
|
static int cursor = MOUSE_CURSOR_POINTER;
|
||||||
if( restore ) {
|
if( restore ) {
|
||||||
glutSetCursor(cursor);
|
fgSetMouseCursor(cursor);
|
||||||
} else {
|
} else {
|
||||||
cursor = (GLenum) glutGet( (GLenum) GLUT_WINDOW_CURSOR );
|
cursor = fgGetMouseCursor();
|
||||||
#if defined(WIN32_CURSOR_TWEAKS)
|
#if defined(WIN32_CURSOR_TWEAKS)
|
||||||
TurnCursorOn();
|
TurnCursorOn();
|
||||||
#endif
|
#endif
|
||||||
glutSetCursor( GLUT_CURSOR_WAIT );
|
fgSetMouseCursor( MOUSE_CURSOR_WAIT );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,14 +315,14 @@ void CenterView( void ) {
|
||||||
_mVtoggle = 0;
|
_mVtoggle = 0;
|
||||||
Quat0();
|
Quat0();
|
||||||
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
||||||
glutSetCursor(GLUT_CURSOR_INHERIT);
|
fgSetMouseCursor(MOUSE_CURSOR_POINTER);
|
||||||
|
|
||||||
// Is this necessary ??
|
// Is this necessary ??
|
||||||
#if defined(FG_OLD_MENU)
|
#if defined(FG_OLD_MENU)
|
||||||
if( !gui_menu_on ) TurnCursorOff();
|
if( !gui_menu_on ) TurnCursorOff();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
glutWarpPointer( _savedX, _savedY );
|
fgWarpMouse( _savedX, _savedY );
|
||||||
}
|
}
|
||||||
set_goal_view_offset(0.0);
|
set_goal_view_offset(0.0);
|
||||||
set_view_offset(0.0);
|
set_view_offset(0.0);
|
||||||
|
@ -386,7 +378,7 @@ void guiMotionFunc ( int x, int y )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
puMouse ( x, y ) ;
|
puMouse ( x, y ) ;
|
||||||
glutPostRedisplay () ;
|
fgRequestRedraw () ;
|
||||||
} else {
|
} else {
|
||||||
if( x == _mX && y == _mY)
|
if( x == _mX && y == _mY)
|
||||||
return;
|
return;
|
||||||
|
@ -501,7 +493,7 @@ void guiMotionFunc ( int x, int y )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( need_warp)
|
if( need_warp)
|
||||||
glutWarpPointer(x, y);
|
fgWarpMouse(x, y);
|
||||||
|
|
||||||
// Record the new mouse position.
|
// Record the new mouse position.
|
||||||
_mX = x;
|
_mX = x;
|
||||||
|
@ -511,7 +503,6 @@ void guiMotionFunc ( int x, int y )
|
||||||
|
|
||||||
void guiMouseFunc(int button, int updown, int x, int y)
|
void guiMouseFunc(int button, int updown, int x, int y)
|
||||||
{
|
{
|
||||||
int glutModifiers;
|
|
||||||
|
|
||||||
// private MOUSE_VIEW state variables
|
// private MOUSE_VIEW state variables
|
||||||
// to allow alternate left clicks in MOUSE_VIEW mode
|
// to allow alternate left clicks in MOUSE_VIEW mode
|
||||||
|
@ -521,14 +512,9 @@ void guiMouseFunc(int button, int updown, int x, int y)
|
||||||
static float _quat[4];
|
static float _quat[4];
|
||||||
static double _view_offset;
|
static double _view_offset;
|
||||||
|
|
||||||
glutModifiers = glutGetModifiers();
|
|
||||||
glut_active_shift = glutModifiers & GLUT_ACTIVE_SHIFT;
|
|
||||||
glut_active_ctrl = glutModifiers & GLUT_ACTIVE_CTRL;
|
|
||||||
glut_active_alt = glutModifiers & GLUT_ACTIVE_ALT;
|
|
||||||
|
|
||||||
// Was the left button pressed?
|
// Was the left button pressed?
|
||||||
if (updown == GLUT_DOWN ) {
|
if ( updown == MOUSE_BUTTON_DOWN ) {
|
||||||
if( button == GLUT_LEFT_BUTTON)
|
if( button == MOUSE_BUTTON_LEFT)
|
||||||
{
|
{
|
||||||
switch (mouse_mode) {
|
switch (mouse_mode) {
|
||||||
case MOUSE_POINTER:
|
case MOUSE_POINTER:
|
||||||
|
@ -566,12 +552,12 @@ void guiMouseFunc(int button, int updown, int x, int y)
|
||||||
set_view_tilt(0.0);
|
set_view_tilt(0.0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
glutWarpPointer( x , y);
|
fgWarpMouse( x , y);
|
||||||
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
||||||
_mVtoggle = ~_mVtoggle;
|
_mVtoggle = ~_mVtoggle;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if ( button == GLUT_RIGHT_BUTTON) {
|
} else if ( button == MOUSE_BUTTON_RIGHT) {
|
||||||
switch (mouse_mode) {
|
switch (mouse_mode) {
|
||||||
|
|
||||||
case MOUSE_POINTER:
|
case MOUSE_POINTER:
|
||||||
|
@ -590,7 +576,7 @@ void guiMouseFunc(int button, int updown, int x, int y)
|
||||||
x = _mX - (int)(get_aileron() * aileron_sensitivity);
|
x = _mX - (int)(get_aileron() * aileron_sensitivity);
|
||||||
y = _mY - (int)(get_elevator() * elevator_sensitivity);
|
y = _mY - (int)(get_elevator() * elevator_sensitivity);
|
||||||
|
|
||||||
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
|
fgSetMouseCursor(MOUSE_CURSOR_CROSSHAIR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MOUSE_YOKE:
|
case MOUSE_YOKE:
|
||||||
|
@ -607,7 +593,7 @@ void guiMouseFunc(int button, int updown, int x, int y)
|
||||||
Quat0();
|
Quat0();
|
||||||
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
build_rotmatrix(GuiQuat_mat, curGuiQuat);
|
||||||
// #endif
|
// #endif
|
||||||
glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
|
fgSetMouseCursor(MOUSE_CURSOR_LEFTRIGHT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MOUSE_VIEW:
|
case MOUSE_VIEW:
|
||||||
|
@ -626,7 +612,7 @@ void guiMouseFunc(int button, int updown, int x, int y)
|
||||||
set_view_tilt(0.0);
|
set_view_tilt(0.0);
|
||||||
#endif // NO_SMOOTH_MOUSE_VIEW
|
#endif // NO_SMOOTH_MOUSE_VIEW
|
||||||
#endif // RESET_VIEW_ON_LEAVING_MOUSE_VIEW
|
#endif // RESET_VIEW_ON_LEAVING_MOUSE_VIEW
|
||||||
glutSetCursor(GLUT_CURSOR_INHERIT);
|
fgSetMouseCursor(MOUSE_CURSOR_POINTER);
|
||||||
|
|
||||||
#if defined(FG_OLD_MENU)
|
#if defined(FG_OLD_MENU)
|
||||||
#if defined(WIN32_CURSOR_TWEAKS_OFF)
|
#if defined(WIN32_CURSOR_TWEAKS_OFF)
|
||||||
|
@ -636,12 +622,12 @@ void guiMouseFunc(int button, int updown, int x, int y)
|
||||||
#endif // FG_OLD_MENU
|
#endif // FG_OLD_MENU
|
||||||
break;
|
break;
|
||||||
} // end switch (mouse_mode)
|
} // end switch (mouse_mode)
|
||||||
glutWarpPointer( x, y );
|
fgWarpMouse( x, y );
|
||||||
} // END RIGHT BUTTON
|
} // END RIGHT BUTTON
|
||||||
} // END UPDOWN == GLUT_DOWN
|
} // END MOUSE DOWN
|
||||||
|
|
||||||
// Note which button is pressed.
|
// Update the button state
|
||||||
if ( updown == GLUT_DOWN ) {
|
if ( updown == MOUSE_BUTTON_DOWN ) {
|
||||||
last_buttons |= ( 1 << button ) ;
|
last_buttons |= ( 1 << button ) ;
|
||||||
} else {
|
} else {
|
||||||
last_buttons &= ~( 1 << button ) ;
|
last_buttons &= ~( 1 << button ) ;
|
||||||
|
@ -650,7 +636,7 @@ void guiMouseFunc(int button, int updown, int x, int y)
|
||||||
// If we're in pointer mode, let PUI
|
// If we're in pointer mode, let PUI
|
||||||
// know what's going on.
|
// know what's going on.
|
||||||
if (mouse_mode == MOUSE_POINTER) {
|
if (mouse_mode == MOUSE_POINTER) {
|
||||||
if (!puMouse (button, updown, x,y)) {
|
if (!puMouse (button, updown , x,y)) {
|
||||||
if ( globals->get_current_panel() != NULL ) {
|
if ( globals->get_current_panel() != NULL ) {
|
||||||
globals->get_current_panel()->doMouseAction(button, updown, x, y);
|
globals->get_current_panel()->doMouseAction(button, updown, x, y);
|
||||||
}
|
}
|
||||||
|
@ -662,7 +648,7 @@ void guiMouseFunc(int button, int updown, int x, int y)
|
||||||
_mX = x;
|
_mX = x;
|
||||||
_mY = y;
|
_mY = y;
|
||||||
|
|
||||||
glutPostRedisplay ();
|
fgRequestRedraw ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,10 +37,6 @@
|
||||||
#include STL_STRING
|
#include STL_STRING
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include FG_GLUT_H
|
|
||||||
|
|
||||||
#include <plib/pu.h>
|
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
|
|
||||||
#include <simgear/constants.h>
|
#include <simgear/constants.h>
|
||||||
|
@ -64,6 +60,9 @@ SG_USING_STD(ifstream);
|
||||||
SG_USING_STD(string);
|
SG_USING_STD(string);
|
||||||
SG_USING_STD(vector);
|
SG_USING_STD(vector);
|
||||||
|
|
||||||
|
void mouseClickHandler(int button, int updown, int x, int y);
|
||||||
|
void mouseMotionHandler(int x, int y);
|
||||||
|
void keyHandler(int key, int keymod, int mousex, int mousey);
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -175,13 +174,9 @@ FGInput::init ()
|
||||||
_init_joystick();
|
_init_joystick();
|
||||||
_init_mouse();
|
_init_mouse();
|
||||||
|
|
||||||
glutKeyboardFunc(GLUTkey);
|
fgRegisterKeyHandler(keyHandler);
|
||||||
glutKeyboardUpFunc(GLUTkeyup);
|
fgRegisterMouseClickHandler(mouseClickHandler);
|
||||||
glutSpecialFunc(GLUTspecialkey);
|
fgRegisterMouseMotionHandler(mouseMotionHandler);
|
||||||
glutSpecialUpFunc(GLUTspecialkeyup);
|
|
||||||
glutMouseFunc (GLUTmouse);
|
|
||||||
glutMotionFunc (GLUTmotion);
|
|
||||||
glutPassiveMotionFunc (GLUTmotion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -234,7 +229,7 @@ FGInput::doKey (int k, int modifiers, int x, int y)
|
||||||
button &b = _key_bindings[k];
|
button &b = _key_bindings[k];
|
||||||
|
|
||||||
// Key pressed.
|
// Key pressed.
|
||||||
if (modifiers&FG_MOD_UP == 0) {
|
if (modifiers&KEYMOD_RELEASED == 0) {
|
||||||
SG_LOG( SG_INPUT, SG_DEBUG, "User pressed key " << k
|
SG_LOG( SG_INPUT, SG_DEBUG, "User pressed key " << k
|
||||||
<< " with modifiers " << modifiers );
|
<< " with modifiers " << modifiers );
|
||||||
if (!b.last_state || b.is_repeatable) {
|
if (!b.last_state || b.is_repeatable) {
|
||||||
|
@ -268,62 +263,19 @@ FGInput::doKey (int k, int modifiers, int x, int y)
|
||||||
|
|
||||||
// Use the old, default actions.
|
// Use the old, default actions.
|
||||||
SG_LOG( SG_INPUT, SG_DEBUG, "(No user binding.)" );
|
SG_LOG( SG_INPUT, SG_DEBUG, "(No user binding.)" );
|
||||||
if (modifiers&FG_MOD_UP)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// everything after here will be removed sooner or later...
|
|
||||||
|
|
||||||
if (modifiers & FG_MOD_SHIFT) {
|
|
||||||
|
|
||||||
switch (k) {
|
|
||||||
case 72: // H key
|
|
||||||
HUD_brightkey( true );
|
|
||||||
return;
|
|
||||||
case 73: // I key
|
|
||||||
// Minimal Hud
|
|
||||||
fgHUDInit2(¤t_aircraft);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
SG_LOG( SG_INPUT, SG_DEBUG, "" );
|
|
||||||
switch (k) {
|
|
||||||
case 104: // h key
|
|
||||||
HUD_masterswitch( true );
|
|
||||||
return;
|
|
||||||
case 105: // i key
|
|
||||||
fgHUDInit(¤t_aircraft); // normal HUD
|
|
||||||
return;
|
|
||||||
|
|
||||||
// START SPECIALS
|
|
||||||
|
|
||||||
case 256+GLUT_KEY_F6: // F6 toggles Autopilot target location
|
|
||||||
if ( strcmp( heading_enabled->getStringValue(),
|
|
||||||
"true-heading-hold" ) != 0 ) {
|
|
||||||
heading_enabled->setStringValue( "true-heading-hold" );
|
|
||||||
} else {
|
|
||||||
heading_enabled->setStringValue( "" );
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// END SPECIALS
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FGInput::doMouseClick (int b, int updown, int x, int y)
|
FGInput::doMouseClick (int b, int updown, int x, int y)
|
||||||
{
|
{
|
||||||
int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones?
|
int modifiers = fgGetKeyModifiers();
|
||||||
|
|
||||||
mouse &m = _mouse_bindings[0];
|
mouse &m = _mouse_bindings[0];
|
||||||
mouse_mode &mode = m.modes[m.current_mode];
|
mouse_mode &mode = m.modes[m.current_mode];
|
||||||
|
|
||||||
// Let the property manager know.
|
// Let the property manager know.
|
||||||
if (b >= 0 && b < MAX_MOUSE_BUTTONS)
|
if (b >= 0 && b < MAX_MOUSE_BUTTONS)
|
||||||
m.mouse_button_nodes[b]->setBoolValue(updown == GLUT_DOWN);
|
m.mouse_button_nodes[b]->setBoolValue(updown == MOUSE_BUTTON_DOWN);
|
||||||
|
|
||||||
// Pass on to PUI and the panel if
|
// Pass on to PUI and the panel if
|
||||||
// requested, and return if one of
|
// requested, and return if one of
|
||||||
|
@ -352,7 +304,7 @@ FGInput::doMouseClick (int b, int updown, int x, int y)
|
||||||
void
|
void
|
||||||
FGInput::doMouseMotion (int x, int y)
|
FGInput::doMouseMotion (int x, int y)
|
||||||
{
|
{
|
||||||
int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones?
|
int modifiers = fgGetKeyModifiers();
|
||||||
|
|
||||||
int xsize = fgGetInt("/sim/startup/xsize", 800);
|
int xsize = fgGetInt("/sim/startup/xsize", 800);
|
||||||
int ysize = fgGetInt("/sim/startup/ysize", 600);
|
int ysize = fgGetInt("/sim/startup/ysize", 600);
|
||||||
|
@ -399,7 +351,7 @@ FGInput::doMouseMotion (int x, int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (need_warp)
|
if (need_warp)
|
||||||
glutWarpPointer(x, y);
|
fgWarpMouse(x, y);
|
||||||
}
|
}
|
||||||
m.x = x;
|
m.x = x;
|
||||||
m.y = y;
|
m.y = y;
|
||||||
|
@ -422,7 +374,7 @@ FGInput::_init_keyboard ()
|
||||||
|
|
||||||
_key_bindings[index].bindings->clear();
|
_key_bindings[index].bindings->clear();
|
||||||
_key_bindings[index].is_repeatable = keys[i]->getBoolValue("repeatable");
|
_key_bindings[index].is_repeatable = keys[i]->getBoolValue("repeatable");
|
||||||
_read_bindings(keys[i], _key_bindings[index].bindings, FG_MOD_NONE);
|
_read_bindings(keys[i], _key_bindings[index].bindings, KEYMOD_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,7 +475,7 @@ FGInput::_init_joystick ()
|
||||||
maxRange[j] = axis_node->getDoubleValue("max-range", maxRange[j]);
|
maxRange[j] = axis_node->getDoubleValue("max-range", maxRange[j]);
|
||||||
center[j] = axis_node->getDoubleValue("center", center[j]);
|
center[j] = axis_node->getDoubleValue("center", center[j]);
|
||||||
|
|
||||||
_read_bindings(axis_node, a.bindings, FG_MOD_NONE);
|
_read_bindings(axis_node, a.bindings, KEYMOD_NONE);
|
||||||
|
|
||||||
// Initialize the virtual axis buttons.
|
// Initialize the virtual axis buttons.
|
||||||
_init_button(axis_node->getChild("low"), a.low, "low");
|
_init_button(axis_node->getChild("low"), a.low, "low");
|
||||||
|
@ -562,40 +514,26 @@ FGInput::_init_joystick ()
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Map of all known GLUT cursor names
|
// Map of all known cursor names
|
||||||
|
// This used to contain all the Glut cursors, but those are
|
||||||
|
// not defined by other toolkits. It now supports only the cursor
|
||||||
|
// images we actually use, in the interest of portability. Someday,
|
||||||
|
// it would be cool to write an OpenGL cursor renderer, with the
|
||||||
|
// cursors defined as textures referenced in the property tree. This
|
||||||
|
// list could then be eliminated. -Andy
|
||||||
//
|
//
|
||||||
struct {
|
struct {
|
||||||
const char * name;
|
const char * name;
|
||||||
int cursor;
|
int cursor;
|
||||||
} mouse_cursor_map[] = {
|
} mouse_cursor_map[] = {
|
||||||
{ "right-arrow", GLUT_CURSOR_RIGHT_ARROW },
|
{ "none", MOUSE_CURSOR_NONE },
|
||||||
{ "left-arrow", GLUT_CURSOR_LEFT_ARROW },
|
{ "inherit", MOUSE_CURSOR_POINTER },
|
||||||
{ "info", GLUT_CURSOR_INFO },
|
{ "wait", MOUSE_CURSOR_WAIT },
|
||||||
{ "destroy", GLUT_CURSOR_DESTROY },
|
{ "crosshair", MOUSE_CURSOR_CROSSHAIR },
|
||||||
{ "help", GLUT_CURSOR_HELP },
|
{ "left-right", MOUSE_CURSOR_LEFTRIGHT },
|
||||||
{ "cycle", GLUT_CURSOR_CYCLE },
|
|
||||||
{ "spray", GLUT_CURSOR_SPRAY },
|
|
||||||
{ "wait", GLUT_CURSOR_WAIT },
|
|
||||||
{ "text", GLUT_CURSOR_TEXT },
|
|
||||||
{ "crosshair", GLUT_CURSOR_CROSSHAIR },
|
|
||||||
{ "up-down", GLUT_CURSOR_UP_DOWN },
|
|
||||||
{ "left-right", GLUT_CURSOR_LEFT_RIGHT },
|
|
||||||
{ "top-side", GLUT_CURSOR_TOP_SIDE },
|
|
||||||
{ "bottom-side", GLUT_CURSOR_BOTTOM_SIDE },
|
|
||||||
{ "left-side", GLUT_CURSOR_LEFT_SIDE },
|
|
||||||
{ "right-side", GLUT_CURSOR_RIGHT_SIDE },
|
|
||||||
{ "top-left-corner", GLUT_CURSOR_TOP_LEFT_CORNER },
|
|
||||||
{ "top-right-corner", GLUT_CURSOR_TOP_RIGHT_CORNER },
|
|
||||||
{ "bottom-right-corner", GLUT_CURSOR_BOTTOM_RIGHT_CORNER },
|
|
||||||
{ "bottom-left-corner", GLUT_CURSOR_BOTTOM_LEFT_CORNER },
|
|
||||||
{ "inherit", GLUT_CURSOR_INHERIT },
|
|
||||||
{ "none", GLUT_CURSOR_NONE },
|
|
||||||
{ "full-crosshair", GLUT_CURSOR_FULL_CROSSHAIR },
|
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FGInput::_init_mouse ()
|
FGInput::_init_mouse ()
|
||||||
{
|
{
|
||||||
|
@ -637,7 +575,7 @@ FGInput::_init_mouse ()
|
||||||
SGPropertyNode * mode_node = mouse_node->getChild("mode", j, true);
|
SGPropertyNode * mode_node = mouse_node->getChild("mode", j, true);
|
||||||
const char * cursor_name =
|
const char * cursor_name =
|
||||||
mode_node->getStringValue("cursor", "inherit");
|
mode_node->getStringValue("cursor", "inherit");
|
||||||
m.modes[j].cursor = GLUT_CURSOR_INHERIT;
|
m.modes[j].cursor = MOUSE_CURSOR_POINTER;
|
||||||
for (k = 0; mouse_cursor_map[k].name != 0; k++) {
|
for (k = 0; mouse_cursor_map[k].name != 0; k++) {
|
||||||
if (!strcmp(mouse_cursor_map[k].name, cursor_name)) {
|
if (!strcmp(mouse_cursor_map[k].name, cursor_name)) {
|
||||||
m.modes[j].cursor = mouse_cursor_map[k].cursor;
|
m.modes[j].cursor = mouse_cursor_map[k].cursor;
|
||||||
|
@ -663,10 +601,10 @@ FGInput::_init_mouse ()
|
||||||
// Read the axis bindings for this mode
|
// Read the axis bindings for this mode
|
||||||
_read_bindings(mode_node->getChild("x-axis", 0, true),
|
_read_bindings(mode_node->getChild("x-axis", 0, true),
|
||||||
m.modes[j].x_bindings,
|
m.modes[j].x_bindings,
|
||||||
FG_MOD_NONE);
|
KEYMOD_NONE);
|
||||||
_read_bindings(mode_node->getChild("y-axis", 0, true),
|
_read_bindings(mode_node->getChild("y-axis", 0, true),
|
||||||
m.modes[j].y_bindings,
|
m.modes[j].y_bindings,
|
||||||
FG_MOD_NONE);
|
KEYMOD_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -683,7 +621,7 @@ FGInput::_init_button (const SGPropertyNode * node,
|
||||||
b.is_repeatable = node->getBoolValue("repeatable", b.is_repeatable);
|
b.is_repeatable = node->getBoolValue("repeatable", b.is_repeatable);
|
||||||
|
|
||||||
// Get the bindings for the button
|
// Get the bindings for the button
|
||||||
_read_bindings(node, b.bindings, FG_MOD_NONE);
|
_read_bindings(node, b.bindings, KEYMOD_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,7 +636,7 @@ FGInput::_update_keyboard ()
|
||||||
void
|
void
|
||||||
FGInput::_update_joystick (double dt)
|
FGInput::_update_joystick (double dt)
|
||||||
{
|
{
|
||||||
int modifiers = FG_MOD_NONE; // FIXME: any way to get the real ones?
|
int modifiers = KEYMOD_NONE; // FIXME: any way to get the real ones?
|
||||||
int buttons;
|
int buttons;
|
||||||
// float js_val, diff;
|
// float js_val, diff;
|
||||||
float axis_values[MAX_JOYSTICK_AXES];
|
float axis_values[MAX_JOYSTICK_AXES];
|
||||||
|
@ -773,13 +711,13 @@ FGInput::_update_mouse ()
|
||||||
if (mode != m.current_mode) {
|
if (mode != m.current_mode) {
|
||||||
m.current_mode = mode;
|
m.current_mode = mode;
|
||||||
if (mode >= 0 && mode < m.nModes) {
|
if (mode >= 0 && mode < m.nModes) {
|
||||||
glutSetCursor(m.modes[mode].cursor);
|
fgSetMouseCursor(m.modes[mode].cursor);
|
||||||
m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
|
m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
|
||||||
m.y = fgGetInt("/sim/startup/ysize", 600) / 2;
|
m.y = fgGetInt("/sim/startup/ysize", 600) / 2;
|
||||||
glutWarpPointer(m.x, m.y);
|
fgWarpMouse(m.x, m.y);
|
||||||
} else {
|
} else {
|
||||||
SG_LOG(SG_INPUT, SG_DEBUG, "Mouse mode " << mode << " out of range");
|
SG_LOG(SG_INPUT, SG_DEBUG, "Mouse mode " << mode << " out of range");
|
||||||
glutSetCursor(GLUT_CURSOR_INHERIT);
|
fgSetMouseCursor(MOUSE_CURSOR_POINTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -799,8 +737,8 @@ FGInput::_update_button (button &b, int modifiers, bool pressed,
|
||||||
// The release event is never repeated.
|
// The release event is never repeated.
|
||||||
if (b.last_state) {
|
if (b.last_state) {
|
||||||
SG_LOG( SG_INPUT, SG_DEBUG, "Button has been released" );
|
SG_LOG( SG_INPUT, SG_DEBUG, "Button has been released" );
|
||||||
for (unsigned int k = 0; k < b.bindings[modifiers|FG_MOD_UP].size(); k++)
|
for (unsigned int k = 0; k < b.bindings[modifiers|KEYMOD_RELEASED].size(); k++)
|
||||||
b.bindings[modifiers|FG_MOD_UP][k]->fire(x, y);
|
b.bindings[modifiers|KEYMOD_RELEASED][k]->fire(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,19 +762,19 @@ FGInput::_read_bindings (const SGPropertyNode * node,
|
||||||
// Read nested bindings for modifiers
|
// Read nested bindings for modifiers
|
||||||
if (node->getChild("mod-up") != 0)
|
if (node->getChild("mod-up") != 0)
|
||||||
_read_bindings(node->getChild("mod-up"), binding_list,
|
_read_bindings(node->getChild("mod-up"), binding_list,
|
||||||
modifiers|FG_MOD_UP);
|
modifiers|KEYMOD_RELEASED);
|
||||||
|
|
||||||
if (node->getChild("mod-shift") != 0)
|
if (node->getChild("mod-shift") != 0)
|
||||||
_read_bindings(node->getChild("mod-shift"), binding_list,
|
_read_bindings(node->getChild("mod-shift"), binding_list,
|
||||||
modifiers|FG_MOD_SHIFT);
|
modifiers|KEYMOD_SHIFT);
|
||||||
|
|
||||||
if (node->getChild("mod-ctrl") != 0)
|
if (node->getChild("mod-ctrl") != 0)
|
||||||
_read_bindings(node->getChild("mod-ctrl"), binding_list,
|
_read_bindings(node->getChild("mod-ctrl"), binding_list,
|
||||||
modifiers|FG_MOD_CTRL);
|
modifiers|KEYMOD_CTRL);
|
||||||
|
|
||||||
if (node->getChild("mod-alt") != 0)
|
if (node->getChild("mod-alt") != 0)
|
||||||
_read_bindings(node->getChild("mod-alt"), binding_list,
|
_read_bindings(node->getChild("mod-alt"), binding_list,
|
||||||
modifiers|FG_MOD_ALT);
|
modifiers|KEYMOD_ALT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -851,25 +789,25 @@ FGInput::_find_key_bindings (unsigned int k, int modifiers)
|
||||||
return b.bindings[modifiers];
|
return b.bindings[modifiers];
|
||||||
|
|
||||||
// Alt-Gr is CTRL+ALT
|
// Alt-Gr is CTRL+ALT
|
||||||
else if (modifiers&(FG_MOD_CTRL|FG_MOD_ALT))
|
else if (modifiers&(KEYMOD_CTRL|KEYMOD_ALT))
|
||||||
return _find_key_bindings(k, modifiers&~(FG_MOD_CTRL|FG_MOD_ALT));
|
return _find_key_bindings(k, modifiers&~(KEYMOD_CTRL|KEYMOD_ALT));
|
||||||
|
|
||||||
// Try removing the control modifier
|
// Try removing the control modifier
|
||||||
// for control keys.
|
// for control keys.
|
||||||
else if ((modifiers&FG_MOD_CTRL) && iscntrl(kc))
|
else if ((modifiers&KEYMOD_CTRL) && iscntrl(kc))
|
||||||
return _find_key_bindings(k, modifiers&~FG_MOD_CTRL);
|
return _find_key_bindings(k, modifiers&~KEYMOD_CTRL);
|
||||||
|
|
||||||
// Try removing shift modifier
|
// Try removing shift modifier
|
||||||
// for upper case or any punctuation
|
// for upper case or any punctuation
|
||||||
// (since different keyboards will
|
// (since different keyboards will
|
||||||
// shift different punctuation types)
|
// shift different punctuation types)
|
||||||
else if ((modifiers&FG_MOD_SHIFT) && (isupper(kc) || ispunct(kc)))
|
else if ((modifiers&KEYMOD_SHIFT) && (isupper(kc) || ispunct(kc)))
|
||||||
return _find_key_bindings(k, modifiers&~FG_MOD_SHIFT);
|
return _find_key_bindings(k, modifiers&~KEYMOD_SHIFT);
|
||||||
|
|
||||||
// Try removing alt modifier for
|
// Try removing alt modifier for
|
||||||
// high-bit characters.
|
// high-bit characters.
|
||||||
else if ((modifiers&FG_MOD_ALT) && k >= 128 && k < 256)
|
else if ((modifiers&KEYMOD_ALT) && k >= 128 && k < 256)
|
||||||
return _find_key_bindings(k, modifiers&~FG_MOD_ALT);
|
return _find_key_bindings(k, modifiers&~KEYMOD_ALT);
|
||||||
|
|
||||||
// Give up and return the empty vector.
|
// Give up and return the empty vector.
|
||||||
else
|
else
|
||||||
|
@ -891,7 +829,7 @@ FGInput::button::button ()
|
||||||
FGInput::button::~button ()
|
FGInput::button::~button ()
|
||||||
{
|
{
|
||||||
// FIXME: memory leak
|
// FIXME: memory leak
|
||||||
// for (int i = 0; i < FG_MOD_MAX; i++)
|
// for (int i = 0; i < KEYMOD_MAX; i++)
|
||||||
// for (int j = 0; i < bindings[i].size(); j++)
|
// for (int j = 0; i < bindings[i].size(); j++)
|
||||||
// delete bindings[i][j];
|
// delete bindings[i][j];
|
||||||
}
|
}
|
||||||
|
@ -912,7 +850,7 @@ FGInput::axis::axis ()
|
||||||
|
|
||||||
FGInput::axis::~axis ()
|
FGInput::axis::~axis ()
|
||||||
{
|
{
|
||||||
// for (int i = 0; i < FG_MOD_MAX; i++)
|
// for (int i = 0; i < KEYMOD_MAX; i++)
|
||||||
// for (int j = 0; i < bindings[i].size(); j++)
|
// for (int j = 0; i < bindings[i].size(); j++)
|
||||||
// delete bindings[i][j];
|
// delete bindings[i][j];
|
||||||
}
|
}
|
||||||
|
@ -941,7 +879,7 @@ FGInput::joystick::~joystick ()
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
FGInput::mouse_mode::mouse_mode ()
|
FGInput::mouse_mode::mouse_mode ()
|
||||||
: cursor(GLUT_CURSOR_INHERIT),
|
: cursor(MOUSE_CURSOR_POINTER),
|
||||||
constrained(false),
|
constrained(false),
|
||||||
pass_through(false),
|
pass_through(false),
|
||||||
buttons(0)
|
buttons(0)
|
||||||
|
@ -951,7 +889,7 @@ FGInput::mouse_mode::mouse_mode ()
|
||||||
FGInput::mouse_mode::~mouse_mode ()
|
FGInput::mouse_mode::~mouse_mode ()
|
||||||
{
|
{
|
||||||
// FIXME: memory leak
|
// FIXME: memory leak
|
||||||
// for (int i = 0; i < FG_MOD_MAX; i++) {
|
// for (int i = 0; i < KEYMOD_MAX; i++) {
|
||||||
// int j;
|
// int j;
|
||||||
// for (j = 0; i < x_bindings[i].size(); j++)
|
// for (j = 0; i < x_bindings[i].size(); j++)
|
||||||
// delete bindings[i][j];
|
// delete bindings[i][j];
|
||||||
|
@ -981,83 +919,28 @@ FGInput::mouse::~mouse ()
|
||||||
delete [] modes;
|
delete [] modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Implementation of GLUT callbacks.
|
// Implementation of OS callbacks.
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void keyHandler(int key, int keymod, int mousex, int mousey)
|
||||||
/**
|
|
||||||
* Construct the modifiers.
|
|
||||||
*/
|
|
||||||
static inline int get_mods ()
|
|
||||||
{
|
{
|
||||||
int glut_modifiers = glutGetModifiers();
|
if((keymod & KEYMOD_RELEASED) == 0)
|
||||||
int modifiers = 0;
|
if(puKeyboard(key, PU_DOWN))
|
||||||
|
return;
|
||||||
|
|
||||||
if (glut_modifiers & GLUT_ACTIVE_SHIFT)
|
if(default_input)
|
||||||
modifiers |= FGInput::FG_MOD_SHIFT;
|
default_input->doKey(key, keymod, mousex, mousey);
|
||||||
if (glut_modifiers & GLUT_ACTIVE_CTRL)
|
|
||||||
modifiers |= FGInput::FG_MOD_CTRL;
|
|
||||||
if (glut_modifiers & GLUT_ACTIVE_ALT)
|
|
||||||
modifiers |= FGInput::FG_MOD_ALT;
|
|
||||||
|
|
||||||
return modifiers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mouseClickHandler(int button, int updown, int x, int y)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
|
||||||
// GLUT C callbacks.
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void
|
|
||||||
GLUTkey(unsigned char k, int x, int y)
|
|
||||||
{
|
{
|
||||||
// Give PUI a chance to grab it first.
|
if(default_input)
|
||||||
if (!puKeyboard(k, PU_DOWN)) {
|
|
||||||
if (default_input != 0)
|
|
||||||
default_input->doKey(k, get_mods(), x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
GLUTkeyup(unsigned char k, int x, int y)
|
|
||||||
{
|
|
||||||
if (default_input != 0)
|
|
||||||
default_input->doKey(k, get_mods()|FGInput::FG_MOD_UP, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
GLUTspecialkey(int k, int x, int y)
|
|
||||||
{
|
|
||||||
// Give PUI a chance to grab it first.
|
|
||||||
if (!puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN)) {
|
|
||||||
if (default_input != 0)
|
|
||||||
default_input->doKey(k + 256, get_mods(), x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
GLUTspecialkeyup(int k, int x, int y)
|
|
||||||
{
|
|
||||||
if (default_input != 0)
|
|
||||||
default_input->doKey(k + 256, get_mods()|FGInput::FG_MOD_UP, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
GLUTmouse (int button, int updown, int x, int y)
|
|
||||||
{
|
|
||||||
if (default_input != 0)
|
|
||||||
default_input->doMouseClick(button, updown, x, y);
|
default_input->doMouseClick(button, updown, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void mouseMotionHandler(int x, int y)
|
||||||
GLUTmotion (int x, int y)
|
|
||||||
{
|
{
|
||||||
if (default_input != 0)
|
if (default_input != 0)
|
||||||
default_input->doMouseMotion(x, y);
|
default_input->doMouseMotion(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// end of input.cxx
|
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <simgear/props/condition.hxx>
|
#include <simgear/props/condition.hxx>
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
|
|
||||||
|
#include <Main/fg_os.hxx>
|
||||||
#include <Main/fg_props.hxx>
|
#include <Main/fg_props.hxx>
|
||||||
#include <Main/globals.hxx>
|
#include <Main/globals.hxx>
|
||||||
|
|
||||||
|
@ -169,23 +170,11 @@ private:
|
||||||
class FGInput : public SGSubsystem
|
class FGInput : public SGSubsystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum {
|
|
||||||
FG_MOD_NONE = 0,
|
|
||||||
FG_MOD_UP = 1, // key- or button-up
|
|
||||||
FG_MOD_SHIFT = 2,
|
|
||||||
FG_MOD_CTRL = 4,
|
|
||||||
FG_MOD_ALT = 8,
|
|
||||||
FG_MOD_MAX = 16 // enough to handle all combinations
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
*/
|
*/
|
||||||
FGInput ();
|
FGInput ();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor.
|
* Destructor.
|
||||||
*/
|
*/
|
||||||
|
@ -216,16 +205,10 @@ public:
|
||||||
/**
|
/**
|
||||||
* Handle a single keystroke.
|
* Handle a single keystroke.
|
||||||
*
|
*
|
||||||
* <p>Note: for special keys, the integer key code will be the Glut
|
* @param k The integer key code, see Main/fg_os.hxx
|
||||||
* code + 256.</p>
|
|
||||||
*
|
|
||||||
* @param k The integer key code, as returned by glut.
|
|
||||||
* @param modifiers Modifier keys pressed (bitfield).
|
* @param modifiers Modifier keys pressed (bitfield).
|
||||||
* @param x The mouse x position at the time of keypress.
|
* @param x The mouse x position at the time of keypress.
|
||||||
* @param y The mouse y position at the time of keypress.
|
* @param y The mouse y position at the time of keypress.
|
||||||
* @see #FG_MOD_SHIFT
|
|
||||||
* @see #FG_MOD_CTRL
|
|
||||||
* @see #FG_MOD_ALT
|
|
||||||
*/
|
*/
|
||||||
virtual void doKey (int k, int modifiers, int x, int y);
|
virtual void doKey (int k, int modifiers, int x, int y);
|
||||||
|
|
||||||
|
@ -282,7 +265,7 @@ private:
|
||||||
float interval_sec;
|
float interval_sec;
|
||||||
float last_dt;
|
float last_dt;
|
||||||
int last_state;
|
int last_state;
|
||||||
binding_list_t bindings[FG_MOD_MAX];
|
binding_list_t bindings[KEYMOD_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -294,7 +277,7 @@ private:
|
||||||
virtual ~axis ();
|
virtual ~axis ();
|
||||||
float last_value;
|
float last_value;
|
||||||
float tolerance;
|
float tolerance;
|
||||||
binding_list_t bindings[FG_MOD_MAX];
|
binding_list_t bindings[KEYMOD_MAX];
|
||||||
float low_threshold;
|
float low_threshold;
|
||||||
float high_threshold;
|
float high_threshold;
|
||||||
struct button low;
|
struct button low;
|
||||||
|
@ -329,8 +312,8 @@ private:
|
||||||
bool constrained;
|
bool constrained;
|
||||||
bool pass_through;
|
bool pass_through;
|
||||||
button * buttons;
|
button * buttons;
|
||||||
binding_list_t x_bindings[FG_MOD_MAX];
|
binding_list_t x_bindings[KEYMOD_MAX];
|
||||||
binding_list_t y_bindings[FG_MOD_MAX];
|
binding_list_t y_bindings[KEYMOD_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -420,83 +403,4 @@ private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
|
||||||
// GLUT callbacks.
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// Handle GLUT events.
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Key-down event handler for Glut.
|
|
||||||
*
|
|
||||||
* <p>Pass the value on to the FGInput module unless PUI wants it.</p>
|
|
||||||
*
|
|
||||||
* @param k The integer value for the key pressed.
|
|
||||||
* @param x (unused)
|
|
||||||
* @param y (unused)
|
|
||||||
*/
|
|
||||||
void GLUTkey (unsigned char k, int x, int y);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Key-up event handler for GLUT.
|
|
||||||
*
|
|
||||||
* <p>PUI doesn't use this, so always pass it to the input manager.</p>
|
|
||||||
*
|
|
||||||
* @param k The integer value for the key pressed.
|
|
||||||
* @param x (unused)
|
|
||||||
* @param y (unused)
|
|
||||||
*/
|
|
||||||
void GLUTkeyup (unsigned char k, int x, int y);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Special key-down handler for Glut.
|
|
||||||
*
|
|
||||||
* <p>Pass the value on to the FGInput module unless PUI wants it.
|
|
||||||
* The key value will have 256 added to it.</p>
|
|
||||||
*
|
|
||||||
* @param k The integer value for the key pressed (will have 256 added
|
|
||||||
* to it).
|
|
||||||
* @param x (unused)
|
|
||||||
* @param y (unused)
|
|
||||||
*/
|
|
||||||
void GLUTspecialkey (int k, int x, int y);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Special key-up handler for Glut.
|
|
||||||
*
|
|
||||||
* @param k The integer value for the key pressed (will have 256 added
|
|
||||||
* to it).
|
|
||||||
* @param x (unused)
|
|
||||||
* @param y (unused)
|
|
||||||
*/
|
|
||||||
void GLUTspecialkeyup (int k, int x, int y);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mouse click handler for Glut.
|
|
||||||
*
|
|
||||||
* @param button The mouse button pressed.
|
|
||||||
* @param updown Press or release flag.
|
|
||||||
* @param x The x-location of the click.
|
|
||||||
* @param y The y-location of the click.
|
|
||||||
*/
|
|
||||||
void GLUTmouse (int button, int updown, int x, int y);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mouse motion handler for Glut.
|
|
||||||
*
|
|
||||||
* @param x The new x-location of the mouse.
|
|
||||||
* @param y The new y-location of the mouse.
|
|
||||||
*/
|
|
||||||
void GLUTmotion (int x, int y);
|
|
||||||
|
|
||||||
} // extern "C"
|
|
||||||
|
|
||||||
#endif // _INPUT_HXX
|
#endif // _INPUT_HXX
|
||||||
|
|
|
@ -40,7 +40,8 @@ libMain_a_SOURCES = \
|
||||||
splash.cxx splash.hxx \
|
splash.cxx splash.hxx \
|
||||||
util.cxx util.hxx \
|
util.cxx util.hxx \
|
||||||
viewer.cxx viewer.hxx \
|
viewer.cxx viewer.hxx \
|
||||||
viewmgr.cxx viewmgr.hxx
|
viewmgr.cxx viewmgr.hxx \
|
||||||
|
fg_os.cxx fg_os.hxx
|
||||||
|
|
||||||
fgfs_SOURCES = bootstrap.cxx
|
fgfs_SOURCES = bootstrap.cxx
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ SG_USING_STD(endl);
|
||||||
# include <float.h>
|
# include <float.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include FG_GLUT_H
|
#include "fg_os.hxx"
|
||||||
|
|
||||||
#ifdef macintosh
|
#ifdef macintosh
|
||||||
# include <console.h> // -dw- for command line dialog
|
# include <console.h> // -dw- for command line dialog
|
||||||
|
@ -133,7 +133,7 @@ int main ( int argc, char **argv ) {
|
||||||
{
|
{
|
||||||
PSN psn;
|
PSN psn;
|
||||||
|
|
||||||
glutInit (&argc, argv);
|
fgOSInit (&argc, argv);
|
||||||
|
|
||||||
CPSGetCurrentProcess(&psn);
|
CPSGetCurrentProcess(&psn);
|
||||||
CPSSetProcessName(&psn, "FlightGear");
|
CPSSetProcessName(&psn, "FlightGear");
|
||||||
|
|
200
src/Main/fg_os.cxx
Normal file
200
src/Main/fg_os.cxx
Normal file
|
@ -0,0 +1,200 @@
|
||||||
|
// The mac puts this in a weird location (GLUT/glut.h), so the
|
||||||
|
// configure script detects the location and defines it as a macro.
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
# include FG_GLUT_H
|
||||||
|
#else
|
||||||
|
# include <GL/glut.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <plib/pu.h>
|
||||||
|
|
||||||
|
#include "fg_os.hxx"
|
||||||
|
|
||||||
|
//
|
||||||
|
// fg_os callback registration APIs
|
||||||
|
// (These are not glut-specific)
|
||||||
|
//
|
||||||
|
|
||||||
|
static fgIdleHandler IdleHandler = 0;
|
||||||
|
static fgDrawHandler DrawHandler = 0;
|
||||||
|
static fgWindowResizeHandler WindowResizeHandler = 0;
|
||||||
|
static fgKeyHandler KeyHandler = 0;
|
||||||
|
static fgMouseClickHandler MouseClickHandler = 0;
|
||||||
|
static fgMouseMotionHandler MouseMotionHandler = 0;
|
||||||
|
|
||||||
|
void fgRegisterIdleHandler(fgIdleHandler func)
|
||||||
|
{
|
||||||
|
IdleHandler = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgRegisterDrawHandler(fgDrawHandler func)
|
||||||
|
{
|
||||||
|
DrawHandler = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgRegisterWindowResizeHandler(fgWindowResizeHandler func)
|
||||||
|
{
|
||||||
|
WindowResizeHandler = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgRegisterKeyHandler(fgKeyHandler func)
|
||||||
|
{
|
||||||
|
KeyHandler = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgRegisterMouseClickHandler(fgMouseClickHandler func)
|
||||||
|
{
|
||||||
|
MouseClickHandler = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgRegisterMouseMotionHandler(fgMouseMotionHandler func)
|
||||||
|
{
|
||||||
|
MouseMotionHandler = func;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Native glut callbacks.
|
||||||
|
// These translate the glut event model into fg*Handler callbacks
|
||||||
|
//
|
||||||
|
|
||||||
|
static int GlutModifiers = 0;
|
||||||
|
|
||||||
|
static void callKeyHandler(int k, int mods, int x, int y)
|
||||||
|
{
|
||||||
|
int puiup = mods & KEYMOD_RELEASED ? PU_UP : PU_DOWN;
|
||||||
|
if(puKeyboard(k, puiup))
|
||||||
|
return;
|
||||||
|
if(KeyHandler) (*KeyHandler)(k, mods, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLUTmotion (int x, int y)
|
||||||
|
{
|
||||||
|
if(MouseMotionHandler) (*MouseMotionHandler)(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLUTmouse (int button, int updown, int x, int y)
|
||||||
|
{
|
||||||
|
GlutModifiers = glutGetModifiers();
|
||||||
|
if(MouseClickHandler) (*MouseClickHandler)(button, updown, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLUTspecialkeyup(int k, int x, int y)
|
||||||
|
{
|
||||||
|
GlutModifiers = glutGetModifiers();
|
||||||
|
callKeyHandler(256 + k, fgGetKeyModifiers() | KEYMOD_RELEASED, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLUTspecialkey(int k, int x, int y)
|
||||||
|
{
|
||||||
|
GlutModifiers = glutGetModifiers();
|
||||||
|
callKeyHandler(256 + k, fgGetKeyModifiers(), x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLUTkeyup(unsigned char k, int x, int y)
|
||||||
|
{
|
||||||
|
GlutModifiers = glutGetModifiers();
|
||||||
|
callKeyHandler(k, fgGetKeyModifiers() | KEYMOD_RELEASED, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLUTkey(unsigned char k, int x, int y)
|
||||||
|
{
|
||||||
|
GlutModifiers = glutGetModifiers();
|
||||||
|
callKeyHandler(k, fgGetKeyModifiers(), x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLUTidle()
|
||||||
|
{
|
||||||
|
if(IdleHandler) (*IdleHandler)();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLUTdraw()
|
||||||
|
{
|
||||||
|
if(DrawHandler) (*DrawHandler)();
|
||||||
|
glutSwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GLUTreshape(int w, int h)
|
||||||
|
{
|
||||||
|
if(WindowResizeHandler) (*WindowResizeHandler)(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// fg_os API definition
|
||||||
|
//
|
||||||
|
|
||||||
|
void fgOSInit(int* argc, char** argv)
|
||||||
|
{
|
||||||
|
glutInit(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgOSFullScreen()
|
||||||
|
{
|
||||||
|
glutFullScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgOSMainLoop()
|
||||||
|
{
|
||||||
|
glutMainLoop();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int CurrentCursor = MOUSE_CURSOR_POINTER;
|
||||||
|
|
||||||
|
int fgGetMouseCursor()
|
||||||
|
{
|
||||||
|
return CurrentCursor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgSetMouseCursor(int cursor)
|
||||||
|
{
|
||||||
|
CurrentCursor = cursor;
|
||||||
|
if (cursor == MOUSE_CURSOR_NONE) cursor = GLUT_CURSOR_NONE;
|
||||||
|
else if(cursor == MOUSE_CURSOR_POINTER) cursor = GLUT_CURSOR_INHERIT;
|
||||||
|
else if(cursor == MOUSE_CURSOR_WAIT) cursor = GLUT_CURSOR_WAIT;
|
||||||
|
else if(cursor == MOUSE_CURSOR_CROSSHAIR) cursor = GLUT_CURSOR_CROSSHAIR;
|
||||||
|
else if(cursor == MOUSE_CURSOR_LEFTRIGHT) cursor = GLUT_CURSOR_LEFT_RIGHT;
|
||||||
|
// Otherwise, pass it through unchanged...
|
||||||
|
glutSetCursor(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgWarpMouse(int x, int y)
|
||||||
|
{
|
||||||
|
glutWarpPointer(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int fgGetKeyModifiers()
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
if(GlutModifiers & GLUT_ACTIVE_SHIFT) result |= KEYMOD_SHIFT;
|
||||||
|
if(GlutModifiers & GLUT_ACTIVE_CTRL) result |= KEYMOD_CTRL;
|
||||||
|
if(GlutModifiers & GLUT_ACTIVE_ALT) result |= KEYMOD_ALT;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgRequestRedraw()
|
||||||
|
{
|
||||||
|
glutPostRedisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void fgOSOpenWindow(int w, int h, bool alpha)
|
||||||
|
{
|
||||||
|
int mode = GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE;
|
||||||
|
if(alpha) mode |= GLUT_ALPHA;
|
||||||
|
|
||||||
|
glutInitDisplayMode(mode);
|
||||||
|
glutInitWindowSize(w, h);
|
||||||
|
glutCreateWindow("FlightGear");
|
||||||
|
|
||||||
|
// Register these here. Calling them before the window is open
|
||||||
|
// crashes.
|
||||||
|
glutMotionFunc(GLUTmotion);
|
||||||
|
glutPassiveMotionFunc(GLUTmotion);
|
||||||
|
glutMouseFunc(GLUTmouse);
|
||||||
|
glutSpecialUpFunc(GLUTspecialkeyup);
|
||||||
|
glutSpecialFunc(GLUTspecialkey);
|
||||||
|
glutKeyboardUpFunc(GLUTkeyup);
|
||||||
|
glutKeyboardFunc(GLUTkey);
|
||||||
|
glutIdleFunc(GLUTidle);
|
||||||
|
glutDisplayFunc(GLUTdraw);
|
||||||
|
glutReshapeFunc(GLUTreshape);
|
||||||
|
}
|
73
src/Main/fg_os.hxx
Normal file
73
src/Main/fg_os.hxx
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
#ifndef _FG_OS_HXX
|
||||||
|
#define _FG_OS_HXX
|
||||||
|
|
||||||
|
// Plib pui needs to know at compile time what toolkit is in use.
|
||||||
|
// Change this when we move to something other than glut.
|
||||||
|
#define PU_USE_GLUT
|
||||||
|
|
||||||
|
enum { MOUSE_BUTTON_LEFT,
|
||||||
|
MOUSE_BUTTON_MIDDLE,
|
||||||
|
MOUSE_BUTTON_RIGHT };
|
||||||
|
|
||||||
|
enum { MOUSE_BUTTON_DOWN,
|
||||||
|
MOUSE_BUTTON_UP };
|
||||||
|
|
||||||
|
enum { MOUSE_CURSOR_NONE,
|
||||||
|
MOUSE_CURSOR_POINTER,
|
||||||
|
MOUSE_CURSOR_WAIT,
|
||||||
|
MOUSE_CURSOR_CROSSHAIR,
|
||||||
|
MOUSE_CURSOR_LEFTRIGHT };
|
||||||
|
|
||||||
|
enum { KEYMOD_NONE = 0,
|
||||||
|
KEYMOD_RELEASED = 1, // Not a mod key, indicates "up" action
|
||||||
|
KEYMOD_SHIFT = 2,
|
||||||
|
KEYMOD_CTRL = 4,
|
||||||
|
KEYMOD_ALT = 8,
|
||||||
|
KEYMOD_MAX = 16 };
|
||||||
|
|
||||||
|
// A note on key codes: none are defined here. FlightGear has no
|
||||||
|
// hard-coded interpretations of codes other than modifier keys, so we
|
||||||
|
// can get away with that. The only firm requirement is that the
|
||||||
|
// codes passed to the fgKeyHandler function be correctly interpreted
|
||||||
|
// by the PUI library. Users who need to hard-code key codes
|
||||||
|
// (probably not a good idea in any case) can use the pu.hxx header
|
||||||
|
// for definitions.
|
||||||
|
|
||||||
|
//
|
||||||
|
// OS integration functions
|
||||||
|
//
|
||||||
|
|
||||||
|
void fgOSInit(int* argc, char** argv);
|
||||||
|
void fgOSOpenWindow(int w, int h, bool alpha);
|
||||||
|
void fgOSFullScreen();
|
||||||
|
void fgOSMainLoop();
|
||||||
|
|
||||||
|
void fgSetMouseCursor(int cursor);
|
||||||
|
int fgGetMouseCursor();
|
||||||
|
void fgWarpMouse(int x, int y);
|
||||||
|
|
||||||
|
int fgGetKeyModifiers();
|
||||||
|
|
||||||
|
void fgRequestRedraw();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Callbacks and registration API
|
||||||
|
//
|
||||||
|
|
||||||
|
typedef void (*fgIdleHandler)();
|
||||||
|
typedef void (*fgDrawHandler)();
|
||||||
|
typedef void (*fgWindowResizeHandler)(int w, int h);
|
||||||
|
|
||||||
|
typedef void (*fgKeyHandler)(int key, int keymod, int mousex, int mousey);
|
||||||
|
typedef void (*fgMouseClickHandler)(int button, int updown, int x, int y);
|
||||||
|
typedef void (*fgMouseMotionHandler)(int x, int y);
|
||||||
|
|
||||||
|
void fgRegisterIdleHandler(fgIdleHandler func);
|
||||||
|
void fgRegisterDrawHandler(fgDrawHandler func);
|
||||||
|
void fgRegisterWindowResizeHandler(fgWindowResizeHandler func);
|
||||||
|
|
||||||
|
void fgRegisterKeyHandler(fgKeyHandler func);
|
||||||
|
void fgRegisterMouseClickHandler(fgMouseClickHandler func);
|
||||||
|
void fgRegisterMouseMotionHandler(fgMouseMotionHandler func);
|
||||||
|
|
||||||
|
#endif // _FG_OS_HXX
|
|
@ -42,7 +42,6 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <plib/ssg.h>
|
#include <plib/ssg.h>
|
||||||
#include <plib/pu.h>
|
|
||||||
#include <plib/netSocket.h>
|
#include <plib/netSocket.h>
|
||||||
|
|
||||||
#include <simgear/screen/extensions.hxx>
|
#include <simgear/screen/extensions.hxx>
|
||||||
|
@ -127,7 +126,7 @@ bool glPointParameterIsSupported = false;
|
||||||
FGGeneral general;
|
FGGeneral general;
|
||||||
|
|
||||||
// Specify our current idle function state. This is used to run all
|
// Specify our current idle function state. This is used to run all
|
||||||
// our initializations out of the glutIdleLoop() so that we can get a
|
// our initializations out of the idle callback so that we can get a
|
||||||
// splash screen up and running right away.
|
// splash screen up and running right away.
|
||||||
static int idle_state = 0;
|
static int idle_state = 0;
|
||||||
static long global_multi_loop;
|
static long global_multi_loop;
|
||||||
|
@ -159,27 +158,6 @@ sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
|
||||||
{ 0.0f, 0.0f, 0.0f, 1.0f }
|
{ 0.0f, 0.0f, 0.0f, 1.0f }
|
||||||
};
|
};
|
||||||
|
|
||||||
// The following defines flightgear options. Because glutlib will also
|
|
||||||
// want to parse its own options, those options must not be included here
|
|
||||||
// or they will get parsed by the main program option parser. Hence case
|
|
||||||
// is significant for any option added that might be in conflict with
|
|
||||||
// glutlib's parser.
|
|
||||||
//
|
|
||||||
// glutlib parses for:
|
|
||||||
// -display
|
|
||||||
// -direct (invalid in Win32)
|
|
||||||
// -geometry
|
|
||||||
// -gldebug
|
|
||||||
// -iconized
|
|
||||||
// -indirect (invalid in Win32)
|
|
||||||
// -synce
|
|
||||||
//
|
|
||||||
// Note that glutlib depends upon strings while this program's
|
|
||||||
// option parser wants only initial characters followed by numbers
|
|
||||||
// or pathnames.
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
ssgSimpleState *cloud3d_imposter_state;
|
ssgSimpleState *cloud3d_imposter_state;
|
||||||
ssgSimpleState *default_state;
|
ssgSimpleState *default_state;
|
||||||
ssgSimpleState *hud_and_panel;
|
ssgSimpleState *hud_and_panel;
|
||||||
|
@ -236,12 +214,10 @@ void fgInitVisuals( void ) {
|
||||||
|
|
||||||
FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
|
FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
|
||||||
|
|
||||||
#ifndef GLUT_WRONG_VERSION
|
|
||||||
// Go full screen if requested ...
|
// Go full screen if requested ...
|
||||||
if ( fgGetBool("/sim/startup/fullscreen") ) {
|
if ( fgGetBool("/sim/startup/fullscreen") ) {
|
||||||
glutFullScreen();
|
fgOSFullScreen();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
// If enabled, normal vectors specified with glNormal are scaled
|
// If enabled, normal vectors specified with glNormal are scaled
|
||||||
// to unit length after transformation. Enabling this has
|
// to unit length after transformation. Enabling this has
|
||||||
|
@ -829,8 +805,6 @@ void fgRenderFrame() {
|
||||||
fgSplashUpdate(0.0, (3.0 - t) / 2.0);
|
fgSplashUpdate(0.0, (3.0 - t) / 2.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glutSwapBuffers();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -989,10 +963,6 @@ static void fgMainLoop( void ) {
|
||||||
// {
|
// {
|
||||||
// fgJoystickRead();
|
// fgJoystickRead();
|
||||||
// }
|
// }
|
||||||
#elif defined( ENABLE_GLUT_JOYSTICK )
|
|
||||||
// Glut joystick support works by feeding a joystick handler
|
|
||||||
// function to glut. This is taken care of once in the joystick
|
|
||||||
// init routine and we don't have to worry about it again.
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Fix elevation. I'm just sticking this here for now, it should
|
// Fix elevation. I'm just sticking this here for now, it should
|
||||||
|
@ -1210,8 +1180,7 @@ static void fgMainLoop( void ) {
|
||||||
// glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
|
// glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// redraw display
|
fgRequestRedraw();
|
||||||
fgRenderFrame();
|
|
||||||
|
|
||||||
SG_LOG( SG_ALL, SG_DEBUG, "" );
|
SG_LOG( SG_ALL, SG_DEBUG, "" );
|
||||||
}
|
}
|
||||||
|
@ -1312,7 +1281,7 @@ static void fgIdleFunction ( void ) {
|
||||||
// We've finished all our initialization steps, from now on we
|
// We've finished all our initialization steps, from now on we
|
||||||
// run the main loop.
|
// run the main loop.
|
||||||
|
|
||||||
glutIdleFunc(fgMainLoop);
|
fgRegisterIdleHandler(fgMainLoop);
|
||||||
} else {
|
} else {
|
||||||
if ( fgGetBool("/sim/startup/splash-screen") ) {
|
if ( fgGetBool("/sim/startup/splash-screen") ) {
|
||||||
fgSplashUpdate(0.0, 1.0);
|
fgSplashUpdate(0.0, 1.0);
|
||||||
|
@ -1360,110 +1329,6 @@ void fgReshape( int width, int height ) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize GLUT and define a main window
|
|
||||||
static bool fgGlutInit( int *argc, char **argv ) {
|
|
||||||
|
|
||||||
#if !defined( macintosh )
|
|
||||||
// GLUT will extract all glut specific options so later on we only
|
|
||||||
// need wory about our own.
|
|
||||||
glutInit(argc, argv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Define Display Parameters. Clouds3d works best with --bpp32 option
|
|
||||||
if ( fgGetBool("/sim/rendering/clouds3d") ) {
|
|
||||||
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ALPHA );
|
|
||||||
} else {
|
|
||||||
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
|
|
||||||
}
|
|
||||||
|
|
||||||
SG_LOG( SG_GENERAL, SG_INFO, "Opening a window: " <<
|
|
||||||
fgGetInt("/sim/startup/xsize") << "x"
|
|
||||||
<< fgGetInt("/sim/startup/ysize") );
|
|
||||||
|
|
||||||
// Define initial window size
|
|
||||||
glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
|
|
||||||
fgGetInt("/sim/startup/ysize") );
|
|
||||||
|
|
||||||
// Initialize windows
|
|
||||||
if ( !fgGetBool("/sim/startup/game-mode")) {
|
|
||||||
// Open the regular window
|
|
||||||
glutCreateWindow("FlightGear");
|
|
||||||
#ifndef GLUT_WRONG_VERSION
|
|
||||||
} else {
|
|
||||||
// Open the cool new 'game mode' window
|
|
||||||
char game_mode_str[256];
|
|
||||||
//#define SYNC_OPENGL_WITH_DESKTOP_SETTINGS
|
|
||||||
#if defined(WIN32) && defined(SYNC_OPENGL_WITH_DESKTOP_SETTINGS)
|
|
||||||
#ifndef ENUM_CURRENT_SETTINGS
|
|
||||||
#define ENUM_CURRENT_SETTINGS ((DWORD)-1)
|
|
||||||
#define ENUM_REGISTRY_SETTINGS ((DWORD)-2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DEVMODE dm;
|
|
||||||
dm.dmSize = sizeof(DEVMODE);
|
|
||||||
EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm);
|
|
||||||
fgSetInt("/sim/startup/xsize", dm.dmPelsWidth);
|
|
||||||
fgSetInt("/sim/startup/ysize", dm.dmPelsHeight);
|
|
||||||
glutInitWindowSize( fgGetInt("/sim/startup/xsize"),
|
|
||||||
fgGetInt("/sim/startup/ysize") );
|
|
||||||
sprintf( game_mode_str, "%dx%d:%d@%d",
|
|
||||||
dm.dmPelsWidth,
|
|
||||||
dm.dmPelsHeight,
|
|
||||||
dm.dmBitsPerPel,
|
|
||||||
dm.dmDisplayFrequency );
|
|
||||||
#else
|
|
||||||
// Open the cool new 'game mode' window
|
|
||||||
sprintf( game_mode_str, "width=%d height=%d bpp=%d",
|
|
||||||
fgGetInt("/sim/startup/xsize"),
|
|
||||||
fgGetInt("/sim/startup/ysize"),
|
|
||||||
fgGetInt("/sim/rendering/bits-per-pixel"));
|
|
||||||
|
|
||||||
#endif // HAVE_WINDOWS_H
|
|
||||||
SG_LOG( SG_GENERAL, SG_INFO,
|
|
||||||
"game mode params = " << game_mode_str );
|
|
||||||
glutGameModeString( game_mode_str );
|
|
||||||
glutEnterGameMode();
|
|
||||||
#endif // GLUT_WRONG_VERSION
|
|
||||||
}
|
|
||||||
|
|
||||||
// This seems to be the absolute earliest in the init sequence
|
|
||||||
// that these calls will return valid info. Too bad it's after
|
|
||||||
// we've already created and sized out window. :-(
|
|
||||||
general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
|
|
||||||
general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
|
|
||||||
general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
|
|
||||||
SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );
|
|
||||||
|
|
||||||
GLint tmp;
|
|
||||||
glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
|
|
||||||
general.set_glMaxTexSize( tmp );
|
|
||||||
SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );
|
|
||||||
|
|
||||||
glGetIntegerv( GL_DEPTH_BITS, &tmp );
|
|
||||||
general.set_glDepthBits( tmp );
|
|
||||||
SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Initialize GLUT event handlers
|
|
||||||
static bool fgGlutInitEvents( void ) {
|
|
||||||
// call fgReshape() on window resizes
|
|
||||||
glutReshapeFunc( fgReshape );
|
|
||||||
|
|
||||||
// keyboard and mouse callbacks are set in FGInput::init
|
|
||||||
|
|
||||||
// call fgMainLoop() whenever there is
|
|
||||||
// nothing else to do
|
|
||||||
glutIdleFunc( fgIdleFunction );
|
|
||||||
|
|
||||||
// draw the scene
|
|
||||||
glutDisplayFunc( fgRenderFrame );
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main top level initialization
|
// Main top level initialization
|
||||||
bool fgMainInit( int argc, char **argv ) {
|
bool fgMainInit( int argc, char **argv ) {
|
||||||
|
|
||||||
|
@ -1533,28 +1398,49 @@ bool fgMainInit( int argc, char **argv ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the Window/Graphics environment.
|
// Initialize the Window/Graphics environment.
|
||||||
if( !fgGlutInit(&argc, argv) ) {
|
#if !defined(__APPLE__) || defined(OSX_BUNDLE)
|
||||||
SG_LOG( SG_GENERAL, SG_ALERT, "GLUT initialization failed ..." );
|
// Mac OS X command line ("non-bundle") applications call this
|
||||||
exit(-1);
|
// from main(), in bootstrap.cxx. Andy doesn't know why, someone
|
||||||
}
|
// feel free to add comments...
|
||||||
|
fgOSInit(&argc, argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Initialize the various GLUT Event Handlers.
|
fgRegisterWindowResizeHandler( fgReshape );
|
||||||
if( !fgGlutInitEvents() ) {
|
fgRegisterIdleHandler( fgIdleFunction );
|
||||||
SG_LOG( SG_GENERAL, SG_ALERT,
|
fgRegisterDrawHandler( fgRenderFrame );
|
||||||
"GLUT event handler initialization failed ..." );
|
|
||||||
exit(-1);
|
// Clouds3D requires an alpha channel
|
||||||
}
|
fgOSOpenWindow( fgGetInt("/sim/startup/xsize"),
|
||||||
|
fgGetInt("/sim/startup/ysize"),
|
||||||
|
fgGetBool("/sim/rendering/clouds3d") );
|
||||||
|
|
||||||
|
// This seems to be the absolute earliest in the init sequence
|
||||||
|
// that these calls will return valid info. Too bad it's after
|
||||||
|
// we've already created and sized out window. :-(
|
||||||
|
general.set_glVendor( (char *)glGetString ( GL_VENDOR ) );
|
||||||
|
general.set_glRenderer( (char *)glGetString ( GL_RENDERER ) );
|
||||||
|
general.set_glVersion( (char *)glGetString ( GL_VERSION ) );
|
||||||
|
SG_LOG( SG_GENERAL, SG_INFO, general.get_glRenderer() );
|
||||||
|
|
||||||
|
GLint tmp;
|
||||||
|
glGetIntegerv( GL_MAX_TEXTURE_SIZE, &tmp );
|
||||||
|
general.set_glMaxTexSize( tmp );
|
||||||
|
SG_LOG ( SG_GENERAL, SG_INFO, "Max texture size = " << tmp );
|
||||||
|
|
||||||
|
glGetIntegerv( GL_DEPTH_BITS, &tmp );
|
||||||
|
general.set_glDepthBits( tmp );
|
||||||
|
SG_LOG ( SG_GENERAL, SG_INFO, "Depth buffer bits = " << tmp );
|
||||||
|
|
||||||
// Initialize plib net interface
|
// Initialize plib net interface
|
||||||
netInit( &argc, argv );
|
netInit( &argc, argv );
|
||||||
|
|
||||||
// Initialize ssg (from plib). Needs to come before we do any
|
// Initialize ssg (from plib). Needs to come before we do any
|
||||||
// other ssg stuff, but after opengl/glut has been initialized.
|
// other ssg stuff, but after opengl has been initialized.
|
||||||
ssgInit();
|
ssgInit();
|
||||||
|
|
||||||
// Initialize the user interface (we need to do this before
|
// Initialize the user interface (we need to do this before
|
||||||
// passing off control to glut and before fgInitGeneral to get our
|
// passing off control to the OS main loop and before
|
||||||
// fonts !!!
|
// fgInitGeneral to get our fonts !!!
|
||||||
guiInit();
|
guiInit();
|
||||||
|
|
||||||
// Read the list of available aircrafts
|
// Read the list of available aircrafts
|
||||||
|
@ -1705,8 +1591,8 @@ bool fgMainInit( int argc, char **argv ) {
|
||||||
// build our custom render states
|
// build our custom render states
|
||||||
fgBuildRenderStates();
|
fgBuildRenderStates();
|
||||||
|
|
||||||
// pass control off to the master GLUT event handler
|
// pass control off to the master event handler
|
||||||
glutMainLoop();
|
fgOSMainLoop();
|
||||||
|
|
||||||
// we never actually get here ... but to avoid compiler warnings,
|
// we never actually get here ... but to avoid compiler warnings,
|
||||||
// etc.
|
// etc.
|
||||||
|
|
|
@ -34,10 +34,10 @@
|
||||||
# include <windows.h>
|
# include <windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include FG_GLUT_H
|
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <GL/glu.h>
|
||||||
|
|
||||||
#include <simgear/debug/logstream.hxx>
|
#include <simgear/debug/logstream.hxx>
|
||||||
#include <simgear/screen/texture.hxx>
|
#include <simgear/screen/texture.hxx>
|
||||||
#include <simgear/math/sg_random.h>
|
#include <simgear/math/sg_random.h>
|
||||||
|
@ -46,6 +46,8 @@
|
||||||
#include "globals.hxx"
|
#include "globals.hxx"
|
||||||
#include "fg_props.hxx"
|
#include "fg_props.hxx"
|
||||||
#include "splash.hxx"
|
#include "splash.hxx"
|
||||||
|
#include "fg_os.hxx"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static SGTexture splash;
|
static SGTexture splash;
|
||||||
|
@ -141,8 +143,6 @@ void fgSplashUpdate ( double progress, float alpha ) {
|
||||||
glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax);
|
glTexCoord2f(0.0, 1.0); glVertex2f(xmin, ymax);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
glutSwapBuffers();
|
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
Loading…
Add table
Reference in a new issue