Context.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #include "precompiled.h"
  2. #include "Context.h"
  3. #include <Rocket/Core/Context.h>
  4. namespace Rocket {
  5. namespace Core {
  6. namespace Lua {
  7. //methods
  8. int ContextAddEventListener(lua_State* L, Context* obj)
  9. {
  10. //need to make an EventListener for Lua before I can do anything else
  11. return 0;
  12. }
  13. int ContextAddMouseCursor(lua_State* L, Context* obj)
  14. {
  15. return 1;
  16. }
  17. int ContextCreateDocument(lua_State* L, Context* obj)
  18. {
  19. const char* tag = luaL_checkstring(L,1);
  20. return 1;
  21. }
  22. int ContextLoadDocument(lua_State* L, Context* obj)
  23. {
  24. const char* path = luaL_checkstring(L,1);
  25. return 1;
  26. }
  27. int ContextLoadMouseCursor(lua_State* L, Context* obj)
  28. {
  29. const char* path = luaL_checkstring(L,1);
  30. ElementDocument* doc = obj->LoadMouseCursor(path);
  31. //LuaType<Document>::push(L,doc);
  32. return 1;
  33. }
  34. int ContextRender(lua_State* L, Context* obj)
  35. {
  36. obj->Render();
  37. return 0;
  38. }
  39. int ContextShowMouseCursor(lua_State* L, Context* obj)
  40. {
  41. bool show = CHECK_BOOL(L,1);
  42. obj->ShowMouseCursor(show);
  43. return 0;
  44. }
  45. int ContextUnloadAllDocuments(lua_State* L, Context* obj)
  46. {
  47. obj->UnloadAllDocuments();
  48. return 0;
  49. }
  50. int ContextUnloadAllMouseCursors(lua_State* L, Context* obj)
  51. {
  52. obj->UnloadAllMouseCursors();
  53. return 0;
  54. }
  55. int ContextUnloadDocument(lua_State* L, Context* obj)
  56. {
  57. //Document* doc = LuaType<Document>::check(L,1);
  58. //obj->UnloadDocument(doc);
  59. return 0;
  60. }
  61. int ContextUnloadMouseCursor(lua_State* L, Context* obj)
  62. {
  63. const char* name = luaL_checkstring(L,1);
  64. obj->UnloadMouseCursor(name);
  65. return 0;
  66. }
  67. int ContextUpdate(lua_State* L, Context* obj)
  68. {
  69. obj->Update();
  70. return 0;
  71. }
  72. //getters
  73. int ContextGetAttrdimensions(lua_State* L)
  74. {
  75. Context* cont = LuaType<Context>::check(L,1);
  76. const Vector2i* dim = &cont->GetDimensions();
  77. //const_cast-ing so that the user can do dimensions.x = 3 and it will actually change the dimensions
  78. //of the context
  79. LuaType<Vector2i>::push(L,const_cast<Vector2i*>(dim),true);
  80. return 1;
  81. }
  82. //returns a table of everything. Not exactly the most efficient way of doing it.
  83. int ContextGetAttrdocuments(lua_State* L)
  84. {
  85. Context* cont = LuaType<Context>::check(L,1);
  86. Element* root = cont->GetRootElement();
  87. lua_newtable(L);
  88. int tableindex = lua_gettop(L);
  89. for(int i = 0; i < root->GetNumChildren(); i++)
  90. {
  91. ElementDocument* doc = root->GetChild(i)->GetOwnerDocument();
  92. if(doc == NULL)
  93. continue;
  94. //LuaType<Document>::push(L,doc);
  95. lua_setfield(L, tableindex,doc->GetId().CString());
  96. lua_pushinteger(L,i);
  97. lua_setfield(L,tableindex,doc->GetId().CString());
  98. }
  99. return 1;
  100. }
  101. int ContextGetAttrfocus_element(lua_State* L)
  102. {
  103. Context* cont = LuaType<Context>::check(L,1);
  104. //LuaType<Element>::push(L,cont->GetFocusElement());
  105. return 1;
  106. }
  107. int ContextGetAttrhover_element(lua_State* L)
  108. {
  109. Context* cont = LuaType<Context>::check(L,1);
  110. //LuaType<Element>::push(L,cont->GetHoverElement());
  111. return 1;
  112. }
  113. int ContextGetAttrname(lua_State* L)
  114. {
  115. Context* cont = LuaType<Context>::check(L,1);
  116. lua_pushstring(L,cont->GetName().CString());
  117. return 1;
  118. }
  119. int ContextGetAttrroot_element(lua_State* L)
  120. {
  121. Context* cont = LuaType<Context>::check(L,1);
  122. //LuaType<Element>::push(L,cont->GetRootElement());
  123. return 1;
  124. }
  125. //setters
  126. int ContextSetAttrdimensions(lua_State* L)
  127. {
  128. Context* cont = LuaType<Context>::check(L,1);
  129. Vector2i* dim = LuaType<Vector2i>::check(L,2);
  130. cont->SetDimensions(*dim);
  131. return 0;
  132. }
  133. RegType<Context> ContextMethods[] =
  134. {
  135. LUAMETHOD(Context,AddEventListener)
  136. LUAMETHOD(Context,AddMouseCursor)
  137. LUAMETHOD(Context,CreateDocument)
  138. LUAMETHOD(Context,LoadDocument)
  139. LUAMETHOD(Context,LoadMouseCursor)
  140. LUAMETHOD(Context,Render)
  141. LUAMETHOD(Context,ShowMouseCursor)
  142. LUAMETHOD(Context,UnloadAllDocuments)
  143. LUAMETHOD(Context,UnloadAllMouseCursors)
  144. LUAMETHOD(Context,UnloadDocument)
  145. LUAMETHOD(Context,UnloadMouseCursor)
  146. LUAMETHOD(Context,Update)
  147. { NULL, NULL },
  148. };
  149. luaL_reg ContextGetters[] =
  150. {
  151. LUAGETTER(Context,dimensions)
  152. LUAGETTER(Context,documents)
  153. LUAGETTER(Context,focus_element)
  154. LUAGETTER(Context,hover_element)
  155. LUAGETTER(Context,name)
  156. LUAGETTER(Context,root_element)
  157. { NULL, NULL },
  158. };
  159. luaL_reg ContextSetters[] =
  160. {
  161. LUASETTER(Context,dimensions)
  162. { NULL, NULL },
  163. };
  164. template<> const char* GetTClassName<Context>() { return "Context"; }
  165. template<> RegType<Context>* GetMethodTable<Context>() { return ContextMethods; }
  166. template<> luaL_reg* GetAttrTable<Context>() { return ContextGetters; }
  167. template<> luaL_reg* SetAttrTable<Context>() { return ContextSetters; }
  168. }
  169. }
  170. }