1 /**
2 * Copyright (c) 2006-2011 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 #include "wrap_SpriteBatch.h"
22 
23 namespace love
24 {
25 namespace graphics
26 {
27 namespace opengl
28 {
luax_checkspritebatch(lua_State * L,int idx)29 	SpriteBatch * luax_checkspritebatch(lua_State * L, int idx)
30 	{
31 		return luax_checktype<SpriteBatch>(L, idx, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T);
32 	}
33 
w_SpriteBatch_add(lua_State * L)34 	int w_SpriteBatch_add(lua_State * L)
35 	{
36 		SpriteBatch * t = luax_checkspritebatch(L, 1);
37 		float x = (float)luaL_optnumber(L, 2, 0.0f);
38 		float y = (float)luaL_optnumber(L, 3, 0.0f);
39 		float angle = (float)luaL_optnumber(L, 4, 0.0f);
40 		float sx = (float)luaL_optnumber(L, 5, 1.0f);
41 		float sy = (float)luaL_optnumber(L, 6, sx);
42 		float ox = (float)luaL_optnumber(L, 7, 0);
43 		float oy = (float)luaL_optnumber(L, 8, 0);
44 		t->add(x, y, angle, sx, sy, ox, oy);
45 		return 0;
46 	}
47 
w_SpriteBatch_addq(lua_State * L)48 	int w_SpriteBatch_addq(lua_State * L)
49 	{
50 		SpriteBatch * t = luax_checkspritebatch(L, 1);
51 		Quad * q = luax_checktype<Quad>(L, 2, "Quad", GRAPHICS_QUAD_T);
52 		float x = (float)luaL_optnumber(L, 3, 0.0f);
53 		float y = (float)luaL_optnumber(L, 4, 0.0f);
54 		float angle = (float)luaL_optnumber(L, 5, 0.0f);
55 		float sx = (float)luaL_optnumber(L, 6, 1.0f);
56 		float sy = (float)luaL_optnumber(L, 7, sx);
57 		float ox = (float)luaL_optnumber(L, 8, 0);
58 		float oy = (float)luaL_optnumber(L, 9, 0);
59 		t->addq(q, x, y, angle, sx, sy, ox, oy);
60 		return 0;
61 	}
62 
w_SpriteBatch_clear(lua_State * L)63 	int w_SpriteBatch_clear(lua_State * L)
64 	{
65 		SpriteBatch * t = luax_checkspritebatch(L, 1);
66 		t->clear();
67 		return 0;
68 	}
69 
w_SpriteBatch_lock(lua_State * L)70 	int w_SpriteBatch_lock(lua_State * L)
71 	{
72 		SpriteBatch * t = luax_checkspritebatch(L, 1);
73 		lua_pushlightuserdata(L, t->lock());
74 		return 1;
75 	}
76 
w_SpriteBatch_unlock(lua_State * L)77 	int w_SpriteBatch_unlock(lua_State * L)
78 	{
79 		SpriteBatch * t = luax_checkspritebatch(L, 1);
80 		t->unlock();
81 		return 0;
82 	}
83 
w_SpriteBatch_setImage(lua_State * L)84 	int w_SpriteBatch_setImage(lua_State * L)
85 	{
86 		SpriteBatch * t = luax_checkspritebatch(L, 1);
87 		Image * image = luax_checktype<Image>(L, 2, "Image", GRAPHICS_IMAGE_T);
88 		t->setImage(image);
89 		return 0;
90 	}
91 
92 	static const luaL_Reg functions[] = {
93 		{ "add", w_SpriteBatch_add },
94 		{ "addq", w_SpriteBatch_addq },
95 		{ "clear", w_SpriteBatch_clear },
96 		{ "lock", w_SpriteBatch_lock },
97 		{ "unlock", w_SpriteBatch_unlock },
98 		{ "setImage", w_SpriteBatch_setImage },
99 		{ 0, 0 }
100 	};
101 
luaopen_spritebatch(lua_State * L)102 	int luaopen_spritebatch(lua_State * L)
103 	{
104 		return luax_register_type(L, "SpriteBatch", functions);
105 	}
106 
107 } // opengl
108 } // graphics
109 } // love
110