Bart van Strien avatar Bart van Strien committed 76e5b9c

Add point and rectangle

Comments (0)

Files changed (4)

src/modules/graphics/sdl/Graphics.cpp

 	{
 		return backgroundColor;
 	}
+
+	void Graphics::point(float x, float y)
+	{
+		pixelRGBA(surface, (int) x, (int) y,
+				foregroundColor.r, foregroundColor.g, foregroundColor.b, foregroundColor.a);
+	}
+
+	void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h)
+	{
+		float x2 = x+w;
+		float y2 = y+h;
+
+		switch(mode)
+		{
+		case DRAW_LINE:
+			rectangleRGBA(surface, (int) x, (int) y, (int) x2, (int) y2,
+					foregroundColor.r, foregroundColor.g, foregroundColor.b, foregroundColor.a);
+			break;
+		case DRAW_FILL:
+			boxRGBA(surface, (int) x, (int) y, (int) x2, (int) y2,
+					foregroundColor.r, foregroundColor.g, foregroundColor.b, foregroundColor.a);
+			break;
+		default: // prevent warnings
+			break;
+		}
+	}
 } // sdl
 } // graphics
 } // love

src/modules/graphics/sdl/Graphics.h

 		void setBackgroundColor(const Color &c);
 		Color getBackgroundColor();
 
-/*		void point(float x, float y);
-		void triangle(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3);
+		void point(float x, float y);
+/*		void triangle(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3);*/
 		void rectangle(DrawMode mode, float x, float y, float w, float h);
-		void quad(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
+/*		void quad(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
 		void circle(DrawMode mode, float x, float y, float radius, int points = 10);*/
 	}; // Graphics
 } // sdl

src/modules/graphics/sdl/wrap_Graphics.cpp

 		return 4;
 	}
 
-/*	int w_point(lua_State *L)
+	int w_point(lua_State *L)
 	{
+		float x = luaL_checknumber(L, 1);
+		float y = luaL_checknumber(L, 2);
+		instance->point(x, y);
 		return 0;
 	}
 
-	int w_triangle(lua_State *L)
+/*	int w_triangle(lua_State *L)
 	{
 		return 0;
+	}*/
+
+	int w_rectangle(lua_State *L)
+	{
+		Graphics::DrawMode mode;
+		const char * str = luaL_checkstring(L, 1);
+		if (!Graphics::getConstant(str, mode))
+			return luaL_error(L, "Incorrect draw mode %s", str);
+
+		float x = luaL_checknumber(L, 2);
+		float y = luaL_checknumber(L, 3);
+		float w = luaL_checknumber(L, 4);
+		float h = luaL_checknumber(L, 5);
+		instance->rectangle(mode, x, y, w, h);
+		return 0;
 	}
 
-	int w_rectangle(lua_State *L)
-	{
-		return 0;
-	}
-
-	int w_quad(lua_State *L)
+/*	int w_quad(lua_State *L)
 	{
 		return 0;
 	}
 		{ "getColor", w_getColor },
 		{ "setBackgroundColor", w_setBackgroundColor },
 		{ "getBackgroundColor", w_getBackgroundColor },
-/*		{ "point", w_point },
-		{ "triangle", w_triangle },
+		{ "point", w_point },
+/*		{ "triangle", w_triangle },*/
 		{ "rectangle", w_rectangle },
-		{ "quad", w_quad },
+/*		{ "quad", w_quad },
 		{ "circle", w_circle },
 		{ "draw", w_draw },
 		{ "drawq", w_drawq },*/

src/modules/graphics/sdl/wrap_Graphics.h

 	int w_getColor(lua_State *L);
 	int w_setBackgroundColor(lua_State *L);
 	int w_getBackgroundColor(lua_State *L);
-/*	int w_point(lua_State *L);
-	int w_triangle(lua_State *L);
+	int w_point(lua_State *L);
+/*	int w_triangle(lua_State *L);*/
 	int w_rectangle(lua_State *L);
-	int w_quad(lua_State *L);
+/*	int w_quad(lua_State *L);
 	int w_circle(lua_State *L);
 	int w_draw(lua_State *L);
 	int w_drawq(lua_State *L);*/
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.