X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=Source%2FOpenGL_Windows.cpp;h=2efaac415be6bcf6fdc188de8a408bd63ad35fee;hb=5d346cad6a50bbd83d84721caae9235dff8132f0;hp=17766dbb66ead777eb92cc6700c692949ce4f1f6;hpb=f415499bb932770841f668fb6dc1ea6c76cbf494;p=lugaru.git diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index 17766db..2efaac4 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -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,7 +880,7 @@ Boolean SetUp (Game & game) if (!cmdline("windowed")) sdlflags |= SDL_FULLSCREEN; - SDL_WM_SetCaption("Lugaru", "lugaru"); + SDL_WM_SetCaption("Lugaru", "Lugaru"); SDL_ShowCursor(0); @@ -1350,112 +1346,26 @@ static bool IsFocused() } -#if PLATFORM_LINUX -#include -#include -#include -static bool try_launch_browser(const char *browser, const char *url) -{ - // make sure string isn't empty... - while ( (*browser) && (isspace(*browser)) ) browser++; - if (*browser == '\0') return false; - - bool seenurl = false; - char buf[4096]; // !!! FIXME: we aren't checking for overflow here! - char *dst = buf; - while (*browser) - { - char ch = *(browser++); - if (ch == '%') - { - ch = *(browser++); - if (ch == '%') - *(dst++) = '%'; - else if (ch == 's') // "%s" == insert URL here. - { - *(dst++) = '\''; - strcpy(dst, url); - dst += strlen(url); - *(dst++) = '\''; - seenurl = true; - } - // (not %% or %s? Drop the char.) - } - else - { - *(dst++) = ch; - } - } - - *dst = '\0'; - if (!seenurl) - { - strcat(dst, " "); - strcat(dst, url); - } - - #define MAX_BROWSER_ARGS 512 - char *args[MAX_BROWSER_ARGS]; - char *path = NULL; - memset(args, '\0', sizeof (args)); - path = args[0] = strtok(buf, " "); - if (path == NULL) - return false; - - size_t i = 0; - for (i = 1; i < MAX_BROWSER_ARGS; i++) - { - args[i] = strtok(NULL, " "); - if (args[i] == NULL) - break; - } - - if (i == MAX_BROWSER_ARGS) - return false; - #undef MAX_BROWSER_ARGS - - //printf("calling execvp(\"%s\"", path); - //for (i = 0; args[i]; i++) - // printf(", \"%s\"", args[i]); - //printf("); ...\n\n\n"); - - execvp(path, args); - return(false); // exec shouldn't return unless there's an error. -} -#endif - - static void launch_web_browser(const char *url) { #ifdef WIN32 ShellExecute(NULL, "open", url, NULL, NULL, SW_SHOWNORMAL); -// lousy linux doesn't have a clean way to do this, but you can point people -// to docs on the BROWSER variable: -// http://www.catb.org/~esr/BROWSER/ -#elif PLATFORM_LINUX - if (strchr(url, '\'') != NULL) // Prevent simple shell injection. - return; - - const char *envr = getenv("BROWSER"); - if (envr == NULL) // not specified? We'll try a pseudo-sane list... - envr = "opera:mozilla:konqueror:firefox:netscape:xterm -e links:xterm -e lynx:"; - - char *ptr = (char *) alloca(strlen(envr) + 1); - if (ptr == NULL) - return; - strcpy(ptr, envr); - envr = ptr; - - while ((ptr = strchr(envr, ':')) != NULL) - { - *ptr = '\0'; - if (try_launch_browser(envr, url)) - return; - envr = ptr + 1; - } +#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; - try_launch_browser(envr, url); +#elif PLATFORM_LINUX + const char *fmt = "PATH=$PATH:. xdg-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; #endif } @@ -1542,6 +1452,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); } @@ -1670,10 +1593,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 }