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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <memory>
#include <map>
#include <functional>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
#include <irrlicht.h>
#include "../guiparts.hpp"
#include "iguielement.hpp"
#include "iguiwindow.hpp"
//#include "iguiutil.hpp"
#include "../../callbackhandeler.hpp"
#include <shared/lua_api/common.hpp>
using namespace irr;
using namespace gui;
/***
Creates a new gui window .
@function gui.newwindow()
@tparam rect dimensions The rectangle to create the window at.
@tparam string title_text The text to show in the title bar of the window
@tparam? iguielement parent The parent element of the window.
@treturn iguiwindow The window element
In return to the usual gui element calls, IGUI window may call a `onClose()` callback.
*/
//new({{sx,sy},{ex,ey}},"title"[,{guielement=parent}]) :: {guielement}
static int newiguiwindow(lua_State* L){
IGUIElement* parent = NULL;
int numargs = lua_gettop(L);
if(numargs == 4){
lua_getfield(L,-1,"guielement");//{{sx,sy},{ex,ey}},"title",{guielement=parent},parent
parent = (IGUIElement*)lua_touserdata(L,-1);
lua_pop(L,2);
}
//{{sx,sy},{ex,ey},"title"
const char* title_c = lua_tostring(L,-1);
const wchar_t* title_w = irr::core::stringw(title_c).c_str();
lua_pop(L,1);//{{sx,sy},{ex,ey}}
//Frame position
long sx,sy,ex,ey;
poprecti(L,&sx,&sy,&ex,&ey);//
//Create the window
IGUIEnvironment* env = guidevice->getGUIEnvironment();
IGUIWindow* wi = env->addWindow(
core::rect<s32>(sx,sy,ex,ey),
false,
title_w,
parent,
-1
);
lua_newtable(L);//{}
lua_pushlightuserdata(L,wi);//{},{ud_window}
lua_setfield(L,-2,"guielement");//{element=ud_window}
luaL_getmetatable(L,"gui.window");//{element=ud_window},{m_gui.window}
lua_setmetatable(L,-2);//{element=ud_window, __meta=gui.window}
int ref = luaL_ref(L,LUA_REGISTRYINDEX);//
lua_rawgeti(L,LUA_REGISTRYINDEX,ref);//{element=ud_window, __meta=gui.window}
registerguielement(L,EGET_ELEMENT_CLOSED,"onClose");
iguielements[wi] = ref;
//registerguicallback(wi,EGET_ELEMENT_CLOSED,iguiwindowevent);
return 1;
}
static const luaL_reg iguiwindow_m[] = {
// bool :: iguiwindow:close() -- Called when window is closed, returning
// -- Anything but false or nil prevents close
{0, 0},
};
/***
A window that you can add other gui elements to.
@class iguiwindow
@inherits iguielement
*/
int iguiwindow_register(lua_State* L, IrrlichtDevice* d){
luaL_newmetatable(L,"gui.window");//m{gui.window}
lua_newtable(L);
luaL_register(L,NULL,iguiwindow_m);
luaL_register(L,NULL,iguielement_m);
lua_setfield(L,-2,"__index");
lua_pop(L,1);//
lua_getglobal(L,"gui");
lua_pushcfunction(L,newiguiwindow);
lua_setfield(L,-2,"newwindow");
lua_pop(L,1);
return 0;
}
|