Browse Source

Make love.mouse.isDown accept a list too

Credits go to Boolsheet for making this patch (imported unmodified!)
Bart van Strien 14 years ago
parent
commit
4f6acb5f48

+ 8 - 5
src/modules/mouse/sdl/Mouse.cpp

@@ -63,14 +63,17 @@ namespace sdl
 		SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
 	}
 
-	bool Mouse::isDown(Button button) const
+	bool Mouse::isDown(Button * buttonlist) const
 	{
-		unsigned b = 0;
+		Uint8 buttonstate = SDL_GetMouseState(0, 0);
 
-		if(!buttons.find(button, b))
-			return false;
+		for (Button button = *buttonlist; button != BUTTON_MAX_ENUM; button = *(++buttonlist))
+		{
+			if (buttonstate & SDL_BUTTON(button))
+				return true;
+		}
 
-		return (SDL_GetMouseState(0, 0) & SDL_BUTTON(b)) != 0;
+		return false;
 	}
 
 	bool Mouse::isVisible() const

+ 2 - 2
src/modules/mouse/sdl/Mouse.h

@@ -43,7 +43,7 @@ namespace sdl
 		void getPosition(int & x, int & y) const;
 		void setPosition(int x, int y);
 		void setVisible(bool visible);
-		bool isDown(Button button) const;
+		bool isDown(Button * buttonlist) const;
 		bool isVisible() const;
 		void setGrab(bool grab);
 		bool isGrabbed() const;
@@ -59,4 +59,4 @@ namespace sdl
 } // mouse
 } // love
 
-#endif // LOVE_MOUSE_SDL_MOUSE_H
+#endif // LOVE_MOUSE_SDL_MOUSE_H

+ 14 - 7
src/modules/mouse/sdl/wrap_Mouse.cpp

@@ -59,13 +59,20 @@ namespace sdl
 
 	int w_isDown(lua_State * L)
 	{
-		Mouse::Button button;
-
-		if(!Mouse::getConstant(luaL_checkstring(L, 1), button))
-			luax_pushboolean(L, false);
-		else
-			luax_pushboolean(L, instance->isDown(button));
-
+		Mouse::Button b;
+		unsigned int num = lua_gettop(L);
+		Mouse::Button * buttonlist = new Mouse::Button[num+1];
+		unsigned int counter = 0;
+		
+		for (unsigned int i = 0; i < num; i++)
+		{
+			if(Mouse::getConstant(luaL_checkstring(L, i+1), b))
+				buttonlist[counter++] = b;
+		}
+		buttonlist[counter] = Mouse::BUTTON_MAX_ENUM;
+		
+		luax_pushboolean(L, instance->isDown(buttonlist));
+		delete[] buttonlist;
 		return 1;
 	}