aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/load_gui.cpp
blob: 598f8429990bbcf4f95a558db70091d8d313adf7 (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
70
71
72
73
74
75
76
77
78
79
80
#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 "gui/iguiwindow.hpp"
#include "gui/iguiskin.hpp"
#include "gui/iguicheckbox.hpp"
#include "gui/iguiimage.hpp"
#include "../callbackhandeler.hpp"
#include "guiparts.hpp"

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

extern IrrlichtDevice* device;

//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){
	printf("Started loading gui...\n");
	tL = L;
	guidevice = device;
	//gui_elenum = 0;
	//guielements[0] = NULL;

	//Various enums
	register_skin(L);

	lua_newtable(L);
	lua_setglobal(L,"gui");
	//printf("Registering label...\n");
	iguilabel_register(L);
	//printf("Registering checkbox...\n");
	iguicheckbox_register(L);
	//printf("Registering window...\n");
	iguiwindow_register(L,device);
	//printf("Registering guiimage\n");
	iguiimage_register(L);
	//printf("Registering button\n");
	iguibutton_register(L);

	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;
}