Commits

itsnotabigtruck  committed 4074f88 Merge

Merging upstream changes

  • Participants
  • Parent commits 4a0f046, a17b9a7

Comments (0)

Files changed (11)

File src/modules/filesystem/physfs/Filesystem.cpp

 		}
 	}
 
+	int Filesystem::getLastModified(lua_State * L)
+	{
+		const char * filename = luaL_checkstring(L, 1);
+		int64_t time = PHYSFS_getLastModTime(filename);
+		if (time == -1)
+		{
+			lua_pushnil(L);
+			lua_pushstring(L, "Could not determine file modification date.");
+			return 2;
+		}
+		lua_pushnumber(L, time);
+		return 1;
+	}
+
 } // physfs
 } // filesystem
 } // love

File src/modules/filesystem/physfs/Filesystem.h

 		**/
 		int load(lua_State * L);
 
+		int getLastModified(lua_State * L);
+
 	}; // Filesystem
 
 } // physfs

File src/modules/filesystem/physfs/wrap_Filesystem.cpp

 		return instance->load(L);
 	}
 
+	int w_getLastModified(lua_State * L)
+	{
+		return instance->getLastModified(L);
+	}
+
 	int loader(lua_State * L)
 	{
 		const char * filename = lua_tostring(L, -1);
 		{ "enumerate",  w_enumerate },
 		{ "lines",  w_lines },
 		{ "load",  w_load },
+		{ "getLastModified", w_getLastModified },
 		{ "newFileData", w_newFileData },
 		{ 0, 0 }
 	};

File src/modules/filesystem/physfs/wrap_Filesystem.h

 	int w_enumerate(lua_State * L);
 	int w_lines(lua_State * L);
 	int w_load(lua_State * L);
+	int w_getLastModified(lua_State * L);
 	int loader(lua_State * L);
 	extern "C" LOVE_EXPORT int luaopen_love_filesystem(lua_State * L);
 

