Browse Source

Cleaned up some code.

Alex Szpakowski 11 years ago
parent
commit
c6b610d116

+ 5 - 7
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;

+ 12 - 20
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<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))
 	{

+ 10 - 20
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<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;
-
-	love::window::Window *window = love::window::sdl::Window::getSingleton();
-	if (window != nullptr)
-		scale = window->getPixelScale();
-
-	if (x != nullptr)
-		*x = int(double(*x) / scale);
+	window::Window *window = Module::getInstance<window::Window>(Module::M_WINDOW);
 
-	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

+ 5 - 0
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

+ 4 - 16
src/modules/window/sdl/Window.cpp

@@ -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;