mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Cleaned up some code.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<window::Window>(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))
|
||||
{
|
||||
|
||||
@@ -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<window::Window>(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<window::Window>(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
|
||||
|
||||
@@ -84,6 +84,11 @@ public:
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
|
||||
bool operator == (const WindowSize &w) const
|
||||
{
|
||||
return w.width == width && w.height == height;
|
||||
}
|
||||
};
|
||||
|
||||
struct MessageBoxData
|
||||
|
||||
@@ -505,29 +505,17 @@ std::vector<WindowSize> Window::getFullscreenSizes(int displayindex) const
|
||||
{
|
||||
std::vector<WindowSize> sizes;
|
||||
|
||||
SDL_DisplayMode mode = {};
|
||||
std::vector<WindowSize>::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;
|
||||
|
||||
Reference in New Issue
Block a user