瀏覽代碼

Added all standard optional draw parameters to love.graphics.printf: angle, sx, sy, ox, oy, kx, and ky

Alex Szpakowski 12 年之前
父節點
當前提交
288971a3ad

+ 43 - 25
src/modules/graphics/opengl/Graphics.cpp

@@ -722,7 +722,7 @@ void Graphics::print(const char *str, float x, float y , float angle, float sx,
 	}
 	}
 }
 }
 
 
-void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode align)
+void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
 {
 {
 	if (currentFont == 0)
 	if (currentFont == 0)
 		return;
 		return;
@@ -731,34 +731,52 @@ void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode a
 	string text(str);
 	string text(str);
 	vector<string> lines_to_draw = currentFont->getWrap(text, wrap);
 	vector<string> lines_to_draw = currentFont->getWrap(text, wrap);
 
 
-	// now for the actual printing
-	vector<string>::const_iterator line_iter, line_end = lines_to_draw.end();
-	float letter_spacing = 0.0f;
-	for (line_iter = lines_to_draw.begin(); line_iter != line_end; ++line_iter)
+	glPushMatrix();
+
+	static Matrix t;
+	t.setTransformation(ceil(x), ceil(y), angle, sx, sy, ox, oy, kx, ky);
+	glMultMatrixf((const GLfloat *)t.getElements());
+
+	x = y = 0.0f;
+
+	try
 	{
 	{
-		float width = static_cast<float>(currentFont->getWidth(*line_iter));
-		switch (align)
+		// now for the actual printing
+		vector<string>::const_iterator line_iter, line_end = lines_to_draw.end();
+		float letter_spacing = 0.0f;
+		for (line_iter = lines_to_draw.begin(); line_iter != line_end; ++line_iter)
 		{
 		{
-		case ALIGN_RIGHT:
-			currentFont->print(*line_iter, ceil(x + wrap - width), ceil(y));
-			break;
-		case ALIGN_CENTER:
-			currentFont->print(*line_iter, ceil(x + (wrap - width) / 2), ceil(y));
-			break;
-		case ALIGN_JUSTIFY:
-			if (line_iter->length() > 1 && (line_iter+1) != line_end)
-				letter_spacing = (wrap - width) / float(line_iter->length() - 1);
-			else
-				letter_spacing = 0.0f;
-			currentFont->print(*line_iter, ceil(x), ceil(y), letter_spacing);
-			break;
-		case ALIGN_LEFT:
-		default:
-			currentFont->print(*line_iter, ceil(x), ceil(y));
-			break;
+			float width = static_cast<float>(currentFont->getWidth(*line_iter));
+			switch (align)
+			{
+			case ALIGN_RIGHT:
+				currentFont->print(*line_iter, ceil(x + (wrap - width)), ceil(y), 0.0f);
+				break;
+			case ALIGN_CENTER:
+				currentFont->print(*line_iter, ceil(x + (wrap - width) / 2), ceil(y), 0.0f);
+				break;
+			case ALIGN_JUSTIFY:
+				if (line_iter->length() > 1 && (line_iter+1) != line_end)
+					letter_spacing = (wrap - width) / float(line_iter->length() - 1);
+				else
+					letter_spacing = 0.0f;
+				currentFont->print(*line_iter, ceil(x), ceil(y), letter_spacing);
+				break;
+			case ALIGN_LEFT:
+			default:
+				currentFont->print(*line_iter, ceil(x), ceil(y), 0.0f);
+				break;
+			}
+			y += currentFont->getHeight() * currentFont->getLineHeight();
 		}
 		}
-		y += currentFont->getHeight() * currentFont->getLineHeight();
 	}
 	}
+	catch (love::Exception &)
+	{
+		glPopMatrix();
+		throw;
+	}
+
+	glPopMatrix();
 }
 }
 
 
 /**
 /**

+ 9 - 2
src/modules/graphics/opengl/Graphics.h

@@ -392,7 +392,7 @@ public:
 	 * @param kx Shear along the x-axis.
 	 * @param kx Shear along the x-axis.
 	 * @param ky Shear along the y-axis.
 	 * @param ky Shear along the y-axis.
 	 **/
 	 **/
-	void print(const char *str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky);
+	void print(const char *str, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
 
 
 	/**
 	/**
 	 * Draw formatted text on screen at the specified coordinates.
 	 * Draw formatted text on screen at the specified coordinates.
@@ -402,8 +402,15 @@ public:
 	 * @param y The y-coordinate.
 	 * @param y The y-coordinate.
 	 * @param wrap The maximum width of the text area.
 	 * @param wrap The maximum width of the text area.
 	 * @param align Where to align the text.
 	 * @param align Where to align the text.
+	 * @param angle The amount of rotation.
+	 * @param sx The scale factor along the x-axis. (1 = normal).
+	 * @param sy The scale factor along the y-axis. (1 = normal).
+	 * @param ox The origin offset along the x-axis.
+	 * @param oy The origin offset along the y-axis.
+	 * @param kx Shear along the x-axis.
+	 * @param ky Shear along the y-axis.
 	 **/
 	 **/
-	void printf(const char *str, float x, float y, float wrap, AlignMode align);
+	void printf(const char *str, float x, float y, float wrap, AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky);
 
 
 	/**
 	/**
 	 * Draws a point at (x,y).
 	 * Draws a point at (x,y).

+ 20 - 4
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -1055,18 +1055,34 @@ int w_printf(lua_State *L)
 	float y = (float)luaL_checknumber(L, 3);
 	float y = (float)luaL_checknumber(L, 3);
 	float wrap = (float)luaL_checknumber(L, 4);
 	float wrap = (float)luaL_checknumber(L, 4);
 
 
+	float angle = 0.0f;
+	float sx = 1.0f, sy = 1.0f;
+	float ox = 0.0f, oy = 0.0f;
+	float kx = 0.0f, ky = 0.0f;
+
 	Graphics::AlignMode align = Graphics::ALIGN_LEFT;
 	Graphics::AlignMode align = Graphics::ALIGN_LEFT;
 
 
 	if (lua_gettop(L) >= 5)
 	if (lua_gettop(L) >= 5)
 	{
 	{
-		const char *str = luaL_checkstring(L, 5);
-		if (!Graphics::getConstant(str, align))
-			return luaL_error(L, "Incorrect alignment: %s", str);
+		if (!lua_isnil(L, 5))
+		{
+			const char *str = luaL_checkstring(L, 5);
+			if (!Graphics::getConstant(str, align))
+				return luaL_error(L, "Incorrect alignment: %s", str);
+		}
+
+		angle = (float) luaL_optnumber(L, 6, 0.0f);
+		sx = (float) luaL_optnumber(L, 7, 1.0f);
+		sy = (float) luaL_optnumber(L, 8, sx);
+		ox = (float) luaL_optnumber(L, 9, 0.0f);
+		oy = (float) luaL_optnumber(L, 10, 0.0f);
+		kx = (float) luaL_optnumber(L, 11, 0.0f);
+		ky = (float) luaL_optnumber(L, 12, 0.0f);
 	}
 	}
 
 
 	try
 	try
 	{
 	{
-		instance->printf(str, x, y, wrap, align);
+		instance->printf(str, x, y, wrap, align, angle, sx, sy, ox, oy, kx, ky);
 	}
 	}
 	catch(love::Exception e)
 	catch(love::Exception e)
 	{
 	{