Commits

Bart van Strien  committed 85e543d

Add love.mouse.setX/setY (issue #438)

  • Participants
  • Parent commits 56a4af2

Comments (0)

Files changed (5)

File src/modules/mouse/Mouse.h

 		virtual int getX() const = 0;
 		virtual int getY() const = 0;
 		virtual void getPosition(int & x, int & y) const = 0;
+		virtual void setX(int x) = 0;
+		virtual void setY(int y) = 0;
 		virtual void setPosition(int x, int y) = 0;
 		virtual void setVisible(bool visible) = 0;
 		virtual bool isDown(Button * buttonlist) const = 0;
 } // mouse
 } // love
 
-#endif // LOVE_MOUSE_MOUSE_H
+#endif // LOVE_MOUSE_MOUSE_H

File src/modules/mouse/sdl/Mouse.cpp

 		SDL_WarpMouse(x, y);
 	}
 
+	void Mouse::setX(int x)
+	{
+		int y = getY();
+		setPosition(x, y);
+	}
+
+	void Mouse::setY(int y)
+	{
+		int x = getX();
+		setPosition(x, y);
+	}
+
 	void Mouse::setVisible(bool visible)
 	{
 		SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);

File src/modules/mouse/sdl/Mouse.h

 		int getX() const;
 		int getY() const;
 		void getPosition(int & x, int & y) const;
+		void setX(int x);
+		void setY(int y);
 		void setPosition(int x, int y);
 		void setVisible(bool visible);
 		bool isDown(Button * buttonlist) const;

File src/modules/mouse/wrap_Mouse.cpp

 		return 2;
 	}
 
+	int w_setX(lua_State * L)
+	{
+		int x = luaL_checkint(L, 1);
+		instance->setX(x);
+		return 0;
+	}
+
+	int w_setY(lua_State * L)
+	{
+		int y = luaL_checkint(L, 1);
+		instance->setY(y);
+		return 0;
+	}
+
 	int w_setPosition(lua_State * L)
 	{
 		int x = luaL_checkint(L, 1);
 	static const luaL_Reg functions[] = {
 		{ "getX", w_getX },
 		{ "getY", w_getY },
+		{ "setX", w_setX },
+		{ "setY", w_setY },
 		{ "setPosition", w_setPosition },
 		{ "isDown", w_isDown },
 		{ "setVisible", w_setVisible },

File src/modules/mouse/wrap_Mouse.h

 	int w_getX(lua_State * L);
 	int w_getY(lua_State * L);
 	int w_getPosition(lua_State * L);
+	int w_setX(lua_State * L);
+	int w_setY(lua_State * L);
 	int w_setPosition(lua_State * L);
 	int w_isDown(lua_State * L);
 	int w_setVisible(lua_State * L);