From 17bcab4f32568fe875b5ef421663e2ab6c478c97 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 11 Mar 2013 19:03:37 -0300 Subject: [PATCH] Added love.graphics.getDimensions and Image/Canvas/ImageData:getDimensions (issue #566) --- src/modules/graphics/opengl/wrap_Canvas.cpp | 9 +++++++++ src/modules/graphics/opengl/wrap_Canvas.h | 1 + src/modules/graphics/opengl/wrap_Graphics.cpp | 8 ++++++++ src/modules/graphics/opengl/wrap_Graphics.h | 1 + src/modules/graphics/opengl/wrap_Image.cpp | 9 +++++++++ src/modules/graphics/opengl/wrap_Image.h | 1 + src/modules/image/wrap_ImageData.cpp | 9 +++++++++ src/modules/image/wrap_ImageData.h | 1 + 8 files changed, 39 insertions(+) diff --git a/src/modules/graphics/opengl/wrap_Canvas.cpp b/src/modules/graphics/opengl/wrap_Canvas.cpp index f9dab3ee4..39728391b 100644 --- a/src/modules/graphics/opengl/wrap_Canvas.cpp +++ b/src/modules/graphics/opengl/wrap_Canvas.cpp @@ -209,6 +209,14 @@ int w_Canvas_getHeight(lua_State *L) return 1; } +int w_Canvas_getDimensions(lua_State *L) +{ + Canvas *canvas = luax_checkcanvas(L, 1); + lua_pushnumber(L, canvas->getWidth()); + lua_pushnumber(L, canvas->getHeight()); + return 2; +} + int w_Canvas_getType(lua_State *L) { Canvas *canvas = luax_checkcanvas(L, 1); @@ -231,6 +239,7 @@ static const luaL_Reg functions[] = { "clear", w_Canvas_clear }, { "getWidth", w_Canvas_getWidth }, { "getHeight", w_Canvas_getHeight }, + { "getDimensions", w_Canvas_getDimensions }, { "getType", w_Canvas_getType }, { 0, 0 } }; diff --git a/src/modules/graphics/opengl/wrap_Canvas.h b/src/modules/graphics/opengl/wrap_Canvas.h index 2281fe713..88ae75e1b 100644 --- a/src/modules/graphics/opengl/wrap_Canvas.h +++ b/src/modules/graphics/opengl/wrap_Canvas.h @@ -44,6 +44,7 @@ int w_Canvas_getWrap(lua_State *L); int w_Canvas_clear(lua_State *L); int w_Canvas_getWidth(lua_State *L); int w_Canvas_getHeight(lua_State *L); +int w_Canvas_getDimensions(lua_State *L); int w_Canvas_getType(lua_State *L); extern "C" int luaopen_canvas(lua_State *L); diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index d0a685f13..7d30eb79e 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -186,6 +186,13 @@ int w_getHeight(lua_State *L) return 1; } +int w_getDimensions(lua_State *L) +{ + lua_pushnumber(L, instance->getWidth()); + lua_pushnumber(L, instance->getHeight()); + return 2; +} + int w_isCreated(lua_State *L) { luax_pushboolean(L, instance->isCreated()); @@ -1340,6 +1347,7 @@ static const luaL_Reg functions[] = { "getWidth", w_getWidth }, { "getHeight", w_getHeight }, + { "getDimensions", w_getDimensions }, { "isCreated", w_isCreated }, diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index b86e4abed..aa2e1abde 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -50,6 +50,7 @@ int w_setCaption(lua_State *L); int w_getCaption(lua_State *L); int w_getWidth(lua_State *L); int w_getHeight(lua_State *L); +int w_getDimensions(lua_State *L); int w_isCreated(lua_State *L); int w_setScissor(lua_State *L); int w_getScissor(lua_State *L); diff --git a/src/modules/graphics/opengl/wrap_Image.cpp b/src/modules/graphics/opengl/wrap_Image.cpp index 16d140901..fbf98857e 100644 --- a/src/modules/graphics/opengl/wrap_Image.cpp +++ b/src/modules/graphics/opengl/wrap_Image.cpp @@ -47,6 +47,14 @@ int w_Image_getHeight(lua_State *L) return 1; } +int w_Image_getDimensions(lua_State *L) +{ + Image *t = luax_checkimage(L, 1); + lua_pushnumber(L, t->getWidth()); + lua_pushnumber(L, t->getHeight()); + return 2; +} + int w_Image_setFilter(lua_State *L) { Image *t = luax_checkimage(L, 1); @@ -178,6 +186,7 @@ static const luaL_Reg functions[] = { { "getWidth", w_Image_getWidth }, { "getHeight", w_Image_getHeight }, + { "getDimensions", w_Image_getDimensions }, { "setFilter", w_Image_setFilter }, { "getFilter", w_Image_getFilter }, { "setWrap", w_Image_setWrap }, diff --git a/src/modules/graphics/opengl/wrap_Image.h b/src/modules/graphics/opengl/wrap_Image.h index a986bed9b..ac88456f2 100644 --- a/src/modules/graphics/opengl/wrap_Image.h +++ b/src/modules/graphics/opengl/wrap_Image.h @@ -35,6 +35,7 @@ namespace opengl Image *luax_checkimage(lua_State *L, int idx); int w_Image_getWidth(lua_State *L); int w_Image_getHeight(lua_State *L); +int w_Image_getDimensions(lua_State *L); int w_Image_setFilter(lua_State *L); int w_image_getFilter(lua_State *L); int w_Image_setMipmapFilter(lua_State *L); diff --git a/src/modules/image/wrap_ImageData.cpp b/src/modules/image/wrap_ImageData.cpp index 8bbd996e2..0261bd59c 100644 --- a/src/modules/image/wrap_ImageData.cpp +++ b/src/modules/image/wrap_ImageData.cpp @@ -47,6 +47,14 @@ int w_ImageData_getHeight(lua_State *L) return 1; } +int w_ImageData_getDimensions(lua_State *L) +{ + ImageData *t = luax_checkimagedata(L, 1); + lua_pushinteger(L, t->getWidth()); + lua_pushinteger(L, t->getHeight()); + return 2; +} + int w_ImageData_getPixel(lua_State *L) { ImageData *t = luax_checkimagedata(L, 1); @@ -188,6 +196,7 @@ static const luaL_Reg functions[] = { "getWidth", w_ImageData_getWidth }, { "getHeight", w_ImageData_getHeight }, + { "getDimensions", w_ImageData_getDimensions }, { "getPixel", w_ImageData_getPixel }, { "setPixel", w_ImageData_setPixel }, { "mapPixel", w_ImageData_mapPixel }, diff --git a/src/modules/image/wrap_ImageData.h b/src/modules/image/wrap_ImageData.h index 142439d4a..7e375bb8e 100644 --- a/src/modules/image/wrap_ImageData.h +++ b/src/modules/image/wrap_ImageData.h @@ -33,6 +33,7 @@ namespace image ImageData *luax_checkimagedata(lua_State *L, int idx); int w_ImageData_getWidth(lua_State *L); int w_ImageData_getHeight(lua_State *L); +int w_ImageData_getDimensions(lua_State *L); int w_ImageData_getPixel(lua_State *L); int w_ImageData_setPixel(lua_State *L); int w_ImageData_mapPixel(lua_State *L);