wrap_Quad.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Copyright (c) 2006-2016 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. // LOVE
  21. #include "wrap_Quad.h"
  22. namespace love
  23. {
  24. namespace graphics
  25. {
  26. Quad *luax_checkquad(lua_State *L, int idx)
  27. {
  28. return luax_checktype<Quad>(L, idx, GRAPHICS_QUAD_ID);
  29. }
  30. int w_Quad_setViewport(lua_State *L)
  31. {
  32. Quad *quad = luax_checkquad(L, 1);
  33. Quad::Viewport v;
  34. v.x = luaL_checknumber(L, 2);
  35. v.y = luaL_checknumber(L, 3);
  36. v.w = luaL_checknumber(L, 4);
  37. v.h = luaL_checknumber(L, 5);
  38. if (lua_isnoneornil(L, 6))
  39. quad->setViewport(v);
  40. else
  41. {
  42. double sw = luaL_checknumber(L, 6);
  43. double sh = luaL_checknumber(L, 7);
  44. quad->refresh(v, sw, sh);
  45. }
  46. return 0;
  47. }
  48. int w_Quad_getViewport(lua_State *L)
  49. {
  50. Quad *quad = luax_checkquad(L, 1);
  51. Quad::Viewport v = quad->getViewport();
  52. lua_pushnumber(L, v.x);
  53. lua_pushnumber(L, v.y);
  54. lua_pushnumber(L, v.w);
  55. lua_pushnumber(L, v.h);
  56. return 4;
  57. }
  58. int w_Quad_getTextureDimensions(lua_State *L)
  59. {
  60. Quad *quad = luax_checkquad(L, 1);
  61. double sw = quad->getTextureWidth();
  62. double sh = quad->getTextureHeight();
  63. lua_pushnumber(L, sw);
  64. lua_pushnumber(L, sh);
  65. return 2;
  66. }
  67. static const luaL_Reg w_Quad_functions[] =
  68. {
  69. { "setViewport", w_Quad_setViewport },
  70. { "getViewport", w_Quad_getViewport },
  71. { "getTextureDimensions", w_Quad_getTextureDimensions },
  72. { 0, 0 }
  73. };
  74. extern "C" int luaopen_quad(lua_State *L)
  75. {
  76. return luax_register_type(L, GRAPHICS_QUAD_ID, "Quad", w_Quad_functions, nullptr);
  77. }
  78. } // graphics
  79. } // love