diff src/scripts/graphics.lua @ 1102:c9f31b85db1d

Make love.graphics.getFont() return (and set) default font when no font set. Use closures instead of love.graphics.print(f)1() and love.graphics.newFont1.
author vrld <vrld@vrld.org>
date Thu, 05 Jul 2012 16:14:44 +0200
parents 86a44f2bc38f
children 526db808b1c9
line wrap: on
line diff
--- a/src/scripts/graphics.lua	Wed Jul 04 17:25:57 2012 +0200
+++ b/src/scripts/graphics.lua	Thu Jul 05 16:14:44 2012 +0200
@@ -1244,12 +1244,13 @@
 	AAIAAAxQCuxfDzz1AB8IAAAAAAC6ufC4AAAAALrCZ5H+if4dCkwHbQAAAAgAAQAAAAAAAA==
 	]], "Vera.ttf", "base64")
 
+	local _newFont = love.graphics.newFont
 	love.graphics.newFont = function(font, size)
 		if type(font) == "number" or not font then
 			size = font
 			font = vera_ttf
 		end
-		return love.graphics.newFont1(font, size or 12)
+		return _newFont(font, size or 12)
 	end
 
 	love.graphics.setNewFont = function(...)
@@ -1258,20 +1259,28 @@
 		return font
 	end
 
-	love.graphics.print = function (...)
-		if not love.graphics.getFont() then
-			love.graphics.setNewFont(12)
+	local _getFont = love.graphics.getFont
+	love.graphics.getFont = function(...)
+		local font = _getFont()
+		if not font then
+			font = love.graphics.setNewFont(12)
 		end
-		love.graphics.print1(...)
-		love.graphics.print = love.graphics.print1
+		love.graphics.getFont = _getFont
+		return font
 	end
 
+	local _print = love.graphics.print
+	love.graphics.print = function (...)
+		love.graphics.getFont() -- make sure we have a font
+		love.graphics.print = _print
+		love.graphics.print(...)
+	end
+
+	local _printf = love.graphics.printf
 	love.graphics.printf = function (...)
-		if not love.graphics.getFont() then
-			love.graphics.setNewFont(12)
-		end
-		love.graphics.printf1(...)
-		love.graphics.printf = love.graphics.printf1
+		love.graphics.getFont() -- make sure we have a font
+		love.graphics.printf = _printf
+		love.graphics.printf(...)
 	end
 
 	-- PIXEL EFFECTS