File src/modules/graphics/opengl/Font.cpp

 namespace opengl
 {
 
-	Font::Font(love::font::FontData * data)
-	: height(data->getHeight()), lineHeight(1.25), mSpacing(1)
+	Font::Font(love::font::FontData * data, const Image::Filter& filter)
+	: height(data->getHeight()), lineHeight(1), mSpacing(1)
 	{
 		glyphs = new Glyph*[MAX_CHARS];
 		type = FONT_UNKNOWN;
 		for(unsigned int i = 0; i < MAX_CHARS; i++)
 		{
 			gd = data->getGlyphData(i);
-			glyphs[i] = new Glyph(gd);
+			glyphs[i] = new Glyph(gd, filter);
 			glyphs[i]->load();
 			widths[i] = gd->getWidth();
 			spacing[i] = gd->getAdvance();
 
 	float Font::getHeight() const
 	{
-		return height / lineHeight;
+		return height;
 	}
 
 	void Font::print(std::string text, float x, float y, float angle, float sx, float sy) const
 		for (unsigned int i = 0; i < text.size(); i++) {
 			unsigned char g = (unsigned char)text[i];
 			if (g == '\n') { // wrap newline, but do not print it
-				glTranslatef(-dx, floor(getHeight() + 0.5f), 0);
+				glTranslatef(-dx, floor(getHeight() * getLineHeight() + 0.5f), 0);
 				dx = 0.0f;
 				continue;
 			}
 			if (!glyphs[g]) g = 32; // space
 			glPushMatrix();
-			if (type == FONT_TRUETYPE) glTranslatef(0, floor(getHeight() + 0.5f), 0);
+			// 1.25 is magic line height for true type fonts
+			if (type == FONT_TRUETYPE) glTranslatef(0, floor(getHeight() / 1.25f + 0.5f), 0);
 			glyphs[g]->draw(0, 0, 0, 1, 1, 0, 0);
 			glPopMatrix();
 			glTranslatef(spacing[g], 0, 0);
 
 	void Font::print(char character, float x, float y) const
 	{
-		if (!glyphs[character]) character = ' ';
+		if (!glyphs[(int)character]) character = ' ';
 		glPushMatrix();
 		glTranslatef(x, floor(y+getHeight() + 0.5f), 0.0f);
 		glCallList(list+character);

File src/modules/graphics/opengl/Font.h

 // LOVE
 #include <common/Object.h>
 #include <font/FontData.h>
+#include <graphics/Image.h>
 #include "Glyph.h"
 
 namespace love
 		*
 		* @param data The font data to construct from.
 		**/
-		Font(love::font::FontData * data);
+		Font(love::font::FontData * data, const Image::Filter& filter = Image::Filter());
 
 		virtual ~Font();
 

File src/modules/graphics/opengl/Glyph.cpp

 namespace opengl
 {
 
-	Glyph::Glyph(love::font::GlyphData * data)
-		: data(data), width((float)data->getWidth()), height((float)data->getHeight()), texture(0)
+	Glyph::Glyph(love::font::GlyphData * data, const Image::Filter& filter_)
+		: data(data),
+		width((float)data->getWidth()), height((float)data->getHeight()),
+		texture(0), filter(filter_)
 	{
 		data->retain();
 
 		
 		glGenTextures(1,&texture);
 		glBindTexture(GL_TEXTURE_2D, texture);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+				(filter.mag == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+				(filter.min == Image::FILTER_LINEAR) ? GL_LINEAR : GL_NEAREST);
 
 		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

File src/modules/graphics/opengl/Glyph.h

 #include <font/GlyphData.h>
 #include <graphics/Drawable.h>
 #include <graphics/Volatile.h>
+#include <graphics/Image.h>
 
 // OpenGL
 #include "GLee.h"
 
 		vertex vertices[4];
 
+		Image::Filter filter;
+
 	public:
 
 
-		Glyph(love::font::GlyphData * data);
+		Glyph(love::font::GlyphData * data, const Image::Filter& filter_ = Image::Filter());
 		virtual ~Glyph();
 
 		bool load();

File src/modules/graphics/opengl/Graphics.cpp

 		return new Quad(v, sw, sh);
 	}
 
-	Font * Graphics::newFont(love::font::FontData * data)
+	Font * Graphics::newFont(love::font::FontData * data, const Image::Filter& filter)
 	{
-		Font * font = new Font(data);
+		Font * font = new Font(data, filter);
 
 		// Load it and check for errors.
 		if(!font)
 		switch(mode)
 		{
 		case DRAW_LINE:
+			// offsets here because OpenGL is being a bitch about line drawings
 			glBegin(GL_LINE_LOOP);
 				glVertex2f(x, y);
 				glVertex2f(x, y+h-1);

File src/modules/graphics/opengl/Graphics.h

 		/**
 		* Creates a Font object.
 		**/
-		Font * newFont(love::font::FontData * data);
+		Font * newFont(love::font::FontData * data, const Image::Filter& filter = Image::Filter());
 
 		SpriteBatch * newSpriteBatch(Image * image, int size, int usage);
 

File src/modules/graphics/opengl/wrap_Graphics.cpp

 
 	int w_newImageFont(lua_State * L)
 	{
+		// filter for glyphs, defaults to linear/linear
+		Image::Filter img_filter;
+
 		// Convert to ImageData if necessary.
 		if(lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || (luax_istype(L, 1, DATA_T) && !luax_istype(L, 1, IMAGE_IMAGE_DATA_T) && !luax_istype(L, 1, FONT_FONT_DATA_T)))
 			luax_convobj(L, 1, "image", "newImageData");
 		else if(luax_istype(L, 1, GRAPHICS_IMAGE_T)) {
 			Image * i = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
+			img_filter = i->getFilter();
 			love::image::ImageData * id = i->getData();
 			luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*)id, false);
 			lua_replace(L, 1);
 		love::font::FontData * data = luax_checktype<love::font::FontData>(L, 1, "FontData", FONT_FONT_DATA_T);
 
 		// Create the font.
-		Font * font = instance->newFont(data);
+		Font * font = instance->newFont(data, img_filter);
 
 		if(font == 0)
 			return luaL_error(L, "Could not load font.");