From 6df9cb0de3e457788808b485b8b34bd8f0d6e42b Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Wed, 31 Oct 2018 12:39:50 -0400 Subject: Added more documentation Added documentation for luadoc for * io.* * phys.* * video.* --- src/client/lua_api/video/iimage.cpp | 52 ++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'src/client/lua_api/video') diff --git a/src/client/lua_api/video/iimage.cpp b/src/client/lua_api/video/iimage.cpp index 86d984e..6fbf6c5 100644 --- a/src/client/lua_api/video/iimage.cpp +++ b/src/client/lua_api/video/iimage.cpp @@ -4,12 +4,24 @@ #include +/*** +@module video +*/ + using namespace irr; using namespace video; extern IrrlichtDevice* device; extern IVideoDriver* driver; +/*** +Creates a new irrlicht image. +A newly created image will be fully white by default. +@function newiimage(format, size) +@tparam enum_color_format format The format for the image +@tparam vec2d size The size of the image +@treturn iimage The image +*/ //newiimage(ECOLOR_FORMAT,{width,height}) -> {image} int newiimage(lua_State* L){ //printf("Attempting to create new iimage\n"); @@ -28,23 +40,43 @@ int newiimage(lua_State* L){ return 1; } +/*** +Creates a new irrlicht image. +Creates a new irrlicht image from a file. The format and width/height will be +taken from the image file. +@function newiimagefromfile(path) +@tparam string path The file path of the image file +@treturn iimage The loaded image +*/ //newiimagefromfile("/path/to/file") -> {image} int newiimagefromfile(lua_State* L){ - //printf("Creating new iimage from file"); + printf("Creating new iimage from file"); const char* strpath = lua_tostring(L,-1); lua_pop(L,1); int numloaders = driver->getImageLoaderCount(); bool hasloaded = false; IImage* img = NULL; + printf("About to create and open file\n"); + io::IReadFile *f = device->getFileSystem()->createAndOpenFile(strpath); + if(!f){ + lua_pushstring(L,"Failed to open file: "); + lua_pushstring(L,strpath); + lua_concat(L,2); + lua_error(L); + } + printf("Opened file\n"); for(int j = 0; j < numloaders; j++){ IImageLoader* loader = driver->getImageLoader(j); - io::IReadFile* f = device->getFileSystem()->createAndOpenFile(strpath); if(!loader->isALoadableFileExtension(strpath)) continue; if(!loader->isALoadableFileFormat(f)) continue; + f->seek(0,false); hasloaded = true; + printf("Found a loader, about to load\n"); img = loader->loadImage(f); + printf("Done loading\n"); + f->drop(); } if(!hasloaded){ lua_pushstring(L,"Failed to load file, no image loader for this type."); @@ -54,15 +86,23 @@ int newiimagefromfile(lua_State* L){ lua_pushstring(L,"Failed to load image"); lua_error(L); } + printf("Successfully loaded\n"); lua_newtable(L); lua_pushlightuserdata(L,img); lua_setfield(L,-2,"image"); luaL_getmetatable(L,"iimage"); lua_setmetatable(L,-2); - //printf("IImage made, returning!"); + printf("IImage made, returning!"); return 1; } +/*** +Sets the color of an image at a particular pixel. +@function iimage:setpixel(position,color,shouldblend) +@tparam vec2i position The position of the pixel to change colors +@tparam color color The color to change the pixel to +@tparam boolean shouldblend Should this pixel blend into it's neighbors? +*/ //setpixel({self},{x,y},{r,g,b,a},bool_shouldblend) int setiimagepixel(lua_State* L){ bool sb = lua_toboolean(L,-1);//{ud_iimage},{x,y},{r,g,b,a},bool_shouldblend @@ -78,6 +118,12 @@ int setiimagepixel(lua_State* L){ return 0; } +/*** +Returns the color at a position in the image. +@function iimage:getpixel(position) +@tparam vec2i position The position of the pixel to return +@treturn color The color of the image at the position +*/ //getpixel({self},{x,y}) int getiimagepixel(lua_State* L){ long x,y; -- cgit v1.2.3-70-g09d2