aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/load_gui.cpp
blob: ed7faac1d4f82e2f97ba21d3425415d79daffae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
extern "C" {
  #include <lua.h>
  #include <lauxlib.h>
  #include <lualib.h>
}
#include <irrlicht.h>

#include "gui/iguibutton.hpp"
#include "gui/iguilabel.hpp"
#include "../callbackhandeler.hpp"
#include "guiparts.hpp"

using namespace irr;
using namespace gui;
using namespace core;

//Things from guiparts.hpp
std::map<irr::gui::IGUIElement*,int> iguielements;
IrrlichtDevice* guidevice;
long gui_elenum;
std::vector<irr::gui::IGUIElement*> guielements(1);
lua_State* tL;

int screenwidth(lua_State* L);
int screenheight(lua_State* L);

void load_guifuncs(lua_State* L, IrrlichtDevice* d){
  tL = L;
  guidevice = d;
  gui_elenum = 0;
  guielements[0] = NULL;
  printf("About to initalize guielements vector\n");
  printf("Done initalizeing guilements vector\n");

  iguibutton_register(L,d);
  iguilabel_register(L,d);
  lua_pop(L, 1);

  lua_newtable(L);
  //lua_pushcfunction(L,createiguibutton);
  //lua_setfield(L,-2,"createButton");
  lua_setglobal(L,"gui");

  lua_pushcfunction(L,screenwidth);
  lua_setglobal(L,"scrw");

  lua_pushcfunction(L,screenheight);
  lua_setglobal(L,"scrh");

}


int screenheight(lua_State* L){
  core::rect<s32> dim = guidevice->getGUIEnvironment()->getRootGUIElement()->getAbsoluteClippingRect();
  lua_pushnumber(L,dim.getHeight());
  printf("Got screen height:%d\n",dim.getWidth());
  return 1;
}

int screenwidth(lua_State* L){
  core::rect<s32> dim = guidevice->getGUIEnvironment()->getRootGUIElement()->getAbsoluteClippingRect();
  lua_pushnumber(L,dim.getWidth());
  printf("Got screen width:%d\n",dim.getWidth());
  return 1;
}