diff --git a/platform/macosx/OSX.mm b/platform/macosx/OSX.mm index 418de494f..bce0d6a43 100644 --- a/platform/macosx/OSX.mm +++ b/platform/macosx/OSX.mm @@ -34,13 +34,11 @@ std::string getLoveInResources() @autoreleasepool { - // check to see if there are any .love files in Resources - props to stevejohnson/diordna - NSArray *lovePaths = [[NSBundle mainBundle] pathsForResourcesOfType:@"love" inDirectory:nil]; - if ([lovePaths count] > 0) - { - NSString *firstLovePath = [lovePaths objectAtIndex:0]; - path = std::string([firstLovePath UTF8String]); - } + // Check to see if there are any .love files in Resources. + NSString *lovepath = [[NSBundle mainBundle] pathForResource:nil ofType:@"love"]; + + if (lovepath != nil) + path = [lovepath UTF8String]; } return path; diff --git a/src/modules/event/sdl/Event.cpp b/src/modules/event/sdl/Event.cpp index 8e0fe7365..f3537a6e9 100644 --- a/src/modules/event/sdl/Event.cpp +++ b/src/modules/event/sdl/Event.cpp @@ -42,17 +42,12 @@ namespace sdl // we want them in pixel coordinates (may be different with high-DPI enabled.) static void windowToPixelCoords(int *x, int *y) { - double scale = 1.0; - window::Window *window = Module::getInstance(Module::M_WINDOW); - if (window != nullptr) - scale = window->getPixelScale(); - if (x != nullptr) - *x = int(double(*x) * scale); - - if (y != nullptr) - *y = int(double(*y) * scale); + if (window && x) + *x = (int) window->toPixels(*x); + if (window && y) + *y = (int) window->toPixels(*y); } @@ -74,15 +69,11 @@ Event::~Event() void Event::pump() { - SDL_PumpEvents(); - - static SDL_Event e; - - Message *msg; + SDL_Event e; while (SDL_PollEvent(&e)) { - msg = convert(e); + Message *msg = convert(e); if (msg) { push(msg); @@ -93,16 +84,17 @@ void Event::pump() Message *Event::wait() { - static SDL_Event e; - bool ok = (SDL_WaitEvent(&e) == 1); - if (!ok) - return NULL; + SDL_Event e; + + if (SDL_WaitEvent(&e) != 1) + return nullptr; + return convert(e); } void Event::clear() { - static SDL_Event e; + SDL_Event e; while (SDL_PollEvent(&e)) { diff --git a/src/modules/mouse/sdl/Mouse.cpp b/src/modules/mouse/sdl/Mouse.cpp index cf1ccd0c9..ed97d4438 100644 --- a/src/modules/mouse/sdl/Mouse.cpp +++ b/src/modules/mouse/sdl/Mouse.cpp @@ -36,33 +36,23 @@ namespace sdl // we want them in pixel coordinates (may be different with high-DPI enabled.) static void windowToPixelCoords(int *x, int *y) { - double scale = 1.0; + window::Window *window = Module::getInstance(Module::M_WINDOW); - love::window::Window *window = love::window::sdl::Window::getSingleton(); - if (window != nullptr) - scale = window->getPixelScale(); - - if (x != nullptr) - *x = int(double(*x) * scale); - - if (y != nullptr) - *y = int(double(*y) * scale); + if (window && x) + *x = (int) window->toPixels(*x); + if (window && y) + *y = (int) window->toPixels(*y); } // And vice versa for setting mouse coordinates. static void pixelToWindowCoords(int *x, int *y) { - double scale = 1.0; + window::Window *window = Module::getInstance(Module::M_WINDOW); - love::window::Window *window = love::window::sdl::Window::getSingleton(); - if (window != nullptr) - scale = window->getPixelScale(); - - if (x != nullptr) - *x = int(double(*x) / scale); - - if (y != nullptr) - *y = int(double(*y) / scale); + if (window && x) + *x = (int) window->fromPixels(*x); + if (window && y) + *y = (int) window->fromPixels(*y); } const char *Mouse::getName() const diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index 4ada807c9..ecd7bd368 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -84,6 +84,11 @@ public: { int width; int height; + + bool operator == (const WindowSize &w) const + { + return w.width == width && w.height == height; + } }; struct MessageBoxData diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 5791c8fc7..89bb3a9c9 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -505,29 +505,17 @@ std::vector Window::getFullscreenSizes(int displayindex) const { std::vector sizes; - SDL_DisplayMode mode = {}; - std::vector::const_iterator it; for (int i = 0; i < SDL_GetNumDisplayModes(displayindex); i++) { + SDL_DisplayMode mode = {}; SDL_GetDisplayMode(displayindex, i, &mode); + WindowSize w = {mode.w, mode.h}; + // SDL2's display mode list has multiple entries for modes of the same // size with different bits per pixel, so we need to filter those out. - bool alreadyhassize = false; - for (it = sizes.begin(); it != sizes.end(); ++it) - { - if (it->width == mode.w && it->height == mode.h) - { - alreadyhassize = true; - break; - } - } - - if (!alreadyhassize) - { - WindowSize w = {mode.w, mode.h}; + if (std::find(sizes.begin(), sizes.end(), w) == sizes.end()) sizes.push_back(w); - } } return sizes;