cross platform gui lib for lua
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

106 lines
2.8 KiB

  1. /* uiImage ******************************************************************/
  2. /*** Object
  3. * Name: image
  4. * an image
  5. */
  6. #define uiImage(this) ((uiImage *) (this))
  7. #define LUI_IMAGE "lui_image"
  8. #define lui_pushImage(L) lui_pushObject(L, LUI_IMAGE, 0)
  9. #define lui_checkImage(L, pos) ((lui_object*)luaL_checkudata(L, pos, LUI_IMAGE))
  10. static int lui_image__gc(lua_State *L)
  11. {
  12. lui_object *lobj = lui_checkImage(L, 1);
  13. if (lobj->object) {
  14. DEBUGMSG("lui_image__gc (%s)", lui_debug_controlTostring(L, 1));
  15. uiFreeImage(uiImage(lobj->object));
  16. lobj->object = 0;
  17. }
  18. return 0;
  19. }
  20. // TODO __index for width and height?
  21. /* metamethods for image */
  22. static const luaL_Reg lui_image_meta[] = {
  23. {"__gc", lui_image__gc},
  24. {0, 0}
  25. };
  26. // TODO should this be append? See libui/test/page16.c, appendImageNamed()
  27. /*** Method
  28. * Object: image
  29. * Name: append
  30. * Signature: image = image:append(width, height, pixels)
  31. * set the pixels of an image. pixels is a table of either width * height * 4
  32. * float values in the order r, g, b, a for each pixel, or width * height rgba
  33. * tables as used with ui.draw.
  34. * Returns the image this method was called upon.
  35. */
  36. static int lui_image_append(lua_State *L)
  37. {
  38. lui_object *lobj = lui_checkImage(L, 1);
  39. (void) lobj; // TODO
  40. //uiImageAppend(uiImage(lobj->object), pixels, width, height, width * 4);
  41. // check what happens if a representation with same width / height is appended to an image
  42. //lua_pushvalue(L, 1);
  43. //return 1;
  44. return luaL_error(L, "not implemented");
  45. }
  46. /* methods for image */
  47. static const luaL_Reg lui_image_methods[] = {
  48. {"append", lui_image_append},
  49. {0, 0}
  50. };
  51. /*** Constructor
  52. * Object: image
  53. * Name: image
  54. * Signature: image = lui.image(width, height)
  55. * create a new, empty image object. width and height are the respective
  56. * sizes of the image in points. Typically this is the size in pixels.
  57. */
  58. static int lui_newImage(lua_State *L)
  59. {
  60. double width = luaL_checknumber(L, 1);
  61. double height = luaL_checknumber(L, 2);
  62. lui_object *lobj = lui_pushImage(L);
  63. lobj->object = uiNewImage(width, height);
  64. lui_registerObject(L, lua_gettop(L));
  65. return 1;
  66. }
  67. /*** Constructor
  68. * Object: image
  69. * Name: loadimage
  70. * Signature: image = lui.loadimage(filename)
  71. * create a new image object by loading it from a file. Width and height are
  72. * set from the respective sizes of the image file.
  73. */
  74. static int lui_loadImage(lua_State *L)
  75. {
  76. const char *file = luaL_checkstring(L, 1);
  77. (void) file; // TODO
  78. return luaL_error(L, "not implemented");
  79. }
  80. /* image function list table
  81. */
  82. static const struct luaL_Reg lui_image_funcs [] ={
  83. /* utility constructors */
  84. {"image", lui_newImage},
  85. {"loadimage", lui_loadImage},
  86. {0, 0}
  87. };
  88. static int lui_init_image(lua_State *L)
  89. {
  90. luaL_setfuncs(L, lui_image_funcs, 0);
  91. lui_add_utility_type(L, LUI_IMAGE, lui_image_methods, lui_image_meta);
  92. return 1;
  93. }