| 1 | /** | 
|---|
| 2 | * Copyright (c) 2006-2023 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 |  | 
|---|
| 21 | // LOVE | 
|---|
| 22 | #include "wrap_Quad.h" | 
|---|
| 23 |  | 
|---|
| 24 | namespace love | 
|---|
| 25 | { | 
|---|
| 26 | namespace graphics | 
|---|
| 27 | { | 
|---|
| 28 |  | 
|---|
| 29 | Quad *luax_checkquad(lua_State *L, int idx) | 
|---|
| 30 | { | 
|---|
| 31 | return luax_checktype<Quad>(L, idx); | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | int w_Quad_setViewport(lua_State *L) | 
|---|
| 35 | { | 
|---|
| 36 | Quad *quad = luax_checkquad(L, 1); | 
|---|
| 37 |  | 
|---|
| 38 | Quad::Viewport v; | 
|---|
| 39 | v.x = luaL_checknumber(L, 2); | 
|---|
| 40 | v.y = luaL_checknumber(L, 3); | 
|---|
| 41 | v.w = luaL_checknumber(L, 4); | 
|---|
| 42 | v.h = luaL_checknumber(L, 5); | 
|---|
| 43 |  | 
|---|
| 44 | if (lua_isnoneornil(L, 6)) | 
|---|
| 45 | quad->setViewport(v); | 
|---|
| 46 | else | 
|---|
| 47 | { | 
|---|
| 48 | double sw = luaL_checknumber(L, 6); | 
|---|
| 49 | double sh = luaL_checknumber(L, 7); | 
|---|
| 50 | quad->refresh(v, sw, sh); | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | return 0; | 
|---|
| 54 | } | 
|---|
| 55 |  | 
|---|
| 56 | int w_Quad_getViewport(lua_State *L) | 
|---|
| 57 | { | 
|---|
| 58 | Quad *quad = luax_checkquad(L, 1); | 
|---|
| 59 | Quad::Viewport v = quad->getViewport(); | 
|---|
| 60 | lua_pushnumber(L, v.x); | 
|---|
| 61 | lua_pushnumber(L, v.y); | 
|---|
| 62 | lua_pushnumber(L, v.w); | 
|---|
| 63 | lua_pushnumber(L, v.h); | 
|---|
| 64 | return 4; | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | int w_Quad_getTextureDimensions(lua_State *L) | 
|---|
| 68 | { | 
|---|
| 69 | Quad *quad = luax_checkquad(L, 1); | 
|---|
| 70 | double sw = quad->getTextureWidth(); | 
|---|
| 71 | double sh = quad->getTextureHeight(); | 
|---|
| 72 | lua_pushnumber(L, sw); | 
|---|
| 73 | lua_pushnumber(L, sh); | 
|---|
| 74 | return 2; | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | int w_Quad_setLayer(lua_State *L) | 
|---|
| 78 | { | 
|---|
| 79 | Quad *quad = luax_checkquad(L, 1); | 
|---|
| 80 | int layer = (int) luaL_checkinteger(L, 2) - 1; | 
|---|
| 81 | quad->setLayer(layer); | 
|---|
| 82 | return 0; | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | int w_Quad_getLayer(lua_State *L) | 
|---|
| 86 | { | 
|---|
| 87 | Quad *quad = luax_checkquad(L, 1); | 
|---|
| 88 | lua_pushnumber(L, quad->getLayer() + 1); | 
|---|
| 89 | return 1; | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 | static const luaL_Reg w_Quad_functions[] = | 
|---|
| 93 | { | 
|---|
| 94 | { "setViewport", w_Quad_setViewport }, | 
|---|
| 95 | { "getViewport", w_Quad_getViewport }, | 
|---|
| 96 | { "getTextureDimensions", w_Quad_getTextureDimensions }, | 
|---|
| 97 | { "setLayer", w_Quad_setLayer }, | 
|---|
| 98 | { "getLayer", w_Quad_getLayer }, | 
|---|
| 99 | { 0, 0 } | 
|---|
| 100 | }; | 
|---|
| 101 |  | 
|---|
| 102 | extern "C"int luaopen_quad(lua_State *L) | 
|---|
| 103 | { | 
|---|
| 104 | return luax_register_type(L, &Quad::type, w_Quad_functions, nullptr); | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | } // graphics | 
|---|
| 108 | } // love | 
|---|
| 109 |  | 
|---|