#include <simgear/compiler.h>
-#ifdef FG_MATH_EXCEPTION_CLASH
+#ifdef SG_MATH_EXCEPTION_CLASH
# include <math.h>
#endif
# include <windows.h>
#endif
-#include <GL/glut.h>
-#include <simgear/xgl/xgl.h>
+#include GLUT_H
#if defined(FX) && defined(XMESA)
# include <GL/xmesa.h>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
-#include <simgear/misc/fgpath.hxx>
+#include <simgear/misc/sg_path.hxx>
#include <simgear/screen/screen-dump.hxx>
#include <Include/general.hxx>
#include <FDM/flight.hxx>
#include <Main/fg_init.hxx>
#include <Main/fg_props.hxx>
-//#include <Main/views.hxx>
-//#include <Network/network.h>
-//#include <Time/fg_time.hxx>
-
-#if defined( WIN32 ) && !defined( __CYGWIN__ )
-# include <simgear/screen/win32-printer.h>
-# include <simgear/screen/GlBitmaps.h>
-#endif
+#include <Main/viewmgr.hxx>
#include "gui.h"
#include "gui_local.hxx"
-FG_USING_STD(string);
-
-#ifndef FG_HAVE_NATIVE_SGI_COMPILERS
-FG_USING_STD(cout);
-#endif
+SG_USING_STD(string);
+SG_USING_STD(cout);
/* --------------------------------------------------------------------
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 glut_active_shift = 0;
+static int glut_active_ctrl = 0;
+static int glut_active_alt = 0;
+
+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;
return( last_buttons & (1 << GLUT_RIGHT_BUTTON) );
}
+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(FGControls::ALL_WHEELS, 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() {
+ return globals->get_autopilot()->get_HeadingEnabled();
+}
+
+static inline bool AP_AltitudeEnabled() {
+ return globals->get_autopilot()->get_AltitudeEnabled();
+}
+
void TurnCursorOn( void )
{
mouse_active = ~0;
-#if defined(WIN32_CURSOR_TWEAKS)
+#if defined(WIN32)
switch (mouse_mode) {
case MOUSE_POINTER:
glutSetCursor(GLUT_CURSOR_INHERIT);
}
#endif
#if defined(X_CURSOR_TWEAKS)
- glutWarpPointer( fgGetInt("/sim/startup/xsize")/2,
- fgGetInt("/sim/startup/ysize")/2);
+ glutWarpPointer( MOUSE_XSIZE/2,
+ MOUSE_YSIZE/2);
#endif
}
#if defined(WIN32_CURSOR_TWEAKS)
glutSetCursor(GLUT_CURSOR_NONE);
#elif defined(X_CURSOR_TWEAKS)
- glutWarpPointer( fgGetInt("/sim/startup/xsize"),
- fgGetInt("/sim/startup/ysize"));
+ glutWarpPointer( MOUSE_XSIZE,
+ MOUSE_YSIZE);
#endif
}
void maybeToggleMouse( void )
{
-#if defined(WIN32_CURSOR_TWEAKS)
+#if defined(WIN32_CURSOR_TWEAKS_OFF)
static int first_time = ~0;
static int mouse_changed = 0;
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);
// Is this necessary ??
+#if defined(FG_OLD_MENU)
if( !gui_menu_on ) TurnCursorOff();
+#endif
glutWarpPointer( _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 = MOUSE_XSIZE;
+ wh = MOUSE_YSIZE;
+
if (mouse_mode == MOUSE_POINTER) {
+#if defined(FG_OLD_MENU)
+ // TURN MENU ON IF MOUSE AT TOP
+ if( y < 1 ) {
+ if( !gui_menu_on )
+ guiToggleMenu();
+ }
+ // TURN MENU OFF IF MOUSE AT BOTTOM
+ else if( y > wh-2 ) {
+ if( gui_menu_on )
+ guiToggleMenu();
+ }
+#endif
puMouse ( x, y ) ;
glutPostRedisplay () ;
} else {
// reset left click MOUSE_VIEW toggle feature
_mVtoggle = 0;
- ww = fgGetInt("/sim/startup/xsize");
- wh = fgGetInt("/sim/startup/ysize");
-
switch (mouse_mode) {
case MOUSE_YOKE:
if( !mouse_joystick_control ) {
fgSetString("/sim/control-mode", "mouse");
} else {
if ( left_button() ) {
- offset = (_mX - x) * brake_sensitivity;
- controls.move_brake(FGControls::ALL_WHEELS, offset);
- offset = (_mY - y) * throttle_sensitivity;
- 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;
- controls.move_rudder(offset);
+ if( ! AP_HeadingEnabled() ) {
+ move_rudder((x - _mX) * rudder_sensitivity);
}
- if( ! current_autopilot->get_AltitudeEnabled() ) {
- offset = (_mY - y) * trim_sensitivity;
- 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;
- controls.move_aileron(offset);
+ if( ! AP_HeadingEnabled() ) {
+ move_aileron((x - _mX) * aileron_sensitivity);
}
- if( ! current_autopilot->get_AltitudeEnabled() ) {
- offset = (_mY - y) * elevator_sensitivity;
- controls.move_elevator(offset);
+ if( ! AP_AltitudeEnabled() ) {
+ move_elevator((_mY - y) * elevator_sensitivity);
}
}
}
need_warp = 1;
x = 1;
}
- // try to get FG_PI movement in each half of screen
+ // try to get SGD_PI movement in each half of screen
// do spherical pan
W = ww;
H = wh;
// 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 += ((_mX - x) * FG_2PI / W );
+ offset = get_goal_view_offset();
+ offset += ((_mX - x) * SGD_2PI / W );
while (offset < 0.0) {
- offset += FG_2PI;
+ offset += SGD_2PI;
}
- while (offset > FG_2PI) {
- offset -= FG_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;
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;
_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);
_mVtoggle = ~_mVtoggle;
break;
}
- }else if ( button == GLUT_RIGHT_BUTTON) {
+ } else if ( button == GLUT_RIGHT_BUTTON) {
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 = controls.get_aileron();
- x = _mX - (int)(offset * aileron_sensitivity);
- offset = 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);
- FG_LOG( FG_INPUT, FG_INFO, "Mouse in yoke mode" );
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;
+ fgSetString("/sim/control-mode", "joystick");
+
+ // 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);
+// #endif
glutSetCursor(GLUT_CURSOR_LEFT_RIGHT);
- FG_LOG( FG_INPUT, FG_INFO, "Mouse in view mode" );
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);
-#endif
-#endif // RESET_VIEW_ON_LEAVING_MOUSE_VIEW
+ 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);
-
+
+#if defined(FG_OLD_MENU)
+#if defined(WIN32_CURSOR_TWEAKS_OFF)
if(!gui_menu_on)
TurnCursorOff();
-
- FG_LOG( FG_INPUT, FG_INFO, "Mouse in pointer mode" );
+#endif // WIN32_CURSOR_TWEAKS_OFF
+#endif // FG_OLD_MENU
break;
- }
+ } // end switch (mouse_mode)
glutWarpPointer( x, y );
} // END RIGHT BUTTON
} // END UPDOWN == GLUT_DOWN
// know what's going on.
if (mouse_mode == MOUSE_POINTER) {
if (!puMouse (button, updown, x,y)) {
- current_panel->doMouseAction(button, updown, x, y);
+ if ( globals->get_current_panel() != NULL ) {
+ globals->get_current_panel()->doMouseAction(button, updown, x, y);
+ }
}
}
glutPostRedisplay ();
}
+
+
+