]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_os_sdl.cxx
- implement progress information (enabled by default; can be turned off via
[flightgear.git] / src / Main / fg_os_sdl.cxx
index 99f93056c115a0b5524a75f3d4d75ccf4fb6bf3d..16ab62d22f0ef2ac9ace1b4c4336caccc5bc0d22 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)
@@ -70,6 +72,7 @@ void fgOSOpenWindow(int w, int h, int bpp,
     if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) == -1)
         throw sg_throwable(string("Failed to initialize SDL: ")
                            + SDL_GetError());
+    atexit(SDL_Quit);
 
     SDL_WM_SetCaption("FlightGear", "FlightGear");
 
@@ -83,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());
 
@@ -175,12 +177,9 @@ static void handleKey(int key, int raw, int keyup)
         (*KeyHandler)(key, keymod, CurrentMouseX, CurrentMouseY);
 }
 
-// FIXME: need to export this and get the rest of FlightGear to use
-// it, the SDL hook is required to do things like reset the video
-// mode and key repeat.  Integrate with existing fgExit() in util.cxx.
+// FIXME: Integrate with existing fgExit() in util.cxx.
 void fgOSExit(int code)
 {
-    SDL_Quit();
     exit(code);
 }
 
@@ -216,6 +215,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)();
@@ -341,7 +348,7 @@ void fgSetMouseCursor(int cursor)
         return;
     }
     SDL_ShowCursor(SDL_ENABLE);
-    for(int i=0; i<NCURSORS; i++) {
+    for(unsigned int i=0; i<NCURSORS; i++) {
         if(cursor == cursors[i].name) {
             CurrentMouseCursor = cursor;
             SDL_SetCursor(cursors[i].sdlCursor);
@@ -361,8 +368,7 @@ int fgGetMouseCursor()
 static void initCursors()
 {
     unsigned char mask[128], img[128];
-    int i=0;
-    for(int i=0; i<NCURSORS; i++) {
+    for(unsigned int i=0; i<NCURSORS; i++) {
         if(cursors[i].name == MOUSE_CURSOR_NONE) break;
         for(int j=0; j<128; j++) mask[j] = img[j] = 0;
         for(int y=0; y<cursors[i].h; y++) {