wrap_Graphics.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /**
  2. * Copyright (c) 2006-2009 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. #include "wrap_Graphics.h"
  21. namespace love
  22. {
  23. namespace graphics
  24. {
  25. namespace opengl
  26. {
  27. static Graphics * instance = 0;
  28. int w_checkMode(lua_State * L)
  29. {
  30. int w = luaL_checkint(L, 1);
  31. int h = luaL_checkint(L, 2);
  32. bool fs = luax_toboolean(L, 3);
  33. luax_pushboolean(L, instance->checkMode(w, h, fs));
  34. return 1;
  35. }
  36. int w_setMode(lua_State * L)
  37. {
  38. int w = luaL_checkint(L, 1);
  39. int h = luaL_checkint(L, 2);
  40. bool fs = luax_optboolean(L, 3, false);
  41. bool vsync = luax_optboolean(L, 4, true);
  42. int fsaa = luaL_optint(L, 5, 0);
  43. luax_pushboolean(L, instance->setMode(w, h, fs, vsync, fsaa));
  44. return 1;
  45. }
  46. int w_toggleFullscreen(lua_State * L)
  47. {
  48. luax_pushboolean(L, instance->toggleFullscreen());
  49. return 1;
  50. }
  51. int w_reset(lua_State * L)
  52. {
  53. instance->reset();
  54. return 0;
  55. }
  56. int w_clear(lua_State * L)
  57. {
  58. instance->clear();
  59. return 0;
  60. }
  61. int w_present(lua_State * L)
  62. {
  63. instance->present();
  64. return 0;
  65. }
  66. int w_setCaption(lua_State * L)
  67. {
  68. const char * str = luaL_checkstring(L, 1);
  69. instance->setCaption(str);
  70. return 0;
  71. }
  72. int w_getCaption(lua_State * L)
  73. {
  74. return instance->getCaption(L);
  75. }
  76. int w_getWidth(lua_State * L)
  77. {
  78. lua_pushnumber(L, instance->getWidth());
  79. return 1;
  80. }
  81. int w_getHeight(lua_State * L)
  82. {
  83. lua_pushnumber(L, instance->getHeight());
  84. return 1;
  85. }
  86. int w_isCreated(lua_State * L)
  87. {
  88. luax_pushboolean(L, instance->isCreated());
  89. return 1;
  90. }
  91. int w_getModes(lua_State * L)
  92. {
  93. return instance->getModes(L);
  94. }
  95. int w_setScissor(lua_State * L)
  96. {
  97. if(lua_gettop(L) == 0)
  98. {
  99. instance->setScissor();
  100. return 0;
  101. }
  102. int x = luaL_checkint(L, 1);
  103. int y = luaL_checkint(L, 2);
  104. int w = luaL_checkint(L, 3);
  105. int h = luaL_checkint(L, 4);
  106. instance->setScissor(x, y, w, h);
  107. return 0;
  108. }
  109. int w_getScissor(lua_State * L)
  110. {
  111. return instance->getScissor(L);
  112. }
  113. int w_newImage(lua_State * L)
  114. {
  115. // Convert to File, if necessary.
  116. if(lua_isstring(L, 1))
  117. luax_convobj(L, 1, "filesystem", "newFile");
  118. // Convert to ImageData, if necessary.
  119. if(luax_istype(L, 1, FILESYSTEM_FILE_T))
  120. luax_convobj(L, 1, "image", "newImageData");
  121. love::image::ImageData * data = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
  122. // Create the image.
  123. Image * image = instance->newImage(data);
  124. if(image == 0)
  125. return luaL_error(L, "Could not load image.");
  126. // Push the type.
  127. luax_newtype(L, "Image", GRAPHICS_IMAGE_T, (void*)image);
  128. return 1;
  129. }
  130. int w_newGlyph(lua_State * L)
  131. {
  132. love::font::GlyphData * data = luax_checktype<love::font::GlyphData>(L, 1, "GlyphData", FONT_GLYPH_DATA_T);
  133. // Create the image.
  134. Glyph * t = new Glyph(data);
  135. t->load();
  136. // Push the type.
  137. luax_newtype(L, "Glyph", GRAPHICS_GLYPH_T, (void*)t);
  138. return 1;
  139. }
  140. int w_newQuad(lua_State * L)
  141. {
  142. int x = luaL_checkint(L, 1);
  143. int y = luaL_checkint(L, 2);
  144. int w = luaL_checkint(L, 3);
  145. int h = luaL_checkint(L, 4);
  146. int sw = luaL_checkint(L, 5);
  147. int sh = luaL_checkint(L, 6);
  148. Quad * frame = instance->newQuad(x, y, w, h, sw, sh);
  149. if (frame == 0)
  150. return luaL_error(L, "Could not create frame.");
  151. luax_newtype(L, "Quad", GRAPHICS_QUAD_T, (void*)frame);
  152. return 1;
  153. }
  154. int w_newFont(lua_State * L)
  155. {
  156. Data * d = 0;
  157. // Convert to File, if necessary.
  158. if(lua_isstring(L, 1))
  159. luax_convobj(L, 1, "filesystem", "newFile");
  160. if(luax_istype(L, 1, FILESYSTEM_FILE_T))
  161. {
  162. // Check the value.
  163. love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
  164. d = file->read();
  165. }
  166. else if(luax_istype(L, 1, DATA_T))
  167. {
  168. d = luax_checktype<Data>(L, 1, "Data", DATA_T);
  169. }
  170. // Second optional parameter can be a number:
  171. int size = luaL_optint(L, 2, 12);
  172. Font * font = instance->newFont(d, size);
  173. if(font == 0)
  174. return luaL_error(L, "Could not load the font");
  175. luax_newtype(L, "Font", GRAPHICS_FONT_T, (void*)font);
  176. return 1;
  177. }
  178. int w_newImageFont(lua_State * L)
  179. {
  180. // Convert to File, if necessary.
  181. if(lua_isstring(L, 1))
  182. luax_convobj(L, 1, "filesystem", "newFile");
  183. // Convert to Image, if necessary.
  184. if(luax_istype(L, 1, FILESYSTEM_FILE_T))
  185. luax_convobj(L, 1, "graphics", "newImage");
  186. // Check the value.
  187. Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
  188. const char * glyphs = luaL_checkstring(L, 2);
  189. Font * font = instance->newImageFont(image, glyphs);
  190. if(font == 0)
  191. return luaL_error(L, "Could not load the font");
  192. luax_newtype(L, "Font", GRAPHICS_FONT_T, (void*)font);
  193. return 1;
  194. }
  195. int w_newSpriteBatch(lua_State * L)
  196. {
  197. Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
  198. int size = luaL_optint(L, 2, 1000);
  199. int usage = luaL_optint(L, 3, SpriteBatch::USAGE_DYNAMIC);
  200. SpriteBatch * t = instance->newSpriteBatch(image, size, usage);
  201. luax_newtype(L, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T, (void*)t);
  202. return 1;
  203. }
  204. int w_newParticleSystem(lua_State * L)
  205. {
  206. Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
  207. int size = luaL_checkint(L, 2);
  208. ParticleSystem * t = instance->newParticleSystem(image, size);
  209. luax_newtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, (void*)t);
  210. return 1;
  211. }
  212. int w_setColor(lua_State * L)
  213. {
  214. Color c;
  215. c.r = (unsigned char)luaL_checkint(L, 1);
  216. c.g = (unsigned char)luaL_checkint(L, 2);
  217. c.b = (unsigned char)luaL_checkint(L, 3);
  218. c.a = (unsigned char)luaL_optint(L, 4, 255);
  219. instance->setColor(c);
  220. return 0;
  221. }
  222. int w_getColor(lua_State * L)
  223. {
  224. Color c = instance->getColor();
  225. lua_pushinteger(L, c.r);
  226. lua_pushinteger(L, c.g);
  227. lua_pushinteger(L, c.b);
  228. lua_pushinteger(L, c.a);
  229. return 4;
  230. }
  231. int w_setBackgroundColor(lua_State * L)
  232. {
  233. Color c;
  234. c.r = (unsigned char)luaL_checkint(L, 1);
  235. c.g = (unsigned char)luaL_checkint(L, 2);
  236. c.b = (unsigned char)luaL_checkint(L, 3);
  237. c.a = 255;
  238. instance->setBackgroundColor(c);
  239. return 0;
  240. }
  241. int w_getBackgroundColor(lua_State * L)
  242. {
  243. Color c = instance->getBackgroundColor();
  244. lua_pushinteger(L, c.r);
  245. lua_pushinteger(L, c.g);
  246. lua_pushinteger(L, c.b);
  247. lua_pushinteger(L, c.a);
  248. return 4;
  249. }
  250. int w_setFont(lua_State * L)
  251. {
  252. // The second parameter is an optional int.
  253. int size = luaL_optint(L, 2, 12);
  254. // If the first parameter is a string, convert it to a file.
  255. if(lua_isstring(L, 1))
  256. luax_convobj(L, 1, "filesystem", "newFile");
  257. // If the first parameter is a File, use another setFont function.
  258. if(luax_istype(L, 1, FILESYSTEM_FILE_T))
  259. {
  260. love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
  261. instance->setFont(file->read(), size);
  262. return 0;
  263. }
  264. else if(luax_istype(L, 1, DATA_T))
  265. {
  266. Data * data = luax_checktype<Data>(L, 1, "Data", DATA_T);
  267. instance->setFont(data, size);
  268. return 0;
  269. }
  270. Font * font = luax_checktype<Font>(L, 1, "Font", GRAPHICS_FONT_T);
  271. instance->setFont(font);
  272. return 0;
  273. }
  274. int w_getFont(lua_State * L)
  275. {
  276. Font * f = instance->getFont();
  277. if(f == 0)
  278. return 0;
  279. f->retain();
  280. luax_newtype(L, "Font", GRAPHICS_FONT_T, (void*)f);
  281. return 1;
  282. }
  283. int w_setBlendMode(lua_State * L)
  284. {
  285. int mode = luaL_checkint(L, 1);
  286. instance->setBlendMode(mode);
  287. return 0;
  288. }
  289. int w_setColorMode(lua_State * L)
  290. {
  291. int mode = luaL_checkint(L, 1);
  292. instance->setColorMode(mode);
  293. return 0;
  294. }
  295. int w_getBlendMode(lua_State * L)
  296. {
  297. lua_pushinteger(L, instance->getBlendMode());
  298. return 1;
  299. }
  300. int w_getColorMode(lua_State * L)
  301. {
  302. lua_pushinteger(L, instance->getColorMode());
  303. return 1;
  304. }
  305. int w_setLineWidth(lua_State * L)
  306. {
  307. float width = (float)luaL_checknumber(L, 1);
  308. instance->setLineWidth(width);
  309. return 0;
  310. }
  311. int w_setLineStyle(lua_State * L)
  312. {
  313. int style = luaL_checkint(L, 1);
  314. instance->setLineStyle(style);
  315. return 0;
  316. }
  317. int w_setLine(lua_State * L)
  318. {
  319. float width = (float)luaL_checknumber(L, 1);
  320. int style = luaL_optint(L, 2, Graphics::LINE_SMOOTH);
  321. instance->setLine(width, style);
  322. return 0;
  323. }
  324. int w_setLineStipple(lua_State * L)
  325. {
  326. if(lua_gettop(L) == 0)
  327. {
  328. instance->setLineStipple();
  329. return 0;
  330. }
  331. unsigned short pattern = (unsigned short)luaL_checkint(L, 1);
  332. int repeat = luaL_optint(L, 2, 1);
  333. instance->setLineStipple(pattern, repeat);
  334. return 0;
  335. }
  336. int w_getLineWidth(lua_State * L)
  337. {
  338. lua_pushnumber(L, instance->getLineWidth());
  339. return 1;
  340. }
  341. int w_getLineStyle(lua_State * L)
  342. {
  343. lua_pushinteger(L, instance->getLineStyle());
  344. return 1;
  345. }
  346. int w_getLineStipple(lua_State * L)
  347. {
  348. return instance->getLineStipple(L);
  349. }
  350. int w_setPointSize(lua_State * L)
  351. {
  352. float size = (float)luaL_checknumber(L, 1);
  353. instance->setPointSize(size);
  354. return 0;
  355. }
  356. int w_setPointStyle(lua_State * L)
  357. {
  358. int style = luaL_checkint(L, 1);
  359. instance->setPointStyle(style);
  360. return 0;
  361. }
  362. int w_setPoint(lua_State * L)
  363. {
  364. float size = (float)luaL_checknumber(L, 1);
  365. int style = luaL_optint(L, 2, Graphics::POINT_SMOOTH);
  366. instance->setPoint(size, style);
  367. return 0;
  368. }
  369. int w_getPointSize(lua_State * L)
  370. {
  371. lua_pushnumber(L, instance->getPointSize());
  372. return 1;
  373. }
  374. int w_getPointStyle(lua_State * L)
  375. {
  376. lua_pushinteger(L, instance->getPointStyle());
  377. return 1;
  378. }
  379. int w_getMaxPointSize(lua_State * L)
  380. {
  381. lua_pushnumber(L, instance->getMaxPointSize());
  382. return 1;
  383. }
  384. /**
  385. * Draws an Image at the specified coordinates, with rotation and
  386. * scaling along both axes.
  387. * @param x The x-coordinate.
  388. * @param y The y-coordinate.
  389. * @param angle The amount of rotation.
  390. * @param sx The scale factor along the x-axis. (1 = normal).
  391. * @param sy The scale factor along the y-axis. (1 = normal).
  392. * @param ox The offset along the x-axis.
  393. * @param oy The offset along the y-axis.
  394. **/
  395. int w_draw(lua_State * L)
  396. {
  397. Drawable * drawable = luax_checktype<Drawable>(L, 1, "Drawable", GRAPHICS_DRAWABLE_T);
  398. float x = (float)luaL_optnumber(L, 2, 0.0f);
  399. float y = (float)luaL_optnumber(L, 3, 0.0f);
  400. float angle = (float)luaL_optnumber(L, 4, 0.0f);
  401. float sx = (float)luaL_optnumber(L, 5, 1.0f);
  402. float sy = (float)luaL_optnumber(L, 6, sx);
  403. float ox = (float)luaL_optnumber(L, 7, 0);
  404. float oy = (float)luaL_optnumber(L, 8, 0);
  405. drawable->draw(x, y, angle, sx, sy, ox, oy);
  406. return 0;
  407. }
  408. /**
  409. * Draws an Quad of an Image at the specified coordinates,
  410. * with rotation and scaling along both axes.
  411. *
  412. * @param x The x-coordinate.
  413. * @param y The y-coordinate.
  414. * @param angle The amount of rotation.
  415. * @param sx The scale factor along the x-axis. (1 = normal).
  416. * @param sy The scale factor along the y-axis. (1 = normal).
  417. * @param ox The offset along the x-axis.
  418. * @param oy The offset along the y-axis.
  419. * @param f The Quad to dra.
  420. **/
  421. int w_drawq(lua_State * L)
  422. {
  423. Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
  424. Quad * q = luax_checkframe(L, 2);
  425. float x = (float)luaL_checknumber(L, 3);
  426. float y = (float)luaL_checknumber(L, 4);
  427. float angle = (float)luaL_optnumber(L, 5, 0);
  428. float sx = (float)luaL_optnumber(L, 6, 1);
  429. float sy = (float)luaL_optnumber(L, 7, sx);
  430. float ox = (float)luaL_optnumber(L, 8, 0);
  431. float oy = (float)luaL_optnumber(L, 9, 0);
  432. image->drawq(q, x, y, angle, sx, sy, ox, oy);
  433. return 0;
  434. }
  435. int w_drawTest(lua_State * L)
  436. {
  437. Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
  438. float x = (float)luaL_optnumber(L, 2, 0.0f);
  439. float y = (float)luaL_optnumber(L, 3, 0.0f);
  440. float angle = (float)luaL_optnumber(L, 4, 0.0f);
  441. float sx = (float)luaL_optnumber(L, 5, 1.0f);
  442. float sy = (float)luaL_optnumber(L, 6, sx);
  443. float ox = (float)luaL_optnumber(L, 7, 0);
  444. float oy = (float)luaL_optnumber(L, 8, 0);
  445. instance->drawTest(image, x, y, angle, sx, sy, ox, oy);
  446. return 0;
  447. }
  448. int w_print1(lua_State * L)
  449. {
  450. const char * str = luaL_checkstring(L, 1);
  451. float x = (float)luaL_checknumber(L, 2);
  452. float y = (float)luaL_checknumber(L, 3);
  453. float angle = (float)luaL_optnumber(L, 4, 0.0f);
  454. float sx = (float)luaL_optnumber(L, 5, 1.0f);
  455. float sy = (float)luaL_optnumber(L, 6, sx);
  456. switch(lua_gettop(L))
  457. {
  458. case 3:
  459. instance->print(str, x, y);
  460. break;
  461. case 4:
  462. instance->print(str, x, y, angle);
  463. break;
  464. case 5:
  465. instance->print(str, x, y, angle, sx);
  466. break;
  467. case 6:
  468. instance->print(str, x, y, angle, sx, sy);
  469. break;
  470. default:
  471. return luaL_error(L, "Incorrect number of parameters");
  472. }
  473. return 0;
  474. }
  475. int w_printf1(lua_State * L)
  476. {
  477. const char * str = luaL_checkstring(L, 1);
  478. float x = (float)luaL_checknumber(L, 2);
  479. float y = (float)luaL_checknumber(L, 3);
  480. float wrap = (float)luaL_checknumber(L, 4);
  481. int align = luaL_optint(L, 5, 0);
  482. instance->printf(str, x, y, wrap, align);
  483. return 0;
  484. }
  485. int w_point(lua_State * L)
  486. {
  487. float x = (float)luaL_checknumber(L, 1);
  488. float y = (float)luaL_checknumber(L, 2);
  489. instance->point(x, y);
  490. return 0;
  491. }
  492. int w_line(lua_State * L)
  493. {
  494. float x1 = (float)luaL_checknumber(L, 1);
  495. float y1 = (float)luaL_checknumber(L, 2);
  496. float x2 = (float)luaL_checknumber(L, 3);
  497. float y2 = (float)luaL_checknumber(L, 4);
  498. instance->line(x1, y1, x2, y2);
  499. return 0;
  500. }
  501. int w_triangle(lua_State * L)
  502. {
  503. int type = luaL_checkint(L, 1);
  504. float x1 = (float)luaL_checknumber(L, 2);
  505. float y1 = (float)luaL_checknumber(L, 3);
  506. float x2 = (float)luaL_checknumber(L, 4);
  507. float y2 = (float)luaL_checknumber(L, 5);
  508. float x3 = (float)luaL_checknumber(L, 6);
  509. float y3 = (float)luaL_checknumber(L, 7);
  510. instance->triangle(type, x1, y1, x2, y2, x3, y3);
  511. return 0;
  512. }
  513. int w_rectangle(lua_State * L)
  514. {
  515. int type = luaL_checkint(L, 1);
  516. float x = (float)luaL_checknumber(L, 2);
  517. float y = (float)luaL_checknumber(L, 3);
  518. float w = (float)luaL_checknumber(L, 4);
  519. float h = (float)luaL_checknumber(L, 5);
  520. instance->rectangle(type, x, y, w, h);
  521. return 0;
  522. }
  523. int w_quad(lua_State * L)
  524. {
  525. int type = luaL_checkint(L, 1);
  526. float x1 = (float)luaL_checknumber(L, 2);
  527. float y1 = (float)luaL_checknumber(L, 3);
  528. float x2 = (float)luaL_checknumber(L, 4);
  529. float y2 = (float)luaL_checknumber(L, 5);
  530. float x3 = (float)luaL_checknumber(L, 6);
  531. float y3 = (float)luaL_checknumber(L, 7);
  532. float x4 = (float)luaL_checknumber(L, 6);
  533. float y4 = (float)luaL_checknumber(L, 7);
  534. instance->quad(type, x1, y1, x2, y2, x3, y3, x4, y4);
  535. return 0;
  536. }
  537. int w_circle(lua_State * L)
  538. {
  539. int type = luaL_checkint(L, 1);
  540. float x = (float)luaL_checknumber(L, 2);
  541. float y = (float)luaL_checknumber(L, 3);
  542. float radius = (float)luaL_checknumber(L, 4);
  543. int points = luaL_optint(L, 5, 10);
  544. instance->circle(type, x, y, radius, points);
  545. return 0;
  546. }
  547. int w_polygon(lua_State * L)
  548. {
  549. return instance->polygon(L);
  550. }
  551. int w_push(lua_State * L)
  552. {
  553. instance->push();
  554. return 0;
  555. }
  556. int w_pop(lua_State * L)
  557. {
  558. instance->pop();
  559. return 0;
  560. }
  561. int w_rotate(lua_State * L)
  562. {
  563. float deg = (float)luaL_checknumber(L, 1);
  564. instance->rotate(deg);
  565. return 0;
  566. }
  567. int w_scale(lua_State * L)
  568. {
  569. float sx = (float)luaL_optnumber(L, 1, 1.0f);
  570. float sy = (float)luaL_optnumber(L, 2, sx);
  571. instance->scale(sx, sy);
  572. return 0;
  573. }
  574. int w_translate(lua_State * L)
  575. {
  576. float x = (float)luaL_checknumber(L, 1);
  577. float y = (float)luaL_checknumber(L, 2);
  578. instance->translate(x, y);
  579. return 0;
  580. }
  581. // List of functions to wrap.
  582. static const luaL_Reg functions[] = {
  583. { "checkMode", w_checkMode },
  584. { "setMode", w_setMode },
  585. { "toggleFullscreen", w_toggleFullscreen },
  586. { "reset", w_reset },
  587. { "clear", w_clear },
  588. { "present", w_present },
  589. { "newImage", w_newImage },
  590. { "newGlyph", w_newGlyph },
  591. { "newQuad", w_newQuad },
  592. { "newFont", w_newFont },
  593. { "newImageFont", w_newImageFont },
  594. { "newSpriteBatch", w_newSpriteBatch },
  595. { "newParticleSystem", w_newParticleSystem },
  596. { "setColor", w_setColor },
  597. { "getColor", w_getColor },
  598. { "setBackgroundColor", w_setBackgroundColor },
  599. { "getBackgroundColor", w_getBackgroundColor },
  600. { "setFont", w_setFont },
  601. { "getFont", w_getFont },
  602. { "setBlendMode", w_setBlendMode },
  603. { "setColorMode", w_setColorMode },
  604. { "getBlendMode", w_getBlendMode },
  605. { "getColorMode", w_getColorMode },
  606. { "setLineWidth", w_setLineWidth },
  607. { "setLineStyle", w_setLineStyle },
  608. { "setLine", w_setLine },
  609. { "setLineStipple", w_setLineStipple },
  610. { "getLineWidth", w_getLineWidth },
  611. { "getLineStyle", w_getLineStyle },
  612. { "getLineStipple", w_getLineStipple },
  613. { "setPointSize", w_setPointSize },
  614. { "setPointStyle", w_setPointStyle },
  615. { "setPoint", w_setPoint },
  616. { "getPointSize", w_getPointSize },
  617. { "getPointStyle", w_getPointStyle },
  618. { "getMaxPointSize", w_getMaxPointSize },
  619. { "draw", w_draw },
  620. { "drawq", w_drawq },
  621. { "drawTest", w_drawTest },
  622. { "print1", w_print1 },
  623. { "printf1", w_printf1 },
  624. { "setCaption", w_setCaption },
  625. { "getCaption", w_getCaption },
  626. { "getWidth", w_getWidth },
  627. { "getHeight", w_getHeight },
  628. { "isCreated", w_isCreated },
  629. { "getModes", w_getModes },
  630. { "setScissor", w_setScissor },
  631. { "getScissor", w_getScissor },
  632. { "point", w_point },
  633. { "line", w_line },
  634. { "triangle", w_triangle },
  635. { "rectangle", w_rectangle },
  636. { "quad", w_quad },
  637. { "circle", w_circle },
  638. { "polygon", w_polygon },
  639. { "push", w_push },
  640. { "pop", w_pop },
  641. { "rotate", w_rotate },
  642. { "scale", w_scale },
  643. { "translate", w_translate },
  644. { 0, 0 }
  645. };
  646. // Types for this module.
  647. static const lua_CFunction types[] = {
  648. luaopen_font,
  649. luaopen_image,
  650. luaopen_glyph,
  651. luaopen_frame,
  652. luaopen_spritebatch,
  653. luaopen_particlesystem,
  654. 0
  655. };
  656. // List of constants.
  657. static const LuaConstant constants[] = {
  658. { "align_left", Graphics::ALIGN_LEFT },
  659. { "align_right", Graphics::ALIGN_RIGHT },
  660. { "align_center", Graphics::ALIGN_CENTER },
  661. { "blend_alpha", Graphics::BLEND_ALPHA },
  662. { "blend_additive", Graphics::BLEND_ADDITIVE },
  663. { "color_replace", Graphics::COLOR_REPLACE },
  664. { "color_modulate", Graphics::COLOR_MODULATE },
  665. { "draw_line", Graphics::DRAW_LINE },
  666. { "draw_fill", Graphics::DRAW_FILL },
  667. { "line_smooth", Graphics::LINE_SMOOTH },
  668. { "line_rough", Graphics::LINE_ROUGH },
  669. { "point_smooth", Graphics::POINT_SMOOTH },
  670. { "point_rough", Graphics::POINT_ROUGH },
  671. { "filter_linear", Image::FILTER_LINEAR },
  672. { "filter_nearest", Image::FILTER_NEAREST },
  673. { "wrap_clamp", Image::WRAP_CLAMP },
  674. { "wrap_repeat", Image::WRAP_REPEAT },
  675. /**
  676. // Vertex buffer geometry types.
  677. { "type_points", TYPE_POINTS },
  678. { "type_lines", TYPE_LINES },
  679. { "type_line_strip", TYPE_LINE_STRIP },
  680. { "type_triangles", TYPE_TRIANGLES },
  681. { "type_triangle_strip", TYPE_TRIANGLE_STRIP },
  682. { "type_triangle_fan", TYPE_TRIANGLE_FAN },
  683. { "type_num", TYPE_NUM },
  684. // Vertex buffer usage hints.
  685. { "usage_array", USAGE_ARRAY },
  686. { "usage_dynamic", USAGE_DYNAMIC },
  687. { "usage_static", USAGE_STATIC },
  688. { "usage_stream", USAGE_STREAM },
  689. { "usage_num", USAGE_NUM },
  690. **/
  691. { 0, 0 }
  692. };
  693. int luaopen_love_graphics(lua_State * L)
  694. {
  695. if(instance == 0)
  696. {
  697. try
  698. {
  699. instance = new Graphics();
  700. }
  701. catch(Exception & e)
  702. {
  703. return luaL_error(L, e.what());
  704. }
  705. }
  706. luax_register_gc(L, instance);
  707. luax_register_module(L, functions, types, constants, "graphics");
  708. # include <scripts/graphics.lua.h>
  709. return 0;
  710. }
  711. } // opengl
  712. } // graphics
  713. } // love