]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_os_sdl.cxx
- Added ultra-light traffic is now a separate traffic class that can have its
[flightgear.git] / src / Main / fg_os_sdl.cxx
index 318c7d3b98c9666f991f51db0364907c103e072e..7917832075409f7473ffa640c15a00a1ac243957 100644 (file)
@@ -15,6 +15,7 @@
 
 static fgIdleHandler IdleHandler = 0;
 static fgDrawHandler DrawHandler = 0;
+static fgWindowResizeHandler WindowResizeHandler = 0;
 static fgKeyHandler KeyHandler = 0;
 static fgMouseClickHandler MouseClickHandler = 0;
 static fgMouseMotionHandler MouseMotionHandler = 0;
@@ -24,6 +25,7 @@ static int CurrentMouseX = 0;
 static int CurrentMouseY = 0;
 static int CurrentMouseCursor = MOUSE_CURSOR_POINTER;
 static bool NeedRedraw = false;
+static int VidMask = SDL_OPENGL|SDL_RESIZABLE;
 
 void fgRegisterIdleHandler(fgIdleHandler func)
 {
@@ -38,7 +40,7 @@ void fgRegisterDrawHandler(fgDrawHandler func)
 
 void fgRegisterWindowResizeHandler(fgWindowResizeHandler func)
 {
-    // Noop.  SDL does not support window resize.
+    WindowResizeHandler = func;
 }
 
 void fgRegisterKeyHandler(fgKeyHandler func)
@@ -84,11 +86,10 @@ void fgOSOpenWindow(int w, int h, int bpp,
     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, zbits);
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 
-    int vidmask = SDL_OPENGL;
     if(fullscreen) {
-        vidmask |= SDL_FULLSCREEN;
+        VidMask |= SDL_FULLSCREEN;
     }
-    if (SDL_SetVideoMode(w, h, 16, vidmask) == 0)
+    if (SDL_SetVideoMode(w, h, 16, VidMask) == 0)
         throw sg_throwable(string("Failed to set SDL video mode: ")
                                    + SDL_GetError());
 
@@ -111,6 +112,14 @@ void fgOSOpenWindow(int w, int h, int bpp,
     // int realh = screen->h;
 }
 
+
+struct keydata {
+    keydata() : unicode(0), mod(0) {};
+    Uint16 unicode;
+    unsigned int mod;
+} keys[SDLK_LAST];
+
+
 static void handleKey(int key, int raw, int keyup)
 {
     int modmask = 0;
@@ -172,8 +181,19 @@ static void handleKey(int key, int raw, int keyup)
         CurrentModifiers |= modmask;
         keymod = CurrentModifiers & ~KEYMOD_RELEASED;
     }
-    if(modmask == 0 && KeyHandler)
+
+    if(modmask == 0 && KeyHandler) {
+        if (keymod & KEYMOD_RELEASED) {
+            if (keys[raw].mod) {
+                key = keys[raw].unicode;
+                keys[raw].mod = 0;
+            }
+        } else {
+            keys[raw].mod = keymod;
+            keys[raw].unicode = key;
+        }
         (*KeyHandler)(key, keymod, CurrentMouseX, CurrentMouseY);
+    }
 }
 
 // FIXME: Integrate with existing fgExit() in util.cxx.
@@ -206,7 +226,7 @@ void fgOSMainLoop()
                 if(MouseClickHandler)
                     (*MouseClickHandler)(e.button.button - 1,
                                          e.button.state == SDL_RELEASED,
-                                         e.button.x, e.button.y);
+                                         e.button.x, e.button.y, true, 0);
                 break;
             case SDL_MOUSEMOTION:
                 CurrentMouseX = e.motion.x;
@@ -214,6 +234,14 @@ void fgOSMainLoop()
                 if(MouseMotionHandler)
                     (*MouseMotionHandler)(e.motion.x, e.motion.y);
                 break;
+            case SDL_VIDEORESIZE:
+                if (SDL_SetVideoMode(e.resize.w, e.resize.h, 16, VidMask) == 0)
+                    throw sg_throwable(string("Failed to set SDL video mode: ")
+                            + SDL_GetError());
+
+                if (WindowResizeHandler)
+                    (*WindowResizeHandler)(e.resize.w, e.resize.h);
+                break;
             }
         }
         if(IdleHandler) (*IdleHandler)();
@@ -232,6 +260,9 @@ int fgGetKeyModifiers()
 
 void fgWarpMouse(int x, int y)
 {
+    SDL_Event e[10];
+    SDL_PumpEvents();
+    SDL_PeepEvents(e, 10, SDL_GETEVENT, SDL_MOUSEMOTIONMASK);
     SDL_WarpMouse(x, y);
 }
 
@@ -376,3 +407,18 @@ static void initCursors()
                                                 cursors[i].hoty);
     }
 }
+
+// Noop; the graphics context is always current
+void fgMakeCurrent()
+{
+}
+
+bool fgOSIsMainCamera(const osg::Camera*)
+{
+  return true;
+}
+
+bool fgOSIsMainContext(const osg::GraphicsContext*)
+{
+  return true;
+}