# include <windows.h>
#endif
-#include <GL/glut.h>
-#include <GL/gl.h>
+#include <Main/fg_os.hxx>
#if defined(FX) && defined(XMESA)
# include <GL/xmesa.h>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sg_path.hxx>
-#include <simgear/screen/screen-dump.hxx>
#include <Include/general.hxx>
-//#include <Include/fg_memory.h>
#include <Aircraft/aircraft.hxx>
#include <Airports/simple.hxx>
-//#include <Autopilot/auto_gui.hxx>
-#include <Autopilot/newauto.hxx>
+#include <Autopilot/auto_gui.hxx>
#include <Cockpit/panel.hxx>
#include <Controls/controls.hxx>
#include <FDM/flight.hxx>
#include "gui_local.hxx"
SG_USING_STD(string);
-
-#ifndef SG_HAVE_NATIVE_SGI_COMPILERS
SG_USING_STD(cout);
-#endif
/* --------------------------------------------------------------------
Mouse stuff
// on second left click in MOUSE_VIEW mode
// This has file scope so that it can be reset
// if the little rodent is moved NHV
-static int _mVtoggle;
+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;
-static int glut_active_ctrl;
-static int glut_active_alt;
+static int MOUSE_XSIZE = 0;
+static int MOUSE_YSIZE = 0;
// uncomment this for view to exactly follow mouse in MOUSE_VIEW mode
// else smooth out the view panning to .01 radian per frame
static double rudder_sensitivity = 1.0/500.0;
static double trim_sensitivity = 1.0/1000.0;
+void guiInitMouse(int width, int height)
+{
+ MOUSE_XSIZE = width;
+ MOUSE_YSIZE = height;
+}
+
static inline int guiGetMouseButton(void)
{
return last_buttons;
};
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 ) {
- return( last_buttons & (1 << GLUT_MIDDLE_BUTTON) );
+ return( last_buttons & (1 << MOUSE_BUTTON_MIDDLE) );
}
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 )
+{
+ globals->get_current_view()->setGoalHeadingOffset_deg(offset * SGD_RADIANS_TO_DEGREES);
+}
+
+static inline void set_view_offset( float offset )
+{
+ globals->get_current_view()->setHeadingOffset_deg(offset * SGD_RADIANS_TO_DEGREES);
+}
+
+static inline void set_goal_view_tilt( float tilt )
+{
+ globals->get_current_view()->setGoalPitchOffset_deg(tilt);
+}
+
+static inline void set_view_tilt( float tilt )
+{
+ globals->get_current_view()->setPitchOffset_deg(tilt);
+}
+
+static inline float get_view_offset() {
+ return globals->get_current_view()->getHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
+}
+
+static inline float get_goal_view_offset() {
+ return globals->get_current_view()->getGoalHeadingOffset_deg() * SGD_DEGREES_TO_RADIANS;
+}
+
+static inline void move_brake(float offset) {
+ globals->get_controls()->move_brake_left(offset);
+ globals->get_controls()->move_brake_right(offset);
+}
+
+static inline void move_throttle(float offset) {
+ globals->get_controls()->move_throttle(FGControls::ALL_ENGINES, offset);
+}
+
+static inline void move_rudder(float offset) {
+ globals->get_controls()->move_rudder(offset);
+}
+
+static inline void move_elevator_trim(float offset) {
+ globals->get_controls()->move_elevator_trim(offset);
+}
+
+static inline void move_aileron(float offset) {
+ globals->get_controls()->move_aileron(offset);
+}
+
+static inline void move_elevator(float offset) {
+ globals->get_controls()->move_elevator(offset);
+}
+
+static inline float get_aileron() {
+ return globals->get_controls()->get_aileron();
+}
+
+static inline float get_elevator() {
+ return globals->get_controls()->get_elevator();
+}
+
+static inline bool AP_HeadingEnabled() {
+ static const SGPropertyNode *heading_enabled
+ = fgGetNode("/autopilot/locks/heading");
+ return ( strcmp( heading_enabled->getStringValue(), "" ) != 0 );
+}
+
+static inline bool AP_AltitudeEnabled() {
+ static const SGPropertyNode *altitude_enabled
+ = fgGetNode("/autopilot/locks/altitude");
+ return ( strcmp( altitude_enabled->getStringValue(), "" ) != 0 );
}
void TurnCursorOn( void )
#if defined(WIN32)
switch (mouse_mode) {
case MOUSE_POINTER:
- glutSetCursor(GLUT_CURSOR_INHERIT);
+ fgSetMouseCursor(MOUSE_CURSOR_POINTER);
break;
case MOUSE_YOKE:
- glutSetCursor(GLUT_CURSOR_CROSSHAIR);
+ fgSetMouseCursor(MOUSE_CURSOR_CROSSHAIR);
break;
case MOUSE_VIEW:
- glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
+ fgSetMouseCursor(MOUSE_CURSOR_LEFTRIGHT);
break;
}
#endif
#if defined(X_CURSOR_TWEAKS)
- glutWarpPointer( fgGetInt("/sim/startup/xsize")/2,
- fgGetInt("/sim/startup/ysize")/2);
+ fgWarpMouse( MOUSE_XSIZE/2, MOUSE_YSIZE/2 );
#endif
}
{
mouse_active = 0;
#if defined(WIN32_CURSOR_TWEAKS)
- glutSetCursor(GLUT_CURSOR_NONE);
+ fgSetMouseCursor(MOUSE_CURSOR_NONE);
#elif defined(X_CURSOR_TWEAKS)
- glutWarpPointer( fgGetInt("/sim/startup/xsize"),
- fgGetInt("/sim/startup/ysize"));
+ fgWarpMouse( MOUSE_XSIZE, MOUSE_YSIZE );
#endif
}
// Call with FALSE to init and TRUE to restore
void BusyCursor( int restore )
{
- static GLenum cursor = (GLenum) 0;
+ static int cursor = MOUSE_CURSOR_POINTER;
if( restore ) {
- glutSetCursor(cursor);
+ fgSetMouseCursor(cursor);
} else {
- cursor = (GLenum) glutGet( (GLenum) GLUT_WINDOW_CURSOR );
+ cursor = fgGetMouseCursor();
#if defined(WIN32_CURSOR_TWEAKS)
TurnCursorOn();
#endif
- glutSetCursor( GLUT_CURSOR_WAIT );
+ fgSetMouseCursor( MOUSE_CURSOR_WAIT );
}
}
void CenterView( void ) {
if( mouse_mode == MOUSE_VIEW ) {
mouse_mode = MOUSE_POINTER;
- _savedX = fgGetInt("/sim/startup/xsize")/2;
- _savedY = fgGetInt("/sim/startup/ysize")/2;
+ _savedX = MOUSE_XSIZE/2;
+ _savedY = MOUSE_YSIZE/2;
_mVtoggle = 0;
Quat0();
build_rotmatrix(GuiQuat_mat, curGuiQuat);
- glutSetCursor(GLUT_CURSOR_INHERIT);
+ fgSetMouseCursor(MOUSE_CURSOR_POINTER);
// Is this necessary ??
+#if defined(FG_OLD_MENU)
if( !gui_menu_on ) TurnCursorOff();
+#endif
- glutWarpPointer( _savedX, _savedY );
+ fgWarpMouse( _savedX, _savedY );
}
- globals->get_current_view()->set_goal_view_offset(0.0);
- globals->get_current_view()->set_view_offset(0.0);
+ set_goal_view_offset(0.0);
+ set_view_offset(0.0);
}
+//#define TRANSLATE_HUD
+// temporary hack until pitch_offset is added to view pipeline
+void fgTranslateHud( void ) {
+#ifdef TRANSLATE_HUD
+ if(mouse_mode == MOUSE_VIEW) {
+
+ int ww = MOUSE_XSIZE;
+ int wh = MOUSE_YSIZE;
+
+ float y = 4*(_mY-(wh/2));// * ((wh/SGD_PI)*SG_RADIANS_TO_DEGREES);
+
+ float x = get_view_offset() * SG_RADIANS_TO_DEGREES;
+
+ if( x < -180 ) x += 360;
+ else if( x > 180 ) x -= 360;
+
+ x *= ww/90.0;
+ // x *= ww/180.0;
+ // x *= ww/360.0;
+
+ // glTranslatef( x*ww/640, y*wh/480, 0 );
+ glTranslatef( x*640/ww, y*480/wh, 0 );
+ }
+#endif // TRANSLATE_HUD
+}
+
void guiMotionFunc ( int x, int y )
{
int ww, wh, need_warp = 0;
float W, H;
double offset;
- ww = fgGetInt("/sim/startup/xsize");
- wh = fgGetInt("/sim/startup/ysize");
+ ww = MOUSE_XSIZE;
+ wh = MOUSE_YSIZE;
if (mouse_mode == MOUSE_POINTER) {
+#if defined(FG_OLD_MENU)
// TURN MENU ON IF MOUSE AT TOP
- if( y < 2 ) {
+ if( y < 1 ) {
if( !gui_menu_on )
guiToggleMenu();
}
if( gui_menu_on )
guiToggleMenu();
}
+#endif
puMouse ( x, y ) ;
- glutPostRedisplay () ;
+ fgRequestRedraw () ;
} else {
if( x == _mX && y == _mY)
return;
fgSetString("/sim/control-mode", "mouse");
} else {
if ( left_button() ) {
- offset = (_mX - x) * brake_sensitivity;
- globals->get_controls()->move_brake(FGControls::ALL_WHEELS, offset);
- offset = (_mY - y) * throttle_sensitivity;
- globals->get_controls()->move_throttle(FGControls::ALL_ENGINES, offset);
+ move_brake( (_mX - x) * brake_sensitivity);
+ move_throttle((_mY - y) * throttle_sensitivity);
} else if ( right_button() ) {
- if( ! current_autopilot->get_HeadingEnabled() ) {
- offset = (x - _mX) * rudder_sensitivity;
- globals->get_controls()->move_rudder(offset);
+ if( ! AP_HeadingEnabled() ) {
+ move_rudder((x - _mX) * rudder_sensitivity);
}
- if( ! current_autopilot->get_AltitudeEnabled() ) {
- offset = (_mY - y) * trim_sensitivity;
- globals->get_controls()->move_elevator_trim(offset);
+ if( ! AP_AltitudeEnabled() ) {
+ move_elevator_trim((_mY - y) * trim_sensitivity);
}
} else {
- if( ! current_autopilot->get_HeadingEnabled() ) {
- offset = (x - _mX) * aileron_sensitivity;
- globals->get_controls()->move_aileron(offset);
+ if( ! AP_HeadingEnabled() ) {
+ move_aileron((x - _mX) * aileron_sensitivity);
}
- if( ! current_autopilot->get_AltitudeEnabled() ) {
- offset = (_mY - y) * elevator_sensitivity;
- globals->get_controls()->move_elevator(offset);
+ if( ! AP_AltitudeEnabled() ) {
+ move_elevator((_mY - y) * elevator_sensitivity);
}
}
}
// do horizontal pan
// this could be done in above quat
// but requires redoing view pipeline
- offset = globals->get_current_view()->get_goal_view_offset();
+ offset = get_goal_view_offset();
offset += ((_mX - x) * SGD_2PI / W );
while (offset < 0.0) {
offset += SGD_2PI;
while (offset > SGD_2PI) {
offset -= SGD_2PI;
}
- globals->get_current_view()->set_goal_view_offset(offset);
+ set_goal_view_offset(offset);
+ set_goal_view_tilt(asin( GuiQuat_mat[1][2]) * SGD_RADIANS_TO_DEGREES );
#ifdef NO_SMOOTH_MOUSE_VIEW
- globals->get_current_view()->set_view_offset(offset);
+ set_view_offset(offset);
+ set_view_tilt(asin( GuiQuat_mat[1][2]) * SGD_RADIANS_TO_DEGREES );
#endif
break;
}
}
if( need_warp)
- glutWarpPointer(x, y);
+ fgWarpMouse(x, y);
// Record the new mouse position.
_mX = x;
void guiMouseFunc(int button, int updown, int x, int y)
{
- int glutModifiers;
// private MOUSE_VIEW state variables
// to allow alternate left clicks in MOUSE_VIEW mode
static float _quat[4];
static double _view_offset;
- // general purpose variables
- double 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?
- if (updown == GLUT_DOWN ) {
- if( button == GLUT_LEFT_BUTTON)
+ if ( updown == MOUSE_BUTTON_DOWN ) {
+ if( button == MOUSE_BUTTON_LEFT)
{
switch (mouse_mode) {
case MOUSE_POINTER:
_mY = _mVy;
x = _Vx;
y = _Vy;
- curGuiQuat[0] = _quat[0];
- curGuiQuat[1] = _quat[1];
- curGuiQuat[2] = _quat[2];
- curGuiQuat[3] = _quat[3];
- globals->get_current_view()->set_goal_view_offset(_view_offset);
+ sgCopyVec4(curGuiQuat, _quat);
+ set_goal_view_offset(_view_offset);
+ set_goal_view_tilt(0.0);
#ifdef NO_SMOOTH_MOUSE_VIEW
- globals->get_current_view()->set_view_offset(_view_offset);
+ set_view_offset(_view_offset);
#endif
} else {
// center view
_mVy = _mY;
_Vx = x;
_Vy = y;
- _quat[0] = curGuiQuat[0];
- _quat[1] = curGuiQuat[1];
- _quat[2] = curGuiQuat[2];
- _quat[3] = curGuiQuat[3];
- x = fgGetInt("/sim/startup/xsize")/2;
- y = fgGetInt("/sim/startup/ysize")/2;
+ sgCopyVec4(_quat,curGuiQuat);
+ x = MOUSE_XSIZE/2;
+ y = MOUSE_YSIZE/2;
Quat0();
- _view_offset =
- globals->get_current_view()->get_goal_view_offset();
- globals->get_current_view()->set_goal_view_offset(0.0);
+ _view_offset = get_goal_view_offset();
+ set_goal_view_offset(0.0);
+ set_goal_view_tilt(0.0);
#ifdef NO_SMOOTH_MOUSE_VIEW
- globals->get_current_view()->set_view_offset(0.0);
+ set_view_offset(0.0);
+ set_view_tilt(0.0);
#endif
}
- glutWarpPointer( x , y);
+ fgWarpMouse( x , y);
build_rotmatrix(GuiQuat_mat, curGuiQuat);
_mVtoggle = ~_mVtoggle;
break;
}
- }else if ( button == GLUT_RIGHT_BUTTON) {
+ } else if ( button == MOUSE_BUTTON_RIGHT) {
switch (mouse_mode) {
+
case MOUSE_POINTER:
+ SG_LOG( SG_INPUT, SG_INFO, "Mouse in yoke mode" );
+
mouse_mode = MOUSE_YOKE;
mouse_joystick_control = 0;
_savedX = x;
_savedY = y;
// start with zero point in center of screen
- _mX = fgGetInt("/sim/startup/xsize")/2;
- _mY = fgGetInt("/sim/startup/ysize")/2;
+ _mX = MOUSE_XSIZE/2;
+ _mY = MOUSE_YSIZE/2;
// try to have the MOUSE_YOKE position
// reflect the current stick position
- offset = globals->get_controls()->get_aileron();
- x = _mX - (int)(offset * aileron_sensitivity);
- offset = globals->get_controls()->get_elevator();
- y = _mY - (int)(offset * elevator_sensitivity);
+ x = _mX - (int)(get_aileron() * aileron_sensitivity);
+ y = _mY - (int)(get_elevator() * elevator_sensitivity);
- glutSetCursor(GLUT_CURSOR_CROSSHAIR);
- SG_LOG( SG_INPUT, SG_INFO, "Mouse in yoke mode" );
+ fgSetMouseCursor(MOUSE_CURSOR_CROSSHAIR);
break;
case MOUSE_YOKE:
+ SG_LOG( SG_INPUT, SG_INFO, "Mouse in view mode" );
+
mouse_mode = MOUSE_VIEW;
fgSetString("/sim/control-mode", "joystick");
- x = fgGetInt("/sim/startup/xsize")/2;
- y = fgGetInt("/sim/startup/ysize")/2;
+
+ // recenter cursor and reset
+ x = MOUSE_XSIZE/2;
+ y = MOUSE_YSIZE/2;
_mVtoggle = 0;
+// #ifndef RESET_VIEW_ON_LEAVING_MOUSE_VIEW
Quat0();
build_rotmatrix(GuiQuat_mat, curGuiQuat);
- glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
- SG_LOG( SG_INPUT, SG_INFO, "Mouse in view mode" );
+// #endif
+ fgSetMouseCursor(MOUSE_CURSOR_LEFTRIGHT);
break;
case MOUSE_VIEW:
+ SG_LOG( SG_INPUT, SG_INFO, "Mouse in pointer mode" );
+
mouse_mode = MOUSE_POINTER;
x = _savedX;
y = _savedY;
#ifdef RESET_VIEW_ON_LEAVING_MOUSE_VIEW
Quat0();
build_rotmatrix(GuiQuat_mat, curGuiQuat);
- globals->get_current_view()->set_goal_view_offset(0.0);
+ set_goal_view_offset(0.0);
+ set_goal_view_tilt(0.0);
#ifdef NO_SMOOTH_MOUSE_VIEW
- globals->get_current_view()->set_view_offset(0.0);
+ set_view_offset(0.0);
+ set_view_tilt(0.0);
#endif // NO_SMOOTH_MOUSE_VIEW
#endif // RESET_VIEW_ON_LEAVING_MOUSE_VIEW
- glutSetCursor(GLUT_CURSOR_INHERIT);
-
+ fgSetMouseCursor(MOUSE_CURSOR_POINTER);
+
+#if defined(FG_OLD_MENU)
#if defined(WIN32_CURSOR_TWEAKS_OFF)
if(!gui_menu_on)
TurnCursorOff();
#endif // WIN32_CURSOR_TWEAKS_OFF
-
- SG_LOG( SG_INPUT, SG_INFO, "Mouse in pointer mode" );
+#endif // FG_OLD_MENU
break;
} // end switch (mouse_mode)
- glutWarpPointer( x, y );
+ fgWarpMouse( x, y );
} // END RIGHT BUTTON
- } // END UPDOWN == GLUT_DOWN
+ } // END MOUSE DOWN
- // Note which button is pressed.
- if ( updown == GLUT_DOWN ) {
+ // Update the button state
+ if ( updown == MOUSE_BUTTON_DOWN ) {
last_buttons |= ( 1 << button ) ;
} else {
last_buttons &= ~( 1 << button ) ;
// If we're in pointer mode, let PUI
// know what's going on.
if (mouse_mode == MOUSE_POINTER) {
- if (!puMouse (button, updown, x,y)) {
- if ( current_panel != NULL ) {
- current_panel->doMouseAction(button, updown, x, y);
+ if (!puMouse (button, updown , x,y)) {
+ if ( globals->get_current_panel() != NULL ) {
+ globals->get_current_panel()->doMouseAction(button, updown, x, y);
}
}
}
_mX = x;
_mY = y;
- glutPostRedisplay ();
+ fgRequestRedraw ();
}
+
+
+