]> git.jsancho.org Git - lugaru.git/blobdiff - Source/OpenGL_Windows.cpp
Try fallbacks if we can't set video mode.
[lugaru.git] / Source / OpenGL_Windows.cpp
index 1588b6456c4014505707bc2fe9fe047782132239..2937fefc3948994ab0af8bd9aaf803c729c209c5 100644 (file)
@@ -468,17 +468,10 @@ static void sdlEventProc(const SDL_Event &e, Game &game)
                case SDL_MOUSEBUTTONDOWN:
                        {
                 val = clamp_sdl_mouse_button(e.button.button);
-                if (val >= 0)
+                if ((val >= 0) && (val <= 2))
                 {
                     if (val == 0)
-                    {
                                    g_button = true;
-                        SetKey(MAC_MOUSEBUTTON1);
-                    }
-
-                    else if (val == 1)
-                        SetKey(MAC_MOUSEBUTTON2);
-
                                buttons[val] = true;
                 }
                        }
@@ -487,17 +480,10 @@ static void sdlEventProc(const SDL_Event &e, Game &game)
                case SDL_MOUSEBUTTONUP:
                        {
                 val = clamp_sdl_mouse_button(e.button.button);
-                if (val >= 0)
+                if ((val >= 0) && (val <= 2))
                 {
                     if (val == 0)
-                    {
                                    g_button = false;
-                        ClearKey(MAC_MOUSEBUTTON1);
-                    }
-
-                    else if (val == 1)
-                        ClearKey(MAC_MOUSEBUTTON2);
-
                                buttons[val] = false;
                 }
                        }
@@ -518,6 +504,16 @@ static void sdlEventProc(const SDL_Event &e, Game &game)
                 }
             }
 
+            #if (defined(__APPLE__) && defined(__MACH__))
+            if (e.key.keysym.sym == SDLK_q)
+            {
+                if (e.key.keysym.mod & KMOD_META)
+                {
+                    gDone=true;
+                }
+            }
+            #endif
+
             else if (e.key.keysym.sym == SDLK_RETURN)
             {
                 if (e.key.keysym.mod & KMOD_ALT)
@@ -884,14 +880,27 @@ Boolean SetUp (Game & game)
     if (!cmdline("windowed"))
         sdlflags |= SDL_FULLSCREEN;
 
-    SDL_WM_SetCaption("Lugaru", "lugaru");
+    SDL_WM_SetCaption("Lugaru", "Lugaru");
 
     SDL_ShowCursor(0);
 
     if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL)
     {
         fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
-        return false;
+        fprintf(stderr, "forcing 640x480...\n");
+        kContextWidth = 640;
+        kContextHeight = 480;
+        if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL)
+        {
+            fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+            fprintf(stderr, "forcing 640x480 windowed mode...\n");
+            sdlflags &= ~SDL_FULLSCREEN;
+            if (SDL_SetVideoMode(kContextWidth, kContextHeight, 0, sdlflags) == NULL)
+            {
+                fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+                return false;
+            }
+        }
     }
 
     if (!lookup_all_glsyms())
@@ -1355,6 +1364,14 @@ static void launch_web_browser(const char *url)
 #ifdef WIN32
     ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL);
 
+#elif (defined(__APPLE__) && defined(__MACH__))
+    const char *fmt = "open '%s'";
+    const size_t len = strlen(fmt) + strlen(url) + 16;
+    char *buf = new char[len];
+    snprintf(buf, len, fmt, url);
+    system(buf);
+    delete[] buf;
+
 #elif PLATFORM_LINUX
     const char *fmt = "PATH=$PATH:. xdg-open '%s'";
     const size_t len = strlen(fmt) + strlen(url) + 16;
@@ -1448,6 +1465,19 @@ static inline void chdirToAppPath(const char *argv0)
     char *dir = calcBaseDir(argv0);
     if (dir)
     {
+        #if (defined(__APPLE__) && defined(__MACH__))
+        // Chop off /Contents/MacOS if it's at the end of the string, so we
+        //  land in the base of the app bundle.
+        const size_t len = strlen(dir);
+        const char *bundledirs = "/Contents/MacOS";
+        const size_t bundledirslen = strlen(bundledirs);
+        if (len > bundledirslen)
+        {
+            char *ptr = (dir + len) - bundledirslen;
+            if (strcasecmp(ptr, bundledirs) == 0)
+                *ptr = '\0';
+        }
+        #endif
         chdir(dir);
         free(dir);
     }
@@ -1576,10 +1606,12 @@ int main(int argc, char **argv)
 //             if(game.registernow){
                if(regnow)
                {
-            #if PLATFORM_LINUX  // (this may not be necessary any more.)
-            launch_web_browser("http://www.wolfire.com/registerlinux.html");
+            #if (defined(__APPLE__) && defined(__MACH__))
+            launch_web_browser("http://www.wolfire.com/purchase/lugaru/mac");
+            #elif PLATFORM_LINUX
+            launch_web_browser("http://www.wolfire.com/purchase/lugaru/linux");
             #else
-            launch_web_browser("http://www.wolfire.com/registerpc.html");
+            launch_web_browser("http://www.wolfire.com/purchase/lugaru/pc");
             #endif
                }