wrap_Font.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Copyright (c) 2006-2010 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_Font.h"
  22. namespace love
  23. {
  24. namespace graphics
  25. {
  26. namespace opengl
  27. {
  28. Font * luax_checkfont(lua_State * L, int idx)
  29. {
  30. return luax_checktype<Font>(L, idx, "Font", GRAPHICS_FONT_T);
  31. }
  32. int w_Font_getHeight(lua_State * L)
  33. {
  34. Font * t = luax_checkfont(L, 1);
  35. lua_pushnumber(L, t->getHeight());
  36. return 1;
  37. }
  38. int w_Font_getWidth(lua_State * L)
  39. {
  40. Font * t = luax_checkfont(L, 1);
  41. const char * str = luaL_checkstring(L, 2);
  42. lua_pushinteger(L, t->getWidth(str));
  43. return 1;
  44. }
  45. int w_Font_setLineHeight(lua_State * L)
  46. {
  47. Font * t = luax_checkfont(L, 1);
  48. float h = (float)luaL_checknumber(L, 2);
  49. t->setLineHeight(h);
  50. return 0;
  51. }
  52. int w_Font_getLineHeight(lua_State * L)
  53. {
  54. Font * t = luax_checkfont(L, 1);
  55. lua_pushnumber(L, t->getLineHeight());
  56. return 1;
  57. }
  58. static const luaL_Reg functions[] = {
  59. { "getHeight", w_Font_getHeight },
  60. { "getWidth", w_Font_getWidth },
  61. { "setLineHeight", w_Font_setLineHeight },
  62. { "getLineHeight", w_Font_getLineHeight },
  63. { 0, 0 }
  64. };
  65. int luaopen_font(lua_State * L)
  66. {
  67. return luax_register_type(L, "Font", functions);
  68. }
  69. } // opengl
  70. } // graphics
  71. } // love