Colourb.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include "Colourb.h"
  29. namespace Rocket {
  30. namespace Core {
  31. namespace Lua {
  32. int Colourbnew(lua_State* L)
  33. {
  34. byte red = (byte)luaL_checkint(L,1);
  35. byte green = (byte)luaL_checkint(L,2);
  36. byte blue = (byte)luaL_checkint(L,3);
  37. byte alpha = (byte)luaL_checkint(L,4);
  38. Colourb* col = new Colourb(red,green,blue,alpha);
  39. LuaType<Colourb>::push(L,col,true);
  40. return 1;
  41. }
  42. int Colourb__eq(lua_State* L)
  43. {
  44. Colourb* lhs = LuaType<Colourb>::check(L,1);
  45. LUACHECKOBJ(lhs);
  46. Colourb* rhs = LuaType<Colourb>::check(L,2);
  47. LUACHECKOBJ(rhs);
  48. lua_pushboolean(L, (*lhs) == (*rhs) ? 1 : 0);
  49. return 1;
  50. }
  51. int Colourb__add(lua_State* L)
  52. {
  53. Colourb* lhs = LuaType<Colourb>::check(L,1);
  54. LUACHECKOBJ(lhs);
  55. Colourb* rhs = LuaType<Colourb>::check(L,2);
  56. LUACHECKOBJ(rhs);
  57. Colourb* res = new Colourb((*lhs) + (*rhs));
  58. LuaType<Colourb>::push(L,res,true);
  59. return 1;
  60. }
  61. int Colourb__mul(lua_State* L)
  62. {
  63. Colourb* lhs = LuaType<Colourb>::check(L,1);
  64. LUACHECKOBJ(lhs);
  65. float rhs = (float)luaL_checknumber(L,2);
  66. Colourb* res = new Colourb((*lhs) * rhs);
  67. LuaType<Colourb>::push(L,res,true);
  68. return 1;
  69. }
  70. //getters
  71. int ColourbGetAttrred(lua_State* L)
  72. {
  73. Colourb* obj = LuaType<Colourb>::check(L,1);
  74. LUACHECKOBJ(obj);
  75. lua_pushinteger(L,obj->red);
  76. return 1;
  77. }
  78. int ColourbGetAttrgreen(lua_State* L)
  79. {
  80. Colourb* obj = LuaType<Colourb>::check(L,1);
  81. LUACHECKOBJ(obj);
  82. lua_pushinteger(L,obj->green);
  83. return 1;
  84. }
  85. int ColourbGetAttrblue(lua_State* L)
  86. {
  87. Colourb* obj = LuaType<Colourb>::check(L,1);
  88. LUACHECKOBJ(obj);
  89. lua_pushinteger(L,obj->blue);
  90. return 1;
  91. }
  92. int ColourbGetAttralpha(lua_State* L)
  93. {
  94. Colourb* obj = LuaType<Colourb>::check(L,1);
  95. LUACHECKOBJ(obj);
  96. lua_pushinteger(L,obj->alpha);
  97. return 1;
  98. }
  99. int ColourbGetAttrrgba(lua_State* L)
  100. {
  101. Colourb* obj = LuaType<Colourb>::check(L,1);
  102. LUACHECKOBJ(obj);
  103. lua_pushinteger(L,obj->red);
  104. lua_pushinteger(L,obj->green);
  105. lua_pushinteger(L,obj->blue);
  106. lua_pushinteger(L,obj->alpha);
  107. return 4;
  108. }
  109. //setters
  110. int ColourbSetAttrred(lua_State* L)
  111. {
  112. Colourb* obj = LuaType<Colourb>::check(L,1);
  113. LUACHECKOBJ(obj);
  114. byte red = (byte)luaL_checkinteger(L,2);
  115. obj->red = red;
  116. return 0;
  117. }
  118. int ColourbSetAttrgreen(lua_State* L)
  119. {
  120. Colourb* obj = LuaType<Colourb>::check(L,1);
  121. LUACHECKOBJ(obj);
  122. byte green = (byte)luaL_checkinteger(L,2);
  123. obj->green = green;
  124. return 0;
  125. }
  126. int ColourbSetAttrblue(lua_State* L)
  127. {
  128. Colourb* obj = LuaType<Colourb>::check(L,1);
  129. LUACHECKOBJ(obj);
  130. byte blue = (byte)luaL_checkinteger(L,2);
  131. obj->blue = blue;
  132. return 0;
  133. }
  134. int ColourbSetAttralpha(lua_State* L)
  135. {
  136. Colourb* obj = LuaType<Colourb>::check(L,1);
  137. LUACHECKOBJ(obj);
  138. byte alpha = (byte)luaL_checkinteger(L,2);
  139. obj->alpha = alpha;
  140. return 0;
  141. }
  142. RegType<Colourb> ColourbMethods[] =
  143. {
  144. { NULL, NULL },
  145. };
  146. luaL_reg ColourbGetters[] =
  147. {
  148. LUAGETTER(Colourb,red)
  149. LUAGETTER(Colourb,green)
  150. LUAGETTER(Colourb,blue)
  151. LUAGETTER(Colourb,alpha)
  152. LUAGETTER(Colourb,rgba)
  153. { NULL, NULL },
  154. };
  155. luaL_reg ColourbSetters[] =
  156. {
  157. LUASETTER(Colourb,red)
  158. LUASETTER(Colourb,green)
  159. LUASETTER(Colourb,blue)
  160. LUASETTER(Colourb,alpha)
  161. { NULL, NULL },
  162. };
  163. }
  164. }
  165. }